db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1331179 [1/2] - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/ torque-runtime/src/main/java/org/apache/torque/criteria/ torque-runtime/src/main/java/org/apache/torque/oid/ torque-runtime/src/main/java/org/apac...
Date Fri, 27 Apr 2012 02:00:17 GMT
Author: tfischer
Date: Fri Apr 27 02:00:16 2012
New Revision: 1331179

URL: http://svn.apache.org/viewvc?rev=1331179&view=rev
Log:
TORQUE-196: Make transaction handling pluggable
TORQUE-195: Remove autocommit handling from Transaction management
TORQUE-187 	Allow joins with subselects in the FROM clause 

Added:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManager.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/JoinTest.java
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/WhereClauseSubselectTest.java
      - copied, changed from r1329656, db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SubselectTest.java
Removed:
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SubselectTest.java
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-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/JoinBuilder.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/PreparedStatementPart.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Transaction.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTestOldCriteria.java
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doDelete.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelectJoin.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelectJoinAllExcept.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.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/DataTest.java

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=1331179&r1=1331178&r2=1331179&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 Apr 27 02:00:16 2012
@@ -85,6 +85,11 @@ public final class Torque
     public static final String CACHE_KEY = "manager.useCache";
 
     /**
+     * The prefix for configuring the transaction manger.
+     */
+    public static final String TRANSACTION_MANAGER_KEY = "transactionManager";
+
+    /**
      * The single instance of {@link TorqueInstance} used by the
      * static API presented by this class.
      */

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=1331179&r1=1331178&r2=1331179&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 Apr 27 02:00:16 2012
@@ -41,6 +41,9 @@ import org.apache.torque.manager.Abstrac
 import org.apache.torque.map.DatabaseMap;
 import org.apache.torque.oid.IDBroker;
 import org.apache.torque.oid.IDGeneratorFactory;
+import org.apache.torque.util.Transaction;
+import org.apache.torque.util.TransactionManager;
+import org.apache.torque.util.TransactionManagerImpl;
 
 /**
  * The core of Torque's implementation.  Both the classic {@link
@@ -137,6 +140,7 @@ public class TorqueInstance
         // properties that are contained in the configuration. First
         // look for properties that are in the "torque" namespace.
 
+        initTransactionManager(conf);
         initDefaultDbName(conf);
         initDataSourceFactories(conf);
         initAdapters(conf);
@@ -191,6 +195,56 @@ public class TorqueInstance
      *        of the properties file.
      * @throws TorqueException if the appropriate key is not set.
      */
+    private void initTransactionManager(Configuration conf)
+            throws TorqueException
+    {
+        String transactionManagerClassName =
+                conf.getString(Torque.TRANSACTION_MANAGER_KEY);
+        TransactionManager transactionManager;
+        if (StringUtils.isEmpty(transactionManagerClassName))
+        {
+            if (log.isTraceEnabled())
+            {
+                log.trace("Configuration key " + Torque.TORQUE_KEY + "."
+                    + Torque.TRANSACTION_MANAGER_KEY
+                    + " not set, using default transaction manager "
+                    + TransactionManagerImpl.class.getName());
+            }
+            transactionManager = new TransactionManagerImpl();
+        }
+        else
+        {
+            try
+            {
+                Class<?> transactionManagerClass
+                        = Class.forName(transactionManagerClassName);
+                transactionManager = (TransactionManager)
+                        transactionManagerClass.newInstance();
+                if (log.isTraceEnabled())
+                {
+                    log.trace("Using transaction manager "
+                            + transactionManager.getClass().getName());
+                }
+            }
+            catch (Exception e)
+            {
+                log.error("Error handling transaction manager configuration",
+                        e);
+                throw new TorqueException(e);
+            }
+        }
+        Transaction.setTransactionManager(transactionManager);
+    }
+
+    /**
+     * Initializes the name of the default database and
+     * associates the database with the name <code>DEFAULT_NAME</code>
+     * to the default database.
+     *
+     * @param conf the configuration representing the torque section.
+     *        of the properties file.
+     * @throws TorqueException if the appropriate key is not set.
+     */
     private void initDefaultDbName(Configuration conf)
             throws TorqueException
     {

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java Fri Apr 27 02:00:16 2012
@@ -185,15 +185,14 @@ public class Criteria
 
     /**
      * Aliases for table names. The key of the map is the alias,
-     * and the value is the real name of the table.
+     * and the value is either the real name of the table
+     * or a corresponding subselect.
      */
-    private Map<String, String> aliases = new HashMap<String, String>();
+    private Map<String, Object> aliases = new HashMap<String, Object>();
 
     /** The JDBC statement fetch size, if any. */
     private Integer fetchSize;
 
-    private boolean useTransaction = false;
-
     /**
      * Creates a new instance with the default capacity.
      */
@@ -248,9 +247,10 @@ public class Criteria
     /**
      * Get the table aliases.
      *
-     * @return A Map which maps the table alias names to the actual table names.
+     * @return A Map which maps the table alias names to either the actual
+     *         table names (String) or to a subselect (Criteria).
      */
-    public Map<String, String> getAliases()
+    public Map<String, Object> getAliases()
     {
         return aliases;
     }
@@ -267,36 +267,68 @@ public class Criteria
     }
 
     /**
-     * Returns the table name associated with an alias.
+     * Allows one to specify an alias for a subselect.
      *
-     * @param alias a <code>String</code> value
-     * @return a <code>String</code> value
+     * @param alias the alias for the subselect.
+     * @param subselect the Criteria for the subselect.
      */
-    public String getTableForAlias(String alias)
+    public void addAlias(String alias, Criteria subselect)
     {
-        return aliases.get(alias);
+        aliases.put(alias, subselect);
     }
 
     /**
-     * Will force the sql represented by this criteria to be executed within
-     * a transaction.  This is here primarily to support the oid type in
-     * postgresql.  Though it can be used to require any single sql statement
-     * to use a transaction.
+     * Returns the database table name associated with an alias.
+     *
+     * @param alias a <code>String</code> value.
+     *
+     * @return a <code>String</code> value, or null if the alias is not defined.
+     *
+     * @throws IllegalArgumentException if the alias with the name
+     *         <code>alias</code> is defined but is no alias for a table name
+     *         (e.g. it is an alias for a subselect).
      */
-    public void setUseTransaction(boolean v)
+    public String getTableForAlias(String alias)
     {
-        useTransaction = v;
+        Object aliasResolved = aliases.get(alias);
+        if (aliasResolved == null)
+        {
+            return null;
+        }
+        if (aliasResolved instanceof String)
+        {
+            return (String) aliasResolved;
+        }
+        throw new IllegalArgumentException("The alias " + alias
+                + " is not associated to a table but to an object of type "
+                + alias.getClass().getName());
     }
 
     /**
-     * called by BasePeer to determine whether the sql command specified by
-     * this criteria must be wrapped in a transaction.
+     * Returns the subselect associated with an alias.
+     *
+     * @param alias a <code>String</code> value.
+     *
+     * @return a <code>String</code> value, or null if the alias is not defined.
      *
-     * @return a <code>boolean</code> value
+     * @throws IllegalArgumentException if the alias with the name
+     *         <code>alias</code> is defined but is not an alias for a subselect
+     *         (e.g. it is an alias for a table).
      */
