Author: tfischer
Date: Fri May 11 01:09:05 2012
New Revision: 1336994
URL: http://svn.apache.org/viewvc?rev=1336994&view=rev
Log:
TORQUE-177: Function re-works to let functions implement the column interface and ease aggregate function handling
Added:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AggregateFunction.java
- copied, changed from r1335015, db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Aggregate.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Avg.java (with props)
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Count.java (with props)
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Max.java (with props)
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Min.java (with props)
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Sum.java (with props)
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AbstractFunctionTest.java (with props)
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AggregateFunctionTest.java (with props)
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AvgTest.java (with props)
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/CountTest.java (with props)
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MaxTest.java (with props)
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MinTest.java (with props)
db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/SumTest.java (with props)
Removed:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Aggregate.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/FunctionEnum.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/FunctionFactory.java
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/CountHelper.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AbstractFunction.java
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/SQLFunction.java
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java?rev=1336994&r1=1336993&r2=1336994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java Fri May 11 01:09:05 2012
@@ -21,14 +21,9 @@ package org.apache.torque.adapter;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.Hashtable;
-import java.util.Map;
import org.apache.torque.TorqueException;
import org.apache.torque.sql.Query;
-import org.apache.torque.util.functions.Aggregate;
-import org.apache.torque.util.functions.FunctionEnum;
-import org.apache.torque.util.functions.SQLFunction;
/**
* This class is the abstract base for any database adapter
@@ -57,29 +52,6 @@ public abstract class AbstractDBAdapter
private static final long serialVersionUID = 1L;
/**
- * The default look up table for function classes.
- */
- private final Map<FunctionEnum, Class<? extends SQLFunction>> functionClasses
- = new Hashtable<FunctionEnum, Class<? extends SQLFunction>>();
-
- /*
- * Initialize the functionClasses lookup table with SQL99 standard
- * functions. Uses this method because DB implementations don't
- * currently call super() in their constructors and we want this
- * to be set in all of them.
- *
- * Override the values set here in the DB Specific adaptor's
- * constructor.
- */
- {
- functionClasses.put(FunctionEnum.AVG, Aggregate.Avg.class);
- functionClasses.put(FunctionEnum.COUNT, Aggregate.Count.class);
- functionClasses.put(FunctionEnum.MAX, Aggregate.Max.class);
- functionClasses.put(FunctionEnum.MIN, Aggregate.Min.class);
- functionClasses.put(FunctionEnum.SUM, Aggregate.Sum.class);
- }
-
- /**
* Empty constructor.
*/
protected AbstractDBAdapter()
@@ -265,19 +237,4 @@ public abstract class AbstractDBAdapter
{
return false;
}
-
- /**
- * Return the class which implements the SQLFunction interface for the
- * specified function.
- *
- * @param function The function to get the class for.
- * @return The SQLFunction implementation for a function of this type that
- * will work with this type of DB. Null indicates a class was not
- * found.
- */
- public Class<? extends SQLFunction> getFunctionClass(FunctionEnum function)
- {
- return functionClasses.get(function);
- }
-
}
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java?rev=1336994&r1=1336993&r2=1336994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java Fri May 11 01:09:05 2012
@@ -25,7 +25,6 @@ import java.sql.SQLException;
import org.apache.torque.TorqueException;
import org.apache.torque.sql.Query;
-import org.apache.torque.util.functions.FunctionEnum;
/**
* <code>DB</code> defines the interface for a Torque database
@@ -211,21 +210,4 @@ public interface DB extends Serializable
* @return whether the escape clause should be appended or not.
*/
boolean useEscapeClauseForLike();
-
- /**
- * Return the class which implements the SQLFunction interface for the
- * specified function. This class must have an empty constructor and
- * can be a single level inner class (or not).
- *
- * @param function The function to get the class for.
- *
- * @return The SQLFunction implementation for a function of this type that
- * will work with this type of DB. Null indicates a class was not
- * found.
- *
- * @see org.apache.torque.util.functions.AbstractFunction
- * @see org.apache.torque.util.functions.Aggregate
- * @see org.apache.torque.util.functions.SQLFunction
- */
- Class<?> getFunctionClass(FunctionEnum function);
}
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/CountHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/CountHelper.java?rev=1336994&r1=1336993&r2=1336994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/CountHelper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/CountHelper.java Fri May 11 01:09:05 2012
@@ -37,6 +37,7 @@ import org.apache.torque.TorqueException
import org.apache.torque.criteria.SqlEnum;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.mapper.IntegerMapper;
+import org.apache.torque.util.functions.Count;
/**
* Counts entries matching a criteria.
@@ -59,6 +60,7 @@ public class CountHelper
* org.apache.toraue.util.Criteria. This method will be removed
* in Torque 4.1.
*/
+ @Deprecated
public int count(Criteria c) throws TorqueException
{
return count(c, null, "*", null);
@@ -98,6 +100,7 @@ public class CountHelper
* org.apache.toraue.util.Criteria. This method will be removed
* in Torque 4.1.
*/
+ @Deprecated
public int count(Criteria c, Connection conn) throws TorqueException
{
return count(c, conn, "*", null);
@@ -134,6 +137,7 @@ public class CountHelper
* org.apache.toraue.util.Criteria. This method will be removed
* in Torque 4.1.
*/
+ @Deprecated
public int count(Criteria c, String columnName)
throws TorqueException
{
@@ -168,6 +172,7 @@ public class CountHelper
* org.apache.toraue.util.Criteria. This method will be removed
* in Torque 4.1.
*/
+ @Deprecated
public int count(Criteria c, Column column)
throws TorqueException
{
@@ -203,6 +208,7 @@ public class CountHelper
* org.apache.toraue.util.Criteria. This method will be removed
* in Torque 4.1.
*/
+ @Deprecated
public int count(Criteria c, Connection conn, Column column)
throws TorqueException
{
@@ -285,6 +291,7 @@ public class CountHelper
* org.apache.toraue.util.Criteria. This method will be removed
* in Torque 4.1.
*/
+ @Deprecated
public int count(
Criteria c,
Connection conn,
@@ -309,12 +316,7 @@ public class CountHelper
distinct = true;
}
- StringBuffer countStr = new StringBuffer("COUNT(");
- countStr.append(distinct ? SqlEnum.DISTINCT.toString() : "");
- countStr.append(columnName);
- countStr.append(")");
-
- c.addSelectColumn(new ColumnImpl(countStr.toString()));
+ c.addSelectColumn(new Count(new ColumnImpl(columnName), distinct));
List<Integer> result;
if (conn == null)
@@ -367,12 +369,7 @@ public class CountHelper
distinct = true;
}
- StringBuffer countStr = new StringBuffer("COUNT(");
- countStr.append(distinct ? SqlEnum.DISTINCT.toString() : "");
- countStr.append(columnName);
- countStr.append(")");
-
- c.addSelectColumn(new ColumnImpl(countStr.toString()));
+ c.addSelectColumn(new Count(new ColumnImpl(columnName), distinct));
List<Integer> result;
if (conn == null)
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java?rev=1336994&r1=1336993&r2=1336994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java Fri May 11 01:09:05 2012
@@ -150,7 +150,7 @@ public class SummaryHelper
* @param crit The base criteria to build on.
* @param resultTypes the classes to which the return values of the query
* should be cast, or null to let the database driver decide.
- * See org.apache.torque.om.mapper.ObjectListMapper´for the supported
+ * See org.apache.torque.om.mapper.ObjectListMapper�for the supported
* classes.
*
* @return Results as a ListOrderMapCI<String, List<Object>> object.
@@ -188,7 +188,7 @@ public class SummaryHelper
* @param crit The base criteria to build on.
* @param resultTypes the classes to which the return values of the query
* should be cast, or null to let the database driver decide.
- * See org.apache.torque.om.mapper.ObjectListMapper´for the supported
+ * See org.apache.torque.om.mapper.ObjectListMapper�for the supported
* classes.
*
* @return Results as a ListOrderMapCI<String, List<Object>> object.
@@ -268,7 +268,7 @@ public class SummaryHelper
* @param crit The base criteria to build on.
* @param resultTypes the classes to which the return values of the query
* should be cast, or null to let the database driver decide.
- * See org.apache.torque.om.mapper.ObjectListMapper´for the supported
+ * See org.apache.torque.om.mapper.ObjectListMapper�for the supported
* classes.
* @param conn The DB Connection to use.
*
@@ -376,7 +376,7 @@ public class SummaryHelper
* @param crit The base criteria to build on.
* @param resultTypes the classes to which the return values of the query
* should be cast, or null to let the database driver decide.
- * See org.apache.torque.om.mapper.ObjectListMapper´for the supported
+ * See org.apache.torque.om.mapper.ObjectListMapper�for the supported
* classes.
* @param conn The DB Connection to use.
*
@@ -530,7 +530,7 @@ public class SummaryHelper
null,
col.getTableName(),
col.getColumnName(),
- f.toSQL()));
+ f.getSqlExpression()));
if (!haveFromTable) // Last chance. Get it from the func.
{
{
@@ -612,7 +612,7 @@ public class SummaryHelper
null,
col.getTableName(),
col.getColumnName(),
- f.toSQL()));
+ f.getSqlExpression()));
if (!haveFromTable) // Last chance. Get it from the func.
{
{
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AbstractFunction.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AbstractFunction.java?rev=1336994&r1=1336993&r2=1336994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AbstractFunction.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AbstractFunction.java Fri May 11 01:09:05 2012
@@ -19,11 +19,12 @@ package org.apache.torque.util.functions
* under the License.
*/
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
-import java.util.Vector;
+import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.Column;
-import org.apache.torque.Torque;
/**
* A default framework that implements the core SQLFunction interface
@@ -35,9 +36,7 @@ import org.apache.torque.Torque;
public abstract class AbstractFunction implements SQLFunction
{
/** The arguments being used by this function */
- private List<Object> argumentList;
- /** The Torque DB connector name this function is associated with */
- private String dbName;
+ private List<Object> argumentList = new ArrayList<Object>();
/**
* Functions should only be created via the FunctionFactory class.
@@ -54,7 +53,7 @@ public abstract class AbstractFunction i
*
* @return The SQL String.
*/
- public abstract String toSQL();
+ public abstract String getSqlExpression();
/**
* Return all the parameters as an object array. This allow for
@@ -76,6 +75,17 @@ public abstract class AbstractFunction i
}
/**
+ * Sets the function arguments.
+ *
+ * @param args the function arguments, not null.
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void setArguments(Object[] args)
+ {
+ this.argumentList = new ArrayList(Arrays.asList(args));
+ }
+
+ /**
* Returns the column to which this function is applied.
*
* @return the column, not null.
@@ -97,27 +107,6 @@ public abstract class AbstractFunction i
}
/**
- * Get the name of the Torque Database associated with this function.
- *
- * @return The DB name. Should not be null (use default DB in this case).
- * @exception IllegalStateException If Torque has not been initialized and
- * the default DB name can not be determined.
- */
- public String getDBName()
- {
- if (this.dbName == null)
- {
- this.dbName = Torque.getDefaultDB();
- }
- if (this.dbName == null)
- {
- throw new IllegalStateException(
- "Could not get DB Name! Torque may not be initialized yet!");
- }
- return this.dbName;
- }
-
- /**
* Return the object representation of the function parameter
* at the specified index. Will be null if parameter does not exist.
*
@@ -164,16 +153,112 @@ public abstract class AbstractFunction i
{
if (this.argumentList == null)
{
- this.argumentList = new Vector<Object>();
+ this.argumentList = new ArrayList<Object>();
}
return this.argumentList;
}
/**
- * @param dbName the dbName to set
+ * Returns the column name.
+ * This implementation always return null because we do not reference
+ * a real column.
+ *
+ * @return the column name, always null.
*/
- public void setDBName(String dbName)
+ public String getColumnName()
{
- this.dbName = dbName;
+ return null;
+ }
+
+
+ /**
+ * Returns the name of the associated table
+ * (not prefixed by the schema name) from the function argument(s).
+ * In case that no unique table name can be determined, null is returned.
+ *
+ * @return the name of the table, may be null but not blank.
+ */
+ public String getTableName()
+ {
+ String tableName = null;
+ boolean columnFound = false;
+ for (Object argument : argumentList)
+ {
+ if (argument instanceof Column)
+ {
+ Column column = (Column) argument;
+ if (columnFound
+ && !ObjectUtils.equals(tableName, column.getTableName()))
+ {
+ // cannot determine unique table name, return null
+ return null;
+ }
+ tableName = column.getTableName();
+ columnFound = true;
+ }
+ }
+ return tableName;
+ }
+
+ /**
+ * Returns the name of any fixed schema prefix for the column's table
+ * (if any) from the function argument(s).
+ * In case that no unique schema can be determined, null is returned.
+ *
+ * @return the schema name, or null if the schema is not known.
+ */
+ public String getSchemaName()
+ {
+ String schemaName = null;
+ boolean columnFound = false;
+ for (Object argument : argumentList)
+ {
+ if (argument instanceof Column)
+ {
+ Column column = (Column) argument;
+ if (columnFound
+ && !ObjectUtils.equals(schemaName, column.getSchemaName()))
+ {
+ // cannot determine unique schema name, return null
+ return null;
+ }
+ schemaName = column.getSchemaName();
+ columnFound = true;
+ }
+ }
+ return schemaName;
+ }
+
+ /**
+ * Returns the table name prefixed with the schema name if it exists
+ * from the function argument(s).
+ * I.e. if a schema name exists, the result will be schemaName.tableName,
+ * and otherwise it will just be tableName.
+ * In case that no unique full table can be determined, null is returned.
+ *
+ * @return the fully qualified table name may be null but not blank.
+ */
+ public String getFullTableName()
+ {
+ String fullTableName = null;
+ boolean columnFound = false;
+ for (Object argument : argumentList)
+ {
+ if (argument instanceof Column)
+ {
+ Column column = (Column) argument;
+ if (columnFound
+ && !ObjectUtils.equals(
+ fullTableName,
+ column.getFullTableName()))
+ {
+ // cannot determine unique full table name, return null
+ return null;
+ }
+ fullTableName = column.getFullTableName();
+ columnFound = true;
+ }
+ }
+ return fullTableName;
}
}
Copied: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AggregateFunction.java (from r1335015, db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Aggregate.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AggregateFunction.java?p2=db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AggregateFunction.java&p1=db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Aggregate.java&r1=1335015&r2=1336994&rev=1336994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Aggregate.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/AggregateFunction.java Fri May 11 01:09:05 2012
@@ -19,237 +19,222 @@ package org.apache.torque.util.functions
* under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.apache.torque.Column;
/**
* <p>A container for classes that will generate SQL for the SQL99 Standard
- * Aggregate functions. These can be used via the Criteria.addAsColumn
+ * Aggregate functions. These can be used via the Criteria.addSelectColumn
* method to produce SQL statements that can be called via the
* BasePeer.doSelect methods.</p>
* <p>
* Note database servers that use non-standard function names
- * can be supported by using the setFunction(String) method.</p>
+ * can be supported by setting the function name in the constructor accordingly.
+ * </p>
* <p>
* E.g., older MySQL servers use LEAST instead of MIN. This can be
- * supported by creating a Aggregate.Min instance and then calling
- * the setFunction("LEAST") method.</p>
+ * supported by supplying "LEAST" as function name.</p>
*
- * @see org.apache.torque.util.SummaryHelper
* @author <a href="mailto:greg.monroe@dukece.com">Greg Monroe</a>
- * @version $Id
+ * @version $Id$
*/
-public class Aggregate
+public class AggregateFunction implements SQLFunction
{
+ /** Should the column have DISTINCT added before it */
+ private boolean distinct;
- /**
- * The base class for all the standard aggregate function classes.
- */
- public abstract class AgregateFunction
- extends AbstractFunction
- implements SQLFunction
- {
- /** Should the column have DISTINCT added before it */
- private boolean distinct;
- /** The function to use */
- private String function;
- /** Flag to determine if arguments have been set */
- private boolean argumentsSet = false;
-
- /**
- * Base constructor for aggregate functions which must be created
- * via the FunctionFactory / DB classes.<p>
- *
- * @see FunctionFactory
- * @see org.apache.torque.adapter.DB
- */
- protected AgregateFunction()
- {
- super();
- }
-
- /**
- * Assumes that there are one or two arguments being specified. The
- * first being a column identifier. (TODO: handle expressions)
- * and the second being an optional boolean indicating if DISTINCT
- * needs to be added.
- *
- * @param args The column to apply the function to.
- * @throws IllegalArgumentException If at least one argument has not
- * been supplied or the second argument
- * object is not Boolean.
- */
- public void setArguments(Object[] args)
- {
+ /** The function to use */
+ private String function;
- if (args.length < 1)
- {
- throw new IllegalArgumentException(
- "There must be at least one argument object specified!");
- }
- if (args.length < 2)
- {
- this.distinct = false;
- }
- else
- {
- if (!(args[1] instanceof Boolean))
- {
- throw new IllegalArgumentException(
- "Second argument object is not type Boolean!");
- }
- this.distinct = ((Boolean) args[1]).booleanValue();
- }
- if (!(args[0] instanceof Column))
- {
- throw new IllegalArgumentException(
- "First argument object is not type Column!");
- }
- addArgument(args[0]);
- this.argumentsSet = true;
- }
-
- /**
- * Should the column have DISTINCT added in front of it?
- *
- * @return True if DISTINCT is needed.
- */
- public boolean isDistinct()
- {
- return this.distinct;
- }
+ /** The column to apply the function to, not null. */
+ private Column column;
- /**
- * Get the function name to use, e.g. AVG, MIN, LEAST.
- *
- * @return The function.
- */
- protected String getFunction()
+ /**
+ * Constructor for aggregate functions.
+ *
+ * @param function the function name, not null or blank.
+ * @param column the column to apply the function to, not null.
+ * @param distinct whether to apply DISTINCT to the column.
+ */
+ protected AggregateFunction(
+ String function,
+ Column column,
+ boolean distinct)
+ {
+ if (StringUtils.isBlank(function))
{
- return this.function;
+ throw new IllegalArgumentException(
+ "function must not be null or blank");
}
+ this.function = function;
+ setColumn(column);
+ this.distinct = distinct;
+ }
- /**
- * Set the function to use.
- *
- * @param value The function to use.
- */
- public void setFunction(String value)
- {
- this.function = value;
- }
+ /**
+ * Returns the column the function is applied to.
+ *
+ * @return the column, not null.
+ */
+ public Column getColumn()
+ {
+ return column;
+ }
- /**
- * Generate the SQL for this function.
- *
- * @throws IllegalStateException if the arguments are not set
- */
- public String toSQL()
+ /**
+ * Sets the column the function is applied to.
+ *
+ * @param column the column, not null.
+ */
+ public void setColumn(Column column)
+ {
+ if (column == null)
{
- if (!argumentsSet)
- {
- throw new IllegalStateException (
- "Function arguments have not been set!");
- }
- StringBuffer sb = new StringBuffer();
- sb.append(getFunction()).append("(");
- if (isDistinct())
- {
- sb.append("DISTINCT ");
- }
- sb.append(((Column) getArgument(0)).getSqlExpression())
- .append(")");
- return sb.toString();
+ throw new IllegalArgumentException(
+ "column must not be null");
}
+ this.column = column;
+ }
+ /**
+ * Should the column have DISTINCT added in front of it?
+ *
+ * @return True if DISTINCT is needed.
+ */
+ public boolean isDistinct()
+ {
+ return this.distinct;
}
/**
- * SQL99 Standard Average a column function.
+ * Get the function name to use, e.g. AVG, MIN, LEAST.
+ *
+ * @return The function name.
*/
- public class Avg extends Aggregate.AgregateFunction
+ protected String getFunction()
{
- /**
- * Construct an AVG function class.
- *
- * @see Aggregate.AgregateFunction
- * @see FunctionFactory
- */
- protected Avg()
- {
- super();
- setFunction("AVG");
- }
+ return this.function;
}
/**
- * SQL99 Standard Count records function.
+ * Set the function name to use, e.g. AVG, MIN, LEAST.
+ *
+ * @param function The function name to use, not null or blank.
+ *
+ * @throws UnsupportedOperationException if a subclass does not support
+ * changing the function name; never thrown by this implementation.
*/
- public class Count extends Aggregate.AgregateFunction
+ public void setFunction(String function)
{
- /**
- * Construct a COUNT function class.
- *
- * @see Aggregate.AgregateFunction
- * @see FunctionFactory
- */
- protected Count()
+ if (StringUtils.isBlank(function))
{
- super();
- setFunction("COUNT");
+ throw new IllegalArgumentException(
+ "function must not be null or blank");
}
+ this.function = function;
}
/**
- * SQL99 Standard Minimum value of column function.
+ * Generate the SQL for this function.
+ *
+ * @throws IllegalStateException if the arguments are not set
*/
- public class Min extends Aggregate.AgregateFunction
+ public String getSqlExpression()
{
- /**
- * Construct a MIN function class.
- *
- * @see Aggregate.AgregateFunction
- * @see FunctionFactory
- */
- protected Min()
+ StringBuilder sb = new StringBuilder();
+ sb.append(getFunction()).append("(");
+ if (isDistinct())
{
- super();
- setFunction("MIN");
+ sb.append("DISTINCT ");
}
+ sb.append(column.getSqlExpression())
+ .append(")");
+ return sb.toString();
}
- /**
- * SQL99 Standard maximum value of column function.
- */
- public class Max extends Aggregate.AgregateFunction
+ public Object getArgument(int i)
{
- /**
- * Construct a MAX function class.
- *
- * @see FunctionFactory
- * @see Aggregate.AgregateFunction
- */
- protected Max()
+ switch (i)
{
- super();
- setFunction("MAX");
+ case 0:
+ return column;
+ case 1:
+ return distinct;
+ default:
+ return null;
}
}
+
+ public Object[] getArguments()
+ {
+ return new Object[] {column, distinct};
+ }
+
/**
- * SQL99 Standard sum column values function.
+ * Assumes that there are one or two arguments being specified. The
+ * first being a column identifier,
+ * and the second being an optional boolean indicating if DISTINCT
+ * needs to be added.
+ *
+ * @param args The column to apply the function to.
+ * @throws IllegalArgumentException If at least one argument has not
+ * been supplied or the second argument
+ * object is not Boolean.
*/
- public class Sum extends Aggregate.AgregateFunction
+ public void setArguments(Object[] args)
+ {
+
+ if (args.length < 1)
+ {
+ throw new IllegalArgumentException(
+ "There must be at least one argument object specified!");
+ }
+ if (args.length < 2)
+ {
+ this.distinct = false;
+ }
+ else
+ {
+ if (!(args[1] instanceof Boolean))
+ {
+ throw new IllegalArgumentException(
+ "Second argument object is not type Boolean!");
+ }
+ this.distinct = ((Boolean) args[1]).booleanValue();
+ }
+ if (!(args[0] instanceof Column))
+ {
+ throw new IllegalArgumentException(
+ "First argument object is not type Column!");
+ }
+ this.column = (Column) args[0];
+ }
+
+ /**
+ * Returns the column name.
+ * This implementation always return null because we do not reference
+ * a real column.
+ *
+ * @return the column name, always null.
+ */
+ public String getColumnName()
+ {
+ return null;
+ }
+
+ public String getTableName()
{
- /**
- * Construct a SUM function class.
- *
- * @see FunctionFactory
- * @see Aggregate.AgregateFunction
- */
- protected Sum()
- {
- super();
- setFunction("SUM");
- }
+ return column.getTableName();
+ }
+
+ public String getSchemaName()
+ {
+ return column.getSchemaName();
+ }
+
+ public String getFullTableName()
+ {
+ return column.getFullTableName();
}
}
Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Avg.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Avg.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Avg.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Avg.java Fri May 11 01:09:05 2012
@@ -0,0 +1,78 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.Column;
+import org.apache.torque.ColumnImpl;
+
+/**
+ * SQL99 Standard Average function.
+ *
+ * @version $Id$
+ */
+public class Avg extends AggregateFunction
+{
+ /**
+ * Construct an AVG function class with the column to average over.
+ *
+ * @param column the Column to average over.
+ */
+ public Avg(Column column)
+ {
+ super("AVG", column, false);
+ }
+
+ /**
+ * Construct an AVG function class with an SQL expression to average over.
+ *
+ * @param column the SQL expression to average over.
+ */
+ public Avg(String sqlExpression)
+ {
+ super("AVG", new ColumnImpl(sqlExpression), false);
+ }
+
+ /**
+ * Construct an AVG function class with the column to average over
+ * and possibly a distinct modifier.
+ *
+ * @param column the Column to average over.
+ * @param distinct whether to average only over distinct values.
+ */
+ public Avg(Column column, boolean distinct)
+ {
+ super("AVG", column, distinct);
+ }
+
+ /**
+ * This method cannot be called, an UnsupportedOperationException
+ * will always be thrown.
+ *
+ * @param function disregarded.
+ *
+ * @throws UnsupportedOperationException always.
+ */
+ @Override
+ public void setFunction(String function)
+ {
+ throw new UnsupportedOperationException(
+ "The function name may not be changed.");
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Avg.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Count.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Count.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Count.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Count.java Fri May 11 01:09:05 2012
@@ -0,0 +1,78 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.Column;
+import org.apache.torque.ColumnImpl;
+
+/**
+ * SQL99 Standard count function.
+ *
+ * @version $Id$
+ */
+public class Count extends AggregateFunction
+{
+ /**
+ * Construct an COUNT function class with the column to count.
+ *
+ * @param column the Column to count.
+ */
+ public Count(Column column)
+ {
+ super("COUNT", column, false);
+ }
+
+ /**
+ * Construct an COUNT function class with an SQL expression to count.
+ *
+ * @param column the SQL expression to count.
+ */
+ public Count(String sqlExpression)
+ {
+ super("COUNT", new ColumnImpl(sqlExpression), false);
+ }
+
+ /**
+ * Construct an COUNT function class with the column to count
+ * and possibly a distinct modifier.
+ *
+ * @param column the Column to count.
+ * @param distinct whether to count only over distinct values.
+ */
+ public Count(Column column, boolean distinct)
+ {
+ super("COUNT", column, distinct);
+ }
+
+ /**
+ * This method cannot be called, an UnsupportedOperationException
+ * will always be thrown.
+ *
+ * @param function disregarded.
+ *
+ * @throws UnsupportedOperationException always.
+ */
+ @Override
+ public void setFunction(String function)
+ {
+ throw new UnsupportedOperationException(
+ "The function name may not be changed.");
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Count.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Max.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Max.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Max.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Max.java Fri May 11 01:09:05 2012
@@ -0,0 +1,81 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.Column;
+import org.apache.torque.ColumnImpl;
+
+/**
+ * SQL99 Standard max function.
+ *
+ * @version $Id$
+ */
+public class Max extends AggregateFunction
+{
+ /**
+ * Construct an MAX function class with the column to calculate the maximum
+ * from.
+ *
+ * @param column the Column to calculate the maximum from.
+ */
+ public Max(Column column)
+ {
+ super("MAX", column, false);
+ }
+
+ /**
+ * Construct an MAX function class with an SQL expression to calculate
+ * the maximum from.
+ *
+ * @param column the SQL expression to calculate the maximum from.
+ */
+ public Max(String sqlExpression)
+ {
+ super("MAX", new ColumnImpl(sqlExpression), false);
+ }
+
+ /**
+ * Construct an MAX function class with the column to calculate
+ * the maximum from and possibly a distinct modifier.
+ *
+ * @param column the Column to calculate the maximum from.
+ * @param distinct whether to calculate the maximum from only
+ * distinct values.
+ */
+ public Max(Column column, boolean distinct)
+ {
+ super("MAX", column, distinct);
+ }
+
+ /**
+ * This method cannot be called, an UnsupportedOperationException
+ * will always be thrown.
+ *
+ * @param function disregarded.
+ *
+ * @throws UnsupportedOperationException always.
+ */
+ @Override
+ public void setFunction(String function)
+ {
+ throw new UnsupportedOperationException(
+ "The function name may not be changed.");
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Max.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Min.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Min.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Min.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Min.java Fri May 11 01:09:05 2012
@@ -0,0 +1,81 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.Column;
+import org.apache.torque.ColumnImpl;
+
+/**
+ * SQL99 Standard min function.
+ *
+ * @version $Id$
+ */
+public class Min extends AggregateFunction
+{
+ /**
+ * Construct an MIN function class with the column to calculate the minimum
+ * from.
+ *
+ * @param column the Column to calculate the minimum from.
+ */
+ public Min(Column column)
+ {
+ super("MIN", column, false);
+ }
+
+ /**
+ * Construct an MIN function class with an SQL expression to calculate
+ * the minimum from.
+ *
+ * @param column the SQL expression to calculate the minimum from.
+ */
+ public Min(String sqlExpression)
+ {
+ super("MIN", new ColumnImpl(sqlExpression), false);
+ }
+
+ /**
+ * Construct an MIN function class with the column to calculate
+ * the minimum from and possibly a distinct modifier.
+ *
+ * @param column the Column to calculate the minimum from.
+ * @param distinct whether to calculate the minimum from only
+ * distinct values.
+ */
+ public Min(Column column, boolean distinct)
+ {
+ super("MIN", column, distinct);
+ }
+
+ /**
+ * This method cannot be called, an UnsupportedOperationException
+ * will always be thrown.
+ *
+ * @param function disregarded.
+ *
+ * @throws UnsupportedOperationException always.
+ */
+ @Override
+ public void setFunction(String function)
+ {
+ throw new UnsupportedOperationException(
+ "The function name may not be changed.");
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Min.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/SQLFunction.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/SQLFunction.java?rev=1336994&r1=1336993&r2=1336994&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/SQLFunction.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/SQLFunction.java Fri May 11 01:09:05 2012
@@ -33,18 +33,9 @@ import org.apache.torque.Column;
* @author <a href="mailto:greg.monroe@dukece.com">Greg Monroe</a>
* @version $Id
*/
-public interface SQLFunction
+public interface SQLFunction extends Column
{
/**
- * This should return the SQL string that can be used
- * when constructing the query. E.g. "AVG( table.column )" or
- * CONCAT(table.column, " foobar");
- *
- * @return The SQL String.
- */
- String toSQL();
-
- /**
* Returns the function parameters at index i.
* Should be null if parameter does not exist.
*
@@ -80,23 +71,4 @@ public interface SQLFunction
* @param args The function specific arguments.
*/
void setArguments(Object[] args);
-
- /**
- * Get the name of the Torque Database associated with this function.
- *
- * @return The DB name. Should not be null (use default DB in this case).
- *
- * @exception IllegalStateException If Torque has not been initialized and
- * the default DB name can not be determined.
- */
- String getDBName();
-
- /**
- * Sets the Torque DB name this function is being used with.
- *
- * @param dbName The DB name, if null, the getDBName will return default DB
- * name (if it can be determined).
- */
- void setDBName(String dbName);
-
}
Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Sum.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Sum.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Sum.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Sum.java Fri May 11 01:09:05 2012
@@ -0,0 +1,78 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.Column;
+import org.apache.torque.ColumnImpl;
+
+/**
+ * SQL99 Standard sum function.
+ *
+ * @version $Id$
+ */
+public class Sum extends AggregateFunction
+{
+ /**
+ * Construct an SUM function class with the column to sum over.
+ *
+ * @param column the Column to sum over.
+ */
+ public Sum(Column column)
+ {
+ super("SUM", column, false);
+ }
+
+ /**
+ * Construct an SUM function class with an SQL expression to sum over.
+ *
+ * @param column the SQL expression to sum over.
+ */
+ public Sum(String sqlExpression)
+ {
+ super("SUM", new ColumnImpl(sqlExpression), false);
+ }
+
+ /**
+ * Construct an SUM function class with the column to sum over
+ * and possibly a distinct modifier.
+ *
+ * @param column the Column to sum over.
+ * @param distinct whether to count only over distinct values.
+ */
+ public Sum(Column column, boolean distinct)
+ {
+ super("SUM", column, distinct);
+ }
+
+ /**
+ * This method cannot be called, an UnsupportedOperationException
+ * will always be thrown.
+ *
+ * @param function disregarded.
+ *
+ * @throws UnsupportedOperationException always.
+ */
+ @Override
+ public void setFunction(String function)
+ {
+ throw new UnsupportedOperationException(
+ "The function name may not be changed.");
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/functions/Sum.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AbstractFunctionTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AbstractFunctionTest.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AbstractFunctionTest.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AbstractFunctionTest.java Fri May 11 01:09:05 2012
@@ -0,0 +1,204 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.apache.torque.ColumnImpl;
+
+/**
+ * Tests the AggregateFunction class.
+ *
+ * @version $Id$
+ */
+public class AbstractFunctionTest extends TestCase
+{
+ private AbstractFunction abstractFunction;
+
+ @Override
+ public void setUp()
+ {
+ abstractFunction = new MyFunction();
+ }
+
+
+ /**
+ * Tests that getArguments and SetArguments work
+ */
+ public void testGetSetArguments()
+ {
+ assertTrue(Arrays.equals(
+ new Object[] {},
+ abstractFunction.getArguments()));
+
+ abstractFunction.setArguments(
+ new Object[] {new ColumnImpl("fooColumn"), true});
+ assertTrue(Arrays.equals(
+ new Object[] {new ColumnImpl("fooColumn"), true},
+ abstractFunction.getArguments()));
+ }
+
+ /**
+ * Tests that getArgumentList and SetArgumentList work
+ */
+ public void testGetSetArgumentList()
+ {
+ ArrayList<Object> arguments = new ArrayList<Object>();
+ arguments.add(false);
+ arguments.add(new ColumnImpl("fooColumn"));
+ abstractFunction.setArgumentList(arguments);
+ assertEquals(arguments, abstractFunction.getArgumentList());
+ }
+
+ /**
+ * Tests that addArgument works
+ */
+ public void testAdArgument()
+ {
+ abstractFunction.addArgument(false);
+ assertTrue(Arrays.equals(
+ new Object[] {false},
+ abstractFunction.getArguments()));
+ }
+
+ /**
+ * Tests that getArgument(0) returns the column.
+ */
+ public void testGetArgument()
+ {
+ abstractFunction.setArguments(
+ new Object[] {
+ new ColumnImpl("fooColumn"),
+ new ColumnImpl("barColumn"),
+ true});
+ assertEquals(
+ new ColumnImpl("barColumn"),
+ abstractFunction.getArgument(01));
+ }
+
+ /**
+ * Tests the getColumnName method always returns null.
+ * This is because the function has no real column name.
+ */
+ public void testGetColumnName()
+ {
+ abstractFunction.setArguments(
+ new Object[] {
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ true});
+ assertNull(abstractFunction.getColumnName());
+ }
+
+ /**
+ * Tests the getTableName method returns the table of the column argument.
+ */
+ public void testGetTableName()
+ {
+ abstractFunction.setArguments(
+ new Object[] {
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ true});
+ assertEquals("table", abstractFunction.getTableName());
+ }
+
+ /**
+ * Tests the getTableName method returns null if different tables
+ * are encountered.
+ */
+ public void testGetTableNameDifferentTables()
+ {
+ abstractFunction.setArguments(
+ new Object[] {
+ new ColumnImpl(null, null, null, "sqlExpression"),
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ true});
+ assertNull(abstractFunction.getTableName());
+ }
+
+ /**
+ * Tests the getFullTableName method returns the fullTableName of the
+ * column argument.
+ */
+ public void testGetFullTableName()
+ {
+ abstractFunction.setArguments(
+ new Object[] {
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ true});
+ assertEquals("schema.table", abstractFunction.getFullTableName());
+ }
+
+ /**
+ * Tests the getFullTableName method returns null if different tables
+ * are encountered.
+ */
+ public void testGetFullTableNameDifferentTables()
+ {
+ abstractFunction.setArguments(
+ new Object[] {
+ new ColumnImpl(null, null, null, "sqlExpression"),
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ true});
+ assertNull(abstractFunction.getFullTableName());
+ }
+
+ /**
+ * Tests the getSchemaName method returns the schema of the column
+ * argument.
+ */
+ public void testGetSchemaName()
+ {
+ abstractFunction.setArguments(
+ new Object[] {
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ true});
+ assertEquals("schema", abstractFunction.getSchemaName());
+ }
+
+ /**
+ * Tests the getSchemaName method returns null if different schemas
+ * are encountered.
+ */
+ public void testGetSchemaNameDifferentTables()
+ {
+ abstractFunction.setArguments(
+ new Object[] {
+ new ColumnImpl(null, null, null, "sqlExpression"),
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ true});
+ assertNull(abstractFunction.getSchemaName());
+ }
+
+ private static class MyFunction extends AbstractFunction
+ {
+ @Override
+ public String getSqlExpression()
+ {
+ return "MYFUNCTION(" + getArgumentList().toString() + ")";
+ }
+
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AbstractFunctionTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AggregateFunctionTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AggregateFunctionTest.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AggregateFunctionTest.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AggregateFunctionTest.java Fri May 11 01:09:05 2012
@@ -0,0 +1,218 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.apache.torque.ColumnImpl;
+
+/**
+ * Tests the AggregateFunction class.
+ *
+ * @version $Id$
+ */
+public class AggregateFunctionTest extends TestCase
+{
+ /**
+ * Tests the aggregateFunction constructor without distinct
+ * returns the correct SQL.
+ */
+ public void testAggregateFunction()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("myColumn"),
+ false);
+ assertEquals(
+ "FUNCTION(myColumn)",
+ aggregateFunction.getSqlExpression());
+ }
+
+ /**
+ * Tests the aggregateFunction constructor with distinct
+ * returns the correct SQL.
+ */
+ public void testAggregateFunctionWithDistinct()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("myColumn"),
+ true);
+ assertEquals(
+ "FUNCTION(DISTINCT myColumn)",
+ aggregateFunction.getSqlExpression());
+ }
+
+ /**
+ * Tests that setFunction works
+ */
+ public void testSetFunction()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("myColumn"),
+ false);
+ assertEquals("FUNCTION", aggregateFunction.getFunction());
+ aggregateFunction.setFunction("OTHERFUNCTION");
+ assertEquals("OTHERFUNCTION", aggregateFunction.getFunction());
+ assertEquals(
+ "OTHERFUNCTION(myColumn)",
+ aggregateFunction.getSqlExpression());
+ }
+
+ /**
+ * Tests that getArguments and SetArguments work
+ */
+ public void testGetSetArguments()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("myColumn"),
+ false);
+ assertTrue(Arrays.equals(
+ new Object[] {new ColumnImpl("myColumn"), false},
+ aggregateFunction.getArguments()));
+
+ aggregateFunction.setArguments(
+ new Object[] {new ColumnImpl("otherColumn")});
+ assertTrue(Arrays.equals(
+ new Object[] {new ColumnImpl("otherColumn"), false},
+ aggregateFunction.getArguments()));
+
+ aggregateFunction.setArguments(
+ new Object[] {new ColumnImpl("fooColumn"), true});
+ assertTrue(Arrays.equals(
+ new Object[] {new ColumnImpl("fooColumn"), true},
+ aggregateFunction.getArguments()));
+ }
+
+ /**
+ * Tests that getArgument(0) returns the column.
+ */
+ public void testGetFirstArgument()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("myColumn"),
+ false);
+ assertEquals(
+ new ColumnImpl("myColumn"),
+ aggregateFunction.getArgument(0));
+ }
+
+ /**
+ * Tests that getArgument(1) returns the distinct value.
+ */
+ public void testGetSecondArgument()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("myColumn"),
+ false);
+ assertEquals(
+ false,
+ aggregateFunction.getArgument(1));
+ }
+
+ /**
+ * Tests that getArgument(2) returns null.
+ */
+ public void testGetThirdArgument()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("myColumn"),
+ false);
+ assertNull(aggregateFunction.getArgument(2));
+ }
+
+ /**
+ * Tests that setColumn cannot be called with a null value.
+ */
+ public void testSetColumnNull()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("myColumn"),
+ false);
+ try
+ {
+ aggregateFunction.setColumn(null);
+ fail("Exception expected");
+ }
+ catch (IllegalArgumentException e)
+ {
+ assertEquals("column must not be null", e.getMessage());
+ }
+ }
+
+ /**
+ * Tests the getColumnName method always returns null.
+ * This is because the function has no real column name.
+ */
+ public void testGetColumnName()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ false);
+ assertNull(aggregateFunction.getColumnName());
+ }
+
+ /**
+ * Tests the getTableName method returns the table of the column argument.
+ */
+ public void testGetTableName()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ false);
+ assertEquals("table", aggregateFunction.getTableName());
+ }
+
+ /**
+ * Tests the getFullTableName method returns the fullTableName of the
+ * column argument.
+ */
+ public void testGetFullTableName()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ false);
+ assertEquals("schema.table", aggregateFunction.getFullTableName());
+ }
+
+ /**
+ * Tests the getSchemaName method returns the schema of the column
+ * argument.
+ */
+ public void testGetSchemaName()
+ {
+ AggregateFunction aggregateFunction = new AggregateFunction(
+ "FUNCTION",
+ new ColumnImpl("schema", "table", "column", "sqlExpression"),
+ false);
+ assertEquals("schema", aggregateFunction.getSchemaName());
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AggregateFunctionTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AvgTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AvgTest.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AvgTest.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AvgTest.java Fri May 11 01:09:05 2012
@@ -0,0 +1,78 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.torque.ColumnImpl;
+
+/**
+ * Tests the Avg class.
+ *
+ * @version $Id$
+ */
+public class AvgTest extends TestCase
+{
+ /**
+ * Tests the avg constructor with a column returns the correct SQL.
+ */
+ public void testAvg()
+ {
+ Avg avg = new Avg(new ColumnImpl("myColumn"));
+ assertEquals("AVG(myColumn)", avg.getSqlExpression());
+ }
+
+ /**
+ * Tests the avg constructor with a column returns the correct SQL.
+ */
+ public void testAvgFromString()
+ {
+ Avg avg = new Avg("myColumn");
+ assertEquals("AVG(myColumn)", avg.getSqlExpression());
+ }
+
+ /**
+ * Tests the avg constructor with distinct returns the correct SQL.
+ */
+ public void testAvgWithDistinct()
+ {
+ Avg avg = new Avg(new ColumnImpl("myColumn"), true);
+ assertEquals("AVG(DISTINCT myColumn)", avg.getSqlExpression());
+ }
+
+ /**
+ * tests that setFunction throws a
+ */
+ public void testSetFunction()
+ {
+ Avg avg = new Avg(new ColumnImpl("myColumn"));
+ try
+ {
+ avg.setFunction("other");
+ fail("Exception expected");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ assertEquals(
+ "The function name may not be changed.",
+ e.getMessage());
+ }
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/AvgTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/CountTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/CountTest.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/CountTest.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/CountTest.java Fri May 11 01:09:05 2012
@@ -0,0 +1,78 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.torque.ColumnImpl;
+
+/**
+ * Tests the Count class.
+ *
+ * @version $Id$
+ */
+public class CountTest extends TestCase
+{
+ /**
+ * Tests the Count constructor with a column returns the correct SQL.
+ */
+ public void testCount()
+ {
+ Count count = new Count(new ColumnImpl("myColumn"));
+ assertEquals("COUNT(myColumn)", count.getSqlExpression());
+ }
+
+ /**
+ * Tests the Count constructor with a column returns the correct SQL.
+ */
+ public void testCountFromString()
+ {
+ Count count = new Count("myColumn");
+ assertEquals("COUNT(myColumn)", count.getSqlExpression());
+ }
+
+ /**
+ * Tests the Count constructor with distinct returns the correct SQL.
+ */
+ public void testCountWithDistinct()
+ {
+ Count count = new Count(new ColumnImpl("myColumn"), true);
+ assertEquals("COUNT(DISTINCT myColumn)", count.getSqlExpression());
+ }
+
+ /**
+ * tests that setFunction throws a
+ */
+ public void testSetFunction()
+ {
+ Count count = new Count(new ColumnImpl("myColumn"));
+ try
+ {
+ count.setFunction("other");
+ fail("Exception expected");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ assertEquals(
+ "The function name may not be changed.",
+ e.getMessage());
+ }
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/CountTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MaxTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MaxTest.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MaxTest.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MaxTest.java Fri May 11 01:09:05 2012
@@ -0,0 +1,78 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.torque.ColumnImpl;
+
+/**
+ * Tests the Max class
+ *
+ * @version $Id$
+ */
+public class MaxTest extends TestCase
+{
+ /**
+ * Tests the max constructor with a column returns the correct SQL.
+ */
+ public void testMax()
+ {
+ Max max = new Max(new ColumnImpl("myColumn"));
+ assertEquals("MAX(myColumn)", max.getSqlExpression());
+ }
+
+ /**
+ * Tests the max constructor with a column returns the correct SQL.
+ */
+ public void testMaxFromString()
+ {
+ Max max = new Max("myColumn");
+ assertEquals("MAX(myColumn)", max.getSqlExpression());
+ }
+
+ /**
+ * Tests the max constructor with distinct returns the correct SQL.
+ */
+ public void testMaxWithDistinct()
+ {
+ Max max = new Max(new ColumnImpl("myColumn"), true);
+ assertEquals("MAX(DISTINCT myColumn)", max.getSqlExpression());
+ }
+
+ /**
+ * tests that setFunction throws a
+ */
+ public void testSetFunction()
+ {
+ Max max = new Max(new ColumnImpl("myColumn"));
+ try
+ {
+ max.setFunction("other");
+ fail("Exception expected");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ assertEquals(
+ "The function name may not be changed.",
+ e.getMessage());
+ }
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MaxTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MinTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MinTest.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MinTest.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MinTest.java Fri May 11 01:09:05 2012
@@ -0,0 +1,78 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.torque.ColumnImpl;
+
+/**
+ * Tests the Min class
+ *
+ * @version $Id$
+ */
+public class MinTest extends TestCase
+{
+ /**
+ * Tests the min constructor with a column returns the correct SQL.
+ */
+ public void testMin()
+ {
+ Min min = new Min(new ColumnImpl("myColumn"));
+ assertEquals("MIN(myColumn)", min.getSqlExpression());
+ }
+
+ /**
+ * Tests the min constructor with a column returns the correct SQL.
+ */
+ public void testSumFromString()
+ {
+ Min min = new Min("myColumn");
+ assertEquals("MIN(myColumn)", min.getSqlExpression());
+ }
+
+ /**
+ * Tests the min constructor with distinct returns the correct SQL.
+ */
+ public void testSumWithDistinct()
+ {
+ Min min = new Min(new ColumnImpl("myColumn"), true);
+ assertEquals("MIN(DISTINCT myColumn)", min.getSqlExpression());
+ }
+
+ /**
+ * tests that setFunction throws a
+ */
+ public void testSetFunction()
+ {
+ Min min = new Min(new ColumnImpl("myColumn"));
+ try
+ {
+ min.setFunction("other");
+ fail("Exception expected");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ assertEquals(
+ "The function name may not be changed.",
+ e.getMessage());
+ }
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/MinTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/SumTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/SumTest.java?rev=1336994&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/SumTest.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/SumTest.java Fri May 11 01:09:05 2012
@@ -0,0 +1,78 @@
+package org.apache.torque.util.functions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.torque.ColumnImpl;
+
+/**
+ * Tests the Sum class
+ *
+ * @version $Id$
+ */
+public class SumTest extends TestCase
+{
+ /**
+ * Tests the sum constructor with a column returns the correct SQL.
+ */
+ public void testSum()
+ {
+ Sum sum = new Sum(new ColumnImpl("myColumn"));
+ assertEquals("SUM(myColumn)", sum.getSqlExpression());
+ }
+
+ /**
+ * Tests the sum constructor with a column returns the correct SQL.
+ */
+ public void testSumFromString()
+ {
+ Sum sum = new Sum("myColumn");
+ assertEquals("SUM(myColumn)", sum.getSqlExpression());
+ }
+
+ /**
+ * Tests the sum constructor with distinct returns the correct SQL.
+ */
+ public void testSumWithDistinct()
+ {
+ Sum sum = new Sum(new ColumnImpl("myColumn"), true);
+ assertEquals("SUM(DISTINCT myColumn)", sum.getSqlExpression());
+ }
+
+ /**
+ * tests that setFunction throws a
+ */
+ public void testSetFunction()
+ {
+ Sum sum = new Sum(new ColumnImpl("myColumn"));
+ try
+ {
+ sum.setFunction("other");
+ fail("Exception expected");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ assertEquals(
+ "The function name may not be changed.",
+ e.getMessage());
+ }
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/functions/SumTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org
|