db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1301049 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/ torque-runtime/src/main/java/org/apache/torque/criteria/ torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/
Date Thu, 15 Mar 2012 15:32:16 GMT
Author: tfischer
Date: Thu Mar 15 15:32:16 2012
New Revision: 1301049

URL: http://svn.apache.org/viewvc?rev=1301049&view=rev
Log:
TORQUE-188 use null for "not set" in Criteria.dbName

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-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/setDbName.vm

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/Torque.java?rev=1301049&r1=1301048&r2=1301049&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 Thu
Mar 15 15:32:16 2012
@@ -243,7 +243,8 @@ public final class Torque
      * of the connection pool to associate with the map.
      *
      * @param name The name of the database corresponding to the
-     *        <code>DatabaseMap</code> to retrieve, not null.
+     *        <code>DatabaseMap</code> to retrieve, or null
+     *        for the default database.
      *
      * @return The named <code>DatabaseMap</code>, not null.
      *
@@ -317,8 +318,10 @@ public final class Torque
     /**
      * Returns the database adapter for a specific database name.
      *
-     * @param name the database name.
+     * @param name the database name, or null for the default db.
+     *
      * @return The corresponding database adapter.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
@@ -378,9 +381,12 @@ public final class Torque
     /**
      * Returns the database for the given key.
      *
-     * @param name The database name.
+     * @param databaseName the key to get the database for,
+     *        or null for the default database.
+     *
      * @return the Database for the given name, or null if no database exists
      *         for the given name.
+     *
      * @throws TorqueException if Torque is not yet initialized.
      */
     public static Database getDatabase(String name) throws TorqueException

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=1301049&r1=1301048&r2=1301049&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
Thu Mar 15 15:32:16 2012
@@ -764,7 +764,8 @@ public class TorqueInstance
      * of the connection pool to associate with the map.
      *
      * @param name The name of the database corresponding to the
-     *        <code>DatabaseMap</code> to retrieve, not null.
+     *        <code>DatabaseMap</code> to retrieve, or null
+     *        for the default database.
      *
      * @return The named <code>DatabaseMap</code>, not null.
      *
@@ -774,7 +775,7 @@ public class TorqueInstance
     {
         if (name == null)
         {
-            throw new NullPointerException ("name was null!");
+            name = getDefaultDB();
         }
 
         Database database = getOrCreateDatabase(name);
@@ -905,9 +906,11 @@ public class TorqueInstance
     /**
      * Returns the database adapter for a specific database.
      *
-     * @param name the name of the database to get the adapter for.
+     * @param name the database name, or null for the default db.
+     *
      * @return The corresponding database adapter, or null if no database
      *         adapter is defined for the given database.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
@@ -989,9 +992,12 @@ public class TorqueInstance
     /**
      * Returns the database for the key <code>databaseName</code>.
      *
-     * @param databaseName the key to get the database for.
+     * @param databaseName the key to get the database for,
+     *        or null for the default database.
+     *
      * @return the database for the specified key, or null if the database
      *         does not exist.
+     *
      * @throws TorqueException if Torque is not yet initialized.
      */
     public Database getDatabase(String databaseName) throws TorqueException
@@ -1000,6 +1006,10 @@ public class TorqueInstance
         {
             throw new TorqueException("Torque is not initialized.");
         }
+        if (databaseName == null)
+        {
+            databaseName = getDefaultDB();
+        }
         return databases.get(databaseName);
     }
 

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=1301049&r1=1301048&r2=1301049&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
Thu Mar 15 15:32:16 2012
@@ -32,7 +32,6 @@ import org.apache.commons.lang.builder.E
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.torque.Column;
 import org.apache.torque.ColumnImpl;
-import org.apache.torque.Torque;
 import org.apache.torque.sql.OrderBy;
 import org.apache.torque.sql.Query;
 import org.apache.torque.sql.SqlBuilder;
@@ -191,7 +190,6 @@ public class Criteria
      */
     public Criteria()
     {
-        this(Torque.getDefaultDB());
     }
 
     /**
@@ -375,14 +373,15 @@ public class Criteria
     }
 
     /**
-     * Set the Database name.  If <code>null</code> is supplied, uses value
-     * provided by <code>Torque.getDefaultDB()</code>.
+     * Set the Database name.  The value <code>null</code> denotes the
+     * database name provided by <code>Torque.getDefaultDB()</code>
+     * (but this is not resolved here).
      *
      * @param dbName The Database(Map) name.
      */
     public void setDbName(String dbName)
     {
-        this.dbName = (dbName == null ? Torque.getDefaultDB() : dbName.trim());
+        this.dbName = dbName;
     }
 
     /**

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/setDbName.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/setDbName.vm?rev=1301049&r1=1301048&r2=1301049&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/setDbName.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/setDbName.vm
Thu Mar 15 15:32:16 2012
@@ -20,15 +20,25 @@
 ## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer
$
 ##
 ## Creates the setDbName method for the base peer.
-## This template expects no input.
+## This template expects the current source element to be a "table" element 
+## from the torque schema.
+## The schema needs to be processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.
 ##
+    /**
+     * Sets the database name in the passed criteria to the table's default,
+     * if it is not already set.
+     *
+     * @param crit the criteria to set the database name in, not null.
+     */
     private static void setDbName(Criteria crit) throws TorqueException
     {
         if (!Torque.isInit())
         {
             throw new TorqueException("Torque is not initialized");
         }
-        if (Torque.getDefaultDB().equals(crit.getDbName()))
+        if (crit.getDbName() == null)
         {
             crit.setDbName(${peerClassName}.DATABASE_NAME);
         }



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