db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1755349 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/ torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/
Date Fri, 05 Aug 2016 15:38:05 GMT
Author: tv
Date: Fri Aug  5 15:38:05 2016
New Revision: 1755349

URL: http://svn.apache.org/viewvc?rev=1755349&view=rev
Log:
TORQUE-343: First steps

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/peerImplGetter.vm

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java?rev=1755349&r1=1755348&r2=1755349&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java Fri
Aug  5 15:38:05 2016
@@ -28,6 +28,7 @@ import org.apache.torque.manager.Abstrac
 import org.apache.torque.map.DatabaseMap;
 import org.apache.torque.oid.IDBroker;
 import org.apache.torque.om.Persistent;
+import org.apache.torque.util.BasePeerImpl;
 
 /**
  * A static facade wrapper around the Torque implementation (which is in
@@ -226,6 +227,34 @@ public final class Torque
     }
 
     /**
+     * This method registers a PeerImpl for a given class.
+     *
+     * @param omClass the class of the associated OM object
+     * @param peerInstance PeerImpl instance
+     */
+    public static <T> void registerPeerInstance(final Class<T> omClass, BasePeerImpl<T>
peerInstance)
+    {
+        getInstance().registerPeerInstance(omClass, peerInstance);
+    }
+
+    /**
+     * This method returns a PeerImpl for the given class.
+     *
+     * @param omClass the class of the associated OM object
+     * @return a PeerImpl instance
+     */
+    @SuppressWarnings("unchecked")
+    public static <T, P extends BasePeerImpl<T>> P getPeerInstance(final Class<T>
omClass)
+    {
+        /*
+         *  The cast is necessary to work around bug
+         *  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
+         *  in JDK 5.0
+         */
+        return (P) getInstance().getPeerInstance(omClass);
+    }
+
+    /**
      * Shuts down the service.
      *
      * This method halts the IDBroker's daemon thread in all of

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java?rev=1755349&r1=1755348&r2=1755349&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
Fri Aug  5 15:38:05 2016
@@ -43,6 +43,7 @@ import org.apache.torque.map.DatabaseMap
 import org.apache.torque.oid.IDBroker;
 import org.apache.torque.oid.IDGeneratorFactory;
 import org.apache.torque.om.Persistent;
+import org.apache.torque.util.BasePeerImpl;
 import org.apache.torque.util.Transaction;
 import org.apache.torque.util.TransactionManager;
 import org.apache.torque.util.TransactionManagerImpl;
@@ -77,7 +78,7 @@ public class TorqueInstance
 
     /**
      * The Map which contains all known databases. All iterations over the map
-     * and other operations where the databaase map needs to stay
+     * and other operations where the database map needs to stay
      * in a defined state must be synchronized to this map.
      */
     private final Map<String, Database> databases
@@ -86,6 +87,9 @@ public class TorqueInstance
     /** A repository of Manager instances. */
     private Map<String, AbstractBaseManager<?>> managers;
 
+    /** A repository of Peer instances. */
+    private Map<Class<?>, BasePeerImpl<?>> peers;
+
     /** A repository of idBroker instances. */
     private final Set<IDBroker> idBrokers = new HashSet<IDBroker>();
 
@@ -799,6 +803,34 @@ public class TorqueInstance
     }
 
     /**
+     * This method registers a PeerImpl for a given class.
+     *
+     * @param omClass the class of the associated OM object
+     * @param peerInstance PeerImpl instance
+     */
+    public <T> void registerPeerInstance(final Class<T> omClass, BasePeerImpl<T>
peerInstance)
+    {
+        peers.put(omClass, peerInstance);
+    }
+
+    /**
+     * This method returns a PeerImpl for the given class.
+     *
+     * @param omClass the class of the associated OM object
+     * @return a PeerImpl instance
+     */
+    public <T, P extends BasePeerImpl<T>> P getPeerInstance(final Class<T>
omClass)
+    {
+        @SuppressWarnings("unchecked")
+        P p = (P) peers.get(omClass);
+        if (p == null)
+        {
+            log.error("No registered peer for class " + omClass + ".");
+        }
+        return p;
+    }
+
+    /**
      * Shuts down Torque.
      *
      * This method halts the IDBroker's daemon thread in all of
@@ -885,6 +917,7 @@ public class TorqueInstance
     private void resetConfiguration()
     {
         managers = new HashMap<String, AbstractBaseManager<?>>();
+        peers = new HashMap<Class<?>, BasePeerImpl<?>>();
         isInit = false;
     }
 

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/peerImplGetter.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/peerImplGetter.vm?rev=1755349&r1=1755348&r2=1755349&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/peerImplGetter.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/peerImplGetter.vm
Fri Aug  5 15:38:05 2016
@@ -38,6 +38,7 @@
         {
             peerImplInstance = ${peerClassName}.create${peerImplClassName}();
             ${peerImplFieldName} = peerImplInstance;
+            Torque.registerPeerInstance(${dbObjectClassName}.class, peerImplInstance);
         }
         return peerImplInstance;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message