incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1072979 - in /incubator/isis/trunk/alternatives/objectstore/sql: persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/ persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/ persistor/src/main/java/org/a...
Date Mon, 21 Feb 2011 14:24:25 GMT
Author: kevin
Date: Mon Feb 21 14:24:24 2011
New Revision: 1072979

URL: http://svn.apache.org/viewvc?rev=1072979&view=rev
Log:
In the process of pulling constant strings for SQL data types out of the various mapper files. Tests currently work on MS SQL Server 2008, but are incompatible with PostgreSQL (DATETIME vs TIMESTAMP).
Part 1 of 2

Modified:
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/Sql.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlMetaData.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlObjectStore.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlOidGenerator.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/VersionMapping.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/AbstractAutoMapper.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/CombinedCollectionMapper.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcDateTimeMapper.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcSqlMetaData.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcTimestampMapper.java
    incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/test/java/org/apache/isis/alternatives/objectstore/sql/SqlOidTest.java
    incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/singleton/SqlIntegrationTestSingleton.java
    incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/testsystem/TestProxySystemIII.java
    incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/test/java/org/apache/isis/alternatives/objectstore/sql/HsqlTest.java
    incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/MySqlTest.java
    incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/PostgreSqlTest.java

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/Sql.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/Sql.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/Sql.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/Sql.java Mon Feb 21 14:24:24 2011
@@ -17,19 +17,18 @@
  *  under the License.
  */
 
-
 package org.apache.isis.alternatives.objectstore.sql;
 
