}
private void addOwningSide(EntityType targetType)
{
AmberPersistenceUnit persistenceUnit = _sourceType.getPersistenceUnit();
ManyToManyField manyToManyField;
manyToManyField
= new ManyToManyField(_sourceType, _fieldName, getCascade());
manyToManyField.setType(targetType);
String sqlTable = _sourceType.getTable().getName() + "_" +
targetType.getTable().getName();
JoinTableConfig joinTableConfig = getJoinTable();
AmberTable mapTable = null;
ArrayList<ForeignColumn> sourceColumns = null;
ArrayList<ForeignColumn> targetColumns = null;
HashMap<String,JoinColumnConfig> joinColumnsConfig = null;
HashMap<String,JoinColumnConfig> inverseJoinColumnsConfig = null;
if (joinTableConfig != null) {
String joinTableName = joinTableConfig.getName();
joinColumnsConfig = joinTableConfig.getJoinColumnMap();
inverseJoinColumnsConfig = joinTableConfig.getInverseJoinColumnMap();
if (joinColumnsConfig != null
&& joinColumnsConfig.size() > 0)
manyToManyField.setJoinColumns(true);
if (inverseJoinColumnsConfig != null
&& inverseJoinColumnsConfig.size() > 0)
manyToManyField.setInverseJoinColumns(true);
if (! joinTableName.equals(""))
sqlTable = joinTableName;
}
mapTable = persistenceUnit.createTable(sqlTable);
sourceColumns
= calculateColumns(_field, _fieldName, mapTable,
_sourceType.getTable().getName() + "_",
_sourceType, joinColumnsConfig);
targetColumns
= calculateColumns(_field, _fieldName, mapTable,
targetType.getTable().getName() + "_",
targetType,
inverseJoinColumnsConfig);
manyToManyField.setAssociationTable(mapTable);
manyToManyField.setTable(sqlTable);
manyToManyField.setLazy(isFetchLazy());
manyToManyField.setSourceLink(new LinkColumns(mapTable,
_sourceType.getTable(),
sourceColumns));
manyToManyField.setTargetLink(new LinkColumns(mapTable,
targetType.getTable(),
targetColumns));
_sourceType.addField(manyToManyField);
}