db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1403997 - in /db/torque/torque4/trunk/torque-runtime/src: main/java/org/apache/torque/map/ main/java/org/apache/torque/util/ test/java/org/apache/torque/util/
Date Wed, 31 Oct 2012 06:12:45 GMT
Author: tfischer
Date: Wed Oct 31 06:12:45 2012
New Revision: 1403997

URL: http://svn.apache.org/viewvc?rev=1403997&view=rev
Log:
TORQUE-241 fix issues with fully qualified table names in schema,xml

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java?rev=1403997&r1=1403996&r2=1403997&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
Wed Oct 31 06:12:45 2012
@@ -683,7 +683,7 @@ public class ColumnMap implements Column
      */
     public String getSqlExpression()
     {
-        return table.getName() + '.' + columnName;
+        return table.getFullyQualifiedTableName() + '.' + columnName;
     }
 
     @Override

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java?rev=1403997&r1=1403996&r2=1403997&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
Wed Oct 31 06:12:45 2012
@@ -52,6 +52,9 @@ public class TableMap implements Seriali
      */
     private static final long serialVersionUID = 1L;
 
+    /** The dot String. */
+    private static final String DOT = ".";
+
     /** The columns in the table. XML Order is preserved. */
     private final Map<String, ColumnMap> columns
             = Collections.synchronizedMap(
@@ -151,7 +154,7 @@ public class TableMap implements Seriali
         {
             throw new NullPointerException("tableName must not be null");
         }
-        int dotIndex = tableName.indexOf(".");
+        int dotIndex = tableName.indexOf(DOT);
         if (dotIndex != -1)
         {
             this.schemaName = tableName.substring(0, dotIndex);
@@ -254,6 +257,21 @@ public class TableMap implements Seriali
     }
 
     /**
+     * Returns the fully qualified table name, if available.
+     *
+     * @return the fully qualified table name, if a schema is set,
+     *         or just the table name if no schema is set, not null.
+     */
+    public String getFullyQualifiedTableName()
+    {
+        if (!StringUtils.isEmpty(schemaName))
+        {
+            return schemaName + DOT + tableName;
+        }
+        return tableName;
+    }
+
+    /**
      * Get the Java name of the table as defined in XML.
      *
      * @return A String with the Java name of the table.

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=1403997&r1=1403996&r2=1403997&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
Wed Oct 31 06:12:45 2012
@@ -409,7 +409,7 @@ public class BasePeerImpl<T> implements 
         else
         {
             fullTableName = SqlBuilder.getFullTableName(
-                    tableMap.getName(),
+                    tableMap.getFullyQualifiedTableName(),
                     criteria.getDbName());
         }
         boolean ownTableAdded = false;
@@ -549,7 +549,7 @@ public class BasePeerImpl<T> implements 
         if (tableMap != null)
         {
             fullTableName = SqlBuilder.getFullTableName(
-                    tableMap.getName(),
+                    tableMap.getFullyQualifiedTableName(),
                     criteria.getDbName());
         }
         else
@@ -746,7 +746,7 @@ public class BasePeerImpl<T> implements 
         }
 
         String fullTableName = SqlBuilder.getFullTableName(
-                getTableMap().getName(),
+                getTableMap().getFullyQualifiedTableName(),
                 databaseNameFromInsertValues);
         StringBuilder query = new StringBuilder("INSERT INTO ")
             .append(fullTableName)
@@ -1389,7 +1389,7 @@ public class BasePeerImpl<T> implements 
         if (query.getFromClause().isEmpty())
         {
             String tableName = SqlBuilder.getFullTableName(
-                    getTableMap().getName(),
+                    getTableMap().getFullyQualifiedTableName(),
                     criteria.getDbName());
             query.getFromClause().add(new FromElement(tableName));
         }
@@ -1537,7 +1537,7 @@ public class BasePeerImpl<T> implements 
         if (query.getFromClause().isEmpty())
         {
             String tableName = SqlBuilder.getFullTableName(
-                    getTableMap().getName(),
+                    getTableMap().getFullyQualifiedTableName(),
                     criteria.getDbName());
             query.getFromClause().add(new FromElement(tableName));
         }
@@ -1940,7 +1940,7 @@ public class BasePeerImpl<T> implements 
 
         query.getFromClause().clear();
         String fullTableName = SqlBuilder.getFullTableName(
-                getTableMap().getName(),
+                getTableMap().getFullyQualifiedTableName(),
                 criteria.getDbName());
         query.getFromClause().add(new FromElement(fullTableName));
 
@@ -2037,7 +2037,7 @@ public class BasePeerImpl<T> implements 
 
         query.getFromClause().clear();
         String fullTableName = SqlBuilder.getFullTableName(
-                getTableMap().getName(),
+                getTableMap().getFullyQualifiedTableName(),
                 criteria.getDbName());
         query.getFromClause().add(new FromElement(fullTableName));
 

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java?rev=1403997&r1=1403996&r2=1403997&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java
Wed Oct 31 06:12:45 2012
@@ -31,10 +31,16 @@ import java.sql.ResultSet;
 import java.util.List;
 
 import org.apache.torque.BaseTestCase;
+import org.apache.torque.Torque;
 import org.apache.torque.criteria.Criteria;
+import org.apache.torque.map.ColumnMap;
+import org.apache.torque.map.DatabaseMap;
+import org.apache.torque.map.TableMap;
 import org.apache.torque.om.mapper.CompositeMapper;
 import org.apache.torque.om.mapper.IntegerMapper;
 import org.apache.torque.om.mapper.StringMapper;
+import org.apache.torque.sql.Query;
+import org.apache.torque.sql.SqlBuilder;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
@@ -46,7 +52,7 @@ import org.mockito.MockitoAnnotations;
 public class BasePeerImplTest extends BaseTestCase
 {
     /** System under test. */
-    private BasePeerImpl basePeerImpl;
+    private BasePeerImpl<?> basePeerImpl;
 
     /** Mock db connection. */
     @Mock
@@ -63,13 +69,15 @@ public class BasePeerImplTest extends Ba
     @Override
     public void setUp() throws Exception
     {
-        basePeerImpl = new BasePeerImpl();
+        basePeerImpl = new BasePeerImpl<Object>();
         super.setUp();
         basePeerImpl.setTableMap(tableMap);
+        basePeerImpl.setDatabaseName("databaseName");
         MockitoAnnotations.initMocks(this);
         when(connection.prepareStatement((String) any()))
                 .thenReturn(preparedStatement);
         when(preparedStatement.executeQuery()).thenReturn(resultSet);
+        when(preparedStatement.executeUpdate()).thenReturn(1);
     }
 
     /**
@@ -106,7 +114,7 @@ public class BasePeerImplTest extends Ba
         verify(resultSet).close();
         verifyNoMoreInteractions(connection, preparedStatement, resultSet);
         // verify result
-        assertEquals(1, result.size()); // one rwow
+        assertEquals(1, result.size()); // one row
         assertEquals(2, result.get(0).size()); // two columns
         assertEquals("fd", result.get(0).get(0));
         assertEquals(23, result.get(0).get(1));
@@ -128,4 +136,35 @@ public class BasePeerImplTest extends Ba
         basePeerImpl.doSelect(criteria, new IntegerMapper(), connection);
         verify(preparedStatement).setFetchSize(13);
     }
+
+    public void testDeleteWithQualifiedTableName()
+            throws Exception
+    {
+        // prepare
+        DatabaseMap fullyQualifiedDatatabaseMap
+            = Torque.getDatabaseMap("fullyQualifiedDatatabaseMap");
+        TableMap tableMap = new TableMap(
+                "schema.fully_qualified_table",
+                fullyQualifiedDatatabaseMap);
+        ColumnMap columnMap = new ColumnMap("column", tableMap);
+        basePeerImpl.setTableMap(tableMap);
+        Criteria criteria = new Criteria();
+        criteria.where(columnMap, 42);
+
+        // execute
+        int deleteCount = basePeerImpl.doDelete(criteria, connection);
+
+        // verify mock
+        verify(connection).prepareStatement(
+                "DELETE FROM schema.fully_qualified_table "
+                + "WHERE fully_qualified_table.column=?");
+        verify(preparedStatement).setInt(1, 42);
+        verify(preparedStatement).executeUpdate();
+        verify(preparedStatement).close();
+        verifyNoMoreInteractions(connection, preparedStatement, resultSet);
+
+        // verify result
+        assertEquals(1, deleteCount);
+    }
+
 }



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