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); }
public void BindTable(string schema, string catalog, string tableName, IList <String[]> uniqueConstraints, string constraints, Table denormalizedSuperclassTable) { String logicalName = StringHelper.IsNotEmpty(tableName) ? tableName : StringHelper.Unqualify(name); Table table = TableBinder.FillTable(schema, catalog, GetClassTableName(tableName), logicalName, persistentClass.IsAbstract, uniqueConstraints, constraints, denormalizedSuperclassTable, mappings); if (persistentClass is ITableOwner) { log.InfoFormat("Bind entity {0} on table {1}", persistentClass.EntityName, table.Name); ((ITableOwner)persistentClass).Table = table; } else { throw new AssertionFailure("Binding a table for a subclass"); } }
/// <summary> /// A non null propertyHolder means than we process the Pk creation without delay /// </summary> /// <param name="secondaryTable"></param> /// <param name="joinTable"></param> /// <param name="propertyHolder"></param> /// <param name="noDelayInPkColumnCreation"></param> /// <returns></returns> private Join AddJoin(SecondaryTableAttribute secondaryTable, JoinTableAttribute joinTable, IPropertyHolder propertyHolder, bool noDelayInPkColumnCreation) { Join join = new Join(); join.PersistentClass = persistentClass; string schema; string catalog; string table; string realTable; System.Persistence.UniqueConstraintAttribute[] uniqueConstraintsAnn; if (secondaryTable != null) { schema = secondaryTable.Schema; catalog = secondaryTable.Catalog; table = secondaryTable.Name; realTable = mappings.NamingStrategy.TableName(table); //always an explicit table name uniqueConstraintsAnn = secondaryTable.UniqueConstraints; } else if (joinTable != null) { schema = joinTable.Schema; catalog = joinTable.Catalog; table = joinTable.Name; realTable = mappings.NamingStrategy.TableName(table); //always an explicit table name uniqueConstraintsAnn = joinTable.UniqueConstraints; } else { throw new AssertionFailure("Both JoinTable and SecondaryTable are null"); } var uniqueConstraints = new List <string[]>(uniqueConstraintsAnn == null ? 0 : uniqueConstraintsAnn.Length); if (uniqueConstraintsAnn != null && uniqueConstraintsAnn.Length != 0) { foreach (UniqueConstraintAttribute uc in uniqueConstraintsAnn) { uniqueConstraints.Add(uc.ColumnNames); } } Table tableMapping = TableBinder.FillTable( schema, catalog, realTable, table, false, uniqueConstraints, null, null, mappings); //no check constraints available on joins join.Table = tableMapping; //somehow keep joins() for later. //Has to do the work later because it needs persistentClass id! object joinColumns = null; //get the appropriate pk columns if (secondaryTable != null) { joinColumns = secondaryTable.PkJoinColumns; } else if (joinTable != null) { joinColumns = joinTable.JoinColumns; } log.InfoFormat("Adding secondary table to entity {0} -> {1}", persistentClass.EntityName, join.Table.Name); TableAttribute matchingTable = FindMatchingComplimentTableAnnotation(join); if (matchingTable != null) { join.IsSequentialSelect = FetchMode.Join != matchingTable.Fetch; join.IsInverse = matchingTable.IsInverse; join.IsOptional = matchingTable.IsOptional; if (!BinderHelper.IsDefault(matchingTable.SqlInsert.Sql)) { join.SetCustomSQLInsert(matchingTable.SqlInsert.Sql.Trim(), matchingTable.SqlInsert.Callable, ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlInsert.Check.ToString().ToLower())); } if (!BinderHelper.IsDefault(matchingTable.SqlUpdate.Sql)) { join.SetCustomSQLUpdate(matchingTable.SqlUpdate.Sql.Trim(), matchingTable.SqlUpdate.Callable, ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlUpdate.Check.ToString().ToLower()) ); } if (!BinderHelper.IsDefault(matchingTable.SqlDelete.Sql)) { join.SetCustomSQLDelete(matchingTable.SqlDelete.Sql.Trim(), matchingTable.SqlDelete.Callable, ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlDelete.Check.ToString().ToLower()) ); } } else { //default join.IsSequentialSelect = false; join.IsInverse = false; join.IsOptional = false; //perhaps not quite per-spec, but a Good Thing anyway } if (noDelayInPkColumnCreation) { CreatePrimaryColumnsToSecondaryTable(joinColumns, propertyHolder, join); } else { secondaryTables.Add(table, join); secondaryTableJoins.Add(table, joinColumns); } return(join); }