@Test public void testCallBatchTasksAutoCommitTrueSynchronized() throws Exception { TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(connectionSource, null, Foo.class); ConnectionSource connectionSource = createMock(ConnectionSource.class); DatabaseConnection connection = createMock(DatabaseConnection.class); expect(connectionSource.isSingleConnection("foo")).andReturn(true); expect(connectionSource.getReadWriteConnection("foo")).andReturn(connection); expect(connectionSource.saveSpecialConnection(connection)).andReturn(false); connectionSource.releaseConnection(connection); expect(connection.isAutoCommitSupported()).andReturn(true); expect(connection.isAutoCommit()).andReturn(true); connection.setAutoCommit(false); connection.setAutoCommit(true); StatementExecutor<Foo, String> statementExec = new StatementExecutor<Foo, String>(databaseType, tableInfo, null); replay(connectionSource, connection); final AtomicBoolean called = new AtomicBoolean(false); statementExec.callBatchTasks(connectionSource, new Callable<Void>() { @Override public Void call() { called.set(true); return null; } }); assertTrue(called.get()); verify(connectionSource, connection); }
public <CT> CT callBatchTasks(ConnectionSource connectionSource, Callable<CT> callable) throws SQLException { if (connectionSource.isSingleConnection(tableInfo.getTableName())) { synchronized (this) { return doCallBatchTasks(connectionSource, callable); } } else { return doCallBatchTasks(connectionSource, callable); } }
StatementExecutor implements GenericRowMapper<String[]> { public <CT> CT callBatchTasks(ConnectionSource connectionSource, Callable<CT> callable) throws SQLException { if (connectionSource.isSingleConnection(tableInfo.getTableName())) { synchronized (this) { return doCallBatchTasks(connectionSource, callable); } } else { return doCallBatchTasks(connectionSource, callable); } } }
StatementExecutor implements GenericRowMapper<String[]> { public <CT> CT callBatchTasks(ConnectionSource connectionSource, Callable<CT> callable) throws SQLException { if (connectionSource.isSingleConnection(tableInfo.getTableName())) { synchronized (this) { return doCallBatchTasks(connectionSource, callable); } } else { return doCallBatchTasks(connectionSource, callable); } } StatementExecutor(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao); }
StatementExecutor implements GenericRowMapper<String[]> { public <CT> CT callBatchTasks(ConnectionSource connectionSource, Callable<CT> callable) throws SQLException { if (connectionSource.isSingleConnection(tableInfo.getTableName())) { synchronized (this) { return doCallBatchTasks(connectionSource, callable); } } else { return doCallBatchTasks(connectionSource, callable); } } StatementExecutor(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao); T queryForId(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache); T queryForFirst(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt, ObjectCache objectCache); List<T> queryForAll(ConnectionSource connectionSource, ObjectCache objectCache); long queryForCountStar(DatabaseConnection databaseConnection); long queryForLong(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt); long queryForLong(DatabaseConnection databaseConnection, String query, String[] arguments); List<T> query(ConnectionSource connectionSource, PreparedStmt<T> preparedStmt, ObjectCache objectCache); SelectIterator<T, ID> buildIterator(BaseDaoImpl<T, ID> classDao, ConnectionSource connectionSource,
			int resultFlags, ObjectCache objectCache); GenericRowMapper<T> getSelectStarRowMapper(); RawRowMapper<T> getRawRowMapper(); SelectIterator<T, ID> buildIterator(BaseDaoImpl<T, ID> classDao, ConnectionSource connectionSource,
			PreparedStmt<T> preparedStmt, ObjectCache objectCache, int resultFlags); GenericRawResults<String[]> queryRaw(ConnectionSource connectionSource, String query, String[] arguments,
			ObjectCache objectCache); GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query,
			RawRowMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache); GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
			RawRowObjectMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache); GenericRawResults<Object[]> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
			String[] arguments, ObjectCache objectCache); GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query,
			DatabaseResultsMapper<UO> mapper, String[] arguments, ObjectCache objectCache); int updateRaw(DatabaseConnection connection, String statement, String[] arguments); int executeRawNoArgs(DatabaseConnection connection, String statement); int executeRaw(DatabaseConnection connection, String statement, String[] arguments); int create(DatabaseConnection databaseConnection, T data, ObjectCache objectCache); int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache); int updateId(DatabaseConnection databaseConnection, T data, ID newId, ObjectCache objectCache); int update(DatabaseConnection databaseConnection, PreparedUpdate<T> preparedUpdate); int refresh(DatabaseConnection databaseConnection, T data, ObjectCache objectCache); int delete(DatabaseConnection databaseConnection, T data, ObjectCache objectCache); int deleteById(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache); int deleteObjects(DatabaseConnection databaseConnection, Collection<T> datas, ObjectCache objectCache); int deleteIds(DatabaseConnection databaseConnection, Collection<ID> ids, ObjectCache objectCache); int delete(DatabaseConnection databaseConnection, PreparedDelete<T> preparedDelete); CT callBatchTasks(ConnectionSource connectionSource, Callable<CT> callable); @Override String[] mapRow(DatabaseResults results); boolean ifExists(DatabaseConnection connection, ID id); }
