public override string[] GetMappings() { List<string> mapping = new List<string>(); ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); foreach (Type type in RhinoSecurity.Entities) { builder.CreateDummyModelFor(type); Stream stream = type.Assembly.GetManifestResourceStream(type.FullName+".hbm.xml"); if (stream == null) continue; using (StreamReader reader = new StreamReader(stream)) mapping.Add(reader.ReadToEnd()); } return mapping.ToArray(); }
public void XmlConfigTest() { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModel model = builder.Create(typeof(Order)); Assert.IsNotNull(model); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(builder.Models); semanticVisitor.VisitNode(model); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; String expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<hibernate-mapping auto-import=\"true\" default-lazy=\"false\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:nhibernate-mapping-2.2\">\r\n" + " <class name=\"Castle.ActiveRecord.Tests.Model.AnyModel.Order, Castle.ActiveRecord.Tests\" table=\"Orders\">\r\n" + " <id name=\"Id\" access=\"property\" column=\"Id\" type=\"Int32\" unsaved-value=\"0\">\r\n" + " <generator class=\"native\">\r\n" + " </generator>\r\n" + " </id>\r\n" + " <bag name=\"Payments\" access=\"property\" table=\"payments_table\" lazy=\"false\">\r\n" + " <key column=\"pay_id\" />\r\n" + " <many-to-any id-type=\"Int32\" meta-type=\"System.String\">\r\n" + " <meta-value value=\"BANK_ACCOUNT\" class=\"Castle.ActiveRecord.Tests.Model.AnyModel.BankAccounts, Castle.ActiveRecord.Tests\" />\r\n" + " <meta-value value=\"CREDIT_CARD\" class=\"Castle.ActiveRecord.Tests.Model.AnyModel.CreditCards, Castle.ActiveRecord.Tests\" />\r\n" + " <column name=\"Billing_Details_Type\" />\r\n" + " <column name=\"Billing_Details_Id\" />\r\n" + " </many-to-any>\r\n" + " </bag>\r\n" + " </class>\r\n" + "</hibernate-mapping>\r\n"; Assert.AreEqual(expected, xml); }
private static ActiveRecordModelCollection BuildModels(ISessionFactoryHolder holder, IConfigurationSource source, IEnumerable<Type> types, bool ignoreProblematicTypes) { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); builder.SetExtension(new ModelBuilderExtensionComposite(extensions)); ActiveRecordModelCollection models = builder.Models; foreach(Type type in types) { if (ShouldIgnoreType(type)) { if (ignoreProblematicTypes) { continue; } else { throw new ActiveRecordException( String.Format("Type `{0}` is registered already", type.FullName)); } } else if (IsConfiguredAsRootType(type)) { if (TypeDefinesADatabaseBoundary(type)) { SetUpConfiguration(source, type, holder); continue; } else { throw new ActiveRecordException( string.Format( "Type `{0}` is not a valid root type. Make sure it is abstract and does not define a table itself.", type.FullName)); } } else if (!IsActiveRecordType(type)) { if (ignoreProblematicTypes) { continue; } else { throw new ActiveRecordException( String.Format("Type `{0}` is not an ActiveRecord type. Use ActiveRecordAttributes to define one", type.FullName)); } } if (type.ContainsGenericParameters) { // Owing to a restriction in NHibernate the reflection optimiser will not work // if we have generic types so turn it off. Do we have anywhere we could log this? Environment.UseReflectionOptimizer = false; } ActiveRecordModel model = builder.Create(type); if (model == null) { throw new ActiveRecordException( String.Format("ActiveRecordModel for `{0}` could not be created", type.FullName)); } registeredTypes.Add(type, String.Empty); if (ModelCreated != null) { ModelCreated(model, source); } } return models; }
private static ActiveRecordModelCollection BuildModels(ISessionFactoryHolder holder, IConfigurationSource source, IEnumerable<Type> types, bool ignoreProblematicTypes) { ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); builder.SetExtension(new ModelBuilderExtensionComposite(extensions)); ActiveRecordModelCollection models = builder.Models; foreach(Type type in types) { if (ShouldIgnoreType(type)) { if (ignoreProblematicTypes) { continue; } else { throw new ActiveRecordException( String.Format("Type `{0}` is registered already", type.FullName)); } } else if (IsConfiguredAsRootType(type)) { if (TypeDefinesADatabaseBoundary(type)) { SetUpConfiguration(source, type, holder); continue; } else { throw new ActiveRecordException( string.Format( "Type `{0}` is not a valid root type. Make sure it is abstract and does not define a table itself.", type.FullName)); } } else if (!IsActiveRecordType(type)) { if (ignoreProblematicTypes) { continue; } else { throw new ActiveRecordException( String.Format("Type `{0}` is not an ActiveRecord type. Use ActiveRecordAttributes to define one", type.FullName)); } } ActiveRecordModel model = builder.Create(type); if (model == null) { throw new ActiveRecordException( String.Format("ActiveRecordModel for `{0}` could not be created", type.FullName)); } registeredTypes.Add(type, String.Empty); if (ModelCreated != null) { ModelCreated(model, source); } } return models; }