-
 /**
  * SQL functions, commands, names that are database dependent
  */
 public class Sql {
-    private Sql() {}
+    private Sql() {
+    }
 
     private static SqlMetaData metadata;
 
-    //public static String timestamp = "CURRENT_TIMESTAMP";
+    // public static String timestamp = "CURRENT_TIMESTAMP";
 
     public static void setMetaData(SqlMetaData metadata) {
         Sql.metadata = metadata;
@@ -39,7 +38,8 @@ public class Sql {
         if (encodedString == null || encodedString.equals("NULL")) {
             return "NULL";
         }
-        StringBuffer buffer = new StringBuffer("'");
+        // StringBuffer buffer = new StringBuffer("'");
+        StringBuffer buffer = new StringBuffer(metadata.getQuoteString());
         for (int i = 0; i < encodedString.length(); i++) {
             char c = encodedString.charAt(i);
             if (c == '\'') {
@@ -50,30 +50,21 @@ public class Sql {
                 buffer.append(c);
             }
         }
-        buffer.append("'");
+        // buffer.append("'");
+        buffer.append(metadata.getQuoteString());
         String string = buffer.toString();
         return string;
     }
 
     public static String sqlName(String name) {
-//        TODO need to deal with non-ascii (ie unicode characters) 
+        // TODO need to deal with non-ascii (ie unicode characters)
         return name.replace(' ', '_').toLowerCase();
-        
+
         /*
-        int length = name.length();
-        StringBuffer convertedName = new StringBuffer(length);
-        for (int i = 0; i < length; i++) {
-            char ch = name.charAt(i);
-            if (ch == ' ') {
-                i++;
-                //ch = name.charAt(i);
-                //Character.toUpperCase(ch);
-                ch = '_';
-            }
-            convertedName.append(ch);
-        }
-        return convertedName.toString();
-        */
+         * int length = name.length(); StringBuffer convertedName = new StringBuffer(length); for (int i = 0; i <
+         * length; i++) { char ch = name.charAt(i); if (ch == ' ') { i++; //ch = name.charAt(i);
+         * //Character.toUpperCase(ch); ch = '_'; } convertedName.append(ch); } return convertedName.toString();
+         */
     }
 
     public static String sqlFieldName(String name) {
@@ -83,7 +74,7 @@ public class Sql {
         for (int i = 0; i < length; i++) {
             char ch = name.charAt(i);
             if (Character.isUpperCase(ch)) {
-                if (lastWasLowerCase ) {
+                if (lastWasLowerCase) {
                     convertedName.append('_');
                 }
                 lastWasLowerCase = false;
@@ -95,8 +86,12 @@ public class Sql {
         return sqlName(convertedName.toString());
     }
 
-
     public static String identifier(String name) {
+        // return metadata.quoteIdentifier(name);
+        return tableIdentifier(name);
+    }
+
+    public static String tableIdentifier(String name) {
         if (metadata.isStoresMixedCaseIdentifiers()) {
             return name;
         } else if (metadata.isStoresLowerCaseIdentifiers()) {
@@ -107,5 +102,5 @@ public class Sql {
             throw new SqlObjectStoreException("No case preference set up: " + name);
         }
     }
-    
+
 }

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlMetaData.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlMetaData.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlMetaData.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlMetaData.java Mon Feb 21 14:24:24 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.alternatives.objectstore.sql;
 
 public interface SqlMetaData {
@@ -30,5 +29,8 @@ public interface SqlMetaData {
     boolean isStoresMixedCaseIdentifiers();
 
     boolean isStoresUpperCaseIdentifiers();
-}
 
+    String getQuoteString();
+
+    String quoteIdentifier(String identifier);
+}

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlObjectStore.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlObjectStore.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlObjectStore.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlObjectStore.java Mon Feb 21 14:24:24 2011
@@ -46,367 +46,345 @@ import org.apache.isis.core.runtime.tran
 import org.apache.log4j.Logger;
 
 public final class SqlObjectStore implements ObjectStore {
-	private static final String TABLE_NAME = "no_services";
-	private static final String ID_COLUMN = "id";
-	private static final String PRIMARYKEY_COLUMN = "pk_id";
-	public static final String BASE_NAME = "isis.persistor.sql";
-	private static final Logger LOG = Logger.getLogger(SqlObjectStore.class);
-	private DatabaseConnectorPool connectionPool;
-	private ObjectMappingLookup objectMappingLookup;
-	private boolean isInitialized;
-
-	@Override
-	public void abortTransaction() {
-	}
-
-	@Override
-	public CreateObjectCommand createCreateObjectCommand(
-			final ObjectAdapter object) {
-		return new CreateObjectCommand() {
-			@Override
-			public void execute(final PersistenceCommandContext context) {
-				DatabaseConnector connection = ((SqlExecutionContext) context)
-						.getConnection();
-				LOG.debug("  create object " + object);
-				ObjectMapping mapping = objectMappingLookup.getMapping(object,
-						connection);
-				mapping.createObject(connection, object);
-			}
-
-			@Override
-			public ObjectAdapter onObject() {
-				return object;
-			}
-
-			@Override
-			public String toString() {
-				return "CreateObjectCommand [object=" + object + "]";
-			}
-		};
-	}
-
-	@Override
-	public DestroyObjectCommand createDestroyObjectCommand(
-			final ObjectAdapter object) {
-		return new DestroyObjectCommand() {
-			@Override
-			public void execute(final PersistenceCommandContext context) {
-				DatabaseConnector connection = ((SqlExecutionContext) context)
-						.getConnection();
-				LOG.debug("  destroy object " + object);
-				ObjectMapping mapping = objectMappingLookup.getMapping(object,
-						connection);
-				mapping.destroyObject(connection, object);
-			}
-
-			@Override
-			public ObjectAdapter onObject() {
-				return object;
-			}
-
-			@Override
-			public String toString() {
-				return "DestroyObjectCommand [object=" + object + "]";
-			}
-		};
-	}
-
-	@Override
-	public SaveObjectCommand createSaveObjectCommand(final ObjectAdapter object) {
-		return new SaveObjectCommand() {
-			@Override
-			public void execute(final PersistenceCommandContext context) {
-				DatabaseConnector connection = ((SqlExecutionContext) context)
-						.getConnection();
-				LOG.debug("  save object " + object);
-				if (object.getSpecification().isCollectionOrIsAggregated()) {
-					/*
-					 * ObjectAdapter parent =
-					 * object.getSpecification().getAggregate(object);
-					 * LOG.debug(
-					 * "change to internal collection being persisted through parent"
-					 * );
-					 * 
-					 * // TODO a better plan would be ask the mapper to save the
-					 * collection // - saveCollection(parent, collection)
-					 * mapperLookup.getMapper(connection,
-					 * parent).save(connection, parent);
-					 * connectionPool.release(connection);
-					 */
-					throw new NotYetImplementedException(object.toString());
-				} else {
-					ObjectMapping mapping = objectMappingLookup.getMapping(
-							object, connection);
-					mapping.save(connection, object);
-					connectionPool.release(connection);
-				}
-			}
-
-			@Override
-			public ObjectAdapter onObject() {
-				return object;
-			}
-
-			@Override
-			public String toString() {
-				return "SaveObjectCommand [object=" + object + "]";
-			}
-
-		};
-	}
-
-	@Override
-	public void debugData(final DebugString debug) {
-		debug.appendln("initialised", isInitialized);
-		debug.appendln("connection pool", connectionPool);
-		debug.appendln("Database:");
-		debug.indent();
-		connectionPool.debug(debug);
-		debug.unindent();
-		objectMappingLookup.debugData(debug);
-	}
-
-	@Override
-	public String debugTitle() {
-		return null;
-	}
-
-	@Override
-	public void endTransaction() {
-	}
-
-	@Override
-	public void execute(final List<PersistenceCommand> commands) {
-		DatabaseConnector connector = connectionPool.acquire();
-		connector.begin();
-
-		IsisTransactionManager transactionManager = IsisContext
-				.getTransactionManager();
-		MessageBroker messageBroker = IsisContext.getMessageBroker();
-		UpdateNotifier updateNotifier = IsisContext.getUpdateNotifier();
-		SqlExecutionContext context = new SqlExecutionContext(connector,
-				transactionManager, messageBroker, updateNotifier);
-		try {
-			for (PersistenceCommand command : commands) {
-				command.execute(context);
-			}
-			connector.commit();
-		} catch (IsisException e) {
-			LOG.warn("Failure during execution", e);
-			connector.rollback();
-			throw e;
-		} finally {
-			connectionPool.release(connector);
-		}
-	}
-
-	public boolean flush(final PersistenceCommand[] commands) {
-		return false;
-	}
-
-	@Override
-	public ObjectAdapter[] getInstances(final PersistenceQuery query) {
-		if (query instanceof PersistenceQueryFindByTitle) {
-			return findByTitle((PersistenceQueryFindByTitle) query);
-		} else if (query instanceof PersistenceQueryFindAllInstances) {
-			return getAllInstances((PersistenceQueryFindAllInstances) query);
-		} else if (query instanceof PersistenceQueryFindByPattern) {
-			return findByPattern((PersistenceQueryFindByPattern) query);
-		} else {
-			throw new SqlObjectStoreException("Query type not supported: "
-					+ query);
-		}
-	}
-
-	private ObjectAdapter[] findByPattern(
-			final PersistenceQueryFindByPattern query) {
-		ObjectSpecification specification = query.getSpecification();
-		DatabaseConnector connector = connectionPool.acquire();
-		ObjectMapping mapper = objectMappingLookup.getMapping(specification,
-				connector);
-		ObjectAdapter instances[] = mapper.getInstances(connector,
-				specification, query);
-		connectionPool.release(connector);
-		return instances;
-	}
-
-	private ObjectAdapter[] getAllInstances(
-			final PersistenceQueryFindAllInstances criteria) {
-		ObjectSpecification spec = criteria.getSpecification();
-		return allInstances(spec);
-	}
-
-	private ObjectAdapter[] allInstances(ObjectSpecification spec) {
-		DatabaseConnector connector = connectionPool.acquire();
-		ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
-		ObjectAdapter[] instances = mapper.getInstances(connector, spec);
-		Vector<ObjectAdapter> matchingInstances = new Vector<ObjectAdapter>();
-		for (int i = 0; i < instances.length; i++) {
-			matchingInstances.addElement(instances[i]);
-		}
-		connectionPool.release(connector);
-		ObjectAdapter[] instanceArray = new ObjectAdapter[matchingInstances
-				.size()];
-		matchingInstances.copyInto(instanceArray);
-		return instanceArray;
-	}
-
-	private ObjectAdapter[] findByTitle(
-			final PersistenceQueryFindByTitle criteria) {
-		ObjectSpecification spec = criteria.getSpecification();
-		DatabaseConnector connector = connectionPool.acquire();
-		ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
-
-		ObjectAdapter[] instances = mapper.getInstances(connector, spec,
-				criteria.getTitle());
-		connectionPool.release(connector);
-		return instances;
-	}
-
-	@Override
-	public ObjectAdapter getObject(final Oid oid, final ObjectSpecification hint) {
-		DatabaseConnector connection = connectionPool.acquire();
-		ObjectMapping mapper = objectMappingLookup.getMapping(hint, connection);
-		ObjectAdapter object = mapper.getObject(connection, oid, hint);
-		connectionPool.release(connection);
-		return object;
-	}
-
-	@Override
-	public Oid getOidForService(String name) {
-		DatabaseConnector connector = connectionPool.acquire();
-
-		StringBuffer sql = new StringBuffer();
-		sql.append("select ");
-		sql.append(Sql.identifier(PRIMARYKEY_COLUMN));
-		sql.append(" from ");
-		sql.append(Sql.identifier(TABLE_NAME));
-		sql.append(" where ");
-		sql.append(Sql.identifier(ID_COLUMN));
-		sql.append(" = ?");
-		connector.addToQueryValues(name);
-
-		Results results = connector.select(sql.toString());
-		if (results.next()) {
-			int key = results.getInt(PRIMARYKEY_COLUMN);
-			connectionPool.release(connector);
-			return SqlOid.createPersistent(name, new IntegerPrimaryKey(key));
-		} else {
-			connectionPool.release(connector);
-			return null;
-		}
-	}
-
-	@Override
-	public boolean hasInstances(final ObjectSpecification spec) {
-		DatabaseConnector connection = connectionPool.acquire();
-		ObjectMapping mapper = objectMappingLookup.getMapping(spec, connection);
-		boolean hasInstances = mapper.hasInstances(connection, spec);
-		connectionPool.release(connection);
-		return hasInstances;
-	}
-
-	@Override
-	public boolean isFixturesInstalled() {
-		return isInitialized;
-	}
-
-	@Override
-	public void open() {
-		Sql.setMetaData(connectionPool.acquire().getMetaData());
-
-		DebugString debug = new DebugString();
-		connectionPool.debug(debug);
-		LOG.info("Database: " + debug);
-
-		objectMappingLookup.init();
-
-		DatabaseConnector connector = connectionPool.acquire();
-		isInitialized = connector.hasTable(Sql.identifier(TABLE_NAME));
-		if (!isInitialized) {
-			StringBuffer sql = new StringBuffer();
-			sql.append("create table ");
-			sql.append(Sql.identifier(TABLE_NAME));
-			sql.append(" (");
-			sql.append(Sql.identifier(PRIMARYKEY_COLUMN));
-			sql.append(" int, ");
-			sql.append(Sql.identifier(ID_COLUMN));
-			sql.append(" varchar(255)");
-			sql.append(")");
-			connector.update(sql.toString());
-		}
-	}
-
-	@Override
-	public String name() {
-		return "SQL Object Store";
-	}
-
-	@Override
-	public void registerService(final String name, final Oid oid) {
-		DatabaseConnector connector = connectionPool.acquire();
-
-		StringBuffer sql = new StringBuffer();
-		sql.append("insert into ");
-		sql.append(Sql.identifier(TABLE_NAME));
-		sql.append(" (");
-		sql.append(Sql.identifier(PRIMARYKEY_COLUMN));
-		sql.append(", ");
-		sql.append(Sql.identifier(ID_COLUMN));
-		sql.append(") values (?,?)");
-
-		connector.addToQueryValues(((SqlOid) oid).getPrimaryKey()
-				.naturalValue());
-		connector.addToQueryValues(name);
-
-		connector.insert(sql.toString());
-		connectionPool.release(connector);
-	}
-
-	@Override
-	public void reset() {
-	}
-
-	@Override
-	public void resolveField(final ObjectAdapter object,
-			final ObjectAssociation field) {
-		if (field.isOneToManyAssociation()) {
-			DatabaseConnector connection = connectionPool.acquire();
-			ObjectSpecification spec = object.getSpecification();
-			ObjectMapping mapper = objectMappingLookup.getMapping(spec,
-					connection);
-			mapper.resolveCollection(connection, object, field);
-			connectionPool.release(connection);
-		} else {
-			resolveImmediately(field.get(object));
-		}
-	}
-
-	@Override
-	public void resolveImmediately(final ObjectAdapter object) {
-		DatabaseConnector connector = connectionPool.acquire();
-		ObjectMapping mapping = objectMappingLookup.getMapping(object,
-				connector);
-		mapping.resolve(connector, object);
-		connectionPool.release(connector);
-	}
-
-	public void setConnectionPool(final DatabaseConnectorPool connectionPool) {
-		this.connectionPool = connectionPool;
-	}
-
-	public void setMapperLookup(final ObjectMappingLookup mapperLookup) {
-		this.objectMappingLookup = mapperLookup;
-	}
-
-	@Override
-	public void close() {
-		objectMappingLookup.shutdown();
-		connectionPool.shutdown();
-	}
-
-	@Override
-	public void startTransaction() {
-	}
+    private static final String TABLE_NAME = "isis_admin_services";
+    private static final String ID_COLUMN = "id";
+    private static final String PRIMARYKEY_COLUMN = "pk_id";
+    public static final String BASE_NAME = "isis.persistor.sql";
+    private static final Logger LOG = Logger.getLogger(SqlObjectStore.class);
+    private DatabaseConnectorPool connectionPool;
+    private ObjectMappingLookup objectMappingLookup;
+    private boolean isInitialized;
+
+    @Override
+    public void abortTransaction() {
+    }
+
+    @Override
+    public CreateObjectCommand createCreateObjectCommand(final ObjectAdapter object) {
+        return new CreateObjectCommand() {
+            @Override
+            public void execute(final PersistenceCommandContext context) {
+                DatabaseConnector connection = ((SqlExecutionContext) context).getConnection();
+                LOG.debug("  create object " + object);
+                ObjectMapping mapping = objectMappingLookup.getMapping(object, connection);
+                mapping.createObject(connection, object);
+            }
+
+            @Override
+            public ObjectAdapter onObject() {
+                return object;
+            }
+
+            @Override
+            public String toString() {
+                return "CreateObjectCommand [object=" + object + "]";
+            }
+        };
+    }
+
+    @Override
+    public DestroyObjectCommand createDestroyObjectCommand(final ObjectAdapter object) {
+        return new DestroyObjectCommand() {
+            @Override
+            public void execute(final PersistenceCommandContext context) {
+                DatabaseConnector connection = ((SqlExecutionContext) context).getConnection();
+                LOG.debug("  destroy object " + object);
+                ObjectMapping mapping = objectMappingLookup.getMapping(object, connection);
+                mapping.destroyObject(connection, object);
+            }
+
+            @Override
+            public ObjectAdapter onObject() {
+                return object;
+            }
+
+            @Override
+            public String toString() {
+                return "DestroyObjectCommand [object=" + object + "]";
+            }
+        };
+    }
+
+    @Override
+    public SaveObjectCommand createSaveObjectCommand(final ObjectAdapter object) {
+        return new SaveObjectCommand() {
+            @Override
+            public void execute(final PersistenceCommandContext context) {
+                DatabaseConnector connection = ((SqlExecutionContext) context).getConnection();
+                LOG.debug("  save object " + object);
+                if (object.getSpecification().isCollectionOrIsAggregated()) {
+                    /*
+                     * ObjectAdapter parent = object.getSpecification().getAggregate(object); LOG.debug(
+                     * "change to internal collection being persisted through parent" );
+                     * 
+                     * // TODO a better plan would be ask the mapper to save the collection // - saveCollection(parent,
+                     * collection) mapperLookup.getMapper(connection, parent).save(connection, parent);
+                     * connectionPool.release(connection);
+                     */
+                    throw new NotYetImplementedException(object.toString());
+                } else {
+                    ObjectMapping mapping = objectMappingLookup.getMapping(object, connection);
+                    mapping.save(connection, object);
+                    connectionPool.release(connection);
+                }
+            }
+
+            @Override
+            public ObjectAdapter onObject() {
+                return object;
+            }
+
+            @Override
+            public String toString() {
+                return "SaveObjectCommand [object=" + object + "]";
+            }
+
+        };
+    }
+
+    @Override
+    public void debugData(final DebugString debug) {
+        debug.appendln("initialised", isInitialized);
+        debug.appendln("connection pool", connectionPool);
+        debug.appendln("Database:");
+        debug.indent();
+        connectionPool.debug(debug);
+        debug.unindent();
+        objectMappingLookup.debugData(debug);
+    }
+
+    @Override
+    public String debugTitle() {
+        return null;
+    }
+
+    @Override
+    public void endTransaction() {
+    }
+
+    @Override
+    public void execute(final List<PersistenceCommand> commands) {
+        DatabaseConnector connector = connectionPool.acquire();
+        connector.begin();
+
+        IsisTransactionManager transactionManager = IsisContext.getTransactionManager();
+        MessageBroker messageBroker = IsisContext.getMessageBroker();
+        UpdateNotifier updateNotifier = IsisContext.getUpdateNotifier();
+        SqlExecutionContext context =
+            new SqlExecutionContext(connector, transactionManager, messageBroker, updateNotifier);
+        try {
+            for (PersistenceCommand command : commands) {
+                command.execute(context);
+            }
+            connector.commit();
+        } catch (IsisException e) {
+            LOG.warn("Failure during execution", e);
+            connector.rollback();
+            throw e;
+        } finally {
+            connectionPool.release(connector);
+        }
+    }
+
+    public boolean flush(final PersistenceCommand[] commands) {
+        return false;
+    }
+
+    @Override
+    public ObjectAdapter[] getInstances(final PersistenceQuery query) {
+        if (query instanceof PersistenceQueryFindByTitle) {
+            return findByTitle((PersistenceQueryFindByTitle) query);
+        } else if (query instanceof PersistenceQueryFindAllInstances) {
+            return getAllInstances((PersistenceQueryFindAllInstances) query);
+        } else if (query instanceof PersistenceQueryFindByPattern) {
+            return findByPattern((PersistenceQueryFindByPattern) query);
+        } else {
+            throw new SqlObjectStoreException("Query type not supported: " + query);
+        }
+    }
+
+    private ObjectAdapter[] findByPattern(final PersistenceQueryFindByPattern query) {
+        ObjectSpecification specification = query.getSpecification();
+        DatabaseConnector connector = connectionPool.acquire();
+        ObjectMapping mapper = objectMappingLookup.getMapping(specification, connector);
+        ObjectAdapter instances[] = mapper.getInstances(connector, specification, query);
+        connectionPool.release(connector);
+        return instances;
+    }
+
+    private ObjectAdapter[] getAllInstances(final PersistenceQueryFindAllInstances criteria) {
+        ObjectSpecification spec = criteria.getSpecification();
+        return allInstances(spec);
+    }
+
+    private ObjectAdapter[] allInstances(ObjectSpecification spec) {
+        DatabaseConnector connector = connectionPool.acquire();
+        ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
+        ObjectAdapter[] instances = mapper.getInstances(connector, spec);
+        Vector<ObjectAdapter> matchingInstances = new Vector<ObjectAdapter>();
+        for (int i = 0; i < instances.length; i++) {
+            matchingInstances.addElement(instances[i]);
+        }
+        connectionPool.release(connector);
+        ObjectAdapter[] instanceArray = new ObjectAdapter[matchingInstances.size()];
+        matchingInstances.copyInto(instanceArray);
+        return instanceArray;
+    }
+
+    private ObjectAdapter[] findByTitle(final PersistenceQueryFindByTitle criteria) {
+        ObjectSpecification spec = criteria.getSpecification();
+        DatabaseConnector connector = connectionPool.acquire();
+        ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
+
+        ObjectAdapter[] instances = mapper.getInstances(connector, spec, criteria.getTitle());
+        connectionPool.release(connector);
+        return instances;
+    }
+
+    @Override
+    public ObjectAdapter getObject(final Oid oid, final ObjectSpecification hint) {
+        DatabaseConnector connection = connectionPool.acquire();
+        ObjectMapping mapper = objectMappingLookup.getMapping(hint, connection);
+        ObjectAdapter object = mapper.getObject(connection, oid, hint);
+        connectionPool.release(connection);
+        return object;
+    }
+
+    @Override
+    public Oid getOidForService(String name) {
+        DatabaseConnector connector = connectionPool.acquire();
+
+        StringBuffer sql = new StringBuffer();
+        sql.append("select ");
+        sql.append(Sql.identifier(PRIMARYKEY_COLUMN));
+        sql.append(" from ");
+        sql.append(Sql.tableIdentifier(TABLE_NAME));
+        sql.append(" where ");
+        sql.append(Sql.identifier(ID_COLUMN));
+        sql.append(" = ?");
+        connector.addToQueryValues(name);
+
+        Results results = connector.select(sql.toString());
+        if (results.next()) {
+            int key = results.getInt(PRIMARYKEY_COLUMN);
+            connectionPool.release(connector);
+            return SqlOid.createPersistent(name, new IntegerPrimaryKey(key));
+        } else {
+            connectionPool.release(connector);
+            return null;
+        }
+    }
+
+    @Override
+    public boolean hasInstances(final ObjectSpecification spec) {
+        DatabaseConnector connection = connectionPool.acquire();
+        ObjectMapping mapper = objectMappingLookup.getMapping(spec, connection);
+        boolean hasInstances = mapper.hasInstances(connection, spec);
+        connectionPool.release(connection);
+        return hasInstances;
+    }
+
+    @Override
+    public boolean isFixturesInstalled() {
+        return isInitialized;
+    }
+
+    @Override
+    public void open() {
+        Sql.setMetaData(connectionPool.acquire().getMetaData());
+
+        DebugString debug = new DebugString();
+        connectionPool.debug(debug);
+        LOG.info("Database: " + debug);
+
+        objectMappingLookup.init();
+
+        DatabaseConnector connector = connectionPool.acquire();
+        isInitialized = connector.hasTable(Sql.tableIdentifier(TABLE_NAME));
+        if (!isInitialized) {
+            StringBuffer sql = new StringBuffer();
+            sql.append("create table ");
+            sql.append(Sql.tableIdentifier(TABLE_NAME));
+            sql.append(" (");
+            sql.append(Sql.identifier(PRIMARYKEY_COLUMN));
+            sql.append(" int, ");
+            sql.append(Sql.identifier(ID_COLUMN));
+            sql.append(" varchar(255)");
+            sql.append(")");
+            connector.update(sql.toString());
+        }
+    }
+
+    @Override
+    public String name() {
+        return "SQL Object Store";
+    }
+
+    @Override
+    public void registerService(final String name, final Oid oid) {
+        DatabaseConnector connector = connectionPool.acquire();
+
+        StringBuffer sql = new StringBuffer();
+        sql.append("insert into ");
+        sql.append(Sql.tableIdentifier(TABLE_NAME));
+        sql.append(" (");
+        sql.append(Sql.identifier(PRIMARYKEY_COLUMN));
+        sql.append(", ");
+        sql.append(Sql.identifier(ID_COLUMN));
+        sql.append(") values (?,?)");
+
+        connector.addToQueryValues(((SqlOid) oid).getPrimaryKey().naturalValue());
+        connector.addToQueryValues(name);
+
+        connector.insert(sql.toString());
+        connectionPool.release(connector);
+    }
+
+    @Override
+    public void reset() {
+    }
+
+    @Override
+    public void resolveField(final ObjectAdapter object, final ObjectAssociation field) {
+        if (field.isOneToManyAssociation()) {
+            DatabaseConnector connection = connectionPool.acquire();
+            ObjectSpecification spec = object.getSpecification();
+            ObjectMapping mapper = objectMappingLookup.getMapping(spec, connection);
+            mapper.resolveCollection(connection, object, field);
+            connectionPool.release(connection);
+        } else {
+            resolveImmediately(field.get(object));
+        }
+    }
+
+    @Override
+    public void resolveImmediately(final ObjectAdapter object) {
+        DatabaseConnector connector = connectionPool.acquire();
+        ObjectMapping mapping = objectMappingLookup.getMapping(object, connector);
+        mapping.resolve(connector, object);
+        connectionPool.release(connector);
+    }
+
+    public void setConnectionPool(final DatabaseConnectorPool connectionPool) {
+        this.connectionPool = connectionPool;
+    }
+
+    public void setMapperLookup(final ObjectMappingLookup mapperLookup) {
+        this.objectMappingLookup = mapperLookup;
+    }
+
+    @Override
+    public void close() {
+        objectMappingLookup.shutdown();
+        connectionPool.shutdown();
+    }
+
+    @Override
+    public void startTransaction() {
+    }
+    
+    public static String getTableName(){
+        return TABLE_NAME;
+    }
 
 }

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlOidGenerator.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlOidGenerator.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlOidGenerator.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/SqlOidGenerator.java Mon Feb 21 14:24:24 2011
@@ -27,117 +27,107 @@ import org.apache.isis.core.runtime.tran
 import org.apache.log4j.Logger;
 
 public class SqlOidGenerator extends OidGeneratorAbstract {
-	private static final Logger LOG = Logger.getLogger(SqlOidGenerator.class);
+    private static final Logger LOG = Logger.getLogger(SqlOidGenerator.class);
 
-	private static class IdNumbers {
-		private static final String NUMBER_COLUMN = "number";
-		private static final String TABLE_NAME = "no_serial_id";
-		private static int BATCH_SIZE = 50;
-		private long transientNumber = -9999999;
-		private long lastId = 0;
-		private long newBatchAt = 0;
-
-		public synchronized long nextTransientId() {
-			return transientNumber++;
-		}
-
-		public synchronized long nextPersistentId(
-				DatabaseConnectorPool connectionPool) {
-			if (lastId > newBatchAt) {
-				throw new SqlObjectStoreException("ID exception, last id ("
-						+ lastId + ") past new batch boundary (" + newBatchAt
-						+ ")");
-			}
-			if (lastId == newBatchAt) {
-				prepareNewBatch(connectionPool);
-			}
-			lastId++;
-			return lastId;
-		}
-
-		private void prepareNewBatch(DatabaseConnectorPool connectionPool) {
-			DatabaseConnector db = connectionPool.acquire();
-			try {
-				String tableName = Sql.identifier(TABLE_NAME);
-				String numberColumn = Sql.identifier(NUMBER_COLUMN);
-				if (!db.hasTable(tableName)) {
-					lastId = 1;
-					newBatchAt = BATCH_SIZE;
-					db.update("create table " + tableName + " (" + numberColumn
-							+ " INTEGER)");
-					db.update("insert into " + tableName + " values ("
-							+ newBatchAt + ")");
-					LOG.debug("Initial ID batch created, from " + lastId
-							+ " to " + newBatchAt);
-				} else {
-					if (db.update("update " + tableName + " set "
-							+ numberColumn + " = " + numberColumn + " + "
-							+ BATCH_SIZE) != 1) {
-						throw new SqlObjectStoreException(
-								"failed to update serial id table; no rows updated");
-					}
-					Results rs = db.select("select " + numberColumn + " from "
-							+ tableName);
-					rs.next();
-					newBatchAt = rs.getLong(numberColumn);
-					lastId = newBatchAt - BATCH_SIZE;
-					LOG.debug("New ID batch created, from " + lastId + " to "
-							+ newBatchAt);
-					rs.close();
-				}
-			} catch (ObjectPersistenceException e) {
-				throw e;
-			} finally {
-				connectionPool.release(db);
-			}
-		}
-
-		public void debugData(DebugString debug) {
-			debug.appendln("id", lastId);
-			debug.appendln("transient id", transientNumber);
-		}
-
-	}
-
-	private final DatabaseConnectorPool connectionPool;
-	private final IdNumbers ids = new IdNumbers();
-
-	public SqlOidGenerator(final DatabaseConnectorPool connectionPool) {
-		this.connectionPool = connectionPool;
-	}
-
-	public String name() {
-		return "Sql Oids";
-	}
-
-	@Override
-	public SqlOid createTransientOid(final Object object) {
-		String className = object.getClass().getName();
-		return SqlOid.createTransient(className, ids.nextTransientId());
-	}
-
-	@Override
-	public void convertTransientToPersistentOid(final Oid oid) {
-		Assert.assertNotNull("No connection set up", connectionPool);
-		IntegerPrimaryKey primaryKey = new IntegerPrimaryKey(
-				(int) ids.nextPersistentId(connectionPool));
-		((SqlOid) oid).setId(primaryKey);
-		((SqlOid) oid).makePersistent();
-	}
-
-	public void convertPersistentToTransientOid(final Oid oid) {
-	}
-
-	@Override
-	public void debugData(final DebugString debug) {
-		debug.appendln(this.toString());
-		debug.indent();
-		ids.debugData(debug);
-		debug.unindent();
-	}
-
-	@Override
-	public String debugTitle() {
-		return "SQL OID Generator";
-	}
+    private static class IdNumbers {
+        private static final String NUMBER_COLUMN = "number";
+        private static final String TABLE_NAME = "isis_admin_serial_id";
+        private static int BATCH_SIZE = 50;
+        private long transientNumber = -9999999;
+        private long lastId = 0;
+        private long newBatchAt = 0;
+
+        public synchronized long nextTransientId() {
+            return transientNumber++;
+        }
+
+        public synchronized long nextPersistentId(DatabaseConnectorPool connectionPool) {
+            if (lastId > newBatchAt) {
+                throw new SqlObjectStoreException("ID exception, last id (" + lastId + ") past new batch boundary ("
+                    + newBatchAt + ")");
+            }
+            if (lastId == newBatchAt) {
+                prepareNewBatch(connectionPool);
+            }
+            lastId++;
+            return lastId;
+        }
+
+        private void prepareNewBatch(DatabaseConnectorPool connectionPool) {
+            DatabaseConnector db = connectionPool.acquire();
+            try {
+                String tableName = Sql.tableIdentifier(TABLE_NAME);
+                String numberColumn = Sql.identifier(NUMBER_COLUMN);
+                if (!db.hasTable(tableName)) {
+                    lastId = 1;
+                    newBatchAt = BATCH_SIZE;
+                    db.update("create table " + tableName + " (" + numberColumn + " INTEGER)");
+                    db.update("insert into " + tableName + " values (" + newBatchAt + ")");
+                    LOG.debug("Initial ID batch created, from " + lastId + " to " + newBatchAt);
+                } else {
+                    if (db.update("update " + tableName + " set " + numberColumn + " = " + numberColumn + " + "
+                        + BATCH_SIZE) != 1) {
+                        throw new SqlObjectStoreException("failed to update serial id table; no rows updated");
+                    }
+                    Results rs = db.select("select " + numberColumn + " from " + tableName);
+                    rs.next();
+                    newBatchAt = rs.getLong(NUMBER_COLUMN); // TODO here
+                    lastId = newBatchAt - BATCH_SIZE;
+                    LOG.debug("New ID batch created, from " + lastId + " to " + newBatchAt);
+                    rs.close();
+                }
+            } catch (ObjectPersistenceException e) {
+                throw e;
+            } finally {
+                connectionPool.release(db);
+            }
+        }
+
+        public void debugData(DebugString debug) {
+            debug.appendln("id", lastId);
+            debug.appendln("transient id", transientNumber);
+        }
+
+    }
+
+    private final DatabaseConnectorPool connectionPool;
+    private final IdNumbers ids = new IdNumbers();
+
+    public SqlOidGenerator(final DatabaseConnectorPool connectionPool) {
+        this.connectionPool = connectionPool;
+    }
+
+    public String name() {
+        return "Sql Oids";
+    }
+
+    @Override
+    public SqlOid createTransientOid(final Object object) {
+        String className = object.getClass().getName();
+        return SqlOid.createTransient(className, ids.nextTransientId());
+    }
+
+    @Override
+    public void convertTransientToPersistentOid(final Oid oid) {
+        Assert.assertNotNull("No connection set up", connectionPool);
+        IntegerPrimaryKey primaryKey = new IntegerPrimaryKey((int) ids.nextPersistentId(connectionPool));
+        ((SqlOid) oid).setId(primaryKey);
+        ((SqlOid) oid).makePersistent();
+    }
+
+    public void convertPersistentToTransientOid(final Oid oid) {
+    }
+
+    @Override
+    public void debugData(final DebugString debug) {
+        debug.appendln(this.toString());
+        debug.indent();
+        ids.debugData(debug);
+        debug.unindent();
+    }
+
+    @Override
+    public String debugTitle() {
+        return "SQL OID Generator";
+    }
 }

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/VersionMapping.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/VersionMapping.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/VersionMapping.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/VersionMapping.java Mon Feb 21 14:24:24 2011
@@ -26,84 +26,79 @@ import org.apache.isis.core.metamodel.ad
 import org.apache.isis.core.metamodel.adapter.version.Version;
 
 public class VersionMapping {
-	private String lastActivityDateColumn;
-	private String lastActivityUserColumn;
-	private String versionColumn;
-
-	public void init() {
-		lastActivityDateColumn = Sql.identifier("MODIFIED_ON");
-		lastActivityUserColumn = Sql.identifier("MODIFIED_BY");
-		versionColumn = Sql.identifier("VERSION");
-	}
-
-	public String insertColumns() {
-		return versionColumn + ", " + lastActivityUserColumn + ", "
-				+ lastActivityDateColumn;
-	}
-
-	// TODO:KAM: here
-	public String insertValues(DatabaseConnector connector,
-			SerialNumberVersion version) {
-		connector.addToQueryValues(version.getSequence());
-		String user = version.getUser();
-		if (user == ""){
-			user = "unknown";
-		}
-		connector.addToQueryValues(user);
-		connector.addToQueryValues(new Timestamp(new Date().getTime()));
-		return "?,?,?";
-	}
-
-	public String whereClause(DatabaseConnector connector,
-			SerialNumberVersion version) {
-		connector.addToQueryValues(version.getSequence());
-		return versionColumn + " = ?";
-	}
-
-	public String updateAssigment(DatabaseConnector connector, long nextSequence) {
-		connector.addToQueryValues(nextSequence);
-		return versionColumn + " = ?";
-	}
-
-	public String appendSelectColumns() {
-		StringBuffer sql = new StringBuffer();
-		sql.append(versionColumn);
-		sql.append(",");
-		sql.append(lastActivityUserColumn);
-		sql.append(",");
-		sql.append(lastActivityDateColumn);
-		return sql.toString();
-	}
-
-	public String appendColumnDefinitions() {
-		StringBuffer sql = new StringBuffer();
-
-		sql.append(versionColumn);
-		sql.append(" bigint");
-
-		sql.append(",");
-		sql.append(lastActivityUserColumn);
-		sql.append(" varchar(32)");
-
-		sql.append(",");
-		sql.append(lastActivityDateColumn);
-		sql.append(" timestamp");
-
-		return sql.toString();
-	}
-
-	public Object appendUpdateValues(DatabaseConnector connector,
-			long versionSequence) {
-		connector.addToQueryValues(versionSequence);
-		return versionColumn + "= ?";
-	}
-
-	public Version getLock(Results rs) {
-		long number = rs.getLong(versionColumn);
-		String user = rs.getString(lastActivityUserColumn);
-		Date time = rs.getDate(lastActivityDateColumn);
-		Version version = new SerialNumberVersion(number, user, time);
-		return version;
-	}
+    private String lastActivityDateColumn;
+    private String lastActivityUserColumn;
+    private String versionColumn;
+
+    public void init() {
+        lastActivityDateColumn = Sql.identifier("MODIFIED_ON");
+        lastActivityUserColumn = Sql.identifier("MODIFIED_BY");
+        versionColumn = Sql.identifier("VERSION");
+    }
+
+    public String insertColumns() {
+        return versionColumn + ", " + lastActivityUserColumn + ", " + lastActivityDateColumn;
+    }
+
+    public String insertValues(DatabaseConnector connector, SerialNumberVersion version) {
+        connector.addToQueryValues(version.getSequence());
+        String user = version.getUser();
+        if (user == "") {
+            user = "unknown";
+        }
+        connector.addToQueryValues(user);
+        connector.addToQueryValues(new Timestamp(new Date().getTime()));
+        return "?,?,?";
+    }
+
+    public String whereClause(DatabaseConnector connector, SerialNumberVersion version) {
+        connector.addToQueryValues(version.getSequence());
+        return versionColumn + " = ?";
+    }
+
+    public String updateAssigment(DatabaseConnector connector, long nextSequence) {
+        connector.addToQueryValues(nextSequence);
+        return versionColumn + " = ?";
+    }
+
+    public String appendSelectColumns() {
+        StringBuffer sql = new StringBuffer();
+        sql.append(versionColumn);
+        sql.append(",");
+        sql.append(lastActivityUserColumn);
+        sql.append(",");
+        sql.append(lastActivityDateColumn);
+        return sql.toString();
+    }
+
+    public String appendColumnDefinitions() {
+        StringBuffer sql = new StringBuffer();
+
+        sql.append(versionColumn);
+        sql.append(" bigint");
+
+        sql.append(",");
+        sql.append(lastActivityUserColumn);
+        sql.append(" varchar(32)");
+
+        sql.append(",");
+        sql.append(lastActivityDateColumn);
+        sql.append(" datetime");
+
+        return sql.toString();
+    }
+
+    public Object appendUpdateValues(DatabaseConnector connector, long versionSequence) {
+        connector.addToQueryValues(versionSequence);
+        return versionColumn + "= ?";
+    }
+
+    public Version getLock(Results rs) {
+        long number = rs.getLong(versionColumn);
+        String user = rs.getString(lastActivityUserColumn);
+        Date time = rs.getDate(lastActivityDateColumn);
+        Version version = new SerialNumberVersion(number, user, time);
+        return version;
+    }
 
 }

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/AbstractAutoMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/AbstractAutoMapper.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/AbstractAutoMapper.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/AbstractAutoMapper.java Mon Feb 21 14:24:24 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.alternatives.objectstore.sql.auto;
 
 import java.util.ArrayList;
@@ -25,8 +24,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.log4j.Logger;
-
 import org.apache.isis.alternatives.objectstore.sql.AbstractMapper;
 import org.apache.isis.alternatives.objectstore.sql.CollectionMapper;
 import org.apache.isis.alternatives.objectstore.sql.DatabaseConnector;
@@ -43,7 +40,7 @@ import org.apache.isis.core.metamodel.sp
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.core.runtime.context.IsisContext;
 import org.apache.isis.core.runtime.persistence.adaptermanager.AdapterManager;
-
+import org.apache.log4j.Logger;
 
 public abstract class AbstractAutoMapper extends AbstractMapper {
     private static final Logger LOG = Logger.getLogger(AbstractAutoMapper.class);
@@ -54,8 +51,9 @@ public abstract class AbstractAutoMapper
     protected String table;
     protected List<FieldMapping> fieldMappings = new ArrayList<FieldMapping>();
     protected Map<ObjectAssociation, FieldMapping> fieldMappingLookup = new HashMap<ObjectAssociation, FieldMapping>();
-    
-    protected AbstractAutoMapper(final String className, final String parameterBase, FieldMappingLookup lookup, ObjectMappingLookup objectMapperLookup) {
+
+    protected AbstractAutoMapper(final String className, final String parameterBase, FieldMappingLookup lookup,
+        ObjectMappingLookup objectMapperLookup) {
         specification = IsisContext.getSpecificationLoader().loadSpecification(className);
         if (specification.getProperties() == null || specification.getProperties().size() == 0) {
             throw new SqlObjectStoreException(specification.getFullIdentifier() + " has no fields: " + specification);
@@ -63,11 +61,12 @@ public abstract class AbstractAutoMapper
         setUpFieldMappers(lookup, objectMapperLookup, className, parameterBase);
     }
 
-    private void setUpFieldMappers(FieldMappingLookup lookup, ObjectMappingLookup objectMapperLookup, final String className, final String parameterBase) {
+    private void setUpFieldMappers(FieldMappingLookup lookup, ObjectMappingLookup objectMapperLookup,
+        final String className, final String parameterBase) {
         IsisConfiguration configParameters = IsisContext.getConfiguration();
         table = configParameters.getString(parameterBase + "table");
         if (table == null) {
-            String name = className.substring(className.lastIndexOf('.') + 1).toUpperCase();
+            String name = "isis_" + className.substring(className.lastIndexOf('.') + 1).toUpperCase();
             table = Sql.sqlName(name);
         }
 
@@ -75,20 +74,16 @@ public abstract class AbstractAutoMapper
         if (configParameters.getBoolean(parameterBase + "all-fields", true)) {
             setupFullMapping(lookup, objectMapperLookup, className, configParameters, parameterBase);
         } else {
-   //         setupSpecifiedMapping(specification, configParameters, parameterBase);
+            // setupSpecifiedMapping(specification, configParameters, parameterBase);
         }
-        
-        table = Sql.identifier(table);
+
+        table = Sql.tableIdentifier(table);
 
         LOG.info("table mapping: " + table + " (" + columnList() + ")");
     }
 
-    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) {
         List<? extends ObjectAssociation> fields = specification.getAssociations();
 
         int simpleFieldCount = 0;
@@ -121,10 +116,14 @@ public abstract class AbstractAutoMapper
                 // default CollectionMapper
                 String type = subset.getString(field.getId());
                 if (type == null || type.equals("association-table")) {
-//                    collectionMappers[collectionFieldNo] = new AutoCollectionMapper(specification,
-//                            oneToManyProperties[collectionFieldNo], lookup);
-                    //collectionMappers[collectionFieldNo] = new CombinedCollectionMapper(oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup);
-                    collectionMappers[collectionFieldNo] = new MultiColumnCombinedCollectionMapper(oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup);
+                    // collectionMappers[collectionFieldNo] = new AutoCollectionMapper(specification,
+                    // oneToManyProperties[collectionFieldNo], lookup);
+                    // collectionMappers[collectionFieldNo] = new
+                    // CombinedCollectionMapper(oneToManyProperties[collectionFieldNo], parameterBase, lookup,
+                    // objectMapperLookup);
+                    collectionMappers[collectionFieldNo] =
+                        new MultiColumnCombinedCollectionMapper(oneToManyProperties[collectionFieldNo], parameterBase,
+                            lookup, objectMapperLookup);
 
                 } else if (type.equals("fk-table")) {
                     String property = parameterBase + field.getId() + ".element-type";
@@ -133,9 +132,9 @@ public abstract class AbstractAutoMapper
                         throw new SqlObjectStoreException("Expected property " + property);
                     }
                     /*
-                    collectionMappers[collectionFieldNo] = new CombinedCollectionMapper(elementType,
-                            oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup);
-*/
+                     * collectionMappers[collectionFieldNo] = new CombinedCollectionMapper(elementType,
+                     * oneToManyProperties[collectionFieldNo], parameterBase, lookup, objectMapperLookup);
+                     */
                 } else {
                     // TODO use other mappers where necessary
                     throw new NotYetImplementedException("for " + type);
@@ -159,48 +158,32 @@ public abstract class AbstractAutoMapper
         }
 
     }
-/*
-    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;
-        }
-
-        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);
-
-            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();
-            }
-        }
-    }
-*/
+    /*
+     * 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; }
+     * 
+     * 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);
+     * 
+     * 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(); } } }
+     */
     protected String columnList() {
         StringBuffer sql = new StringBuffer();
         for (FieldMapping mapping : fieldMappings) {
@@ -239,7 +222,7 @@ public abstract class AbstractAutoMapper
     @Override
     public String toString() {
         return "AbstractAutoMapper [table=" + table + ",noColumns=" + fieldMappings.size() + ",specification="
-                + specification.getFullIdentifier() + "]";
+            + specification.getFullIdentifier() + "]";
     }
 
     protected String values(DatabaseConnector connector, final ObjectAdapter object) {

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/CombinedCollectionMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/CombinedCollectionMapper.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/CombinedCollectionMapper.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/auto/CombinedCollectionMapper.java Mon Feb 21 14:24:24 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.alternatives.objectstore.sql.auto;
 
 import java.util.ArrayList;
@@ -48,65 +47,68 @@ public class CombinedCollectionMapper ex
     private final ObjectAssociation field;
     private final IdMapping idMapping;
     private final VersionMapping versionMapping;
-    private ObjectReferenceMapping foreignKeyMapping;
+    private final ObjectReferenceMapping foreignKeyMapping;
     private String foreignKeyName;
     private String columnName;
-    private ObjectMapping originalMapping;
+    private final ObjectMapping originalMapping;
     private final ObjectMappingLookup objectMapperLookup2;
 
-	public CombinedCollectionMapper(
-            ObjectAssociation objectAssociation,
-            String parameterBase,
-            FieldMappingLookup lookup, 
-            ObjectMappingLookup objectMapperLookup) {
+    public CombinedCollectionMapper(ObjectAssociation objectAssociation, String parameterBase,
+        FieldMappingLookup lookup, ObjectMappingLookup objectMapperLookup) {
         super(objectAssociation.getSpecification().getFullIdentifier(), parameterBase, lookup, objectMapperLookup);
         this.field = objectAssociation;
-		
+
         objectMapperLookup2 = objectMapperLookup;
-        
+
         idMapping = lookup.createIdMapping();
         versionMapping = lookup.createVersionMapping();
 
         originalMapping = objectMapperLookup.getMapping(objectAssociation.getSpecification(), null);
-        
+
         setColumnName(determineColumnName(objectAssociation));
-    	foreignKeyName = Sql.sqlName("fk_" + getColumnName());
-        
+        foreignKeyName = Sql.sqlName("fk_" + getColumnName());
+
         foreignKeyName = Sql.identifier(foreignKeyName);
-        foreignKeyMapping = lookup.createMapping(columnName, objectAssociation.getSpecification()); 
+        foreignKeyMapping = lookup.createMapping(columnName, objectAssociation.getSpecification());
+    }
+
+    protected String determineColumnName(ObjectAssociation objectAssociation) {
+        return objectAssociation.getSpecification().getShortIdentifier();
     }
 
-	protected String determineColumnName(ObjectAssociation objectAssociation){
-    	return  objectAssociation.getSpecification().getShortIdentifier();
-	}
-	
     public String getColumnName() {
-		return columnName;
-	}
-	public void setColumnName(String columnName) {
-		this.columnName = columnName;
-	}
-    
+        return columnName;
+    }
+
+    public void setColumnName(String columnName) {
+        this.columnName = columnName;
+    }
+
+    @Override
     public boolean needsTables(DatabaseConnector connection) {
         return !connection.hasColumn(table, foreignKeyName);
     }
 
+    @Override
     public void startup(DatabaseConnector connector, FieldMappingLookup lookup) {
         originalMapping.startup(connector, objectMapperLookup2);
         super.startup(connector, lookup);
     }
-    
+
+    @Override
     public void createTables(DatabaseConnector connection) {
         StringBuffer sql = new StringBuffer();
         sql.append("alter table ");
         sql.append(table);
-        sql.append(" add column ");
-        foreignKeyMapping.appendColumnDefinitions(sql); 
+        // TODO MSSQL chokes: sql.append(" add column ");
+        sql.append(" add ");
+        foreignKeyMapping.appendColumnDefinitions(sql);
         connection.update(sql.toString());
     }
 
+    @Override
     public void loadInternalCollection(DatabaseConnector connector, ObjectAdapter parent) {
-        ObjectAdapter collection = (ObjectAdapter) field.get(parent);
+        ObjectAdapter collection = field.get(parent);
         if (collection.getResolveState().canChangeTo(ResolveState.RESOLVING)) {
             LOG.debug("loading internal collection " + field);
             PersistorUtil.start(collection, ResolveState.RESOLVING);
@@ -114,23 +116,23 @@ public class CombinedCollectionMapper ex
             StringBuffer sql = new StringBuffer();
             sql.append("select ");
             idMapping.appendColumnNames(sql);
-            
+
             sql.append(", ");
             String columnList = columnList();
-            if (columnList.length() > 0){
-            	sql.append(columnList);
-            	sql.append(", ");
+            if (columnList.length() > 0) {
+                sql.append(columnList);
+                sql.append(", ");
             }
             sql.append(versionMapping.appendSelectColumns());
             sql.append(" from ");
             sql.append(table);
             sql.append(" where ");
             foreignKeyMapping.appendUpdateValues(connector, sql, parent);
-            
+
             Results rs = connector.select(sql.toString());
             List<ObjectAdapter> list = new ArrayList<ObjectAdapter>();
             while (rs.next()) {
-                Oid oid = idMapping.recreateOid(rs,  specification);
+                Oid oid = idMapping.recreateOid(rs, specification);
                 ObjectAdapter element = getAdapter(specification, oid);
                 loadFields(element, rs);
                 LOG.debug("  element  " + element.getOid());
@@ -143,11 +145,10 @@ public class CombinedCollectionMapper ex
         }
     }
 
-    
     protected void loadFields(final ObjectAdapter object, final Results rs) {
         if (object.getResolveState().canChangeTo(ResolveState.RESOLVING)) {
             PersistorUtil.start(object, ResolveState.RESOLVING);
-            for (FieldMapping mapping  : fieldMappings) {
+            for (FieldMapping mapping : fieldMappings) {
                 mapping.initializeField(object, rs);
             }
             object.setOptimisticLock(versionMapping.getLock(rs));
@@ -155,10 +156,11 @@ public class CombinedCollectionMapper ex
         }
     }
 
+    @Override
     public void saveInternalCollection(DatabaseConnector connector, ObjectAdapter parent) {
         ObjectAdapter collection = field.get(parent);
         LOG.debug("Saving internal collection " + collection);
-        
+
         StringBuffer sql = new StringBuffer();
         sql.append("update ");
         sql.append(table);
@@ -166,13 +168,13 @@ public class CombinedCollectionMapper ex
         sql.append(foreignKeyName);
         sql.append(" = NULL where ");
         foreignKeyMapping.appendUpdateValues(connector, sql, parent);
-        connector.update(sql.toString()); 
-         
+        connector.update(sql.toString());
+
         sql = new StringBuffer();
         sql.append("update ");
         sql.append(table);
         sql.append(" set ");
-        
+
         CollectionFacet collectionFacet = collection.getSpecification().getFacet(CollectionFacet.class);
         for (ObjectAdapter element : collectionFacet.iterable(collection)) {
             StringBuffer update = new StringBuffer(sql);
@@ -182,7 +184,8 @@ public class CombinedCollectionMapper ex
             connector.insert(update.toString());
         }
     }
-    
+
+    @Override
     public void debugData(DebugString debug) {
         debug.appendln(field.getName(), "collection");
         debug.indent();
@@ -195,5 +198,3 @@ public class CombinedCollectionMapper ex
     }
 
 }
-
-

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcDateTimeMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcDateTimeMapper.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcDateTimeMapper.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcDateTimeMapper.java Mon Feb 21 14:24:24 2011
@@ -72,7 +72,9 @@ public class JdbcDateTimeMapper extends 
     }
     
     public String columnType() {
-    	return "TIMESTAMP";
+        // TODO MS-SQLServer chokes:
+        // return "TIMESTAMP";
+        return "DATETIME";
     }
 
 }

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcSqlMetaData.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcSqlMetaData.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcSqlMetaData.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcSqlMetaData.java Mon Feb 21 14:24:24 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.alternatives.objectstore.sql.jdbc;
 
 import java.sql.DatabaseMetaData;
@@ -25,43 +24,63 @@ import java.sql.SQLException;
 
 import org.apache.isis.alternatives.objectstore.sql.SqlMetaData;
 
-
 public class JdbcSqlMetaData implements SqlMetaData {
 
-    private String keywords;
-    private String timeDateFunctions;
-    private boolean storesLowerCaseIdentifiers;
-    private boolean storesMixedCaseIdentifiers;
-    private boolean storesUpperCaseIdentifiers;
+    private final boolean hasQuoteString;
+    private final String quoteString;
+    private final String keywords;
+    private final String timeDateFunctions;
+    private final boolean storesLowerCaseIdentifiers;
+    private final boolean storesMixedCaseIdentifiers;
+    private final boolean storesUpperCaseIdentifiers;
 
     public JdbcSqlMetaData(DatabaseMetaData metaData) throws SQLException {
         keywords = metaData.getSQLKeywords();
         timeDateFunctions = metaData.getTimeDateFunctions();
+        quoteString = metaData.getIdentifierQuoteString();
+        hasQuoteString = (quoteString != " ");
         storesLowerCaseIdentifiers = metaData.storesLowerCaseIdentifiers();
         storesMixedCaseIdentifiers = metaData.storesMixedCaseIdentifiers();
         storesUpperCaseIdentifiers = metaData.storesUpperCaseIdentifiers();
 
     }
 
+    @Override
     public String getKeywords() {
         return keywords;
     }
 
+    @Override
     public String getTimeDateFunctions() {
         return timeDateFunctions;
     }
 
+    @Override
+    public String getQuoteString() {
+        return quoteString;
+    }
+
+    @Override
     public boolean isStoresLowerCaseIdentifiers() {
         return storesLowerCaseIdentifiers;
     }
 
+    @Override
     public boolean isStoresMixedCaseIdentifiers() {
         return storesMixedCaseIdentifiers;
     }
 
+    @Override
     public boolean isStoresUpperCaseIdentifiers() {
         return storesUpperCaseIdentifiers;
     }
 
+    @Override
+    public String quoteIdentifier(String identifier) {
+        if (hasQuoteString) {
+            return quoteString + identifier + quoteString;
+        } else {
+            return identifier;
+        }
+    }
 }
-

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcTimestampMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcTimestampMapper.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcTimestampMapper.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/main/java/org/apache/isis/alternatives/objectstore/sql/jdbc/JdbcTimestampMapper.java Mon Feb 21 14:24:24 2011
@@ -29,74 +29,67 @@ import org.apache.isis.core.metamodel.sp
 
 public class JdbcTimestampMapper extends AbstractJdbcFieldMapping {
 
-	public static class Factory implements FieldMappingFactory {
-		@Override
-		public FieldMapping createFieldMapping(final ObjectAssociation field) {
-			return new JdbcTimestampMapper(field);
-		}
-	}
-
-	protected JdbcTimestampMapper(ObjectAssociation field) {
-		super(field);
-	}
-
-	// TODO:KAM:here XYZ
-	@Override
-	public String valueAsDBString(final ObjectAdapter value,
-			DatabaseConnector connector) {
-		TimeStamp asDate = (TimeStamp) value.getObject();
-		java.sql.Timestamp xxx = new java.sql.Timestamp(asDate.longValue());
-		connector.addToQueryValues(xxx);
-		return "?";
-		/*
-		 * EncodableFacet encodeableFacet =
-		 * value.getSpecification().getFacet(EncodableFacet.class); String
-		 * encodedString = encodeableFacet.toEncodedString(value); String year =
-		 * encodedString.substring(0, 4); String month =
-		 * encodedString.substring(4, 6); String day =
-		 * encodedString.substring(6, 8); String hour =
-		 * encodedString.substring(8+1, 10+1); String minute =
-		 * encodedString.substring(10+1, 12+1); String second =
-		 * encodedString.substring(12+1, 14+1); String millisecond =
-		 * encodedString.substring(14+1, 17+1); String encodedWithAdaptions =
-		 * year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" +
-		 * second + "." + millisecond; return "'" + encodedWithAdaptions + "'";
-		 */
-	}
-
-	@Override
-	public ObjectAdapter setFromDBColumn(final String encodedValue,
-			final ObjectAssociation field) {
-		// convert date to yyyymmddhhmm
-		String year = encodedValue.substring(0, 4);
-		String month = encodedValue.substring(5, 7);
-		String day = encodedValue.substring(8, 10);
-		String hour = encodedValue.substring(11, 13);
-		String minute = encodedValue.substring(14, 16);
-		String second = encodedValue.substring(17, 19);
-		int length = encodedValue.length();
-		String millisecond;
-		if (length > 20) {
-			millisecond = encodedValue.substring(20, length);
-		} else {
-			millisecond = "";
-		}
-		if (length < 21) {
-			millisecond = millisecond + "000";
-		} else if (length < 22) {
-			millisecond = millisecond + "00";
-		} else if (length < 23) {
-			millisecond = millisecond + "0";
-		}
-		String valueString = year + month + day + "T" + hour + minute + second
-				+ millisecond;
-		return field.getSpecification().getFacet(EncodableFacet.class)
-				.fromEncodedString(valueString);
-	}
-
-	@Override
-	public String columnType() {
-		return "TIMESTAMP";
-	}
+    public static class Factory implements FieldMappingFactory {
+        @Override
+        public FieldMapping createFieldMapping(final ObjectAssociation field) {
+            return new JdbcTimestampMapper(field);
+        }
+    }
+
+    protected JdbcTimestampMapper(ObjectAssociation field) {
+        super(field);
+    }
+
+    // TODO:KAM:here XYZ
+    @Override
+    public String valueAsDBString(final ObjectAdapter value, DatabaseConnector connector) {
+        TimeStamp asDate = (TimeStamp) value.getObject();
+        java.sql.Timestamp xxx = new java.sql.Timestamp(asDate.longValue());
+        connector.addToQueryValues(xxx);
+        return "?";
+        /*
+         * EncodableFacet encodeableFacet = value.getSpecification().getFacet(EncodableFacet.class); String
+         * encodedString = encodeableFacet.toEncodedString(value); String year = encodedString.substring(0, 4); String
+         * month = encodedString.substring(4, 6); String day = encodedString.substring(6, 8); String hour =
+         * encodedString.substring(8+1, 10+1); String minute = encodedString.substring(10+1, 12+1); String second =
+         * encodedString.substring(12+1, 14+1); String millisecond = encodedString.substring(14+1, 17+1); String
+         * encodedWithAdaptions = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "." +
+         * millisecond; return "'" + encodedWithAdaptions + "'";
+         */
+    }
+
+    @Override
+    public ObjectAdapter setFromDBColumn(final String encodedValue, final ObjectAssociation field) {
+        // convert date to yyyymmddhhmm
+        String year = encodedValue.substring(0, 4);
+        String month = encodedValue.substring(5, 7);
+        String day = encodedValue.substring(8, 10);
+        String hour = encodedValue.substring(11, 13);
+        String minute = encodedValue.substring(14, 16);
+        String second = encodedValue.substring(17, 19);
+        int length = encodedValue.length();
+        String millisecond;
+        if (length > 20) {
+            millisecond = encodedValue.substring(20, length);
+        } else {
+            millisecond = "";
+        }
+        if (length < 21) {
+            millisecond = millisecond + "000";
+        } else if (length < 22) {
+            millisecond = millisecond + "00";
+        } else if (length < 23) {
+            millisecond = millisecond + "0";
+        }
+        String valueString = year + month + day + "T" + hour + minute + second + millisecond;
+        return field.getSpecification().getFacet(EncodableFacet.class).fromEncodedString(valueString);
+    }
+
+    @Override
+    public String columnType() {
+        // TODO MS-SQLServer chokes:
+        // return "TIMESTAMP";
+        return "DATETIME";
+    }
 
 }

Modified: incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/test/java/org/apache/isis/alternatives/objectstore/sql/SqlOidTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/test/java/org/apache/isis/alternatives/objectstore/sql/SqlOidTest.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/test/java/org/apache/isis/alternatives/objectstore/sql/SqlOidTest.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/persistor/src/test/java/org/apache/isis/alternatives/objectstore/sql/SqlOidTest.java Mon Feb 21 14:24:24 2011
@@ -30,7 +30,7 @@ import org.apache.isis.alternatives.obje
 public class SqlOidTest extends TestCase {
 
     /*
-     * Test method for 'org.apache.isis.persistence.sql.SqlOid.hashCode()'
+     * Test method for 'org.apache.isis.alternatives.objectstore.sql.SqlOid.hashCode()'
      */
     public void testHashCode() {
         SqlOid oid1 = new SqlOid("className", new IntegerPrimaryKey(13), State.TRANSIENT);
@@ -40,7 +40,7 @@ public class SqlOidTest extends TestCase
     }
 
     /*
-     * Test method for 'org.apache.isis.persistence.sql.SqlOid.copyFrom(Oid)'
+     * Test method for 'org.apache.isis.alternatives.objectstore.sql.SqlOid.copyFrom(Oid)'
      */
     public void testCopyFrom() {
 

Modified: incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/singleton/SqlIntegrationTestSingleton.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/singleton/SqlIntegrationTestSingleton.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/singleton/SqlIntegrationTestSingleton.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/singleton/SqlIntegrationTestSingleton.java Mon Feb 21 14:24:24 2011
@@ -114,7 +114,7 @@ public class SqlIntegrationTestSingleton
                 IsisConfigurationDefault.getString(SqlObjectStore.BASE_NAME + ".jdbc.password"));
 		s = c.createStatement();
 			
-	    dropTable("no_services");
+	    dropTable(SqlObjectStore.getTableName());
 	}
 	private void dropTable(String tableName) {
 		if (s == null){
@@ -122,21 +122,21 @@ public class SqlIntegrationTestSingleton
 				// Delete the xml files..
 			}
 			
-			if (tableName == "sqldataclass"){
+			if (tableName.equalsIgnoreCase("sqldataclass")){
 				List<SqlDataClass> list = sqlDataClassFactory.allDataClasses();
 				for (SqlDataClass sqlDataClass : list) {
 					sqlDataClassFactory.delete(sqlDataClass);
 				}
 				return;
 			}
-			if (tableName == "simpleclass"){
+			if (tableName.equalsIgnoreCase("simpleclass")){
 				List<SimpleClass> list = sqlDataClassFactory.allSimpleClasses();
 				for (SimpleClass sqlClass : list) {
 					sqlDataClassFactory.delete(sqlClass);
 				}
 				return;
 			}
-            if (tableName == "simpleclasstwo"){
+            if (tableName.equalsIgnoreCase("simpleclasstwo")){
                 List<SimpleClassTwo> list = sqlDataClassFactory.allSimpleClassTwos();
                 for (SimpleClassTwo sqlClass : list) {
                     sqlDataClassFactory.delete(sqlClass);

Modified: incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/testsystem/TestProxySystemIII.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/testsystem/TestProxySystemIII.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/testsystem/TestProxySystemIII.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/main/java/org/apache/isis/alternatives/objectstore/sql/testsystem/TestProxySystemIII.java Mon Feb 21 14:24:24 2011
@@ -103,7 +103,6 @@ public class TestProxySystemIII {
 
         if (configuration.getString(SqlObjectStore.BASE_NAME + ".jdbc.driver") == null){
         	if (configuration.getString("isis.persistor") == "in-memory"){
-                /*InMemoryPersistenceMechanismInstaller*/ //persistenceMechanismInstaller = new InMemoryPersistenceMechanismInstaller();
         		persistenceMechanismInstaller = new InMemoryPersistenceMechanismInstaller();
         	} else {
         		persistenceMechanismInstaller = new XmlPersistenceMechanismInstaller();

Modified: incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/test/java/org/apache/isis/alternatives/objectstore/sql/HsqlTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/test/java/org/apache/isis/alternatives/objectstore/sql/HsqlTest.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/test/java/org/apache/isis/alternatives/objectstore/sql/HsqlTest.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/tests-common/src/test/java/org/apache/isis/alternatives/objectstore/sql/HsqlTest.java Mon Feb 21 14:24:24 2011
@@ -58,15 +58,15 @@ public class HsqlTest extends SqlIntegra
 	}
 	
     public String getPersonTableName() {
-        return "SQLDATACLASS";
+        return "ISIS_SQLDATACLASS";
     }
 
     public String getSimpleClassTableName() {
-        return "SIMPLECLASS";
+        return "ISIS_SIMPLECLASS";
     }
 
     public String getSimpleClassTwoTableName() {
-        return "SIMPLECLASSTWO";
+        return "ISIS_SIMPLECLASSTWO";
     }
 	
 }

Modified: incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/MySqlTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/MySqlTest.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/MySqlTest.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/MySqlTest.java Mon Feb 21 14:24:24 2011
@@ -49,6 +49,20 @@ public class MySqlTest extends SqlIntegr
 	
 	public  String getPropertiesFilename(){
 		return "mysql.properties";
-	}
+	}
+
+    public String getPersonTableName() {
+        return "isis_sqldataclass";
+    }
+
+    public String getSimpleClassTableName() {
+        return "isis_simpleclass";
+    }
+
+    public String getSimpleClassTwoTableName() {
+        return "isis_simpleclasstwo";
+    }
+
+	
 }
 

Modified: incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/PostgreSqlTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/PostgreSqlTest.java?rev=1072979&r1=1072978&r2=1072979&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/PostgreSqlTest.java (original)
+++ incubator/isis/trunk/alternatives/objectstore/sql/tests-served/src/test/java/org/apache/isis/alternatives/objectstore/sql/PostgreSqlTest.java Mon Feb 21 14:24:24 2011
@@ -47,6 +47,19 @@ public class PostgreSqlTest extends SqlI
 	
 	public  String getPropertiesFilename(){
 		return "postgresql.properties";
-	}	
+	}	
+	
+    public String getPersonTableName() {
+        return "isis_sqldataclass";
+    }
+
+    public String getSimpleClassTableName() {
+        return "isis_simpleclass";
+    }
+
+    public String getSimpleClassTwoTableName() {
+        return "isis_simpleclasstwo";
+    }
+	
 }
 



Mime
View raw message