sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1722709 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/factory/ main/java/org/apache/sis/referencing/factory/sql/ test/java/org/apache/sis/referencing/factory/
Date Sun, 03 Jan 2016 11:18:15 GMT
Author: desruisseaux
Date: Sun Jan  3 11:18:15 2016
New Revision: 1722709

URL: http://svn.apache.org/viewvc?rev=1722709&view=rev
Log:
Renamed createBackingStore() as newDataAccess(). The "DataAccess" part is for matching the
name used in DAO.
The "new" prefix instead of "create" is for differentiating this method from all the other
'create' methods
inherited from GeodeticAuthorityFactory, which perform a very different task.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/UnavailableFactoryException.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java?rev=1722709&r1=1722708&r2=1722709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/ConcurrentAuthorityFactory.java
[UTF-8] Sun Jan  3 11:18:15 2016
@@ -60,9 +60,9 @@ import org.apache.sis.util.ArraysExt;
  * A concurrent authority factory that caches all objects created by another factory.
  * All {@code createFoo(String)} methods first check if a previously created object exists
for the given code.
  * If such object exists, it is returned. Otherwise, the object creation is delegated to
another factory given
- * by {@link #createBackingStore()} and the result is cached in this factory.
+ * by {@link #newDataAccess()} and the result is cached in this factory.
  *
- * <p>{@code ConcurrentAuthorityFactory} delays the call to {@code createBackingStore()}
until first needed,
+ * <p>{@code ConcurrentAuthorityFactory} delays the call to {@code newDataAccess()}
until first needed,
  * and {@linkplain AutoCloseable#close() closes} the backing store after some timeout. This
approach allows
  * to establish a connection to a database (for example) and keep it only for a relatively
short amount of time.</p>
  *
@@ -131,7 +131,7 @@ public abstract class ConcurrentAuthorit
         final GeodeticAuthorityFactory factory;
 
         /**
-         * Incremented on every call to {@link ConcurrentAuthorityFactory#getBackingStore()}
and decremented on every call
+         * Incremented on every call to {@link ConcurrentAuthorityFactory#getDataAccess()}
and decremented on every call
          * to {@link ConcurrentAuthorityFactory#release()}. When this value reach zero, the
factory is really released.
          */
         int depth;
@@ -286,8 +286,9 @@ public abstract class ConcurrentAuthorit
     }
 
     /**
-     * Creates a new backing store authority factory. This method is invoked the first time
a {@code createFoo(String)}
-     * method is invoked. It may also be invoked again if additional factories are needed
in different threads,
+     * Creates a factory which will perform the actual geodetic object creation work.
+     * This method is invoked the first time a {@code createFoo(String)} method is invoked.
+     * It may also be invoked again if additional factories are needed in different threads,
      * or if all factories have been closed after the timeout.
      *
      * <div class="section">Multi-threading</div>
@@ -302,7 +303,7 @@ public abstract class ConcurrentAuthorit
      * @throws UnavailableFactoryException if the backing store is unavailable because an
optional resource is missing.
      * @throws FactoryException if the creation of backing store failed for another reason.
      */
-    protected abstract GeodeticAuthorityFactory createBackingStore() throws UnavailableFactoryException,
FactoryException;
+    protected abstract GeodeticAuthorityFactory newDataAccess() throws UnavailableFactoryException,
FactoryException;
 
     /**
      * Returns a backing store authority factory. This method <strong>must</strong>
@@ -311,7 +312,7 @@ public abstract class ConcurrentAuthorit
      * @return The backing store to use in {@code createXXX(…)} methods.
      * @throws FactoryException if the backing store creation failed.
      */
-    private GeodeticAuthorityFactory getBackingStore() throws FactoryException {
+    private GeodeticAuthorityFactory getDataAccess() throws FactoryException {
         /*
          * First checks if the current thread is already using a factory. If yes, we will
          * avoid creating new factories on the assumption that factories are reentrant.
@@ -346,11 +347,11 @@ public abstract class ConcurrentAuthorit
             /*
              * If there is a need to create a new factory, do that outside the synchronized
block because this
              * creation may involve a lot of client code. This is better for reducing the
dead-lock risk.
-             * Subclasses are responsible of synchronizing their createBackingStore() method
if necessary.
+             * Subclasses are responsible of synchronizing their newDataAccess() method if
necessary.
              */
             try {
                 if (usage == null) {
-                    final GeodeticAuthorityFactory factory = createBackingStore();
+                    final GeodeticAuthorityFactory factory = newDataAccess();
                     if (factory == null) {
                         throw new UnavailableFactoryException(Errors.format(
                                 Errors.Keys.FactoryNotFound_1, GeodeticAuthorityFactory.class));
@@ -382,7 +383,7 @@ public abstract class ConcurrentAuthorit
     }
 
     /**
-     * Releases the backing store previously obtained with {@link #getBackingStore()}.
+     * Releases the backing store previously obtained with {@link #getDataAccess()}.
      * This method marks the factory as available for reuse by other threads.
      */
     private void release() {
@@ -519,7 +520,7 @@ public abstract class ConcurrentAuthorit
 
     /**
      * Sets a timer for closing the backing store after the specified amount of time of inactivity.
-     * If a new backing store is needed after the disposal of the last one, then the {@link
#createBackingStore()}
+     * If a new backing store is needed after the disposal of the last one, then the {@link
#newDataAccess()}
      * method will be invoked again.
      *
      * @param delay The delay of inactivity before to close a backing store.
@@ -557,7 +558,7 @@ public abstract class ConcurrentAuthorit
     public Citation getAuthority() {
         Citation c = authority;
         if (c == null) try {
-            final GeodeticAuthorityFactory factory = getBackingStore();
+            final GeodeticAuthorityFactory factory = getDataAccess();
             try {
                 // Cache only in case of success. If we failed, we
                 // will try again next time this method is invoked.
@@ -588,7 +589,7 @@ public abstract class ConcurrentAuthorit
      */
     @Override
     public Set<String> getAuthorityCodes(final Class<? extends IdentifiedObject>
type) throws FactoryException {
-        final GeodeticAuthorityFactory factory = getBackingStore();
+        final GeodeticAuthorityFactory factory = getDataAccess();
         try {
             return factory.getAuthorityCodes(type);
             /*
@@ -620,7 +621,7 @@ public abstract class ConcurrentAuthorit
     public InternationalString getDescriptionText(final String code)
             throws NoSuchAuthorityCodeException, FactoryException
     {
-        final GeodeticAuthorityFactory factory = getBackingStore();
+        final GeodeticAuthorityFactory factory = getDataAccess();
         try {
             return factory.getDescriptionText(code);
         } finally {
@@ -1259,7 +1260,7 @@ public abstract class ConcurrentAuthorit
     /**
      * Returns an object from a code using the given proxy. This method first checks in the
cache.
      * If no object exists in the cache for the given code, then a lock is created and the
object
-     * creation is delegated to the {@linkplain #getBackingStore() backing store}.
+     * creation is delegated to the {@linkplain #getDataAccess() backing store}.
      * The result is then stored in the cache and returned.
      *
      * @param  <T>   The type of the object to be returned.
@@ -1279,7 +1280,7 @@ public abstract class ConcurrentAuthorit
                 value = handler.peek();
                 if (!type.isInstance(value)) {
                     final T result;
-                    final GeodeticAuthorityFactory factory = getBackingStore();
+                    final GeodeticAuthorityFactory factory = getDataAccess();
                     try {
                         result = proxy.create(factory, code);
                     } finally {
@@ -1328,7 +1329,7 @@ public abstract class ConcurrentAuthorit
             try {
                 value = handler.peek();
                 if (!(value instanceof Set<?>)) {
-                    final GeodeticAuthorityFactory factory = getBackingStore();
+                    final GeodeticAuthorityFactory factory = getDataAccess();
                     try {
                         value = factory.createFromCoordinateReferenceSystemCodes(sourceCRS,
targetCRS);
                     } finally {
@@ -1414,10 +1415,10 @@ public abstract class ConcurrentAuthorit
             assert Thread.holdsLock(this);
             assert (acquireCount == 0) == (finder == null) : acquireCount;
             if (acquireCount == 0) {
-                final GeodeticAuthorityFactory delegate = ((ConcurrentAuthorityFactory) factory).getBackingStore();
+                final GeodeticAuthorityFactory delegate = ((ConcurrentAuthorityFactory) factory).getDataAccess();
                 /*
                  * Set 'acquireCount' only after we succeed in fetching the factory, and
before any operation on it.
-                 * The intend is to get ConcurrentAuthorityFactory.release() invoked if and
only if the getBackingStore()
+                 * The intend is to get ConcurrentAuthorityFactory.release() invoked if and
only if the getDataAccess()
                  * method succeed, no matter what happen after this point.
                  */
                 acquireCount = 1;
@@ -1434,7 +1435,7 @@ public abstract class ConcurrentAuthorit
         private void release() {
             assert Thread.holdsLock(this);
             if (acquireCount == 0) {
-                // May happen only if a failure occurred during getBackingStore() execution.
+                // May happen only if a failure occurred during getDataAccess() execution.
                 return;
             }
             if (--acquireCount == 0) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/UnavailableFactoryException.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/UnavailableFactoryException.java?rev=1722709&r1=1722708&r2=1722709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/UnavailableFactoryException.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/UnavailableFactoryException.java
[UTF-8] Sun Jan  3 11:18:15 2016
@@ -29,7 +29,7 @@ import org.opengis.util.FactoryException
  * @version 0.7
  * @module
  *
- * @see ConcurrentAuthorityFactory#createBackingStore()
+ * @see ConcurrentAuthorityFactory#newDataAccess()
  */
 public class UnavailableFactoryException extends FactoryException {
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java?rev=1722709&r1=1722708&r2=1722709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
[UTF-8] Sun Jan  3 11:18:15 2016
@@ -287,8 +287,9 @@ public class EPSGDataAccess extends Geod
      *
      * <div class="note"><b>API design note:</b>
      * this constructor is protected because {@code EPSGDataAccess} instances should not
be created as standalone factories.
-     * This constructor is invoked either by {@link EPSGFactory#createBackingStore()}, or
by the constructor of an
-     * {@code EPSGDataAccess} subclass which is itself invoked by a corresponding {@code
EPSGFactory} subclass.</div>
+     * This constructor is invoked either by {@link EPSGFactory#newDataAccess(Connection,
SQLTranslator)},
+     * or by the constructor of an {@code EPSGDataAccess} subclass which is itself invoked
by a corresponding
+     * {@code EPSGFactory} subclass.</div>
      *
      * @param parent      The {@code EPSGFactory} which is creating this Data Access Object
(DAO).
      * @param connection  The connection to the underlying EPSG database.
@@ -3097,7 +3098,7 @@ addURIs:    for (int i=0; ; i++) {
 
     /**
      * Closes the JDBC connection used by this factory.
-     * If this {@code EPSGDataAccess} is used by a {@link EPSGFactory}, then this method
+     * If this {@code EPSGDataAccess} is used by an {@link EPSGFactory}, then this method
      * will be automatically invoked after some {@linkplain EPSGFactory#getTimeout timeout}.
      *
      * @throws FactoryException if an error occurred while closing the connection.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java?rev=1722709&r1=1722708&r2=1722709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
[UTF-8] Sun Jan  3 11:18:15 2016
@@ -48,7 +48,8 @@ import org.apache.sis.util.Localized;
  * <div class="section">Note for subclasses</div>
  * If there is no cached object for a given code, then {@code EPSGFactory} creates an {@link
EPSGDataAccess} instance
  * for performing the actual creation work. Developers who need to customize the geodetic
object creation can override
- * the {@link #createBackingStore()} method in order to return their own {@link EPSGDataAccess}
subclass.
+ * the {@link #newDataAccess(Connection, SQLTranslator)} method in order to return their
own {@link EPSGDataAccess}
+ * subclass.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
@@ -130,7 +131,7 @@ public class EPSGFactory extends Concurr
      * @param crsFactory    The factory to use for creating {@link CoordinateReferenceSystem}
instances.
      * @param copFactory    The factory to use for creating {@link CoordinateOperation} instances.
      * @param mtFactory     The factory to use for creating {@link MathTransform} instances.
-     * @param translator    The adapter from the SQL statements using MS-Access dialect to
SQL statements
+     * @param translator    The translator from the SQL statements using MS-Access dialect
to SQL statements
      *                      using the dialect of the actual database.
      * @throws FactoryException if an error occurred while creating the EPSG factory.
      */
@@ -199,16 +200,16 @@ public class EPSGFactory extends Concurr
      * This method is invoked automatically when a new worker is required, either because
the previous
      * one has been disposed after its timeout or because a new one is required for concurrency.
      *
-     * <p>The default implementation gets a new connection from the {@link #dataSource}
-     * and creates a new {@link EPSGDataAccess} instance.
-     * Subclasses can override this method if they want to return a custom instance.</p>
+     * <p>The default implementation gets a new connection from the {@link #dataSource}
and delegates to
+     * {@link #newDataAccess(Connection, SQLTranslator)}, which provides an easier overriding
point
+     * for subclasses wanting to return a custom {@link EPSGDataAccess} instance.</p>
      *
      * @return The backing store to use in {@code createFoo(String)} methods.
      * @throws FactoryException if the constructor failed to connect to the EPSG database.
      *         This exception usually has a {@link SQLException} as its cause.
      */
     @Override
-    protected GeodeticAuthorityFactory createBackingStore() throws FactoryException {
+    protected GeodeticAuthorityFactory newDataAccess() throws FactoryException {
         Connection connection = null;
         try {
             connection = dataSource.getConnection();
@@ -221,7 +222,7 @@ public class EPSGFactory extends Concurr
                     }
                 }
             }
-            return new EPSGDataAccess(this, connection, tr);
+            return newDataAccess(connection, tr);
         } catch (Exception e) {
             if (connection != null) try {
                 connection.close();
@@ -231,4 +232,27 @@ public class EPSGFactory extends Concurr
             throw new UnavailableFactoryException(e.getLocalizedMessage(), e);
         }
     }
+
+    /**
+     * Creates the factory which will perform the actual geodetic object creation from a
given connection.
+     * This method is a convenience hook easier to override than {@link #newDataAccess()}
for subclasses
+     * wanting to return instances of their own {@link EPSGDataAccess} subclass.
+     * The default implementation is simply:
+     *
+     * {@preformat java
+     *     return new EPSGDataAccess(this, connection, translator);
+     * }
+     *
+     * Subclasses can override this method with a similar code but with {@code new EPSGDataAccess(…)}
replaced
+     * by {@code new MyDataAccessSubclass(…)}.
+     *
+     * @param  connection A connection to the EPSG database.
+     * @param  translator The translator from the SQL statements using MS-Access dialect
to SQL statements
+     *                    using the dialect of the actual database.
+     * @throws SQLException if {@code EPSGDataAccess} detected a problem with the database.
+     * @return The backing store to use in {@code createFoo(String)} methods.
+     */
+    protected EPSGDataAccess newDataAccess(Connection connection, SQLTranslator translator)
throws SQLException {
+        return new EPSGDataAccess(this, connection, translator);
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java?rev=1722709&r1=1722708&r2=1722709&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/IdentifiedObjectFinderTest.java
[UTF-8] Sun Jan  3 11:18:15 2016
@@ -121,7 +121,7 @@ public final strictfp class IdentifiedOb
         }
 
         @Override
-        protected GeodeticAuthorityFactory createBackingStore() {
+        protected GeodeticAuthorityFactory newDataAccess() {
             return factory;
         }
     }



Mime
View raw message