incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1221311 - in /incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src: main/java/org/apache/isis/runtimes/dflt/objectstores/sql/ main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ test/java/org/apache/isis/ru...
Date Tue, 20 Dec 2011 15:15:59 GMT
Author: kevin
Date: Tue Dec 20 15:15:59 2011
New Revision: 1221311

URL: http://svn.apache.org/viewvc?rev=1221311&view=rev
Log:
ISIS-160: Allow user to specify "isis.persistor.sql.default.tableprefix" to override default
table name prefix of "isis_"

Added:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/DefaultsTest.java
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-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlPersistorInstaller.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AbstractAutoMapper.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.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=1221311&r1=1221310&r2=1221311&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
Tue Dec 20 15:15:59 2011
@@ -24,7 +24,6 @@ import java.util.Calendar;
 import org.joda.time.DateTimeZone;
 
 import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 
 /**
  * Provides objectstore defaults. Most significantly, maintains the object store default
TimeZone, and maintains
@@ -35,22 +34,24 @@ import org.apache.isis.runtimes.dflt.run
  */
 public class Defaults {
     private static String propertiesBase;
+    private static IsisConfiguration isisConfiguration;
 
-    public static void initialise(String propertiesBase) {
+    public static void initialise(String propertiesBase, IsisConfiguration isisConfiguration)
{
         Defaults.propertiesBase = propertiesBase;
         setTimeZone(DateTimeZone.UTC);
 
-        final IsisConfiguration configParameters = IsisContext.getConfiguration();
+        Defaults.isisConfiguration = isisConfiguration;
 
-        setPkIdLabel(getStringProperty(propertiesBase, configParameters, "pk_id"));
-        setIdColumn(getStringProperty(propertiesBase, configParameters, "id"));
-        setMaxInstances(getIntProperty(propertiesBase, configParameters, "maxinstances",
100));
-        final String useVersioningProperty = getStringProperty(propertiesBase, configParameters,
"versioning", "true");
+        setTablePrefix(getStringProperty(propertiesBase, isisConfiguration, "tableprefix",
"isis_"));
+        setPkIdLabel(getStringProperty(propertiesBase, isisConfiguration, "pk_id"));
+        setIdColumn(getStringProperty(propertiesBase, isisConfiguration, "id"));
+        setMaxInstances(getIntProperty(propertiesBase, isisConfiguration, "maxinstances",
100));
+        final String useVersioningProperty = getStringProperty(propertiesBase, isisConfiguration,
"versioning", "true");
         final int isTrue = useVersioningProperty.compareToIgnoreCase("true");
         useVersioning(isTrue == 0);
 
         final String BASE_DATATYPE = propertiesBase + ".datatypes.";
-        final IsisConfiguration dataTypes = IsisContext.getConfiguration().getProperties(BASE_DATATYPE);
+        final IsisConfiguration dataTypes = isisConfiguration.getProperties(BASE_DATATYPE);
         populateSqlDataTypes(dataTypes, BASE_DATATYPE);
 
     }
@@ -93,6 +94,19 @@ public class Defaults {
 
     // }}
 
+    // {{ Table prefix, defaults to "isis_"
+    private static String tablePrefix;
+
+    public static String getTablePrefix() {
+        return Defaults.tablePrefix;
+    }
+
+    public static void setTablePrefix(final String prefix) {
+        Defaults.tablePrefix = prefix;
+    }
+
+    // }}
+
     // {{ Primary Key label, defaults to "pk_id"
     private static String pkIdLabel;
 
@@ -252,9 +266,8 @@ public class Defaults {
         if (useVersioning() == false) {
             return false;
         }
-        final IsisConfiguration configParameters = IsisContext.getConfiguration();
         final String useVersioningProperty =
-            getStringProperty(propertiesBase, configParameters, "versioning." + shortIdentifier,
"true");
+            getStringProperty(propertiesBase, isisConfiguration, "versioning." + shortIdentifier,
"true");
         return (useVersioningProperty.compareToIgnoreCase("true") == 0);
     }
     // }}

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=1221311&r1=1221310&r2=1221311&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
Tue Dec 20 15:15:59 2011
@@ -69,7 +69,7 @@ public final class SqlObjectStore implem
         Sql.setMetaData(connectionPool.acquire().getMetaData());
 
         if (!isInitialized) {
-            Defaults.initialise(BASE_NAME);
+            Defaults.initialise(BASE_NAME, IsisContext.getConfiguration());
             Defaults.setPkIdLabel(Sql.identifier(Defaults.getPkIdLabel()));
             Defaults.setIdColumn(Sql.identifier(Defaults.getIdColumn()));
         }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlPersistorInstaller.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/SqlPersistorInstaller.java?rev=1221311&r1=1221310&r2=1221311&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlPersistorInstaller.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlPersistorInstaller.java
Tue Dec 20 15:15:59 2011
@@ -27,6 +27,7 @@ import org.apache.isis.runtimes.dflt.obj
 import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.ObjectStorePersistenceMechanismInstallerAbstract;
 import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.ObjectStore;
 import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSessionFactory;
@@ -48,7 +49,7 @@ public class SqlPersistorInstaller exten
             final FieldMappingLookup fieldMappingLookup = new FieldMappingLookup();
             final JdbcFieldMappingFactoryInstaller installer = new JdbcFieldMappingFactoryInstaller();
 
-            Defaults.initialise(SqlObjectStore.BASE_NAME);
+            Defaults.initialise(SqlObjectStore.BASE_NAME, IsisContext.getConfiguration());
 
             installer.load(fieldMappingLookup);
             // fieldMappingLookup.setValueMappingFactory(new

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AbstractAutoMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AbstractAutoMapper.java?rev=1221311&r1=1221310&r2=1221311&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AbstractAutoMapper.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AbstractAutoMapper.java
Tue Dec 20 15:15:59 2011
@@ -35,6 +35,7 @@ import org.apache.isis.core.metamodel.sp
 import org.apache.isis.runtimes.dflt.objectstores.sql.AbstractMapper;
 import org.apache.isis.runtimes.dflt.objectstores.sql.CollectionMapper;
 import org.apache.isis.runtimes.dflt.objectstores.sql.DatabaseConnector;
+import org.apache.isis.runtimes.dflt.objectstores.sql.Defaults;
 import org.apache.isis.runtimes.dflt.objectstores.sql.FieldMappingLookup;
 import org.apache.isis.runtimes.dflt.objectstores.sql.ObjectMappingLookup;
 import org.apache.isis.runtimes.dflt.objectstores.sql.Sql;
@@ -112,7 +113,7 @@ public abstract class AbstractAutoMapper
     }
 
     protected String getTableNameFromSpecification(ObjectSpecification objectSpecification)
{
-        return Sql.tableIdentifier(Sql.sqlName("isis_" + objectSpecification.getShortIdentifier()));
+        return Sql.tableIdentifier(Sql.sqlName(Defaults.getTablePrefix() + objectSpecification.getShortIdentifier()));
     }
 
     protected List<ObjectAssociation> fields = new ArrayList<ObjectAssociation>();

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.java?rev=1221311&r1=1221310&r2=1221311&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.java
Tue Dec 20 15:15:59 2011
@@ -201,7 +201,7 @@ public class AutoMapper extends Abstract
                                 continue;
                             }
                         } catch (ObjectSpecificationException e) {
-                            // this is ok
+                            // this is OK
                         }
 
                         if (foundFields == 0) {

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/DefaultsTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/DefaultsTest.java?rev=1221311&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/DefaultsTest.java
(added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/DefaultsTest.java
Tue Dec 20 15:15:59 2011
@@ -0,0 +1,48 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.runtimes.dflt.objectstores.sql;
+
+import static org.hamcrest.Matchers.is;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+
+public class DefaultsTest {
+    @Test
+    public void tablePrefixDefaultsTo_Isis() {
+        final String prefix = "isis.persistor.sql";
+        IsisConfiguration config = new IsisConfigurationDefault();
+        Defaults.initialise(prefix, config);
+        Assert.assertThat(Defaults.getTablePrefix(), is("isis_"));
+    }
+
+    @Test
+    public void tablePrefixCanBeReplaced() {
+        final String prefix = "isis.persistor.sql";
+        final String key = "isis.persistor.sql.default.tableprefix";
+        IsisConfigurationDefault config = new IsisConfigurationDefault();
+        config.add(key, "");
+        Defaults.initialise(prefix, config);
+        Assert.assertThat(Defaults.getTablePrefix(), is(""));
+    }
+}



Mime
View raw message