incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1301918 - in /incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql: sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/ sql-tests-common/src/test/config/ sql-tests-common/src/test/java/org/apache/isis/runtimes/d...
Date Sat, 17 Mar 2012 10:49:43 GMT
Author: kevin
Date: Sat Mar 17 10:49:42 2012
New Revision: 1301918

URL: http://svn.apache.org/viewvc?rev=1301918&view=rev
Log:
ISIS-217: possible complete SQL transaction support

Modified:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/config/hsql.properties
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/HsqlTest.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.java?rev=1301918&r1=1301917&r2=1301918&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.java
Sat Mar 17 10:49:42 2012
@@ -26,8 +26,8 @@ import org.joda.time.DateTimeZone;
 import org.apache.isis.core.commons.config.IsisConfiguration;
 
 /**
- * Provides objectstore defaults. Most significantly, maintains the object store
- * default TimeZone, and maintains Calendar.
+ * Provides objectstore defaults. Most significantly, maintains the object store default
TimeZone, and maintains
+ * Calendar.
  * 
  * 
  * @version $Rev$ $Date$
@@ -57,6 +57,8 @@ public class Defaults {
         final int isTrue = useVersioningProperty.compareToIgnoreCase("true");
         useVersioning(isTrue == 0);
 
+        defineDatabaseCommands();
+
         final String BASE_DATATYPE = propertiesBase + ".datatypes.";
         final IsisConfiguration dataTypes = isisConfiguration.getProperties(BASE_DATATYPE);
         populateSqlDataTypes(dataTypes, BASE_DATATYPE);
@@ -71,13 +73,14 @@ public class Defaults {
      * @param property
      * @return
      */
