diff --git a/jOOQ/src/main/java/org/jooq/AggregateFunction.java b/jOOQ/src/main/java/org/jooq/AggregateFunction.java new file mode 100644 index 0000000000..ddc9a90565 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/AggregateFunction.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2009-2011, Lukas Eder, lukas.eder@gmail.com + * All rights reserved. + * + * This software is licensed to you under the Apache License, Version 2.0 + * (the "License"); You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * . Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * . 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. + * + * . Neither the name "jOOQ" nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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. + */ +package org.jooq; + +/** + * An aggregate function is a special field that is usually used in a + * GROUP BY context. It is also the base for window function + * construction. + * + * @author Lukas Eder + */ +public interface AggregateFunction extends Field { + +} diff --git a/jOOQ/src/main/java/org/jooq/impl/AggregateFunctionImpl.java b/jOOQ/src/main/java/org/jooq/impl/AggregateFunctionImpl.java new file mode 100644 index 0000000000..ffa313e1d4 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/AggregateFunctionImpl.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2009-2011, Lukas Eder, lukas.eder@gmail.com + * All rights reserved. + * + * This software is licensed to you under the Apache License, Version 2.0 + * (the "License"); You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * . Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * . 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. + * + * . Neither the name "jOOQ" nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS 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 COPYRIGHT OWNER OR 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. + */ +package org.jooq.impl; + +import org.jooq.AggregateFunction; +import org.jooq.DataType; +import org.jooq.QueryPart; + +class AggregateFunctionImpl extends Function implements AggregateFunction { + + /** + * Generated UID + */ + private static final long serialVersionUID = 1952351506930280715L; + + AggregateFunctionImpl(String name, DataType type, QueryPart... arguments) { + super(name, type, arguments); + } + + AggregateFunctionImpl(Term term, DataType type, QueryPart... arguments) { + super(term, type, arguments); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/Count.java b/jOOQ/src/main/java/org/jooq/impl/Count.java index 402949df66..dad022db4c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Count.java +++ b/jOOQ/src/main/java/org/jooq/impl/Count.java @@ -43,7 +43,7 @@ import org.jooq.RenderContext; /** * @author Lukas Eder */ -class Count extends Function { +class Count extends AggregateFunctionImpl { private static final long serialVersionUID = 4685583105296376461L; diff --git a/jOOQ/src/main/java/org/jooq/impl/Factory.java b/jOOQ/src/main/java/org/jooq/impl/Factory.java index 2a94f31f74..4eef4a77ff 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Factory.java +++ b/jOOQ/src/main/java/org/jooq/impl/Factory.java @@ -54,6 +54,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import org.jooq.AggregateFunction; import org.jooq.ArrayRecord; import org.jooq.Attachable; import org.jooq.Batch; @@ -2107,50 +2108,50 @@ public class Factory implements FactoryOperations { /** * Get the count(*) function */ - public static Field count() { + public static AggregateFunction count() { return new Count(field("*", Integer.class), false); } /** * Get the count(field) function */ - public static Field count(Field field) { + public static AggregateFunction count(Field field) { return new Count(field, false); } /** * Get the count(distinct field) function */ - public static Field countDistinct(Field field) { + public static AggregateFunction countDistinct(Field field) { return new Count(field, true); } /** * Get the max value over a field: max(field) */ - public static Field max(Field field) { - return function("max", field.getDataType(), field); + public static AggregateFunction max(Field field) { + return new AggregateFunctionImpl("max", field.getDataType(), field); } /** * Get the min value over a field: min(field) */ - public static Field min(Field field) { - return function("min", field.getDataType(), field); + public static AggregateFunction min(Field field) { + return new AggregateFunctionImpl("min", field.getDataType(), field); } /** * Get the sum over a numeric field: sum(field) */ - public static Field sum(Field field) { - return function("sum", SQLDataType.NUMERIC, field); + public static AggregateFunction sum(Field field) { + return new AggregateFunctionImpl("sum", SQLDataType.NUMERIC, field); } /** * Get the average over a numeric field: avg(field) */ - public static Field avg(Field field) { - return function("avg", SQLDataType.NUMERIC, field); + public static AggregateFunction avg(Field field) { + return new AggregateFunctionImpl("avg", SQLDataType.NUMERIC, field); } /** @@ -2163,8 +2164,8 @@ public class Factory implements FactoryOperations { *
  • Sybase SQL Anywhere
  • * */ - public static Field median(Field field) { - return function("median", SQLDataType.NUMERIC, field); + public static AggregateFunction median(Field field) { + return new AggregateFunctionImpl("median", SQLDataType.NUMERIC, field); } /** @@ -2184,8 +2185,8 @@ public class Factory implements FactoryOperations { *
  • Sybase SQL Anywhere
  • * */ - public static Field stddevPop(Field field) { - return new Function(Term.STDDEV_POP, SQLDataType.NUMERIC, field); + public static AggregateFunction stddevPop(Field field) { + return new AggregateFunctionImpl(Term.STDDEV_POP, SQLDataType.NUMERIC, field); } /** @@ -2205,8 +2206,8 @@ public class Factory implements FactoryOperations { *
  • Sybase SQL Anywhere
  • * */ - public static Field stddevSamp(Field field) { - return new Function(Term.STDDEV_SAMP, SQLDataType.NUMERIC, field); + public static AggregateFunction stddevSamp(Field field) { + return new AggregateFunctionImpl(Term.STDDEV_SAMP, SQLDataType.NUMERIC, field); } /** @@ -2226,8 +2227,8 @@ public class Factory implements FactoryOperations { *
  • Sybase SQL Anywhere
  • * */ - public static Field varPop(Field field) { - return new Function(Term.VAR_POP, SQLDataType.NUMERIC, field); + public static AggregateFunction varPop(Field field) { + return new AggregateFunctionImpl(Term.VAR_POP, SQLDataType.NUMERIC, field); } /** @@ -2245,8 +2246,8 @@ public class Factory implements FactoryOperations { *
  • Sybase SQL Anywhere
  • * */ - public static Field varSamp(Field field) { - return new Function(Term.VAR_SAMP, SQLDataType.NUMERIC, field); + public static AggregateFunction varSamp(Field field) { + return new AggregateFunctionImpl(Term.VAR_SAMP, SQLDataType.NUMERIC, field); } // -------------------------------------------------------------------------