You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by mp...@apache.org on 2002/12/12 15:53:29 UTC
cvs commit: jakarta-turbine-torque/src/java/org/apache/torque/util BasePeer.java Criteria.java Query.java SqlExpression.java Transaction.java
mpoeschl 2002/12/12 06:53:29
Modified: src/java/org/apache/torque/util BasePeer.java Criteria.java
Query.java SqlExpression.java Transaction.java
Log:
o remove deprecated methods
o checkstyle fixes
Revision Changes Path
1.57 +122 -66 jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java
Index: BasePeer.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- BasePeer.java 9 Dec 2002 21:24:33 -0000 1.56
+++ BasePeer.java 12 Dec 2002 14:53:28 -0000 1.57
@@ -128,6 +128,7 @@
/** Hashtable that contains the cached mapBuilders. */
private static Hashtable mapBuilders = new Hashtable(5);
+ /** the log */
protected static Category category = Category.getInstance(BasePeer.class);
/**
@@ -135,7 +136,8 @@
*
* @param hash The Hashtable to convert.
* @return A byte[] with the converted Hashtable.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static byte[] hashtableToByteArray(Hashtable hash)
throws TorqueException
@@ -333,7 +335,8 @@
* @param table The table to delete records from.
* @param column The column in the where clause.
* @param value The value of the column.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static void deleteAll(
Connection con,
@@ -386,7 +389,8 @@
* @param table The table to delete records from.
* @param column The column in the where clause.
* @param value The value of the column.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static void deleteAll(String table, String column, int value)
throws TorqueException
@@ -409,7 +413,8 @@
* Criteria.
*
* @param criteria The criteria to use.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static void doDelete(Criteria criteria) throws TorqueException
{
@@ -436,7 +441,8 @@
*
* @param criteria The criteria to use.
* @param con A Connection.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static void doDelete(Criteria criteria, Connection con)
throws TorqueException
@@ -599,7 +605,8 @@
* @return An Object which is the id of the row that was inserted
* (if the table has a primary key) or null (if the table does not
* have a primary key).
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static ObjectKey doInsert(Criteria criteria) throws TorqueException
{
@@ -646,7 +653,8 @@
* @return An Object which is the id of the row that was inserted
* (if the table has a primary key) or null (if the table does not
* have a primary key).
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static ObjectKey doInsert(Criteria criteria, Connection con)
throws TorqueException
@@ -774,7 +782,8 @@
* @param rec A Record.
* @param tableName Name of table.
* @param criteria A Criteria.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
private static void insertOrUpdateRecord(
Record rec,
@@ -906,6 +915,7 @@
* Criteria.
*
* @param criteria A Criteria.
+ * @return the SQL query for display
* @exception TorqueException Trouble creating the query string.
*/
static String createQueryDisplayString(Criteria criteria)
@@ -919,6 +929,7 @@
* Criteria.
*
* @param criteria A Criteria.
+ * @return the SQL query for actual execution
* @exception TorqueException Trouble creating the query string.
*/
public static String createQueryString(Criteria criteria)
@@ -932,36 +943,37 @@
int offset = criteria.getOffset();
String sql;
- if ((limit > 0 || offset > 0)
- && db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
+ if ((limit > 0 || offset > 0)
+ && db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
{
// Build Oracle-style query with limit or offset.
- // If the original SQL is in variable: query then the requlting
+ // If the original SQL is in variable: query then the requlting
// SQL looks like this:
- // SELECT B.* FROM (
+ // SELECT B.* FROM (
// SELECT A.*, rownum as TORQUE$ROWNUM FROM (
// query
// ) A
- // ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM <= offset + limit
+ // ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM
+ // <= offset + limit
StringBuffer buf = new StringBuffer();
buf.append("SELECT B.* FROM ( ");
buf.append("SELECT A.*, rownum AS TORQUE$ROWNUM FROM ( ");
-
+
buf.append(query.toString());
buf.append(" ) A ");
buf.append(" ) B WHERE ");
- if (offset > 0)
+ if (offset > 0)
{
buf.append(" B.TORQUE$ROWNUM > ");
buf.append(offset);
- if (limit > 0)
+ if (limit > 0)
{
buf.append(" AND B.TORQUE$ROWNUM <= ");
buf.append(offset + limit);
}
}
- else
+ else
{
buf.append(" B.TORQUE$ROWNUM <= ");
buf.append(limit);
@@ -970,8 +982,8 @@
criteria.setOffset(0);
sql = buf.toString();
- }
- else
+ }
+ else
{
if (offset > 0 && db.supportsNativeOffset())
{
@@ -1001,6 +1013,7 @@
* is actually executed.
*
* @param criteria A Criteria.
+ * @return the sql query
* @exception TorqueException Trouble creating the query string.
*/
static Query createQuery(Criteria criteria)
@@ -1314,7 +1327,7 @@
//criteria.setLimit(-1);
//criteria.setOffset(0);
}
- else if (limit > 0 && db.supportsNativeLimit()
+ else if (limit > 0 && db.supportsNativeLimit()
&& db.getLimitStyle() != DB.LIMIT_STYLE_ORACLE)
{
limitString = String.valueOf(limit);
@@ -1343,7 +1356,8 @@
*
* @param criteria A Criteria.
* @return List of Record objects.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List doSelect(Criteria criteria) throws TorqueException
{
@@ -1382,7 +1396,8 @@
* @param criteria A Criteria.
* @param con A Connection.
* @return List of Record objects.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List doSelect(Criteria criteria, Connection con)
throws TorqueException
@@ -1400,7 +1415,8 @@
*
* @param queryString A String with the sql statement to execute.
* @return List of Record objects.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List executeQuery(String queryString) throws TorqueException
{
@@ -1415,7 +1431,8 @@
* @param queryString A String with the sql statement to execute.
* @param dbName The database to connect to.
* @return List of Record objects.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List executeQuery(String queryString, String dbName)
throws TorqueException
@@ -1431,7 +1448,8 @@
* @param singleRecord Whether or not we want to select only a
* single record.
* @return List of Record objects.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List executeQuery(
String queryString,
@@ -1450,7 +1468,8 @@
* single record.
* @param con A Connection.
* @return List of Record objects.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List executeQuery(
String queryString,
@@ -1471,7 +1490,8 @@
* @param singleRecord Whether or not we want to select only a
* single record.
* @return List of Record objects.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List executeQuery(
String queryString,
@@ -1512,7 +1532,8 @@
* single record.
* @param con A Connection.
* @return List of Record objects.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List executeQuery(
String queryString,
@@ -1561,6 +1582,10 @@
* objects. Used for functionality like util.LargeSelect.
*
* @see #getSelectResults(QueryDataSet, int, int, boolean)
+ * @param qds the QueryDataSet
+ * @return a List of Record objects
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List getSelectResults(QueryDataSet qds)
throws TorqueException
@@ -1573,6 +1598,11 @@
* objects. Used for functionality like util.LargeSelect.
*
* @see #getSelectResults(QueryDataSet, int, int, boolean)
+ * @param qds the QueryDataSet
+ * @param singleRecord
+ * @return a List of Record objects
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List getSelectResults(QueryDataSet qds, boolean singleRecord)
throws TorqueException
@@ -1586,6 +1616,12 @@
* functionality like util.LargeSelect.
*
* @see #getSelectResults(QueryDataSet, int, int, boolean)
+ * @param qds the QueryDataSet
+ * @param numberOfResults
+ * @param singleRecord
+ * @return a List of Record objects
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List getSelectResults(
QueryDataSet qds,
@@ -1671,7 +1707,8 @@
* @param criteria A Criteria.
* @return ColumnMap if the Criteria object contains a primary
* key, or null if it doesn't.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
private static ColumnMap getPrimaryKey(Criteria criteria)
throws TorqueException
@@ -1723,7 +1760,8 @@
*
* @param updateValues A Criteria object containing values used in
* set clause.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static void doUpdate(Criteria updateValues) throws TorqueException
{
@@ -1760,7 +1798,8 @@
* @param updateValues A Criteria object containing values used in
* set clause.
* @param con A Connection.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static void doUpdate(Criteria updateValues, Connection con)
throws TorqueException
@@ -1796,7 +1835,8 @@
* clause.
* @param updateValues A Criteria object containing values used in set
* clause.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static void doUpdate(Criteria selectCriteria, Criteria updateValues)
throws TorqueException
@@ -1832,7 +1872,8 @@
* @param updateValues A Criteria object containing values used in set
* clause.
* @param con A Connection.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static void doUpdate(
Criteria selectCriteria,
@@ -1943,7 +1984,8 @@
*
* @param stmt A String with the sql statement to execute.
* @return The number of rows affected.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static int executeStatement(String stmt) throws TorqueException
{
@@ -1958,7 +2000,8 @@
* @param stmt A String with the sql statement to execute.
* @param dbName Name of database to connect to.
* @return The number of rows affected.
- * @exception TorqueException a generic exception.
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static int executeStatement(String stmt, String dbName)
throws TorqueException
@@ -1985,7 +2028,8 @@
* @param stmt A String with the sql statement to execute.
* @param con A Connection.
* @return The number of rows affected.
- * @exception TorqueException
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static int executeStatement(String stmt, Connection con)
throws TorqueException
@@ -2037,19 +2081,13 @@
}
/**
- * @deprecated Use the better-named handleMultipleRecords() instead.
- */
- protected static void handleMultiple(DataSet ds) throws TorqueException
- {
- handleMultipleRecords(ds);
- }
-
- /**
* This method returns the MapBuilder specified in the
* TurbineResources.properties file. By default, this is
* org.apache.torque.util.db.map.TurbineMapBuilder.
*
* @return A MapBuilder.
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static MapBuilder getMapBuilder() throws TorqueException
{
@@ -2062,6 +2100,7 @@
* org.apache.torque.util.db.map.TurbineMapBuilder. The
* MapBuilder instances are cached in this class for speed.
*
+ * @param name name of the MapBuilder
* @return A MapBuilder, or null (and logs the error) if the
* MapBuilder was not found.
*/
@@ -2134,7 +2173,10 @@
* Performs a SQL <code>select</code> using a PreparedStatement.
* Note: this method does not handle null criteria values.
*
- * @exception TorqueException Error performing database query.
+ * @param criteria
+ * @param con
+ * @return
+ * @throws TorqueException Error performing database query.
*/
public static List doPSSelect(Criteria criteria, Connection con)
throws TorqueException
@@ -2208,6 +2250,11 @@
/**
* Do a Prepared Statement select according to the given criteria
+ *
+ * @param criteria
+ * @return
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static List doPSSelect(Criteria criteria) throws TorqueException
{
@@ -2229,6 +2276,12 @@
/**
* Create a new PreparedStatement. It builds a string representation
* of a query and a list of PreparedStatement parameters.
+ *
+ * @param criteria
+ * @param queryString
+ * @param params
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
public static void createPreparedStatement(
Criteria criteria,
@@ -2287,8 +2340,8 @@
String tableName2 = criteria.getTableForAlias(tableName);
if (tableName2 != null)
{
- fromClause.add(
- new StringBuffer(tableName.length() + tableName2.length() + 1)
+ fromClause.add(new StringBuffer(tableName.length()
+ + tableName2.length() + 1)
.append(tableName2)
.append(' ')
.append(tableName)
@@ -2323,8 +2376,8 @@
table = criteria.getTableForAlias(tableName);
if (table != null)
{
- fromClause.add(
- new StringBuffer(tableName.length() + table.length() + 1)
+ fromClause.add(new StringBuffer(tableName.length()
+ + table.length() + 1)
.append(table)
.append(' ')
.append(tableName)
@@ -2375,8 +2428,8 @@
String table = criteria.getTableForAlias(tableName);
if (table != null)
{
- fromClause.add(
- new StringBuffer(tableName.length() + table.length() + 1)
+ fromClause.add(new StringBuffer(tableName.length()
+ + table.length() + 1)
.append(table)
.append(' ')
.append(tableName)
@@ -2392,8 +2445,8 @@
table = criteria.getTableForAlias(tableName);
if (table != null)
{
- fromClause.add(
- new StringBuffer(tableName.length() + table.length() + 1)
+ fromClause.add(new StringBuffer(tableName.length()
+ + table.length() + 1)
.append(table)
.append(' ')
.append(tableName)
@@ -2521,7 +2574,7 @@
{
switch (db.getLimitStyle())
{
- /* Don't have a Sybase install to validate this against. (dlr)
+ /* Don't have a Sybase install to validate this against(dlr)
case DB.LIMIT_STYLE_SYBASE:
query.setRowcount(limitString);
break;
@@ -2532,27 +2585,28 @@
}
String sql;
- if ((limit > 0 || offset > 0)
- && db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
+ if ((limit > 0 || offset > 0)
+ && db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
{
// Build Oracle-style query with limit or offset.
- // If the original SQL is in variable: query then the requlting
+ // If the original SQL is in variable: query then the requlting
// SQL looks like this:
- // SELECT B.* FROM (
+ // SELECT B.* FROM (
// SELECT A.*, rownum as TORQUE$ROWNUM FROM (
// query
// ) A
- // ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM <= offset + limit
+ // ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM
+ // <= offset + limit
StringBuffer buf = new StringBuffer();
buf.append("SELECT B.* FROM ( ");
buf.append("SELECT A.*, rownum AS TORQUE$ROWNUM FROM ( ");
-
+
buf.append(query.toString());
buf.append(" ) A ");
buf.append(" ) B WHERE ");
- if (offset > 0)
- {
+ if (offset > 0)
+ {
buf.append(" B.TORQUE$ROWNUM > ");
buf.append(offset);
if (limit > 0)
@@ -2560,7 +2614,7 @@
buf.append(" AND B.TORQUE$ROWNUM <= ");
buf.append(offset + limit);
}
- }
+ }
else
{
buf.append(" B.TORQUE$ROWNUM <= ");
@@ -2570,8 +2624,8 @@
criteria.setOffset(0);
sql = buf.toString();
- }
- else
+ }
+ else
{
sql = query.toString();
}
@@ -2591,6 +2645,8 @@
*
* @param criteriaPhrase a String, one of "select", "join", or "order by"
* @param columnName a String containing the offending column name
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
*/
private static void throwMalformedColumnNameException(
String criteriaPhrase,
1.36 +74 -217 jakarta-turbine-torque/src/java/org/apache/torque/util/Criteria.java
Index: Criteria.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/Criteria.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- Criteria.java 28 Nov 2002 16:32:36 -0000 1.35
+++ Criteria.java 12 Dec 2002 14:53:28 -0000 1.36
@@ -54,9 +54,9 @@
* <http://www.apache.org/>.
*/
+import java.io.Serializable;
import java.lang.reflect.Array;
import java.math.BigDecimal;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.GregorianCalendar;
@@ -65,14 +65,12 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.apache.commons.collections.StringStack;
+import org.apache.log4j.Category;
import org.apache.torque.Torque;
-import org.apache.torque.TorqueException;
import org.apache.torque.adapter.DB;
-import org.apache.torque.map.DatabaseMap;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.ObjectKey;
-import org.apache.commons.collections.StringStack;
-import org.apache.log4j.Category;
/**
* This is a utility class that is used for retrieving different types
@@ -369,66 +367,6 @@
}
/**
- * Returns true if any of the tables in the criteria contain an
- * Object column.
- *
- * @return A boolean.
- * @throws TorqueException Any exceptions caught during processing will be
- * rethrown wrapped into a TorqueException.
- */
- public boolean containsObjectColumn() throws TorqueException
- {
- return containsObjectColumn(dbName);
- }
-
- /**
- * Returns true if any of the tables in the criteria contain an
- * Object column.
- *
- * @param databaseMapName A String.
- * @return A boolean.
- * @throws TorqueException Any exceptions caught during processing will be
- * rethrown wrapped into a TorqueException.
- * @deprecated not sure why anyone would need to use this outside of its
- * use in BasePeer, but it was public, so its now deprecated.
- * It was used to decide whether a transaction should be used, this can
- * be done with the useTransaction() method.
- */
- public boolean containsObjectColumn(String databaseMapName)
- throws TorqueException
- {
- // Peer or application may have noted the existence of a blob
- // so we can save the lookup.
- if (blobFlag != null)
- {
- return blobFlag.booleanValue();
- }
-
- DatabaseMap map = Torque.getDatabaseMap(databaseMapName);
- StringStack tables = new StringStack();
- for (Iterator it = super.values().iterator(); it.hasNext();)
- {
- Criterion co = (Criterion) it.next();
- String tableName = co.getTable();
- String tableName2 = getTableForAlias(tableName);
- if (tableName2 != null)
- {
- tableName = tableName2;
- }
-
- if (!tables.contains(tableName))
- {
- if (map.getTable(tableName).containsObjectColumn())
- {
- return true;
- }
- tables.add(tableName);
- }
- }
- return false;
- }
-
- /**
* Will force the sql represented by this criteria to be executed within
* a transaction. This is here primarily to support the oid type in
* postgresql. Though it can be used to require any single sql statement
@@ -900,7 +838,7 @@
*/
public ObjectKey getObjectKey(String name)
{
- return (ObjectKey)getCriterion(name).getValue();
+ return (ObjectKey) getCriterion(name).getValue();
}
/**
@@ -1108,8 +1046,8 @@
* @param table Name of table which contains the column
* @param column The column to run the comparison on
* @param value An Object.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria add(String table,
@@ -1117,11 +1055,13 @@
Object value,
SqlEnum comparison)
{
- StringBuffer sb = new StringBuffer(table.length() + column.length() + 1);
+ StringBuffer sb = new StringBuffer(table.length()
+ + column.length() + 1);
sb.append(table);
sb.append('.');
sb.append(column);
- super.put(sb.toString(),new Criterion(table, column, value, comparison));
+ super.put(sb.toString(),
+ new Criterion(table, column, value, comparison));
return this;
}
@@ -1156,8 +1096,8 @@
*
* @param column The column to run the comparison on
* @param value A Boolean.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria add(String column, boolean value, SqlEnum comparison)
@@ -1175,10 +1115,8 @@
* add(column, new Integer(value), EQUAL);
* </code>
*
- *
* @param column The column to run the comparison on
* @param value An int.
- *
* @return A modified Criteria object.
*/
public Criteria add(String column, int value)
@@ -1198,8 +1136,8 @@
*
* @param column The column to run the comparison on
* @param value An int.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria add(String column, int value, SqlEnum comparison)
@@ -1219,7 +1157,6 @@
*
* @param column The column to run the comparison on
* @param value A long.
- *
* @return A modified Criteria object.
*/
public Criteria add(String column, long value)
@@ -1237,11 +1174,10 @@
* add(column, new Long(value), comparison);
* </code>
*
- *
* @param column The column to run the comparison on
* @param value A long.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria add(String column, long value, SqlEnum comparison)
@@ -1280,8 +1216,8 @@
*
* @param column The column to run the comparison on
* @param value A float.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria add(String column, float value, SqlEnum comparison)
@@ -1301,7 +1237,6 @@
*
* @param column The column to run the comparison on
* @param value A double.
- *
* @return A modified Criteria object.
*/
public Criteria add(String column, double value)
@@ -1321,8 +1256,8 @@
*
* @param column The column to run the comparison on
* @param value A double.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria add(String column, double value, SqlEnum comparison)
@@ -1332,25 +1267,6 @@
}
/**
- * @deprecated These methods were wrongly named and are misleading.
- * Use addDate() instead.
- */
- public Criteria addTime(String column, int year, int month, int date)
- {
- return addDate(column, year, month, date);
- }
-
- /**
- * @deprecated These methods were wrongly named and are misleading.
- * Use addDate() instead.
- */
- public Criteria addTime(String column, int year, int month, int date,
- SqlEnum comparison)
- {
- return addDate(column, year, month, date, comparison);
- }
-
- /**
* Convenience method to add a Date object specified by
* year, month, and date into the Criteria.
* Equal to
@@ -1386,7 +1302,8 @@
* @param year An int with the year.
* @param month An int with the month.
* @param date An int with the date.
- * @param comparison String describing how to compare the column with the value
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria addDate(String column, int year, int month, int date,
@@ -1396,21 +1313,6 @@
return this;
}
- /* *
- * Convenience method to add a Key to Criteria.
- *
- * @param key A String value to use as key.
- * @param value A Key.
- * @return A modified Criteria object.
- * /
- public Criteria add (String key,
- Key value)
- {
- add(key, value.getInternalObject());
- return this;
- }
- */
-
/**
* This is the way that you should add a join of two tables. For
* example:
@@ -1766,15 +1668,6 @@
}
/**
- * @deprecated Use addAscendingOrderByColumn() instead.
- */
- public Criteria addOrderByColumn(String name)
- {
- orderByColumns.add(name);
- return this;
- }
-
- /**
* Add group by column name.
*
* @param groupBy The name of the column to group by.
@@ -1877,7 +1770,9 @@
sb.append("\nCurrent Query SQL (may not be complete or applicable): ")
.append(BasePeer.createQueryDisplayString(this));
}
- catch (Exception exc) {}
+ catch (Exception exc)
+ {
+ }
return sb.toString();
}
@@ -1899,7 +1794,7 @@
}
else if (this.size() == ((Criteria) crit).size())
{
- Criteria criteria = (Criteria)crit;
+ Criteria criteria = (Criteria) crit;
if (this.offset == criteria.getOffset()
&& this.limit == criteria.getLimit()
&& ignoreCase == criteria.isIgnoreCase()
@@ -1912,7 +1807,7 @@
)
{
isEquiv = true;
- for (Iterator it = criteria.keySet().iterator(); it.hasNext(); )
+ for (Iterator it = criteria.keySet().iterator(); it.hasNext();)
{
String key = (String) it.next();
if (this.containsKey(key))
@@ -1945,19 +1840,19 @@
*/
/**
- * This method adds a prepared Criterion object to the Criteria as a having clause.
- * You can get a new, empty Criterion object with the
+ * This method adds a prepared Criterion object to the Criteria as a having
+ * clause. You can get a new, empty Criterion object with the
* getNewCriterion() method.
*
* <p>
* <code>
* Criteria crit = new Criteria();
- * Criteria.Criterion c = crit.getNewCriterion(BasePeer.ID, new Integer(5), Criteria.LESS_THAN);
+ * Criteria.Criterion c = crit.getNewCriterion(BasePeer.ID, new Integer(5),
+ * Criteria.LESS_THAN);
* crit.addHaving(c);
* </code>
*
* @param having A Criterion object
- *
* @return A modified Criteria object.
*/
public Criteria addHaving(Criterion having)
@@ -1976,17 +1871,17 @@
* <p>
* <code>
* Criteria crit = new Criteria();
- * Criteria.Criterion c = crit.getNewCriterion(BasePeer.ID, new Integer(5), Criteria.LESS_THAN);
+ * Criteria.Criterion c = crit.getNewCriterion(BasePeer.ID, new Integer(5),
+ * Criteria.LESS_THAN);
* crit.and(c);
* </code>
*
* @param c A Criterion object
- *
* @return A modified Criteria object.
*/
public Criteria and(Criterion c)
{
- Criterion oc = getCriterion(c.getTable()+'.'+c.getColumn());
+ Criterion oc = getCriterion(c.getTable() + '.' + c.getColumn());
if (oc == null)
{
@@ -2084,7 +1979,6 @@
* @param table Name of the table which contains the column
* @param column The column to run the comparison on
* @param value An Object.
- *
* @return A modified Criteria object.
*/
public Criteria and(String table, String column, Object value)
@@ -2111,14 +2005,15 @@
* @param table Name of table which contains the column
* @param column The column to run the comparison on
* @param value An Object.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria and(String table, String column, Object value,
SqlEnum comparison)
{
- StringBuffer sb = new StringBuffer(table.length() + column.length() + 1);
+ StringBuffer sb = new StringBuffer(table.length()
+ + column.length() + 1);
sb.append(table);
sb.append('.');
sb.append(column);
@@ -2128,7 +2023,7 @@
if (oc == null)
{
- super.put(sb.toString(),nc);
+ super.put(sb.toString(), nc);
}
else
{
@@ -2148,7 +2043,6 @@
*
* @param column The column to run the comparison on
* @param value A Boolean.
- *
* @return A modified Criteria object.
*/
public Criteria and(String column, boolean value)
@@ -2170,7 +2064,6 @@
* @param value A Boolean.
* @param comparison String describing how to compare the column
* with the value
- *
* @return A modified Criteria object.
*/
public Criteria and(String column, boolean value, SqlEnum comparison)
@@ -2188,10 +2081,8 @@
* and(column, new Integer(value), EQUAL);
* </code>
*
- *
* @param column The column to run the comparison on
* @param value An int.
- *
* @return A modified Criteria object.
*/
public Criteria and(String column, int value)
@@ -2209,11 +2100,9 @@
* and(column, new Integer(value), comparison);
* </code>
*
- *
* @param column The column to run the comparison on
* @param value An int.
* @param comparison String describing how to compare the column with the value
- *
* @return A modified Criteria object.
*/
public Criteria and(String column, int value, SqlEnum comparison)
@@ -2231,10 +2120,8 @@
* and(column, new Long(value), EQUAL);
* </code>
*
- *
* @param column The column to run the comparison on
* @param value A long.
- *
* @return A modified Criteria object.
*/
public Criteria and(String column, long value)
@@ -2254,8 +2141,8 @@
*
* @param column The column to run the comparison on
* @param value A long.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria and(String column, long value, SqlEnum comparison)
@@ -2275,7 +2162,6 @@
*
* @param column The column to run the comparison on
* @param value A float.
- *
* @return A modified Criteria object.
*/
public Criteria and(String column, float value)
@@ -2295,8 +2181,8 @@
*
* @param column The column to run the comparison on
* @param value A float.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria and(String column, float value, SqlEnum comparison)
@@ -2316,7 +2202,6 @@
*
* @param column The column to run the comparison on
* @param value A double.
- *
* @return A modified Criteria object.
*/
public Criteria and(String column, double value)
@@ -2336,8 +2221,8 @@
*
* @param column The column to run the comparison on
* @param value A double.
- * @param comparison String describing how to compare the column with the value
- *
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria and(String column, double value, SqlEnum comparison)
@@ -2382,7 +2267,8 @@
* @param year An int with the year.
* @param month An int with the month.
* @param date An int with the date.
- * @param comparison String describing how to compare the column with the value
+ * @param comparison String describing how to compare the column with
+ * the value
* @return A modified Criteria object.
*/
public Criteria andDate(String column, int year, int month, int date,
@@ -2557,7 +2443,6 @@
* </code>
*
* @param c A Criterion object
- *
* @return A modified Criteria object.
*/
public Criteria or(Criterion c)
@@ -2624,7 +2509,6 @@
* @param column The column to run the comparison on
* @param value An Object.
* @param comparison A String.
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, Object value, SqlEnum comparison)
@@ -2660,7 +2544,6 @@
* @param table Name of the table which contains the column
* @param column The column to run the comparison on
* @param value An Object.
- *
* @return A modified Criteria object.
*/
public Criteria or(String table, String column, Object value)
@@ -2688,7 +2571,6 @@
* @param column The column to run the comparison on
* @param value An Object.
* @param comparison String describing how to compare the column with the value
- *
* @return A modified Criteria object.
*/
public Criteria or(String table, String column, Object value,
@@ -2723,7 +2605,6 @@
*
* @param column The column to run the comparison on
* @param value A Boolean.
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, boolean value)
@@ -2745,7 +2626,6 @@
* @param value A Boolean.
* @param comparison String describing how to compare the column
* with the value
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, boolean value, SqlEnum comparison)
@@ -2766,7 +2646,6 @@
*
* @param column The column to run the comparison on
* @param value An int.
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, int value)
@@ -2789,7 +2668,6 @@
* @param value An int.
* @param comparison String describing how to compare the column
* with the value
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, int value, SqlEnum comparison)
@@ -2807,10 +2685,8 @@
* or(column, new Long(value), EQUAL);
* </code>
*
- *
* @param column The column to run the comparison on
* @param value A long.
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, long value)
@@ -2832,7 +2708,6 @@
* @param value A long.
* @param comparison String describing how to compare the column
* with the value
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, long value, SqlEnum comparison)
@@ -2852,7 +2727,6 @@
*
* @param column The column to run the comparison on
* @param value A float.
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, float value)
@@ -2874,7 +2748,6 @@
* @param value A float.
* @param comparison String describing how to compare the column
* with the value
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, float value, SqlEnum comparison)
@@ -2894,7 +2767,6 @@
*
* @param column The column to run the comparison on
* @param value A double.
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, double value)
@@ -2916,7 +2788,6 @@
* @param value A double.
* @param comparison String describing how to compare the column
* with the value
- *
* @return A modified Criteria object.
*/
public Criteria or(String column, double value, SqlEnum comparison)
@@ -2992,7 +2863,7 @@
*/
public Criteria orIn(String column, Object[] values)
{
- or(column, (Object)values, Criteria.IN);
+ or(column, (Object) values, Criteria.IN);
return this;
}
@@ -3119,23 +2990,10 @@
* in the Criteria contain Blobs, so that the operation can be placed
* in a transaction if the db requires it.
* This is primarily to support Postgresql.
- * The flag is set to true by this method.
- * @deprecated Use @see #setBlobFlag(boolean)
- */
- public void setBlobFlag()
- {
- blobFlag = Boolean.TRUE;
- }
-
- /**
- * Peers can set this flag to notify BasePeer that the table(s) involved
- * in the Criteria contain Blobs, so that the operation can be placed
- * in a transaction if the db requires it.
- * This is primarily to support Postgresql.
*/
public void setBlobFlag(boolean b)
{
- blobFlag = (b ? Boolean.TRUE: Boolean.FALSE);
+ blobFlag = (b ? Boolean.TRUE : Boolean.FALSE);
}
/**
@@ -3339,7 +3197,7 @@
{
this.db = v;
- for(int i = 0; i < this.clauses.size(); i++)
+ for (int i = 0; i < this.clauses.size(); i++)
{
((Criterion) (clauses.get(i))).setDB(v);
}
@@ -3418,15 +3276,15 @@
}
Criterion clause = null;
- for(int j = 0; j < this.clauses.size(); j++)
+ for (int j = 0; j < this.clauses.size(); j++)
{
sb.append('(');
}
if (CUSTOM == comparison)
{
- if (value != null && ! "".equals(value))
+ if (value != null && !"".equals(value))
{
- sb.append((String)value);
+ sb.append((String) value);
}
}
else
@@ -3447,7 +3305,7 @@
ignoreStringCase, getDb(), sb);
}
- for(int i = 0; i < this.clauses.size(); i++)
+ for (int i = 0; i < this.clauses.size(); i++)
{
sb.append(this.conjunctions.get(i));
clause = (Criterion) (this.clauses.get(i));
@@ -3473,7 +3331,7 @@
DB db = getDb();
- for(int j = 0; j < this.clauses.size(); j++)
+ for (int j = 0; j < this.clauses.size(); j++)
{
sb.append('(');
}
@@ -3481,13 +3339,13 @@
{
if (!"".equals(value))
{
- sb.append((String)value);
+ sb.append((String) value);
}
}
else
{
String field = null;
- if (table == null)
+ if (table == null)
{
field = column;
}
@@ -3509,7 +3367,7 @@
if (value instanceof List)
{
- value = ((List)value).toArray (new Object[0]);
+ value = ((List) value).toArray (new Object[0]);
}
for (int i = 0; i < Array.getLength(value); i++)
@@ -3524,46 +3382,45 @@
StringBuffer inString = new StringBuffer();
inString.append('(')
.append(inClause.toString(",")).append(')');
-
- sb.append (inString.toString());
+ sb.append(inString.toString());
}
else
{
if (ignoreCase)
{
- sb.append (db.ignoreCase(field))
- .append (comparison)
- .append (db.ignoreCase("?"));
+ sb.append(db.ignoreCase(field))
+ .append(comparison)
+ .append(db.ignoreCase("?"));
}
else
{
- sb.append (field)
- .append (comparison)
- .append (" ? ");
+ sb.append(field)
+ .append(comparison)
+ .append(" ? ");
}
if (value instanceof java.util.Date)
{
params.add(new java.sql.Date(
- ((java.util.Date)value).getTime()));
+ ((java.util.Date) value).getTime()));
}
else if (value instanceof DateKey)
{
params.add(new java.sql.Date(
- ((DateKey)value).getDate().getTime()));
+ ((DateKey) value).getDate().getTime()));
}
else
{
- params.add (value.toString());
+ params.add(value.toString());
}
}
}
- for(int i = 0; i < this.clauses.size(); i++)
+ for (int i = 0; i < this.clauses.size(); i++)
{
sb.append(this.conjunctions.get(i));
Criterion clause = (Criterion) (this.clauses.get(i));
- clause.appendPsTo(sb,params);
+ clause.appendPsTo(sb, params);
sb.append(')');
}
}
@@ -3661,7 +3518,7 @@
h ^= column.hashCode();
}
- for(int i = 0; i < this.clauses.size(); i++)
+ for (int i = 0; i < this.clauses.size(); i++)
{
h ^= ((Criterion) (clauses.get(i))).hashCode();
}
@@ -3688,7 +3545,7 @@
if (c != null)
{
s.add(c.getTable());
- for(int i = 0; i < c.getClauses().size(); i++)
+ for (int i = 0; i < c.getClauses().size(); i++)
{
addCriterionTable((Criterion) (c.getClauses().get(i)), s);
}
@@ -3721,7 +3578,7 @@
if (c != null)
{
a.add(c);
- for(int i = 0; i < c.getClauses().size(); i++)
+ for (int i = 0; i < c.getClauses().size(); i++)
{
traverseCriterion((Criterion) (c.getClauses().get(i)), a);
}
1.9 +2 -2 jakarta-turbine-torque/src/java/org/apache/torque/util/Query.java
Index: Query.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/Query.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Query.java 27 Nov 2002 11:31:00 -0000 1.8
+++ Query.java 12 Dec 2002 14:53:28 -0000 1.9
@@ -250,7 +250,7 @@
if (!whereCriteria.empty())
{
stmt.append(WHERE)
- .append(whereCriteria.toString( AND ));
+ .append(whereCriteria.toString(AND));
}
if (!groupByColumns.empty())
{
1.20 +8 -16 jakarta-turbine-torque/src/java/org/apache/torque/util/SqlExpression.java
Index: SqlExpression.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/SqlExpression.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- SqlExpression.java 27 Nov 2002 11:31:00 -0000 1.19
+++ SqlExpression.java 12 Dec 2002 14:53:28 -0000 1.20
@@ -82,7 +82,9 @@
*/
public class SqlExpression
{
+ /** escaped single quote */
private static final char SINGLE_QUOTE = '\'';
+ /** escaped backslash */
private static final char BACKSLASH = '\\';
/**
@@ -219,7 +221,6 @@
* @param db Represents the database in use, for vendor specific functions.
* @param whereClause A StringBuffer to which the sql expression will be
* appended.
- * @exception Exception, a generic exception.
*/
public static void build(String columnName,
Object criteria,
@@ -555,7 +556,7 @@
String ret = null;
if (value instanceof String)
{
- ret = quoteAndEscapeText((String)value, db);
+ ret = quoteAndEscapeText((String) value, db);
}
else
{
@@ -574,12 +575,12 @@
* escaped.
*
* @param rawText The <i>unquoted</i>, <i>unescaped</i> text to process.
- * @param db
+ * @param db the db
* @return Quoted and escaped text.
*/
public static String quoteAndEscapeText(String rawText, DB db)
{
- StringBuffer buf = new StringBuffer((int)(rawText.length() * 1.1));
+ StringBuffer buf = new StringBuffer((int) (rawText.length() * 1.1));
// Some databases do not need escaping.
String escapeString = new String();
@@ -589,7 +590,8 @@
}
else
{
- escapeString = String.valueOf(BACKSLASH) + String.valueOf(BACKSLASH);
+ escapeString = String.valueOf(BACKSLASH)
+ + String.valueOf(BACKSLASH);
}
char[] data = rawText.toCharArray();
@@ -611,15 +613,5 @@
buf.append(SINGLE_QUOTE);
return buf.toString();
- }
-
- /**
- * @deprecated Use quoteAndEscapeText(String rawText, DB db) instead.
- * the quoteAndEscapeText rules depend on the database.
- * @see #quoteAndEscapeText(String, DB)
- */
- public static String quoteAndEscapeText(String rawText)
- {
- return quoteAndEscapeText(rawText, null);
}
}
1.3 +15 -21 jakarta-turbine-torque/src/java/org/apache/torque/util/Transaction.java
Index: Transaction.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/Transaction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Transaction.java 14 Aug 2002 12:10:45 -0000 1.2
+++ Transaction.java 12 Dec 2002 14:53:28 -0000 1.3
@@ -64,16 +64,16 @@
/**
* Refactored begin/commit/rollback transaction methods away from
* the <code>BasePeer</code>.
- *
+ *
* <p>
* This can be used to handle cases where transaction support is optional.
- * The second parameter of beginOptionalTransaction will determine with a transaction
+ * The second parameter of beginOptionalTransaction will determine with a transaction
* is used or not. If a transaction is not used, the commit and rollback methods
* do not have any effect. Instead it simply makes the logic easier to follow
* by cutting down on the if statements based solely on whether a transaction
* is needed or not.
- *
- *
+ *
+ *
* @author <a href="mailto:stephenh@chase3000.com">Stephen Haberman</a>
* @version $Id$
*/
@@ -107,7 +107,8 @@
* @return The Connection for the transaction.
* @throws TorqueException
*/
- public static Connection beginOptional(String dbName, boolean useTransaction)
+ public static Connection beginOptional(String dbName,
+ boolean useTransaction)
throws TorqueException
{
Connection con = Torque.getConnection(dbName);
@@ -137,10 +138,9 @@
{
if (con == null)
{
- throw new NullPointerException(
- "Connection object was null. "
+ throw new NullPointerException("Connection object was null. "
+ "This could be due to a misconfiguration of the "
- + "DataSourceFactory. Check the logs and Torque.properties "
+ + "DataSourceFactory. Check the logs and Torque.properties "
+ "to better determine the cause.");
}
@@ -176,8 +176,7 @@
{
if (con == null)
{
- throw new NullPointerException(
- "Connection object was null. "
+ throw new NullPointerException("Connection object was null. "
+ "This could be due to a misconfiguration of the "
+ "DataSourceFactory. Check the logs and Torque.properties "
+ "to better determine the cause.");
@@ -194,12 +193,9 @@
}
catch (SQLException e)
{
- category.error(
- "An attempt was made to rollback a transaction "
+ category.error("An attempt was made to rollback a transaction "
+ "but the database did not allow the operation to be "
- + "rolled back.",
- e);
-
+ + "rolled back.", e);
throw new TorqueException(e);
}
finally
@@ -207,14 +203,14 @@
Torque.closeConnection(con);
}
}
-
+
/**
* Roll back a transaction without throwing errors if they occur.
- *
+ *
* @param con The Connection for the transaction.
* @see safeRollback
*/
- public static void safeRollback(Connection con)
+ public static void safeRollback(Connection con)
{
try
{
@@ -225,6 +221,4 @@
category.error("An error occured during rollback.", e);
}
}
-
-
}