private void BindColumns(HbmKeyProperty keyPropertySchema, SimpleValue model, bool isNullable, bool autoColumn,
                                 string propertyPath)
        {
            Table table = model.Table;

            if (keyPropertySchema.column1 == null)
            {
                int count = 0;

                foreach (HbmColumn columnSchema in keyPropertySchema.column ?? new HbmColumn[0])
                {
                    Column col = new Column();
                    col.Value     = model;
                    col.TypeIndex = count++;
                    BindColumn(columnSchema, col, isNullable);

                    col.Name = mappings.NamingStrategy.ColumnName(columnSchema.name);
                    if (table != null)
                    {
                        table.AddColumn(col);
                    }
                    //table=null -> an association, fill it in later
                    model.AddColumn(col);

                    //column index
                    BindIndex(columnSchema.index, table, col);
                    //column group index (although it can serve as a separate column index)

                    BindUniqueKey(columnSchema.uniquekey, table, col);
                }
            }
            else
            {
                Column col = new Column();
                col.Value = compositeId;
                BindColumn(keyPropertySchema, col, isNullable);
                col.Name = mappings.NamingStrategy.ColumnName(keyPropertySchema.column1);
                if (table != null)
                {
                    table.AddColumn(col);
                }
                model.AddColumn(col);
                //column group index (although can serve as a separate column index)
            }

            if (autoColumn && model.ColumnSpan == 0)
            {
                Column col = new Column();
                col.Value = model;
                BindColumn(keyPropertySchema, col, isNullable);
                col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath);
                model.Table.AddColumn(col);
                model.AddColumn(col);
                //column group index (although can serve as a separate column index)
            }
        }
Exemplo n.º 2
0
        private void BindColumn(SimpleValue value, bool nullable, string propName)
        {
            var col = new Column {
                Value = value, IsNullable = nullable, Name = mappings.NamingStrategy.ColumnName(propName)
            };

            value.Table.AddColumn(col);
            value.AddColumn(col);

            value.AddColumn(col);
        }
        private void BindColumns(HbmDiscriminator discriminatorSchema, SimpleValue discriminator)
        {
            Table table = discriminator.Table;

            //COLUMN(S)
            if (discriminatorSchema.column != null)
            {
                Column col = new Column();
                col.Value = discriminator;
                BindColumn(discriminatorSchema, col);
                col.Name = mappings.NamingStrategy.ColumnName(discriminatorSchema.column);

                if (table != null)
                {
                    table.AddColumn(col);
                }

                discriminator.AddColumn(col);
            }
            else if (discriminatorSchema.Item != null && discriminatorSchema.Item is HbmColumn)
            {
                HbmColumn theCol = (HbmColumn)discriminatorSchema.Item;
                Column    col    = new Column();
                col.Value = discriminator;
                BindColumn(theCol, col, false);

                col.Name = mappings.NamingStrategy.ColumnName(theCol.name);

                if (table != null)
                {
                    table.AddColumn(col);
                }
                //table=null -> an association, fill it in later

                discriminator.AddColumn(col);

                BindIndex(theCol.index, table, col);
                BindUniqueKey(theCol.uniquekey, table, col);
            }

            if (discriminator.ColumnSpan == 0)
            {
                Column col = new Column();
                col.Value = discriminator;
                BindColumn(discriminatorSchema, col);

                col.Name = mappings.NamingStrategy.PropertyToColumnName(
                    RootClass.DefaultDiscriminatorColumnName);

                discriminator.Table.AddColumn(col);
                discriminator.AddColumn(col);
            }
        }
Exemplo n.º 4
0
        private static void AddColumn(PersistentClass mapping, string columnName, Type accessorType)
        {
            var  typeName   = DICT_TYPE_TO_NAME[accessorType];
            bool isNullable = typeName[typeName.Length - 1] == '?';

            if (isNullable)
            {
                typeName = typeName.Substring(0, typeName.Length - 1);
            }

            // String annotations can be null also
            isNullable = isNullable || Equals(STRING_TYPE_NAME, typeName);

            var column = new Column(columnName)
            {
                IsNullable = isNullable
            };

            mapping.Table.AddColumn(column);
            var value = new SimpleValue(mapping.Table)
            {
                TypeName = typeName
            };

            value.AddColumn(column);
            var property = new Property(value)
            {
                Name = columnName,
                PropertyAccessorName = accessorType.AssemblyQualifiedName
            };

            mapping.AddProperty(property);
        }
