db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1098658 - /db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java
Date Mon, 02 May 2011 16:52:00 GMT
Author: tfischer
Date: Mon May  2 16:52:00 2011
New Revision: 1098658

URL: http://svn.apache.org/viewvc?rev=1098658&view=rev
Log:
Various bugfixes
- use full table name to apply configured schema prefixes
- improve logging
- enable queries with empty from clause
- improve date handling in queries

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java?rev=1098658&r1=1098657&r2=1098658&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java
Mon May  2 16:52:00 2011
@@ -232,7 +232,8 @@ public abstract class BasePeer
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    protected static void doDelete(Criteria criteria, String tableName) throws TorqueException
+    protected static void doDelete(Criteria criteria, String tableName)
+            throws TorqueException
     {
         Connection con = null;
         try
@@ -332,7 +333,11 @@ public abstract class BasePeer
 
         query.setType(Query.Type.DELETE);
         query.getFromClause().clear();
-        query.getFromClause().add(new Query.FromElement(tableName, null, null));
+        String fullTableName = SQLBuilder.getFullTableName(
+                tableName,
+                criteria.getDbName());
+        query.getFromClause().add(
+                new Query.FromElement(fullTableName, null, null));
         String sql = query.toString();
 
         PreparedStatement preparedStatement = null;
@@ -344,7 +349,9 @@ public abstract class BasePeer
                     query.getPreparedStatementReplacements(),
                     0);
             long startTime = System.currentTimeMillis();
-            log.debug("Executing delete " + sql);
+            log.debug("Executing delete " + sql
+                    + ", parameters = "
+                    + query.getPreparedStatementReplacements());
 
             int affectedRows = preparedStatement.executeUpdate();
             long queryEndTime = System.currentTimeMillis();
@@ -504,8 +511,11 @@ public abstract class BasePeer
             replacementObjects.add(value);
         }
 
+        String fullTableName = SQLBuilder.getFullTableName(
+                tableMap.getName(), 
+                dbMap.getName());
         StringBuilder query = new StringBuilder("INSERT INTO ")
-            .append(tableMap.getName())
+            .append(fullTableName)
             .append("(")
             .append(StringUtils.join(columnNames, ","))
             .append(") VALUES (");
@@ -1273,8 +1283,13 @@ public abstract class BasePeer
         Query query = createQuery(criteria);
         query.setType(Query.Type.UPDATE);
 
-        // ignore select columns in criteria
-        query.getSelectClause().clear();
+        query.getFromClause().clear();
+        String fullTableName = SQLBuilder.getFullTableName(
+                updateValues.getTable().getName(),
+                criteria.getDbName());
+        query.getFromClause().add(
+                new Query.FromElement(fullTableName, null, null));
+
         List<JdbcTypedValue> replacementObjects
                 = new ArrayList<JdbcTypedValue>();
         for (Map.Entry<String, JdbcTypedValue> updateValue
@@ -1316,7 +1331,9 @@ public abstract class BasePeer
                     position - 1);
             long startTime = System.currentTimeMillis();
             log.debug("Executing update " + query.toString()
-                    + " using parameters " + replacementObjects);
+                    + " using update parameters " + replacementObjects
+                    + " and query parameters "
+                    + query.getPreparedStatementReplacements());
 
             int affectedRows = preparedStatement.executeUpdate();
             long queryEndTime = System.currentTimeMillis();
@@ -1456,7 +1473,7 @@ public abstract class BasePeer
      * @param mapper The mapper creating the objects from the resultSet,
      *        not null.
      * @param defaultTableMap The table map used for the
-     *        unqualified columns in the query, not null.
+     *        unqualified columns in the query, TODO or null ???.
      * @param connection the database connection for selecting records,
      *        not null.
      *
@@ -1473,6 +1490,14 @@ public abstract class BasePeer
         correctBooleans(criteria, defaultTableMap);
 
         Query query = SQLBuilder.buildQuery(criteria);
+        if (query.getFromClause().isEmpty() && defaultTableMap != null)
+        {
+            String tableName = SQLBuilder.getFullTableName(
+                    defaultTableMap.getName(),
+                    criteria.getDbName());
+            query.getFromClause().add(
+                    new Query.FromElement(tableName, null, null));
+        }
 
         PreparedStatement statement = null;
         ResultSet resultSet = null;
@@ -1601,10 +1626,21 @@ public abstract class BasePeer
         int i = 1 + offset;
         for (Object param : replacements)
         {
-            if (param instanceof java.sql.Date)
+            if (param instanceof java.sql.Timestamp)
+            {
+                statement.setTimestamp(i, (java.sql.Timestamp) param);
+            }
+            else if (param instanceof java.sql.Date)
             {
                 statement.setDate(i, (java.sql.Date) param);
             }
+            else if (param instanceof java.util.Date)
+            {
+                // TODO change to timestamp 
+                java.sql.Date sqlDate = new java.sql.Date(
+                        ((java.util.Date) param).getTime());
+                statement.setDate(i, sqlDate);
+            }
             else if (param instanceof NumberKey)
             {
                 statement.setBigDecimal(i,



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