BATCH-1915: Reformatting

This commit is contained in:
Michael Minella
2012-12-31 08:10:08 -06:00
parent a583c3a421
commit 96c818e86f
294 changed files with 3154 additions and 3034 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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,8 +18,8 @@ package org.springframework.batch.item;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.util.Assert;
@@ -28,13 +28,14 @@ import org.springframework.util.Assert;
* Object representing a context for an {@link ItemStream}. It is a thin wrapper
* for a map that allows optionally for type safety on reads. It also allows for
* dirty checking by setting a 'dirty' flag whenever any put is called.
*
*
* Note that putting <code>null</code> value is equivalent to removing the entry
* for the given key.
*
*
* @author Lucas Ward
* @author Douglas Kaminsky
*/
@SuppressWarnings("serial")
public class ExecutionContext implements Serializable {
private volatile boolean dirty = false;
@@ -51,7 +52,7 @@ public class ExecutionContext implements Serializable {
/**
* Initializes a new execution context with the contents of another map.
*
*
* @param map Initial contents of context.
*/
public ExecutionContext(Map<String, Object> map) {
@@ -73,7 +74,7 @@ public class ExecutionContext implements Serializable {
/**
* Adds a String value to the context.
*
*
* @param key Key to add to context
* @param value Value to associate with key
*/
@@ -85,7 +86,7 @@ public class ExecutionContext implements Serializable {
/**
* Adds a Long value to the context.
*
*
* @param key Key to add to context
* @param value Value to associate with key
*/
@@ -96,7 +97,7 @@ public class ExecutionContext implements Serializable {
/**
* Adds an Integer value to the context.
*
*
* @param key Key to add to context
* @param value Value to associate with key
*/
@@ -106,7 +107,7 @@ public class ExecutionContext implements Serializable {
/**
* Add a Double value to the context.
*
*
* @param key Key to add to context
* @param value Value to associate with key
*/
@@ -118,7 +119,7 @@ public class ExecutionContext implements Serializable {
/**
* Add an Object value to the context (must be Serializable). Putting
* <code>null</code> value for a given key removes the key.
*
*
* @param key Key to add to context
* @param value Value to associate with key
*/
@@ -138,7 +139,7 @@ public class ExecutionContext implements Serializable {
* Indicates if context has been changed with a "put" operation since the
* dirty flag was last cleared. Note that the last time the flag was cleared
* might correspond to creation of the context.
*
*
* @return True if "put" operation has occurred since flag was last cleared
*/
public boolean isDirty() {
@@ -147,7 +148,7 @@ public class ExecutionContext implements Serializable {
/**
* Typesafe Getter for the String represented by the provided key.
*
*
* @param key The key to get a value for
* @return The <code>String</code> value
*/
@@ -159,7 +160,7 @@ public class ExecutionContext implements Serializable {
/**
* Typesafe Getter for the String represented by the provided key with
* default value to return if key is not represented.
*
*
* @param key The key to get a value for
* @param defaultString Default to return if key is not represented
* @return The <code>String</code> value if key is repreesnted, specified
@@ -175,7 +176,7 @@ public class ExecutionContext implements Serializable {
/**
* Typesafe Getter for the Long represented by the provided key.
*
*
* @param key The key to get a value for
* @return The <code>Long</code> value
*/
@@ -187,7 +188,7 @@ public class ExecutionContext implements Serializable {
/**
* Typesafe Getter for the Long represented by the provided key with default
* value to return if key is not represented.
*
*
* @param key The key to get a value for
* @param defaultLong Default to return if key is not represented
* @return The <code>long</code> value if key is represented, specified
@@ -203,7 +204,7 @@ public class ExecutionContext implements Serializable {
/**
* Typesafe Getter for the Integer represented by the provided key.
*
*
* @param key The key to get a value for
* @return The <code>Integer</code> value
*/
@@ -215,7 +216,7 @@ public class ExecutionContext implements Serializable {
/**
* Typesafe Getter for the Integer represented by the provided key with
* default value to return if key is not represented.
*
*
* @param key The key to get a value for
* @param defaultInt Default to return if key is not represented
* @return The <code>int</code> value if key is represented, specified
@@ -231,7 +232,7 @@ public class ExecutionContext implements Serializable {
/**
* Typesafe Getter for the Double represented by the provided key.
*
*
* @param key The key to get a value for
* @return The <code>Double</code> value
*/
@@ -242,7 +243,7 @@ public class ExecutionContext implements Serializable {
/**
* Typesafe Getter for the Double represented by the provided key with
* default value to return if key is not represented.
*
*
* @param key The key to get a value for
* @param defaultDouble Default to return if key is not represented
* @return The <code>double</code> value if key is represented, specified
@@ -258,7 +259,7 @@ public class ExecutionContext implements Serializable {
/**
* Getter for the value represented by the provided key.
*
*
* @param key The key to get a value for
* @return The value represented by the given key
*/
@@ -269,7 +270,7 @@ public class ExecutionContext implements Serializable {
/**
* Utility method that attempts to take a value represented by a given key
* and validate it as a member of the specified type.
*
*
* @param key The key to validate a value for
* @param type Class against which value should be validated
* @return Value typed to the specified <code>Class</code>
@@ -288,7 +289,7 @@ public class ExecutionContext implements Serializable {
/**
* Indicates whether or not the context is empty.
*
*
* @return True if the context has no entries, false otherwise.
* @see java.util.Map#isEmpty()
*/
@@ -305,7 +306,7 @@ public class ExecutionContext implements Serializable {
/**
* Returns the entry set containing the contents of this context.
*
*
* @return A set representing the contents of the context
* @see java.util.Map#entrySet()
*/
@@ -315,7 +316,7 @@ public class ExecutionContext implements Serializable {
/**
* Indicates whether or not a key is represented in this context.
*
*
* @param key Key to check existence for
* @return True if key is represented in context, false otherwise
* @see java.util.Map#containsKey(Object)
@@ -326,7 +327,7 @@ public class ExecutionContext implements Serializable {
/**
* Removes the mapping for a key from this context if it is present.
*
*
* @see java.util.Map#remove(Object)
*/
public Object remove(String key) {
@@ -335,7 +336,7 @@ public class ExecutionContext implements Serializable {
/**
* Indicates whether or not a value is represented in this context.
*
*
* @param value Value to check existence for
* @return True if value is represented in context, false otherwise
* @see java.util.Map#containsValue(Object)
@@ -346,10 +347,10 @@ public class ExecutionContext implements Serializable {
/*
* (non-Javadoc)
*
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@Override
public boolean equals(Object obj) {
if (obj instanceof ExecutionContext == false) {
return false;
@@ -363,27 +364,27 @@ public class ExecutionContext implements Serializable {
/*
* (non-Javadoc)
*
*
* @see java.lang.Object#hashCode()
*/
@Override
@Override
public int hashCode() {
return map.hashCode();
}
/*
* (non-Javadoc)
*
*
* @see java.lang.Object#toString()
*/
@Override
@Override
public String toString() {
return map.toString();
}
/**
* Returns number of entries in the context
*
*
* @return Number of entries in the context
* @see java.util.Map#size()
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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,7 +18,7 @@ package org.springframework.batch.item;
/**
* Empty method implementation of {@link ItemStream}.
*
*
* @author Dave Syer
*
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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.
@@ -30,12 +30,12 @@ import org.springframework.util.MethodInvoker;
* Superclass for delegating classes which dynamically call a custom method of
* injected object. Provides convenient API for dynamic method invocation
* shielding subclasses from low-level details and exception handling.
*
*
* {@link Exception}s thrown by a successfully invoked delegate method are
* re-thrown without wrapping. In case the delegate method throws a
* {@link Throwable} that doesn't subclass {@link Exception} it will be wrapped
* by {@link InvocationTargetThrowableWrapper}.
*
*
* @author Robert Kasanicky
*/
public abstract class AbstractMethodInvokingDelegator<T> implements InitializingBean {
@@ -129,7 +129,7 @@ public abstract class AbstractMethodInvokingDelegator<T> implements Initializing
}
}
@Override
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(targetObject);
Assert.hasLength(targetMethod);
@@ -171,8 +171,9 @@ public abstract class AbstractMethodInvokingDelegator<T> implements Initializing
argumentsMatchParameters = false;
}
}
if (argumentsMatchParameters)
if (argumentsMatchParameters) {
return true;
}
}
}
}
@@ -201,7 +202,7 @@ public abstract class AbstractMethodInvokingDelegator<T> implements Initializing
* {@link #setTargetMethod(String)}. These will be used only when the
* subclass tries to invoke the target method without providing explicit
* argument values.
*
*
* If arguments are set to not-null value {@link #afterPropertiesSet()} will
* check the values are compatible with target method's signature. In case
* arguments are null (not set) method signature will not be checked and it
@@ -214,7 +215,7 @@ public abstract class AbstractMethodInvokingDelegator<T> implements Initializing
/**
* Used to wrap a {@link Throwable} (not an {@link Exception}) thrown by a
* reflectively-invoked delegate.
*
*
* @author Robert Kasanicky
*/
public static class InvocationTargetThrowableWrapper extends RuntimeException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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.
@@ -21,17 +21,17 @@ import org.springframework.batch.item.ItemProcessor;
/**
* Invokes a custom method on a delegate plain old Java object which itself
* processes an item.
*
*
* @author Dave Syer
*/
public class ItemProcessorAdapter<I,O> extends AbstractMethodInvokingDelegator<O> implements ItemProcessor<I,O> {
/**
* Invoke the delegate method and return the result.
*
*
* @see ItemProcessor#process(Object)
*/
@Override
@Override
public O process(I item) throws Exception {
return invokeDelegateMethodWithArgument(item);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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.
@@ -21,7 +21,7 @@ import org.springframework.batch.item.ItemReader;
/**
* Invokes a custom method on a delegate plain old Java object which itself
* provides an item.
*
*
* @author Robert Kasanicky
*/
public class ItemReaderAdapter<T> extends AbstractMethodInvokingDelegator<T> implements ItemReader<T> {
@@ -29,7 +29,7 @@ public class ItemReaderAdapter<T> extends AbstractMethodInvokingDelegator<T> imp
/**
* @return return value of the target method.
*/
@Override
@Override
public T read() throws Exception {
return invokeDelegateMethod();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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.
@@ -22,21 +22,21 @@ import org.springframework.batch.item.ItemWriter;
/**
* Delegates item processing to a custom method -
* Delegates item processing to a custom method -
* passes the item as an argument for the delegate method.
*
*
* @see PropertyExtractingDelegatingItemWriter
*
*
* @author Robert Kasanicky
*/
public class ItemWriterAdapter<T> extends AbstractMethodInvokingDelegator<T> implements ItemWriter<T> {
@Override
public void write(List<? extends T> items) throws Exception {
for (T item : items) {
invokeDelegateMethodWithArgument(item);
@Override
public void write(List<? extends T> items) throws Exception {
for (T item : items) {
invokeDelegateMethodWithArgument(item);
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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.
@@ -27,13 +27,13 @@ import org.springframework.util.Assert;
/**
* Delegates processing to a custom method - extracts property values from item
* object and uses them as arguments for the delegate method.
*
*
* @see ItemWriterAdapter
*
*
* @author Robert Kasanicky
*/
public class PropertyExtractingDelegatingItemWriter<T> extends AbstractMethodInvokingDelegator<T> implements
ItemWriter<T> {
ItemWriter<T> {
private String[] fieldsUsedAsTargetMethodArguments;
@@ -42,7 +42,7 @@ public class PropertyExtractingDelegatingItemWriter<T> extends AbstractMethodInv
* fieldsUsedAsTargetMethodArguments and passes them as arguments to the
* delegate method.
*/
@Override
@Override
public void write(List<? extends T> items) throws Exception {
for (T item : items) {
@@ -59,7 +59,7 @@ public class PropertyExtractingDelegatingItemWriter<T> extends AbstractMethodInv
}
}
@Override
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
Assert.notEmpty(fieldsUsedAsTargetMethodArguments);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2013 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.
@@ -30,34 +30,34 @@ import org.springframework.util.Assert;
* @author Chris Schaefer
*/
public class AmqpItemReader<T> implements ItemReader<T> {
private final AmqpTemplate amqpTemplate;
private Class<? extends T> itemType;
private final AmqpTemplate amqpTemplate;
private Class<? extends T> itemType;
public AmqpItemReader(final AmqpTemplate amqpTemplate) {
Assert.notNull(amqpTemplate, "AmpqTemplate must not be null");
public AmqpItemReader(final AmqpTemplate amqpTemplate) {
Assert.notNull(amqpTemplate, "AmpqTemplate must not be null");
this.amqpTemplate = amqpTemplate;
}
this.amqpTemplate = amqpTemplate;
}
@Override
@SuppressWarnings("unchecked")
public T read() {
if (itemType != null && itemType.isAssignableFrom(Message.class)) {
return (T) amqpTemplate.receive();
}
@Override
@SuppressWarnings("unchecked")
public T read() {
if (itemType != null && itemType.isAssignableFrom(Message.class)) {
return (T) amqpTemplate.receive();
}
Object result = amqpTemplate.receiveAndConvert();
Object result = amqpTemplate.receiveAndConvert();
if (itemType != null && result != null) {
Assert.state(itemType.isAssignableFrom(result.getClass()),
"Received message payload of wrong type: expected [" + itemType + "]");
}
if (itemType != null && result != null) {
Assert.state(itemType.isAssignableFrom(result.getClass()),
"Received message payload of wrong type: expected [" + itemType + "]");
}
return (T) result;
}
return (T) result;
}
public void setItemType(Class<? extends T> itemType) {
Assert.notNull(itemType, "Item type cannot be null");
this.itemType = itemType;
}
public void setItemType(Class<? extends T> itemType) {
Assert.notNull(itemType, "Item type cannot be null");
this.itemType = itemType;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2009 the original author or authors.
* Copyright 2006-2013 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,27 +45,27 @@ import org.springframework.util.Assert;
/**
* <p>
* Abstract base class for any simple item reader that opens a database cursor and continually retrieves
* the next row in the ResultSet.
* Abstract base class for any simple item reader that opens a database cursor and continually retrieves
* the next row in the ResultSet.
* </p>
*
*
* <p>
* By default the cursor will be opened using a separate connection. The ResultSet for the cursor
* is held open regardless of commits or roll backs in a surrounding transaction. Clients of this
* is held open regardless of commits or roll backs in a surrounding transaction. Clients of this
* reader are responsible for buffering the items in the case that they need to be re-presented on a
* rollback. This buffering is handled by the step implementations provided and is only a concern for
* anyone writing their own step implementations.
* </p>
*
*
* <p>
* There is an option ({@link #setUseSharedExtendedConnection(boolean)} that will share the connection
* used for the cursor with the rest of the step processing. If you set this flag to <code>true</code>
* then you must wrap the DataSource in a {@link ExtendedConnectionDataSourceProxy} to prevent the
* connection from being closed and released after each commit performed as part of the step processing.
* You must also use a JDBC driver supporting JDBC 3.0 or later since the cursor will be opened with the
* additional option of 'HOLD_CUSORS_OVER_COMMIT' enabled.
* There is an option ({@link #setUseSharedExtendedConnection(boolean)} that will share the connection
* used for the cursor with the rest of the step processing. If you set this flag to <code>true</code>
* then you must wrap the DataSource in a {@link ExtendedConnectionDataSourceProxy} to prevent the
* connection from being closed and released after each commit performed as part of the step processing.
* You must also use a JDBC driver supporting JDBC 3.0 or later since the cursor will be opened with the
* additional option of 'HOLD_CUSORS_OVER_COMMIT' enabled.
* </p>
*
*
* <p>
* Each call to {@link #read()} will attempt to map the row at the current position in the
* ResultSet. There is currently no wrapping of the ResultSet to suppress calls
@@ -76,7 +76,7 @@ import org.springframework.util.Assert;
* restartability. This ensures that each call to {@link #read()} returns the
* ResultSet at the correct row, regardless of rollbacks or restarts.
* </p>
*
*
* <p>
* {@link ExecutionContext}: The current row is returned as restart data, and
* when restored from that same data, the cursor is opened and the current row
@@ -84,56 +84,56 @@ import org.springframework.util.Assert;
* {@link #setDriverSupportsAbsolute(boolean)} for improving restart
* performance.
* </p>
*
*
* <p>
* Calling close on this {@link ItemStream} will cause all resources it is
* currently using to be freed. (Connection, ResultSet, etc). It is then illegal
* to call {@link #read()} again until it has been re-opened.
* </p>
*
*
* <p>
* Known limitation: when used with Derby
* {@link #setVerifyCursorPosition(boolean)} needs to be <code>false</code>
* because {@link ResultSet#getRow()} call used for cursor position verification
* is not available for 'TYPE_FORWARD_ONLY' result sets.
* </p>
*
*
* @author Lucas Ward
* @author Peter Zozom
* @author Robert Kasanicky
* @author Thomas Risberg
*/
public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
implements InitializingBean {
implements InitializingBean {
/** Logger available to subclasses */
protected final Log log = LogFactory.getLog(getClass());
public static final int VALUE_NOT_SET = -1;
private Connection con;
protected ResultSet rs;
private DataSource dataSource;
private int fetchSize = VALUE_NOT_SET;
private int maxRows = VALUE_NOT_SET;
private int queryTimeout = VALUE_NOT_SET;
private boolean ignoreWarnings = true;
private boolean verifyCursorPosition = true;
private SQLExceptionTranslator exceptionTranslator;
private boolean initialized = false;
private boolean driverSupportsAbsolute = false;
private boolean useSharedExtendedConnection = false;
public AbstractCursorItemReader() {
super();
@@ -141,18 +141,18 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
/**
* Assert that mandatory properties are set.
*
*
* @throws IllegalArgumentException if either data source or sql properties
* not set.
*/
@Override
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(dataSource, "DataSource must be provided");
}
/**
* Public setter for the data source for injection purposes.
*
*
* @param dataSource
*/
public void setDataSource(DataSource dataSource) {
@@ -161,7 +161,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
/**
* Public getter for the data source.
*
*
* @return the dataSource
*/
public DataSource getDataSource() {
@@ -173,7 +173,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
* CallableStatement), applying statement settings such as fetch size, max
* rows, and query timeout. @param stmt the JDBC Statement to prepare
* @throws SQLException
*
*
* @see #setFetchSize
* @see #setMaxRows
* @see #setQueryTimeout
@@ -193,7 +193,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
/**
* Return the exception translator for this instance.
*
*
* Creates a default SQLErrorCodeSQLExceptionTranslator for the specified
* DataSource if none is set.
*/
@@ -214,31 +214,31 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
/**
* Throw a SQLWarningException if we're not ignoring warnings, else log the
* warnings (at debug level).
*
*
* @param statement the current statement to obtain the warnings from, if there are any.
* @throws SQLException
*
*
* @see org.springframework.jdbc.SQLWarningException
*/
protected void handleWarnings(Statement statement) throws SQLWarningException,
SQLException {
if (ignoreWarnings) {
if (log.isDebugEnabled()) {
SQLWarning warningToLog = statement.getWarnings();
while (warningToLog != null) {
log.debug("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() + "', error code '"
+ warningToLog.getErrorCode() + "', message [" + warningToLog.getMessage() + "]");
warningToLog = warningToLog.getNextWarning();
}
}
}
else {
SQLWarning warnings = statement.getWarnings();
if (warnings != null) {
throw new SQLWarningException("Warning not ignored", warnings);
}
SQLException {
if (ignoreWarnings) {
if (log.isDebugEnabled()) {
SQLWarning warningToLog = statement.getWarnings();
while (warningToLog != null) {
log.debug("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() + "', error code '"
+ warningToLog.getErrorCode() + "', message [" + warningToLog.getMessage() + "]");
warningToLog = warningToLog.getNextWarning();
}
}
}
else {
SQLWarning warnings = statement.getWarnings();
if (warnings != null) {
throw new SQLWarningException("Warning not ignored", warnings);
}
}
}
/**
* Moves the cursor in the ResultSet to the position specified by the row
@@ -262,7 +262,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
* fetched from the database when more rows are needed for this
* <code>ResultSet</code> object. If the fetch size specified is zero, the
* JDBC driver ignores the value.
*
*
* @param fetchSize the number of rows to fetch
* @see ResultSet#setFetchSize(int)
*/
@@ -273,7 +273,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
/**
* Sets the limit for the maximum number of rows that any
* <code>ResultSet</code> object can contain to the given number.
*
*
* @param maxRows the new max rows limit; zero means there is no limit
* @see Statement#setMaxRows(int)
*/
@@ -285,7 +285,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
* Sets the number of seconds the driver will wait for a
* <code>Statement</code> object to execute to the given number of seconds.
* If the limit is exceeded, an <code>SQLException</code> is thrown.
*
*
* @param queryTimeout seconds the new query timeout limit in seconds; zero
* means there is no limit
* @see Statement#setQueryTimeout(int)
@@ -297,7 +297,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
/**
* Set whether SQLWarnings should be ignored (only logged) or exception
* should be thrown.
*
*
* @param ignoreWarnings if TRUE, warnings are ignored
*/
public void setIgnoreWarnings(boolean ignoreWarnings) {
@@ -307,7 +307,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
/**
* Allow verification of cursor position after current row is processed by
* RowMapper or RowCallbackHandler. Default value is TRUE.
*
*
* @param verifyCursorPosition if true, cursor position is verified
*/
public void setVerifyCursorPosition(boolean verifyCursorPosition) {
@@ -320,9 +320,9 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
* <code>true</code> for JDBC drivers that supports ResultSet.absolute() as
* it may improve performance, especially if a step fails while working with
* a large data set.
*
*
* @see ResultSet#absolute(int)
*
*
* @param driverSupportsAbsolute <code>false</code> by default
*/
public void setDriverSupportsAbsolute(boolean driverSupportsAbsolute) {
@@ -331,16 +331,16 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
/**
* Indicate whether the connection used for the cursor should be used by all other processing
* thus sharing the same transaction. If this is set to false, which is the default, then the
* thus sharing the same transaction. If this is set to false, which is the default, then the
* cursor will be opened using in its connection and will not participate in any transactions
* started for the rest of the step processing. If you set this flag to true then you must
* started for the rest of the step processing. If you set this flag to true then you must
* wrap the DataSource in a {@link ExtendedConnectionDataSourceProxy} to prevent the
* connection from being closed and released after each commit.
*
* When you set this option to <code>true</code> then the statement used to open the cursor
* will be created with both 'READ_ONLY' and 'HOLD_CUSORS_OVER_COMMIT' options. This allows
* holding the cursor open over transaction start and commits performed in the step processing.
* To use this feature you need a database that supports this and a JDBC driver supporting
*
* When you set this option to <code>true</code> then the statement used to open the cursor
* will be created with both 'READ_ONLY' and 'HOLD_CUSORS_OVER_COMMIT' options. This allows
* holding the cursor open over transaction start and commits performed in the step processing.
* To use this feature you need a database that supports this and a JDBC driver supporting
* JDBC 3.0 or later.
*
* @param useSharedExtendedConnection <code>false</code> by default
@@ -354,7 +354,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
}
public abstract String getSql();
/**
* Check the result set is in synch with the currentRow attribute. This is
* important to ensure that the user hasn't modified the current row.
@@ -368,10 +368,10 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
}
/**
* Close the cursor and database connection. Make call to cleanupOnClose so sub classes can cleanup
* Close the cursor and database connection. Make call to cleanupOnClose so sub classes can cleanup
* any resources they have allocated.
*/
@Override
@Override
protected void doClose() throws Exception {
initialized = false;
JdbcUtils.closeResultSet(this.rs);
@@ -387,7 +387,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
JdbcUtils.closeConnection(this.con);
}
}
protected abstract void cleanupOnClose() throws Exception;
/**
@@ -402,12 +402,12 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
initializeConnection();
openCursor(con);
initialized = true;
}
protected void initializeConnection() {
Assert.state(getDataSource() != null, "DataSource must not be null.");
try {
if (useSharedExtendedConnection) {
if (!(getDataSource() instanceof ExtendedConnectionDataSourceProxy)) {
@@ -427,19 +427,19 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
throw getExceptionTranslator().translate("Executing query", getSql(), se);
}
}
protected abstract void openCursor(Connection con);
/**
* Read next row and map it to item, verify cursor position if
* {@link #setVerifyCursorPosition(boolean)} is true.
*/
@Override
@Override
protected T doRead() throws Exception {
if (rs == null) {
throw new ReaderNotOpenException("Reader must be open before it can be read.");
}
try {
if (!rs.next()) {
return null;
@@ -453,11 +453,11 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
throw getExceptionTranslator().translate("Attempt to process next row failed", getSql(), se);
}
}
/**
* Read the cursor and map to the type of object this reader should return. This method must be
* Read the cursor and map to the type of object this reader should return. This method must be
* overriden by subclasses.
*
*
* @param rs The current result set
* @param currentRow Current position of the result set
* @return the mapped object at the cursor position
@@ -469,7 +469,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
* Use {@link ResultSet#absolute(int)} if possible, otherwise scroll by
* calling {@link ResultSet#next()}.
*/
@Override
@Override
protected void jumpToItem(int itemIndex) throws Exception {
if (driverSupportsAbsolute) {
try {
@@ -480,7 +480,7 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt
// traversing ResultSet
log.warn("The JDBC driver does not appear to support ResultSet.absolute(). Consider"
+ " reverting to the default behavior setting the driverSupportsAbsolute to false", e);
moveCursorToRow(itemIndex);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2013 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.
@@ -27,20 +27,20 @@ import org.springframework.util.ClassUtils;
/**
* Abstract {@link org.springframework.batch.item.ItemReader} for to extend when
* reading database records in a paging fashion.
*
*
* <p>
* Implementations should execute queries using paged requests of a size
* specified in {@link #setPageSize(int)}. Additional pages are requested when
* needed as {@link #read()} method is called, returning an object corresponding
* to current position.
* </p>
*
*
* @author Thomas Risberg
* @author Dave Syer
* @since 2.0
*/
public abstract class AbstractPagingItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements
InitializingBean {
InitializingBean {
protected Log logger = LogFactory.getLog(getClass());
@@ -78,7 +78,7 @@ public abstract class AbstractPagingItemReader<T> extends AbstractItemCountingIt
/**
* The number of rows to retrieve at a time.
*
*
* @param pageSize the number of rows to fetch per page
*/
public void setPageSize(int pageSize) {
@@ -89,7 +89,7 @@ public abstract class AbstractPagingItemReader<T> extends AbstractItemCountingIt
* Check mandatory properties.
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
@Override
public void afterPropertiesSet() throws Exception {
Assert.isTrue(pageSize > 0, "pageSize must be greater than zero");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2013 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.
@@ -21,18 +21,18 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource;
/**
* A convenient implementation for providing BeanPropertySqlParameterSource when the item has JavaBean properties
* that correspond to names used for parameters in the SQL statement.
*
*
* @author Thomas Risberg
* @since 2.0
*/
public class BeanPropertyItemSqlParameterSourceProvider<T> implements ItemSqlParameterSourceProvider<T> {
/**
* Provide parameter values in an {@link BeanPropertySqlParameterSource} based on values from
* Provide parameter values in an {@link BeanPropertySqlParameterSource} based on values from
* the provided item.
* @param item the item to use for parameter values
*/
@Override
@Override
public SqlParameterSource createSqlParameterSource(T item) {
return new BeanPropertySqlParameterSource(item);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2013 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.
@@ -38,19 +38,19 @@ import org.springframework.util.Assert;
* Implementation of {@link SmartDataSource} that is capable of keeping a single
* JDBC Connection which is NOT closed after each use even if
* {@link Connection#close()} is called.
*
*
* The connection can be kept open over multiple transactions when used together
* with any of Spring's
* {@link org.springframework.transaction.PlatformTransactionManager}
* implementations.
*
*
* <p>
* Loosely based on the SingleConnectionDataSource implementation in Spring
* Core. Intended to be used with the {@link JdbcCursorItemReader} to provide a
* connection that remains open across transaction boundaries, It remains open
* for the life of the cursor, and can be shared with the main transaction of
* the rest of the step processing.
*
*
* <p>
* Once close suppression has been turned on for a connection, it will be
* returned for the first {@link #getConnection()} call. Any subsequent calls to
@@ -64,16 +64,16 @@ import org.springframework.util.Assert;
* {@link Connection} to be the main {@link Connection} for an extended data
* access process. The close suppression is turned off by calling
* {@link #stopCloseSuppression(Connection)}.
*
*
* <p>
* This class is not multi-threading capable.
*
*
* <p>
* The connection returned will be a close-suppressing proxy instead of the
* physical {@link Connection}. Be aware that you will not be able to cast this
* to a native <code>OracleConnection</code> or the like anymore; you need to
* use a {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor}.
*
*
* @author Thomas Risberg
* @see #getConnection()
* @see java.sql.Connection#close()
@@ -111,7 +111,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
/**
* Setter for the {&link DataSource} that is to be wrapped.
*
*
* @param dataSource the DataSource
*/
public void setDataSource(DataSource dataSource) {
@@ -121,7 +121,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
/**
* @see SmartDataSource
*/
@Override
@Override
public boolean shouldClose(Connection connection) {
boolean shouldClose = !isCloseSuppressionActive(connection);
if (borrowedConnection && closeSuppressedConnection.equals(connection)) {
@@ -133,7 +133,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
/**
* Return the status of close suppression being activated for a given
* {@link Connection}
*
*
* @param connection the {@link Connection} that the close suppression
* status is requested for
* @return true or false
@@ -146,7 +146,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
}
/**
*
*
* @param connection the {@link Connection} that close suppression is
* requested for
*/
@@ -160,7 +160,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
}
/**
*
*
* @param connection the {@link Connection} that close suppression should be
* turned off for
*/
@@ -171,14 +171,14 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
}
}
@Override
@Override
public Connection getConnection() throws SQLException {
synchronized (this.connectionMonitor) {
return initConnection(null, null);
}
}
@Override
@Override
public Connection getConnection(String username, String password) throws SQLException {
synchronized (this.connectionMonitor) {
return initConnection(username, password);
@@ -210,22 +210,22 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
return connection;
}
@Override
@Override
public PrintWriter getLogWriter() throws SQLException {
return dataSource.getLogWriter();
}
@Override
@Override
public int getLoginTimeout() throws SQLException {
return dataSource.getLoginTimeout();
}
@Override
@Override
public void setLogWriter(PrintWriter out) throws SQLException {
dataSource.setLogWriter(out);
}
@Override
@Override
public void setLoginTimeout(int seconds) throws SQLException {
dataSource.setLoginTimeout(seconds);
}
@@ -257,7 +257,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
this.target = target;
}
@Override
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Invocation on ConnectionProxy interface coming in...
@@ -300,7 +300,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
* Performs only a 'shallow' non-recursive check of self's and delegate's
* class to retain Java 5 compatibility.
*/
@Override
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
if (iface.isAssignableFrom(SmartDataSource.class) || iface.isAssignableFrom(dataSource.getClass())) {
return true;
@@ -313,7 +313,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
* cast to supplied parameter class. Does *not* support recursive unwrapping
* of the delegate to retain Java 5 compatibility.
*/
@Override
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface.isAssignableFrom(SmartDataSource.class)) {
@SuppressWarnings("unchecked")
@@ -328,7 +328,7 @@ public class ExtendedConnectionDataSourceProxy implements SmartDataSource, Initi
throw new SQLException("Unsupported class " + iface.getSimpleName());
}
@Override
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(dataSource);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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.
@@ -39,8 +39,8 @@ import org.springframework.util.ClassUtils;
* {@link #setQueryString(String)}, a named query can be used by
* {@link #setQueryName(String)}, or a query provider strategy can be supplied
* via {@link #setQueryProvider(HibernateQueryProvider)}.
*
*
*
*
* <p>
* The reader can be configured to use either {@link StatelessSession}
* sufficient for simple mappings without the need to cascade to associated
@@ -49,14 +49,14 @@ import org.springframework.util.ClassUtils;
* the {@link #update(ExecutionContext)} method without being flushed (no data
* modifications are expected).
* </p>
*
*
* The implementation is <b>not</b> thread-safe.
*
*
* @author Robert Kasanicky
* @author Dave Syer
*/
public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements ItemStream,
InitializingBean {
InitializingBean {
private HibernateItemReaderHelper<T> helper = new HibernateItemReaderHelper<T>();
@@ -72,7 +72,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
private Map<String, Object> parameterValues;
@Override
@Override
public void afterPropertiesSet() throws Exception {
Assert.state(fetchSize >= 0, "fetchSize must not be negative");
helper.afterPropertiesSet();
@@ -80,7 +80,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
/**
* The parameter values to apply to a query (map of name:value).
*
*
* @param parameterValues the parameter values to set
*/
public void setParameterValues(Map<String, Object> parameterValues) {
@@ -92,7 +92,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
* {@link #setQueryString(String) query string} or the {
* {@link #setQueryProvider(HibernateQueryProvider) query provider} should
* be set.
*
*
* @param queryName name of a hibernate named query
*/
public void setQueryName(String queryName) {
@@ -102,7 +102,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
/**
* Fetch size used internally by Hibernate to limit amount of data fetched
* from database per round trip.
*
*
* @param fetchSize the fetch size to pass down to Hibernate
*/
public void setFetchSize(int fetchSize) {
@@ -113,7 +113,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
* A query provider. Either this or the {{@link #setQueryString(String)
* query string} or the {{@link #setQueryName(String) query name} should be
* set.
*
*
* @param queryProvider Hibernate query provider
*/
public void setQueryProvider(HibernateQueryProvider queryProvider) {
@@ -124,7 +124,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
* A query string in HQL. Either this or the {
* {@link #setQueryProvider(HibernateQueryProvider) query provider} or the {
* {@link #setQueryName(String) query name} should be set.
*
*
* @param queryString HQL query string
*/
public void setQueryString(String queryString) {
@@ -133,7 +133,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
/**
* The Hibernate SessionFactory to use the create a session.
*
*
* @param sessionFactory the {@link SessionFactory} to set
*/
public void setSessionFactory(SessionFactory sessionFactory) {
@@ -142,7 +142,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
/**
* Can be set only in uninitialized state.
*
*
* @param useStatelessSession <code>true</code> to use
* {@link StatelessSession} <code>false</code> to use standard hibernate
* {@link Session}
@@ -151,7 +151,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
helper.setUseStatelessSession(useStatelessSession);
}
@Override
@Override
protected T doRead() throws Exception {
if (cursor.next()) {
Object[] data = cursor.get();
@@ -180,7 +180,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
/**
* Open hibernate session and create a forward-only cursor for the query.
*/
@Override
@Override
protected void doOpen() throws Exception {
Assert.state(!initialized, "Cannot open an already opened ItemReader, call close first");
cursor = helper.getForwardOnlyCursor(fetchSize, parameterValues);
@@ -189,7 +189,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
/**
* Update the context and clear the session if stateful.
*
*
* @param executionContext the current {@link ExecutionContext}
* @throws ItemStreamException if there is a problem
*/
@@ -204,7 +204,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
* the session every now and then (if stateful) to avoid memory problems.
* The frequency of session clearing is the larger of the fetch size (if
* set) and 100.
*
*
* @param itemIndex the first item to read
* @throws Exception if there is a problem
* @see AbstractItemCountingItemStreamItemReader#jumpToItem(int)
@@ -218,7 +218,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
/**
* Close the cursor and hibernate session.
*/
@Override
@Override
protected void doClose() throws Exception {
initialized = false;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2010 the original author or authors.
* Copyright 2006-2013 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.
@@ -33,9 +33,9 @@ import org.springframework.util.StringUtils;
/**
* Internal shared state helper for hibernate readers managing sessions and
* queries.
*
*
* @author Dave Syer
*
*
*/
public class HibernateItemReaderHelper<T> implements InitializingBean {
@@ -76,7 +76,7 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
/**
* Can be set only in uninitialized state.
*
*
* @param useStatelessSession <code>true</code> to use
* {@link StatelessSession} <code>false</code> to use standard hibernate
* {@link Session}
@@ -94,7 +94,7 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
this.sessionFactory = sessionFactory;
}
@Override
@Override
public void afterPropertiesSet() throws Exception {
Assert.state(sessionFactory != null, "A SessionFactory must be provided");
@@ -113,10 +113,10 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
/**
* Get a cursor over all of the results, with the forward-only flag set.
*
*
* @param fetchSize the fetch size to use retrieving the results
* @param parameterValues the parameter values to use (or null if none).
*
*
* @return a forward-only {@link ScrollableResults}
*/
public ScrollableResults getForwardOnlyCursor(int fetchSize, Map<String, Object> parameterValues) {
@@ -172,7 +172,7 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
/**
* Scroll through the results up to the item specified.
*
*
* @param cursor the results to scroll over
*/
public void jumpToItem(ScrollableResults cursor, int itemIndex, int flushInterval) {
@@ -201,7 +201,7 @@ public class HibernateItemReaderHelper<T> implements InitializingBean {
/**
* Read a page of data, clearing the existing session (if necessary) first,
* and creating a new session before executing the query.
*
*
* @param page the page to read (starting at 0)
* @param pageSize the size of the page or maximum number of items to read
* @param fetchSize the fetch size to use

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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.
@@ -33,13 +33,13 @@ import org.springframework.util.Assert;
* TaskletStep). It will also clear the session on write
* default (see {@link #setClearSession(boolean) clearSession} property).<br/>
* <br/>
*
*
* The writer is thread safe after its properties are set (normal singleton
* behavior), so it can be used to write in multiple concurrent transactions.
*
*
* @author Dave Syer
* @author Thomas Risberg
*
*
*/
public class HibernateItemWriter<T> implements ItemWriter<T>, InitializingBean {
@@ -53,7 +53,7 @@ public class HibernateItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Flag to indicate that the session should be cleared and flushed at the
* end of the write (default true).
*
*
* @param clearSession
* the flag value to set
*/
@@ -63,7 +63,7 @@ public class HibernateItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Public setter for the {@link HibernateOperations} property.
*
*
* @param hibernateTemplate
* the hibernateTemplate to set
*/
@@ -74,7 +74,7 @@ public class HibernateItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Set the Hibernate SessionFactory to be used internally. Will
* automatically create a HibernateTemplate for the given SessionFactory.
*
*
* @see #setHibernateTemplate
*/
public final void setSessionFactory(SessionFactory sessionFactory) {
@@ -84,7 +84,7 @@ public class HibernateItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Check mandatory properties - there must be a hibernateTemplate.
*/
@Override
@Override
public void afterPropertiesSet() {
Assert.notNull(hibernateTemplate,
"HibernateItemWriter requires a HibernateOperations");
@@ -93,10 +93,10 @@ public class HibernateItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Save or update any entities not in the current hibernate session and then
* flush the hibernate session.
*
*
* @see org.springframework.batch.item.ItemWriter#write(java.util.List)
*/
@Override
@Override
public final void write(List<? extends T> items) {
doWrite(hibernateTemplate, items);
hibernateTemplate.flush();
@@ -108,7 +108,7 @@ public class HibernateItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Do perform the actual write operation. This can be overridden in a
* subclass if necessary.
*
*
* @param hibernateTemplate
* the HibernateTemplate to use for the operation
* @param items

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 the original author or authors.
* Copyright 2006-2013 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.
@@ -37,7 +37,7 @@ import org.springframework.util.ClassUtils;
* query can be used by {@link #setQueryName(String)}, or a query provider
* strategy can be supplied via
* {@link #setQueryProvider(HibernateQueryProvider)}.
*
*
* <p>
* The reader can be configured to use either {@link StatelessSession}
* sufficient for simple mappings without the need to cascade to associated
@@ -46,16 +46,16 @@ import org.springframework.util.ClassUtils;
* the {@link #update(ExecutionContext)} method without being flushed (no data
* modifications are expected).
* </p>
*
*
* <p>
* The implementation is thread-safe in between calls to
* {@link #open(ExecutionContext)}, but remember to use
* <code>saveState=false</code> if used in a multi-threaded client (no restart
* available).
* </p>
*
*
* @author Dave Syer
*
*
* @since 2.1
*/
public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> implements ItemStream, InitializingBean {
@@ -72,7 +72,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
/**
* The parameter values to apply to a query (map of name:value).
*
*
* @param parameterValues the parameter values to set
*/
public void setParameterValues(Map<String, Object> parameterValues) {
@@ -84,7 +84,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
* {@link #setQueryString(String) query string} or the {
* {@link #setQueryProvider(HibernateQueryProvider) query provider} should
* be set.
*
*
* @param queryName name of a hibernate named query
*/
public void setQueryName(String queryName) {
@@ -94,7 +94,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
/**
* Fetch size used internally by Hibernate to limit amount of data fetched
* from database per round trip.
*
*
* @param fetchSize the fetch size to pass down to Hibernate
*/
public void setFetchSize(int fetchSize) {
@@ -105,7 +105,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
* A query provider. Either this or the {{@link #setQueryString(String)
* query string} or the {{@link #setQueryName(String) query name} should be
* set.
*
*
* @param queryProvider Hibernate query provider
*/
public void setQueryProvider(HibernateQueryProvider queryProvider) {
@@ -116,7 +116,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
* A query string in HQL. Either this or the {
* {@link #setQueryProvider(HibernateQueryProvider) query provider} or the {
* {@link #setQueryName(String) query name} should be set.
*
*
* @param queryString HQL query string
*/
public void setQueryString(String queryString) {
@@ -125,7 +125,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
/**
* The Hibernate SessionFactory to use the create a session.
*
*
* @param sessionFactory the {@link SessionFactory} to set
*/
public void setSessionFactory(SessionFactory sessionFactory) {
@@ -134,7 +134,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
/**
* Can be set only in uninitialized state.
*
*
* @param useStatelessSession <code>true</code> to use
* {@link StatelessSession} <code>false</code> to use standard hibernate
* {@link Session}
@@ -143,7 +143,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
helper.setUseStatelessSession(useStatelessSession);
}
@Override
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
Assert.state(fetchSize >= 0, "fetchSize must not be negative");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2013 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.
@@ -34,18 +34,18 @@ import com.ibatis.sqlmap.engine.execution.BatchException;
import com.ibatis.sqlmap.engine.execution.BatchResult;
/**
* {@link ItemWriter} that uses the batching features from
* {@link SqlMapClientTemplate} to execute a batch of statements for all items
* {@link ItemWriter} that uses the batching features from
* {@link SqlMapClientTemplate} to execute a batch of statements for all items
* provided.<br/>
*
*
* The user must provide an iBATIS statement id that points to the SQL statement defined
* in the iBATIS SqlMap configuration.<br/>
*
*
* It is expected that {@link #write(List)} is called inside a transaction.<br/>
*
*
* The writer is thread safe after its properties are set (normal singleton
* behavior), so it can be used to write in multiple concurrent transactions.
*
*
* @author Thomas Risberg
* @since 2.0
*/
@@ -62,7 +62,7 @@ public class IbatisBatchItemWriter<T> implements ItemWriter<T>, InitializingBean
/**
* Public setter for the flag that determines whether an assertion is made
* that all items cause at least one row to be updated.
*
*
* @param assertUpdates the flag to set. Defaults to true;
*/
public void setAssertUpdates(boolean assertUpdates) {
@@ -71,7 +71,7 @@ public class IbatisBatchItemWriter<T> implements ItemWriter<T>, InitializingBean
/**
* Public setter for {@link SqlMapClient} for injection purposes.
*
*
* @param sqlMapClient the SqlMapClient
*/
public void setSqlMapClient(SqlMapClient sqlMapClient) {
@@ -82,7 +82,7 @@ public class IbatisBatchItemWriter<T> implements ItemWriter<T>, InitializingBean
/**
* Public setter for the {@link SqlMapClientTemplate}.
*
*
* @param sqlMapClientTemplate the SqlMapClientTemplate
*/
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
@@ -90,9 +90,9 @@ public class IbatisBatchItemWriter<T> implements ItemWriter<T>, InitializingBean
}
/**
* Public setter for the statement id identifying the statement in the SqlMap
* Public setter for the statement id identifying the statement in the SqlMap
* configuration file.
*
*
* @param statementId the id for the statement
*/
public void setStatementId(String statementId) {
@@ -102,16 +102,16 @@ public class IbatisBatchItemWriter<T> implements ItemWriter<T>, InitializingBean
/**
* Check mandatory properties - there must be an SqlMapClient and a statementId.
*/
@Override
@Override
public void afterPropertiesSet() {
Assert.notNull(sqlMapClientTemplate, "A SqlMapClient or a SqlMapClientTemplate is required.");
Assert.notNull(statementId, "A statementId is required.");
}
/* (non-Javadoc)
* @see org.springframework.batch.item.ItemWriter#write(java.util.List)
*/
@Override
@Override
public void write(final List<? extends T> items) {
if (!items.isEmpty()) {
@@ -119,11 +119,11 @@ public class IbatisBatchItemWriter<T> implements ItemWriter<T>, InitializingBean
if (logger.isDebugEnabled()) {
logger.debug("Executing batch with " + items.size() + " items.");
}
@SuppressWarnings("unchecked")
List<BatchResult> results = (List<BatchResult>) sqlMapClientTemplate.execute(
new SqlMapClientCallback() {
@Override
@Override
public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
executor.startBatch();
@@ -137,14 +137,14 @@ public class IbatisBatchItemWriter<T> implements ItemWriter<T>, InitializingBean
}
}
});
if (assertUpdates) {
if (results.size() != 1) {
throw new InvalidDataAccessResourceUsageException("Batch execution returned invalid results. " +
"Expected 1 but number of BatchResult objects returned was " + results.size());
}
int[] updateCounts = results.get(0).getUpdateCounts();
int[] updateCounts = results.get(0).getUpdateCounts();
for (int i = 0; i < updateCounts.length; i++) {
int value = updateCounts[i];

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2013 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.
@@ -16,14 +16,14 @@
package org.springframework.batch.item.database;
import org.springframework.util.ClassUtils;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import com.ibatis.sqlmap.client.SqlMapClient;
@@ -32,7 +32,7 @@ import com.ibatis.sqlmap.client.SqlMapClient;
* {@link org.springframework.batch.item.ItemReader} for reading database
* records using iBATIS in a paging fashion.
* </p>
*
*
* <p>
* It executes the query specified as the {@link #setQueryId(String)} to
* retrieve requested data. The query is executed using paged requests of a size
@@ -53,20 +53,20 @@ import com.ibatis.sqlmap.client.SqlMapClient;
* infinite loop in the reader because it keeps asking for the next page and
* gets the same result set over and over.
* </p>
*
*
* <p>
* The performance of the paging depends on the iBATIS implementation.
* Setting a fairly large page size and using a commit interval that matches the
* page size should provide better performance.
* </p>
*
*
* <p>
* The implementation is thread-safe in between calls to
* {@link #open(ExecutionContext)}, but remember to use
* <code>saveState=false</code> if used in a multi-threaded client (no restart
* available).
* </p>
*
*
* @author Thomas Risberg
* @author Dave Syer
* @since 2.0
@@ -95,7 +95,7 @@ public class IbatisPagingItemReader<T> extends AbstractPagingItemReader<T> {
/**
* The parameter values to be used for the query execution.
*
*
* @param parameterValues the values keyed by the parameter named used in
* the query string.
*/
@@ -107,7 +107,7 @@ public class IbatisPagingItemReader<T> extends AbstractPagingItemReader<T> {
* Check mandatory properties.
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
Assert.notNull(sqlMapClient);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2013 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.
@@ -30,29 +30,29 @@ import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.util.Assert;
/**
* <p>{@link ItemWriter} that uses the batching features from
* <p>{@link ItemWriter} that uses the batching features from
* {@link NamedParameterJdbcTemplate} to execute a batch of statements for all items
* provided.</p>
*
* The user must provide an SQL query and a special callback in the for of either
*
* The user must provide an SQL query and a special callback in the for of either
* {@link ItemPreparedStatementSetter}, or a {@link ItemSqlParameterSourceProvider}.
* You can use either named parameters or the traditional '?' placeholders. If you use the
* named parameter support then you should provide a {@link ItemSqlParameterSourceProvider},
* You can use either named parameters or the traditional '?' placeholders. If you use the
* named parameter support then you should provide a {@link ItemSqlParameterSourceProvider},
* otherwise you should provide a {@link ItemPreparedStatementSetter}.
* This callback would be responsible for mapping the item to the parameters needed to
* This callback would be responsible for mapping the item to the parameters needed to
* execute the SQL statement.<br/>
*
*
* It is expected that {@link #write(List)} is called inside a transaction.<br/>
*
*
* The writer is thread safe after its properties are set (normal singleton
* behavior), so it can be used to write in multiple concurrent transactions.
*
*
* @author Dave Syer
* @author Thomas Risberg
* @since 2.0
@@ -114,7 +114,7 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Public setter for the data source for injection purposes.
*
*
* @param dataSource
*/
public void setDataSource(DataSource dataSource) {
@@ -132,10 +132,10 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
}
/**
* Check mandatory properties - there must be a SimpleJdbcTemplate and an SQL statement plus a
* Check mandatory properties - there must be a SimpleJdbcTemplate and an SQL statement plus a
* parameter source.
*/
@Override
@Override
public void afterPropertiesSet() {
Assert.notNull(namedParameterJdbcTemplate, "A DataSource or a NamedParameterJdbcTemplate is required.");
Assert.notNull(sql, "An SQL statement is required.");
@@ -154,11 +154,11 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
Assert.notNull(itemPreparedStatementSetter, "Using SQL statement with '?' placeholders requires an ItemPreparedStatementSetter");
}
}
/* (non-Javadoc)
* @see org.springframework.batch.item.ItemWriter#write(java.util.List)
*/
@Override
@Override
public void write(final List<? extends T> items) throws Exception {
if (!items.isEmpty()) {
@@ -168,7 +168,7 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
}
int[] updateCounts = null;
if (usingNamedParameters) {
SqlParameterSource[] batchArgs = new SqlParameterSource[items.size()];
int i = 0;
@@ -179,7 +179,7 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, InitializingBean {
}
else {
updateCounts = (int[]) namedParameterJdbcTemplate.getJdbcOperations().execute(sql, new PreparedStatementCallback() {
@Override
@Override
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
for (T item : items) {
itemPreparedStatementSetter.setValues(item, ps);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2009 the original author or authors.
* Copyright 2006-2013 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.
@@ -21,7 +21,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.JdbcUtils;
@@ -31,26 +30,27 @@ import org.springframework.util.ClassUtils;
/**
* <p>
* Simple item reader implementation that opens a JDBC cursor and continually retrieves the
* next row in the ResultSet.
* next row in the ResultSet.
* </p>
*
*
* <p>
* The statement used to open the cursor is created with the 'READ_ONLY' option since a non read-only
* cursor may unnecessarily lock tables or rows. It is also opened with 'TYPE_FORWARD_ONLY' option.
* By default the cursor will be opened using a separate connection which means that it will not participate
* The statement used to open the cursor is created with the 'READ_ONLY' option since a non read-only
* cursor may unnecessarily lock tables or rows. It is also opened with 'TYPE_FORWARD_ONLY' option.
* By default the cursor will be opened using a separate connection which means that it will not participate
* in any transactions created as part of the step processing.
* </p>
*
*
* <p>
* Each call to {@link #read()} will call the provided RowMapper, passing in the
* ResultSet.
* ResultSet.
* </p>
*
*
* @author Lucas Ward
* @author Peter Zozom
* @author Robert Kasanicky
* @author Thomas Risberg
*/
@SuppressWarnings("rawtypes")
public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
PreparedStatement preparedStatement;
@@ -68,7 +68,7 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
/**
* Set the RowMapper to be used for all calls to read().
*
*
* @param rowMapper
*/
public void setRowMapper(RowMapper rowMapper) {
@@ -79,7 +79,7 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
* Set the SQL statement to be used when creating the cursor. This statement
* should be a complete and valid SQL statement, as it will be run directly
* without any modification.
*
*
* @param sql
*/
public void setSql(String sql) {
@@ -89,7 +89,7 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
/**
* Set the PreparedStatementSetter to use if any parameter values that need
* to be set in the supplied query.
*
*
* @param preparedStatementSetter
*/
public void setPreparedStatementSetter(PreparedStatementSetter preparedStatementSetter) {
@@ -98,11 +98,11 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
/**
* Assert that mandatory properties are set.
*
*
* @throws IllegalArgumentException if either data source or sql properties
* not set.
*/
@Override
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
Assert.notNull(sql, "The SQL query must be provided");
@@ -110,7 +110,7 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
}
@Override
@Override
protected void openCursor(Connection con) {
try {
if (isUseSharedExtendedConnection()) {
@@ -131,20 +131,20 @@ public class JdbcCursorItemReader<T> extends AbstractCursorItemReader<T> {
close();
throw getExceptionTranslator().translate("Executing query", getSql(), se);
}
}
@Override
@Override
@SuppressWarnings("unchecked")
protected T readCursor(ResultSet rs, int currentRow) throws SQLException {
return (T) rowMapper.mapRow(rs, currentRow);
}
/**
* Close the cursor and database connection.
*/
@Override
@Override
protected void cleanupOnClose() throws Exception {
JdbcUtils.closeStatement(this.preparedStatement);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2013 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.
@@ -33,18 +33,18 @@ import org.springframework.util.Assert;
* {@link org.springframework.batch.item.ItemWriter} that is using a JPA
* EntityManagerFactory to merge any Entities that aren't part of the
* persistence context.
*
*
* It is required that {@link #write(List)} is called inside a transaction.<br/>
*
*
* The reader must be configured with an
* {@link javax.persistence.EntityManagerFactory} that is capable of
* participating in Spring managed transactions.
*
*
* The writer is thread safe after its properties are set (normal singleton
* behaviour), so it can be used to write in multiple concurrent transactions.
*
*
* @author Thomas Risberg
*
*
*/
public class JpaItemWriter<T> implements ItemWriter<T>, InitializingBean {
@@ -54,7 +54,7 @@ public class JpaItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Set the EntityManager to be used internally.
*
*
* @param entityManagerFactory the entityManagerFactory to set
*/
public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
@@ -64,7 +64,7 @@ public class JpaItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Check mandatory properties - there must be an entityManagerFactory.
*/
@Override
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(entityManagerFactory, "An EntityManagerFactory is required");
}
@@ -72,10 +72,10 @@ public class JpaItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Merge all provided items that aren't already in the persistence context
* and then flush the entity manager.
*
*
* @see org.springframework.batch.item.ItemWriter#write(java.util.List)
*/
@Override
@Override
public final void write(List<? extends T> items) {
EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
if (entityManager == null) {
@@ -88,7 +88,7 @@ public class JpaItemWriter<T> implements ItemWriter<T>, InitializingBean {
/**
* Do perform the actual write operation. This can be overridden in a
* subclass if necessary.
*
*
* @param entityManager the EntityManager to use for the operation
* @param items the list of items to use for the write
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2013 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.
@@ -36,7 +36,7 @@ import org.springframework.util.ClassUtils;
* {@link org.springframework.batch.item.ItemReader} for reading database
* records built on top of JPA.
* </p>
*
*
* <p>
* It executes the JPQL {@link #setQueryString(String)} to retrieve requested
* data. The query is executed using paged requests of a size specified in
@@ -44,39 +44,39 @@ import org.springframework.util.ClassUtils;
* {@link #read()} method is called, returning an object corresponding to
* current position.
* </p>
*
*
* <p>
* The performance of the paging depends on the JPA implementation and its use
* of database specific features to limit the number of returned rows.
* </p>
*
*
* <p>
* Setting a fairly large page size and using a commit interval that matches the
* page size should provide better performance.
* </p>
*
*
* <p>
* In order to reduce the memory usage for large results the persistence context
* is flushed and cleared after each page is read. This causes any entities read
* to be detached. If you make changes to the entities and want the changes
* persisted then you must explicitly merge the entities.
* </p>
*
*
* <p>
* The reader must be configured with an
* {@link javax.persistence.EntityManagerFactory}. All entity access is
* performed within a new transaction, independent of any existing Spring
* managed transactions.
* </p>
*
*
* <p>
* The implementation is thread-safe in between calls to
* {@link #open(ExecutionContext)}, but remember to use
* <code>saveState=false</code> if used in a multi-threaded client (no restart
* available).
* </p>
*
*
*
*
* @author Thomas Risberg
* @author Dave Syer
* @since 2.0
@@ -118,7 +118,7 @@ public class JpaPagingItemReader<T> extends AbstractPagingItemReader<T> {
/**
* The parameter values to be used for the query execution.
*
*
* @param parameterValues the values keyed by the parameter named used in
* the query string.
*/
@@ -126,7 +126,7 @@ public class JpaPagingItemReader<T> extends AbstractPagingItemReader<T> {
this.parameterValues = parameterValues;
}
@Override
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2009 the original author or authors.
* Copyright 2006-2013 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.
@@ -34,27 +34,28 @@ import org.springframework.util.ClassUtils;
/**
* <p>
* Item reader implementation that executes a stored procedure and then reads the returned cursor
* and continually retrieves the next row in the <code>ResultSet</code>.
* Item reader implementation that executes a stored procedure and then reads the returned cursor
* and continually retrieves the next row in the <code>ResultSet</code>.
* </p>
*
*
* <p>
* The callable statement used to open the cursor is created with the 'READ_ONLY' option as well as with the
* 'TYPE_FORWARD_ONLY' option. By default the cursor will be opened using a separate connection which means
* The callable statement used to open the cursor is created with the 'READ_ONLY' option as well as with the
* 'TYPE_FORWARD_ONLY' option. By default the cursor will be opened using a separate connection which means
* that it will not participate in any transactions created as part of the step processing.
* </p>
*
*
* <p>
* Each call to {@link #read()} will call the provided RowMapper, passing in the
* ResultSet.
* ResultSet.
* </p>
*
*
* <p>
* This class is modeled after the similar <code>JdbcCursorItemReader</code> class.
* This class is modeled after the similar <code>JdbcCursorItemReader</code> class.
* </p>
*
*
* @author Thomas Risberg
*/
@SuppressWarnings("rawtypes")
public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
private CallableStatement callableStatement;
@@ -62,15 +63,15 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
private PreparedStatementSetter preparedStatementSetter;
private String procedureName;
private String callString;
private RowMapper rowMapper;
private SqlParameter[] parameters = new SqlParameter[0];
private boolean function = false;
private int refCursorPosition = 0;
public StoredProcedureItemReader() {
@@ -80,7 +81,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
/**
* Set the RowMapper to be used for all calls to read().
*
*
* @param rowMapper
*/
public void setRowMapper(RowMapper rowMapper) {
@@ -91,7 +92,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
* Set the SQL statement to be used when creating the cursor. This statement
* should be a complete and valid SQL statement, as it will be run directly
* without any modification.
*
*
* @param sprocedureName
*/
public void setProcedureName(String sprocedureName) {
@@ -101,7 +102,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
/**
* Set the PreparedStatementSetter to use if any parameter values that need
* to be set in the supplied query.
*
*
* @param preparedStatementSetter
*/
public void setPreparedStatementSetter(PreparedStatementSetter preparedStatementSetter) {
@@ -109,15 +110,15 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
}
/**
* Add one or more declared parameters. Used for configuring this operation when used in a
* bean factory. Each parameter will specify SQL type and (optionally) the parameter's name.
*
* Add one or more declared parameters. Used for configuring this operation when used in a
* bean factory. Each parameter will specify SQL type and (optionally) the parameter's name.
*
* @param parameters Array containing the declared <code>SqlParameter</code> objects
*/
public void setParameters(SqlParameter[] parameters) {
this.parameters = parameters;
}
/**
* Set whether this stored procedure is a function.
*/
@@ -127,9 +128,9 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
/**
* Set the parameter position of the REF CURSOR. Only used for Oracle and
* PostgreSQL that use REF CURSORs. For any other database this should be
* PostgreSQL that use REF CURSORs. For any other database this should be
* kept as 0 which is the default.
*
*
* @param refCursorPosition The parameter position of the REF CURSOR
*/
public void setRefCursorPosition(int refCursorPosition) {
@@ -138,27 +139,27 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
/**
* Assert that mandatory properties are set.
*
*
* @throws IllegalArgumentException if either data source or sql properties
* not set.
*/
@Override
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
Assert.notNull(procedureName, "The name of the stored procedure must be provided");
Assert.notNull(rowMapper, "RowMapper must be provided");
}
@Override
@Override
protected void openCursor(Connection con) {
Assert.state(procedureName != null, "Procedure Name must not be null.");
Assert.state(refCursorPosition >= 0,
Assert.state(refCursorPosition >= 0,
"invalid refCursorPosition specified as " + refCursorPosition + "; it can't be " +
"specified as a negative number.");
Assert.state(refCursorPosition == 0 || refCursorPosition > 0,
"invalid refCursorPosition specified as " + refCursorPosition + "; there are " +
parameters.length + " parameters defined.");
Assert.state(refCursorPosition == 0 || refCursorPosition > 0,
"invalid refCursorPosition specified as " + refCursorPosition + "; there are " +
parameters.length + " parameters defined.");
CallMetaDataContext callContext = new CallMetaDataContext();
callContext.setAccessCallParameterMetaData(false);
@@ -170,7 +171,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
this.callString = callContext.createCallString();
log.debug("Call string is: " + callString);
int cursorSqlType = Types.OTHER;
if (function) {
if (cursorParameter instanceof SqlOutParameter) {
@@ -182,7 +183,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
cursorSqlType = parameters[refCursorPosition - 1].getSqlType();
}
}
try {
if (isUseSharedExtendedConnection()) {
callableStatement = con.prepareCall(callString, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
@@ -195,7 +196,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
if (this.preparedStatementSetter != null) {
preparedStatementSetter.setValues(callableStatement);
}
if (function) {
callableStatement.registerOutParameter(1, cursorSqlType);
}
@@ -225,7 +226,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
}
@Override
@Override
@SuppressWarnings("unchecked")
protected T readCursor(ResultSet rs, int currentRow) throws SQLException {
return (T) rowMapper.mapRow(rs, currentRow);
@@ -234,7 +235,7 @@ public class StoredProcedureItemReader<T> extends AbstractCursorItemReader<T> {
/**
* Close the cursor and database connection.
*/
@Override
@Override
protected void cleanupOnClose() throws Exception {
JdbcUtils.closeStatement(this.callableStatement);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2013 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.
@@ -21,44 +21,44 @@ import org.hibernate.Session;
import org.hibernate.StatelessSession;
/**
* <p>Abstract Hibernate Query Provider to serve as a base class for all
* <p>Abstract Hibernate Query Provider to serve as a base class for all
* Hibernate {@link Query} providers.</p>
*
* <p>The implementing provider can be configured to use either
* {@link StatelessSession} sufficient for simple mappings without the need
* to cascade to associated objects or standard Hibernate {@link Session}
*
* <p>The implementing provider can be configured to use either
* {@link StatelessSession} sufficient for simple mappings without the need
* to cascade to associated objects or standard Hibernate {@link Session}
* for more advanced mappings or when caching is desired.</p>
*
*
* @author Anatoly Polinsky
* @author Dave Syer
*
*
* @since 2.1
*
*/
public abstract class AbstractHibernateQueryProvider implements HibernateQueryProvider {
private StatelessSession statelessSession;
private Session statefulSession;
@Override
public void setStatelessSession(StatelessSession statelessSession) {
private StatelessSession statelessSession;
private Session statefulSession;
@Override
public void setStatelessSession(StatelessSession statelessSession) {
this.statelessSession = statelessSession;
}
@Override
@Override
public void setSession(Session statefulSession) {
this.statefulSession = statefulSession;
}
public boolean isStatelessSession() {
return this.statefulSession==null && this.statelessSession!=null;
}
protected StatelessSession getStatelessSession() {
return statelessSession;
return this.statefulSession==null && this.statelessSession!=null;
}
protected Session getStatefulSession() {
return statefulSession;
}
protected StatelessSession getStatelessSession() {
return statelessSession;
}
protected Session getStatefulSession() {
return statefulSession;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2013 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.
@@ -26,10 +26,10 @@ import org.springframework.beans.factory.InitializingBean;
* Abstract JPA Query Provider to serve as a base class for all JPA
* {@link Query} providers.
* </p>
*
*
* @author Anatoly Polinsky
* @author Dave Syer
*
*
* @since 2.1
*/
public abstract class AbstractJpaQueryProvider implements JpaQueryProvider, InitializingBean {
@@ -42,10 +42,10 @@ public abstract class AbstractJpaQueryProvider implements JpaQueryProvider, Init
* {@link HibernateQueryProvider}. This is currently needed to allow
* {@link HibernateQueryProvider} to participate in a user's managed transaction.
* </p>
*
*
* @param entityManager
*/
@Override
@Override
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
@@ -54,7 +54,7 @@ public abstract class AbstractJpaQueryProvider implements JpaQueryProvider, Init
* <p>
* Getter for {@link EntityManager}
* </p>
*
*
* @return entityManager the injected {@link EntityManager}
*/
protected EntityManager getEntityManager() {