[#4557] ExceptionTranslator in spring examples shouldn't use dialect.name() for SQLErrorCodeSQLExceptionTranslator

This commit is contained in:
lukaseder 2015-09-16 20:48:15 +02:00
parent 248fa38cc6
commit cf92bf2979
4 changed files with 162 additions and 111 deletions

View File

@ -26,7 +26,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>org.jooq.example.spring.Application</start-class>
<org.jooq.version>3.6.2</org.jooq.version>
<org.jooq.version>3.7.0-SNAPSHOT</org.jooq.version>
<java.version>1.8</java.version>
</properties>

View File

@ -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 <a
* href="http://www.petrikainulainen.net/programming/jooq/using-jooq-with-spring-configuration/">http://www.petrikainulainen.net/programming/jooq/using-jooq-with-spring-configuration/</a>
* @see <a href="https://gist.github.com/azell/5655888">https://gist.github.com/azell/5655888</a>
* @see <a
* href="https://gist.github.com/azell/5655888">https://gist.github.com/azell/5655888</a>
*/
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()));
}
}
}

View File

@ -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()));

View File

@ -11789,6 +11789,102 @@ public class DSL {
return new GroupConcat(nullSafe(field), true);
}
// -------------------------------------------------------------------------
// XXX Ordered-set aggregate functions and hypothetical set functions
// -------------------------------------------------------------------------
/**
* The <code>rank(expr) within group (order by [order clause])</code>
* ordered aggregate function.
*/
@Support({ POSTGRES_9_4 })
public static OrderedAggregateFunction<Integer> rank(Field<?>... fields) {
return new Function<Integer>("rank", SQLDataType.INTEGER, fields);
}
/**
* The <code>dense_rank(expr) within group (order by [order clause])</code>
* ordered aggregate function.
*/
@Support({ POSTGRES_9_4 })
public static OrderedAggregateFunction<Integer> denseRank(Field<?>... fields) {
return new Function<Integer>("dense_rank", SQLDataType.INTEGER, fields);
}
/**
* The <code>percent_rank(expr) within group (order by [order clause])</code>
* ordered aggregate function.
*/
@Support({ POSTGRES_9_4 })
public static OrderedAggregateFunction<Integer> percentRank(Field<?>... fields) {
return new Function<Integer>("percent_rank", SQLDataType.INTEGER, fields);
}
/**
* The <code>cume_dist(expr) within group (order by [order clause])</code>
* ordered aggregate function.
*/
@Support({ POSTGRES_9_4 })
public static OrderedAggregateFunction<BigDecimal> cumeDist(Field<?>... fields) {
return new Function<BigDecimal>("cume_dist", SQLDataType.NUMERIC, fields);
}
/**
* The
* <code>percentile_cont([number]) within group (order by [column])</code>
* function.
* <p>
* 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<BigDecimal> percentileCont(Number number) {
return percentileCont(val(number));
}
/**
* The
* <code>percentile_cont([number]) within group (order by [column])</code>
* function.
* <p>
* 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<BigDecimal> percentileCont(Field<? extends Number> field) {
return new Function<BigDecimal>("percentile_cont", SQLDataType.NUMERIC, nullSafe(field));
}
/**
* The
* <code>percentile_disc([number]) within group (order by [column])</code>
* function.
* <p>
* 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<BigDecimal> percentileDisc(Number number) {
return percentileDisc(val(number));
}
/**
* The
* <code>percentile_disc([number]) within group (order by [column])</code>
* function.
* <p>
* 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<BigDecimal> percentileDisc(Field<? extends Number> field) {
return new Function<BigDecimal>("percentile_disc", SQLDataType.NUMERIC, nullSafe(field));
}
// -------------------------------------------------------------------------
// XXX Window clauses
// -------------------------------------------------------------------------
@ -11939,15 +12035,6 @@ public class DSL {
return new Function<Integer>("rank", SQLDataType.INTEGER);
}
/**
* The <code>rank(expr) within group (order by [order clause])</code>
* ordered aggregate function.
*/
@Support({ POSTGRES_9_4 })
public static OrderedAggregateFunction<Integer> rank(Field<?>... fields) {
return new Function<Integer>("rank", SQLDataType.INTEGER, fields);
}
/**
* The <code>dense_rank() over ([analytic clause])</code> function.
*/
@ -11956,15 +12043,6 @@ public class DSL {
return new Function<Integer>("dense_rank", SQLDataType.INTEGER);
}
/**
* The <code>dense_rank(expr) within group (order by [order clause])</code>
* ordered aggregate function.
*/
@Support({ POSTGRES_9_4 })
public static OrderedAggregateFunction<Integer> denseRank(Field<?>... fields) {
return new Function<Integer>("dense_rank", SQLDataType.INTEGER, fields);
}
/**
* The <code>precent_rank() over ([analytic clause])</code> function.
*/
@ -11973,15 +12051,6 @@ public class DSL {
return new Function<BigDecimal>("percent_rank", SQLDataType.NUMERIC);
}
/**
* The <code>percent_rank(expr) within group (order by [order clause])</code>
* ordered aggregate function.
*/
@Support({ POSTGRES_9_4 })
public static OrderedAggregateFunction<Integer> percentRank(Field<?>... fields) {
return new Function<Integer>("percent_rank", SQLDataType.INTEGER, fields);
}
/**
* The <code>cume_dist() over ([analytic clause])</code> function.
*/
@ -11990,15 +12059,6 @@ public class DSL {
return new Function<BigDecimal>("cume_dist", SQLDataType.NUMERIC);
}
/**
* The <code>cume_dist(expr) within group (order by [order clause])</code>
* ordered aggregate function.
*/
@Support({ POSTGRES_9_4 })
public static OrderedAggregateFunction<BigDecimal> cumeDist(Field<?>... fields) {
return new Function<BigDecimal>("cume_dist", SQLDataType.NUMERIC, fields);
}
/**
* The <code>ntile([number]) over ([analytic clause])</code> function.
*/
@ -12007,62 +12067,6 @@ public class DSL {
return new Function<Integer>("ntile", SQLDataType.INTEGER, inline(number));
}
/**
* The
* <code>percentile_cont([number]) within group (order by [column])</code>
* function.
* <p>
* 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<BigDecimal> percentileCont(Number number) {
return percentileCont(val(number));
}
/**
* The
* <code>percentile_cont([number]) within group (order by [column])</code>
* function.
* <p>
* 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<BigDecimal> percentileCont(Field<? extends Number> field) {
return new Function<BigDecimal>("percentile_cont", SQLDataType.NUMERIC, nullSafe(field));
}
/**
* The
* <code>percentile_disc([number]) within group (order by [column])</code>
* function.
* <p>
* 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<BigDecimal> percentileDisc(Number number) {
return percentileDisc(val(number));
}
/**
* The
* <code>percentile_disc([number]) within group (order by [column])</code>
* function.
* <p>
* 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<BigDecimal> percentileDisc(Field<? extends Number> field) {
return new Function<BigDecimal>("percentile_disc", SQLDataType.NUMERIC, nullSafe(field));
}
/**
* The <code>first_value(field) over ([analytic clause])</code> function.
*/