コード例 #1
0
        private void BindJoinToPersistentClass(Join join, Ejb3JoinColumn[] ejb3JoinColumns)
        {
            SimpleValue key = new DependantValue(join.Table, persistentClass.Identifier);

            join.Key = key;
            SetFKNameIfDefined(join);
            key.IsCascadeDeleteEnabled = false;
            TableBinder.BindFk(persistentClass, null, ejb3JoinColumns, key, false, mappings);
            join.CreatePrimaryKey(dialect);
            join.CreateForeignKey();
            persistentClass.AddJoin(join);
        }
コード例 #2
0
        private void BindJoin(HbmJoin joinMapping, Join join, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            PersistentClass persistentClass = join.PersistentClass;

            // TABLENAME
            string schema  = joinMapping.schema ?? mappings.SchemaName;
            string catalog = joinMapping.catalog ?? mappings.CatalogName;

            string action = "all";             // joinMapping.schemaaction ?? "all";

            string tableName = joinMapping.table;
            Table  table     = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, tableName), joinMapping.Subselect, false, action);

            join.Table = table;

            join.IsSequentialSelect = joinMapping.fetch == HbmJoinFetch.Select;
            join.IsInverse          = joinMapping.inverse;
            join.IsOptional         = joinMapping.optional;

            log.InfoFormat("Mapping class join: {0} -> {1}", persistentClass.EntityName, join.Table.Name);

            // KEY
            SimpleValue key = new DependantValue(table, persistentClass.Identifier);

            key.ForeignKeyName         = joinMapping.key.foreignkey;
            join.Key                   = key;
            key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade;
            new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false);

            join.CreatePrimaryKey(dialect);
            join.CreateForeignKey();

            // PROPERTIES
            new PropertiesBinder(Mappings, persistentClass, dialect).Bind(joinMapping.Properties, join.Table,
                                                                          inheritedMetas, p => { },
                                                                          join.AddProperty);

            // CUSTOM SQL
            HandleCustomSQL(joinMapping, join);
        }
コード例 #3
0
        private void BindJoin(HbmJoin joinMapping, Join join, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            PersistentClass persistentClass = join.PersistentClass;

            // TABLENAME
            string schema  = joinMapping.schema ?? mappings.SchemaName;
            string catalog = joinMapping.catalog ?? mappings.CatalogName;

            string action = "all";             // joinMapping.schemaaction ?? "all";

            string tableName = joinMapping.table;
            Table  table     = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, tableName), joinMapping.Subselect, false, action);

            join.Table = table;

            join.IsSequentialSelect = joinMapping.fetch == HbmJoinFetch.Select;
            join.IsInverse          = joinMapping.inverse;
            join.IsOptional         = joinMapping.optional;

            log.Info("Mapping class join: {0} -> {1}", persistentClass.EntityName, @join.Table.Name);

            // KEY
            SimpleValue key;

            if (!String.IsNullOrEmpty(joinMapping.key.propertyref))
            {
                string propertyRef    = joinMapping.key.propertyref;
                var    propertyRefKey = new SimpleValue(persistentClass.Table)
                {
                    IsAlternateUniqueKey = true
                };
                var property = persistentClass.GetProperty(propertyRef);
                join.RefIdProperty = property;
                //we only want one column
                var column = (Column)property.ColumnIterator.First();
                if (!column.Unique)
                {
                    throw new MappingException(
                              string.Format(
                                  "Property {0}, on class {1} must be marked as unique to be joined to with a property-ref.",
                                  property.Name,
                                  persistentClass.ClassName));
                }
                propertyRefKey.AddColumn(column);
                propertyRefKey.TypeName = property.Type.Name;
                key = new ReferenceDependantValue(table, propertyRefKey);
            }
            else
            {
                key = new DependantValue(table, persistentClass.Identifier);
            }

            key.ForeignKeyName         = joinMapping.key.foreignkey;
            join.Key                   = key;
            key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade;
            new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false);

            join.CreatePrimaryKey();
            join.CreateForeignKey();

            // PROPERTIES
            new PropertiesBinder(Mappings, persistentClass).Bind(joinMapping.Properties, join.Table,
                                                                 inheritedMetas, p => { },
                                                                 join.AddProperty);

            // CUSTOM SQL
            HandleCustomSQL(joinMapping, join);
        }