Author: tfischer
Date: Tue Feb 19 08:39:56 2013
New Revision: 1447624
URL: http://svn.apache.org/r1447624
Log:
TORQUE-268 Copy constructor for Criteria
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java?rev=1447624&r1=1447623&r2=1447624&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
Tue Feb 19 08:39:56 2013
@@ -137,23 +137,22 @@ public class Criteria
private boolean singleRecord = false;
/** List of modifiers like DISTICT. */
- private final UniqueList<String> selectModifiers = new
UniqueList<String>();
+ private final UniqueList<String> selectModifiers;
/** List of all columns to select. */
- private final UniqueColumnList selectColumns = new UniqueColumnList();
+ private final UniqueColumnList selectColumns;
/** All "order by" clauses, containing the order ASC or DESC. */
- private final UniqueList<OrderBy> orderByColumns = new
UniqueList<OrderBy>();
+ private final UniqueList<OrderBy> orderByColumns;
/** The names of columns to add to a groupBy clause */
- private final UniqueColumnList groupByColumns = new UniqueColumnList();
+ private final UniqueColumnList groupByColumns;
/**
* All "from" clauses. Empty if the from clause should be computed
* automatically.
*/
- private final UniqueList<FromElement> fromElements
- = new UniqueList<FromElement>();
+ private final UniqueList<FromElement> fromElements;
/** The having clause in a query. */
private Criterion having = null;
@@ -168,11 +167,10 @@ public class Criteria
* Maps column alias names to the real column names.
* The key of the map is the alias and the value is the real column.
*/
- private final Map<String, Column> asColumns
- = new LinkedHashMap<String, Column>();
+ private final Map<String, Column> asColumns;
/** Contains all joins. */
- private final List<Join> joins = new ArrayList<Join>();
+ private final List<Join> joins;
/** The name of the database in which this criteria should execute. */
private String dbName;
@@ -191,31 +189,72 @@ public class Criteria
* and the value is either the real name of the table
* or a corresponding subselect.
*/
- private final Map<String, Object> aliases = new HashMap<String, Object>();
+ private final Map<String, Object> aliases;
/** The JDBC statement fetch size, if any. */
private Integer fetchSize;
/**
- * Creates a new instance with the default capacity.
+ * Constructor.
*/
public Criteria()
{
- // empty
+ selectModifiers = new UniqueList<String>();
+ selectColumns = new UniqueColumnList();
+ orderByColumns = new UniqueList<OrderBy>();
+ groupByColumns = new UniqueColumnList();
+ fromElements = new UniqueList<FromElement>();
+ asColumns = new LinkedHashMap<String, Column>();
+ joins = new ArrayList<Join>();
+ aliases = new HashMap<String, Object>();
}
/**
- * Creates a new instance with the default capacity which corresponds to
- * the specified database.
+ * Constructor with the database name as parameter..
*
* @param dbName The database name.
*/
public Criteria(String dbName)
{
+ this();
this.dbName = dbName;
}
/**
+ * Copy-constructor.
+ * The copy is deep insofar as all contained lists are copied,
+ * however the elements contained in the list are not copied.
+ *
+ * @param toCopy the criteria to copy.
+ */
+ public Criteria(Criteria toCopy)
+ {
+ ignoreCase = toCopy.ignoreCase;
+ singleRecord = toCopy.singleRecord;
+ selectModifiers = new UniqueList<String>(toCopy.selectModifiers);
+ selectColumns = new UniqueColumnList(toCopy.selectColumns);
+ orderByColumns = new UniqueList<OrderBy>(toCopy.orderByColumns);
+ groupByColumns = new UniqueColumnList(toCopy.groupByColumns);
+ fromElements = new UniqueList<FromElement>(toCopy.fromElements);
+ if (toCopy.having != null)
+ {
+ having = new Criterion(toCopy.having);
+ }
+ forUpdate = toCopy.forUpdate;
+ if (toCopy.topLevelCriterion != null)
+ {
+ topLevelCriterion = new Criterion(toCopy.topLevelCriterion);
+ }
+ asColumns = new HashMap<String, Column>(toCopy.asColumns);
+ joins = new ArrayList<Join>(toCopy.joins);
+ dbName = toCopy.dbName;
+ limit = toCopy.limit;
+ offset = toCopy.offset;
+ aliases = new HashMap<String, Object>(toCopy.aliases);
+ fetchSize = toCopy.fetchSize;
+ }
+
+ /**
* Add an AS clause to the select columns. Usage:
* <p>
* <code>
@@ -982,7 +1021,9 @@ public class Criteria
}
/**
- * Returns a cloned object.
+ * Returns a shallow copy of this object.
+ *
+ * @return the cloned criteria.
*/
@Override
public Object clone()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]