From 55c351523de05d68013b1eab459e815522cca54a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 7 Jul 2014 16:28:48 +0200 Subject: [PATCH] Polishing --- .../SQLExceptionSubclassTranslator.java | 29 +++++----- .../config/AbstractJmsListenerEndpoint.java | 58 +++++++++---------- 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java index 26b528e9f9..78455c1865 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,9 +45,8 @@ import org.springframework.jdbc.BadSqlGrammarException; * {@link SQLExceptionTranslator} implementation which analyzes the specific * {@link java.sql.SQLException} subclass thrown by the JDBC driver. * - *

This is only available with JDBC 4.0 and later drivers when using Java 6 or later. - * Falls back to a standard {@link SQLStateSQLExceptionTranslator} if the JDBC driver - * does not actually expose JDBC 4 compliant {@code SQLException} subclasses. + *

Falls back to a standard {@link SQLStateSQLExceptionTranslator} if the JDBC + * driver does not actually expose JDBC 4 compliant {@code SQLException} subclasses. * * @author Thomas Risberg * @author Juergen Hoeller @@ -65,22 +64,22 @@ public class SQLExceptionSubclassTranslator extends AbstractFallbackSQLException @Override protected DataAccessException doTranslate(String task, String sql, SQLException ex) { if (ex instanceof SQLTransientException) { - if (ex instanceof SQLTransactionRollbackException) { - return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); - } if (ex instanceof SQLTransientConnectionException) { return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); } - if (ex instanceof SQLTimeoutException) { + else if (ex instanceof SQLTransactionRollbackException) { + return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); + } + else if (ex instanceof SQLTimeoutException) { return new QueryTimeoutException(buildMessage(task, sql, ex), ex); } } else if (ex instanceof SQLNonTransientException) { - if (ex instanceof SQLDataException) { - return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); + if (ex instanceof SQLNonTransientConnectionException) { + return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); } - else if (ex instanceof SQLFeatureNotSupportedException) { - return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex); + else if (ex instanceof SQLDataException) { + return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLIntegrityConstraintViolationException) { return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); @@ -88,12 +87,12 @@ public class SQLExceptionSubclassTranslator extends AbstractFallbackSQLException else if (ex instanceof SQLInvalidAuthorizationSpecException) { return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex); } - else if (ex instanceof SQLNonTransientConnectionException) { - return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); - } else if (ex instanceof SQLSyntaxErrorException) { return new BadSqlGrammarException(task, sql, ex); } + else if (ex instanceof SQLFeatureNotSupportedException) { + return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex); + } } else if (ex instanceof SQLRecoverableException) { return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex); diff --git a/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java b/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java index ba00fd0745..a355984b57 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java @@ -43,20 +43,13 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint private String selector; - @Override - public String getId() { - return id; - } - public void setId(String id) { this.id = id; } - /** - * Return the name of the destination for this endpoint. - */ - public String getDestination() { - return destination; + @Override + public String getId() { + return this.id; } /** @@ -67,10 +60,10 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint } /** - * Return the name for the durable subscription, if any. + * Return the name of the destination for this endpoint. */ - public String getSubscription() { - return subscription; + public String getDestination() { + return this.destination; } /** @@ -81,32 +74,40 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint } /** - * Return the JMS message selector expression, if any. - *

See the JMS specification for a detailed definition of selector expressions. + * Return the name for the durable subscription, if any. */ - public String getSelector() { - return selector; + public String getSubscription() { + return this.subscription; } /** * Set the JMS message selector expression. + *

See the JMS specification for a detailed definition of selector expressions. */ public void setSelector(String selector) { this.selector = selector; } + /** + * Return the JMS message selector expression, if any. + */ + public String getSelector() { + return this.selector; + } + + @Override public void setupMessageContainer(MessageListenerContainer container) { - if (container instanceof AbstractMessageListenerContainer) { // JMS + if (container instanceof AbstractMessageListenerContainer) { // JMS setupJmsMessageContainer((AbstractMessageListenerContainer) container); } - else if (container instanceof JmsMessageEndpointManager) { // JCA + else if (container instanceof JmsMessageEndpointManager) { // JCA setupJcaMessageContainer((JmsMessageEndpointManager) container); } else { - throw new IllegalArgumentException("Could not configure endpoint with the specified container '" - + container + "' Only JMS (" + AbstractMessageListenerContainer.class.getName() - + " subclass) or JCA (" + JmsMessageEndpointManager.class.getName() + ") are supported."); + throw new IllegalArgumentException("Could not configure endpoint with the specified container '" + + container + "' Only JMS (" + AbstractMessageListenerContainer.class.getName() + + " subclass) or JCA (" + JmsMessageEndpointManager.class.getName() + ") are supported."); } } @@ -160,16 +161,9 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint */ protected StringBuilder getEndpointDescription() { StringBuilder result = new StringBuilder(); - return result.append(getClass().getSimpleName()) - .append("[") - .append(this.id) - .append("] destination=") - .append(this.destination) - .append("' | subscription='") - .append(this.subscription) - .append(" | selector='") - .append(this.selector) - .append("'"); + return result.append(getClass().getSimpleName()).append("[").append(this.id).append("] destination="). + append(this.destination).append("' | subscription='").append(this.subscription). + append(" | selector='").append(this.selector).append("'"); } @Override