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

@@ -1272,7 +1272,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
else 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.

View File

@@ -30,9 +30,9 @@ import org.springframework.util.Assert;
*/
public abstract class AbstractSqlParameterSource implements SqlParameterSource {
private final Map sqlTypes = new HashMap();
private final Map<String, Integer> sqlTypes = new HashMap<String, Integer>();
private final Map typeNames = new HashMap();
private final Map<String, String> typeNames = new HashMap<String, String>();
/**
@@ -42,7 +42,7 @@ public abstract class AbstractSqlParameterSource implements SqlParameterSource {
*/
public void registerSqlType(String paramName, int sqlType) {
Assert.notNull(paramName, "Parameter name must not be null");
this.sqlTypes.put(paramName, new Integer(sqlType));
this.sqlTypes.put(paramName, sqlType);
}
/**
@@ -63,9 +63,9 @@ public abstract class AbstractSqlParameterSource implements SqlParameterSource {
*/
public int getSqlType(String paramName) {
Assert.notNull(paramName, "Parameter name must not be null");
Integer sqlType = (Integer) this.sqlTypes.get(paramName);
Integer sqlType = this.sqlTypes.get(paramName);
if (sqlType != null) {
return sqlType.intValue();
return sqlType;
}
return TYPE_UNKNOWN;
}
@@ -78,7 +78,7 @@ public abstract class AbstractSqlParameterSource implements SqlParameterSource {
*/
public String getTypeName(String paramName) {
Assert.notNull(paramName, "Parameter name must not be null");
return (String) this.typeNames.get(paramName);
return this.typeNames.get(paramName);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2005 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.
@@ -51,10 +51,11 @@ import org.springframework.jdbc.support.lob.LobHandler;
* @since 1.0.2
* @see org.springframework.jdbc.support.lob.LobCreator
*/
public abstract class AbstractLobCreatingPreparedStatementCallback implements PreparedStatementCallback {
public abstract class AbstractLobCreatingPreparedStatementCallback implements PreparedStatementCallback<Integer> {
private final LobHandler lobHandler;
/**
* Create a new AbstractLobCreatingPreparedStatementCallback for the
* given LobHandler.
@@ -64,11 +65,12 @@ public abstract class AbstractLobCreatingPreparedStatementCallback implements Pr
this.lobHandler = lobHandler;
}
public final Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
public final Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
LobCreator lobCreator = this.lobHandler.getLobCreator();
try {
setValues(ps, lobCreator);
return new Integer(ps.executeUpdate());
return ps.executeUpdate();
}
finally {
lobCreator.close();

View File

@@ -170,7 +170,7 @@ public abstract class DataSourceUtils {
logger.debug("Changing isolation level of JDBC Connection [" + con + "] to " +
definition.getIsolationLevel());
}
previousIsolationLevel = new Integer(con.getTransactionIsolation());
previousIsolationLevel = con.getTransactionIsolation();
con.setTransactionIsolation(definition.getIsolationLevel());
}

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.
@@ -101,11 +101,10 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd
* @see org.springframework.transaction.support.TransactionSynchronizationManager#getCurrentTransactionIsolationLevel()
*/
public void setIsolationLevel(int isolationLevel) {
if (!constants.getValues(DefaultTransactionDefinition.PREFIX_ISOLATION).contains(new Integer(isolationLevel))) {
if (!constants.getValues(DefaultTransactionDefinition.PREFIX_ISOLATION).contains(isolationLevel)) {
throw new IllegalArgumentException("Only values of isolation constants allowed");
}
this.isolationLevel =
(isolationLevel != TransactionDefinition.ISOLATION_DEFAULT ? new Integer(isolationLevel) : null);
this.isolationLevel = (isolationLevel != TransactionDefinition.ISOLATION_DEFAULT ? isolationLevel : null);
}
/**
@@ -128,11 +127,11 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd
Connection con = super.doGetConnection(username, password);
Boolean readOnlyToUse = getCurrentReadOnlyFlag();
if (readOnlyToUse != null) {
con.setReadOnly(readOnlyToUse.booleanValue());
con.setReadOnly(readOnlyToUse);
}
Integer isolationLevelToUse = getCurrentIsolationLevel();
if (isolationLevelToUse != null) {
con.setTransactionIsolation(isolationLevelToUse.intValue());
con.setTransactionIsolation(isolationLevelToUse);
}
return con;
}

View File

@@ -118,7 +118,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
* @see java.sql.Connection#setAutoCommit
*/
public void setDefaultAutoCommit(boolean defaultAutoCommit) {
this.defaultAutoCommit = new Boolean(defaultAutoCommit);
this.defaultAutoCommit = defaultAutoCommit;
}
/**
@@ -135,7 +135,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
* @see java.sql.Connection#setTransactionIsolation
*/
public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
this.defaultTransactionIsolation = new Integer(defaultTransactionIsolation);
this.defaultTransactionIsolation = defaultTransactionIsolation;
}
/**
@@ -187,10 +187,10 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
*/
protected synchronized void checkDefaultConnectionProperties(Connection con) throws SQLException {
if (this.defaultAutoCommit == null) {
this.defaultAutoCommit = new Boolean(con.getAutoCommit());
this.defaultAutoCommit = con.getAutoCommit();
}
if (this.defaultTransactionIsolation == null) {
this.defaultTransactionIsolation = new Integer(con.getTransactionIsolation());
this.defaultTransactionIsolation = con.getTransactionIsolation();
}
}
@@ -281,13 +281,13 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
if (method.getName().equals("equals")) {
// We must avoid fetching a target Connection for "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")) {
// We must avoid fetching a target Connection for "hashCode",
// and we must return the same hash code even when the target
// Connection has been fetched: use hashCode of Connection proxy.
return new Integer(System.identityHashCode(proxy));
return System.identityHashCode(proxy);
}
else if (method.getName().equals("getTargetConnection")) {
// Handle getTargetConnection method: return underlying connection.
@@ -346,7 +346,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
return null;
}
else if (method.getName().equals("isClosed")) {
return (this.closed ? Boolean.TRUE : Boolean.FALSE);
return (this.closed);
}
else if (method.getName().equals("close")) {
// Ignore: no target connection yet.
@@ -397,15 +397,15 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
checkDefaultConnectionProperties(this.target);
// Apply kept transaction settings, if any.
if (this.readOnly.booleanValue()) {
this.target.setReadOnly(this.readOnly.booleanValue());
if (this.readOnly) {
this.target.setReadOnly(this.readOnly);
}
if (this.transactionIsolation != null &&
!this.transactionIsolation.equals(defaultTransactionIsolation())) {
this.target.setTransactionIsolation(this.transactionIsolation.intValue());
this.target.setTransactionIsolation(this.transactionIsolation);
}
if (this.autoCommit != null && this.autoCommit.booleanValue() != this.target.getAutoCommit()) {
this.target.setAutoCommit(this.autoCommit.booleanValue());
if (this.autoCommit != null && this.autoCommit != this.target.getAutoCommit()) {
this.target.setAutoCommit(this.autoCommit);
}
}

View File

@@ -166,7 +166,7 @@ public class SingleConnectionDataSource extends DriverManagerDataSource
* Set whether the returned Connection's "autoCommit" setting should be overridden.
*/
public void setAutoCommit(boolean autoCommit) {
this.autoCommit = (autoCommit ? Boolean.TRUE : Boolean.FALSE);
this.autoCommit = (autoCommit);
}
/**
@@ -270,8 +270,8 @@ public class SingleConnectionDataSource extends DriverManagerDataSource
*/
protected void prepareConnection(Connection con) throws SQLException {
Boolean autoCommit = getAutoCommitValue();
if (autoCommit != null && con.getAutoCommit() != autoCommit.booleanValue()) {
con.setAutoCommit(autoCommit.booleanValue());
if (autoCommit != null && con.getAutoCommit() != autoCommit) {
con.setAutoCommit(autoCommit);
}
}
@@ -319,11 +319,11 @@ public class SingleConnectionDataSource extends DriverManagerDataSource
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 Connection proxy.
return new Integer(System.identityHashCode(proxy));
return System.identityHashCode(proxy);
}
else if (method.getName().equals("close")) {
// Handle close method: don't pass the call on.

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.
@@ -180,11 +180,11 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
if (method.getName().equals("equals")) {
// Only considered as 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 Connection proxy.
return new Integer(System.identityHashCode(proxy));
return System.identityHashCode(proxy);
}
else if (method.getName().equals("toString")) {
// Allow for differentiating between the proxy and the raw Connection.

View File

@@ -158,7 +158,7 @@ public class BatchSqlUpdate extends SqlUpdate {
* @see #flush
*/
@Override
public int update(Object[] params) throws DataAccessException {
public int update(Object... params) throws DataAccessException {
validateParameters(params);
this.parameterQueue.add(params.clone());

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2002-2005 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.
* 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.
@@ -19,7 +19,6 @@ package org.springframework.jdbc.object;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import javax.sql.DataSource;
/**
@@ -36,7 +35,7 @@ import javax.sql.DataSource;
* @author Jean-Pierre Pawlak
* @see MappingSqlQueryWithParameters
*/
public abstract class MappingSqlQuery extends MappingSqlQueryWithParameters {
public abstract class MappingSqlQuery<T> extends MappingSqlQueryWithParameters<T> {
/**
* Constructor that allows use as a JavaBean.
@@ -53,13 +52,14 @@ public abstract class MappingSqlQuery extends MappingSqlQueryWithParameters {
super(ds, sql);
}
/**
* This method is implemented to invoke the simpler mapRow
* template method, ignoring parameters.
* @see #mapRow(ResultSet, int)
*/
@Override
protected final Object mapRow(ResultSet rs, int rowNum, Object[] parameters, Map context)
protected final T mapRow(ResultSet rs, int rowNum, Object[] parameters, Map context)
throws SQLException {
return mapRow(rs, rowNum);
@@ -78,6 +78,6 @@ public abstract class MappingSqlQuery extends MappingSqlQueryWithParameters {
* Subclasses can simply not catch SQLExceptions, relying on the
* framework to clean up.
*/
protected abstract Object mapRow(ResultSet rs, int rowNum) throws SQLException;
protected abstract T mapRow(ResultSet rs, int rowNum) throws SQLException;
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2002-2005 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.
* 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.
@@ -19,7 +19,6 @@ package org.springframework.jdbc.object;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.jdbc.core.RowMapper;
@@ -48,7 +47,7 @@ import org.springframework.jdbc.core.RowMapper;
* @see org.springframework.jdbc.object.MappingSqlQuery
* @see org.springframework.jdbc.object.SqlQuery
*/
public abstract class MappingSqlQueryWithParameters extends SqlQuery {
public abstract class MappingSqlQueryWithParameters<T> extends SqlQuery<T> {
/**
* Constructor to allow use as a JavaBean
@@ -71,7 +70,7 @@ public abstract class MappingSqlQueryWithParameters extends SqlQuery {
* implementation of the mapRow() method.
*/
@Override
protected RowMapper newRowMapper(Object[] parameters, Map context) {
protected RowMapper<T> newRowMapper(Object[] parameters, Map context) {
return new RowMapperImpl(parameters, context);
}
@@ -90,7 +89,7 @@ public abstract class MappingSqlQueryWithParameters extends SqlQuery {
* Subclasses can simply not catch SQLExceptions, relying on the
* framework to clean up.
*/
protected abstract Object mapRow(ResultSet rs, int rowNum, Object[] parameters, Map context)
protected abstract T mapRow(ResultSet rs, int rowNum, Object[] parameters, Map context)
throws SQLException;
@@ -98,7 +97,7 @@ public abstract class MappingSqlQueryWithParameters extends SqlQuery {
* Implementation of RowMapper that calls the enclosing
* class's <code>mapRow</code> method for each row.
*/
protected class RowMapperImpl implements RowMapper {
protected class RowMapperImpl implements RowMapper<T> {
private final Object[] params;
@@ -112,7 +111,7 @@ public abstract class MappingSqlQueryWithParameters extends SqlQuery {
this.context = context;
}
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
return MappingSqlQueryWithParameters.this.mapRow(rs, rowNum, this.params, this.context);
}
}

View File

@@ -305,7 +305,7 @@ public abstract class RdbmsOperation implements InitializingBean {
/**
* Return a list of the declared {@link SqlParameter} objects.
*/
protected List getDeclaredParameters() {
protected List<SqlParameter> getDeclaredParameters() {
return this.declaredParameters;
}
@@ -398,7 +398,7 @@ public abstract class RdbmsOperation implements InitializingBean {
* @param parameters parameter Map supplied. May be <code>null</code>.
* @throws InvalidDataAccessApiUsageException if the parameters are invalid
*/
protected void validateNamedParameters(Map<String, Object> parameters) throws InvalidDataAccessApiUsageException {
protected void validateNamedParameters(Map<String, ?> parameters) throws InvalidDataAccessApiUsageException {
checkCompiled();
Map paramsToUse = (parameters != null ? parameters : Collections.emptyMap());
int declaredInParameters = 0;

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.
@@ -18,14 +18,12 @@ package org.springframework.jdbc.object;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.jdbc.core.CallableStatementCreator;
import org.springframework.jdbc.core.CallableStatementCreatorFactory;
import org.springframework.jdbc.core.ParameterMapper;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.SqlReturnResultSet;
/**
* RdbmsOperation using a JdbcTemplate and representing a SQL-based
@@ -130,7 +128,7 @@ public abstract class SqlCall extends RdbmsOperation {
this.callString = getSql();
}
else {
List parameters = getDeclaredParameters();
List<SqlParameter> parameters = getDeclaredParameters();
int parameterCount = 0;
if (isFunction()) {
this.callString = "{? = call " + getSql() + "(";
@@ -139,8 +137,7 @@ public abstract class SqlCall extends RdbmsOperation {
else {
this.callString = "{call " + getSql() + "(";
}
for (int i = 0; i < parameters.size(); i++) {
SqlParameter parameter = (SqlParameter) parameters.get(i);
for (SqlParameter parameter : parameters) {
if (!(parameter.isResultsParameter())) {
if (parameterCount > 0) {
this.callString += ", ";
@@ -184,7 +181,7 @@ public abstract class SqlCall extends RdbmsOperation {
* with this parameters.
* @param inParams parameters. May be <code>null</code>.
*/
protected CallableStatementCreator newCallableStatementCreator(Map inParams) {
protected CallableStatementCreator newCallableStatementCreator(Map<String, ?> inParams) {
return this.callableStatementFactory.newCallableStatementCreator(inParams);
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2002-2005 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.
* 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.
@@ -18,13 +18,10 @@ package org.springframework.jdbc.object;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import javax.sql.DataSource;
import org.springframework.dao.TypeMismatchDataAccessException;
import org.springframework.jdbc.core.SingleColumnRowMapper;
import org.springframework.jdbc.support.JdbcUtils;
/**
* SQL "function" wrapper for a query that returns a single row of results.
@@ -50,9 +47,9 @@ import org.springframework.jdbc.support.JdbcUtils;
* @author Jean-Pierre Pawlak
* @see org.springframework.jdbc.object.StoredProcedure
*/
public class SqlFunction extends MappingSqlQuery {
public class SqlFunction<T> extends MappingSqlQuery<T> {
private final SingleColumnRowMapper rowMapper = new SingleColumnRowMapper();
private final SingleColumnRowMapper<T> rowMapper = new SingleColumnRowMapper<T>();
/**
@@ -104,7 +101,7 @@ public class SqlFunction extends MappingSqlQuery {
* @see #setResultType(Class)
* @see java.sql.Types
*/
public SqlFunction(DataSource ds, String sql, int[] types, Class resultType) {
public SqlFunction(DataSource ds, String sql, int[] types, Class<T> resultType) {
setRowsExpected(1);
setDataSource(ds);
setSql(sql);
@@ -118,7 +115,7 @@ public class SqlFunction extends MappingSqlQuery {
* <p>If not specified, the result value will be exposed as
* returned by the JDBC driver.
*/
public void setResultType(Class resultType) {
public void setResultType(Class<T> resultType) {
this.rowMapper.setRequiredType(resultType);
}
@@ -129,7 +126,7 @@ public class SqlFunction extends MappingSqlQuery {
* of rows returned, this is treated as an error.
*/
@Override
protected Object mapRow(ResultSet rs, int rowNum) throws SQLException {
protected T mapRow(ResultSet rs, int rowNum) throws SQLException {
return this.rowMapper.mapRow(rs, rowNum);
}
@@ -139,7 +136,7 @@ public class SqlFunction extends MappingSqlQuery {
* @return the value of the function
*/
public int run() {
return run(null);
return run(new Object[0]);
}
/**
@@ -148,7 +145,7 @@ public class SqlFunction extends MappingSqlQuery {
* @return the value of the function
*/
public int run(int parameter) {
return run(new Object[] {new Integer(parameter)});
return run(new Object[] {parameter});
}
/**
@@ -158,7 +155,7 @@ public class SqlFunction extends MappingSqlQuery {
* object wrapper types for primitives.
* @return the value of the function
*/
public int run(Object[] parameters) {
public int run(Object... parameters) {
Object obj = super.findObject(parameters);
if (!(obj instanceof Number)) {
throw new TypeMismatchDataAccessException("Couldn't convert result object [" + obj + "] to int");

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.
@@ -52,7 +52,7 @@ import org.springframework.jdbc.core.namedparam.ParsedSql;
* @author Thomas Risberg
* @see SqlUpdate
*/
public abstract class SqlQuery extends SqlOperation {
public abstract class SqlQuery<T> extends SqlOperation {
/** The number of rows to expect; if 0, unknown. */
private int rowsExpected = 0;
@@ -106,9 +106,9 @@ public abstract class SqlQuery extends SqlOperation {
* @return a List of objects, one per row of the ResultSet. Normally all these
* will be of the same class, although it is possible to use different types.
*/
public List execute(Object[] params, Map context) throws DataAccessException {
public List<T> execute(Object[] params, Map context) throws DataAccessException {
validateParameters(params);
RowMapper rowMapper = newRowMapper(params, context);
RowMapper<T> rowMapper = newRowMapper(params, context);
return getJdbcTemplate().query(newPreparedStatementCreator(params), rowMapper);
}
@@ -118,7 +118,7 @@ public abstract class SqlQuery extends SqlOperation {
* be represented by their Object wrapper type. The ordering of parameters is
* significant.
*/
public List execute(Object[] params) throws DataAccessException {
public List<T> execute(Object... params) throws DataAccessException {
return execute(params, null);
}
@@ -126,14 +126,14 @@ public abstract class SqlQuery extends SqlOperation {
* Convenient method to execute without parameters.
* @param context the contextual information for object creation
*/
public List execute(Map context) throws DataAccessException {
public List<T> execute(Map context) throws DataAccessException {
return execute((Object[]) null, context);
}
/**
* Convenient method to execute without parameters nor context.
*/
public List execute() throws DataAccessException {
public List<T> execute() throws DataAccessException {
return execute((Object[]) null);
}
@@ -142,15 +142,15 @@ public abstract class SqlQuery extends SqlOperation {
* @param p1 single int parameter
* @param context the contextual information for object creation
*/
public List execute(int p1, Map context) throws DataAccessException {
return execute(new Object[] {new Integer(p1)}, context);
public List<T> execute(int p1, Map context) throws DataAccessException {
return execute(new Object[] {p1}, context);
}
/**
* Convenient method to execute with a single int parameter.
* @param p1 single int parameter
*/
public List execute(int p1) throws DataAccessException {
public List<T> execute(int p1) throws DataAccessException {
return execute(p1, null);
}
@@ -160,8 +160,8 @@ public abstract class SqlQuery extends SqlOperation {
* @param p2 second int parameter
* @param context the contextual information for object creation
*/
public List execute(int p1, int p2, Map context) throws DataAccessException {
return execute(new Object[] {new Integer(p1), new Integer(p2)}, context);
public List<T> execute(int p1, int p2, Map context) throws DataAccessException {
return execute(new Object[] {p1, p2}, context);
}
/**
@@ -169,7 +169,7 @@ public abstract class SqlQuery extends SqlOperation {
* @param p1 first int parameter
* @param p2 second int parameter
*/
public List execute(int p1, int p2) throws DataAccessException {
public List<T> execute(int p1, int p2) throws DataAccessException {
return execute(p1, p2, null);
}
@@ -178,15 +178,15 @@ public abstract class SqlQuery extends SqlOperation {
* @param p1 single long parameter
* @param context the contextual information for object creation
*/
public List execute(long p1, Map context) throws DataAccessException {
return execute(new Object[] {new Long(p1)}, context);
public List<T> execute(long p1, Map context) throws DataAccessException {
return execute(new Object[] {p1}, context);
}
/**
* Convenient method to execute with a single long parameter.
* @param p1 single long parameter
*/
public List execute(long p1) throws DataAccessException {
public List<T> execute(long p1) throws DataAccessException {
return execute(p1, null);
}
@@ -195,7 +195,7 @@ public abstract class SqlQuery extends SqlOperation {
* @param p1 single String parameter
* @param context the contextual information for object creation
*/
public List execute(String p1, Map context) throws DataAccessException {
public List<T> execute(String p1, Map context) throws DataAccessException {
return execute(new Object[] {p1}, context);
}
@@ -203,7 +203,7 @@ public abstract class SqlQuery extends SqlOperation {
* Convenient method to execute with a single String parameter.
* @param p1 single String parameter
*/
public List execute(String p1) throws DataAccessException {
public List<T> execute(String p1) throws DataAccessException {
return execute(p1, null);
}
@@ -219,13 +219,13 @@ public abstract class SqlQuery extends SqlOperation {
* @return a List of objects, one per row of the ResultSet. Normally all these
* will be of the same class, although it is possible to use different types.
*/
public List executeByNamedParam(Map paramMap, Map context) throws DataAccessException {
public List<T> executeByNamedParam(Map<String, ?> paramMap, Map context) throws DataAccessException {
validateNamedParameters(paramMap);
ParsedSql parsedSql = getParsedSql();
MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
RowMapper rowMapper = newRowMapper(params, context);
RowMapper<T> rowMapper = newRowMapper(params, context);
return getJdbcTemplate().query(newPreparedStatementCreator(sqlToUse, params), rowMapper);
}
@@ -235,7 +235,7 @@ public abstract class SqlQuery extends SqlOperation {
* the SqlParameters. Primitive parameters must be represented by their Object wrapper
* type. The ordering of parameters is not significant.
*/
public List executeByNamedParam(Map paramMap) throws DataAccessException {
public List<T> executeByNamedParam(Map<String, ?> paramMap) throws DataAccessException {
return executeByNamedParam(paramMap, null);
}
@@ -248,15 +248,15 @@ public abstract class SqlQuery extends SqlOperation {
* choose to treat this as an error and throw an exception.
* @see org.springframework.dao.support.DataAccessUtils#singleResult
*/
public Object findObject(Object[] params, Map context) throws DataAccessException {
List results = execute(params, context);
public T findObject(Object[] params, Map context) throws DataAccessException {
List<T> results = execute(params, context);
return DataAccessUtils.singleResult(results);
}
/**
* Convenient method to find a single object without context.
*/
public Object findObject(Object[] params) throws DataAccessException {
public T findObject(Object... params) throws DataAccessException {
return findObject(params, null);
}
@@ -264,14 +264,14 @@ public abstract class SqlQuery extends SqlOperation {
* Convenient method to find a single object given a single int parameter
* and a context.
*/
public Object findObject(int p1, Map context) throws DataAccessException {
return findObject(new Object[] {new Integer(p1)}, context);
public T findObject(int p1, Map context) throws DataAccessException {
return findObject(new Object[] {p1}, context);
}
/**
* Convenient method to find a single object given a single int parameter.
*/
public Object findObject(int p1) throws DataAccessException {
public T findObject(int p1) throws DataAccessException {
return findObject(p1, null);
}
@@ -279,14 +279,14 @@ public abstract class SqlQuery extends SqlOperation {
* Convenient method to find a single object given two int parameters
* and a context.
*/
public Object findObject(int p1, int p2, Map context) throws DataAccessException {
return findObject(new Object[] {new Integer(p1), new Integer(p2)}, context);
public T findObject(int p1, int p2, Map context) throws DataAccessException {
return findObject(new Object[] {p1, p2}, context);
}
/**
* Convenient method to find a single object given two int parameters.
*/
public Object findObject(int p1, int p2) throws DataAccessException {
public T findObject(int p1, int p2) throws DataAccessException {
return findObject(p1, p2, null);
}
@@ -294,14 +294,14 @@ public abstract class SqlQuery extends SqlOperation {
* Convenient method to find a single object given a single long parameter
* and a context.
*/
public Object findObject(long p1, Map context) throws DataAccessException {
return findObject(new Object[] {new Long(p1)}, context);
public T findObject(long p1, Map context) throws DataAccessException {
return findObject(new Object[] {p1}, context);
}
/**
* Convenient method to find a single object given a single long parameter.
*/
public Object findObject(long p1) throws DataAccessException {
public T findObject(long p1) throws DataAccessException {
return findObject(p1, null);
}
@@ -309,14 +309,14 @@ public abstract class SqlQuery extends SqlOperation {
* Convenient method to find a single object given a single String parameter
* and a context.
*/
public Object findObject(String p1, Map context) throws DataAccessException {
public T findObject(String p1, Map context) throws DataAccessException {
return findObject(new Object[] {p1}, context);
}
/**
* Convenient method to find a single object given a single String parameter.
*/
public Object findObject(String p1) throws DataAccessException {
public T findObject(String p1) throws DataAccessException {
return findObject(p1, null);
}
@@ -331,8 +331,8 @@ public abstract class SqlQuery extends SqlOperation {
* @return a List of objects, one per row of the ResultSet. Normally all these
* will be of the same class, although it is possible to use different types.
*/
public Object findObjectByNamedParam(Map paramMap, Map context) throws DataAccessException {
List results = executeByNamedParam(paramMap, context);
public T findObjectByNamedParam(Map<String, ?> paramMap, Map context) throws DataAccessException {
List<T> results = executeByNamedParam(paramMap, context);
return DataAccessUtils.singleResult(results);
}
@@ -342,7 +342,7 @@ public abstract class SqlQuery extends SqlOperation {
* matching named parameters specified in the SQL statement.
* Ordering is not significant.
*/
public Object findObjectByNamedParam(Map paramMap) throws DataAccessException {
public T findObjectByNamedParam(Map<String, ?> paramMap) throws DataAccessException {
return findObjectByNamedParam(paramMap, null);
}
@@ -358,6 +358,6 @@ public abstract class SqlQuery extends SqlOperation {
* but it can be useful for creating the objects of the result list.
* @see #execute
*/
protected abstract RowMapper newRowMapper(Object[] parameters, Map context);
protected abstract RowMapper<T> newRowMapper(Object[] parameters, Map context);
}

View File

@@ -163,7 +163,7 @@ public class SqlUpdate extends SqlOperation {
* @param params array of parameters objects
* @return the number of rows affected by the update
*/
public int update(Object[] params) throws DataAccessException {
public int update(Object... params) throws DataAccessException {
validateParameters(params);
int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(params));
checkRowsAffected(rowsAffected);
@@ -195,28 +195,28 @@ public class SqlUpdate extends SqlOperation {
* Convenient method to execute an update given one int arg.
*/
public int update(int p1) throws DataAccessException {
return update(new Object[] {new Integer(p1)});
return update(new Object[] {p1});
}
/**
* Convenient method to execute an update given two int args.
*/
public int update(int p1, int p2) throws DataAccessException {
return update(new Object[] {new Integer(p1), new Integer(p2)});
return update(new Object[] {p1, p2});
}
/**
* Convenient method to execute an update given one long arg.
*/
public int update(long p1) throws DataAccessException {
return update(new Object[] {new Long(p1)});
return update(new Object[] {p1});
}
/**
* Convenient method to execute an update given two long args.
*/
public int update(long p1, long p2) throws DataAccessException {
return update(new Object[] {new Long(p1), new Long(p2)});
return update(new Object[] {p1, p2});
}
/**

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2002-2005 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.
* 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.
@@ -35,7 +35,7 @@ import org.springframework.jdbc.core.RowMapper;
* @author Thomas Risberg
* @see org.springframework.jdbc.object.SqlQuery
*/
public abstract class UpdatableSqlQuery extends SqlQuery {
public abstract class UpdatableSqlQuery<T> extends SqlQuery<T> {
/**
* Constructor to allow use as a JavaBean
@@ -54,12 +54,13 @@ public abstract class UpdatableSqlQuery extends SqlQuery {
setUpdatableResults(true);
}
/**
* Implementation of the superclass template method. This invokes the subclass's
* implementation of the <code>updateRow()</code> method.
*/
@Override
protected RowMapper newRowMapper(Object[] parameters, Map context) {
protected RowMapper<T> newRowMapper(Object[] parameters, Map context) {
return new RowMapperImpl(context);
}
@@ -78,14 +79,14 @@ public abstract class UpdatableSqlQuery extends SqlQuery {
* Subclasses can simply not catch SQLExceptions, relying on the
* framework to clean up.
*/
protected abstract Object updateRow(ResultSet rs, int rowNum, Map context) throws SQLException;
protected abstract T updateRow(ResultSet rs, int rowNum, Map context) throws SQLException;
/**
* Implementation of RowMapper that calls the enclosing
* class's <code>updateRow()</code> method for each row.
*/
protected class RowMapperImpl implements RowMapper {
protected class RowMapperImpl implements RowMapper<T> {
private final Map context;
@@ -93,8 +94,8 @@ public abstract class UpdatableSqlQuery extends SqlQuery {
this.context = context;
}
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
Object result = updateRow(rs, rowNum, this.context);
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
T result = updateRow(rs, rowNum, this.context);
rs.updateRow();
return result;
}

View File

@@ -142,32 +142,32 @@ public abstract class JdbcUtils {
value = rs.getString(index);
}
else if (boolean.class.equals(requiredType) || Boolean.class.equals(requiredType)) {
value = Boolean.valueOf(rs.getBoolean(index));
value = rs.getBoolean(index);
wasNullCheck = true;
}
else if (byte.class.equals(requiredType) || Byte.class.equals(requiredType)) {
value = new Byte(rs.getByte(index));
value = rs.getByte(index);
wasNullCheck = true;
}
else if (short.class.equals(requiredType) || Short.class.equals(requiredType)) {
value = new Short(rs.getShort(index));
value = rs.getShort(index);
wasNullCheck = true;
}
else if (int.class.equals(requiredType) || Integer.class.equals(requiredType)) {
value = new Integer(rs.getInt(index));
value = rs.getInt(index);
wasNullCheck = true;
}
else if (long.class.equals(requiredType) || Long.class.equals(requiredType)) {
value = new Long(rs.getLong(index));
value = rs.getLong(index);
wasNullCheck = true;
}
else if (float.class.equals(requiredType) || Float.class.equals(requiredType)) {
value = new Float(rs.getFloat(index));
value = rs.getFloat(index);
wasNullCheck = true;
}
else if (double.class.equals(requiredType) || Double.class.equals(requiredType) ||
Number.class.equals(requiredType)) {
value = new Double(rs.getDouble(index));
value = rs.getDouble(index);
wasNullCheck = true;
}
else if (byte[].class.equals(requiredType)) {

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.
@@ -96,9 +96,9 @@ public class OracleLobHandler extends AbstractLobHandler {
private Class clobClass;
private final Map durationSessionConstants = new HashMap(2);
private final Map<Class, Integer> durationSessionConstants = new HashMap<Class, Integer>(2);
private final Map modeReadWriteConstants = new HashMap(2);
private final Map<Class, Integer> modeReadWriteConstants = new HashMap<Class, Integer>(2);
/**
@@ -128,7 +128,7 @@ public class OracleLobHandler extends AbstractLobHandler {
* @see oracle.sql.CLOB#createTemporary
*/
public void setCache(boolean cache) {
this.cache = new Boolean(cache);
this.cache = cache;
}
@@ -149,16 +149,16 @@ public class OracleLobHandler extends AbstractLobHandler {
// Initialize oracle.sql.BLOB class
this.blobClass = con.getClass().getClassLoader().loadClass(BLOB_CLASS_NAME);
this.durationSessionConstants.put(
this.blobClass, new Integer(this.blobClass.getField(DURATION_SESSION_FIELD_NAME).getInt(null)));
this.blobClass, this.blobClass.getField(DURATION_SESSION_FIELD_NAME).getInt(null));
this.modeReadWriteConstants.put(
this.blobClass, new Integer(this.blobClass.getField(MODE_READWRITE_FIELD_NAME).getInt(null)));
this.blobClass, this.blobClass.getField(MODE_READWRITE_FIELD_NAME).getInt(null));
// Initialize oracle.sql.CLOB class
this.clobClass = con.getClass().getClassLoader().loadClass(CLOB_CLASS_NAME);
this.durationSessionConstants.put(
this.clobClass, new Integer(this.clobClass.getField(DURATION_SESSION_FIELD_NAME).getInt(null)));
this.clobClass, this.clobClass.getField(DURATION_SESSION_FIELD_NAME).getInt(null));
this.modeReadWriteConstants.put(
this.clobClass, new Integer(this.clobClass.getField(MODE_READWRITE_FIELD_NAME).getInt(null)));
this.clobClass, this.clobClass.getField(MODE_READWRITE_FIELD_NAME).getInt(null));
}
catch (Exception ex) {
throw new InvalidDataAccessApiUsageException(
@@ -219,8 +219,8 @@ public class OracleLobHandler extends AbstractLobHandler {
if (content != null) {
Blob blob = (Blob) createLob(ps, false, new LobCallback() {
public void populateLob(Object lob) throws Exception {
Method methodToInvoke = lob.getClass().getMethod("getBinaryOutputStream", new Class[0]);
OutputStream out = (OutputStream) methodToInvoke.invoke(lob, (Object[]) null);
Method methodToInvoke = lob.getClass().getMethod("getBinaryOutputStream");
OutputStream out = (OutputStream) methodToInvoke.invoke(lob);
FileCopyUtils.copy(content, out);
}
});
@@ -389,11 +389,10 @@ public class OracleLobHandler extends AbstractLobHandler {
return blob;
*/
Method createTemporary = lobClass.getMethod(
"createTemporary", new Class[] {Connection.class, boolean.class, int.class});
Object lob = createTemporary.invoke(
null, new Object[] {con, cache, durationSessionConstants.get(lobClass)});
Method open = lobClass.getMethod("open", new Class[] {int.class});
open.invoke(lob, new Object[] {modeReadWriteConstants.get(lobClass)});
"createTemporary", Connection.class, boolean.class, int.class);
Object lob = createTemporary.invoke(null, con, cache, durationSessionConstants.get(lobClass));
Method open = lobClass.getMethod("open", int.class);
open.invoke(lob, modeReadWriteConstants.get(lobClass));
return lob;
}
@@ -408,8 +407,8 @@ public class OracleLobHandler extends AbstractLobHandler {
blob.freeTemporary();
*/
Object lob = it.next();
Method freeTemporary = lob.getClass().getMethod("freeTemporary", new Class[0]);
freeTemporary.invoke(lob, new Object[0]);
Method freeTemporary = lob.getClass().getMethod("freeTemporary");
freeTemporary.invoke(lob);
it.remove();
}
}