dlr 2003/07/02 16:03:58
Modified: src/java/org/apache/torque Torque.java TorqueInstance.java
src/java/org/apache/torque/avalon TorqueComponent.java
Log:
Work towards the goal of allowing multiple instances of TorqueInstance
per ClassLoader hierarchy.
* src/java/org/apache/torque/Torque.java
torqueSingleton, getInstance(): Added singleton implementation
cribbed from TorqueInstance.java.
* src/java/org/apache/torque/TorqueInstance.java
Updated header JavaDoc.
TorqueInstance(): Made ctor public to allow instantiation of the
Torque core.
torqueSingleton, getInstance(): Removed singleton implementation.
* src/java/org/apache/torque/avalon/TorqueComponent.java
torqueInstance, getTorque(): To allow both the Torque static
wrapper and an Avalon component to be used within the same
ClassLoader hierarchy, TorqueComponent now use its own instance of
TorqueInstance.
TorqueComponent(), TorqueComponent(TorqueInstance): Explicitly
define the default ctor used by Avalon's componentry, and supply a
protected cotr which it delegates to for definition of the
TorqueInstance to use.
Revision Changes Path
1.89 +12 -2 db-torque/src/java/org/apache/torque/Torque.java
Index: Torque.java
===================================================================
RCS file: /home/cvs/db-torque/src/java/org/apache/torque/Torque.java,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -u -r1.88 -r1.89
--- Torque.java 2 Jul 2003 22:19:07 -0000 1.88
+++ Torque.java 2 Jul 2003 23:03:57 -0000 1.89
@@ -113,6 +113,12 @@
*/
public static final String CACHE_KEY = "manager.useCache";
+ /**
+ * The single instance of [EMAIL PROTECTED] TorqueInstance} used by the
+ * static API presented by this class.
+ */
+ private static TorqueInstance torqueSingleton = null;
+
/**
* This is a member variable of Torque objects created by the Stratum
* lifecycle
@@ -137,7 +143,11 @@
*/
private static TorqueInstance getInstance()
{
- return TorqueInstance.getInstance();
+ if (torqueSingleton == null)
+ {
+ torqueSingleton = new TorqueInstance();
+ }
+ return torqueSingleton;
}
/**
1.3 +11 -35 db-torque/src/java/org/apache/torque/TorqueInstance.java
Index: TorqueInstance.java
===================================================================
RCS file: /home/cvs/db-torque/src/java/org/apache/torque/TorqueInstance.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -u -r1.2 -r1.3
--- TorqueInstance.java 2 Jul 2003 05:02:05 -0000 1.2
+++ TorqueInstance.java 2 Jul 2003 23:03:57 -0000 1.3
@@ -81,11 +81,11 @@
import org.apache.torque.util.BasePeer;
/**
- * The implementation of Torque.
- * <br/>
- * This is a singleton pattern so that Torque works both as a Avalon component
- * and as a standalone application by using the Torque facade.
- *
+ * The core of Torque's implementation. Both the classic [EMAIL PROTECTED]
+ * org.apache.torque.Torque} static wrapper and the [EMAIL PROTECTED]
+ * org.apache.torque.avalon.TorqueComponent} <a
+ * href="http://avalon.apache.org/">Avalon</a> implementation leverage
+ * this class.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Magn�s ��r Torfason</a>
@@ -145,42 +145,18 @@
*/
private List mapBuilders = null;
- /*
- * ========================================================================
- *
- * Singleton Pattern
- *
- * ========================================================================
- */
-
- /** The only instance in this class */
- private static TorqueInstance torqueSingleton = null;
-
/**
- * C'tor
+ * Creates a new instance with default configuration.
+ *
+ * @see #resetConfiguration()
*/
- private TorqueInstance()
+ public TorqueInstance()
{
resetConfiguration();
}
/**
- * Fetch the Torque Instance from the Singleton
- *
- * @return The only TorqueInstance Instance
- */
-
- public static synchronized TorqueInstance getInstance()
- {
- if (torqueSingleton == null)
- {
- torqueSingleton = new TorqueInstance();
- }
- return torqueSingleton;
- }
-
- /**
- * initialize Torque
+ * Initializes this instance of Torque.
*
* @see org.apache.stratum.lifecycle.Initializable
* @throws TorqueException Any exceptions caught during processing will be
1.6 +25 -5 db-torque/src/java/org/apache/torque/avalon/TorqueComponent.java
Index: TorqueComponent.java
===================================================================
RCS file:
/home/cvs/db-torque/src/java/org/apache/torque/avalon/TorqueComponent.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -u -r1.5 -r1.6
--- TorqueComponent.java 2 Jul 2003 04:58:25 -0000 1.5
+++ TorqueComponent.java 2 Jul 2003 23:03:58 -0000 1.6
@@ -95,18 +95,38 @@
/** The Avalon Context */
private Context context = null;
- /** The Configuration File for Torque */
+ /** The instance of Torque used by this component. */
+ private TorqueInstance torqueInstance = null;
+
+ /** The configuration file for Torque. */
private String configFile = null;
/**
- * Get a reference to the actual Torque Core
+ * Creates a new instance. Default constructor used by Avalon.
+ */
+ public TorqueComponent()
+ {
+ this(new TorqueInstance());
+ }
+
+ /**
+ * Creates a new instance.
*
- * @return A Torque Singleton reference
+ * @param torqueInstance The instance of the Torque core used by
+ * this component.
+ */
+ protected TorqueComponent(TorqueInstance torqueInstance)
+ {
+ this.torqueInstance = torqueInstance;
+ }
+
+ /**
+ * @return A reference to our instance of the Torque core.
*/
private TorqueInstance getTorque()
{
- return TorqueInstance.getInstance();
+ return torqueInstance;
}
/*
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]