-    protected static String getStringProperty(final String propertiesBase, final IsisConfiguration
configParameters, final String property) {
+    protected static String getStringProperty(final String propertiesBase, final IsisConfiguration
configParameters,
+        final String property) {
         return configParameters.getString(propertiesBase + ".default." + property, property);
     }
 
     /**
-     * Returns a string value by looking up "isis.persistor.sql.default.XXXX",
-     * returning the specified default, if no value was found.
+     * Returns a string value by looking up "isis.persistor.sql.default.XXXX", returning
the specified default, if no
+     * value was found.
      * 
      * @param propertiesBase
      * @param configParameters
@@ -85,13 +88,14 @@ public class Defaults {
      * @param defaultValue
      * @return
      */
-    protected static String getStringProperty(final String propertiesBase, final IsisConfiguration
configParameters, final String property, final String defaultValue) {
+    protected static String getStringProperty(final String propertiesBase, final IsisConfiguration
configParameters,
+        final String property, final String defaultValue) {
         return configParameters.getString(propertiesBase + ".default." + property, defaultValue);
     }
 
     /**
-     * Returns an integer value by looking up "isis.persistor.sql.default.XXXX",
-     * returning the specified default, if no value was found.
+     * Returns an integer value by looking up "isis.persistor.sql.default.XXXX", returning
the specified default, if no
+     * value was found.
      * 
      * @param propertiesBase
      * @param configParameters
@@ -99,7 +103,8 @@ public class Defaults {
      * @param defaultValue
      * @return
      */
-    protected static int getIntProperty(final String propertiesBase, final IsisConfiguration
configParameters, final String property, final int defaultValue) {
+    protected static int getIntProperty(final String propertiesBase, final IsisConfiguration
configParameters,
+        final String property, final int defaultValue) {
         return configParameters.getInteger(propertiesBase + ".default." + property, defaultValue);
     }
 
@@ -196,11 +201,9 @@ public class Defaults {
     static String TYPE_DEFAULT;
 
     /**
-     * Default SQL data types used to define the fields in the database. By
-     * providing this method, we allow the user an opportunity to override these
-     * types by specifying alternatives in sql.properties (or which ever). For
-     * example, Postgresql does not know about DATETIME, but can use TIMESTAMP
-     * instead.
+     * Default SQL data types used to define the fields in the database. By providing this
method, we allow the user an
+     * opportunity to override these types by specifying alternatives in sql.properties (or
which ever). For example,
+     * Postgresql does not know about DATETIME, but can use TIMESTAMP instead.
      * 
      * @param dataTypes
      * @param baseName
@@ -300,9 +303,39 @@ public class Defaults {
         if (useVersioning() == false) {
             return false;
         }
-        final String useVersioningProperty = getStringProperty(propertiesBase, isisConfiguration,
"versioning." + shortIdentifier, "true");
+        final String useVersioningProperty =
+            getStringProperty(propertiesBase, isisConfiguration, "versioning." + shortIdentifier,
"true");
         return (useVersioningProperty.compareToIgnoreCase("true") == 0);
     }
+
+    // }}
+
+    // {{ Database commands
+
+    private static String START_TRANSACTION;
+    private static String ABORT_TRANSACTION;
+    private static String COMMIT_TRANSACTION;
+
+    private static void defineDatabaseCommands() {
+        START_TRANSACTION =
+            getStringProperty(propertiesBase, isisConfiguration, "command.beginTransaction",
"START TRANSACTION;");
+        ABORT_TRANSACTION =
+            getStringProperty(propertiesBase, isisConfiguration, "command.abortTransaction",
"ROLLBACK;");
+        COMMIT_TRANSACTION =
+            getStringProperty(propertiesBase, isisConfiguration, "command.commitTransaction",
"COMMIT;");
+    }
+
+    public static String START_TRANSACTION() {
+        return START_TRANSACTION;
+    }
+
+    public static String ABORT_TRANSACTION() {
+        return ABORT_TRANSACTION;
+    }
+
+    public static String COMMIT_TRANSACTION() {
+        return COMMIT_TRANSACTION;
+    }
     // }}
 
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java?rev=1301918&r1=1301917&r2=1301918&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
Sat Mar 17 10:49:42 2012
@@ -139,7 +139,30 @@ public final class SqlObjectStore implem
     }
 
     @Override
+    public void startTransaction() {
+        executeSql(Defaults.START_TRANSACTION());
+    }
+
+    @Override
     public void abortTransaction() {
+        executeSql(Defaults.ABORT_TRANSACTION());
+    }
+
+    @Override
+    public void endTransaction() {
+        executeSql(Defaults.COMMIT_TRANSACTION());
+    }
+
+    private void executeSql(String sql) {
+        final DatabaseConnector connector = connectionPool.acquire();
+        try {
+            connector.begin();
+            connector.update(sql);
+            connector.commit();
+            // connector.close();
+        } finally {
+            connectionPool.release(connector);
+        }
     }
 
     @Override
@@ -271,19 +294,6 @@ public final class SqlObjectStore implem
     }
 
     @Override
-    public void endTransaction() {
-        final DatabaseConnector connector = connectionPool.acquire();
-        try {
-            connector.begin();
-            connector.update("COMMIT;");
-            connector.commit();
-            // connector.close();
-        } finally {
-            connectionPool.release(connector);
-        }
-    }
-
-    @Override
     public void execute(final List<PersistenceCommand> commands) {
         final DatabaseConnector connector = connectionPool.acquire();
         connector.begin();
@@ -335,7 +345,7 @@ public final class SqlObjectStore implem
             final ObjectAdapter[] instanceArray = new ObjectAdapter[matchingInstances.size()];
             matchingInstances.copyInto(instanceArray);
             return instanceArray;
-            
+
         } finally {
             connectionPool.release(connector);
         }
@@ -477,10 +487,6 @@ public final class SqlObjectStore implem
         this.objectMappingLookup = mapperLookup;
     }
 
-    @Override
-    public void startTransaction() {
-    }
-
     public static String getTableName() {
         return TABLE_NAME;
     }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/config/hsql.properties
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/config/hsql.properties?rev=1301918&r1=1301917&r2=1301918&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/config/hsql.properties
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/config/hsql.properties
Sat Mar 17 10:49:42 2012
@@ -23,3 +23,6 @@ isis.persistor.sql.jdbc.password=
 
 # testing
 isis.persistor.sql.datatypes.string=VARCHAR(70)
+
+isis.persistor.sql.default.command.beginTransaction=
+

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/HsqlTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/HsqlTest.java?rev=1301918&r1=1301917&r2=1301918&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/HsqlTest.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/HsqlTest.java
Sat Mar 17 10:49:42 2012
@@ -39,6 +39,9 @@ public class HsqlTest extends SqlIntegra
             properties.put(SqlObjectStore.BASE_NAME + ".jdbc.user", "sa");
             properties.put(SqlObjectStore.BASE_NAME + ".jdbc.password", "");
             properties.put("isis.logging.objectstore", "on");
+            properties.put(SqlObjectStore.BASE_NAME + ".default.command.beginTransaction",
"");
+            // properties.put(SqlObjectStore.BASE_NAME + ".command.abortTransaction", "");
+            // properties.put(SqlObjectStore.BASE_NAME + ".command.commitTransaction", "");
         }
 
         return properties;

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java?rev=1301918&r1=1301917&r2=1301918&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java
Sat Mar 17 10:49:42 2012
@@ -92,6 +92,7 @@ public class PolymorphismTest extends Sq
             properties.put(SqlObjectStore.BASE_NAME + ".jdbc.user", "sa");
             properties.put(SqlObjectStore.BASE_NAME + ".jdbc.password", "");
             properties.put("isis.logging.objectstore", "on");
+            properties.put(SqlObjectStore.BASE_NAME + ".default.command.beginTransaction",
"");
         }
 
         return properties;



Mime
View raw message