empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1379934 - in /empire-db/trunk: empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/ empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/ empire-db/src/main/jav...
Date Sun, 02 Sep 2012 08:53:27 GMT
Author: doebele
Date: Sun Sep  2 08:53:27 2012
New Revision: 1379934

URL: http://svn.apache.org/viewvc?rev=1379934&view=rev
Log:
EMPIREDB-158 
avoid accidentially missing command param values for queryXXX-Functions in DBDatabase too!

Modified:
    empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
    empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
    empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/mssql/DBDatabaseDriverMSSqlTest.java
    empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java

Modified: empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
(original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-advanced/src/main/java/org/apache/empire/samples/db/advanced/SampleAdvApp.java
Sun Sep  2 08:53:27 2012
@@ -286,7 +286,7 @@ public class SampleAdvApp 
         cmd.select(T_DEP.count());
         // Check using "select count(*) from DEPARTMENTS"
         System.out.println("Checking whether table DEPARTMENTS exists (SQLException will
be logged if not - please ignore) ...");
-        return (db.querySingleInt(cmd.getSelect(), -1, conn) >= 0);
+        return (db.querySingleInt(cmd, -1, conn) >= 0);
     }
 
     /**

Modified: empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
(original)
+++ empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
Sun Sep  2 08:53:27 2012
@@ -237,7 +237,7 @@ public class SampleApp 
 		cmd.select(db.DEPARTMENTS.count());
 		// Check using "select count(*) from DEPARTMENTS"
 		System.out.println("Checking whether table DEPARTMENTS exists (SQLException will be logged
if not - please ignore) ...");
-		return (db.querySingleInt(cmd.getSelect(), -1, conn) >= 0);
+		return (db.querySingleInt(cmd, -1, conn) >= 0);
 	}
 
 	/**

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java Sun Sep 
2 08:53:27 2012
@@ -810,14 +810,14 @@ public abstract class DBDatabase extends
      * Returns the value of the first row/column of a sql-query as an object.
      * If the query does not return a result a QueryNoResultException is thrown
      * 
-     * @param sqlCmd the SQL-Command
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      * 
      * @return the value of the first column in the first row of the query 
      */
-    public final Object querySingleValue(String sqlCmd, Connection conn)
+    public final Object querySingleValue(DBCommand cmd, Connection conn)
     {
-        return querySingleValue(sqlCmd, (Object[])null, conn);  
+        return querySingleValue(cmd.getSelect(), cmd.getParamValues(), conn);  
     }
     
     /**
@@ -841,29 +841,29 @@ public abstract class DBDatabase extends
      * Returns the value of the first row/column of a sql-query as an int.
      * If the query does not return a result a QueryNoResultException is thrown
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param defVal the default value if no value was returned by the database
      * @param conn a valid connection to the database.
      *
      * @return the result as a int value
      */
-    public final int querySingleInt(String sqlCmd, int defVal, Connection conn)
+    public final int querySingleInt(DBCommand cmd, int defVal, Connection conn)
     { 
-        return querySingleInt(sqlCmd, null, defVal, conn);
+        return querySingleInt(cmd.getSelect(), cmd.getParamValues(), defVal, conn);
     }
 
     /**
      * Returns the value of the first row/column of a sql-query as an int.
      * If the query does not return a result a QueryNoResultException is thrown
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      *
      * @return the result as a int value
      */
-    public final int querySingleInt(String sqlCmd, Connection conn)
+    public final int querySingleInt(DBCommand cmd, Connection conn)
     { 
-        return querySingleInt(sqlCmd, null, 0, conn);
+        return querySingleInt(cmd.getSelect(), cmd.getParamValues(), 0, conn);
     }
 
     /**
@@ -887,29 +887,29 @@ public abstract class DBDatabase extends
      * Returns the value of the first row/column of a sql-query as a long.
      * If the query does not return a result a QueryNoResultException is thrown
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param defVal the default value
      * @param conn a valid connection to the database.
      * 
      * @return the result as a long value
      */