-    public boolean isUseTransaction()
+    public Criteria getSubselectForAlias(String alias)
     {
-        return useTransaction;
+        Object aliasResolved = aliases.get(alias);
+        if (aliasResolved == null)
+        {
+            return null;
+        }
+        if (aliasResolved instanceof Criteria)
+        {
+            return (Criteria) aliasResolved;
+        }
+        throw new IllegalArgumentException("The alias " + alias
+                + " is not associated to a subselect but to an object of type "
+                + alias.getClass().getName());
     }
 
     /**

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java Fri Apr 27 02:00:16 2012
@@ -32,6 +32,8 @@ import org.apache.torque.util.UniqueList
  * Interface for both the old org.apache.torque.util and the new
  * org.apache.torque.criteria Criteria class.
  *
+ * @param <T> the implementation class
+ *
  * @version $Id: $
  *
  * @deprecated This interface will only exist temporarily and will be removed
@@ -52,7 +54,7 @@ public interface CriteriaInterface<T>
      *
      * @return A Map which maps the table alias names to the actual table names.
      */
-    Map<String, String> getAliases();
+    Map<String, ? extends Object> getAliases();
 
     /**
      * Allows one to specify an alias for a table that can
@@ -72,14 +74,6 @@ public interface CriteriaInterface<T>
     String getTableForAlias(String alias);
 
     /**
-     * Will force the sql represented by this criteria to be executed within
-     * a transaction.  This is here primarily to support the oid type in
-     * postgresql.  Though it can be used to require any single sql statement
-     * to use a transaction.
-     */
-    void setUseTransaction(boolean v);
-
-    /**
      * Get the Database(Map) name.
      *
      * @return A String with the Database(Map) name.  By default, this
@@ -177,7 +171,7 @@ public interface CriteriaInterface<T>
      *        by a query.
      * @return A modified Criteria object.
      */
-    public T setLimit(int limit);
+    T setLimit(int limit);
 
     /**
      * Set the offset.
@@ -186,5 +180,5 @@ public interface CriteriaInterface<T>
      *        result.
      * @return A modified Criteria object.
      */
