Skip to content

Commit 31a251e

Browse files
committed
Polishing
1 parent ce6adfb commit 31a251e

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,9 +45,8 @@
4545
* {@link SQLExceptionTranslator} implementation which analyzes the specific
4646
* {@link java.sql.SQLException} subclass thrown by the JDBC driver.
4747
*
48-
* <p>This is only available with JDBC 4.0 and later drivers when using Java 6 or later.
49-
* Falls back to a standard {@link SQLStateSQLExceptionTranslator} if the JDBC driver
50-
* does not actually expose JDBC 4 compliant {@code SQLException} subclasses.
48+
* <p>Falls back to a standard {@link SQLStateSQLExceptionTranslator} if the JDBC
49+
* driver does not actually expose JDBC 4 compliant {@code SQLException} subclasses.
5150
*
5251
* @author Thomas Risberg
5352
* @author Juergen Hoeller
@@ -65,35 +64,35 @@ public SQLExceptionSubclassTranslator() {
6564
@Override
6665
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
6766
if (ex instanceof SQLTransientException) {
68-
if (ex instanceof SQLTransactionRollbackException) {
69-
return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
70-
}
7167
if (ex instanceof SQLTransientConnectionException) {
7268
return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
7369
}
74-
if (ex instanceof SQLTimeoutException) {
70+
else if (ex instanceof SQLTransactionRollbackException) {
71+
return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
72+
}
73+
else if (ex instanceof SQLTimeoutException) {
7574
return new QueryTimeoutException(buildMessage(task, sql, ex), ex);
7675
}
7776
}
7877
else if (ex instanceof SQLNonTransientException) {
79-
if (ex instanceof SQLDataException) {
80-
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
78+
if (ex instanceof SQLNonTransientConnectionException) {
79+
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
8180
}
82-
else if (ex instanceof SQLFeatureNotSupportedException) {
83-
return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex);
81+
else if (ex instanceof SQLDataException) {
82+
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
8483
}
8584
else if (ex instanceof SQLIntegrityConstraintViolationException) {
8685
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
8786
}
8887
else if (ex instanceof SQLInvalidAuthorizationSpecException) {
8988
return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex);
9089
}
91-
else if (ex instanceof SQLNonTransientConnectionException) {
92-
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
93-
}
9490
else if (ex instanceof SQLSyntaxErrorException) {
9591
return new BadSqlGrammarException(task, sql, ex);
9692
}
93+
else if (ex instanceof SQLFeatureNotSupportedException) {
94+
return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex);
95+
}
9796
}
9897
else if (ex instanceof SQLRecoverableException) {
9998
return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/AbstractSockJsMessageCodec.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,9 +27,8 @@
2727
*/
2828
public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec {
2929

30-
3130
@Override
32-
public String encode(String[] messages) {
31+
public String encode(String... messages) {
3332
Assert.notNull(messages, "messages must not be null");
3433
StringBuilder sb = new StringBuilder();
3534
sb.append("a[");
@@ -76,9 +75,9 @@ private String escapeSockJsSpecialChars(char[] characters) {
7675
* See `escapable_by_server` variable in the SockJS protocol test suite.
7776
*/
7877
private boolean isSockJsSpecialChar(char ch) {
79-
return (ch >= '\u0000' && ch <= '\u001F') || (ch >= '\u200C' && ch <= '\u200F')
80-
|| (ch >= '\u2028' && ch <= '\u202F') || (ch >= '\u2060' && ch <= '\u206F')
81-
|| (ch >= '\uFFF0' && ch <= '\uFFFF') || (ch >= '\uD800' && ch <= '\uDFFF');
78+
return (ch >= '\u0000' && ch <= '\u001F') || (ch >= '\u200C' && ch <= '\u200F') ||
79+
(ch >= '\u2028' && ch <= '\u202F') || (ch >= '\u2060' && ch <= '\u206F') ||
80+
(ch >= '\uFFF0' && ch <= '\uFFFF') || (ch >= '\uD800' && ch <= '\uDFFF');
8281
}
8382

8483
}

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,10 +20,10 @@
2020
import java.io.InputStream;
2121

2222
/**
23-
* Encode and decode messages to and from a SockJS message frame, essentially an array of
24-
* JSON-encoded messages. For example:
23+
* Encode and decode messages to and from a SockJS message frame,
24+
* essentially an array of JSON-encoded messages. For example:
2525
*
26-
* <pre>
26+
* <pre class="code">
2727
* a["message1","message2"]
2828
* </pre>
2929
*
@@ -38,22 +38,22 @@ public interface SockJsMessageCodec {
3838
* rules. See the "JSON Unicode Encoding" section of SockJS protocol (i.e. the
3939
* protocol test suite).
4040
* @param messages the messages to encode
41-
* @return the content for a SockJS message frame, never {@code null}
41+
* @return the content for a SockJS message frame (never {@code null})
4242
*/
43-
String encode(String[] messages);
43+
String encode(String... messages);
4444

4545
/**
4646
* Decode the given SockJS message frame.
4747
* @param content the SockJS message frame
48-
* @return an array of messages or {@code null}
48+
* @return an array of messages, or {@code null} if none
4949
* @throws IOException if the content could not be parsed
5050
*/
5151
String[] decode(String content) throws IOException;
5252

5353
/**
5454
* Decode the given SockJS message frame.
5555
* @param content the SockJS message frame
56-
* @return an array of messages or {@code null}
56+
* @return an array of messages, or {@code null} if none
5757
* @throws IOException if the content could not be parsed
5858
*/
5959
String[] decodeInputStream(InputStream content) throws IOException;

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpReceivingTransportHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse
5555
try {
5656
response.getBody().write("ok".getBytes("UTF-8"));
5757
}
58-
catch(IOException ex) {
58+
catch (IOException ex) {
5959
throw new SockJsException("Failed to write to the response body", sockJsSession.getId(), ex);
6060
}
6161
}
@@ -64,10 +64,10 @@ public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse
6464
protected String[] readMessages(ServerHttpRequest request) throws IOException {
6565
SockJsMessageCodec messageCodec = getServiceConfig().getMessageCodec();
6666
MediaType contentType = request.getHeaders().getContentType();
67-
if ((contentType != null) && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
67+
if (contentType != null && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
6868
MultiValueMap<String, String> map = this.formConverter.read(null, request);
6969
String d = map.getFirst("d");
70-
return (StringUtils.hasText(d)) ? messageCodec.decode(d) : null;
70+
return (StringUtils.hasText(d) ? messageCodec.decode(d) : null);
7171
}
7272
else {
7373
return messageCodec.decodeInputStream(request.getBody());

0 commit comments

Comments
 (0)