collectionMappers = new CollectionMapper[collectionFieldCount];
collectionMapperFields = new String[collectionFieldCount];
final IsisConfiguration subset = IsisContext.getConfiguration().createSubset(parameterBase + ".mapper.");
for (int i = 0, simpleFieldNo = 0, collectionFieldNo = 0; i < fields.size(); i++) {
final ObjectAssociation field = fields.get(i);
if (field.isNotPersisted()) {
continue;
} else if (field.isOneToManyAssociation()) {
oneToManyProperties[collectionFieldNo] = field;
// TODO: Replace "new ForeignKeyCollectionMapper" with a factory
// method(?) to allow a different
// default CollectionMapper
// TODO: I think the default order should be changed - and I
// think I (KAM) have dropped support for the
// original "association-table" implementation. This means the
// current checks are misleading.
final String type = subset.getString(field.getId());
if (type == null || type.equals("association-table")) {
// collectionMappers[collectionFieldNo] = new
// AutoCollectionMapper(specification,
// oneToManyProperties[collectionFieldNo], lookup);
// collectionMappers[collectionFieldNo] = new
// ForeignKeyCollectionMapper(oneToManyProperties[collectionFieldNo],
// parameterBase, lookup,
// objectMapperLookup);
CollectionMapper collectionMapper = null;
// Trying to detect recursion, here.
// Let ForeignKeyInChildCollectionMapper find itself when a
// field is a collection of the current
// field type.
if (this instanceof ForeignKeyInChildCollectionMapper) {
final ForeignKeyInChildCollectionMapper mc = (ForeignKeyInChildCollectionMapper) this;
if (mc.priorField == field) {
collectionMapper = mc;
}
}
if (collectionMapper == null) {
// TODO: Polymorphism - is it sufficient for the
// collectionMapper to handle the subclasses?
final ObjectSpecification fieldSpecification = field.getSpecification();
if (fieldSpecification.hasSubclasses() || fieldSpecification.isAbstract()) {
// PolymorphicForeignKeyInChildCollectionBaseMapper
// Or PolymorphicForeignKeyInChildCollectionMapper
collectionMapper = new PolymorphicForeignKeyInChildCollectionBaseMapper(oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup, this, field);
} else {
final ForeignKeyInChildCollectionMapper mapper = new ForeignKeyInChildCollectionMapper(oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup, this, field);
mapper.setUpFieldMappers();
collectionMapper = mapper;
}
}
collectionMappers[collectionFieldNo] = collectionMapper;
collectionMapperFields[collectionFieldNo] = field.getId();
} else if (type.equals("fk-table")) {
final String property = parameterBase + field.getId() + ".element-type";
final String elementType = configParameters.getString(property);
if (elementType == null) {
throw new SqlObjectStoreException("Expected property " + property);
}
/*
* collectionMappers[collectionFieldNo] = new
* ForeignKeyCollectionMapper(elementType,
* oneToManyProperties[collectionFieldNo], parameterBase,
* lookup, objectMapperLookup);
*/
} else {
// TODO use other mappers where necessary
throw new NotYetImplementedException("for " + type);
}
collectionFieldNo++;
} else if (field.isOneToOneAssociation()) {
oneToOneProperties[simpleFieldNo] = field;
simpleFieldNo++;
} else {
oneToOneProperties[simpleFieldNo] = field;
simpleFieldNo++;