You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/07/31 12:59:54 UTC

[5/9] isis git commit: ISIS-1182: CreateSchema... listener now uses the PMF to obtain connection. Upgrading to released version of fast-classpath-scanner. Added migration notes.

ISIS-1182: CreateSchema... listener now uses the PMF to obtain connection.  Upgrading to released version of fast-classpath-scanner.  Added migration notes.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/b83db191
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/b83db191
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/b83db191

Branch: refs/heads/master
Commit: b83db19183fd082355ca24b7cfaea5378038f346
Parents: 97013cb
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Jul 31 10:42:48 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Jul 31 10:42:48 2015 +0100

----------------------------------------------------------------------
 .../_migration-notes_1.8.0-to-1.9.0.adoc        |  1 +
 ...1.8.0-to-1.9.0_specify-all-dom-packages.adoc | 35 +++++++++
 ...notes_1.8.0-to-1.9.0_upgrading-to-java8.adoc |  2 +-
 core/pom.xml                                    |  2 +-
 .../CreateSchemaObjectFromClassMetadata.java    | 81 +++++++++++++-------
 5 files changed, 90 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/b83db191/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0.adoc b/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0.adoc
index 4bae36c..f7b103e 100644
--- a/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0.adoc
+++ b/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0.adoc
@@ -13,6 +13,7 @@ Apache Isis 1.9.0 has not yet been released; it is still 1.9.0-SNAPSHOT.
 ====
 
 include::_migration-notes_1.8.0-to-1.9.0_upgrading-to-dn4.adoc[leveloffset=+1]
+include::_migration-notes_1.8.0-to-1.9.0_specify-all-dom-packages.adoc[leveloffset=+1]
 include::_migration-notes_1.8.0-to-1.9.0_upgrading-to-java8.adoc[leveloffset=+1]
 include::_migration-notes_1.8.0-to-1.9.0_exception-recognizer.adoc[leveloffset=+1]
 include::_migration-notes_1.8.0-to-1.9.0_fixture-scripts-specification-provider.adoc[leveloffset=+1]

http://git-wip-us.apache.org/repos/asf/isis/blob/b83db191/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0_specify-all-dom-packages.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0_specify-all-dom-packages.adoc b/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0_specify-all-dom-packages.adoc
new file mode 100644
index 0000000..72cc639
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0_specify-all-dom-packages.adoc
@@ -0,0 +1,35 @@
+[[_migration-notes_1.8.0-to-1.9.0_specify-all-dom-packages]]
+= Specify all `dom` packages
+:Notice: 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.
+:_basedir: ../
+:_imagesdir: images/
+
+
+
+Apache Isis automatically scans for certain classes on the classpath in order to configure itself.  Specifically these are:
+
+* searching for classes annotated with xref:rg.adoc#_rg_annotations_manpage-DomainService[`@DomainService`].
+
+* searching for classes extending xref:rg.adoc#_rg_classes_super_manpage-FixtureScript[`FixtureScript`]
+
+* searching for classes annotated with xref:rg.adoc#_rg_annotations_manpage-PersistenceCapable[`@PersistenceCapable`].
+
+Prior to 1.9.0 we used the link:https://github.com/ronmamo/reflections[Reflections] library to do this, which under the covers uses link:http://www.javassist.org/[Javassist].  This is a relatively heavyweight approach.
+
+In 1.9.0 we have changed to using the link:https://github.com/lukehutch/fast-classpath-scanner[Fast-Classpath-Scanner] library, which is altogether more lightweight and has no dependencies.
+
+Generally this change should be transparent, however you should ensure that all domain classes are correctly registered using the `isis.persistor.datanucleus.RegisterEntities.packagePrefix` key.  This should include any domain classes for addon modules.
+
+For example, the (non-ASF) http://github.com/isisaddons/isis-app-todoapp[Isis addons' todoapp]'s configuration now reads:
+
+[source,ini]
+----
+isis.persistor.datanucleus.RegisterEntities.packagePrefix=\
+                todoapp.dom.module,\
+                org.isisaddons.module.security.dom,\
+                org.isisaddons.module.settings.dom,\
+                org.isisaddons.module.sessionlogger.dom,\
+                org.isisaddons.module.command.dom,\
+                org.isisaddons.module.audit.dom,\
+                org.isisaddons.module.publishing.dom
+----

http://git-wip-us.apache.org/repos/asf/isis/blob/b83db191/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0_upgrading-to-java8.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0_upgrading-to-java8.adoc b/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0_upgrading-to-java8.adoc
index dacc0f8..185b7f7 100644
--- a/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0_upgrading-to-java8.adoc
+++ b/adocs/documentation/src/main/asciidoc/_migration-notes_1.8.0-to-1.9.0_upgrading-to-java8.adoc
@@ -12,7 +12,7 @@ Apache Isis 1.9.0 is the first version to support Java 8.  You can continue to u
 
 == In the parent `pom.xml`
 
-under `<build>/<pluginManagement>/<plugins>`, add (or update) maven-enforcer-plugin:
+under `build/pluginManagement/plugins`, add (or update) `maven-compiler-plugin`:
 
 [source,xml]
 ----

http://git-wip-us.apache.org/repos/asf/isis/blob/b83db191/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index fcf5c43..ba68a17 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -116,7 +116,7 @@
         <javassist.version>3.19.0-GA</javassist.version>
         <reflections.version>0.9.9</reflections.version>
 
-        <fast-classpath-scanner.version>1.4.2-SNAPSHOT</fast-classpath-scanner.version>
+        <fast-classpath-scanner.version>1.6.0</fast-classpath-scanner.version>
 
         <commons-logging.version>1.1.2</commons-logging.version>
         <commons-cli.version>1.2</commons-cli.version>

