Traverse the tree checking the semantics of the relation and association. The goal is to raise clear exceptions with tips of how to fix any error. It also tries to infer as much information from the class / attribute model as possible so it can complete the missing information without the user needing to specify it.
Inheritance: AbstractDepthFirstVisitor
コード例 #1
0
		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);
		}
コード例 #2
0
		private static void RegisterTypes(ISessionFactoryHolder holder, IConfigurationSource source, IEnumerable<Type> types,
		                                  bool ignoreProblematicTypes)
		{
			lock(lockConfig)
			{
				ActiveRecordModelCollection models = BuildModels(holder, source, types, ignoreProblematicTypes);

				GraphConnectorVisitor connectorVisitor = new GraphConnectorVisitor(models);
				connectorVisitor.VisitNodes(models);

				ModelsDelegate modelsCreatedHandler = ModelsCreated;
				if (modelsCreatedHandler != null)
				{
					modelsCreatedHandler(models, source);
				}

				SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(models);
				semanticVisitor.VisitNodes(models);

				ModelsDelegate modelsValidatedHandler = ModelsValidated;
				if (modelsValidatedHandler != null)
				{
					modelsValidatedHandler(models, source);
				}

				AddXmlToNHibernateCfg(holder, models);

				AddXmlToNHibernateFromAssmebliesAttributes(holder, models);

				SessionFactoryHolderDelegate registeredInConfigurationHandler = MappingRegisteredInConfiguration;
				if(registeredInConfigurationHandler!=null)
				{
					registeredInConfigurationHandler(holder);
				}

				if (source.VerifyModelsAgainstDBSchema)
				{
					VerifySchema(models);
				}
			}
		}