Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-27 00:27:52 +00:00
parent 6bbc966a21
commit b0790bf5e7
248 changed files with 2374 additions and 3208 deletions

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.
@@ -44,7 +44,7 @@ public abstract class DataAccessUtils {
* @throws IncorrectResultSizeDataAccessException if more than one
* element has been found in the given Collection
*/
public static Object singleResult(Collection results) throws IncorrectResultSizeDataAccessException {
public static <T> T singleResult(Collection<T> results) throws IncorrectResultSizeDataAccessException {
int size = (results != null ? results.size() : 0);
if (size == 0) {
return null;
@@ -65,7 +65,7 @@ public abstract class DataAccessUtils {
* @throws EmptyResultDataAccessException if no element at all
* has been found in the given Collection
*/
public static Object requiredSingleResult(Collection results) throws IncorrectResultSizeDataAccessException {
public static <T> T requiredSingleResult(Collection<T> results) throws IncorrectResultSizeDataAccessException {
int size = (results != null ? results.size() : 0);
if (size == 0) {
throw new EmptyResultDataAccessException(1);
@@ -86,7 +86,7 @@ public abstract class DataAccessUtils {
* result object has been found in the given Collection
* @see org.springframework.util.CollectionUtils#hasUniqueObject
*/
public static Object uniqueResult(Collection results) throws IncorrectResultSizeDataAccessException {
public static <T> T uniqueResult(Collection<T> results) throws IncorrectResultSizeDataAccessException {
int size = (results != null ? results.size() : 0);
if (size == 0) {
return null;
@@ -108,7 +108,7 @@ public abstract class DataAccessUtils {
* has been found in the given Collection
* @see org.springframework.util.CollectionUtils#hasUniqueObject
*/
public static Object requiredUniqueResult(Collection results) throws IncorrectResultSizeDataAccessException {
public static <T> T requiredUniqueResult(Collection<T> results) throws IncorrectResultSizeDataAccessException {
int size = (results != null ? results.size() : 0);
if (size == 0) {
throw new EmptyResultDataAccessException(1);
@@ -133,7 +133,8 @@ public abstract class DataAccessUtils {
* @throws TypeMismatchDataAccessException if the unique object does
* not match the specified required type
*/
public static Object objectResult(Collection results, Class requiredType)
@SuppressWarnings("unchecked")
public static <T> T objectResult(Collection<?> results, Class<T> requiredType)
throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException {
Object result = requiredUniqueResult(results);
@@ -155,7 +156,7 @@ public abstract class DataAccessUtils {
"] and could not be converted to required type [" + requiredType.getName() + "]");
}
}
return result;
return (T) result;
}
/**
@@ -174,7 +175,7 @@ public abstract class DataAccessUtils {
public static int intResult(Collection results)
throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException {
return ((Number) objectResult(results, Number.class)).intValue();
return objectResult(results, Number.class).intValue();
}
/**
@@ -193,7 +194,7 @@ public abstract class DataAccessUtils {
public static long longResult(Collection results)
throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException {
return ((Number) objectResult(results, Number.class)).longValue();
return objectResult(results, Number.class).longValue();
}

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.
@@ -47,7 +47,7 @@ public interface CciOperations {
* @return the result object returned by the action, if any
* @throws DataAccessException if there is any problem
*/
Object execute(ConnectionCallback action) throws DataAccessException;
<T> T execute(ConnectionCallback<T> action) throws DataAccessException;
/**
* Execute a request on an EIS with CCI, implemented as callback action
@@ -62,7 +62,7 @@ public interface CciOperations {
* @return the result object returned by the action, if any
* @throws DataAccessException if there is any problem
*/
Object execute(InteractionCallback action) throws DataAccessException;
<T> T execute(InteractionCallback<T> action) throws DataAccessException;
/**
* Execute the specified interaction on an EIS with CCI.
@@ -103,7 +103,7 @@ public interface CciOperations {
* @return the output data extracted with the RecordExtractor object
* @throws DataAccessException if there is any problem
*/
Object execute(InteractionSpec spec, Record inputRecord, RecordExtractor outputExtractor)
<T> T execute(InteractionSpec spec, Record inputRecord, RecordExtractor<T> outputExtractor)
throws DataAccessException;
/**
@@ -115,7 +115,7 @@ public interface CciOperations {
* @return the output data extracted with the RecordExtractor object
* @throws DataAccessException if there is any problem
*/
Object execute(InteractionSpec spec, RecordCreator inputCreator, RecordExtractor outputExtractor)
<T> T execute(InteractionSpec spec, RecordCreator inputCreator, RecordExtractor<T> outputExtractor)
throws DataAccessException;
}

View File

@@ -17,7 +17,6 @@
package org.springframework.jca.cci.core;
import java.sql.SQLException;
import javax.resource.NotSupportedException;
import javax.resource.ResourceException;
import javax.resource.cci.Connection;
@@ -188,9 +187,8 @@ public class CciTemplate implements CciOperations {
}
public Object execute(ConnectionCallback action) throws DataAccessException {
public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
Assert.notNull(action, "Callback object must not be null");
Connection con = ConnectionFactoryUtils.getConnection(getConnectionFactory(), getConnectionSpec());
try {
return action.doInConnection(con, getConnectionFactory());
@@ -209,13 +207,11 @@ public class CciTemplate implements CciOperations {
}
}
public Object execute(final InteractionCallback action) throws DataAccessException {
public <T> T execute(final InteractionCallback<T> action) throws DataAccessException {
Assert.notNull(action, "Callback object must not be null");
return execute(new ConnectionCallback() {
public Object doInConnection(Connection connection, ConnectionFactory connectionFactory)
return execute(new ConnectionCallback<T>() {
public T doInConnection(Connection connection, ConnectionFactory connectionFactory)
throws ResourceException, SQLException, DataAccessException {
Interaction interaction = connection.createInteraction();
try {
return action.doInInteraction(interaction, connectionFactory);
@@ -228,7 +224,7 @@ public class CciTemplate implements CciOperations {
}
public Record execute(InteractionSpec spec, Record inputRecord) throws DataAccessException {
return (Record) doExecute(spec, inputRecord, null, null);
return doExecute(spec, inputRecord, null, new SimpleRecordExtractor());
}
public void execute(InteractionSpec spec, Record inputRecord, Record outputRecord) throws DataAccessException {
@@ -236,16 +232,16 @@ public class CciTemplate implements CciOperations {
}
public Record execute(InteractionSpec spec, RecordCreator inputCreator) throws DataAccessException {
return (Record) doExecute(spec, createRecord(inputCreator), null, null);
return doExecute(spec, createRecord(inputCreator), null, new SimpleRecordExtractor());
}
public Object execute(InteractionSpec spec, Record inputRecord, RecordExtractor outputExtractor)
public <T> T execute(InteractionSpec spec, Record inputRecord, RecordExtractor<T> outputExtractor)
throws DataAccessException {
return doExecute(spec, inputRecord, null, outputExtractor);
}
public Object execute(InteractionSpec spec, RecordCreator inputCreator, RecordExtractor outputExtractor)
public <T> T execute(InteractionSpec spec, RecordCreator inputCreator, RecordExtractor<T> outputExtractor)
throws DataAccessException {
return doExecute(spec, createRecord(inputCreator), null, outputExtractor);
@@ -262,14 +258,13 @@ public class CciTemplate implements CciOperations {
* @return the output data extracted with the RecordExtractor object
* @throws DataAccessException if there is any problem
*/
protected Object doExecute(
protected <T> T doExecute(
final InteractionSpec spec, final Record inputRecord, final Record outputRecord,
final RecordExtractor outputExtractor) throws DataAccessException {
final RecordExtractor<T> outputExtractor) throws DataAccessException {
return execute(new InteractionCallback() {
public Object doInInteraction(Interaction interaction, ConnectionFactory connectionFactory)
return execute(new InteractionCallback<T>() {
public T doInInteraction(Interaction interaction, ConnectionFactory connectionFactory)
throws ResourceException, SQLException, DataAccessException {
Record outputRecordToUse = outputRecord;
try {
if (outputRecord != null || getOutputRecordCreator() != null) {
@@ -283,12 +278,7 @@ public class CciTemplate implements CciOperations {
else {
outputRecordToUse = interaction.execute(spec, inputRecord);
}
if (outputExtractor != null) {
return outputExtractor.extractData(outputRecordToUse);
}
else {
return outputRecordToUse;
}
return (outputExtractor != null ? outputExtractor.extractData(outputRecordToUse) : null);
}
finally {
if (outputRecordToUse instanceof ResultSet) {
@@ -378,7 +368,7 @@ public class CciTemplate implements CciOperations {
*/
protected RecordFactory getRecordFactory(ConnectionFactory connectionFactory) throws ResourceException {
try {
return getConnectionFactory().getRecordFactory();
return connectionFactory.getRecordFactory();
}
catch (NotSupportedException ex) {
return new NotSupportedRecordFactory();
@@ -428,4 +418,12 @@ public class CciTemplate implements CciOperations {
}
}
private static class SimpleRecordExtractor implements RecordExtractor<Record> {
public Record extractData(Record record) {
return record;
}
}
}

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.
@@ -41,7 +41,7 @@ import org.springframework.dao.DataAccessException;
* @see CciTemplate#execute(javax.resource.cci.InteractionSpec, javax.resource.cci.Record)
* @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
*/
public interface ConnectionCallback {
public interface ConnectionCallback<T> {
/**
* Gets called by <code>CciTemplate.execute</code> with an active CCI Connection.
@@ -73,7 +73,7 @@ public interface ConnectionCallback {
* @see javax.resource.cci.ConnectionFactory#getMetaData()
* @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
*/
Object doInConnection(Connection connection, ConnectionFactory connectionFactory)
T doInConnection(Connection connection, ConnectionFactory connectionFactory)
throws ResourceException, SQLException, DataAccessException;
}

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.
@@ -42,7 +42,7 @@ import org.springframework.dao.DataAccessException;
* @see CciTemplate#execute(javax.resource.cci.InteractionSpec, javax.resource.cci.Record)
* @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
*/
public interface InteractionCallback {
public interface InteractionCallback<T> {
/**
* Gets called by <code>CciTemplate.execute</code> with an active CCI Interaction.
@@ -74,7 +74,7 @@ public interface InteractionCallback {
* @see javax.resource.cci.ConnectionFactory#getMetaData()
* @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
*/
Object doInInteraction(Interaction interaction, ConnectionFactory connectionFactory)
T doInInteraction(Interaction interaction, ConnectionFactory connectionFactory)
throws ResourceException, SQLException, DataAccessException;
}

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.
@@ -43,7 +43,7 @@ import org.springframework.dao.DataAccessException;
* @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
* @see javax.resource.cci.ResultSet
*/
public interface RecordExtractor {
public interface RecordExtractor<T> {
/**
* Process the data in the given Record, creating a corresponding result object.
@@ -58,6 +58,6 @@ public interface RecordExtractor {
* @throws DataAccessException in case of custom exceptions
* @see javax.resource.cci.ResultSet
*/
Object extractData(Record record) throws ResourceException, SQLException, DataAccessException;
T extractData(Record record) throws ResourceException, SQLException, DataAccessException;
}