if (isJPA)
_targetLoadIndex = loadGroupIndex;
else
_targetLoadIndex = relatedType.nextLoadGroupIndex();
AmberTable sourceTable = relatedType.getTable();
if (sourceTable == null || ! isJPA) {
// jpa/0ge3, ejb/0602
super.init();
return;
}
// jpa/0j67
setSourceCascadeDelete(isCascade(CascadeType.REMOVE));
int n = 0;
if (_joinColumnMap != null)
n = _joinColumnMap.size();
ArrayList<ForeignColumn> foreignColumns = new ArrayList<ForeignColumn>();
EntityType parentType = _targetType;
ArrayList<AmberColumn> targetIdColumns = _targetType.getId().getColumns();
while (targetIdColumns.size() == 0) {
parentType = parentType.getParentType();
if (parentType == null)
break;
targetIdColumns = parentType.getId().getColumns();
}
for (AmberColumn keyColumn : targetIdColumns) {
String columnName;
columnName = getName() + '_' + keyColumn.getName();
boolean nullable = true;
boolean unique = false;
if (n > 0) {
JoinColumnConfig joinColumn;
if (n == 1) {
joinColumn = (JoinColumnConfig) _joinColumnMap.values().toArray()[0];
} else
joinColumn = _joinColumnMap.get(keyColumn.getName());
if (joinColumn != null) {
// jpa/0h0d
if (! "".equals(joinColumn.getName()))
columnName = joinColumn.getName();
nullable = joinColumn.isNullable();
unique = joinColumn.isUnique();
}
}
else {
JoinColumn joinAnn
= BaseConfigIntrospector.getJoinColumn(_joinColumnsAnn,
keyColumn.getName());
if (joinAnn != null) {
columnName = joinAnn.name();
nullable = joinAnn.nullable();
unique = joinAnn.unique();
}
}
ForeignColumn foreignColumn;
foreignColumn = sourceTable.createForeignColumn(columnName, keyColumn);
foreignColumn.setNotNull(! nullable);
foreignColumn.setUnique(unique);
foreignColumns.add(foreignColumn);
}
LinkColumns linkColumns = new LinkColumns(sourceTable,
_targetType.getTable(),
foreignColumns);
setLinkColumns(linkColumns);
super.init();
Id id = getEntityTargetType().getId();
ArrayList<AmberColumn> keys = id.getColumns();
if (_linkColumns == null) {
ArrayList<ForeignColumn> columns = new ArrayList<ForeignColumn>();
for (int i = 0; i < keys.size(); i++) {
AmberColumn key = keys.get(i);
String name;
if (keys.size() == 1)
name = getName();
else
name = getName() + "_" + key.getName();
columns.add(sourceTable.createForeignColumn(name, key));
}
_linkColumns = new LinkColumns(relatedType.getTable(),
_targetType.getTable(),
columns);