You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2012/10/03 02:59:33 UTC
svn commit: r1393248 - in /db/torque/torque4/trunk:
torque-templates/src/main/resources/org/apache/torque/templates/om/conf/
torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/
torque-templates/src/main/resources/org/apache/torq...
Author: tfischer
Date: Wed Oct 3 00:59:32 2012
New Revision: 1393248
URL: http://svn.apache.org/viewvc?rev=1393248&view=rev
Log:
TORQUE-227: Change handling of fillerChunkSize in filler methods
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeConstant.vm
Removed:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeGetter.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillerChunkSizeGetter.vm
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.xml
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerForViewImpl.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencingObjects.vm
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/FillerTest.java
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties Wed Oct 3 00:59:32 2012
@@ -165,7 +165,7 @@ torque.om.complexObjectModel.generateDoS
# data objects related by a foreign key relation for a list of other
# data objects.
# This setting has no effect if torque.om.objectIsCaching is NOT set to true,
-# in this case no fillers qre generated even if the property below is set
+# in this case no fillers are generated even if the property below is set
# to true
torque.om.complexObjectModel.generateFillers = false
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml Wed Oct 3 00:59:32 2012
@@ -47,6 +47,9 @@
element="column"
outlet="torque.om.peer.base.columnConstant"/>
</mergepoint>
+ <mergepoint name="fillerChunkSizeConstant">
+ <action xsi:type="applyAction" outlet="torque.om.peer.base.fillerChunkSizeConstant"/>
+ </mergepoint>
<mergepoint name="peerImplField">
<action xsi:type="applyAction" outlet="torque.om.peer.base.peerImplField"/>
</mergepoint>
@@ -131,10 +134,6 @@
element="referencing-foreign-keys/foreign-key/foreign-field"
outlet="torque.om.peer.base.fillReferencingObjects"/>
</mergepoint>
- <mergepoint name="fillerChunkSizeGetter">
- <action xsi:type="applyAction"
- outlet="torque.om.peer.base.fillerChunkSizeGetter"/>
- </mergepoint>
<mergepoint name="getTableMap">
<action xsi:type="applyAction" outlet="torque.om.peer.base.getTableMap"/>
</mergepoint>
@@ -170,6 +169,9 @@
element="column"
outlet="torque.om.peer.base.columnConstant"/>
</mergepoint>
+ <mergepoint name="fillerChunkSizeConstant">
+ <action xsi:type="applyAction" outlet="torque.om.peer.base.fillerChunkSizeConstant"/>
+ </mergepoint>
<mergepoint name="peerImplField">
<action xsi:type="applyAction" outlet="torque.om.peer.base.peerImplField"/>
</mergepoint>
@@ -257,6 +259,11 @@
path="peer/base/columnConstant.vm">
</outlet>
+ <outlet name="torque.om.peer.base.fillerChunkSizeConstant"
+ xsi:type="velocityOutlet"
+ path="peer/base/fillerChunkSizeConstant.vm">
+ </outlet>
+
<outlet name="torque.om.peer.base.tableDatabaseNameConstantsInit"
xsi:type="velocityOutlet"
path="peer/base/tableDatabaseNameConstantsInit.vm">
@@ -420,11 +427,6 @@
path="peer/base/fillReferencingObjects.vm">
</outlet>
- <outlet name="torque.om.peer.base.fillerChunkSizeGetter"
- xsi:type="velocityOutlet"
- path="peer/base/fillerChunkSizeGetter.vm">
- </outlet>
-
<outlet name="torque.om.peer.base.getTableMap"
xsi:type="velocityOutlet"
path="peer/base/getTableMap.vm">
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.xml?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerImpl.xml Wed Oct 3 00:59:32 2012
@@ -107,10 +107,6 @@
element="referencing-foreign-keys/foreign-key/foreign-field"
outlet="torque.om.peer.impl.base.fillReferencingObjects"/>
</mergepoint>
- <mergepoint name="fillerChunkSizeGetter">
- <action xsi:type="applyAction"
- outlet="torque.om.peer.impl.base.fillerChunkSizeGetter"/>
- </mergepoint>
<mergepoint name="extensions" />
</outlet>
@@ -243,9 +239,4 @@
path="peer/impl/base/fillReferencingObjects.vm">
</outlet>
- <outlet name="torque.om.peer.impl.base.fillerChunkSizeGetter"
- xsi:type="velocityOutlet"
- path="peer/impl/base/fillerChunkSizeGetter.vm">
- </outlet>
-
</outlets>
\ No newline at end of file
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm Wed Oct 3 00:59:32 2012
@@ -44,6 +44,9 @@ $torqueGen.mergepoint("tableConstant")
$torqueGen.mergepoint("columnConstants")
$torqueGen.mergepoint("numColumnConstant")
$torqueGen.mergepoint("inheritanceClasskeyConstants")
+#if (($complexObjectModel == "true") && ($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
+$torqueGen.mergepoint("fillerChunkSizeConstant")
+#end
$torqueGen.mergepoint("peerImplField")
$torqueGen.mergepoint("staticInit")
$torqueGen.mergepoint("peerImplCreator")
@@ -74,7 +77,6 @@ $torqueGen.mergepoint("doSelectJoinAllEx
#if (($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
$torqueGen.mergepoint("fillReferencedObjects")
$torqueGen.mergepoint("fillReferencingObjects")
-$torqueGen.mergepoint("fillerChunkSizeGetter")
#end
#end
$torqueGen.mergepoint("getTableMap")
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm Wed Oct 3 00:59:32 2012
@@ -45,6 +45,9 @@ $torqueGen.mergepoint("tableMapConstant"
$torqueGen.mergepoint("columnConstants")
$torqueGen.mergepoint("numColumnConstant")
$torqueGen.mergepoint("inheritanceClasskeyConstants")
+#if (($complexObjectModel == "true") && ($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
+$torqueGen.mergepoint("fillerChunkSizeConstant")
+#end
$torqueGen.mergepoint("peerImplField")
$torqueGen.mergepoint("staticInit")
$torqueGen.mergepoint("peerImplCreator")
@@ -60,6 +63,17 @@ $torqueGen.mergepoint("buildSelectCriter
$torqueGen.mergepoint("buildColumnValues")
$torqueGen.mergepoint("retrieveByPK")
$torqueGen.mergepoint("retrieveByPKs")
+#if ($complexObjectModel == "true")
+ #if (($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateDoSelectJoin"))
+$torqueGen.mergepoint("doSelectJoin")
+$torqueGen.mergepoint("doSelectJoinAllExcept")
+ #end
+ #if (($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
+$torqueGen.mergepoint("fillReferencedObjects")
+$torqueGen.mergepoint("fillReferencingObjects")
+$torqueGen.mergepoint("fillerChunkSizeGetter")
+ #end
+#end
$torqueGen.mergepoint("getTableMap")
$torqueGen.mergepoint("initDatabaseMap")
$torqueGen.mergepoint("extensions")
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencedObject.vm Wed Oct 3 00:59:32 2012
@@ -31,12 +31,15 @@
#set ( $peerImplGetter = $localTableElement.getAttribute("peerImplGetter") )
#set ( $localDbObjectClassName = $localTableElement.getAttribute("dbObjectClassName") )
#set ( $foreignTableElement = $foreignKeyElement.getChild("table") )
+#set ( $localPeerClassName = $localTableElement.getAttribute("peerClassName") )
#if ($foreignTableElement.getChild("primary-keys").getChildren().size() > 0)
/**
* Fills the referenced ${fieldType} objects in the ${field} fields
* of the objects in <code>toFill</code> by reading the database.
+ * ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE is used as chunk size.
*
- * @param toFill Contains the objects to fill, not null, may not contain null.
+ * @param toFill Contains the objects to fill, not null,
+ * may not contain null.
*
* @return all read ${fieldType} objects.
*
@@ -54,7 +57,32 @@
* Fills the referenced ${fieldType} objects in the ${field} fields
* of the objects in <code>toFill</code> by reading the database.
*
- * @param toFill Contains the objects to fill, not null, may not contain null.
+ * @param toFill Contains the objects to fill, not null,
+ * may not contain null.
+ * @param chunkSize The maximum number of referencing objects
+ * to be filled by a single database request, or -1
+ * to fill all objects at once.
+ *
+ * @return all read ${fieldType} objects.
+ *
+ * @throws TorqueException if an error querying the database occurs.
+ * @throws NullPointerException if toFill is null or contains null elements.
+ */
+ public static List<${fieldType}> ${filler}(
+ Collection<${localDbObjectClassName}> toFill,
+ int chunkSize)
+ throws TorqueException
+ {
+ return ${peerImplGetter}().${filler}(toFill, chunkSize);
+ }
+
+ /**
+ * Fills the referenced ${fieldType} objects in the ${field} fields
+ * of the objects in <code>toFill</code> by reading the database.
+ * ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE is used as chunk size.
+ *
+ * @param toFill Contains the objects to fill, not null,
+ * may not contain null.
* @param connection the database connection to use, not null.
*
* @return all read ${fieldType} objects.
@@ -69,4 +97,29 @@
{
return ${peerImplGetter}().${filler}(toFill, connection);
}
+
+ /**
+ * Fills the referenced ${fieldType} objects in the ${field} fields
+ * of the objects in <code>toFill</code> by reading the database.
+ *
+ * @param toFill Contains the objects to fill, not null,
+ * may not contain null.
+ * @param chunkSize The maximum number of referencing objects
+ * to be filled by a single database request, or -1
+ * to fill all objects at once.
+ * @param connection the database connection to use, not null.
+ *
+ * @return all read ${fieldType} objects.
+ *
+ * @throws TorqueException if an error querying the database occurs.
+ * @throws NullPointerException if toFill is null or contains null elements.
+ */
+ public static List<${fieldType}> ${filler}(
+ Collection<${localDbObjectClassName}> toFill,
+ int chunkSize,
+ Connection connection)
+ throws TorqueException
+ {
+ return ${peerImplGetter}().${filler}(toFill, chunkSize, connection);
+ }
#end
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillReferencingObjects.vm Wed Oct 3 00:59:32 2012
@@ -31,10 +31,12 @@
#set ( $peerImplGetter = $localTableElement.getAttribute("peerImplGetter") )
#set ( $localDbObjectClassName = $localTableElement.getAttribute("dbObjectClassName") )
#set ( $foreignTableElement = $foreignKeyElement.getParent() )
+#set ( $localPeerClassName = $localTableElement.getAttribute("peerClassName") )
#if ($foreignTableElement.getChild("primary-keys").getChildren().size() > 0)
/**
* Fills the referenced ${fieldContainedType} objects in the ${field} fields
* of the objects in <code>toFill</code> by reading the database.
+ * ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE is used as chunk size.
*
* @param toFill Contains the objects to fill, not null, may not contain null.
*
@@ -55,6 +57,29 @@
* of the objects in <code>toFill</code> by reading the database.
*
* @param toFill Contains the objects to fill, not null, may not contain null.
+ * @param chunkSize The maximum number of referencing objects
+ * to be filled by a single database request, or -1
+ * to fill all objects at once.
+ *
+ * @return all read ${fieldType} objects.
+ *
+ * @throws TorqueException if an error querying the database occurs.
+ * @throws NullPointerException if toFill is null or contains null elements.
+ */
+ public static List<${fieldContainedType}> ${filler}(
+ Collection<${localDbObjectClassName}> toFill,
+ int chunkSize)
+ throws TorqueException
+ {
+ return ${peerImplGetter}().${filler}(toFill, chunkSize);
+ }
+
+ /**
+ * Fills the referenced ${fieldContainedType} objects in the ${field} fields
+ * of the objects in <code>toFill</code> by reading the database.
+ * ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE is used as chunk size.
+ *
+ * @param toFill Contains the objects to fill, not null, may not contain null.
* @param connection the database connection to use, not null.
*
* @return all read ${fieldType} objects.
@@ -69,4 +94,29 @@
{
return ${peerImplGetter}().${filler}(toFill, connection);
}
+
+ /**
+ * Fills the referenced ${fieldContainedType} objects in the ${field} fields
+ * of the objects in <code>toFill</code> by reading the database.
+ *
+ * @param toFill Contains the objects to fill, not null, may not contain null.
+ * @param chunkSize The maximum number of referencing objects
+ * to be filled by a single database request, or -1
+ * to fill all objects at once.
+ * @param connection the database connection to use, not null.
+ *
+ * @return all read ${fieldType} objects.
+ *
+ * @throws TorqueException if an error querying the database occurs.
+ * @throws NullPointerException if toFill is null or contains null elements.
+ */
+ public static List<${fieldContainedType}> ${filler}(
+ Collection<${localDbObjectClassName}> toFill,
+ int chunkSize,
+ Connection connection)
+ throws TorqueException
+ {
+ return ${peerImplGetter}().${filler}(toFill, chunkSize, connection);
+ }
+
#end
Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeConstant.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeConstant.vm?rev=1393248&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeConstant.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/fillerChunkSizeConstant.vm Wed Oct 3 00:59:32 2012
@@ -0,0 +1,29 @@
+## 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.
+##
+######
+##
+## version $Id: columnConstant.vm 1374508 2012-08-18 03:57:20Z tfischer $
+##
+## Creates the constant for the default filler chunk size in the base peer
+## class.
+##
+## This template expects the current source element to be a "database" element
+## from the torque schema.
+##
+ /** The default chunk size for the filler methods. */
+ public static final int DEFAULT_FILLER_CHUNK_SIZE = ${torqueGen.option("torque.om.complexObjectModel.defaultFillerChunkSize")};
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerForViewImpl.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerForViewImpl.vm?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerForViewImpl.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerForViewImpl.vm Wed Oct 3 00:59:32 2012
@@ -63,7 +63,6 @@ $torqueGen.mergepoint("doSelectJoinAllEx
#if (($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
$torqueGen.mergepoint("fillReferencedObjects")
$torqueGen.mergepoint("fillReferencingObjects")
-$torqueGen.mergepoint("fillerChunkSizeGetter")
#end
#end
$torqueGen.mergepoint("extensions")
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/basePeerImpl.vm Wed Oct 3 00:59:32 2012
@@ -63,7 +63,6 @@ $torqueGen.mergepoint("doSelectJoinAllEx
#if (($objectIsCaching == "true") && $torqueGen.booleanOption("torque.om.complexObjectModel.generateFillers"))
$torqueGen.mergepoint("fillReferencedObjects")
$torqueGen.mergepoint("fillReferencingObjects")
-$torqueGen.mergepoint("fillerChunkSizeGetter")
#end
#end
$torqueGen.mergepoint("extensions")
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencedObject.vm Wed Oct 3 00:59:32 2012
@@ -41,6 +41,7 @@
/**
* Fills the referenced ${fieldType} objects in the ${field} fields
* of the objects in <code>toFill</code> by reading the database.
+ * ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE is used as chunk size.
*
* @param toFill Contains the objects to fill, not null,
* may not contain null.
@@ -54,12 +55,38 @@
Collection<${localDbObjectClassName}> toFill)
throws TorqueException
{
+ return ${filler}(
+ toFill,
+ ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE);
+ }
+
+ /**
+ * Fills the referenced ${fieldType} objects in the ${field} fields
+ * of the objects in <code>toFill</code> by reading the database.
+ *
+ * @param toFill Contains the objects to fill, not null,
+ * may not contain null.
+ * @param chunkSize The maximum number of referencing objects
+ * to be filled by a single database request, or -1
+ * to fill all objects at once.
+ *
+ * @return all read ${fieldType} objects.
+ *
+ * @throws TorqueException if an error querying the database occurs.
+ * @throws NullPointerException if toFill is null or contains null elements.
+ */
+ public List<${fieldType}> ${filler}(
+ Collection<${localDbObjectClassName}> toFill,
+ int chunkSize)
+ throws TorqueException
+ {
Connection connection = null;
try
{
connection = Transaction.begin(
${localPeerClassName}.DATABASE_NAME);
- List<${fieldType}> result = ${filler}(toFill, connection);
+ List<${fieldType}> result
+ = ${filler}(toFill, chunkSize, connection);
Transaction.commit(connection);
connection = null;
return result;
@@ -76,9 +103,37 @@
/**
* Fills the referenced ${fieldType} objects in the ${field} fields
* of the objects in <code>toFill</code> by reading the database.
+ * ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE is used as chunk size.
+ *
+ * @param toFill Contains the objects to fill, not null,
+ * may not contain null.
+ * @param connection the database connection to use, not null.
+ *
+ * @return all read ${fieldType} objects.
+ *
+ * @throws TorqueException if an error querying the database occurs.
+ * @throws NullPointerException if toFill is null or contains null elements.
+ */
+ public List<${fieldType}> ${filler}(
+ Collection<${localDbObjectClassName}> toFill,
+ Connection connection)
+ throws TorqueException
+ {
+ return ${filler}(
+ toFill,
+ ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE,
+ connection);
+ }
+
+ /**
+ * Fills the referenced ${fieldType} objects in the ${field} fields
+ * of the objects in <code>toFill</code> by reading the database.
*
* @param toFill Contains the objects to fill, not null,
* may not contain null.
+ * @param chunkSize The maximum number of referencing objects
+ * to be filled by a single database request, or -1
+ * to fill all objects at once.
* @param connection the database connection to use, not null.
*
* @return all read ${fieldType} objects.
@@ -88,6 +143,7 @@
*/
public List<${fieldType}> ${filler}(
Collection<${localDbObjectClassName}> toFill,
+ int chunkSize,
Connection connection)
throws TorqueException
{
@@ -100,18 +156,16 @@
foreignKeySet.add(foreignKey);
}
}
-
- int fillerChunkSize = getFillerChunkSize();
+
Iterator<ObjectKey> foreignKeyIt = foreignKeySet.iterator();
- List<ObjectKey> foreignKeyListChunk
- = new ArrayList<ObjectKey>(fillerChunkSize);;
+ List<ObjectKey> foreignKeyListChunk = new ArrayList<ObjectKey>();
Map<ObjectKey, ${fieldType}> referencedKeyTo${fieldType}Map
= new HashMap<ObjectKey, ${fieldType}>();
while (foreignKeyIt.hasNext())
{
ObjectKey currentKey = foreignKeyIt.next();
foreignKeyListChunk.add(currentKey);
- if (foreignKeyListChunk.size() < fillerChunkSize
+ if ((foreignKeyListChunk.size() < chunkSize || chunkSize == -1)
&& foreignKeyIt.hasNext())
{
continue;
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencingObjects.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencingObjects.vm?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencingObjects.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/fillReferencingObjects.vm Wed Oct 3 00:59:32 2012
@@ -41,6 +41,7 @@
/**
* Fills the referenced ${fieldContainedType} objects in the ${field} fields
* of the objects in <code>toFill</code> by reading the database.
+ * ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE is used as chunk size.
*
* @param toFill Contains the objects to fill, not null,
* may not contain null.
@@ -54,12 +55,40 @@
Collection<${localDbObjectClassName}> toFill)
throws TorqueException
{
+ return ${filler}(
+ toFill,
+ ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE);
+ }
+
+ /**
+ * Fills the referenced ${fieldContainedType} objects in the ${field} fields
+ * of the objects in <code>toFill</code> by reading the database.
+ *
+ * @param toFill Contains the objects to fill, not null,
+ * may not contain null.
+ * @param chunkSize The maximum number of referenced objects
+ * to be filled by a single database request, or -1
+ * to fill all objects at once.
+ *
+ * @return all read ${fieldType} objects.
+ *
+ * @throws TorqueException if an error querying the database occurs.
+ * @throws NullPointerException if toFill is null or contains null elements.
+ */
+ public List<${fieldContainedType}> ${filler}(
+ Collection<${localDbObjectClassName}> toFill,
+ int chunkSize)
+ throws TorqueException
+ {
Connection connection = null;
try
{
connection = Transaction.begin(
${localPeerClassName}.DATABASE_NAME);
- List<${fieldContainedType}> result = ${filler}(toFill, connection);
+ List<${fieldContainedType}> result = ${filler}(
+ toFill,
+ chunkSize,
+ connection);
Transaction.commit(connection);
connection = null;
return result;
@@ -76,9 +105,37 @@
/**
* Fills the referenced ${fieldContainedType} objects in the ${field} fields
* of the objects in <code>toFill</code> by reading the database.
+ * ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE is used as chunk size.
+ *
+ * @param toFill Contains the objects to fill, not null,
+ * may not contain null.
+ * @param connection the database connection to use, not null.
+ *
+ * @return all read ${fieldType} objects.
+ *
+ * @throws TorqueException if an error querying the database occurs.
+ * @throws NullPointerException if toFill is null or contains null elements.
+ */
+ public List<${fieldContainedType}> ${filler}(
+ Collection<${localDbObjectClassName}> toFill,
+ Connection connection)
+ throws TorqueException
+ {
+ return ${filler}(
+ toFill,
+ ${localPeerClassName}.DEFAULT_FILLER_CHUNK_SIZE,
+ connection);
+ }
+
+ /**
+ * Fills the referenced ${fieldContainedType} objects in the ${field} fields
+ * of the objects in <code>toFill</code> by reading the database.
*
* @param toFill Contains the objects to fill, not null,
* may not contain null.
+ * @param chunkSize The maximum number of referenced objects
+ * to be filled by a single database request, or -1
+ * to fill all objects at once.
* @param connection the database connection to use, not null.
*
* @return all read ${fieldType} objects.
@@ -88,6 +145,7 @@
*/
public List<${fieldContainedType}> ${filler}(
Collection<${localDbObjectClassName}> toFill,
+ int chunkSize,
Connection connection)
throws TorqueException
{
@@ -117,17 +175,15 @@
localKeySet.add(localKey);
}
- int fillerChunkSize = getFillerChunkSize();
Iterator<ObjectKey> localKeyIt = localKeySet.iterator();
- List<ObjectKey> localKeyListChunk
- = new ArrayList<ObjectKey>(fillerChunkSize);
+ List<ObjectKey> localKeyListChunk = new ArrayList<ObjectKey>();
Map<ObjectKey, List<${fieldContainedType}>> fkTo${fieldContainedType}Map
= new HashMap<ObjectKey, List<${fieldContainedType}>>();
while (localKeyIt.hasNext())
{
ObjectKey currentKey = localKeyIt.next();
localKeyListChunk.add(currentKey);
- if (localKeyListChunk.size() < fillerChunkSize
+ if ((localKeyListChunk.size() < chunkSize || chunkSize == -1)
&& localKeyIt.hasNext())
{
continue;
Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/FillerTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/FillerTest.java?rev=1393248&r1=1393247&r2=1393248&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/FillerTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/FillerTest.java Wed Oct 3 00:59:32 2012
@@ -567,6 +567,80 @@ public class FillerTest extends BaseData
}
/**
+ * Tests that the chunk size -1 works for filling referenced objects.
+ *
+ * @throws Exception if a database error occurs.
+ */
+ public void testFillReferencedChunkSizeMinus1() throws Exception
+ {
+ ForeignKeySchemaData.clearTablesInDatabase();
+ ForeignKeySchemaData testData
+ = ForeignKeySchemaData.getDefaultTestData();
+ testData.save();
+
+ Criteria criteria = new Criteria();
+ criteria.addAscendingOrderByColumn(
+ RequiredPIntegerFkPeer.ID);
+ List<RequiredPIntegerFk> fkList
+ = RequiredPIntegerFkPeer.doSelect(criteria);
+ assertEquals(3, fkList.size());
+ assertEquals(
+ testData.getRequiredPIntegerFkList().get(0).getId(),
+ fkList.get(0).getId());
+ // TODO check that NullableIntFkList entries have not yet
+ // loaded their referenced intPk object
+
+ List<PIntegerPk> referencedPkList
+ = RequiredPIntegerFkPeer.fillPIntegerPks(
+ fkList);
+ // TODO check that NullableIntFkList entries have now
+ // loaded their referenced intPk object
+
+ // returned list must contain intPk2, intPk3, intPk3
+ // and the last 2 objects must not be the same objects
+ assertEquals(3, referencedPkList.size());
+ assertEquals(
+ testData.getPIntegerPkList().get(1).getId(),
+ referencedPkList.get(0).getId());
+ assertEquals(
+ testData.getPIntegerPkList().get(2).getId(),
+ referencedPkList.get(1).getId());
+ assertEquals(
+ testData.getPIntegerPkList().get(2).getId(),
+ referencedPkList.get(2).getId());
+ assertNotSame(
+ referencedPkList.get(1),
+ referencedPkList.get(2));
+
+ // the fk list must reference intPk2, intPk3, intPk3
+ // and the last 2 referenced objects must not be the same objects
+ assertEquals(
+ testData.getPIntegerPkList().get(1),
+ fkList.get(0).getPIntegerPk());
+ assertEquals(
+ testData.getPIntegerPkList().get(2),
+ fkList.get(1).getPIntegerPk());
+ assertEquals(
+ testData.getPIntegerPkList().get(2),
+ fkList.get(2).getPIntegerPk());
+ assertNotSame(
+ fkList.get(1).getPIntegerPk(),
+ fkList.get(2).getPIntegerPk());
+
+ // The objects in the result list must be the same objects
+ // as the referenced objects in the fk list
+ assertSame(
+ referencedPkList.get(0),
+ fkList.get(0).getPIntegerPk());
+ assertSame(
+ referencedPkList.get(1),
+ fkList.get(1).getPIntegerPk());
+ assertSame(
+ referencedPkList.get(2),
+ fkList.get(2).getPIntegerPk());
+ }
+
+ /**
* Tests that the fill method for referenced objects works for many rows
* in the database.
*/
@@ -654,6 +728,7 @@ public class FillerTest extends BaseData
assertEquals(
testData.getPIntegerPkList().get(0).getId(),
pkList.get(0).getId());
+ // check referencing lists are not initialized
for (PIntegerPk pIntegerPk : pkList)
{
assertFalse(pIntegerPk.isRequiredPIntegerFksInitialized());
@@ -732,8 +807,11 @@ public class FillerTest extends BaseData
assertEquals(
testData.getOIntegerPkList().get(0).getId(),
pkList.get(0).getId());
- // TODO check that pkList entries have not yet
- // loaded its referencing nullablePIntegerFk objects
+ // check referencing lists are not initialized
+ for (OIntegerPk oIntegerPk : pkList)
+ {
+ assertFalse(oIntegerPk.isNullableOIntegerFksInitialized());
+ }
List<NullableOIntegerFk> referencingFkList
= OIntegerPkPeer.fillNullableOIntegerFks(
@@ -870,8 +948,11 @@ public class FillerTest extends BaseData
assertEquals(
testData.getOIntegerPkList().get(0).getId(),
pkList.get(0).getId());
- // TODO check that pkList entries have not yet
- // loaded its referenced intPk object
+ // check referencing lists are not initialized
+ for (OIntegerPk oIntegerPk : pkList)
+ {
+ assertFalse(oIntegerPk.isNonPkOIntegerFksInitialized());
+ }
List<NonPkOIntegerFk> referencingFkList
= OIntegerPkPeer.fillNonPkOIntegerFks(pkList);
@@ -941,8 +1022,11 @@ public class FillerTest extends BaseData
assertEquals(
testData.getCompositeIntegerVarcharPkList().get(0).getPrimaryKey(),
pkList.get(0).getPrimaryKey());
- // TODO check that pkList entries have not yet
- // loaded its referencing nullablePIntegerFk objects
+ // check referencing lists are not initialized
+ for (CompIntegerVarcharPk compIntegerVarcharPk : pkList)
+ {
+ assertFalse(compIntegerVarcharPk.isCompIntegerVarcharFksInitialized());
+ }
List<CompIntegerVarcharFk> referencingFkList
= CompIntegerVarcharPkPeer.fillCompIntegerVarcharFks(
@@ -1015,8 +1099,11 @@ public class FillerTest extends BaseData
assertEquals(
testData.getCompositeIntegerVarcharPkList().get(0).getPrimaryKey(),
pkList.get(0).getPrimaryKey());
- // TODO check that pkList entries have not yet
- // loaded its referencing nullablePIntegerFk objects
+ // check referencing lists are not initialized
+ for (CompIntegerVarcharPk compIntegerVarcharPk : pkList)
+ {
+ assertFalse(compIntegerVarcharPk.isCompNonpkFksInitialized());
+ }
List<CompNonpkFk> referencingFkList
= CompIntegerVarcharPkPeer.fillCompNonpkFks(pkList);
@@ -1106,6 +1193,80 @@ public class FillerTest extends BaseData
}
/**
+ * Tests that the chunk size -1 works for referencing objects.
+ */
+ public void testReferencingObjectChunkSizeMinusOne() throws TorqueException
+ {
+ ForeignKeySchemaData.clearTablesInDatabase();
+ ForeignKeySchemaData testData
+ = ForeignKeySchemaData.getDefaultTestData();
+ testData.save();
+
+ Criteria criteria = new Criteria();
+ criteria.addAscendingOrderByColumn(PIntegerPkPeer.ID);
+ List<PIntegerPk> pkList = PIntegerPkPeer.doSelect(criteria);
+ assertEquals(3, pkList.size());
+ assertEquals(
+ testData.getPIntegerPkList().get(0).getId(),
+ pkList.get(0).getId());
+ // check referencing lists are not initialized
+ for (PIntegerPk pIntegerPk : pkList)
+ {
+ assertFalse(pIntegerPk.isRequiredPIntegerFksInitialized());
+ }
+
+ List<RequiredPIntegerFk> referencingFkList
+ = PIntegerPkPeer.fillRequiredPIntegerFks(pkList, -1);
+
+ // check all referencing lists are initialized
+ for (PIntegerPk pIntegerPk : pkList)
+ {
+ assertTrue(pIntegerPk.isRequiredPIntegerFksInitialized());
+ }
+ // returned list must contain requiredPIntegerFk2,
+ // requiredPIntegerFk3a, requiredPIntegerFk3b
+ // where the last two can be exchanged
+ assertEquals(3, referencingFkList.size());
+ assertEquals(
+ testData.getRequiredPIntegerFkList().get(0).getId(),
+ referencingFkList.get(0).getId());
+ assertTrue(
+ referencingFkList.contains(
+ testData.getRequiredPIntegerFkList().get(1)));
+ assertTrue(
+ referencingFkList.contains(
+ testData.getRequiredPIntegerFkList().get(2)));
+
+ // The second pk entry must reference requiredPIntegerFk2
+ // and the third pk entry must reference requiredPIntegerFk3a
+ // and requiredPIntegerFk3b
+ assertEquals(0, pkList.get(0).getRequiredPIntegerFks().size());
+ assertEquals(1, pkList.get(1).getRequiredPIntegerFks().size());
+ assertEquals(2, pkList.get(2).getRequiredPIntegerFks().size());
+ assertEquals(
+ testData.getRequiredPIntegerFkList().get(0),
+ pkList.get(1).getRequiredPIntegerFks().get(0));
+ assertTrue(
+ pkList.get(2).getRequiredPIntegerFks().contains(
+ testData.getRequiredPIntegerFkList().get(1)));
+ assertTrue(
+ pkList.get(2).getRequiredPIntegerFks().contains(
+ testData.getRequiredPIntegerFkList().get(2)));
+
+ // The objects in the result list must be the same objects
+ // as the referenced objects in the pk list
+ assertSame(
+ referencingFkList.get(0),
+ pkList.get(1).getRequiredPIntegerFks().get(0));
+ assertSame(
+ referencingFkList.get(1),
+ pkList.get(2).getRequiredPIntegerFks().get(0));
+ assertSame(
+ referencingFkList.get(2),
+ pkList.get(2).getRequiredPIntegerFks().get(1));
+ }
+
+ /**
* Tests that the fill method for referencing objects works for many rows
* in the database.
*/
@@ -1135,7 +1296,11 @@ public class FillerTest extends BaseData
criteria.addAscendingOrderByColumn(OIntegerPkPeer.ID);
List<OIntegerPk> pkObjectList = OIntegerPkPeer.doSelect(criteria);
assertEquals(MANY, pkObjectList.size());
- // TODO assert that pkObjectList have not already loaded their fk objects
+ // check referencing lists are not initialized
+ for (OIntegerPk oIntegerPk : pkObjectList)
+ {
+ assertFalse(oIntegerPk.isNullableOIntegerFksInitialized());
+ }
List<NullableOIntegerFk> nullableOIntegerFkList
= OIntegerPkPeer.fillNullableOIntegerFks(pkObjectList);
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org