You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ke...@apache.org on 2011/09/12 21:56:51 UTC
svn commit: r1169900 - in
/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto:
ForeignKeyCollectionMapper.java
PolymorphicForeignKeyInChildCollectionMapper.java
Author: kevin
Date: Mon Sep 12 19:56:51 2011
New Revision: 1169900
URL: http://svn.apache.org/viewvc?rev=1169900&view=rev
Log:
ISIS-118: Code cleanup
Modified:
incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java
incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java
Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java?rev=1169900&r1=1169899&r2=1169900&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java Mon Sep 12 19:56:51 2011
@@ -167,7 +167,8 @@ public class ForeignKeyCollectionMapper
final List<ObjectAdapter> list = new ArrayList<ObjectAdapter>();
- loadCollectionIntoList(connector, parent, makeResolved, idMapping, fieldMappings, versionMapping, list);
+ loadCollectionIntoList(connector, parent, makeResolved, table, specification, idMapping, fieldMappings,
+ versionMapping, list);
final CollectionFacet collectionFacet = collection.getSpecification().getFacet(CollectionFacet.class);
collectionFacet.init(collection, list.toArray(new ObjectAdapter[list.size()]));
@@ -187,8 +188,8 @@ public class ForeignKeyCollectionMapper
}
protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent,
- final boolean makeResolved, final IdMapping idMapping, final List<FieldMapping> fieldMappings,
- final VersionMapping versionMapping, final List<ObjectAdapter> list) {
+ final boolean makeResolved, final String table, ObjectSpecification specification, final IdMapping idMapping,
+ final List<FieldMapping> fieldMappings, final VersionMapping versionMapping, final List<ObjectAdapter> list) {
final StringBuffer sql = new StringBuffer();
sql.append("select ");
idMapping.appendColumnNames(sql);
Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java?rev=1169900&r1=1169899&r2=1169900&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/PolymorphicForeignKeyInChildCollectionMapper.java Mon Sep 12 19:56:51 2011
@@ -34,6 +34,7 @@ import org.apache.isis.core.metamodel.sp
import org.apache.isis.runtimes.dflt.objectstores.sql.DatabaseConnector;
import org.apache.isis.runtimes.dflt.objectstores.sql.FieldMappingLookup;
import org.apache.isis.runtimes.dflt.objectstores.sql.IdMapping;
+import org.apache.isis.runtimes.dflt.objectstores.sql.ObjectMapping;
import org.apache.isis.runtimes.dflt.objectstores.sql.ObjectMappingLookup;
import org.apache.isis.runtimes.dflt.objectstores.sql.VersionMapping;
import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMapping;
@@ -52,8 +53,7 @@ public class PolymorphicForeignKeyInChil
private final ObjectAssociation baseField;
private final List<String> tables;
private final List<ObjectSpecification> tableSpecifications;
- private final List<AutoMapper> subClassMappers;
- // private final String classColumnName;
+ private final List<ObjectMapping> subClassMappers;
// For iterating through the subclasses
private ObjectSpecification currentTableSpecification;
@@ -66,8 +66,6 @@ public class PolymorphicForeignKeyInChil
final String parameterBase;
final FieldMappingLookup lookup;
final ObjectMappingLookup objectMapperLookup;
- // final AbstractAutoMapper abstractAutoMapper;
- // final ObjectAssociation field;
final String fieldClassName;
public PolymorphicForeignKeyInChildCollectionMapper(final ObjectAssociation objectAssociation,
@@ -76,24 +74,19 @@ public class PolymorphicForeignKeyInChil
super(lookup, abstractAutoMapper, field);
- // super(objectAssociation, parameterBase, lookup, objectMapperLookup, abstractAutoMapper, field);
fieldClassName = className;
baseField = objectAssociation;
tables = new ArrayList<String>();
tableSpecifications = new ArrayList<ObjectSpecification>();
- subClassMappers = new ArrayList<AutoMapper>();
+ subClassMappers = new ArrayList<ObjectMapping>();
// Capture for use in creating subclass mappers.
this.parameterBase = parameterBase;
this.lookup = lookup;
this.objectMapperLookup = objectMapperLookup;
- // this.abstractAutoMapper = abstractAutoMapper;
- // this.field = field;
addSubSpecificationsToTable(specification);
-
- // classColumnName = Sql.identifier(getForeignKeyName() + "_cls");
}
protected void addSubSpecificationsToTable(ObjectSpecification objectSpecification) {
@@ -102,9 +95,7 @@ public class PolymorphicForeignKeyInChil
tables.add(tableNameFromSpecification);
tableSpecifications.add(objectSpecification);
- // setUpFieldMappers();
- AutoMapper autoMapper =
- new AutoMapper(objectSpecification.getFullIdentifier(), parameterBase, lookup, objectMapperLookup);
+ ObjectMapping autoMapper = objectMapperLookup.getMapping(objectSpecification, null);
subClassMappers.add(autoMapper);
}
if (objectSpecification.hasSubclasses()) {
@@ -118,7 +109,7 @@ public class PolymorphicForeignKeyInChil
public boolean needsTables(DatabaseConnector connection) {
for (String subTableName : tables) {
table = subTableName;
- if (super.needsTables(connection)) { // || !connection.hasColumn(table, classColumnName)) {
+ if (super.needsTables(connection)) {
// Stop on first table that is needed.
return true;
}
@@ -133,38 +124,10 @@ public class PolymorphicForeignKeyInChil
if (super.needsTables(connection)) {
super.createTables(connection);
}
-
- // if (!connection.hasColumn(table, classColumnName)) {
- // // I couldn't combine this in one operation with appendColumnDefinitions
- // final StringBuffer sql = new StringBuffer();
- // sql.append("alter table ");
- // sql.append(table);
- // sql.append(" add ");
- //
- // sql.append(classColumnName);
- // sql.append(" ");
- // sql.append(JdbcConnector.TYPE_LONG_STRING());
- //
- // connection.update(sql.toString());
- // }
}
}
@Override
- protected void appendCollectionUpdateColumnsToNull(StringBuffer sql) {
- super.appendCollectionUpdateColumnsToNull(sql);
- // sql.append("," + classColumnName + "=NULL");
- }
-
- @Override
- protected void appendCollectionUpdateValues(final DatabaseConnector connector, final ObjectAdapter parent,
- final StringBuffer sql) {
- super.appendCollectionUpdateValues(connector, parent, sql);
- // sql.append("," + classColumnName + "=?");
- // connector.addToQueryValues(currentTableSpecification.getFullIdentifier());
- }
-
- @Override
protected Iterator<ObjectAdapter> getElementsForCollectionAsIterator(final ObjectAdapter collection) {
return currentIterator;
}
@@ -181,7 +144,6 @@ public class PolymorphicForeignKeyInChil
currentCollection.add(item);
}
- // TODO: Polymorphism: save instances to appropriate subclass tables
for (int i = 0; i < tables.size(); i++) {
currentTableSpecification = tableSpecifications.get(i);
currentIndex = 0;
@@ -218,30 +180,19 @@ public class PolymorphicForeignKeyInChil
}
@Override
- public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent,
- final boolean makeResolved) {
- final ObjectAdapter collection = baseField.get(parent);
- LOG.debug("loading polymorphic internal collection " + collection);
- // TODO: Polymorphism: load instances from all subclass tables
- super.loadInternalCollection(connector, parent, makeResolved);
- }
-
- @Override
protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent,
- final boolean makeResolved, final IdMapping idMapping, final List<FieldMapping> fieldMappings,
- final VersionMapping versionMapping, final List<ObjectAdapter> superList) {
- // TODO: Polymorphism: save instances to appropriate subclass tables
+ final boolean makeResolved, final String table, final ObjectSpecification specification,
+ final IdMapping idMapping, final List<FieldMapping> fieldMappings, final VersionMapping versionMapping,
+ final List<ObjectAdapter> superList) {
final List<ObjectAdapter> list = new ArrayList<ObjectAdapter>();
for (int i = 0; i < tables.size(); i++) {
- currentTableSpecification = tableSpecifications.get(i);
-
- AutoMapper mapper = subClassMappers.get(i);
- specification = currentTableSpecification;
+ currentTableSpecification = tableSpecifications.get(i);
+ AutoMapper mapper = (AutoMapper) subClassMappers.get(i);
+ String mapperTable = tables.get(i);
- table = tables.get(i);
- super.loadCollectionIntoList(connector, parent, makeResolved, mapper.getIdMapping(), mapper.fieldMappings,
- mapper.getVersionMapping(), list);
+ super.loadCollectionIntoList(connector, parent, makeResolved, mapperTable, currentTableSpecification,
+ mapper.getIdMapping(), mapper.fieldMappings, mapper.getVersionMapping(), list);
superList.addAll(list);
list.clear();