mpoeschl 2003/03/24 13:53:43
Modified: src/java/org/apache/torque/util BasePeer.java Criteria.java
Query.java
src/test/org/apache/torque/util CriteriaTest.java
QueryTest.java
Added: src/java/org/apache/torque/util UniqueList.java
src/test/org/apache/torque/util UniqueListTest.java
Log:
replace StringStack with UniqueList (ArrayList which does not allow null nor
duplicates)
Revision Changes Path
1.64 +34 -32 db-torque/src/java/org/apache/torque/util/BasePeer.java
Index: BasePeer.java
===================================================================
RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/BasePeer.java,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- BasePeer.java 21 Mar 2003 22:14:03 -0000 1.63
+++ BasePeer.java 24 Mar 2003 21:53:41 -0000 1.64
@@ -71,9 +71,10 @@
import java.util.Iterator;
import java.util.List;
-import org.apache.commons.collections.StringStack;
import org.apache.commons.lang.StringUtils;
+
import org.apache.log4j.Logger;
+
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.adapter.DB;
@@ -457,22 +458,23 @@
{
String key = (String) it.next();
Criteria.Criterion c = criteria.getCriterion(key);
- String[] tableNames = c.getAllTables();
- for (int i = 0; i < tableNames.length; i++)
+ List tableNames = c.getAllTables();
+ for (int i = 0; i < tableNames.size(); i++)
{
- String tableName2 = criteria.getTableForAlias(tableNames[i]);
+ String name = (String) tableNames.get(i);
+ String tableName2 = criteria.getTableForAlias(name);
if (tableName2 != null)
{
tables.add(new StringBuffer(
- tableNames[i].length() + tableName2.length() + 1)
+ name.length() + tableName2.length() + 1)
.append(tableName2)
.append(' ')
- .append(tableNames[i])
+ .append(name)
.toString());
}
else
{
- tables.add(tableNames[i]);
+ tables.add(name);
}
}
@@ -997,18 +999,18 @@
DB db = Torque.getDB(criteria.getDbName());
DatabaseMap dbMap = Torque.getDatabaseMap(criteria.getDbName());
- StringStack selectModifiers = query.getSelectModifiers();
- StringStack selectClause = query.getSelectClause();
- StringStack fromClause = query.getFromClause();
- StringStack whereClause = query.getWhereClause();
- StringStack orderByClause = query.getOrderByClause();
- StringStack groupByClause = query.getGroupByClause();
-
- StringStack orderBy = criteria.getOrderByColumns();
- StringStack groupBy = criteria.getGroupByColumns();
- StringStack select = criteria.getSelectColumns();
+ UniqueList selectModifiers = query.getSelectModifiers();
+ UniqueList selectClause = query.getSelectClause();
+ UniqueList fromClause = query.getFromClause();
+ UniqueList whereClause = query.getWhereClause();
+ UniqueList orderByClause = query.getOrderByClause();
+ UniqueList groupByClause = query.getGroupByClause();
+
+ UniqueList orderBy = criteria.getOrderByColumns();
+ UniqueList groupBy = criteria.getGroupByColumns();
+ UniqueList select = criteria.getSelectColumns();
Hashtable aliases = criteria.getAsColumns();
- StringStack modifiers = criteria.getSelectModifiers();
+ UniqueList modifiers = criteria.getSelectModifiers();
for (int i = 0; i < modifiers.size(); i++)
{
@@ -1017,7 +1019,7 @@
for (int i = 0; i < select.size(); i++)
{
- String columnName = select.get(i);
+ String columnName = (String) select.get(i);
if (columnName.indexOf('.') == -1 && columnName.indexOf('*') == -1)
{
throwMalformedColumnNameException("select", columnName);
@@ -1174,7 +1176,7 @@
{
for (int i = 0; i < groupBy.size(); i++)
{
- String groupByColumn = groupBy.get(i);
+ String groupByColumn = (String) groupBy.get(i);
if (groupByColumn.indexOf('.') == -1)
{
throwMalformedColumnNameException("group by",
@@ -1197,7 +1199,7 @@
// toUpperCase().
for (int i = 0; i < orderBy.size(); i++)
{
- String orderByColumn = orderBy.get(i);
+ String orderByColumn = (String) orderBy.get(i);
if (orderByColumn.indexOf('.') == -1)
{
throwMalformedColumnNameException("order by",
@@ -2239,16 +2241,16 @@
Query query = new Query();
- StringStack selectModifiers = query.getSelectModifiers();
- StringStack selectClause = query.getSelectClause();
- StringStack fromClause = query.getFromClause();
- StringStack whereClause = query.getWhereClause();
- StringStack orderByClause = query.getOrderByClause();
+ UniqueList selectModifiers = query.getSelectModifiers();
+ UniqueList selectClause = query.getSelectClause();
+ UniqueList fromClause = query.getFromClause();
+ UniqueList whereClause = query.getWhereClause();
+ UniqueList orderByClause = query.getOrderByClause();
- StringStack orderBy = criteria.getOrderByColumns();
- StringStack select = criteria.getSelectColumns();
+ UniqueList orderBy = criteria.getOrderByColumns();
+ UniqueList select = criteria.getSelectColumns();
Hashtable aliases = criteria.getAsColumns();
- StringStack modifiers = criteria.getSelectModifiers();
+ UniqueList modifiers = criteria.getSelectModifiers();
for (int i = 0; i < modifiers.size(); i++)
{
@@ -2257,7 +2259,7 @@
for (int i = 0; i < select.size(); i++)
{
- String columnName = select.get(i);
+ String columnName = (String) select.get(i);
if (columnName.indexOf('.') == -1)
{
throwMalformedColumnNameException("select", columnName);
@@ -2418,7 +2420,7 @@
// toUpperCase().
for (int i = 0; i < orderBy.size(); i++)
{
- String orderByColumn = orderBy.get(i);
+ String orderByColumn = (String) orderBy.get(i);
if (orderByColumn.indexOf('.') == -1)
{
throwMalformedColumnNameException("order by",
1.40 +28 -22 db-torque/src/java/org/apache/torque/util/Criteria.java
Index: Criteria.java
===================================================================
RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/Criteria.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- Criteria.java 27 Feb 2003 17:37:42 -0000 1.39
+++ Criteria.java 24 Mar 2003 21:53:42 -0000 1.40
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -65,8 +65,11 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.apache.commons.collections.StringStack;
+
+import org.apache.commons.lang.StringUtils;
+
import org.apache.log4j.Logger;
+
import org.apache.torque.Torque;
import org.apache.torque.adapter.DB;
import org.apache.torque.om.DateKey;
@@ -86,6 +89,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Eric Dobbs</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sam Joseph</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Martin Poeschl</a>
* @version $Id$
*/
public class Criteria extends Hashtable
@@ -159,10 +163,10 @@
private boolean ignoreCase = false;
private boolean singleRecord = false;
private boolean cascade = false;
- private StringStack selectModifiers = new StringStack();
- private StringStack selectColumns = new StringStack();
- private StringStack orderByColumns = new StringStack();
- private StringStack groupByColumns = new StringStack();
+ private UniqueList selectModifiers = new UniqueList();
+ private UniqueList selectColumns = new UniqueList();
+ private UniqueList orderByColumns = new UniqueList();
+ private UniqueList groupByColumns = new UniqueList();
private Criterion having = null;
private Hashtable asColumns = new Hashtable(8);
private ArrayList joinL = null;
@@ -1652,10 +1656,10 @@
/**
* Get select columns.
*
- * @return A StringStack with the name of the select
+ * @return An StringStack with the name of the select
* columns.
*/
- public StringStack getSelectColumns()
+ public UniqueList getSelectColumns()
{
return selectColumns;
}
@@ -1663,9 +1667,9 @@
/**
* Get select modifiers.
*
- * @return A StringStack with the select modifiers.
+ * @return An UniqueList with the select modifiers.
*/
- public StringStack getSelectModifiers()
+ public UniqueList getSelectModifiers()
{
return selectModifiers;
}
@@ -1709,9 +1713,9 @@
/**
* Get order by columns.
*
- * @return A StringStack with the name of the order columns.
+ * @return An UniqueList with the name of the order columns.
*/
- public StringStack getOrderByColumns()
+ public UniqueList getOrderByColumns()
{
return orderByColumns;
}
@@ -1719,9 +1723,9 @@
/**
* Get group by columns.
*
- * @return A StringStack with the name of the groupBy clause.
+ * @return An UniqueList with the name of the groupBy clause.
*/
- public StringStack getGroupByColumns()
+ public UniqueList getGroupByColumns()
{
return groupByColumns;
}
@@ -3366,7 +3370,7 @@
sb.append(field)
.append(comparison);
- StringStack inClause = new StringStack();
+ UniqueList inClause = new UniqueList();
if (value instanceof List)
{
@@ -3383,8 +3387,8 @@
}
StringBuffer inString = new StringBuffer();
- inString.append('(')
- .append(inClause.toString(",")).append(')');
+ inString.append('(').append(StringUtils.join(
+ inClause.iterator(), (","))).append(')');
sb.append(inString.toString());
}
else
@@ -3531,19 +3535,21 @@
/**
* get all tables from nested criterion objects
+ *
+ * @return the list of tables
*/
- public String[] getAllTables()
+ public List getAllTables()
{
- StringStack tables = new StringStack();
+ UniqueList tables = new UniqueList();
addCriterionTable(this, tables);
- return tables.toStringArray();
+ return tables;
}
/**
* method supporting recursion through all criterions to give
* us a StringStack of tables from each criterion
*/
- private void addCriterionTable(Criterion c, StringStack s)
+ private void addCriterionTable(Criterion c, UniqueList s)
{
if (c != null)
{
1.12 +61 -60 db-torque/src/java/org/apache/torque/util/Query.java
Index: Query.java
===================================================================
RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/Query.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Query.java 21 Mar 2003 17:31:08 -0000 1.11
+++ Query.java 24 Mar 2003 21:53:42 -0000 1.12
@@ -54,7 +54,7 @@
* <http://www.apache.org/>.
*/
-import org.apache.commons.collections.StringStack;
+import org.apache.commons.lang.StringUtils;
/**
* Used to assemble an SQL SELECT query. Attributes exist for the
@@ -65,6 +65,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sam Joseph</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Martin Poeschl</a>
* @version $Id$
*/
public class Query
@@ -79,12 +80,12 @@
private static final String LIMIT = " LIMIT ";
private static final String ROWCOUNT = " SET ROWCOUNT ";
- private StringStack selectModifiers = new StringStack();
- private StringStack selectColumns = new StringStack();
- private StringStack fromTables = new StringStack();
- private StringStack whereCriteria = new StringStack();
- private StringStack orderByColumns = new StringStack();
- private StringStack groupByColumns = new StringStack();
+ private UniqueList selectModifiers = new UniqueList();
+ private UniqueList selectColumns = new UniqueList();
+ private UniqueList fromTables = new UniqueList();
+ private UniqueList whereCriteria = new UniqueList();
+ private UniqueList orderByColumns = new UniqueList();
+ private UniqueList groupByColumns = new UniqueList();
private String having;
private String limit;
private String rowcount;
@@ -93,21 +94,21 @@
* Retrieve the modifier buffer in order to add modifiers to this
* query. E.g. DISTINCT and ALL.
*
- * @return A StringStack used to add modifiers.
+ * @return An UniqueList used to add modifiers.
*/
- public StringStack getSelectModifiers()
+ public UniqueList getSelectModifiers()
{
return selectModifiers;
}
-
+
/**
* Set the modifiers. E.g. DISTINCT and ALL.
- *
+ *
* @param modifiers the modifiers
*/
- public void setSelectModifiers(StringStack modifiers)
+ public void setSelectModifiers(UniqueList modifiers)
{
- selectModifiers = modifiers;
+ selectModifiers = modifiers;
}
/**
@@ -115,73 +116,73 @@
* are returned in this query.
*
*
- * @return A StringStack used to add columns to be selected.
+ * @return An UniqueList used to add columns to be selected.
*/
- public StringStack getSelectClause()
+ public UniqueList getSelectClause()
{
return selectColumns;
}
- /**
- * Set the columns.
- *
- * @param columns columns list
- */
- public void setSelectClause(StringStack columns)
- {
- selectColumns = columns;
- }
+ /**
+ * Set the columns.
+ *
+ * @param columns columns list
+ */
+ public void setSelectClause(UniqueList columns)
+ {
+ selectColumns = columns;
+ }
/**
* Retrieve the from buffer in order to specify which tables are
* involved in this query.
*
- * @return A StringStack used to add tables involved in the query.
+ * @return An UniqueList used to add tables involved in the query.
*/
- public StringStack getFromClause()
+ public UniqueList getFromClause()
{
return fromTables;
}
- /**
- * Set the from clause.
- *
- * @param tables the tables
- */
- public void setFromClause(StringStack tables)
- {
- fromTables = tables;
- }
+ /**
+ * Set the from clause.
+ *
+ * @param tables the tables
+ */
+ public void setFromClause(UniqueList tables)
+ {
+ fromTables = tables;
+ }
/**
* Retrieve the where buffer in order to specify the selection
* criteria E.g. column_a=3. Expressions added to the buffer will
* be separated using AND.
*
- * @return A StringStack used to add selection criteria.
+ * @return An UniqueList used to add selection criteria.
*/
- public StringStack getWhereClause()
+ public UniqueList getWhereClause()
{
return whereCriteria;
}
- /**
- * Set the where clause.
- *
- * @param where where clause
- */
- public void setWhereClause(StringStack where)
- {
- whereCriteria = where;
- }
+ /**
+ * Set the where clause.
+ *
+ * @param where where clause
+ */
+ public void setWhereClause(UniqueList where)
+ {
+ whereCriteria = where;
+ }
/**
* Retrieve the order by columns buffer in order to specify which
* columns are used to sort the results of the query.
*
- * @return A StringStack used to add columns to sort on.
+ * @return An UniqueList used to add columns to sort on.
*/
- public StringStack getOrderByClause()
+ public UniqueList getOrderByClause()
{
return orderByColumns;
}
@@ -190,9 +191,9 @@
* Retrieve the group by columns buffer in order to specify which
* columns are used to group the results of the query.
*
- * @return A StringStack used to add columns to group on.
+ * @return An UniqueList used to add columns to group on.
*/
- public StringStack getGroupByClause()
+ public UniqueList getGroupByClause()
{
return groupByColumns;
}
@@ -278,29 +279,29 @@
.append(" ");
}
stmt.append(SELECT)
- .append(selectModifiers.toString(" "))
- .append(selectColumns.toString(", "))
+ .append(StringUtils.join(selectModifiers.iterator(), " "))
+ .append(StringUtils.join(selectColumns.iterator(), ", "))
.append(FROM)
- .append(fromTables.toString(", "));
- if (!whereCriteria.empty())
+ .append(StringUtils.join(fromTables.iterator(), ", "));
+ if (!whereCriteria.isEmpty())
{
stmt.append(WHERE)
- .append(whereCriteria.toString(AND));
+ .append(StringUtils.join(whereCriteria.iterator(), AND));
}
- if (!groupByColumns.empty())
+ if (!groupByColumns.isEmpty())
{
stmt.append(GROUP_BY)
- .append(groupByColumns.toString(", "));
+ .append(StringUtils.join(groupByColumns.iterator(), ", "));
}
if (having != null)
{
stmt.append(HAVING)
.append(having);
}
- if (!orderByColumns.empty())
+ if (!orderByColumns.isEmpty())
{
stmt.append(ORDER_BY)
- .append(orderByColumns.toString(", "));
+ .append(StringUtils.join(orderByColumns.iterator(), ", "));
}
if (limit != null)
{
1.1 db-torque/src/java/org/apache/torque/util/UniqueList.java
Index: UniqueList.java
===================================================================
package org.apache.torque.util;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.ArrayList;
/**
* List with unique entries. UniqueList does not allow null nor duplicates.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Poeschl</a>
* @version $Id: UniqueList.java,v 1.1 2003/03/24 21:53:42 mpoeschl Exp $
*/
class UniqueList extends ArrayList
{
/**
* Adds an Object to the list.
*
* @param o the Object to add
* @return true if the Object is added
*/
public boolean add(Object o)
{
if (o != null && !contains(o))
{
return super.add(o);
}
return false;
}
}
1.18 +10 -7 db-torque/src/test/org/apache/torque/util/CriteriaTest.java
Index: CriteriaTest.java
===================================================================
RCS file: /home/cvs/db-torque/src/test/org/apache/torque/util/CriteriaTest.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- CriteriaTest.java 18 Feb 2003 10:30:54 -0000 1.17
+++ CriteriaTest.java 24 Mar 2003 21:53:43 -0000 1.18
@@ -3,7 +3,7 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,8 +54,11 @@
* <http://www.apache.org/>.
*/
+import java.util.List;
+
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
+
import org.apache.torque.BaseTestCase;
import org.apache.torque.TorqueException;
import org.apache.torque.adapter.DBFactory;
@@ -177,12 +180,12 @@
assertEquals(crit4, crita[2]);
assertEquals(crit5, crita[3]);
- String[] tables = crit2.getAllTables();
+ List tables = crit2.getAllTables();
- assertEquals(crit2.getTable(), tables[0]);
- assertEquals(crit3.getTable(), tables[1]);
- assertEquals(crit4.getTable(), tables[2]);
- assertEquals(crit5.getTable(), tables[3]);
+ assertEquals(crit2.getTable(), tables.get(0));
+ assertEquals(crit3.getTable(), tables.get(1));
+ assertEquals(crit4.getTable(), tables.get(2));
+ assertEquals(crit5.getTable(), tables.get(3));
// simple confirmations that equality operations work
assertTrue(crit2.hashCode() == crit2.hashCode());
1.3 +62 -64 db-torque/src/test/org/apache/torque/util/QueryTest.java
Index: QueryTest.java
===================================================================
RCS file: /home/cvs/db-torque/src/test/org/apache/torque/util/QueryTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- QueryTest.java 21 Mar 2003 17:31:09 -0000 1.2
+++ QueryTest.java 24 Mar 2003 21:53:43 -0000 1.3
@@ -56,74 +56,72 @@
import junit.framework.TestCase;
-import org.apache.commons.collections.StringStack;
-
/**
* Tests for Query
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Poeschl</a>
* @version $Id$
*/
-public class QueryTest extends TestCase
+public class QueryTest extends TestCase
{
- /**
- * Constructor for QueryTest.
- * @param arg0
- */
- public QueryTest(String arg0)
- {
- super(arg0);
- }
-
- /**
- * Test for String toString()
- */
- public void testColumns()
- {
- String expected
- = "SELECT tableA.column1, tableA.column2, tableB.column1 FROM
";
- Query query = new Query();
-
- StringStack columns = new StringStack();
- columns.add("tableA.column1");
- columns.add("tableA.column2");
- columns.add("tableB.column1");
- query.setSelectClause(columns);
-
- System.out.println(expected);
- System.out.println(query.toString());
- assertEquals(expected, query.toString());
- }
-
- /**
- * Test for String toString()
- */
- public void testToString()
- {
- String expected = "SELECT tableA.column1, tableA.column2, "
- + "tableB.column1 FROM tableA, tableB WHERE tableA.A =
tableB.A"
- + " AND tableA.B = 1234";
- Query query = new Query();
-
- StringStack columns = new StringStack();
- columns.add("tableA.column1");
- columns.add("tableA.column2");
- columns.add("tableB.column1");
- query.setSelectClause(columns);
-
- StringStack tables = new StringStack();
- tables.add("tableA");
- tables.add("tableB");
- query.setFromClause(tables);
-
- StringStack where = new StringStack();
- where.add("tableA.A = tableB.A");
- where.add("tableA.B = 1234");
- query.setWhereClause(where);
-
- System.out.println(expected);
- System.out.println(query.toString());
- assertEquals(expected, query.toString());
- }
+ /**
+ * Constructor for QueryTest.
+ * @param arg0
+ */
+ public QueryTest(String arg0)
+ {
+ super(arg0);
+ }
+
+ /**
+ * Test for String toString()
+ */
+ public void testColumns()
+ {
+ String expected
+ = "SELECT tableA.column1, tableA.column2, tableB.column1 FROM ";
+ Query query = new Query();
+
+ UniqueList columns = new UniqueList();
+ columns.add("tableA.column1");
+ columns.add("tableA.column2");
+ columns.add("tableB.column1");
+ query.setSelectClause(columns);
+
+ System.out.println(expected);
+ System.out.println(query.toString());
+ assertEquals(expected, query.toString());
+ }
+
+ /**
+ * Test for String toString()
+ */
+ public void testToString()
+ {
+ String expected = "SELECT tableA.column1, tableA.column2, "
+ + "tableB.column1 FROM tableA, tableB WHERE tableA.A = tableB.A"
+ + " AND tableA.B = 1234";
+ Query query = new Query();
+
+ UniqueList columns = new UniqueList();
+ columns.add("tableA.column1");
+ columns.add("tableA.column2");
+ columns.add("tableB.column1");
+ query.setSelectClause(columns);
+
+ UniqueList tables = new UniqueList();
+ tables.add("tableA");
+ tables.add("tableB");
+ query.setFromClause(tables);
+
+ UniqueList where = new UniqueList();
+ where.add("tableA.A = tableB.A");
+ where.add("tableA.B = 1234");
+ query.setWhereClause(where);
+
+ System.out.println(expected);
+ System.out.println(query.toString());
+ assertEquals(expected, query.toString());
+ }
}
1.1 db-torque/src/test/org/apache/torque/util/UniqueListTest.java
Index: UniqueListTest.java
===================================================================
package org.apache.torque.util;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
/**
* Test for UniqueList
*
* @author <a href="mailto:[EMAIL PROTECTED]">Martin Poeschl</a>
* @version $Id: UniqueListTest.java,v 1.1 2003/03/24 21:53:43 mpoeschl Exp $
*/
public class UniqueListTest extends TestCase
{
public UniqueListTest(String name)
{
super(name);
}
/**
* null values are not allowed
*/
public void testNull()
{
UniqueList uniqueList = new UniqueList();
Object o = null;
boolean actualReturn = uniqueList.add(o);
assertEquals("return value", false, actualReturn);
}
/**
* duplicates values are not allowed
*/
public void testUnique()
{
UniqueList uniqueList = new UniqueList();
uniqueList.add("Table");
uniqueList.add("TableA");
uniqueList.add("Table");
uniqueList.add("TableB");
assertEquals(3, uniqueList.size());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]