-    public final long querySingleLong(String sqlCmd, long defVal, Connection conn)
+    public final long querySingleLong(DBCommand cmd, long defVal, Connection conn)
     { 
-        return querySingleLong(sqlCmd, null, defVal, conn);
+        return querySingleLong(cmd.getSelect(), cmd.getParamValues(), defVal, conn);
     }
 
     /**
      * Returns the value of the first row/column of a sql-query as a long.
      * If the query does not return a result a QueryNoResultException is thrown
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      *
      * @return the result as a long value
      */
-    public final long querySingleLong(String sqlCmd, Connection conn)
+    public final long querySingleLong(DBCommand cmd, Connection conn)
     { 
-        return querySingleLong(sqlCmd, 0, conn);
+        return querySingleLong(cmd, 0, conn);
     }
     
     /**
@@ -933,29 +933,29 @@ public abstract class DBDatabase extends
      * Returns the value of the first row/column of a sql-query as a string.
      * If the query does not return a result a QueryNoResultException is thrown
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param defVal the default value if no value was returned by the database
      * @param conn a valid connection to the database.
      *
      * @return the result as a String object, if no result a empty String
      */
-    public final String querySingleString(String sqlCmd, String defVal, Connection conn)
+    public final String querySingleString(DBCommand cmd, String defVal, Connection conn)
     { 
-        return querySingleString(sqlCmd, null, defVal, conn);
+        return querySingleString(cmd.getSelect(), cmd.getParamValues(), defVal, conn);
     }
     
     /**
      * Returns the value of the first row/column of a sql-query as a string.
      * If the query does not return a result a QueryNoResultException is thrown
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      *
      * @return the result as a String object, if no result a empty String
      */
-    public final String querySingleString(String sqlCmd, Connection conn)
+    public final String querySingleString(DBCommand cmd, Connection conn)
     { 
-        return querySingleString(sqlCmd, null, "", conn);
+        return querySingleString(cmd.getSelect(), cmd.getParamValues(), "", conn);
     }
     
     /**
@@ -1018,14 +1018,14 @@ public abstract class DBDatabase extends
      * 
      * @param c the class type for the list 
      * @param <T> the type for the list
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      * 
      * @return the number of elements that have been added to the collection 
      */
-    public final <T> int querySimpleList(Class<T> c, String sqlCmd, Connection
conn, Collection<T> result)
+    public final <T> int querySimpleList(Class<T> c, DBCommand cmd, Connection
conn, Collection<T> result)
     {
-        return querySimpleList(c, sqlCmd, null, DataType.UNKNOWN, conn, result, -1); 
+        return querySimpleList(c, cmd.getSelect(), cmd.getParamValues(), DataType.UNKNOWN,
conn, result, -1); 
     }
 
     /**
@@ -1034,15 +1034,15 @@ public abstract class DBDatabase extends
      * 
      * @param c the class type for the list 
      * @param <T> the type for the list
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      * 
      * @return a list of the values of the first column of an sql query 
      */
-    public final <T> List<T> querySimpleList(Class<T> c, String sqlCmd,
Connection conn)
+    public final <T> List<T> querySimpleList(Class<T> c, DBCommand cmd,
Connection conn)
     {   // Execute the  Statement
         List<T> result = new ArrayList<T>();
-        if (querySimpleList(c, sqlCmd, conn, result)<0)
+        if (querySimpleList(c, cmd, conn, result)<0)
             return null;
         return result;
     }
@@ -1051,13 +1051,13 @@ public abstract class DBDatabase extends
      * Returns a one dimensional array from an sql query.
      * The array is filled with the values of the first column.
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      * @return a list of values of type Object 
      */
