Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public void DoSecondPass(IDictionary <string, PersistentClass> persistentClasses)
 {
     if (rootClass != null)
     {
         rootClass.CreatePrimaryKey(dialect);
     }
     else if (joinedSubClass != null)
     {
         joinedSubClass.CreatePrimaryKey(dialect);
         joinedSubClass.CreateForeignKey();
     }
     else
     {
         throw new Exception("rootClass and joinedSubClass are null");
     }
 }