Exemplo n.º 5
0
        private void BindColumns(HbmVersion versionSchema, SimpleValue model, bool isNullable, string propertyPath)
        {
            Table table = model.Table;

            if (versionSchema.column1 != null)
            {
                var col = new Column {
                    Value = model
                };
                BindColumn(col, isNullable);
                col.Name = mappings.NamingStrategy.ColumnName(versionSchema.column1);

                if (table != null)
                {
                    table.AddColumn(col);
                }

                model.AddColumn(col);
            }
            else if (versionSchema.column != null)
            {
                foreach (HbmColumn hbmColumn in versionSchema.column)
                {
                    var col = new Column {
                        Value = model
                    };
                    BindColumn(hbmColumn, col, isNullable);
                    if (table != null)
                    {
                        table.AddColumn(col);
                    }

                    model.AddColumn(col);
                }
            }

            if (model.ColumnSpan == 0)
            {
                var col = new Column {
                    Value = model
                };
                BindColumn(col, isNullable);
                col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath);
                model.Table.AddColumn(col);
                model.AddColumn(col);
            }
        }
Exemplo n.º 6
0
        private void AddDefaultColumn(HbmId idSchema, SimpleValue id)
        {
            Column column = CreateColumn(idSchema);

            column.Value = id;
            string propertyName = idSchema.name ?? RootClass.DefaultIdentifierColumnName;

            column.Name = mappings.NamingStrategy.PropertyToColumnName(propertyName);

            id.Table.AddColumn(column);
            id.AddColumn(column);
        }
Exemplo n.º 7
0
        private void AddColumn(SimpleValue id, string propName)
        {
            Column column = CreateColumn();

            column.Value = id;
            column.Name  = mapper.Mappings.NamingStrategy.ColumnName(propName);

            if (id.Table != null)
            {
                id.Table.AddColumn(column);
            }

            id.AddColumn(column);
        }
Exemplo n.º 8
0
        private void AddColumnFromAttribute(HbmId idSchema, SimpleValue id)
        {
            Column column = CreateColumn(idSchema);

            column.Value = id;
            column.Name  = mappings.NamingStrategy.ColumnName(idSchema.column1);

            if (id.Table != null)
            {
                id.Table.AddColumn(column);
            }

            id.AddColumn(column);
        }
Exemplo n.º 9
0
 public void linkWithValue(SimpleValue value)
 {
     if (formula != null)
     {
         value.AddFormula(formula);
     }
     else
     {
         MappingColumn.Value = value;
         value.AddColumn(MappingColumn);
         value.Table.AddColumn(MappingColumn);
         AddColumnBinding(value);
         table = value.Table;
     }
 }
Exemplo n.º 10
0
        private void BindColumn(HbmColumn hbmColumn, Table table, bool isNullable)
        {
            var col = new Column {
                Value = value
            };

            BindColumn(hbmColumn, col, isNullable);

            if (table != null)
            {
                table.AddColumn(col);
            }

            value.AddColumn(col);

            //column index
            BindIndex(hbmColumn.index, table, col);
            //column group index (although it can serve as a separate column index)
            BindUniqueKey(hbmColumn.uniquekey, table, col);
        }
Exemplo n.º 11
0
        private void AddColumnsFromList(HbmId idSchema, SimpleValue id)
        {
            int count = 0;

            foreach (HbmColumn columnSchema in idSchema.column ?? new HbmColumn[0])
            {
                Column column = CreateColumn(columnSchema, id, count++);
                column.Name = mappings.NamingStrategy.ColumnName(columnSchema.name);

                if (id.Table != null)
                {
                    id.Table.AddColumn(column);
                }
                //table=null -> an association, fill it in later

                id.AddColumn(column);

                if (columnSchema.index != null && id.Table != null)
                {
                    var tokens = new StringTokenizer(columnSchema.index, ",", false);
                    foreach (string token in tokens)
                    {
                        id.Table.GetOrCreateIndex(token.Trim()).AddColumn(column);
                    }
                }

                if (columnSchema.uniquekey != null && id.Table != null)
                {
                    var tokens = new StringTokenizer(columnSchema.uniquekey, ",", false);
                    foreach (string token in tokens)
                    {
                        id.Table.GetOrCreateUniqueKey(token.Trim()).AddColumn(column);
                    }
                }
            }
        }
Exemplo n.º 12
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);
        }