-    public final List<Object> querySimpleList(String sqlCmd, Connection conn)
+    public final List<Object> querySimpleList(DBCommand cmd, Connection conn)
     {   // Execute the  Statement
-        return querySimpleList(Object.class, sqlCmd, conn);
+        return querySimpleList(Object.class, cmd, conn);
     }
     
     /**
@@ -1113,27 +1113,27 @@ public abstract class DBDatabase extends
      * Fills an option list provided with the result from a query.
      * The option list is filled with the values of the first and second column.
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      * @return an Options object containing a set a of values and their corresponding names

      */
-    public final int queryOptionList(String sqlCmd, Connection conn, Options result)
+    public final int queryOptionList(DBCommand cmd, Connection conn, Options result)
     {   // Execute the  Statement
-        return queryOptionList(sqlCmd, null, conn, result); 
+        return queryOptionList(cmd.getSelect(), cmd.getParamValues(), conn, result); 
     }
 
     /**
      * Returns a list of key value pairs from an sql query.
      * The option list is filled with the values of the first and second column.
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      * @return an Options object containing a set a of values and their corresponding names

      */
-    public final Options queryOptionList(String sqlCmd, Connection conn)
+    public final Options queryOptionList(DBCommand cmd, Connection conn)
     {   // Execute the  Statement
         Options options = new Options();
-        queryOptionList(sqlCmd, null, conn, options);
+        queryOptionList(cmd.getSelect(), cmd.getParamValues(), conn, options);
         return options; 
     }
     
@@ -1196,27 +1196,27 @@ public abstract class DBDatabase extends
      * <p>This function should only be used for small lists.
      * Otherwise a DBReader should be used!</p>
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      * @return a list of object arrays 
      */
-    public final int queryObjectList(String sqlCmd, Connection conn, Collection<Object[]>
result)
+    public final int queryObjectList(DBCommand cmd, Connection conn, Collection<Object[]>
result)
     {   // Perform query
-        return queryObjectList(sqlCmd, null, conn, result, -1); 
+        return queryObjectList(cmd.getSelect(), cmd.getParamValues(), conn, result, -1);

     }
 
     /**
      * Returns the result of a query as a list Object-Arrays 
      * This function should only be used for small lists.
      * 
-     * @param sqlCmd the SQL statement
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      * @return a list of object arrays 
      */
-    public final List<Object[]> queryObjectList(String sqlCmd, Connection conn)
+    public final List<Object[]> queryObjectList(DBCommand cmd, Connection conn)
     {   // Execute the  Statement
         List<Object[]> result = new ArrayList<Object[]>();
-        queryObjectList(sqlCmd, null, conn, result, -1);
+        queryObjectList(cmd.getSelect(), cmd.getParamValues(), conn, result, -1);
         return result;
     }
 
@@ -1243,14 +1243,14 @@ public abstract class DBDatabase extends
      * Returns all values of the first row of a sql-query as an array.
      * If the query does not return a result a QueryNoResultException is thrown
      * 
-     * @param sqlCmd the SQL-Command
+     * @param cmd the Command object that contains the select statement
      * @param conn a valid connection to the database.
      * 
      * @return the values of the first row 
      */
