db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1003835 - in /db/torque/torque4/trunk/torque-test: pom.xml src/main/schema/test-schema.xml src/test/java/org/apache/torque/sql/ src/test/java/org/apache/torque/sql/DatabaseTools.java src/test/java/org/apache/torque/sql/SkipSqlTest.java
Date Sat, 02 Oct 2010 17:03:11 GMT
Author: tfischer
Date: Sat Oct  2 17:03:11 2010
New Revision: 1003835

URL: http://svn.apache.org/viewvc?rev=1003835&view=rev
Log:
add test for options map and skipsql

Added:
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/DatabaseTools.java
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/SkipSqlTest.java
Modified:
    db/torque/torque4/trunk/torque-test/pom.xml
    db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml

Modified: db/torque/torque4/trunk/torque-test/pom.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/pom.xml?rev=1003835&r1=1003834&r2=1003835&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/pom.xml (original)
+++ db/torque/torque4/trunk/torque-test/pom.xml Sat Oct  2 17:03:11 2010
@@ -392,6 +392,7 @@
           <testIncludes>
             <include>**/*Test.java</include>
             <include>**/*TestCase.java</include>
+            <include>**/*Tools.java</include>
             <include>**/${torque.test.include.beans}</include>
             <include>**/${torque.test.include.managers}</include>
           </testIncludes>

Modified: db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml?rev=1003835&r1=1003834&r2=1003835&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml (original)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/test-schema.xml Sat Oct  2 17:03:11
2010
@@ -27,6 +27,9 @@
     xsi:schemaLocation="http://db.apache.org/torque/4.0/templates/database 
         http://db.apache.org/torque/4.0/templates/database.xsd">
 
+  <option key="databaseOptionKey1" value="databaseOptionValue1"/>
+  <option key="databaseOptionKey2" value="databaseOptionValue2"/>
+
   <external-schema filename="ext-schema.xml" />
 
   <!-- TRQS15 -->
@@ -504,7 +507,7 @@ Column.getJavaObject() not implimented f
   </table>
   
   <table name="SKIP_SQL" skipSql="true" description="table without SQL">
-    <column name="ID" primaryKey="true" type="INTEGER"  description="table without SQL"/>
+    <column name="ID" primaryKey="true" type="INTEGER" description="id for table without
SQL"/>
     <column name="FK" required="true" type="VARCHAR" size="30" />
     <foreign-key foreignTable="varchar_pk">
       <reference 
@@ -512,4 +515,17 @@ Column.getJavaObject() not implimented f
         foreign="test_key"/>
     </foreign-key>
   </table>
+
+  <table name="ABSTRACT" abstract="true" description="table with abstract OM class">
+    <column name="ID" primaryKey="true" type="INTEGER"  description="id for table with
abstract OM class"/>
+  </table>
+
+  <table name="OPTION" description="table with options">
+    <option key="tableOptionKey1" value="tableOptionValue1"/>
+    <option key="tableOptionKey2" value="tableOptionValue2"/>
+    <column name="ID" primaryKey="true" type="INTEGER" description="id for table with
options">
+      <option key="columnOptionKey1" value="columnOptionValue1"/>
+      <option key="columnOptionKey2" value="columnOptionValue2"/>
+    </column>
+  </table>
 </database>

Added: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/DatabaseTools.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/DatabaseTools.java?rev=1003835&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/DatabaseTools.java
(added)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/DatabaseTools.java
Sat Oct  2 17:03:11 2010
@@ -0,0 +1,52 @@
+package org.apache.torque.sql;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.Set;
+
+public class DatabaseTools
+{
+    /**
+     * Returns all table names available for this Connection.
+     * 
+     * @param connection the database connection to.
+     * 
+     * @return the table names in upper case.
+     *
+     * @throws SQLException if an error occurs.
+     */
+    public static Set<String> getTableNames(Connection connection)
+            throws SQLException
+    {
+        DatabaseMetaData metadata = connection.getMetaData();
+        ResultSet tableResultSet = metadata.getTables(
+                null, null, "%", new String[] {"TABLE"});
+        Set<String> result = new HashSet<String>();
+        while (tableResultSet.next())
+        {
+            String tableName = tableResultSet.getString(3);
+            result.add(tableName.toUpperCase());
+        }
+        return result;
+    }
+    
+    /**
+     * Returns whether a table with the given name exists.
+     * 
+     * @param connection the database connection to.
+     * @param name the name of the table to check. 
+     * 
+     * @return whether the table name exists.
+     *  
+     * @throws SQLException if an error occurs.
+     */
+    public static boolean tableExists(String name, Connection connection)
+            throws SQLException
+    {
+        Set<String> tableNames = getTableNames(connection);
+        return tableNames.contains(name.toUpperCase());
+    }
+}

Added: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/SkipSqlTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/SkipSqlTest.java?rev=1003835&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/SkipSqlTest.java
(added)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/sql/SkipSqlTest.java
Sat Oct  2 17:03:11 2010
@@ -0,0 +1,66 @@
+package org.apache.torque.sql;
+
+/*
+ * 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.BaseRuntimeTestCase;
+import org.apache.torque.Torque;
+
+/**
+ * Checks whether the SkipSql flag works on a table.
+ *
+ * @version $Id: DataTest.java 995641 2010-09-10 02:20:27Z tfischer $
+ */
+public class SkipSqlTest extends BaseRuntimeTestCase
+{
+    private static Log log = LogFactory.getLog(SkipSqlTest.class);
+
+    public SkipSqlTest(String name)
+    {
+        super(name);
+    }
+
+    /**
+     * Check that the skip_table (which has skipSql set to true)
+     * is not present in the database.
+     *
+     * @throws Exception if an error occurs.
+     */
+    public void testSkipTableNotPresent() throws Exception
+    {
+        Connection connection = null;
+        try
+        {
+            connection = Torque.getConnection();
+            assertFalse(DatabaseTools.tableExists("SKIP_SQL", connection));
+        }
+        finally
+        {
+            if (connection != null)
+            {
+                connection.close();
+            }
+        }
+    }
+
+}



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