Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-28 11:39:36 +00:00
parent fda7100866
commit f8c690c542
55 changed files with 356 additions and 445 deletions

View File

@@ -1279,7 +1279,7 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
if (method.getName().equals("equals")) {
// Only consider equal when proxies are identical.
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
return (proxy == args[0]);
}
else if (method.getName().equals("hashCode")) {
// Use hashCode of Session proxy.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -145,8 +145,8 @@ public class OpenSessionInViewInterceptor extends HibernateAccessor implements W
// Do not modify the Session: just mark the request accordingly.
String participateAttributeName = getParticipateAttributeName();
Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
int newCount = (count != null) ? count.intValue() + 1 : 1;
request.setAttribute(getParticipateAttributeName(), new Integer(newCount), WebRequest.SCOPE_REQUEST);
int newCount = (count != null ? count + 1 : 1);
request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
}
else {
if (isSingleSession()) {
@@ -197,8 +197,8 @@ public class OpenSessionInViewInterceptor extends HibernateAccessor implements W
Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
if (count != null) {
// Do not modify the Session: just clear the marker.
if (count.intValue() > 1) {
request.setAttribute(participateAttributeName, new Integer(count.intValue() - 1), WebRequest.SCOPE_REQUEST);
if (count > 1) {
request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
}
else {
request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2008 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.
@@ -31,7 +31,7 @@ import com.ibatis.sqlmap.client.SqlMapExecutor;
* @see SqlMapClientTemplate
* @see org.springframework.jdbc.datasource.DataSourceTransactionManager
*/
public interface SqlMapClientCallback {
public interface SqlMapClientCallback<T> {
/**
* Gets called by <code>SqlMapClientTemplate.execute</code> with an active
@@ -57,6 +57,6 @@ public interface SqlMapClientCallback {
* @see SqlMapClientTemplate#executeWithListResult
* @see SqlMapClientTemplate#executeWithMapResult
*/
Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException;
T doInSqlMapClient(SqlMapExecutor executor) throws SQLException;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2008 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.
@@ -103,24 +103,6 @@ public interface SqlMapClientOperations {
void queryWithRowHandler(String statementName, Object parameterObject, RowHandler rowHandler)
throws DataAccessException;
/**
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForPaginatedList(String, int)
* @deprecated as of iBATIS 2.3.0
* @throws org.springframework.dao.DataAccessException in case of errors
*/
@Deprecated
PaginatedList queryForPaginatedList(String statementName, int pageSize)
throws DataAccessException;
/**
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForPaginatedList(String, Object, int)
* @deprecated as of iBATIS 2.3.0
* @throws org.springframework.dao.DataAccessException in case of errors
*/
@Deprecated
PaginatedList queryForPaginatedList(String statementName, Object parameterObject, int pageSize)
throws DataAccessException;
/**
* @see com.ibatis.sqlmap.client.SqlMapExecutor#queryForMap(String, Object, String)
* @throws org.springframework.dao.DataAccessException in case of errors

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -20,18 +20,14 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import com.ibatis.common.util.PaginatedList;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.ibatis.sqlmap.client.SqlMapSession;
import com.ibatis.sqlmap.client.event.RowHandler;
import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.CannotGetJdbcConnectionException;
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException;
import org.springframework.jdbc.datasource.DataSourceUtils;
@@ -89,8 +85,6 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
private SqlMapClient sqlMapClient;
private boolean lazyLoadingAvailable = true;
/**
* Create a new SqlMapClientTemplate.
@@ -148,11 +142,6 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
if (this.sqlMapClient == null) {
throw new IllegalArgumentException("Property 'sqlMapClient' is required");
}
if (this.sqlMapClient instanceof ExtendedSqlMapClient) {
// Check whether iBATIS lazy loading is available, that is,
// whether a DataSource was specified on the SqlMapClient itself.
this.lazyLoadingAvailable = (((ExtendedSqlMapClient) this.sqlMapClient).getDelegate().getTxManager() != null);
}
super.afterPropertiesSet();
}
@@ -163,7 +152,7 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
* @return a result object returned by the action, or <code>null</code>
* @throws DataAccessException in case of SQL Maps errors
*/
public Object execute(SqlMapClientCallback action) throws DataAccessException {
public <T> T execute(SqlMapClientCallback<T> action) throws DataAccessException {
Assert.notNull(action, "Callback object must not be null");
Assert.notNull(this.sqlMapClient, "No SqlMapClient specified");
@@ -246,9 +235,12 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
* @param action callback object that specifies the data access action
* @return the List result
* @throws DataAccessException in case of SQL Maps errors
* @deprecated as of Spring 3.0 - not really needed anymore with generic
* {@link #execute} method
*/
public List executeWithListResult(SqlMapClientCallback action) throws DataAccessException {
return (List) execute(action);
@Deprecated
public List executeWithListResult(SqlMapClientCallback<List> action) throws DataAccessException {
return execute(action);
}
/**
@@ -257,9 +249,12 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
* @param action callback object that specifies the data access action
* @return the Map result
* @throws DataAccessException in case of SQL Maps errors
* @deprecated as of Spring 3.0 - not really needed anymore with generic
* {@link #execute} method
*/
public Map executeWithMapResult(SqlMapClientCallback action) throws DataAccessException {
return (Map) execute(action);
@Deprecated
public Map executeWithMapResult(SqlMapClientCallback<Map> action) throws DataAccessException {
return execute(action);
}
@@ -270,7 +265,7 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
public Object queryForObject(final String statementName, final Object parameterObject)
throws DataAccessException {
return execute(new SqlMapClientCallback() {
return execute(new SqlMapClientCallback<Object>() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.queryForObject(statementName, parameterObject);
}
@@ -281,7 +276,7 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
final String statementName, final Object parameterObject, final Object resultObject)
throws DataAccessException {
return execute(new SqlMapClientCallback() {
return execute(new SqlMapClientCallback<Object>() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.queryForObject(statementName, parameterObject, resultObject);
}
@@ -295,8 +290,8 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
public List queryForList(final String statementName, final Object parameterObject)
throws DataAccessException {
return executeWithListResult(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return execute(new SqlMapClientCallback<List>() {
public List doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.queryForList(statementName, parameterObject);
}
});
@@ -312,8 +307,8 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
final String statementName, final Object parameterObject, final int skipResults, final int maxResults)
throws DataAccessException {
return executeWithListResult(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return execute(new SqlMapClientCallback<List>() {
public List doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.queryForList(statementName, parameterObject, skipResults, maxResults);
}
});
@@ -329,7 +324,7 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
final String statementName, final Object parameterObject, final RowHandler rowHandler)
throws DataAccessException {
execute(new SqlMapClientCallback() {
execute(new SqlMapClientCallback<Object>() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.queryWithRowHandler(statementName, parameterObject, rowHandler);
return null;
@@ -337,44 +332,12 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
});
}
/**
* @deprecated as of iBATIS 2.3.0
*/
@Deprecated
public PaginatedList queryForPaginatedList(String statementName, int pageSize)
throws DataAccessException {
return queryForPaginatedList(statementName, null, pageSize);
}
/**
* @deprecated as of iBATIS 2.3.0
*/
@Deprecated
public PaginatedList queryForPaginatedList(
final String statementName, final Object parameterObject, final int pageSize)
throws DataAccessException {
// Throw exception if lazy loading will not work.
if (!this.lazyLoadingAvailable) {
throw new InvalidDataAccessApiUsageException(
"SqlMapClient needs to have DataSource to allow for lazy loading" +
" - specify SqlMapClientFactoryBean's 'dataSource' property");
}
return (PaginatedList) execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.queryForPaginatedList(statementName, parameterObject, pageSize);
}
});
}
public Map queryForMap(
final String statementName, final Object parameterObject, final String keyProperty)
throws DataAccessException {
return executeWithMapResult(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return execute(new SqlMapClientCallback<Map>() {
public Map doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.queryForMap(statementName, parameterObject, keyProperty);
}
});
@@ -384,8 +347,8 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
final String statementName, final Object parameterObject, final String keyProperty, final String valueProperty)
throws DataAccessException {
return executeWithMapResult(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return execute(new SqlMapClientCallback<Map>() {
public Map doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.queryForMap(statementName, parameterObject, keyProperty, valueProperty);
}
});
@@ -398,7 +361,7 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
public Object insert(final String statementName, final Object parameterObject)
throws DataAccessException {
return execute(new SqlMapClientCallback() {
return execute(new SqlMapClientCallback<Object>() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.insert(statementName, parameterObject);
}
@@ -412,12 +375,11 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
public int update(final String statementName, final Object parameterObject)
throws DataAccessException {
Integer result = (Integer) execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return new Integer(executor.update(statementName, parameterObject));
return execute(new SqlMapClientCallback<Integer>() {
public Integer doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.update(statementName, parameterObject);
}
});
return result.intValue();
}
public void update(String statementName, Object parameterObject, int requiredRowsAffected)
@@ -437,12 +399,11 @@ public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOp
public int delete(final String statementName, final Object parameterObject)
throws DataAccessException {
Integer result = (Integer) execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return new Integer(executor.delete(statementName, parameterObject));
return execute(new SqlMapClientCallback<Integer>() {
public Integer doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
return executor.delete(statementName, parameterObject);
}
});
return result.intValue();
}
public void delete(String statementName, Object parameterObject, int requiredRowsAffected)

View File

@@ -574,11 +574,11 @@ public class JdoTemplate extends JdoAccessor implements JdoOperations {
if (method.getName().equals("equals")) {
// Only consider equal when proxies are identical.
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
return (proxy == args[0]);
}
else if (method.getName().equals("hashCode")) {
// Use hashCode of PersistenceManager proxy.
return new Integer(System.identityHashCode(proxy));
return System.identityHashCode(proxy);
}
else if (method.getName().equals("close")) {
// Handle close method: suppress, not valid.

View File

@@ -148,18 +148,18 @@ public class TransactionAwarePersistenceManagerFactoryProxy implements FactoryBe
if (method.getName().equals("equals")) {
// Only consider equal when proxies are identical.
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
return (proxy == args[0]);
}
else if (method.getName().equals("hashCode")) {
// Use hashCode of PersistenceManagerFactory proxy.
return new Integer(System.identityHashCode(proxy));
return System.identityHashCode(proxy);
}
else if (method.getName().equals("getPersistenceManager")) {
PersistenceManagerFactory target = getTargetPersistenceManagerFactory();
PersistenceManager pm =
PersistenceManagerFactoryUtils.doGetPersistenceManager(target, isAllowCreate());
Class[] ifcs = ClassUtils.getAllInterfacesForClass(pm.getClass(), getClass().getClassLoader());
return (PersistenceManager) Proxy.newProxyInstance(
return Proxy.newProxyInstance(
pm.getClass().getClassLoader(), ifcs, new TransactionAwareInvocationHandler(pm, target));
}
@@ -194,11 +194,11 @@ public class TransactionAwarePersistenceManagerFactoryProxy implements FactoryBe
if (method.getName().equals("equals")) {
// Only consider equal when proxies are identical.
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
return (proxy == args[0]);
}
else if (method.getName().equals("hashCode")) {
// Use hashCode of PersistenceManager proxy.
return new Integer(System.identityHashCode(proxy));
return System.identityHashCode(proxy);
}
else if (method.getName().equals("close")) {
// Handle close method: only close if not within a transaction.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -94,8 +94,8 @@ public class OpenPersistenceManagerInViewInterceptor implements WebRequestInterc
// Do not modify the PersistenceManager: just mark the request accordingly.
String participateAttributeName = getParticipateAttributeName();
Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
int newCount = (count != null) ? count.intValue() + 1 : 1;
request.setAttribute(getParticipateAttributeName(), new Integer(newCount), WebRequest.SCOPE_REQUEST);
int newCount = (count != null ? count + 1 : 1);
request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
}
else {
logger.debug("Opening JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
@@ -114,8 +114,8 @@ public class OpenPersistenceManagerInViewInterceptor implements WebRequestInterc
Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
if (count != null) {
// Do not modify the PersistenceManager: just clear the marker.
if (count.intValue() > 1) {
request.setAttribute(participateAttributeName, new Integer(count.intValue() - 1), WebRequest.SCOPE_REQUEST);
if (count > 1) {
request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
}
else {
request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);

View File

@@ -415,7 +415,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
try {
if (method.getName().equals("equals")) {
// Only consider equal when proxies are identical.
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
return (proxy == args[0]);
}
else if (method.getName().equals("hashCode")) {
// Use hashCode of EntityManagerFactory proxy.

View File

@@ -247,10 +247,10 @@ public class JpaTemplate extends JpaAccessor implements JpaOperations {
public boolean contains(final Object entity) throws DataAccessException {
Boolean result = (Boolean) execute(new JpaCallback() {
public Object doInJpa(EntityManager em) throws PersistenceException {
return new Boolean(em.contains(entity));
return em.contains(entity);
}
}, true);
return result.booleanValue();
return result;
}
public void refresh(final Object entity) throws DataAccessException {
@@ -388,11 +388,11 @@ public class JpaTemplate extends JpaAccessor implements JpaOperations {
if (method.getName().equals("equals")) {
// Only consider equal when proxies are identical.
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
return (proxy == args[0]);
}
else if (method.getName().equals("hashCode")) {
// Use hashCode of EntityManager proxy.
return new Integer(System.identityHashCode(proxy));
return System.identityHashCode(proxy);
}
else if (method.getName().equals("close")) {
// Handle close method: suppress, not valid.

View File

@@ -72,8 +72,8 @@ public class OpenEntityManagerInViewInterceptor extends EntityManagerFactoryAcce
// do not modify the EntityManager: just mark the request accordingly
String participateAttributeName = getParticipateAttributeName();
Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
int newCount = (count != null) ? count.intValue() + 1 : 1;
request.setAttribute(getParticipateAttributeName(), new Integer(newCount), WebRequest.SCOPE_REQUEST);
int newCount = (count != null ? count + 1 : 1);
request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
}
else {
logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewInterceptor");
@@ -95,8 +95,8 @@ public class OpenEntityManagerInViewInterceptor extends EntityManagerFactoryAcce
Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
if (count != null) {
// Do not modify the EntityManager: just clear the marker.
if (count.intValue() > 1) {
request.setAttribute(participateAttributeName, new Integer(count.intValue() - 1), WebRequest.SCOPE_REQUEST);
if (count > 1) {
request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
}
else {
request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);