-    public final Object[] querySingleRow(String sqlCmd, Connection conn)
+    public final Object[] querySingleRow(DBCommand cmd, Connection conn)
     {
-        return querySingleRow(sqlCmd, null, conn); 
+        return querySingleRow(cmd.getSelect(), cmd.getParamValues(), conn); 
     }
     
     /**

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java Sun Sep  2
08:53:27 2012
@@ -656,7 +656,7 @@ public abstract class DBRowSet extends D
         // Set key constraints
         setKeyConstraints(cmd, key);
         // check exits
-        return (db.querySingleInt(cmd.getSelect(), conn)==1);
+        return (db.querySingleInt(cmd, 0, conn)==1);
     }
 
     /**
@@ -916,7 +916,7 @@ public abstract class DBRowSet extends D
                 cmd.orderBy(keyColumns[i], true);
             }
             // Query all keys
-            List<Object[]> recKeys = db.queryObjectList(cmd.getSelect(), conn);
+            List<Object[]> recKeys = db.queryObjectList(cmd, conn);
             for (Object[] recKey : recKeys)
             {   
                 log.info("Deleting Record " + StringUtils.valueOf(recKey) + " from table
" + getName());

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
Sun Sep  2 08:53:27 2012
@@ -235,7 +235,7 @@ public class DBDatabaseDriverHSql extend
         db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
         sql.append(" FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES WHERE SEQUENCE_NAME='"+ seqName.toUpperCase()
+ "'");
         	
-        Object val = db.querySingleValue(sql.toString(), conn);
+        Object val = db.querySingleValue(sql.toString(), null, conn);
         if (val == null)
         { // Error!
             log.error("getNextSequenceValue: Invalid sequence value for sequence " + seqName);

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
Sun Sep  2 08:53:27 2012
@@ -302,7 +302,7 @@ public class DBDatabaseDriverOracle exte
         sql.append("SELECT ");
         db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
         sql.append(".NEXTVAL FROM DUAL");
-        Object val = db.querySingleValue(sql.toString(), conn);
+        Object val = db.querySingleValue(sql.toString(), null, conn);
         if (val == null)
         { // Error!
             log.error("getNextSequenceValue: Invalid sequence value for sequence " + seqName);

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
Sun Sep  2 08:53:27 2012
@@ -418,7 +418,7 @@ public class DBDatabaseDriverPostgreSQL 
         sql.append("SELECT nextval('");
         db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
         sql.append("')");
-        Object val = db.querySingleValue(sql.toString(), conn);
+        Object val = db.querySingleValue(sql.toString(), null, conn);
         if (val == null)
         { // Error!
             log.error("getNextSequenceValue: Invalid sequence value for sequence " + seqName);

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/sqlserver/DBDatabaseDriverMSSQL.java
Sun Sep  2 08:53:27 2012
@@ -416,7 +416,7 @@ public class DBDatabaseDriverMSSQL exten
         // Supports sequences?
         if (column.getDataType()==DataType.UNIQUEID)
         {
-            return db.querySingleValue("select newid()", conn);
+            return db.querySingleValue("select newid()", null, conn);
         }
         return super.getColumnAutoValue(db, column, conn);
     }

Modified: empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/mssql/DBDatabaseDriverMSSqlTest.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/mssql/DBDatabaseDriverMSSqlTest.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/mssql/DBDatabaseDriverMSSqlTest.java
(original)
+++ empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/mssql/DBDatabaseDriverMSSqlTest.java
Sun Sep  2 08:53:27 2012
@@ -107,6 +107,6 @@ public class DBDatabaseDriverMSSqlTest 
 		cmd.select(db.DEPARTMENT.count());
 		// Check using "select count(*) from DEPARTMENTS"
 		System.out.println("Checking whether table DEPARTMENTS exists (SQLException will be logged
if not - please ignore) ...");
-		return (db.querySingleInt(cmd.getSelect(), -1, conn) >= 0);
+		return (db.querySingleInt(cmd, -1, conn) >= 0);
 	}
 }

Modified: empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java?rev=1379934&r1=1379933&r2=1379934&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java
(original)
+++ empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java
Sun Sep  2 08:53:27 2012
@@ -132,7 +132,7 @@ public class DBDatabaseDriverPostgreSQLT
 		// Check using "select count(*) from DEPARTMENTS"
 		
 		try{
-			return (db.querySingleInt(cmd.getSelect(), -1, conn) >= 0);
+			return (db.querySingleInt(cmd, -1, conn) >= 0);
 		}catch(QueryFailedException ex){
 			System.out.println("Checking whether table DEPARTMENTS exists (SQLException will be logged
if not - please ignore) ...");
 			System.out.println(ex.getMessage());



Mime
View raw message