(Term.LIST_AGG, SQLDataType.VARCHAR, nullSafe(field), literal);
}
+ /**
+ * Get the aggregated concatenation for a field.
+ *
+ * This is natively supported by
+ *
+ * - {@link SQLDialect#CUBRID}
+ * - {@link SQLDialect#H2}
+ * - {@link SQLDialect#HSQLDB}
+ * - {@link SQLDialect#MYSQL}
+ *
+ *
+ * It is simulated by the following dialects:
+ *
+ * - {@link SQLDialect#ORACLE}: Using
LISTAGG()
+ * - {@link SQLDialect#SYBASE}: Using
LIST()
+ *
+ *
+ * @see #listAgg(Field)
+ */
+ @Support({ CUBRID, H2, HSQLDB, MYSQL, ORACLE, SYBASE })
+ public static GroupConcatOrderByStep groupConcat(Field> field) {
+ return new GroupConcat(nullSafe(field));
+ }
+
+ /**
+ * Get the aggregated concatenation for a field.
+ *
+ * This is natively supported by
+ *
+ * - {@link SQLDialect#CUBRID}
+ * - {@link SQLDialect#H2}
+ * - {@link SQLDialect#HSQLDB}
+ * - {@link SQLDialect#MYSQL}
+ *
+ *
+ * It is simulated by the following dialects:
+ *
+ * - {@link SQLDialect#SYBASE}: Using
LIST()
+ *
+ *
+ * @see #listAgg(Field)
+ */
+ @Support({ CUBRID, H2, HSQLDB, MYSQL, SYBASE })
+ public static GroupConcatOrderByStep groupConcatDistinct(Field> field) {
+ return new GroupConcat(nullSafe(field), true);
+ }
+
// -------------------------------------------------------------------------
// XXX Window functions
// -------------------------------------------------------------------------
diff --git a/jOOQ/src/main/java/org/jooq/impl/Function.java b/jOOQ/src/main/java/org/jooq/impl/Function.java
index 6a5e8cf1c3..3929ce49e6 100644
--- a/jOOQ/src/main/java/org/jooq/impl/Function.java
+++ b/jOOQ/src/main/java/org/jooq/impl/Function.java
@@ -75,9 +75,11 @@ import org.jooq.WindowRowsStep;
*/
class Function extends AbstractField implements
- // Cascading interface implementations for aggregate and window function behaviour
+ // Cascading interface implementations for aggregate function behaviour
OrderedAggregateFunction,
AggregateFunction,
+
+ // and for window function behaviour
WindowIgnoreNullsStep,
WindowPartitionByStep,
WindowRowsStep,
diff --git a/jOOQ/src/main/java/org/jooq/impl/GroupConcat.java b/jOOQ/src/main/java/org/jooq/impl/GroupConcat.java
new file mode 100644
index 0000000000..e2e5beab00
--- /dev/null
+++ b/jOOQ/src/main/java/org/jooq/impl/GroupConcat.java
@@ -0,0 +1,121 @@
+/**
+ * Copyright (c) 2009-2012, 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 static org.jooq.impl.Factory.literal;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.jooq.AggregateFunction;
+import org.jooq.Configuration;
+import org.jooq.Field;
+import org.jooq.GroupConcatOrderByStep;
+import org.jooq.GroupConcatSeparatorStep;
+import org.jooq.SortField;
+import org.jooq.WindowPartitionByStep;
+
+/**
+ * @author Lukas Eder
+ */
+class GroupConcat extends AbstractFunction implements GroupConcatOrderByStep {
+
+ /**
+ * Generated UID
+ */
+ private static final long serialVersionUID = -6884415527559632960L;
+
+ private final Field> field;
+ private final boolean distinct;
+ private final SortFieldList orderBy;
+ private String separator;
+
+ GroupConcat(Field> field) {
+ this(field, false);
+ }
+
+ GroupConcat(Field> field, boolean distinct) {
+ super("group_concat", SQLDataType.VARCHAR);
+
+ this.field = field;
+ this.distinct = distinct;
+ this.orderBy = new SortFieldList();
+ }
+
+ @Override
+ final Field getFunction0(Configuration configuration) {
+ Function result;
+
+ if (separator == null) {
+ result = new Function(Term.LIST_AGG, distinct, SQLDataType.VARCHAR, field);
+ }
+ else {
+ Field literal = literal("'" + separator.replace("'", "''") + "'");
+ result = new Function(Term.LIST_AGG, distinct, SQLDataType.VARCHAR, field, literal);
+ }
+
+ return result.withinGroupOrderBy(orderBy);
+ }
+
+ @Override
+ public final WindowPartitionByStep over() {
+ throw new UnsupportedOperationException("OVER() not supported on GROUP_CONCAT aggregate function");
+ }
+
+ @Override
+ public final AggregateFunction separator(String s) {
+ this.separator = s;
+ return this;
+ }
+
+ @Override
+ public final GroupConcatSeparatorStep orderBy(Field>... fields) {
+ orderBy.addAll(fields);
+ return this;
+ }
+
+ @Override
+ public final GroupConcatSeparatorStep orderBy(SortField>... fields) {
+ orderBy.addAll(Arrays.asList(fields));
+ return this;
+ }
+
+ @Override
+ public final GroupConcatSeparatorStep orderBy(Collection> fields) {
+ orderBy.addAll(fields);
+ return this;
+ }
+}