StatementExecutor implements GenericRowMapper<String[]> { public <CT> CT callBatchTasks(ConnectionSource connectionSource, Callable<CT> callable) throws SQLException { if (connectionSource.isSingleConnection(tableInfo.getTableName())) { synchronized (this) { return doCallBatchTasks(connectionSource, callable); } } else { return doCallBatchTasks(connectionSource, callable); } } StatementExecutor(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao); T queryForId(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache); T queryForFirst(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt, ObjectCache objectCache); List<T> queryForAll(ConnectionSource connectionSource, ObjectCache objectCache); long queryForCountStar(DatabaseConnection databaseConnection); long queryForLong(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt); long queryForLong(DatabaseConnection databaseConnection, String query, String[] arguments); List<T> query(ConnectionSource connectionSource, PreparedStmt<T> preparedStmt, ObjectCache objectCache); SelectIterator<T, ID> buildIterator(BaseDaoImpl<T, ID> classDao, ConnectionSource connectionSource,
			int resultFlags, ObjectCache objectCache); GenericRowMapper<T> getSelectStarRowMapper(); RawRowMapper<T> getRawRowMapper(); SelectIterator<T, ID> buildIterator(BaseDaoImpl<T, ID> classDao, ConnectionSource connectionSource,
			PreparedStmt<T> preparedStmt, ObjectCache objectCache, int resultFlags); GenericRawResults<String[]> queryRaw(ConnectionSource connectionSource, String query, String[] arguments,
			ObjectCache objectCache); GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query,
			RawRowMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache); GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
			RawRowObjectMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache); GenericRawResults<Object[]> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes,
			String[] arguments, ObjectCache objectCache); GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query,
			DatabaseResultsMapper<UO> mapper, String[] arguments, ObjectCache objectCache); int updateRaw(DatabaseConnection connection, String statement, String[] arguments); int executeRawNoArgs(DatabaseConnection connection, String statement); int executeRaw(DatabaseConnection connection, String statement, String[] arguments); int create(DatabaseConnection databaseConnection, T data, ObjectCache objectCache); int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache); int updateId(DatabaseConnection databaseConnection, T data, ID newId, ObjectCache objectCache); int update(DatabaseConnection databaseConnection, PreparedUpdate<T> preparedUpdate); int refresh(DatabaseConnection databaseConnection, T data, ObjectCache objectCache); int delete(DatabaseConnection databaseConnection, T data, ObjectCache objectCache); int deleteById(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache); int deleteObjects(DatabaseConnection databaseConnection, Collection<T> datas, ObjectCache objectCache); int deleteIds(DatabaseConnection databaseConnection, Collection<ID> ids, ObjectCache objectCache); int delete(DatabaseConnection databaseConnection, PreparedDelete<T> preparedDelete); CT callBatchTasks(ConnectionSource connectionSource, Callable<CT> callable); @Override String[] mapRow(DatabaseResults results); boolean ifExists(DatabaseConnection connection, ID id);  }