diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java index fc7f3a0ba8f..c4884e7344a 100644 --- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java +++ b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AbstractAutoMapper.java @@ -38,7 +38,6 @@ import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation; import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; import org.apache.isis.core.runtime.system.context.IsisContext; -import org.apache.isis.core.runtime.system.persistence.AdapterManagerSpi; import org.apache.isis.core.runtime.system.persistence.PersistenceSession; import org.apache.isis.objectstore.sql.AbstractMapper; import org.apache.isis.objectstore.sql.CollectionMapper; @@ -51,11 +50,11 @@ import org.apache.isis.objectstore.sql.mapping.FieldMapping; public abstract class AbstractAutoMapper extends AbstractMapper { - + private static final Logger LOG = Logger.getLogger(AbstractAutoMapper.class); protected final Map fieldMappingByField = Maps.newLinkedHashMap(); - + protected CollectionMapper collectionMappers[]; protected String collectionMapperFields[]; protected boolean dbCreatesId; @@ -68,15 +67,17 @@ public abstract class AbstractAutoMapper extends AbstractMapper { final FieldMappingLookup lookup; final ObjectMappingLookup objectMappingLookup; - protected AbstractAutoMapper(final String className, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMappingLookup) { - this.specification = specificationFor(className); + protected AbstractAutoMapper(final String className, final String parameterBase, final FieldMappingLookup lookup, + final ObjectMappingLookup objectMappingLookup) { + this.specification = specificationFor(className); this.className = className; this.parameterBase = parameterBase; this.lookup = lookup; this.objectMappingLookup = objectMappingLookup; } - protected AbstractAutoMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper, final String className) { + protected AbstractAutoMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper, + final String className) { this.specification = getSpecificationLoader().loadSpecification(className); this.className = className; @@ -86,21 +87,21 @@ protected AbstractAutoMapper(final FieldMappingLookup lookup, final AbstractAuto this.objectMappingLookup = null; } - private static ObjectSpecification specificationFor(final String className) { - ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(className); + private static ObjectSpecification specificationFor(final String className) { + ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(className); List properties = specification.getProperties(); - if (isNullOrEmpty(properties) && !specification.isAbstract()) { + if (isNullOrEmpty(properties) && !specification.isAbstract()) { throw new SqlObjectStoreException(specification.getFullIdentifier() + " has no fields: " + specification); } - return specification; - } - + return specification; + } protected void setUpFieldMappers() { setUpFieldMappers(lookup, objectMappingLookup, className, parameterBase); } - private void setUpFieldMappers(final FieldMappingLookup lookup, final ObjectMappingLookup objectMappingLookup, final String className, final String parameterBase) { + private void setUpFieldMappers(final FieldMappingLookup lookup, final ObjectMappingLookup objectMappingLookup, + final String className, final String parameterBase) { final IsisConfiguration configParameters = getConfiguration(); table = configParameters.getString(parameterBase + ".table." + className); if (table == null) { @@ -130,7 +131,8 @@ protected String getTableNameFromSpecification(final ObjectSpecification objectS protected void getExtraFields(final List fields) { } - private void setupFullMapping(final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup, final String className, final IsisConfiguration configParameters, final String parameterBase) { + private void setupFullMapping(final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup, + final String className, final IsisConfiguration configParameters, final String parameterBase) { fields.addAll(specification.getAssociations()); @@ -198,9 +200,14 @@ private void setupFullMapping(final FieldMappingLookup lookup, final ObjectMappi if (fieldSpecification.hasSubclasses() || fieldSpecification.isAbstract()) { // PolymorphicForeignKeyInChildCollectionBaseMapper // Or PolymorphicForeignKeyInChildCollectionMapper - collectionMapper = new PolymorphicForeignKeyInChildCollectionBaseMapper(oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup, this, field); + collectionMapper = + new PolymorphicForeignKeyInChildCollectionBaseMapper( + oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup, + this, field); } else { - final ForeignKeyInChildCollectionMapper mapper = new ForeignKeyInChildCollectionMapper(oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup, this, field); + final ForeignKeyInChildCollectionMapper mapper = + new ForeignKeyInChildCollectionMapper(oneToManyProperties[collectionFieldNo], + parameterBase, lookup, objectMapperLookup, this, field); mapper.setUpFieldMappers(); collectionMapper = mapper; } @@ -216,10 +223,8 @@ private void setupFullMapping(final FieldMappingLookup lookup, final ObjectMappi throw new SqlObjectStoreException("Expected property " + property); } /* - * collectionMappers[collectionFieldNo] = new - * ForeignKeyCollectionMapper(elementType, - * oneToManyProperties[collectionFieldNo], parameterBase, - * lookup, objectMapperLookup); + * collectionMappers[collectionFieldNo] = new ForeignKeyCollectionMapper(elementType, + * oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup); */ } else { // TODO use other mappers where necessary @@ -236,53 +241,40 @@ private void setupFullMapping(final FieldMappingLookup lookup, final ObjectMappi } } - for (final ObjectAssociation field : oneToOneProperties) { - if(fieldMappingByField.containsKey(field)) { - continue; - } - final FieldMapping mapping = lookup.createMapping(specification, field); + if (fieldMappingByField.containsKey(field)) { + continue; + } + final FieldMapping mapping = lookup.createMapping(specification, field); fieldMappingByField.put(field, mapping); } } protected String columnList(final Map fieldMappingByField) { - return columnList(fieldMappingByField.values()); + return columnList(fieldMappingByField.values()); } /* - * private void setupSpecifiedMapping( final ObjectSpecification - * specification, final IsisConfiguration configParameters, final String - * parameterBase) { IsisConfiguration columnMappings = - * IsisContext.getConfiguration().createSubset(parameterBase + "column"); - * int columnsSize = columnMappings.size(); // columnNames = new - * String[columnsSize]; oneToOneProperties = new - * ObjectAssociation[columnsSize]; + * private void setupSpecifiedMapping( final ObjectSpecification specification, final IsisConfiguration + * configParameters, final String parameterBase) { IsisConfiguration columnMappings = + * IsisContext.getConfiguration().createSubset(parameterBase + "column"); int columnsSize = columnMappings.size(); + * // columnNames = new String[columnsSize]; oneToOneProperties = new ObjectAssociation[columnsSize]; * - * int i = 0; for (Enumeration names = columnMappings.propertyNames(); - * names.hasMoreElements(); i++) { String columnName = (String) - * names.nextElement(); String fieldName = - * columnMappings.getString(columnName); oneToOneProperties[i] = - * specification.getAssociation(fieldName); // columnNames[i] = columnName; - * } + * int i = 0; for (Enumeration names = columnMappings.propertyNames(); names.hasMoreElements(); i++) { String + * columnName = (String) names.nextElement(); String fieldName = columnMappings.getString(columnName); + * oneToOneProperties[i] = specification.getAssociation(fieldName); // columnNames[i] = columnName; } * - * IsisConfiguration collectionMappings = - * IsisContext.getConfiguration().createSubset( parameterBase + - * "collection"); int collectionsSize = collectionMappings.size(); - * collectionMappers = new AutoCollectionMapper[collectionsSize]; - * oneToManyProperties = new ObjectAssociation[collectionsSize]; + * IsisConfiguration collectionMappings = IsisContext.getConfiguration().createSubset( parameterBase + + * "collection"); int collectionsSize = collectionMappings.size(); collectionMappers = new + * AutoCollectionMapper[collectionsSize]; oneToManyProperties = new ObjectAssociation[collectionsSize]; * - * int j = 0; for (Enumeration names = collectionMappings.propertyNames(); - * names.hasMoreElements(); j++) { String propertyName = (String) - * names.nextElement(); String collectionName = - * collectionMappings.getString(propertyName); String type = - * collectionMappings.getString(collectionName); + * int j = 0; for (Enumeration names = collectionMappings.propertyNames(); names.hasMoreElements(); j++) { String + * propertyName = (String) names.nextElement(); String collectionName = collectionMappings.getString(propertyName); + * String type = collectionMappings.getString(collectionName); * - * oneToManyProperties[j] = specification.getAssociation(collectionName); if - * (type.equals("auto")) { collectionMappers[j] = new - * AutoCollectionMapper(this, specification, oneToManyProperties[j], - * getLookup()); } else { // TODO use other mappers where necessary // new - * ReversedAutoAssociationMapper(specification, collectionName, + * oneToManyProperties[j] = specification.getAssociation(collectionName); if (type.equals("auto")) { + * collectionMappers[j] = new AutoCollectionMapper(this, specification, oneToManyProperties[j], getLookup()); } else + * { // TODO use other mappers where necessary // new ReversedAutoAssociationMapper(specification, collectionName, * parameterBase); * * throw new NotYetImplementedException(); } } } @@ -303,8 +295,9 @@ protected ObjectAdapter getAdapter(final ObjectSpecification spec, final Oid oid if (adapter != null) { return adapter; } - - // REVIEW: where the oid is a TypedOid, the following two lines could be replaced by getPersistenceSession().recreatePersistentAdapter(oid) + + // REVIEW: where the oid is a TypedOid, the following two lines could be replaced by + // getPersistenceSession().recreatePersistentAdapter(oid) // is preferable, since then reuses the PojoRecreator impl defined within SqlPersistorInstaller final Object recreatedPojo = spec.createObject(); return getPersistenceSession().mapRecreatedPojo(oid, recreatedPojo); @@ -333,25 +326,23 @@ protected String values(final DatabaseConnector connector, final ObjectAdapter o return sql.toString(); } - private static boolean isNullOrEmpty(List list) { - return list == null || list.size() == 0; + return list == null || list.size() == 0; } - - @Override public String toString() { - return "AbstractAutoMapper [table=" + table + ",noColumns=" + fieldMappingByField.size() + ",specification=" + specification.getFullIdentifier() + "]"; + return "AbstractAutoMapper [table=" + table + ",noColumns=" + fieldMappingByField.size() + ",specification=" + + specification.getFullIdentifier() + "]"; } - protected SpecificationLoaderSpi getSpecificationLoader() { - return IsisContext.getSpecificationLoader(); - } + protected SpecificationLoaderSpi getSpecificationLoader() { + return IsisContext.getSpecificationLoader(); + } - protected IsisConfiguration getConfiguration() { - return IsisContext.getConfiguration(); - } + protected IsisConfiguration getConfiguration() { + return IsisContext.getConfiguration(); + } protected PersistenceSession getPersistenceSession() { return IsisContext.getPersistenceSession(); @@ -361,5 +352,4 @@ protected AdapterManager getAdapterManager() { return getPersistenceSession().getAdapterManager(); } - } diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java index f6a2f08520f..8e867e68b54 100644 --- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java +++ b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/AutoCollectionMapper.java @@ -26,8 +26,6 @@ import org.apache.isis.core.commons.debug.DebugBuilder; import org.apache.isis.core.metamodel.adapter.ObjectAdapter; -import org.apache.isis.core.metamodel.adapter.ResolveState; -import org.apache.isis.core.metamodel.adapter.oid.Oid; import org.apache.isis.core.metamodel.adapter.oid.RootOid; import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet; import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacet; @@ -51,7 +49,8 @@ public class AutoCollectionMapper extends AbstractMapper implements CollectionMa private final ObjectReferenceMapping elementMapping; private final IdMapping idMapping; - public AutoCollectionMapper(final ObjectSpecification specification, final ObjectAssociation field, final FieldMappingLookup lookup) { + public AutoCollectionMapper(final ObjectSpecification specification, final ObjectAssociation field, + final FieldMappingLookup lookup) { this.field = field; final ObjectSpecification spec = field.getFacet(TypeOfFacet.class).valueSpec(); @@ -87,15 +86,15 @@ public void loadInternalCollection(final DatabaseConnector connector, final Obje final ObjectAdapter collectionAdapter = field.get(parentAdapter); if (!collectionAdapter.canTransitionToResolving()) { return; - } - - if(LOG.isDebugEnabled()) { + } + + if (LOG.isDebugEnabled()) { LOG.debug("loading internal collection " + field); } - + try { PersistorUtil.startResolving(collectionAdapter); - + final StringBuffer sql = new StringBuffer(); sql.append("select "); idMapping.appendColumnNames(sql); @@ -103,17 +102,18 @@ public void loadInternalCollection(final DatabaseConnector connector, final Obje elementMapping.appendColumnNames(sql); sql.append(" from "); sql.append(tableName); - + final Results rs = connector.select(sql.toString()); final List list = new ArrayList(); while (rs.next()) { final ObjectAdapter element = ((JdbcObjectReferenceMapping) elementMapping).initializeField(rs); - if(LOG.isDebugEnabled()) { + if (LOG.isDebugEnabled()) { LOG.debug(" element " + element.getOid()); } list.add(element); } - final CollectionFacet collectionFacet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class); + final CollectionFacet collectionFacet = + collectionAdapter.getSpecification().getFacet(CollectionFacet.class); collectionFacet.init(collectionAdapter, list.toArray(new ObjectAdapter[list.size()])); rs.close(); } finally { diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java index d8cb2211583..2e498f1170d 100644 --- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java +++ b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/ForeignKeyCollectionMapper.java @@ -33,7 +33,6 @@ import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet; import org.apache.isis.core.metamodel.spec.ObjectSpecification; import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation; -import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation; import org.apache.isis.core.runtime.persistence.PersistorUtil; import org.apache.isis.objectstore.sql.CollectionMapper; import org.apache.isis.objectstore.sql.DatabaseConnector; @@ -49,9 +48,8 @@ import org.apache.isis.objectstore.sql.mapping.ObjectReferenceMapping; /** - * Stores 1-to-many collections by creating a foreign-key column in the table - * for the incoming objectAssociation class. This assumes this the class is only - * ever in 1 collection parent. + * Stores 1-to-many collections by creating a foreign-key column in the table for the incoming objectAssociation class. + * This assumes this the class is only ever in 1 collection parent. * * @version $Rev$ $Date$ */ @@ -67,7 +65,8 @@ public class ForeignKeyCollectionMapper extends AbstractAutoMapper implements Co private ObjectMapping originalMapping = null; - public ForeignKeyCollectionMapper(final ObjectAssociation objectAssociation, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup) { + public ForeignKeyCollectionMapper(final ObjectAssociation objectAssociation, final String parameterBase, + final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup) { super(objectAssociation.getSpecification().getFullIdentifier(), parameterBase, lookup, objectMapperLookup); this.field = objectAssociation; @@ -84,7 +83,8 @@ public ForeignKeyCollectionMapper(final ObjectAssociation objectAssociation, fin foreignKeyMapping = lookup.createMapping(columnName, specification); } - protected ForeignKeyCollectionMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) { + protected ForeignKeyCollectionMapper(final FieldMappingLookup lookup, final AbstractAutoMapper abstractAutoMapper, + final ObjectAssociation field) { super(lookup, abstractAutoMapper, field.getSpecification().getFullIdentifier()); this.field = field; @@ -175,11 +175,13 @@ protected void appendCollectionUpdateColumnsToNull(final StringBuffer sql) { sql.append(foreignKeyName + "=NULL "); } - protected void appendCollectionWhereValues(final DatabaseConnector connector, final ObjectAdapter parent, final StringBuffer sql) { + protected void appendCollectionWhereValues(final DatabaseConnector connector, final ObjectAdapter parent, + final StringBuffer sql) { foreignKeyMapping.appendUpdateValues(connector, sql, parent); } - protected void appendCollectionUpdateValues(final DatabaseConnector connector, final ObjectAdapter parent, final StringBuffer sql) { + protected void appendCollectionUpdateValues(final DatabaseConnector connector, final ObjectAdapter parent, + final StringBuffer sql) { appendCollectionWhereValues(connector, parent, sql); } @@ -193,20 +195,22 @@ public void loadInternalCollection(final DatabaseConnector connector, final Obje final ObjectAdapter collectionAdapter = field.get(parentAdapter); if (!collectionAdapter.canTransitionToResolving()) { return; - } - - if(LOG.isDebugEnabled()) { + } + + if (LOG.isDebugEnabled()) { LOG.debug("loading internal collection " + field); } final List list = new ArrayList(); try { PersistorUtil.startResolving(collectionAdapter); - - loadCollectionIntoList(connector, parentAdapter, table, specification, getIdMapping(), fieldMappingByField, versionMapping, list); - - final CollectionFacet collectionFacet = collectionAdapter.getSpecification().getFacet(CollectionFacet.class); + + loadCollectionIntoList(connector, parentAdapter, table, specification, getIdMapping(), fieldMappingByField, + versionMapping, list); + + final CollectionFacet collectionFacet = + collectionAdapter.getSpecification().getFacet(CollectionFacet.class); collectionFacet.init(collectionAdapter, list.toArray(new ObjectAdapter[list.size()])); - + } finally { PersistorUtil.toEndState(collectionAdapter); } @@ -223,8 +227,10 @@ public void loadInternalCollection(final DatabaseConnector connector, final Obje } } - protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent, final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract, final Map fieldMappingByField, final VersionMapping versionMapping, - final List list) { + protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent, + final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract, + final Map fieldMappingByField, final VersionMapping versionMapping, + final List list) { final StringBuffer sql = new StringBuffer(); sql.append("select "); @@ -253,7 +259,8 @@ protected void loadCollectionIntoList(final DatabaseConnector connector, final O rs.close(); } - protected void loadFields(final ObjectAdapter adapter, final Results rs, final Map fieldMappingByField) { + protected void loadFields(final ObjectAdapter adapter, final Results rs, + final Map fieldMappingByField) { if (!adapter.canTransitionToResolving()) { return; } @@ -270,8 +277,8 @@ protected void loadFields(final ObjectAdapter adapter, final Results rs, final M } /** - * Override this in the Polymorphic case to return just the elements that - * are appropriate for the subclass currently being handled. + * Override this in the Polymorphic case to return just the elements that are appropriate for the subclass currently + * being handled. * * @param collection * @return those elements that ought to be used. @@ -285,7 +292,7 @@ protected Iterator getElementsForCollectionAsIterator(final Objec @Override public void saveInternalCollection(final DatabaseConnector connector, final ObjectAdapter parent) { final ObjectAdapter collection = field.get(parent); - if(LOG.isDebugEnabled()) { + if (LOG.isDebugEnabled()) { LOG.debug("Saving internal collection " + collection); } @@ -316,7 +323,8 @@ protected void clearCollectionParent(final DatabaseConnector connector, final Ob connector.update(sql.toString()); } - protected void resetCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent, final Iterator elements) { + protected void resetCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent, + final Iterator elements) { // Reinstall collection parent final StringBuffer update = new StringBuffer(); update.append("update "); diff --git a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java index 47ad94792ad..7c66b2f29f3 100755 --- a/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java +++ b/component/objectstore/sql/sql-impl/src/main/java/org/apache/isis/objectstore/sql/auto/PolymorphicForeignKeyInChildCollectionBaseMapper.java @@ -29,7 +29,6 @@ import org.apache.log4j.Logger; import org.apache.isis.core.metamodel.adapter.ObjectAdapter; -import org.apache.isis.core.metamodel.adapter.oid.Oid; import org.apache.isis.core.metamodel.adapter.oid.RootOid; import org.apache.isis.core.metamodel.adapter.oid.TypedOid; import org.apache.isis.core.metamodel.spec.ObjectSpecification; @@ -50,14 +49,11 @@ import org.apache.isis.objectstore.sql.mapping.FieldMapping; /** - * Used to map 1-to-many collections by creating, in the collection child table - * (which may be an interface or abstract class), 2 columns per parent - * collection. The first column is the class type, the second is the entity ID. - * The columns are named by combining the final part of the parent class name - * and the collection variable name. + * Used to map 1-to-many collections by creating, in the collection child table (which may be an interface or abstract + * class), 2 columns per parent collection. The first column is the class type, the second is the entity ID. The columns + * are named by combining the final part of the parent class name and the collection variable name. * - * You have a choice between this class and - * {@link PolymorphicForeignKeyInChildCollectionMapper} + * You have a choice between this class and {@link PolymorphicForeignKeyInChildCollectionMapper} * * @author Kevin */ @@ -71,7 +67,9 @@ public class PolymorphicForeignKeyInChildCollectionBaseMapper extends ForeignKey private final OidGenerator oidGenerator; - public PolymorphicForeignKeyInChildCollectionBaseMapper(final ObjectAssociation objectAssociation, final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup, final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) { + public PolymorphicForeignKeyInChildCollectionBaseMapper(final ObjectAssociation objectAssociation, + final String parameterBase, final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup, + final AbstractAutoMapper abstractAutoMapper, final ObjectAssociation field) { super(objectAssociation, parameterBase, lookup, objectMapperLookup, abstractAutoMapper, field); @@ -117,7 +115,8 @@ protected void appendCollectionUpdateColumnsToNull(final StringBuffer sql) { } @Override - protected void appendCollectionUpdateValues(final DatabaseConnector connector, final ObjectAdapter parent, final StringBuffer sql) { + protected void appendCollectionUpdateValues(final DatabaseConnector connector, final ObjectAdapter parent, + final StringBuffer sql) { super.appendCollectionUpdateValues(connector, parent, sql); } @@ -138,7 +137,8 @@ protected void clearCollectionParent(final DatabaseConnector connector, final Ob } @Override - protected void resetCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent, final Iterator elements) { + protected void resetCollectionParent(final DatabaseConnector connector, final ObjectAdapter parent, + final Iterator elements) { LOG.debug("Saving polymorphic list"); ObjectSpecification elementSpecification; @@ -161,11 +161,11 @@ protected void resetCollectionParent(final DatabaseConnector connector, final Ob // Row ID column final Object pojo = thisAdapter.getObject(); final RootOid transientRootOid = oidGenerator.createTransientOid(pojo); - + final RootOid persistentRootOid = oidGenerator.createPersistent(pojo, transientRootOid); - + polyIdMapper.appendObjectId(connector, update, persistentRootOid); - + // polyIdMapper.appendObjectId(connector, update, // thisAdapter.getOid()); update.append(","); @@ -192,8 +192,10 @@ public IdMappingAbstract getIdMapping() { } @Override - protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent, final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract, final Map fieldMappingByField, final VersionMapping versionMapping, - final List list) { + protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent, + final String table, final ObjectSpecification specification, final IdMappingAbstract idMappingAbstract, + final Map fieldMappingByField, final VersionMapping versionMapping, + final List list) { LOG.debug("Loading polymorphic list"); final StringBuffer sql = new StringBuffer(); @@ -212,7 +214,8 @@ protected void loadCollectionIntoList(final DatabaseConnector connector, final O final Results rs = connector.select(sql.toString()); final SpecificationLoaderSpi reflector = IsisContext.getSpecificationLoader(); - final JdbcPolymorphicObjectReferenceMapping idMapping = (JdbcPolymorphicObjectReferenceMapping) idMappingAbstract; + final JdbcPolymorphicObjectReferenceMapping idMapping = + (JdbcPolymorphicObjectReferenceMapping) idMappingAbstract; while (rs.next()) { final ObjectSpecification itemSpecification = reflector.loadSpecification(rs.getString(classColumnName)); diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java index 883304e6291..f6c5e9224f6 100755 --- a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java +++ b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java @@ -99,6 +99,8 @@ protected boolean persistenceMechanismIs(final String persistenceMechanism) { /** * This method can be used to do any DB specific actions the first time the test framework is setup. e.g. In the XML * test, it must delete all XML files in the data store directory. + * + * You can also use @BeforeClass to perform pre-connection cleanup, such as deleting hsql-db data directories. */ public void resetPersistenceStoreDirectlyIfRequired() { } diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java index 857fb818f99..17b9bfc3e1b 100644 --- a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java +++ b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/HsqlTest.java @@ -18,6 +18,7 @@ */ package org.apache.isis.objectstore.sql; +import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @@ -39,8 +40,8 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class HsqlTest extends SqlIntegrationTestData { - @Override - public void resetPersistenceStoreDirectlyIfRequired() { + @BeforeClass + public static void deleteHsqlDbFiles() { Files.deleteFilesWithPrefix("hsql-db", "tests", Recursion.DONT_RECURSE); } diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java index 583763779d1..7f79e447578 100755 --- a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java +++ b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java @@ -24,6 +24,7 @@ import java.util.List; +import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; @@ -74,9 +75,13 @@ public String getPropertiesFilename() { return "hsql-poly.properties"; } + @BeforeClass + public static void deleteHsqlDbFiles() { + Files.deleteFilesWithPrefix("hsql-db", "poly", Recursion.DONT_RECURSE); + } + @Override public void resetPersistenceStoreDirectlyIfRequired() { - Files.deleteFilesWithPrefix("hsql-db", "poly", Recursion.DONT_RECURSE); getSqlIntegrationTestFixtures(); }