Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
mminella committed Nov 30, 2017
1 parent dca726a commit 1c9c30c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
* @author Peter Zozom
* @author Robert Kasanicky
* @author Thomas Risberg
* @author Michael Minella
*/
public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
implements InitializingBean {
Expand Down Expand Up @@ -134,9 +135,9 @@ public abstract class AbstractCursorItemReader<T> extends AbstractItemCountingIt

private boolean useSharedExtendedConnection = false;

private Boolean connectionAutoCommit;
private boolean connectionAutoCommit;

private Boolean initialConnectionAutoCommit;
private boolean initialConnectionAutoCommit;

public AbstractCursorItemReader() {
super();
Expand Down Expand Up @@ -364,20 +365,12 @@ public boolean isUseSharedExtendedConnection() {
* Connection / Datasource default configuration.
*
* @param autoCommit value used for {@link Connection#setAutoCommit(boolean)}.
* @since 4.0
*/
public void setConnectionAutoCommit(boolean autoCommit) {
this.connectionAutoCommit = autoCommit;
}

/**
* Return whether "autoCommit" should be overridden for the connection used by the cursor.
*
* @return the "autoCommit" value, or {@code null} if none to be applied.
*/
public Boolean getConnectionAutoCommit() {
return this.connectionAutoCommit;
}

public abstract String getSql();

/**
Expand All @@ -402,9 +395,9 @@ protected void doClose() throws Exception {
JdbcUtils.closeResultSet(this.rs);
rs = null;
cleanupOnClose();
if (this.initialConnectionAutoCommit != null) {
this.con.setAutoCommit(initialConnectionAutoCommit);
}

this.con.setAutoCommit(initialConnectionAutoCommit);

if (useSharedExtendedConnection && dataSource instanceof ExtendedConnectionDataSourceProxy) {
((ExtendedConnectionDataSourceProxy)dataSource).stopCloseSuppression(this.con);
if (!TransactionSynchronizationManager.isActualTransactionActive()) {
Expand Down Expand Up @@ -449,8 +442,10 @@ protected void initializeConnection() {
else {
this.con = dataSource.getConnection();
}
if (this.connectionAutoCommit != null && this.con.getAutoCommit() != this.connectionAutoCommit) {
this.initialConnectionAutoCommit = this.con.getAutoCommit();

this.initialConnectionAutoCommit = this.con.getAutoCommit();

if (this.con.getAutoCommit() != this.connectionAutoCommit) {
this.con.setAutoCommit(this.connectionAutoCommit);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@
*/
package org.springframework.batch.item.database;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.sql.DataSource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;

import org.springframework.batch.item.ExecutionContext;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(JUnit4.class)
public class JdbcCursorItemReaderConfigTests {

Expand Down Expand Up @@ -107,8 +107,8 @@ public Void doInTransaction(TransactionStatus status) {

@Test
public void testOverrideConnectionAutoCommit() throws Exception {
boolean initialAutoCommit= false;
boolean neededAutoCommit = true;
boolean initialAutoCommit= false;
boolean neededAutoCommit = true;

DataSource ds = mock(DataSource.class);
Connection con = mock(Connection.class);
Expand Down

0 comments on commit 1c9c30c

Please sign in to comment.