-    public T setOffset(long offset);
+    T setOffset(long offset);
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java Fri Apr 27 02:00:16 2012
@@ -19,6 +19,9 @@ package org.apache.torque.criteria;
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 
@@ -31,8 +34,11 @@ import org.apache.commons.lang.builder.H
  */
 public class FromElement
 {
-    /** The tablename, might contain an appended alias name */
-    private String tableName = null;
+    /**
+     * The fromExpression, e.g. a simple table name or a table name
+     * or a subquery with an appended alias name.
+     */
+    private String fromExpression = null;
 
     /** The type of the join, e.g. SqlEnum.LEFT_JOIN */
     private SqlEnum joinType = null;
@@ -40,6 +46,10 @@ public class FromElement
     /** The join condition, e.g. table_a.id = table_b.a_id */
     private String joinCondition = null;
 
+    /** The replacements which might occur in the fromExpression. */
+    private List<Object> preparedStatementReplacements
+            = new ArrayList<Object>();
+
     /**
      * Constructor with join type null and joinCondition null.
      * @param tableName the table name, might contain an appended alias name
@@ -49,12 +59,13 @@ public class FromElement
      */
     public FromElement(String tableName)
     {
-        this(tableName, null, null);
+        this(tableName, null, null, null);
     }
 
     /**
      * Constructor
-     * @param tableName the tablename, might contain an appended alias name
+     * @param fromExpression the expression to add to the from clause,
+     *        e.g. a simple table name or a table name with an alias,
      *        e.g. <br />
      *        table_1<br />
      *        table_1 alias_for_table_1
@@ -66,13 +77,45 @@ public class FromElement
      *        (In this case, the join condition is appended to the
      *         whereClause instead)
      */
-    public FromElement(String tableName,
+    public FromElement(
+            String fromExpression,
             SqlEnum joinType,
             String joinCondition)
     {
-        this.tableName = tableName;
+        this(fromExpression, joinType, joinCondition, null);
+    }
+
+    /**
+     * Constructor
+     * @param fromExpression the expression to add to the from clause,
+     *        e.g. a simple table name or a table name with an alias,
+     *        e.g. <br />
+     *        table_1<br />
+     *        table_1 alias_for_table_1
+     * @param joinType the type of the join, e.g. SqlEnum.LEFT_JOIN,
+     *        or null if no explicit join is wanted
+     * @param joinCondition the join condition,
+     *        e.g. table_a.id = table_b.a_id,
+     *        or null if no explicit join is wanted
+     *        (In this case, the join condition is appended to the
+     *         whereClause instead)
+     * @param preparedStatementReplacements the replacements for placeholders
+     *        which might occur in the fromExpression, may be null.
+     */
+    public FromElement(
+            String fromExpression,
+            SqlEnum joinType,
+            String joinCondition,
+            List<Object> preparedStatementReplacements)
+    {
+        this.fromExpression = fromExpression;
         this.joinType = joinType;
         this.joinCondition = joinCondition;
+        if (preparedStatementReplacements != null)
+        {
+            this.preparedStatementReplacements.addAll(
+                    preparedStatementReplacements);
+        }
     }
 
 
@@ -95,15 +138,29 @@ public class FromElement
     }
 
     /**
+     * Returns the fromExpression, which might e.g. be a simple table name or
+     *         a table name or a subquery with an alias appended.
      * @return the tablename, might contain an appended alias name,
      *         e.g. <br />
      *         table_1<br />
      *         table_1 alias_for_table_1
      *
      */
-    public String getTableName()
+    public String getFromExpression()
+    {
+        return fromExpression;
+    }
+
+    /**
+     * Returns the replacements for prepared statement placeholders in the
+     * fromExpression.
+     *
+     * @return the replacements, not null.
+
+     */
+    public List<Object> getPreparedStatementReplacements()
     {
-        return tableName;
+        return preparedStatementReplacements;
     }
 
     /**
@@ -117,7 +174,7 @@ public class FromElement
         {
             result.append(joinType);
         }
-        result.append(tableName);
+        result.append(fromExpression);
         if (joinCondition != null)
         {
             result.append(SqlEnum.ON);
@@ -133,7 +190,8 @@ public class FromElement
         return new HashCodeBuilder()
                 .append(joinCondition)
                 .append(joinType)
-                .append(tableName)
+                .append(fromExpression)
+                .append(preparedStatementReplacements)
                 .toHashCode();
     }
 
@@ -157,7 +215,9 @@ public class FromElement
         return new EqualsBuilder()
             .append(joinCondition, other.joinCondition)
             .append(joinType, other.joinType)
-            .append(tableName, other.tableName)
+            .append(fromExpression, other.fromExpression)
+            .append(preparedStatementReplacements,
+                    other.preparedStatementReplacements)
             .isEquals();
     }
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java Fri Apr 27 02:00:16 2012
@@ -682,8 +682,7 @@ public class IDBroker implements Runnabl
         {
             if (useNewConnection)
             {
-                connection = Transaction.beginOptional(databaseName,
-                    transactionsSupported);
+                connection = Transaction.begin(databaseName);
             }
 
             // Write the current value of quantity of keys to grab

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/JoinBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/JoinBuilder.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/JoinBuilder.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/JoinBuilder.java Fri Apr 27 02:00:16 2012
@@ -59,9 +59,9 @@ public final class JoinBuilder
      * @throws TorqueException if the Joins can not be processed
      */
     public static void processJoins(
-            final Database database,
-            final CriteriaInterface criteria,
-            final Query query)
+                final Database database,
+                final CriteriaInterface criteria,
+                final Query query)
             throws TorqueException
     {
         List<Join> criteriaJoins = criteria.getJoins();
@@ -105,12 +105,14 @@ public final class JoinBuilder
             {
                 // get the table names
                 // (and the alias names for them if necessary))
-                String leftTableName = SqlBuilder.getTableNameForFromClause(
+                PreparedStatementPart leftExpression
+                    = SqlBuilder.getExpressionForFromClause(
                         leftColumn,
                         database,
                         criteria);
 
-                String rightTableName = SqlBuilder.getTableNameForFromClause(
+                PreparedStatementPart rightExpression
+                    = SqlBuilder.getExpressionForFromClause(
                         rightColumn,
                         database,
                         criteria);
@@ -119,52 +121,54 @@ public final class JoinBuilder
                 // This if the case if the fromClause already contains
                 // rightTableName
 
-                if (!SqlBuilder.fromClauseContainsTableName(
+                if (!SqlBuilder.fromClauseContainsExpression(
                             queryFromClause,
-                            rightTableName))
+                            rightExpression))
                 {
-                    if (!SqlBuilder.fromClauseContainsTableName(
+                    if (!SqlBuilder.fromClauseContainsExpression(
                                 queryFromClause,
-                                leftTableName))
+                                leftExpression))
                     {
-                        FromElement fromElement
-                                = new FromElement(
-                                        leftTableName, null, null);
+                        FromElement fromElement = new FromElement(
+                            leftExpression.getSql().toString(),
+                            null,
+                            null,
+                            leftExpression.getPreparedStatementReplacements());
                         queryFromClause.add(fromElement);
                     }
 
-                    FromElement fromElement
-                            = new FromElement(
-                                    rightTableName,
-                                    joinType,
-                                    buildJoinCondition(
-                                            leftColumn, rightColumn));
+                    FromElement fromElement = new FromElement(
+                            rightExpression.getSql().toString(),
+                            joinType,
+                            buildJoinCondition(leftColumn, rightColumn),
+                            rightExpression.getPreparedStatementReplacements());
                     queryFromClause.add(fromElement);
                 }
                 else
                 {
-                    if (SqlBuilder.fromClauseContainsTableName(
+                    if (SqlBuilder.fromClauseContainsExpression(
                                 queryFromClause,
-                                leftTableName))
+                                leftExpression))
                     {
                         // We cannot add an explicit join if both tables
                         // are alredy present in the from clause
                         throw new TorqueException(
-                                "Unable to create a " + joinType
-                                + "because both table names "
-                                + leftTableName + " and " + rightTableName
+                                "Unable to create a" + joinType
+                                + "because both expressions "
+                                + leftExpression.getSql()
+                                + " and " + rightExpression.getSql()
                                 + " are already in use. "
                                 + "Try to create an(other) alias.");
                     }
                     // now add the join in reverse order
                     // rightTableName must not be added
                     // because it is already present
-                    FromElement fromElement
-                            = new FromElement(
-                                    leftTableName,
-                                    reverseJoinType(joinType),
-                                    buildJoinCondition(
-                                            rightColumn, leftColumn));
+                    FromElement fromElement = new FromElement(
+                        leftExpression.getSql().toString(),
+                        reverseJoinType(joinType),
+                        buildJoinCondition(
+                                rightColumn, leftColumn),
+                        leftExpression.getPreparedStatementReplacements());
                     queryFromClause.add(fromElement);
                 }
             }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/PreparedStatementPart.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/PreparedStatementPart.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/PreparedStatementPart.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/PreparedStatementPart.java Fri Apr 27 02:00:16 2012
@@ -20,8 +20,10 @@ package org.apache.torque.sql;
  */
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 /**
@@ -43,6 +45,35 @@ public class PreparedStatementPart
         = new ArrayList<Object>();
 
     /**
+     * Default constructor, creates an empty PreparedStatementPart.
+     */
+    public PreparedStatementPart()
+    {
+    }
+
+    /**
+     * Constructor, creates a pre-filled PreparedStatementPart.
+     *
+     * @param sql The sql to fill into the sql buffer initially, or null.
+     * @param preparedStatementReplacements the prepared statement replacements
+     *        to start with, or null.
+     */
+    public PreparedStatementPart(
+            String sql,
+            Object... preparedStatementReplacements)
+    {
+        if (!StringUtils.isEmpty(sql))
+        {
+            this.sql.append(sql);
+        }
+        if (preparedStatementReplacements != null)
+        {
+            this.preparedStatementReplacements.addAll(
+                    Arrays.asList(preparedStatementReplacements));
+        }
+    }
+
+    /**
      * Returns the SQL of the part.
      *
      * @return the SQL as mutable StringBuilder, not null.

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java Fri Apr 27 02:00:16 2012
@@ -20,6 +20,7 @@ package org.apache.torque.sql;
  */
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -94,12 +95,13 @@ public class Query
      */
 
     private UniqueList<String> columns = new UniqueList<String>();
+
     /**
      * The tables to select from (including join operators) for
      * a select clause, or the tables to update or delete for update
      * or delete statements.
      */
-    private UniqueList<FromElement> tables = new UniqueList<FromElement>();
+    private UniqueList<FromElement> fromClause = new UniqueList<FromElement>();
 
     /**
      * The where clause identifying the rows to select/update/delete.
@@ -108,9 +110,9 @@ public class Query
 
     /**
      * Contains all replacement objects which are inserted into the prepared
-     * statement ? placeholders.
+     * statement ? placeholders for the where Clause.
      */
-    private List<Object> preparedStatementReplacements
+    private List<Object> whereClausePreparedStatementReplacements
             = new ArrayList<Object>();
 
     /** The order by columns, possibly including direction (ASC or DESC). */
@@ -185,7 +187,7 @@ public class Query
      */
     public UniqueList<FromElement> getFromClause()
     {
-        return tables;
+        return fromClause;
     }
 
     /**
@@ -202,15 +204,32 @@ public class Query
 
     /**
      * Retrieves the replacements which are inserted into prepared statement
-     * placeholders. The number and order of the elements in the list
-     * must correspond to the order of the placeholders in the query string.
+     * placeholders in the where clause.
+     * The number and order of the elements in the list must correspond
+     * to the order of the placeholders in the where clause string.
      *
      * @return A List containing all the replacements for the prepared
      *         statement placeholders, not null.
      */
+    public List<Object> getWhereClausePreparedStatementReplacements()
+    {
+        return whereClausePreparedStatementReplacements;
+    }
+
+    /**
+     * Returns all preparedStatementReplacements in the query.
+     *
+     * @return an unmodifiable list of all preparedStatementReplacements.
+     */
     public List<Object> getPreparedStatementReplacements()
     {
-        return preparedStatementReplacements;
+        ArrayList<Object> result = new ArrayList<Object>();
+        for (FromElement fromElement : fromClause)
+        {
+            result.addAll(fromElement.getPreparedStatementReplacements());
+        }
+        result.addAll(whereClausePreparedStatementReplacements);
+        return Collections.unmodifiableList(result);
     }
 
     /**
@@ -473,7 +492,7 @@ public class Query
         }
 
         boolean first = true;
-        for (Iterator<FromElement> it = tables.iterator(); it.hasNext();)
+        for (Iterator<FromElement> it = fromClause.iterator(); it.hasNext();)
         {
             FromElement fromElement = it.next();
 
@@ -552,7 +571,7 @@ public class Query
         toStringBuilder(stringBuilder);
         stringBuilder.append(" Replacements: [");
         boolean first = true;
-        for (Object replacement : preparedStatementReplacements)
+        for (Object replacement : getPreparedStatementReplacements())
         {
             if (!first)
             {

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java Fri Apr 27 02:00:16 2012
@@ -380,7 +380,7 @@ public final class SqlBuilder
         }
 
         where.append(whereClausePartOutput.getSql());
-        query.getPreparedStatementReplacements().addAll(
+        query.getWhereClausePreparedStatementReplacements().addAll(
                 whereClausePartOutput.getPreparedStatementReplacements());
     }
 
@@ -490,7 +490,7 @@ public final class SqlBuilder
                 ignoreCase,
                 db);
         sb.append(whereClausePartOutput.getSql());
-        query.getPreparedStatementReplacements().addAll(
+        query.getWhereClausePreparedStatementReplacements().addAll(
                 whereClausePartOutput.getPreparedStatementReplacements());
 
         for (int i = 0; i < criterion.getClauses().size(); i++)
@@ -672,7 +672,7 @@ public final class SqlBuilder
 
     /**
      * Checks the fromElements in the criteria and replaces the automatically
-     * calculated fromElements in the query b them, if they are filled.
+     * calculated fromElements in the query by them, if they are filled.
      *
      * @param criteria the criteria from which the query should be built.
      * @param query the query to build.
@@ -704,7 +704,7 @@ public final class SqlBuilder
      *         or a String of the form "tableName tableOrAliasName"
      *         if tableOrAliasName is an alias for a table name
      */
-    static String getTableNameForFromClause(
+    static PreparedStatementPart getExpressionForFromClause(
             final Column column,
             final Database database,
             final CriteriaInterface criteria)
@@ -721,15 +721,40 @@ public final class SqlBuilder
         {
             // If the tables have an alias, add an "<xxx> <yyy> statement"
             // <xxx> AS <yyy> causes problems on oracle
-            return new StringBuffer(
-                fullTableName.length() + column.getTableName().length() + 1)
+            PreparedStatementPart result = new PreparedStatementPart();
+            result.getSql()
                     .append(fullTableName)
                     .append(" ")
-                    .append(column.getTableName())
-                .toString();
+                    .append(column.getTableName());
+            return result;
+        }
+        Object resolvedAlias = criteria.getAliases().get(
+                resolvedColumn.getTableName());
+        if (resolvedAlias != null)
+        {
+            if (resolvedAlias instanceof Criteria)
+            {
+                Criteria subquery = (Criteria) resolvedAlias;
+                Query renderedSubquery = SqlBuilder.buildQuery(subquery);
+                PreparedStatementPart result = new PreparedStatementPart();
+                result.getSql().append("(")
+                        .append(renderedSubquery.toString())
+                        .append(") ")
+                        .append(resolvedColumn.getTableName());
+                result.getPreparedStatementReplacements().addAll(
+                        renderedSubquery.getPreparedStatementReplacements());
+                return result;
+            }
+            else
+            {
+                throw new TorqueException("Table name "
+                    + resolvedColumn.getTableName()
+                    + " resolved to an unhandleable class "
+                    + resolvedAlias.getClass().getName());
+            }
         }
 
-        return fullTableName;
+        return new PreparedStatementPart(fullTableName);
     }
 
     /**
@@ -884,9 +909,8 @@ public final class SqlBuilder
 
     /**
      * Returns the database name of a column
-     * @param tableName the name of a table
-     *        or the alias for a table
-     * @param criteria a criteria object to resolve a possible alias
+     * @param tableName the name of a table or the alias for a table.
+     * @param criteria a criteria object to resolve a possible alias,
      * @return either the tablename itself if tableOrAliasName is not an alias,
      *         or a String of the form "tableName tableOrAliasName"
      *         if tableOrAliasName is an alias for a table name
@@ -898,45 +922,47 @@ public final class SqlBuilder
             throws TorqueException
     {
         String columnNameToResolve = columnToResolve.getColumnName();
-        Column column = criteria.getAsColumns().get(columnNameToResolve);
+        Column resolvedColumn = criteria.getAsColumns().get(columnNameToResolve);
         boolean sqlExpressionModified = false;
-        if (column == null)
+        if (resolvedColumn == null)
         {
-            column = columnToResolve;
+            resolvedColumn = columnToResolve;
         }
         else
         {
             sqlExpressionModified = true;
         }
-        String tableNameToResolve = column.getTableName();
-        String tableName = criteria.getAliases().get(tableNameToResolve);
-        if (tableName == null)
+        String tableNameToResolve = resolvedColumn.getTableName();
+        Object resolvedAlias = criteria.getAliases().get(tableNameToResolve);
+        String resolvedTableName;
+        if (resolvedAlias == null || !(resolvedAlias instanceof String))
         {
-            tableName = tableNameToResolve;
+            resolvedTableName = tableNameToResolve;
         }
         else
         {
+            resolvedTableName = (String) resolvedAlias;
             sqlExpressionModified = true;
         }
-        String schemaName = column.getSchemaName();
-        if (schemaName == null)
+        String resolvedSchemaName = resolvedColumn.getSchemaName();
+        if (resolvedSchemaName == null)
         {
-            schemaName = database.getSchema();
+            resolvedSchemaName = database.getSchema();
         }
         if (sqlExpressionModified)
         {
             return new ColumnImpl(
-                    schemaName,
-                    tableName,
-                    column.getColumnName());
+                    resolvedSchemaName,
+                    resolvedTableName,
+                    resolvedColumn.getColumnName());
         }
         else
         {
             return new ColumnImpl(
-                    schemaName,
-                    tableName,
-                    column.getColumnName(),
-                    column.getSqlExpression());
+                    resolvedSchemaName,
+                    resolvedTableName,
+                    resolvedColumn.getColumnName(),
+                    resolvedColumn.getSqlExpression());
         }
     }
 
@@ -956,17 +982,19 @@ public final class SqlBuilder
      * @return if the Tablename tableName is already contained in a from clause.
      *         If tableName is null, true is returned.
      */
-    static boolean fromClauseContainsTableName(
+    static boolean fromClauseContainsExpression(
             final UniqueList<FromElement> fromClause,
-            final String tableName)
+            final PreparedStatementPart fromExpression)
     {
-        if (tableName == null)
+        String fromExpressionSql = fromExpression.getSql().toString();
+        if (fromExpression == null
+                || fromExpressionSql.length() == 0)
         {
             return false;
         }
         for (FromElement fromElement : fromClause)
         {
-            if (tableName.equals(fromElement.getTableName()))
+            if (fromExpressionSql.equals(fromElement.getFromExpression()))
             {
                 return true;
             }
@@ -982,13 +1010,10 @@ public final class SqlBuilder
      *        or the alias for a table. If null, the from clause is left
      *        unchanged.
      * @param criteria a criteria object to resolve a possible alias
-     * @param query the query where the the tablename should be added
+     * @param query the query where the the table name should be added
      *        to the from clause
-     *
-     * @return the table in the from clause which represents the
-     *         supplied tableOrAliasName
      */
-    static String addTableToFromClause(
+    static void addTableToFromClause(
                 final Object possibleColumn,
                 final Database database,
                 final CriteriaInterface criteria,
@@ -997,18 +1022,18 @@ public final class SqlBuilder
     {
         if (possibleColumn == null)
         {
-            return null;
+            return;
         }
         if (!(possibleColumn instanceof Column))
         {
-            return null;
+            return;
         }
         Column column = (Column) possibleColumn;
         if (column.getTableName() == null)
         {
-            return null;
+            return;
         }
-        String tableNameForFromClause = getTableNameForFromClause(
+        PreparedStatementPart fromClauseExpression = getExpressionForFromClause(
                 column,
                 database,
                 criteria);
@@ -1017,16 +1042,17 @@ public final class SqlBuilder
 
         // it is important that this piece of code is executed AFTER
         // the joins are processed
-        if (!fromClauseContainsTableName(
+        if (!fromClauseContainsExpression(
             queryFromClause,
-            tableNameForFromClause))
+            fromClauseExpression))
         {
-            FromElement fromElement
-                    = new FromElement(
-                            tableNameForFromClause, null, null);
+            FromElement fromElement = new FromElement(
+                    fromClauseExpression.getSql().toString(),
+                    null,
+                    null,
+                    fromClauseExpression.getPreparedStatementReplacements());
             queryFromClause.add(fromElement);
         }
-        return tableNameForFromClause;
     }
 
     /**

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java Fri Apr 27 02:00:16 2012
@@ -350,9 +350,7 @@ public class BasePeerImpl implements Ser
         Connection con = null;
         try
         {
-            con = Transaction.beginOptional(
-                    criteria.getDbName(),
-                    criteria.isUseTransaction());
+            con = Transaction.begin(criteria.getDbName());
             int result = doDelete(criteria, tableMap, con);
             Transaction.commit(con);
             con = null;
@@ -389,9 +387,7 @@ public class BasePeerImpl implements Ser
         Connection con = null;
         try
         {
-            con = Transaction.beginOptional(
-                    criteria.getDbName(),
-                    criteria.isUseTransaction());
+            con = Transaction.begin(criteria.getDbName());
             int result = doDelete(criteria, tableMap, con);
             Transaction.commit(con);
             con = null;
@@ -455,7 +451,7 @@ public class BasePeerImpl implements Ser
         {
             // Table names are case insensitive in known databases
             // so use case-insensitive compare
-            if (fullTableName.equalsIgnoreCase(fromElement.getTableName()))
+            if (fullTableName.equalsIgnoreCase(fromElement.getFromExpression()))
             {
                 ownTableAdded = true;
                 break;
@@ -472,14 +468,14 @@ public class BasePeerImpl implements Ser
         try
         {
             preparedStatement = connection.prepareStatement(sql);
-            setPreparedStatementReplacements(
+            List<Object> replacements = setPreparedStatementReplacements(
                     preparedStatement,
                     query.getPreparedStatementReplacements(),
                     0);
             long startTime = System.currentTimeMillis();
             log.debug("Executing delete " + sql
                     + ", parameters = "
-                    + query.getPreparedStatementReplacements());
+                    + replacements);
 
             int affectedRows = preparedStatement.executeUpdate();
             long queryEndTime = System.currentTimeMillis();
@@ -551,7 +547,7 @@ public class BasePeerImpl implements Ser
         {
             // Table names are case insensitive in known databases
             // so use case-insensitive compare
-            if (fullTableName.equalsIgnoreCase(fromElement.getTableName()))
+            if (fullTableName.equalsIgnoreCase(fromElement.getFromExpression()))
             {
                 ownTableAdded = true;
                 break;
@@ -568,14 +564,14 @@ public class BasePeerImpl implements Ser
         try
         {
             preparedStatement = connection.prepareStatement(sql);
-            setPreparedStatementReplacements(
+            List<Object> replacements = setPreparedStatementReplacements(
                     preparedStatement,
                     query.getPreparedStatementReplacements(),
                     0);
             long startTime = System.currentTimeMillis();
             log.debug("Executing delete " + sql
                     + ", parameters = "
-                    + query.getPreparedStatementReplacements());
+                    + replacements);
 
             int affectedRows = preparedStatement.executeUpdate();
             long queryEndTime = System.currentTimeMillis();
@@ -925,9 +921,7 @@ public class BasePeerImpl implements Ser
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    criteria.getDbName(),
-                    criteria.isUseTransaction());
+            connection = Transaction.begin(criteria.getDbName());
 
             List<T> result = doSelect(
                     criteria,
@@ -970,9 +964,7 @@ public class BasePeerImpl implements Ser
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    criteria.getDbName(),
-                    criteria.isUseTransaction());
+            connection = Transaction.begin(criteria.getDbName());
 
             List<T> result = doSelect(
                     criteria,
@@ -1022,9 +1014,7 @@ public class BasePeerImpl implements Ser
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    dbName,
-                    true);
+            connection = Transaction.begin(dbName);
 
             List<T> result = doSelect(
                     query,
@@ -1170,7 +1160,7 @@ public class BasePeerImpl implements Ser
         {
             statement = connection.prepareStatement(query.toString());
 
-            setPreparedStatementReplacements(
+            List<Object> replacements = setPreparedStatementReplacements(
                     statement,
                     query.getPreparedStatementReplacements(),
                     0);
@@ -1178,7 +1168,7 @@ public class BasePeerImpl implements Ser
             long startTime = System.currentTimeMillis();
             log.debug("Executing query " + query
                     + ", parameters = "
-                    + query.getPreparedStatementReplacements());
+                    + replacements);
 
             resultSet = statement.executeQuery();
             long queryEndTime = System.currentTimeMillis();
@@ -1688,7 +1678,7 @@ public class BasePeerImpl implements Ser
                 }
                 position++;
             }
-            setPreparedStatementReplacements(
+            List<Object> replacements = setPreparedStatementReplacements(
                     preparedStatement,
                     query.getPreparedStatementReplacements(),
                     position - 1);
@@ -1696,7 +1686,7 @@ public class BasePeerImpl implements Ser
             log.debug("Executing update " + query.toString()
                     + " using update parameters " + replacementObjects
                     + " and query parameters "
-                    + query.getPreparedStatementReplacements());
+                    + replacements);
 
             int affectedRows = preparedStatement.executeUpdate();
             long queryEndTime = System.currentTimeMillis();
@@ -1786,7 +1776,7 @@ public class BasePeerImpl implements Ser
                 }
                 position++;
             }
-            setPreparedStatementReplacements(
+            List<Object> replacements = setPreparedStatementReplacements(
                     preparedStatement,
                     query.getPreparedStatementReplacements(),
                     position - 1);
@@ -1794,7 +1784,7 @@ public class BasePeerImpl implements Ser
             log.debug("Executing update " + query.toString()
                     + " using update parameters " + replacementObjects
                     + " and query parameters "
-                    + query.getPreparedStatementReplacements());
+                    + replacements);
 
             int affectedRows = preparedStatement.executeUpdate();
             long queryEndTime = System.currentTimeMillis();

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java Fri Apr 27 02:00:16 2012
@@ -199,8 +199,6 @@ public class Criteria implements Seriali
      */
     private Map<String, String> aliases = new HashMap<String, String>();
 
-    private boolean useTransaction = false;
-
     /** the log. */
     private static Log log = LogFactory.getLog(Criteria.class);
 
@@ -272,7 +270,6 @@ public class Criteria implements Seriali
         offset = 0;
         limit = -1;
         aliases.clear();
-        useTransaction = false;
     }
 
     /**
@@ -402,27 +399,6 @@ public class Criteria implements Seriali
         }
         return false;
     }
-    /**
-     * Will force the sql represented by this criteria to be executed within
-     * a transaction.  This is here primarily to support the oid type in
-     * postgresql.  Though it can be used to require any single sql statement
-     * to use a transaction.
-     */
-    public void setUseTransaction(boolean v)
-    {
-        useTransaction = v;
-    }
-
-    /**
-     * called by BasePeer to determine whether the sql command specified by
-     * this criteria must be wrapped in a transaction.
-     *
-     * @return a <code>boolean</code> value
-     */
-    protected boolean isUseTransaction()
-    {
-        return useTransaction;
-    }
 
     /**
      * Return the criterion for a column.

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java Fri Apr 27 02:00:16 2012
@@ -165,9 +165,7 @@ public class SummaryHelper
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    crit.getDbName(),
-                    crit.isUseTransaction());
+            connection = Transaction.begin(crit.getDbName());
             List<ListOrderedMapCI> result = summarize(crit, resultTypes, connection);
             Transaction.commit(connection);
             connection = null;
@@ -205,9 +203,7 @@ public class SummaryHelper
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    crit.getDbName(),
-                    crit.isUseTransaction());
+            connection = Transaction.begin(crit.getDbName());
             List<ListOrderedMapCI> result = summarize(crit, resultTypes, connection);
             Transaction.commit(connection);
             connection = null;

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Transaction.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Transaction.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Transaction.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Transaction.java Fri Apr 27 02:00:16 2012
@@ -20,40 +20,28 @@ package org.apache.torque.util;
  */
 
 import java.sql.Connection;
-import java.sql.SQLException;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.torque.Torque;
 import org.apache.torque.TorqueException;
 
 /**
- * Refactored begin/commit/rollback transaction methods away from
- * the <code>BasePeer</code>.
+ * Encapsulates transaction and connection handling within Torque.
  *
- * <p>
- * This can be used to handle cases where transaction support is optional.
- * The second parameter of beginOptionalTransaction will determine with a
- * transaction is used or not.
- * If a transaction is not used, the commit and rollback methods
- * do not have any effect. Instead it simply makes the logic easier to follow
- * by cutting down on the if statements based solely on whether a transaction
- * is needed or not.
+ * If the underlying database does not support transaction or the database
+ * pool returns autocommit connections, the commit and rollback methods
+ * fallback to simple connection pool handling.
  *
  * @author <a href="mailto:stephenh@chase3000.com">Stephen Haberman</a>
  * @version $Id$
  */
 public final class Transaction
 {
-
-    /** The log. */
-    private static Log log = LogFactory.getLog(Transaction.class);
+    /** The transaction manager to sue. */
+    private static TransactionManager transactionManager;
 
     /**
      * Private constructor to prevent instantiation.
      *
-     * Class contains only static method ans should therefore not be
+     * Class contains only static method and should therefore not be
      * instantiated.
      */
     private Transaction()
@@ -61,69 +49,55 @@ public final class Transaction
     }
 
     /**
-     * Begin a transaction for the default database.
-     * This method will fallback gracefully to
-     * return a normal connection, if the database being accessed does
-     * not support transactions.
+     * Sets the transaction manager to use.
      *
-     * @return The Connection for the transaction.
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
+     * @param transactionManager the transaction manager to use.
      */
-    public static Connection begin() throws TorqueException
+    public static void setTransactionManager(
+            TransactionManager transactionManager)
     {
-        return Transaction.begin(Torque.getDefaultDB());
+        Transaction.transactionManager = transactionManager;
     }
 
     /**
-     * Begin a transaction.  This method will fallback gracefully to
-     * return a normal connection, if the database being accessed does
-     * not support transactions.
+     * Begin a transaction by retrieving a connection from the default database
+     * connection pool.
+     * WARNING: If the database does not support transaction or the pool has set
+     * autocommit to true on the connection, the database will commit after
+     * every statement, regardless of when a commit or rollback is issued.
      *
-     * @param dbName Name of database.
      * @return The Connection for the transaction.
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public static Connection begin(String dbName) throws TorqueException
+    public static Connection begin() throws TorqueException
     {
-        return Transaction.beginOptional(dbName, true);
+        return transactionManager.begin();
     }
 
     /**
-     * Begin a transaction.  This method will fallback gracefully to
-     * return a normal connection, if the database being accessed does
-     * not support transactions.
+     * Begin a transaction by retrieving a connection from the named database
+     * connection pool.
+     * WARNING: If the database does not support transaction or the pool has set
+     * autocommit to true on the connection, the database will commit after
+     * every statement, regardless of when a commit or rollback is issued.
      *
      * @param dbName Name of database.
-     * @param useTransaction If false, a transaction won't be used.
+     *
      * @return The Connection for the transaction.
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
+     *
+     * @throws TorqueException If the connection cannot be retrieved.
      */
-    public static Connection beginOptional(String dbName,
-                                           boolean useTransaction)
-        throws TorqueException
-    {
-        Connection con = Torque.getConnection(dbName);
-        try
-        {
-            if (con.getMetaData().supportsTransactions() && useTransaction)
-            {
-                con.setAutoCommit(false);
-            }
-        }
-        catch (SQLException e)
-        {
-            throw new TorqueException(e);
-        }
-        return con;
+    public static Connection begin(String dbName) throws TorqueException
+    {
+        return transactionManager.begin(dbName);
     }
 
+
     /**
-     * Commit a transaction.  This method takes care of releasing the
-     * connection after the commit.  In databases that do not support
-     * transactions, it only returns the connection.
+     * Commit a transaction and close the connection.
+     * If the connection is in autocommit mode or the database does not support
+     * transactions, only a connection close is performed
      *
      * @param con The Connection for the transaction.
      * @throws TorqueException Any exceptions caught during processing will be
@@ -131,75 +105,22 @@ public final class Transaction
      */
     public static void commit(Connection con) throws TorqueException
     {
-        if (con == null)
-        {
-            throw new NullPointerException("Connection object was null. "
-                    + "This could be due to a misconfiguration of the "
-                    + "DataSourceFactory. Check the logs and Torque.properties "
-                    + "to better determine the cause.");
-        }
-
-        try
-        {
-            if (con.getMetaData().supportsTransactions()
-                && !con.getAutoCommit())
-            {
-                con.commit();
-                con.setAutoCommit(true);
-            }
-        }
-        catch (SQLException e)
-        {
-            throw new TorqueException(e);
-        }
-        finally
-        {
-            Torque.closeConnection(con);
-        }
+        transactionManager.commit(con);
     }
 
     /**
-     * Roll back a transaction in databases that support transactions.
-     * It also releases the connection. In databases that do not support
-     * transactions, this method will log the attempt and release the
-     * connection.
+     * Roll back a transaction and release the connection.
+     * In databases that do not support transactions or if autocommit is true,
+     * no rollback will be performed, but the connection will be closed anyway.
      *
      * @param con The Connection for the transaction.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
     public static void rollback(Connection con) throws TorqueException
     {
-        if (con == null)
-        {
-            throw new TorqueException("Connection object was null. "
-                    + "This could be due to a misconfiguration of the "
-                    + "DataSourceFactory. Check the logs and Torque.properties "
-                    + "to better determine the cause.");
-        }
-        else
-        {
-            try
-            {
-                if (con.getMetaData().supportsTransactions()
-                    && !con.getAutoCommit())
-                {
-                    con.rollback();
-                    con.setAutoCommit(true);
-                }
-            }
-            catch (SQLException e)
-            {
-                log.error("An attempt was made to rollback a transaction "
-                        + "but the database did not allow the operation to be "
-                        + "rolled back.", e);
-                throw new TorqueException(e);
-            }
-            finally
-            {
-                Torque.closeConnection(con);
-            }
-        }
+        transactionManager.rollback(con);
     }
 
     /**
@@ -212,20 +133,6 @@ public final class Transaction
      */
     public static void safeRollback(Connection con)
     {
-        if (con == null)
-        {
-            log.debug("called safeRollback with null argument");
-        }
-        else
-        {
-            try
-            {
-                Transaction.rollback(con);
-            }
-            catch (TorqueException e)
-            {
-                log.warn("An error occured during rollback.", e);
-            }
-        }
+        transactionManager.safeRollback(con);
     }
 }

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManager.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManager.java?rev=1331179&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManager.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManager.java Fri Apr 27 02:00:16 2012
@@ -0,0 +1,94 @@
+package org.apache.torque.util;
+
+/*
+ * 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.
+ */
+
+import java.sql.Connection;
+
+import org.apache.torque.TorqueException;
+
+/**
+ * Torque's interface to the transaction management sytsem.
+ *
+ * @version $Id: $
+ */
+public interface TransactionManager
+{
+    /**
+     * Begin a transaction by retrieving a connection from the default database
+     * connection pool.
+     * WARNING: If the database does not support transaction or the pool has set
+     * autocommit to true on the connection, the database will commit after
+     * every statement, regardless of when a commit or rollback is issued.
+     *
+     * @return The Connection for the transaction.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    Connection begin() throws TorqueException;
+
+    /**
+     * Begin a transaction by retrieving a connection from the named database
+     * connection pool.
+     * WARNING: If the database does not support transaction or the pool has set
+     * autocommit to true on the connection, the database will commit after
+     * every statement, regardless of when a commit or rollback is issued.
+     *
+     * @param dbName Name of database.
+     *
+     * @return The Connection for the transaction.
+     *
+     * @throws TorqueException If the connection cannot be retrieved.
+     */
+    Connection begin(String dbName) throws TorqueException;
+
+
+    /**
+     * Commit a transaction and close the connection.
+     * If the connection is in autocommit mode or the database does not support
+     * transactions, only a connection close is performed
+     *
+     * @param con The Connection for the transaction.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    void commit(Connection con) throws TorqueException;
+
+    /**
+     * Roll back a transaction and release the connection.
+     * In databases that do not support transactions or if autocommit is true,
+     * no rollback will be performed, but the connection will be closed anyway.
+     *
+     * @param con The Connection for the transaction.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    void rollback(Connection con) throws TorqueException;
+
+    /**
+     * Roll back a transaction without throwing errors if they occur.
+     * A null Connection argument is logged at the debug level and other
+     * errors are logged at warn level.
+     *
+     * @param con The Connection for the transaction.
+     * @see TransactionManagerImpl#rollback(Connection)
+     */
+    void safeRollback(Connection con);
+}

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java?rev=1331179&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/TransactionManagerImpl.java Fri Apr 27 02:00:16 2012
@@ -0,0 +1,186 @@
+package org.apache.torque.util;
+
+/*
+ * 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.
+ */
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.Torque;
+import org.apache.torque.TorqueException;
+
+/**
+ * Standard connection and transaction management for Torque.
+ * Uses JDBC connection operations and Torque's own database pools
+ * for managing connections and transactions.
+ *
+ * @author <a href="mailto:stephenh@chase3000.com">Stephen Haberman</a>
+ * @version $Id: Transaction.java 1099785 2011-05-05 13:32:15Z tfischer $
+ */
+public class TransactionManagerImpl implements TransactionManager
+{
+
+    /** The log. */
+    private static Log log = LogFactory.getLog(TransactionManagerImpl.class);
+
+    /**
+     * Begin a transaction by retrieving a connection from the default database
+     * connection pool.
+     * WARNING: If the database does not support transaction or the pool has set
+     * autocommit to true on the connection, the database will commit after
+     * every statement, regardless of when a commit or rollback is issued.
+     *
+     * @return The Connection for the transaction.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public Connection begin() throws TorqueException
+    {
+        return begin(Torque.getDefaultDB());
+    }
+
+    /**
+     * Begin a transaction by retrieving a connection from the named database
+     * connection pool.
+     * WARNING: If the database does not support transaction or the pool has set
+     * autocommit to true on the connection, the database will commit after
+     * every statement, regardless of when a commit or rollback is issued.
+     *
+     * @param dbName Name of database.
+     *
+     * @return The Connection for the transaction.
+     *
+     * @throws TorqueException If the connection cannot be retrieved.
+     */
+    public Connection begin(String dbName) throws TorqueException
+    {
+        Connection con = Torque.getConnection(dbName);
+        return con;
+    }
+
+
+    /**
+     * Commit a transaction and close the connection.
+     * If the connection is in autocommit mode or the database does not support
+     * transactions, only a connection close is performed
+     *
+     * @param con The Connection for the transaction.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public void commit(Connection con) throws TorqueException
+    {
+        if (con == null)
+        {
+            throw new NullPointerException("Connection object was null. "
+                    + "This could be due to a misconfiguration of the "
+                    + "DataSourceFactory. Check the logs and Torque.properties "
+                    + "to better determine the cause.");
+        }
+
+        try
+        {
+            if (con.getMetaData().supportsTransactions()
+                && !con.getAutoCommit())
+            {
+                con.commit();
+            }
+        }
+        catch (SQLException e)
+        {
+            throw new TorqueException(e);
+        }
+        finally
+        {
+            Torque.closeConnection(con);
+        }
+    }
+
+    /**
+     * Roll back a transaction and release the connection.
+     * In databases that do not support transactions or if autocommit is true,
+     * no rollback will be performed, but the connection will be closed anyway.
+     *
+     * @param con The Connection for the transaction.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public void rollback(Connection con) throws TorqueException
+    {
+        if (con == null)
+        {
+            throw new TorqueException("Connection object was null. "
+                    + "This could be due to a misconfiguration of the "
+                    + "DataSourceFactory. Check the logs and Torque.properties "
+                    + "to better determine the cause.");
+        }
+        else
+        {
+            try
+            {
+                if (con.getMetaData().supportsTransactions()
+                    && !con.getAutoCommit())
+                {
+                    con.rollback();
+                }
+            }
+            catch (SQLException e)
+            {
+                log.error("An attempt was made to rollback a transaction "
+                        + "but the database did not allow the operation to be "
+                        + "rolled back.", e);
+                throw new TorqueException(e);
+            }
+            finally
+            {
+                Torque.closeConnection(con);
+            }
+        }
+    }
+
+    /**
+     * Roll back a transaction without throwing errors if they occur.
+     * A null Connection argument is logged at the debug level and other
+     * errors are logged at warn level.
+     *
+     * @param con The Connection for the transaction.
+     * @see TransactionManagerImpl#rollback(Connection)
+     */
+    public void safeRollback(Connection con)
+    {
+        if (con == null)
+        {
+            log.debug("called safeRollback with null argument");
+        }
+        else
+        {
+            try
+            {
+                rollback(con);
+            }
+            catch (TorqueException e)
+            {
+                log.warn("An error occured during rollback.", e);
+            }
+        }
+    }
+}

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java Fri Apr 27 02:00:16 2012
@@ -661,7 +661,7 @@ public class CriteriaTest extends BaseTe
                 SqlEnum.ASC,
                 false)));
         assertEquals(c.getOrderByColumns(), cClone.getOrderByColumns());
-        Map<String, String> aliasesClone = cClone.getAliases();
+        Map<String, Object> aliasesClone = cClone.getAliases();
         assertTrue(aliasesClone.containsKey("Writer"));
         assertEquals("Author", aliasesClone.get("Writer"));
         assertEquals(c.getAliases(), cClone.getAliases());
@@ -754,7 +754,7 @@ public class CriteriaTest extends BaseTe
                 SqlEnum.ASC,
                 false)));
         assertEquals(c.getOrderByColumns(), cClone.getOrderByColumns());
-        Map<String, String> aliasesClone = cClone.getAliases();
+        Map<String, Object> aliasesClone = cClone.getAliases();
         assertTrue(aliasesClone.containsKey("Writer"));
         assertEquals("Author", aliasesClone.get("Writer"));
         assertEquals(c.getAliases(), cClone.getAliases());

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java Fri Apr 27 02:00:16 2012
@@ -709,6 +709,50 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
+    public void testAliasWithSubquery() throws Exception
+    {
+        Criteria subquery = new Criteria()
+            .addSelectColumn(new ColumnImpl("table2.column1"))
+            .where(new ColumnImpl("table2.column2"),
+                    new ColumnImpl("table2.column3"));
+
+        Criteria criteria = new Criteria();
+        criteria.addAlias("alias", subquery);
+        criteria.addSelectColumn(new ColumnImpl("alias.column1"));
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT alias.column1 FROM ("
+                   + "SELECT table2.column1 FROM table2 "
+                   + "WHERE table2.column2=table2.column3) "
+                   + "alias",
+                query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testAliasWithSubqueryAndReplacements() throws Exception
+    {
+        Criteria subquery = new Criteria()
+            .addSelectColumn(new ColumnImpl("table2.column1"))
+            .where(new ColumnImpl("table2.column2"), "x");
+
+        Criteria criteria = new Criteria();
+        criteria.addAlias("alias", subquery);
+        criteria.addSelectColumn(new ColumnImpl("alias.column1"));
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT alias.column1 FROM ("
+                   + "SELECT table2.column1 FROM table2 "
+                   + "WHERE table2.column2=?) "
+                   + "alias",
+                query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals("x", query.getPreparedStatementReplacements().get(0));
+    }
+
     public void testAliasWithIgnoreCaseStringColumnType() throws Exception
     {
         Criteria criteria = new Criteria();
@@ -939,8 +983,8 @@ public class SqlBuilderTest extends Base
         }
         catch (TorqueException e)
         {
-            assertEquals("Unable to create a  INNER JOIN "
-                    + "because both table names table1 and table2 "
+            assertEquals("Unable to create a INNER JOIN "
+                    + "because both expressions table1 and table2 "
                     + "are already in use. Try to create an(other) alias.",
                 e.getMessage());
         }
@@ -1118,6 +1162,33 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
+    public void testInnerJoinImplicitWithSubqueryAndReplacements()
+            throws Exception
+    {
+        Criteria subquery = new Criteria()
+            .addSelectColumn(new ColumnImpl("table2.column2a"))
+            .where(new ColumnImpl("table2.column2b"), "x");
+
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(new ColumnImpl("alias.column1"));
+        criteria.addAlias("alias", subquery);
+        criteria.addJoin(
+                new ColumnImpl("alias.column1"),
+                new ColumnImpl("table2.column2"));
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT alias.column1 FROM ("
+                   + "SELECT table2.column2a FROM table2 "
+                   + "WHERE table2.column2b=?) "
+                   + "alias, table2 "
+                   + "WHERE alias.column1=table2.column2",
+                query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals("x", query.getPreparedStatementReplacements().get(0));
+    }
+
     public void testDistinct()
             throws Exception
     {

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTestOldCriteria.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTestOldCriteria.java?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTestOldCriteria.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTestOldCriteria.java Fri Apr 27 02:00:16 2012
@@ -503,8 +503,8 @@ public class SqlBuilderTestOldCriteria e
         }
         catch (TorqueException e)
         {
-            assertEquals("Unable to create a  INNER JOIN "
-                    + "because both table names table1 and table2 "
+            assertEquals("Unable to create a INNER JOIN "
+                    + "because both expressions table1 and table2 "
                     + "are already in use. Try to create an(other) alias.",
                 e.getMessage());
         }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doDelete.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/doDelete.vm?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doDelete.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doDelete.vm Fri Apr 27 02:00:16 2012
@@ -42,9 +42,8 @@
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    ${peerClassName}.DATABASE_NAME,
-                    true);
+            connection = Transaction.begin(
+                    ${peerClassName}.DATABASE_NAME);
             int deletedRows = doDelete(criteria, connection);
             Transaction.commit(connection);
             connection = null;
@@ -202,9 +201,8 @@
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    ${peerClassName}.DATABASE_NAME,
-                    true);
+            connection = Transaction.begin(
+                    ${peerClassName}.DATABASE_NAME);
             int deletedRows = doDelete(pk, connection);
             Transaction.commit(connection);
             connection = null;

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelectJoin.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/doSelectJoin.vm?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelectJoin.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelectJoin.vm Fri Apr 27 02:00:16 2012
@@ -58,9 +58,8 @@
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    ${peerClassName}.DATABASE_NAME,
-                    true);
+            connection = Transaction.begin(
+                    ${peerClassName}.DATABASE_NAME);
             List<${dbObjectClassName}> result
                     = $peerClassName.${peerJoinSelectMethod}(criteria, connection);
             Transaction.commit(connection);

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelectJoinAllExcept.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/doSelectJoinAllExcept.vm?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelectJoinAllExcept.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelectJoinAllExcept.vm Fri Apr 27 02:00:16 2012
@@ -57,9 +57,8 @@
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    ${peerClassName}.DATABASE_NAME,
-                    true);
+            connection = Transaction.begin(
+                    ${peerClassName}.DATABASE_NAME);
             List<${dbObjectClassName}> result
                     = $peerClassName.${peerJoinAllExceptSelectMethod}(criteria, connection);
             Transaction.commit(connection);

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.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/doUpdate.vm?rev=1331179&r1=1331178&r2=1331179&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm Fri Apr 27 02:00:16 2012
@@ -43,9 +43,8 @@
         Connection connection = null;
         try
         {
-            connection = Transaction.beginOptional(
-                    ${peerClassName}.DATABASE_NAME,
-                    true);
+            connection = Transaction.begin(
+                    ${peerClassName}.DATABASE_NAME);
             int result = doUpdate(columnValues, connection);
             Transaction.commit(connection);
             connection = null;



---------------------------------------------------------------------
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