Author: tfischer
Date: Mon Aug 15 10:36:54 2005
New Revision: 232837
URL: http://svn.apache.org/viewcvs?rev=232837&view=rev
Log:
- Added a method getXXX(connection) to retrieve associated objects in the n->1
direction, which uses the provided connection if a db hit is necessary
- Added a generator property torque.silentDbFetch, which is true by default. If
set to false, the getXXX() methods without arguments will not access the db
silently, but return null if the associated objects has not been read yet.
Also, these methods do not throw a Torque exception any more if silentDbFetch
is false.
- Fixed a few misplaced spaces and differences between Object.vm and
ObjectWithManager.vm
Modified:
db/torque/trunk/profile/axion.profile
db/torque/trunk/profile/db2400.profile
db/torque/trunk/profile/derby.profile
db/torque/trunk/profile/dobbs.oracle.profile
db/torque/trunk/profile/dobbs.postgresql.profile
db/torque/trunk/profile/dobbs.sapdb.profile
db/torque/trunk/profile/firebird.profile
db/torque/trunk/profile/henning.profile
db/torque/trunk/profile/hsqldb.profile
db/torque/trunk/profile/jmcnally.profile
db/torque/trunk/profile/kschrader.profile
db/torque/trunk/profile/mysql.profile
db/torque/trunk/profile/oracle.profile
db/torque/trunk/profile/postgres.profile
db/torque/trunk/profile/sybase.profile
db/torque/trunk/src/generator/src/conf/build.properties
db/torque/trunk/src/generator/src/conf/default.properties
db/torque/trunk/src/generator/src/templates/om/Object.vm
db/torque/trunk/src/generator/src/templates/om/ObjectWithManager.vm
db/torque/trunk/src/maven-plugin/plugin.properties
db/torque/trunk/xdocs/changes.xml
Modified: db/torque/trunk/profile/axion.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/axion.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/axion.profile (original)
+++ db/torque/trunk/profile/axion.profile Mon Aug 15 10:36:54 2005
@@ -56,6 +56,7 @@
torque.addIntakeRetrievable=false
torque.useManagers=true
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/db2400.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/db2400.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/db2400.profile (original)
+++ db/torque/trunk/profile/db2400.profile Mon Aug 15 10:36:54 2005
@@ -56,6 +56,7 @@
torque.addIntakeRetrievable=false
torque.useManagers=true
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/derby.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/derby.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/derby.profile (original)
+++ db/torque/trunk/profile/derby.profile Mon Aug 15 10:36:54 2005
@@ -55,6 +55,7 @@
torque.addIntakeRetrievable=false
torque.useManagers=false
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/dobbs.oracle.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/dobbs.oracle.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/dobbs.oracle.profile (original)
+++ db/torque/trunk/profile/dobbs.oracle.profile Mon Aug 15 10:36:54 2005
@@ -53,6 +53,7 @@
torque.addTimeStamp=true
torque.addIntakeRetrievable=false
torque.useManagers=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/dobbs.postgresql.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/dobbs.postgresql.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/dobbs.postgresql.profile (original)
+++ db/torque/trunk/profile/dobbs.postgresql.profile Mon Aug 15 10:36:54 2005
@@ -53,6 +53,7 @@
torque.addTimeStamp=true
torque.addIntakeRetrievable=false
torque.useManagers=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/dobbs.sapdb.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/dobbs.sapdb.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/dobbs.sapdb.profile (original)
+++ db/torque/trunk/profile/dobbs.sapdb.profile Mon Aug 15 10:36:54 2005
@@ -53,6 +53,7 @@
torque.addTimeStamp=true
torque.addIntakeRetrievable=false
torque.useManagers=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/firebird.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/firebird.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/firebird.profile (original)
+++ db/torque/trunk/profile/firebird.profile Mon Aug 15 10:36:54 2005
@@ -60,6 +60,7 @@
#torque.useManagers=true
torque.useManagers=false
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/henning.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/henning.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/henning.profile (original)
+++ db/torque/trunk/profile/henning.profile Mon Aug 15 10:36:54 2005
@@ -55,6 +55,7 @@
torque.addIntakeRetrievable=false
torque.useManagers=true
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/hsqldb.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/hsqldb.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/hsqldb.profile (original)
+++ db/torque/trunk/profile/hsqldb.profile Mon Aug 15 10:36:54 2005
@@ -54,6 +54,7 @@
torque.addIntakeRetrievable=false
torque.useManagers=true
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/jmcnally.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/jmcnally.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/jmcnally.profile (original)
+++ db/torque/trunk/profile/jmcnally.profile Mon Aug 15 10:36:54 2005
@@ -54,6 +54,7 @@
torque.addIntakeRetrievable=false
torque.useManagers=true
torque.useClasspath=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/kschrader.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/kschrader.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/kschrader.profile (original)
+++ db/torque/trunk/profile/kschrader.profile Mon Aug 15 10:36:54 2005
@@ -54,6 +54,7 @@
torque.addTimeStamp=true
torque.addIntakeRetrievable=false
torque.useManagers=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/mysql.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/mysql.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/mysql.profile (original)
+++ db/torque/trunk/profile/mysql.profile Mon Aug 15 10:36:54 2005
@@ -60,6 +60,7 @@
#torque.useManagers=true
torque.useManagers=false
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/oracle.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/oracle.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/oracle.profile (original)
+++ db/torque/trunk/profile/oracle.profile Mon Aug 15 10:36:54 2005
@@ -55,6 +55,7 @@
torque.addIntakeRetrievable=false
torque.useManagers=true
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/postgres.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/postgres.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/postgres.profile (original)
+++ db/torque/trunk/profile/postgres.profile Mon Aug 15 10:36:54 2005
@@ -55,6 +55,7 @@
torque.addIntakeRetrievable=false
torque.useManagers=true
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/profile/sybase.profile
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/profile/sybase.profile?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/profile/sybase.profile (original)
+++ db/torque/trunk/profile/sybase.profile Mon Aug 15 10:36:54 2005
@@ -54,6 +54,7 @@
torque.addIntakeRetrievable=false
torque.useManagers=true
torque.generateBeans=true
+torque.silentDbFetch=true
# -------------------------------------------------------------------
#
Modified: db/torque/trunk/src/generator/src/conf/build.properties
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/conf/build.properties?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/conf/build.properties (original)
+++ db/torque/trunk/src/generator/src/conf/build.properties Mon Aug 15 10:36:54
2005
@@ -107,6 +107,16 @@
# can be manipulated from other code), set this property to false. This
currently
# cannot combined with the manager setting from above.
#
+# silentDbFetch
+# If true, the getXXX() methods which retrieve associated objects
+# will fetch the associated objects silently. If false, only the
+# methods where a connection is specified explicitly will
+# fetch the associated objects silently; the methods where no connection
+# is specified will not do a silent fetch and return null if no previous
+# explicit fetch was made.
+# This setting has no effect if objectIsCaching is set to false.
+#
+#
# generateBeans
# If true, Torque will generate an additional bean for each data object,
# plus methods to create beans from data objects and vice versa
@@ -127,6 +137,7 @@
torque.useClasspath = true
torque.useManagers = false
torque.objectIsCaching = true
+torque.silentDbFetch = true
torque.generateBeans = false
torque.beanSuffix = Bean
Modified: db/torque/trunk/src/generator/src/conf/default.properties
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/conf/default.properties?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/conf/default.properties (original)
+++ db/torque/trunk/src/generator/src/conf/default.properties Mon Aug 15
10:36:54 2005
@@ -101,6 +101,7 @@
# Whether to generate Manager classes for JCS-based caching.
torque.useManagers = false
torque.objectIsCaching = true
+torque.silentDbFetch = true
torque.generateBeans = false
torque.beanSuffix = Bean
Modified: db/torque/trunk/src/generator/src/templates/om/Object.vm
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/templates/om/Object.vm?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/templates/om/Object.vm (original)
+++ db/torque/trunk/src/generator/src/templates/om/Object.vm Mon Aug 15
10:36:54 2005
@@ -42,7 +42,7 @@
import ${packagePeer}.*;
#end
-#if ($generateBeans)
+#if ($generateBeans)
$generator.parse("om/bean/ObjectBeanImports.vm",$path,"child",$child)
#end
@@ -119,13 +119,13 @@
#else
#set ( $accessLevel = "public" )
#end
-
+
/**
* Get the $cfc
*
* @return $cjtype
*/
- $accessLevel $cjtype ${col.GetterName} ()
+ $accessLevel $cjtype ${col.GetterName}()
{
return $clo;
}
@@ -326,26 +326,79 @@
#end
/**
- * Get the associated $interfaceName object
+ * Returns the associated $interfaceName object.
+ #if ($silentDbFetch)
+ * If it was not retrieved before, the object is retrieved from
+ * the database
+ #end
+ *
+ * @return the associated $interfaceName object
+ #if ($silentDbFetch)
+ * @throws TorqueException
+ #end
+ */
+ public $interfaceName get${pVarName}()
+ #if ($silentDbFetch)
+ throws TorqueException
+ #end
+ {
+ #if ($silentDbFetch)
+ if ($varName == null && ($conditional))
+ {
+ #if ($tblFK.isAlias())
+ #if ($argsize > 1)
+ $varName = ${className}Peer.retrieve${className}ByPK($arglist);
+ #else
+ $varName =
${className}Peer.retrieve${className}ByPK(SimpleKey.keyFor($arglist));
+ #end
+ #else
+ #if ($argsize > 1)
+ $varName = ${className}Peer.retrieveByPK($arglist);
+ #else
+ $varName =
${className}Peer.retrieveByPK(SimpleKey.keyFor($arglist));
+ #end
+ #end
+
+ /* The following can be used instead of the line above to
+ guarantee the related object contains a reference
+ to this object, but this level of coupling
+ may be undesirable in many circumstances.
+ As it can lead to a db query with many results that may
+ never be used.
+ $className obj = ${className}Peer.retrieveByPK($arglist);
+ obj.add${pCollName}(this);
+ */
+ }
+ #end
+ return $varName;
+ }
+
+ /**
+ * Return the associated $interfaceName object
+ * If it was not retrieved before, the object is retrieved from
+ * the database using the passed connection
*
+ * @param connection the connection used to retrieve the associated object
+ * from the database, if it was not retrieved before
* @return the associated $interfaceName object
* @throws TorqueException
*/
- public $interfaceName get${pVarName}() throws TorqueException
+ public $interfaceName get${pVarName}(Connection connection)
+ throws TorqueException
{
if ($varName == null && ($conditional))
{
#if ($tblFK.isAlias())
#if ($argsize > 1)
- $varName = ${className}Peer.retrieve${className}ByPK($arglist);
+ $varName = ${className}Peer.retrieve${className}ByPK($arglist,
connection);
#else
- $varName =
${className}Peer.retrieve${className}ByPK(SimpleKey.keyFor($arglist));
+ $varName =
${className}Peer.retrieve${className}ByPK(SimpleKey.keyFor($arglist),
connection);
#end
#else
#if ($argsize > 1)
- $varName = ${className}Peer.retrieveByPK($arglist);
+ $varName = ${className}Peer.retrieveByPK($arglist, connection);
#else
- $varName =
${className}Peer.retrieveByPK(SimpleKey.keyFor($arglist));
+ $varName =
${className}Peer.retrieveByPK(SimpleKey.keyFor($arglist), connection);
#end
#end
@@ -355,7 +408,7 @@
may be undesirable in many circumstances.
As it can lead to a db query with many results that may
never be used.
- $className obj = ${className}Peer.retrieveByPK($arglist);
+ $className obj = ${className}Peer.retrieveByPK($arglist,
connection);
obj.add${pCollName}(this);
*/
}
@@ -528,22 +581,39 @@
/**
#if ($objectIsCaching)
+ #if (!$silentDbFetch)
+ * returns the Collection.
+ #else
* If this collection has already been initialized, returns
* the collection. Otherwise returns the results of
* get${relCol}(new Criteria())
+ #end
#else
* A wrapper for get${relCol}(new Criteria())
#end
*
+ * @return the collection of associated objects
+ #if ($silentDbFetch)
* @throws TorqueException
+ #end
*/
- public List get${relCol}() throws TorqueException
+ public List get${relCol}()
+ #if ($silentDbFetch)
+ throws TorqueException
+ #end
{
#if ($objectIsCaching)
+ #if (!$silentDbFetch)
+ if (isNew())
+ {
+ init${relCol}();
+ }
+ #else
if ($collName == null)
{
$collName = get${relCol}(new Criteria(10));
}
+ #end
return $collName;
#else
return get${relCol}(new Criteria(10));
@@ -898,7 +968,7 @@
return $collName;
#else
- return
${className}Peer.doSelectJoinAllExcept${table.JavaName}${suffix}(criteria);
+ return
${className}Peer.doSelectJoinAllExcept${table.JavaName}${suffix}(criteria);
#end
}
@@ -1176,7 +1246,7 @@
*#
#end
- // If this object has been modified, then save it to the database.
+ // If this object has been modified, then save it to the database.
if (isModified())
{
if (isNew())
@@ -1550,10 +1620,19 @@
#end
${list}v = get${pCollName}();
- for (int i = 0; i < v.size(); i++)
+ ## v can be null if the generator property
+ ## torque.silentDbFetch is set to false
+ if (v != null)
+ {
+ for (int i = 0; i < v.size(); i++)
+ {
+ $className obj = ($className) v.get(i);
+ copyObj.add$pCollNameNoS(obj.copy());
+ }
+ }
+ else
{
- $className obj = ($className) v.get(i);
- copyObj.add$pCollNameNoS(obj.copy());
+ copyObj.coll${pCollName} = null;
}
#end
#set ( $list = "" )
@@ -1577,7 +1656,7 @@
}
#end
-#if ($generateBeans)
+#if ($generateBeans)
$generator.parse("om/bean/ObjectBeanMethods.vm",$path,"child",$child)
#end
Modified: db/torque/trunk/src/generator/src/templates/om/ObjectWithManager.vm
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/templates/om/ObjectWithManager.vm?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/templates/om/ObjectWithManager.vm
(original)
+++ db/torque/trunk/src/generator/src/templates/om/ObjectWithManager.vm Mon Aug
15 10:36:54 2005
@@ -330,22 +330,33 @@
#end
/**
- * Get the associated $interfaceName object
+ * Returns the associated $interfaceName object.
+ #if ($silentDbFetch)
+ * If it was not retrieved before, the object is retrieved from
+ * the database
+ #end
*
* @return the associated $interfaceName object
+ #if ($silentDbFetch)
* @throws TorqueException
+ #end
*/
- public $interfaceName get${pVarName}() throws TorqueException
+ public $interfaceName get${pVarName}()
+ #if ($silentDbFetch)
+ throws TorqueException
+ #end
{
+ #if ($silentDbFetch)
if ($varName == null && ($conditional))
{
- #if ($argsize > 1)
+ #if ($argsize > 1)
SimpleKey[] keys = { $arglist };
return ${interfaceName}Manager.getInstance(new ComboKey(keys));
- #else
+ #else
return ${interfaceName}Manager.getInstance($arglist);
- #end
+ #end
}
+ #end
return $varName;
}
@@ -515,22 +526,39 @@
/**
#if ($objectIsCaching)
+ #if (!$silentDbFetch)
+ * returns the Collection.
+ #else
* If this collection has already been initialized, returns
* the collection. Otherwise returns the results of
* get${relCol}(new Criteria())
+ #end
#else
* A wrapper for get${relCol}(new Criteria())
#end
*
+ * @return the collection of associated objects
+ #if ($silentDbFetch)
* @throws TorqueException
+ #end
*/
- public List get${relCol}() throws TorqueException
+ public List get${relCol}()
+ #if ($silentDbFetch)
+ throws TorqueException
+ #end
{
#if ($objectIsCaching)
+ #if (!$silentDbFetch)
+ if (isNew())
+ {
+ init${relCol}();
+ }
+ #else
if ($collName == null)
{
$collName = get${relCol}(new Criteria(10));
}
+ #end
return $collName;
#else
return get${relCol}(new Criteria(10));
@@ -1560,10 +1588,19 @@
#end
${list}v = get${pCollName}();
- for (int i = 0; i < v.size(); i++)
+ ## v can be null if the generator property
+ ## torque.silentDbFetch is set to false
+ if (v != null)
+ {
+ for (int i = 0; i < v.size(); i++)
+ {
+ $className obj = ($className) v.get(i);
+ copyObj.add$pCollNameNoS(obj.copy());
+ }
+ }
+ else
{
- $className obj = ($className) v.get(i);
- copyObj.add$pCollNameNoS(obj.copy());
+ copyObj.coll${pCollName} = null;
}
#end
#set ( $list = "" )
Modified: db/torque/trunk/src/maven-plugin/plugin.properties
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/src/maven-plugin/plugin.properties?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/src/maven-plugin/plugin.properties (original)
+++ db/torque/trunk/src/maven-plugin/plugin.properties Mon Aug 15 10:36:54 2005
@@ -24,6 +24,10 @@
# DO NOT EDIT THIS FILE - If you need to change the values found
# in this file, override them in your project.properties or
# build.properties file.
+#
+# This file contains the default properties for the maven plugin.
+# Whenever you use any torque target in maven, these properties
+# will be used as default.
# -------------------------------------------------------------------
# -------------------------------------------------------------------
@@ -124,6 +128,7 @@
torque.useClasspath = ${useClasspath}
torque.useManagers = ${useManagers}
torque.objectIsCaching = true
+torque.silentDbFetch = true
torque.correctGetters = false
torque.generateBeans = ${generateBeans}
torque.beanSuffix = ${beanSuffix}
Modified: db/torque/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewcvs/db/torque/trunk/xdocs/changes.xml?rev=232837&r1=232836&r2=232837&view=diff
==============================================================================
--- db/torque/trunk/xdocs/changes.xml (original)
+++ db/torque/trunk/xdocs/changes.xml Mon Aug 15 10:36:54 2005
@@ -28,6 +28,17 @@
<body>
<release version="3.2-rc2-dev" date="in CVS">
+ <action type="add" dev="tfischer">
+ Added a method getXXX(connection) to retrieve associated objects
+ in the n->1 direction, which uses the provided connection
+ if a db hit is necessary
+ </action>
+ <action type="add" dev="tfischer">
+ Added a generator property torque.silentDbFetch, which is true by
default.
+ If set to false, the getXXX() methods without arguments will not access
+ the db silently, but return null if the associated objects has not been
+ read yet. Also, the method does not throw a Torque exception any more.
+ </action>
<action type="update" dev="tfischer">
Reworked the tutorial.
</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]