public void Bind(HbmClass classSchema, IDictionary <string, MetaAttribute> inheritedMetas) { var rootClass = new RootClass(); BindClass(classSchema, rootClass, inheritedMetas); // OPTIMISTIC LOCK MODE rootClass.OptimisticLockMode = classSchema.optimisticlock.ToOptimisticLock(); inheritedMetas = GetMetas(classSchema, inheritedMetas, true); // get meta's from <class> //TABLENAME string schema = classSchema.schema ?? mappings.SchemaName; string catalog = classSchema.catalog ?? mappings.CatalogName; string tableName = GetClassTableName(rootClass, classSchema); if (string.IsNullOrEmpty(tableName)) { throw new MappingException( string.Format( "Could not determine the name of the table for entity '{0}'; remove the 'table' attribute or assign a value to it.", rootClass.EntityName)); } Table table = mappings.AddTable(schema, catalog, tableName, classSchema.Subselect, rootClass.IsAbstract.GetValueOrDefault(), classSchema.schemaaction); ((ITableOwner)rootClass).Table = table; log.Info("Mapping class: {0} -> {1}", rootClass.EntityName, rootClass.Table.Name); rootClass.IsMutable = classSchema.mutable; rootClass.Where = classSchema.where ?? rootClass.Where; if (classSchema.check != null) { table.AddCheckConstraint(classSchema.check); } rootClass.IsExplicitPolymorphism = classSchema.polymorphism == HbmPolymorphismType.Explicit; BindCache(classSchema.cache, rootClass); new ClassIdBinder(Mappings).BindId(classSchema.Id, rootClass, table); new ClassCompositeIdBinder(Mappings).BindCompositeId(classSchema.CompositeId, rootClass); new ClassDiscriminatorBinder(rootClass, Mappings).BindDiscriminator(classSchema.discriminator, table); BindTimestamp(classSchema.Timestamp, rootClass, table, inheritedMetas); BindVersion(classSchema.Version, rootClass, table, inheritedMetas); rootClass.CreatePrimaryKey(); BindNaturalId(classSchema.naturalid, rootClass, inheritedMetas); new PropertiesBinder(mappings, rootClass).Bind(classSchema.Properties, inheritedMetas); BindJoins(classSchema.Joins, rootClass, inheritedMetas); BindSubclasses(classSchema.Subclasses, rootClass, inheritedMetas); BindJoinedSubclasses(classSchema.JoinedSubclasses, rootClass, inheritedMetas); BindUnionSubclasses(classSchema.UnionSubclasses, rootClass, inheritedMetas); new FiltersBinder(rootClass, Mappings).Bind(classSchema.filter); mappings.AddClass(rootClass); }
public void HandleJoinedSubclass(PersistentClass model, HbmJoinedSubclass joinedSubclassMapping, IDictionary <string, MetaAttribute> inheritedMetas) { var subclass = new JoinedSubclass(model); BindClass(joinedSubclassMapping, subclass, inheritedMetas); inheritedMetas = GetMetas(joinedSubclassMapping, inheritedMetas, true); // get meta's from <joined-subclass> // joined subclass if (subclass.EntityPersisterClass == null) { subclass.RootClazz.EntityPersisterClass = typeof(JoinedSubclassEntityPersister); } //table + schema names string schema = joinedSubclassMapping.schema ?? mappings.SchemaName; string catalog = joinedSubclassMapping.catalog ?? mappings.CatalogName; // TODO: very strange, the schema does not support it //XmlAttribute actionNode = subnode.Attributes["schema-action"]; //string action = actionNode == null ? "all" : actionNode.Value; string action = "all"; Table mytable = mappings.AddTable(schema, catalog, GetClassTableName(subclass, joinedSubclassMapping.table), null, false, action); ((ITableOwner)subclass).Table = mytable; log.InfoFormat("Mapping joined-subclass: {0} -> {1}", subclass.EntityName, subclass.Table.Name); // KEY BindKey(subclass, joinedSubclassMapping.key, mytable); subclass.CreatePrimaryKey(dialect); if (!subclass.IsJoinedSubclass) { throw new MappingException( "Cannot map joined-subclass " + subclass.EntityName + " to table " + subclass.Table.Name + ", the same table as its base class."); } subclass.CreateForeignKey(); // CHECK mytable.AddCheckConstraint(joinedSubclassMapping.check); // properties new PropertiesBinder(mappings, subclass, dialect).Bind(joinedSubclassMapping.Properties, inheritedMetas); BindJoinedSubclasses(joinedSubclassMapping.JoinedSubclasses, subclass, inheritedMetas); model.AddSubclass(subclass); mappings.AddClass(subclass); }
public void AddCheckConstraint() { var TempTable = new Table("Name", "dbo", null); var CheckConstraint = TempTable.AddCheckConstraint("Name", "Definition"); Assert.Empty(TempTable.Columns); Assert.NotEmpty(TempTable.Constraints); Assert.Contains(CheckConstraint, TempTable.Constraints); Assert.Equal("Name", TempTable.Name); Assert.Null(TempTable.Source); Assert.Empty(TempTable.Triggers); Assert.Equal("Name", CheckConstraint.Name); Assert.Equal("Definition", CheckConstraint.Definition); Assert.Equal(TempTable, CheckConstraint.ParentTable); }
public void Bind(XmlNode node, HbmClass classSchema, IDictionary <string, MetaAttribute> inheritedMetas) { RootClass rootClass = new RootClass(); BindClass(node, classSchema, rootClass, inheritedMetas); inheritedMetas = GetMetas(classSchema, inheritedMetas, true); // get meta's from <class> //TABLENAME string schema = classSchema.schema ?? mappings.SchemaName; string catalog = classSchema.catalog ?? mappings.CatalogName; string tableName = GetClassTableName(rootClass, classSchema); if (string.IsNullOrEmpty(tableName)) { throw new MappingException( string.Format( "Could not determine the name of the table for entity '{0}'; remove the 'table' attribute or assign a value to it.", rootClass.EntityName)); } Table table = mappings.AddTable(schema, catalog, tableName, null, rootClass.IsAbstract.GetValueOrDefault(), classSchema.schemaaction); ((ITableOwner)rootClass).Table = table; log.InfoFormat("Mapping class: {0} -> {1}", rootClass.EntityName, rootClass.Table.Name); rootClass.IsMutable = classSchema.mutable; rootClass.Where = classSchema.where ?? rootClass.Where; if (classSchema.check != null) { table.AddCheckConstraint(classSchema.check); } rootClass.IsExplicitPolymorphism = classSchema.polymorphism == HbmPolymorphismType.Explicit; BindCache(classSchema.cache, rootClass); new ClassIdBinder(this).BindId(classSchema.Id, rootClass, table); new ClassCompositeIdBinder(this).BindCompositeId(classSchema.CompositeId, rootClass); new ClassDiscriminatorBinder(this).BindDiscriminator(classSchema.discriminator, rootClass, table); BindTimestamp(classSchema.Timestamp, rootClass, table, inheritedMetas); BindVersion(classSchema.Version, rootClass, table, inheritedMetas); rootClass.CreatePrimaryKey(dialect); PropertiesFromXML(node, rootClass, inheritedMetas); mappings.AddClass(rootClass); }
public void HandleJoinedSubclass(PersistentClass model, XmlNode subnode, IDictionary <string, MetaAttribute> inheritedMetas) { JoinedSubclass subclass = new JoinedSubclass(model); BindClass(subnode, null, subclass, inheritedMetas); inheritedMetas = GetMetas(subnode.SelectNodes(HbmConstants.nsMeta, namespaceManager), inheritedMetas, true); // get meta's from <joined-subclass> // joined subclass if (subclass.EntityPersisterClass == null) { subclass.RootClazz.EntityPersisterClass = typeof(JoinedSubclassEntityPersister); } //table + schema names XmlAttribute schemaNode = subnode.Attributes["schema"]; string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value; XmlAttribute catalogNode = subnode.Attributes["catalog"]; string catalog = catalogNode == null ? mappings.CatalogName : catalogNode.Value; XmlAttribute actionNode = subnode.Attributes["schema-action"]; string action = actionNode == null ? "all" : actionNode.Value; Table mytable = mappings.AddTable(schema, catalog, GetClassTableName(subclass, subnode), null, false, action); ((ITableOwner)subclass).Table = mytable; log.InfoFormat("Mapping joined-subclass: {0} -> {1}", subclass.EntityName, subclass.Table.Name); // KEY XmlNode keyNode = subnode.SelectSingleNode(HbmConstants.nsKey, namespaceManager); SimpleValue key = new DependantValue(mytable, subclass.Identifier); subclass.Key = key; if (keyNode.Attributes["on-delete"] != null) { key.IsCascadeDeleteEnabled = "cascade".Equals(keyNode.Attributes["on-delete"].Value); } BindSimpleValue(keyNode, key, false, subclass.EntityName); subclass.CreatePrimaryKey(dialect); if (!subclass.IsJoinedSubclass) { throw new MappingException( "Cannot map joined-subclass " + subclass.EntityName + " to table " + subclass.Table.Name + ", the same table as its base class."); } subclass.CreateForeignKey(); // CHECK XmlAttribute chNode = subnode.Attributes["check"]; if (chNode != null) { mytable.AddCheckConstraint(chNode.Value); } // properties PropertiesFromXML(subnode, subclass, inheritedMetas); model.AddSubclass(subclass); mappings.AddClass(subclass); }