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); } }
protected virtual void BindColumn(SimpleValue model, ColumnMapping columnMapping) { Table table = model.Table; var column = CreateColumn(model, columnMapping); if (table != null) table.AddColumn(column); model.AddColumn(column); }
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); }
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); }
public static void BindColumns( XmlNode node, SimpleValue model, bool isNullable, bool autoColumn, string propertyPath, Mappings mappings ) { //COLUMN(S) XmlAttribute columnAttribute = node.Attributes[ "column" ]; if( columnAttribute == null ) { int count = 0; Table table = model.Table; foreach( XmlNode columnElement in node.SelectNodes( nsColumn, nsmgr ) ) { Column col = new Column( model.Type, count++ ); BindColumn( columnElement, col, isNullable ); string name = columnElement.Attributes[ "name" ].Value; col.Name = mappings.NamingStrategy.ColumnName( name ); if( table != null ) { table.AddColumn( col ); } //table=null -> an association, fill it in later model.AddColumn( col ); //column index XmlAttribute indexNode = columnElement.Attributes[ "index" ]; if( indexNode != null && table != null ) { table.GetIndex( indexNode.Value ).AddColumn( col ); } //column group index (although it can serve as a separate column index) XmlAttribute parentElementIndexAttr = node.Attributes[ "index" ]; if( parentElementIndexAttr != null && table != null ) { table.GetIndex( parentElementIndexAttr.Value ).AddColumn( col ); } XmlAttribute uniqueNode = columnElement.Attributes[ "unique-key" ]; if( uniqueNode != null && table != null ) { table.GetUniqueKey( uniqueNode.Value ).AddColumn( col ); } } } else { Column col = new Column( model.Type, 0 ); BindColumn( node, col, isNullable ); col.Name = mappings.NamingStrategy.ColumnName( columnAttribute.Value ); Table table = model.Table; if( table != null ) { table.AddColumn( col ); } //table=null -> an association - fill it in later model.AddColumn( col ); //column group index (although can serve as a separate column index) XmlAttribute indexAttr = node.Attributes[ "index" ]; if( indexAttr != null && table != null ) { table.GetIndex( indexAttr.Value ).AddColumn( col ); } } if( autoColumn && model.ColumnSpan == 0 ) { Column col = new Column( model.Type, 0 ); BindColumn( node, col, isNullable ); col.Name = mappings.NamingStrategy.PropertyToColumnName( propertyPath ); model.Table.AddColumn( col ); model.AddColumn( col ); } }
protected void BindColumns(XmlNode node, SimpleValue model, bool isNullable, bool autoColumn, string propertyPath) { Table table = model.Table; //COLUMN(S) XmlAttribute columnAttribute = node.Attributes["column"]; if (columnAttribute == null) { int count = 0; foreach (XmlNode columnElement in node.SelectNodes(HbmConstants.nsColumn, namespaceManager)) { Column col = new Column(); col.Value = model; col.TypeIndex = count++; BindColumn(columnElement, col, isNullable); string name = columnElement.Attributes["name"].Value; col.Name = mappings.NamingStrategy.ColumnName(name); if (table != null) table.AddColumn(col); //table=null -> an association, fill it in later model.AddColumn(col); //column index BindIndex(columnElement.Attributes["index"], table, col); //column group index (although it can serve as a separate column index) BindIndex(node.Attributes["index"], table, col); BindUniqueKey(columnElement.Attributes["unique-key"], table, col); BindUniqueKey(node.Attributes["unique-key"], table, col); } } else { Column col = new Column(); col.Value = model; BindColumn(node, col, isNullable); col.Name = mappings.NamingStrategy.ColumnName(columnAttribute.Value); if (table != null) table.AddColumn(col); model.AddColumn(col); //column group index (although can serve as a separate column index) BindIndex(node.Attributes["index"], table, col); BindUniqueKey(node.Attributes["unique-key"], table, col); } if (autoColumn && model.ColumnSpan == 0) { Column col = new Column(); col.Value = model; BindColumn(node, 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) BindIndex(node.Attributes["index"], table, col); BindUniqueKey(node.Attributes["unique-key"], table, col); } }
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) } }
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; } }
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; 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(dialect); join.CreateForeignKey(); // PROPERTIES new PropertiesBinder(Mappings, persistentClass, dialect).Bind(joinMapping.Properties, join.Table, inheritedMetas, p => { }, join.AddProperty); // CUSTOM SQL HandleCustomSQL(joinMapping, join); }
private void BindColumns(HbmVersion versionSchema, SimpleValue model, bool isNullable, string propertyPath) { Table table = model.Table; if (versionSchema.column != null) { Column col = new Column(); col.Value = model; BindColumn(col, isNullable); col.Name = mappings.NamingStrategy.ColumnName(versionSchema.column); if (table != null) table.AddColumn(col); model.AddColumn(col); } if (model.ColumnSpan == 0) { Column col = new Column(); col.Value = model; BindColumn(col, isNullable); col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath); model.Table.AddColumn(col); model.AddColumn(col); } }
private void BindColumns(HbmTimestamp timestampSchema, SimpleValue model, string propertyPath) { Table table = model.Table; if (timestampSchema.column != null) { Column col = new Column(); col.Value = model; BindColumn(col, false); col.Name = mappings.NamingStrategy.ColumnName(timestampSchema.column); if (table != null) table.AddColumn(col); model.AddColumn(col); } if (model.ColumnSpan == 0) { Column col = new Column(); col.Value = model; BindColumn(col, false); col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath); model.Table.AddColumn(col); model.AddColumn(col); } }
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); }
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); }
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) { StringTokenizer tokens = new StringTokenizer(columnSchema.index, ", "); foreach (string token in tokens) id.Table.GetOrCreateIndex(token).AddColumn(column); } if (columnSchema.uniquekey != null && id.Table != null) { StringTokenizer tokens = new StringTokenizer(columnSchema.uniquekey, ", "); foreach (string token in tokens) id.Table.GetOrCreateUniqueKey(token).AddColumn(column); } } }
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); }
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); } }