diff --git a/jOOQ-examples/jOOQ-spring-boot-example/pom.xml b/jOOQ-examples/jOOQ-spring-boot-example/pom.xml index b204025bee..3babb3d9f1 100644 --- a/jOOQ-examples/jOOQ-spring-boot-example/pom.xml +++ b/jOOQ-examples/jOOQ-spring-boot-example/pom.xml @@ -26,7 +26,7 @@ UTF-8 org.jooq.example.spring.Application - 3.6.2 + 3.7.0-SNAPSHOT 1.8 diff --git a/jOOQ-examples/jOOQ-spring-boot-example/src/main/java/org/jooq/example/spring/config/ExceptionTranslator.java b/jOOQ-examples/jOOQ-spring-boot-example/src/main/java/org/jooq/example/spring/config/ExceptionTranslator.java index de5fb78898..214e3b8d75 100644 --- a/jOOQ-examples/jOOQ-spring-boot-example/src/main/java/org/jooq/example/spring/config/ExceptionTranslator.java +++ b/jOOQ-examples/jOOQ-spring-boot-example/src/main/java/org/jooq/example/spring/config/ExceptionTranslator.java @@ -1,36 +1,83 @@ -package org.jooq.example.spring.config; +/** + * Copyright (c) 2009-2015, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * Licensed 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. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.example.spring.exception; import org.jooq.ExecuteContext; import org.jooq.SQLDialect; import org.jooq.impl.DefaultExecuteListener; + import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; import org.springframework.jdbc.support.SQLExceptionTranslator; import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator; /** - * This class transforms SQLException into a Spring specific DataAccessException. The idea behind this is borrowed from - * Adam Zell's Gist + * This class transforms SQLException into a Spring specific + * DataAccessException. The idea behind this is borrowed from Adam Zell's Gist * * @author Petri Kainulainen * @author Adam Zell * @author Lukas Eder * @see http://www.petrikainulainen.net/programming/jooq/using-jooq-with-spring-configuration/ - * @see https://gist.github.com/azell/5655888 + * @see https://gist.github.com/azell/5655888 */ public class ExceptionTranslator extends DefaultExecuteListener { - /** - * Generated UID - */ - private static final long serialVersionUID = -2450323227461061152L; + /** + * Generated UID + */ + private static final long serialVersionUID = -2450323227461061152L; - @Override - public void exception(ExecuteContext ctx) { - SQLDialect dialect = ctx.configuration().dialect(); - SQLExceptionTranslator translator = (dialect != null) ? new SQLErrorCodeSQLExceptionTranslator(dialect.name()) - : new SQLStateSQLExceptionTranslator(); + @Override + public void exception(ExecuteContext ctx) { - ctx.exception(translator.translate("jOOQ", ctx.sql(), ctx.sqlException())); - } + // [#4391] Translate only SQLExceptions + if (ctx.sqlException() != null) { + SQLDialect dialect = ctx.dialect(); + SQLExceptionTranslator translator = (dialect != null) + ? new SQLErrorCodeSQLExceptionTranslator(dialect.thirdParty().springDbName()) + : new SQLStateSQLExceptionTranslator(); + + ctx.exception(translator.translate("jOOQ", ctx.sql(), ctx.sqlException())); + } + } } diff --git a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/exception/ExceptionTranslator.java b/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/exception/ExceptionTranslator.java index 9fcbf7b23f..214e3b8d75 100644 --- a/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/exception/ExceptionTranslator.java +++ b/jOOQ-examples/jOOQ-spring-example/src/main/java/org/jooq/example/spring/exception/ExceptionTranslator.java @@ -69,12 +69,12 @@ public class ExceptionTranslator extends DefaultExecuteListener { @Override public void exception(ExecuteContext ctx) { - + // [#4391] Translate only SQLExceptions if (ctx.sqlException() != null) { - SQLDialect dialect = ctx.configuration().dialect(); + SQLDialect dialect = ctx.dialect(); SQLExceptionTranslator translator = (dialect != null) - ? new SQLErrorCodeSQLExceptionTranslator(dialect.name()) + ? new SQLErrorCodeSQLExceptionTranslator(dialect.thirdParty().springDbName()) : new SQLStateSQLExceptionTranslator(); ctx.exception(translator.translate("jOOQ", ctx.sql(), ctx.sqlException())); diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 1f96268738..7b8d503ea4 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -11789,6 +11789,102 @@ public class DSL { return new GroupConcat(nullSafe(field), true); } + // ------------------------------------------------------------------------- + // XXX Ordered-set aggregate functions and hypothetical set functions + // ------------------------------------------------------------------------- + + /** + * The rank(expr) within group (order by [order clause]) + * ordered aggregate function. + */ + @Support({ POSTGRES_9_4 }) + public static OrderedAggregateFunction rank(Field... fields) { + return new Function("rank", SQLDataType.INTEGER, fields); + } + + /** + * The dense_rank(expr) within group (order by [order clause]) + * ordered aggregate function. + */ + @Support({ POSTGRES_9_4 }) + public static OrderedAggregateFunction denseRank(Field... fields) { + return new Function("dense_rank", SQLDataType.INTEGER, fields); + } + + /** + * The percent_rank(expr) within group (order by [order clause]) + * ordered aggregate function. + */ + @Support({ POSTGRES_9_4 }) + public static OrderedAggregateFunction percentRank(Field... fields) { + return new Function("percent_rank", SQLDataType.INTEGER, fields); + } + + /** + * The cume_dist(expr) within group (order by [order clause]) + * ordered aggregate function. + */ + @Support({ POSTGRES_9_4 }) + public static OrderedAggregateFunction cumeDist(Field... fields) { + return new Function("cume_dist", SQLDataType.NUMERIC, fields); + } + + /** + * The + * percentile_cont([number]) within group (order by [column]) + * function. + *

+ * While {@link SQLDialect#ORACLE} and {@link SQLDialect#POSTGRES} support + * this as an aggregate function, {@link SQLDialect#SQLSERVER} and + * {@link SQLDialect#REDSHIFT} support only its window function variant. + */ + @Support({ POSTGRES_9_4 }) + public static OrderedAggregateFunction percentileCont(Number number) { + return percentileCont(val(number)); + } + + /** + * The + * percentile_cont([number]) within group (order by [column]) + * function. + *

+ * While {@link SQLDialect#ORACLE} and {@link SQLDialect#POSTGRES} support + * this as an aggregate function, {@link SQLDialect#SQLSERVER} and + * {@link SQLDialect#REDSHIFT} support only its window function variant. + */ + @Support({ POSTGRES_9_4 }) + public static OrderedAggregateFunction percentileCont(Field field) { + return new Function("percentile_cont", SQLDataType.NUMERIC, nullSafe(field)); + } + + /** + * The + * percentile_disc([number]) within group (order by [column]) + * function. + *

+ * While {@link SQLDialect#ORACLE} and {@link SQLDialect#POSTGRES} support + * this as an aggregate function, {@link SQLDialect#SQLSERVER} and + * {@link SQLDialect#REDSHIFT} support only its window function variant. + */ + @Support({ POSTGRES_9_4 }) + public static OrderedAggregateFunction percentileDisc(Number number) { + return percentileDisc(val(number)); + } + + /** + * The + * percentile_disc([number]) within group (order by [column]) + * function. + *

+ * While {@link SQLDialect#ORACLE} and {@link SQLDialect#POSTGRES} support + * this as an aggregate function, {@link SQLDialect#SQLSERVER} and + * {@link SQLDialect#REDSHIFT} support only its window function variant. + */ + @Support({ POSTGRES_9_4 }) + public static OrderedAggregateFunction percentileDisc(Field field) { + return new Function("percentile_disc", SQLDataType.NUMERIC, nullSafe(field)); + } + // ------------------------------------------------------------------------- // XXX Window clauses // ------------------------------------------------------------------------- @@ -11939,15 +12035,6 @@ public class DSL { return new Function("rank", SQLDataType.INTEGER); } - /** - * The rank(expr) within group (order by [order clause]) - * ordered aggregate function. - */ - @Support({ POSTGRES_9_4 }) - public static OrderedAggregateFunction rank(Field... fields) { - return new Function("rank", SQLDataType.INTEGER, fields); - } - /** * The dense_rank() over ([analytic clause]) function. */ @@ -11956,15 +12043,6 @@ public class DSL { return new Function("dense_rank", SQLDataType.INTEGER); } - /** - * The dense_rank(expr) within group (order by [order clause]) - * ordered aggregate function. - */ - @Support({ POSTGRES_9_4 }) - public static OrderedAggregateFunction denseRank(Field... fields) { - return new Function("dense_rank", SQLDataType.INTEGER, fields); - } - /** * The precent_rank() over ([analytic clause]) function. */ @@ -11973,15 +12051,6 @@ public class DSL { return new Function("percent_rank", SQLDataType.NUMERIC); } - /** - * The percent_rank(expr) within group (order by [order clause]) - * ordered aggregate function. - */ - @Support({ POSTGRES_9_4 }) - public static OrderedAggregateFunction percentRank(Field... fields) { - return new Function("percent_rank", SQLDataType.INTEGER, fields); - } - /** * The cume_dist() over ([analytic clause]) function. */ @@ -11990,15 +12059,6 @@ public class DSL { return new Function("cume_dist", SQLDataType.NUMERIC); } - /** - * The cume_dist(expr) within group (order by [order clause]) - * ordered aggregate function. - */ - @Support({ POSTGRES_9_4 }) - public static OrderedAggregateFunction cumeDist(Field... fields) { - return new Function("cume_dist", SQLDataType.NUMERIC, fields); - } - /** * The ntile([number]) over ([analytic clause]) function. */ @@ -12007,62 +12067,6 @@ public class DSL { return new Function("ntile", SQLDataType.INTEGER, inline(number)); } - /** - * The - * percentile_cont([number]) within group (order by [column]) - * function. - *

- * While {@link SQLDialect#ORACLE} and {@link SQLDialect#POSTGRES} support - * this as an aggregate function, {@link SQLDialect#SQLSERVER} and - * {@link SQLDialect#REDSHIFT} support only its window function variant. - */ - @Support({ POSTGRES_9_4 }) - public static OrderedAggregateFunction percentileCont(Number number) { - return percentileCont(val(number)); - } - - /** - * The - * percentile_cont([number]) within group (order by [column]) - * function. - *

- * While {@link SQLDialect#ORACLE} and {@link SQLDialect#POSTGRES} support - * this as an aggregate function, {@link SQLDialect#SQLSERVER} and - * {@link SQLDialect#REDSHIFT} support only its window function variant. - */ - @Support({ POSTGRES_9_4 }) - public static OrderedAggregateFunction percentileCont(Field field) { - return new Function("percentile_cont", SQLDataType.NUMERIC, nullSafe(field)); - } - - /** - * The - * percentile_disc([number]) within group (order by [column]) - * function. - *

- * While {@link SQLDialect#ORACLE} and {@link SQLDialect#POSTGRES} support - * this as an aggregate function, {@link SQLDialect#SQLSERVER} and - * {@link SQLDialect#REDSHIFT} support only its window function variant. - */ - @Support({ POSTGRES_9_4 }) - public static OrderedAggregateFunction percentileDisc(Number number) { - return percentileDisc(val(number)); - } - - /** - * The - * percentile_disc([number]) within group (order by [column]) - * function. - *

- * While {@link SQLDialect#ORACLE} and {@link SQLDialect#POSTGRES} support - * this as an aggregate function, {@link SQLDialect#SQLSERVER} and - * {@link SQLDialect#REDSHIFT} support only its window function variant. - */ - @Support({ POSTGRES_9_4 }) - public static OrderedAggregateFunction percentileDisc(Field field) { - return new Function("percentile_disc", SQLDataType.NUMERIC, nullSafe(field)); - } - /** * The first_value(field) over ([analytic clause]) function. */