http://git-wip-us.apache.org/repos/asf/isis/blob/b83db191/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/CreateSchemaObjectFromClassMetadata.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/CreateSchemaObjectFromClassMetadata.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/CreateSchemaObjectFromClassMetadata.java
index e4ce6cc..1c4e5b8 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/CreateSchemaObjectFromClassMetadata.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/CreateSchemaObjectFromClassMetadata.java
@@ -19,29 +19,43 @@
 package org.apache.isis.objectstore.jdo.datanucleus;
 
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Locale;
 import java.util.Map;
+
+import javax.jdo.PersistenceManager;
 import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.datastore.JDOConnection;
+
 import com.google.common.base.Strings;
+
 import org.datanucleus.metadata.AbstractClassMetaData;
 import org.datanucleus.metadata.MetaDataListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Implementation note: the methods in this class are <tt>protected</tt> to allow for easy subclassing.
+ */
 public class CreateSchemaObjectFromClassMetadata implements MetaDataListener, PersistenceManagerFactoryAware, DataNucleusPropertiesAware {
 
     private static final Logger LOG = LoggerFactory.getLogger(DataNucleusPersistenceMechanismInstaller.class);
 
-    // unused
-    protected PersistenceManagerFactory persistenceManagerFactory;
-    protected Map<String, String> properties;
+    //region > persistenceManagerFactory, properties
+    private PersistenceManagerFactory persistenceManagerFactory;
+    protected PersistenceManagerFactory getPersistenceManagerFactory() {
+        return persistenceManagerFactory;
+    }
 
-    protected String driverName;
-    protected String url;
+    private Map<String, String> properties;
+    protected Map<String, String> getProperties() {
+        return properties;
+    }
+    //endregion
+
+    //region > loaded (API)
 
     @Override
     public void loaded(final AbstractClassMetaData cmd) {
@@ -51,39 +65,36 @@ public class CreateSchemaObjectFromClassMetadata implements MetaDataListener, Pe
             return;
         }
 
-        driverName = properties.get("javax.jdo.option.ConnectionDriverName");
-        url = properties.get("javax.jdo.option.ConnectionURL");
-        final String userName = properties.get("javax.jdo.option.ConnectionUserName");
-        final String password = properties.get("javax.jdo.option.ConnectionPassword");
-
+        JDOConnection dataStoreConnection = null;
         Connection connection = null;
         Statement statement = null;
+
+
+        final PersistenceManager persistenceManager =
+                persistenceManagerFactory.getPersistenceManager();
+        dataStoreConnection = persistenceManager.getDataStoreConnection();
         try {
-            connection = DriverManager.getConnection(url, userName, password);
+            final Object connectionObj = dataStoreConnection.getNativeConnection();
+            connection = (java.sql.Connection) connectionObj;
+
             statement = connection.createStatement();
             if(skip(cmd, statement)) {
                 return;
             }
             exec(cmd, statement);
+
         } catch (SQLException e) {
             LOG.warn("Unable to create schema", e);
+
         } finally {
             closeSafely(statement);
-            closeSafely(connection);
+            dataStoreConnection.close();
         }
-    }
 
-    protected void closeSafely(final AutoCloseable connection) {
-        if(connection != null) {
-            try {
-                connection.close();
-            } catch (Exception e) {
-                // ignore
-            }
-        }
     }
+    //endregion
 
-    //region > skip
+    //region > skip, exec, schemaNameFor
 
     /**
      * Whether to skip creating this schema.
@@ -105,9 +116,6 @@ public class CreateSchemaObjectFromClassMetadata implements MetaDataListener, Pe
         final String schemaName = schemaNameFor(cmd);
         return String.format("SELECT count(*) FROM INFORMATION_SCHEMA.SCHEMATA where SCHEMA_NAME = '%s'", schemaName);
     }
-    //endregion
-
-    //region > exec
 
     /**
      * Create the schema
@@ -121,7 +129,6 @@ public class CreateSchemaObjectFromClassMetadata implements MetaDataListener, Pe
         final String schemaName = schemaNameFor(cmd);
         return String.format("CREATE SCHEMA \"%s\"", schemaName);
     }
-    //endregion
 
     /**
      * Determine the name of the schema.
@@ -138,6 +145,8 @@ public class CreateSchemaObjectFromClassMetadata implements MetaDataListener, Pe
         // db vendors without requiring lots of complex configuration of DataNucleus
         //
 
+        String url = getProperties().get("javax.jdo.option.ConnectionURL");
+
         if(url.contains("postgres")) {
             schemaName = schemaName.toLowerCase(Locale.ROOT);
         }
@@ -149,10 +158,21 @@ public class CreateSchemaObjectFromClassMetadata implements MetaDataListener, Pe
         }
         return schemaName;
     }
+    //endregion
 
+    //region > helpers: closeSafely
+    protected void closeSafely(final AutoCloseable connection) {
+        if(connection != null) {
+            try {
+                connection.close();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+    }
+    //endregion
 
-    // //////////////////////////////////////
-
+    //region > injected dependencies
     public void setPersistenceManagerFactory(final PersistenceManagerFactory persistenceManagerFactory) {
         this.persistenceManagerFactory = persistenceManagerFactory;
     }
@@ -161,4 +181,7 @@ public class CreateSchemaObjectFromClassMetadata implements MetaDataListener, Pe
     public void setDataNucleusProperties(final Map<String, String> properties) {
         this.properties = properties;
     }
+    //endregion
+
+
 }