Projects >> bonecp >>bae77157c64b22116da1cd14fb20031ca3ca871a

Chunk
Conflicting content
		this.logStatementsEnabled = logStatementsEnabled;
	}

<<<<<<< HEAD
	/** Check that the connection was closed before the GC reclaimed it.
	 */
	protected void doFinalize(){
		try {
			if (!isClosed()){
				close();
				logger.warn("BoneCP detected an unclosed connection and has closed it for you. " +
				"You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.");
			}
		} catch (Throwable t) {
			logger.error("An error was detected when trying to close off a connection", t);
=======
	/** {@inheritDoc}
	 * @see java.lang.Object#finalize()
	 *
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		if (!isClosed()){
			try{
				close();
				logger.warn("BoneCP detected an unclosed connection and has closed it for you. " +
				"You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.");
			} catch (Throwable t){
				// exceptions here are dangerous! 
			}
>>>>>>> 1c00ada06af6dca77432cf3a9142c2cfbe45d175
		}

	}
Solution content
		this.logStatementsEnabled = logStatementsEnabled;
	}

	/** Check that the connection was closed before the GC reclaimed it.
	 *
	protected void doFinalize(){
		try {
			if (!isClosed()){
				close();
				logger.warn("BoneCP detected an unclosed connection and has closed it for you. " +
				"You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.");
			}
		} catch (Throwable t) {
			logger.error("An error was detected when trying to close off a connection", t);
		}

	}
File
ConnectionHandle.java
Developer's decision
Combination
Kind of conflict
Catch clause
Comment
If statement
Method invocation
Method signature
Try statement
Chunk
Conflicting content
	/** {@inheritDoc}
	 * @see java.lang.Object#finalize()
<<<<<<< HEAD
	 *
=======
	 * Uncomment this only if you're willing to deal with the performance hit!
>>>>>>> 1c00ada06af6dca77432cf3a9142c2cfbe45d175
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
Solution content
	/** {@inheritDoc}
	 * @see java.lang.Object#finalize()
	 * Uncomment this only if you're willing to deal with the performance hit!
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
File
StatementHandle.java
Developer's decision
Version 2
Kind of conflict
Comment
Chunk
Conflicting content
				logger.warn("BoneCP detected an unclosed statement and didn't manage to close it for you. You should be closing this statement in your application - enable connectionWatch and statement caching for additional debugging assistance.");
			}
		}
<<<<<<< HEAD
	} */
=======
	}
	*/
>>>>>>> 1c00ada06af6dca77432cf3a9142c2cfbe45d175
}
Solution content
				logger.warn("BoneCP detected an unclosed statement and didn't manage to close it for you. You should be closing this statement in your application - enable connectionWatch and statement caching for additional debugging assistance.");
			}
		}
	} */
	*/
}
File
StatementHandle.java
Developer's decision
Combination
Kind of conflict
Comment
Chunk
Conflicting content
	/** Connection handle to return. */
	private Connection connection = null;
	/** called to return. */
<<<<<<< HEAD
	private static MockJDBCAnswer mockJDBCAnswer;
	/** Instance. */
	private static MockJDBCDriver driverInstance;
=======
	private MockJDBCAnswer mockJDBCAnswer;
>>>>>>> 1c00ada06af6dca77432cf3a9142c2cfbe45d175

	/**
	 * Default constructor
Solution content
	/** Connection handle to return. */
	private Connection connection = null;
	/** called to return. */
	private MockJDBCAnswer mockJDBCAnswer;
	/** Instance. */
	private static MockJDBCDriver driverInstance;

	/**
	 * Default constructor
File
MockJDBCDriver.java
Developer's decision
Combination
Kind of conflict
Attribute
Comment
Chunk
Conflicting content
	
	/** 
	 * Disable everything.
<<<<<<< HEAD
	 * @param disabled 
	 * @throws SQLException 
	 */
	public static void disable(boolean disabled) throws SQLException{
		MockJDBCDriver.disabled = disabled;
		if (disabled){
			DriverManager.deregisterDriver(driverInstance);
		}
=======
	 * @throws SQLException 
	 */
	public void disable() throws SQLException{
		DriverManager.deregisterDriver(this);
	}

	/**
	 * @return the connection
	 */
	public Connection getConnection() {
		return this.connection;
	}

	/**
	 * @param connection the connection to set
	 */
	public void setConnection(Connection connection) {
		this.connection = connection;
>>>>>>> 1c00ada06af6dca77432cf3a9142c2cfbe45d175
	}
}
Solution content
	
	/** 
	 * Disable everything.
	 * @throws SQLException 
	 * @throws SQLException 
	 */
	public static void disable(boolean disabled) throws SQLException{
		MockJDBCDriver.disabled = disabled;
		if (disabled){
			DriverManager.deregisterDriver(driverInstance);
		}
	}

	/**
	 * @return the connection
	 */
	public Connection getConnection() {
		return this.connection;
	}

	/**
	 * @param connection the connection to set
	 */
	public void setConnection(Connection connection) {
		this.connection = connection;
	}
}
File
MockJDBCDriver.java
Developer's decision
Combination
Kind of conflict
Attribute
Comment
If statement
Method declaration
Method signature
Chunk
Conflicting content
	static Connection mockConnection3; 
	
	@BeforeClass
<<<<<<< HEAD
	public static void enableMockDriver() throws SQLException{
		MockJDBCDriver.disable(false);
	}
	
	@AfterClass
	public static void disableMockDriver() throws SQLException{
		MockJDBCDriver.disable(true);
=======
	public static void beforeClass(){
		mockConnection = createNiceMock(ConnectionHandle.class);
		// make it return a new connection when asked for again
		mockConnection2 = createNiceMock(Connection.class);
		mockConnection3 = createNiceMock(Connection.class);
		mockCallableStatement = createNiceMock(CallableStatement.class);
		mockStatement = createNiceMock(Statement.class);
		mockPreparedStatement = createNiceMock(PreparedStatement.class);
	}
	@Before
	public void before(){
		reset(mockConnection, mockConnection2, mockConnection3, mockCallableStatement, mockPreparedStatement, mockStatement);
>>>>>>> 1c00ada06af6dca77432cf3a9142c2cfbe45d175
	}
	/** Tests that the statements and connections are proxified.
	 * @throws SQLException
Solution content
	static Connection mockConnection3; 
	
	@BeforeClass
	public static void beforeClass(){
		mockConnection = createNiceMock(ConnectionHandle.class);
		// make it return a new connection when asked for again
		mockConnection2 = createNiceMock(Connection.class);
		mockConnection3 = createNiceMock(Connection.class);
		mockCallableStatement = createNiceMock(CallableStatement.class);
		mockStatement = createNiceMock(Statement.class);
		mockPreparedStatement = createNiceMock(PreparedStatement.class);
	}
	@Before
	public void before(){
		reset(mockConnection, mockConnection2, mockConnection3, mockCallableStatement, mockPreparedStatement, mockStatement);
	}
	/** Tests that the statements and connections are proxified.
	 * @throws SQLException
File
TestMemorizeTransactionProxy.java
Developer's decision
Version 2
Kind of conflict
Annotation
Method declaration
Method invocation
Method signature
Chunk
Conflicting content
		MockJDBCDriver mockDriver = new MockJDBCDriver(mockConnection);
		CommonTestUtils.config.setTransactionRecoveryEnabled(true);
<<<<<<< HEAD
		String jdbcDriver = CommonTestUtils.config.getJdbcUrl();
		CommonTestUtils.config.setJdbcUrl("jdbc:mock:driver");
=======
		CommonTestUtils.config.setJdbcUrl("jdbc:mock:driver2");
		CommonTestUtils.config.setReleaseHelperThreads(0);
>>>>>>> 1c00ada06af6dca77432cf3a9142c2cfbe45d175
		BoneCP pool = new BoneCP(CommonTestUtils.config);
		CommonTestUtils.config.setTransactionRecoveryEnabled(false);
		expect(mockConnection.prepareCall("")).andReturn(mockCallableStatement).anyTimes();
Solution content
		MockJDBCDriver mockDriver = new MockJDBCDriver(mockConnection);
		CommonTestUtils.config.setTransactionRecoveryEnabled(true);
		CommonTestUtils.config.setJdbcUrl("jdbc:mock:driver2");
		CommonTestUtils.config.setReleaseHelperThreads(0);
		BoneCP pool = new BoneCP(CommonTestUtils.config);
		CommonTestUtils.config.setTransactionRecoveryEnabled(false);
		expect(mockConnection.prepareCall("")).andReturn(mockCallableStatement).anyTimes();
File
TestMemorizeTransactionProxy.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content

		handler = java.lang.reflect.Proxy.getInvocationHandler(stmt);
		assertEquals(MemorizeTransactionProxy.class, handler.getClass());
<<<<<<< HEAD
		CommonTestUtils.config.setJdbcUrl(jdbcDriver);
		CommonTestUtils.config.setTransactionRecoveryEnabled(false);
=======

		
		// fake stuff to test for clear
		((ConnectionHandle)con).getReplayLog().add(new ReplayLog(null, null, null));
		((ConnectionHandle)con).recoveryResult.getReplaceTarget().put("test", "test1");
		con.rollback(); // should clear out log
		assertTrue(((ConnectionHandle)con).getReplayLog().isEmpty());
		assertTrue(((ConnectionHandle)con).recoveryResult.getReplaceTarget().isEmpty());

		// fake stuff to test for clear
		((ConnectionHandle)con).getReplayLog().add(new ReplayLog(null, null, null));
		((ConnectionHandle)con).recoveryResult.getReplaceTarget().put("test", "test1");
		con.commit(); // should clear out log
		assertTrue(((ConnectionHandle)con).getReplayLog().isEmpty());
		assertTrue(((ConnectionHandle)con).recoveryResult.getReplaceTarget().isEmpty());

		assertNotNull(((ConnectionHandle)con).getProxyTarget());
		mockDriver.disable();
	}
	
	static int count = 1;
	
	@Test
	public void testReplayTransaction() throws IllegalArgumentException, Throwable{
		
		count = 1;

		MockJDBCDriver mockDriver = new MockJDBCDriver(new MockJDBCAnswer() {
			
			@Override
			public Connection answer() throws SQLException {
				if (count == 1){
					return TestMemorizeTransactionProxy.this.mockConnection;
				}
				return TestMemorizeTransactionProxy.this.mockConnection2;
			}
		}); 
		
		
		CommonTestUtils.config.setTransactionRecoveryEnabled(true);
		CommonTestUtils.config.setJdbcUrl("jdbc:mock:driver");
		CommonTestUtils.config.setMinConnectionsPerPartition(2);
		CommonTestUtils.config.setMaxConnectionsPerPartition(2);
		BoneCP pool = new BoneCP(CommonTestUtils.config);
		reset(mockConnection);
		CommonTestUtils.config.setTransactionRecoveryEnabled(false);

		EasyMock.makeThreadSafe(mockConnection, true);
		String prepCall = "whatever2";
		expect(mockConnection.prepareStatement("whatever")).andReturn(mockPreparedStatement).anyTimes();
		expect(mockConnection.prepareCall(prepCall)).andReturn(mockCallableStatement).anyTimes();
		expect(mockConnection.createStatement()).andReturn(mockStatement).anyTimes();
		
		// trigger a replay
		expect(mockPreparedStatement.execute()).andThrow(new SQLException("", "08S01")).once();
		
		// This connection should be closed off
		mockConnection.close(); // remember that this is the internal connection
		expectLastCall().once();
//		.andThrow(new SQLException("just a fake exception for code coverage")).once();

		
		// we should be getting a new connection and everything replayed on it
		PreparedStatement mockPreparedStatement2 = createStrictMock(PreparedStatement.class);
		expect(mockConnection2.prepareStatement("whatever")).andReturn(mockPreparedStatement2).anyTimes();
		mockPreparedStatement2.setInt(1, 1);
		expectLastCall().once();
		expect(mockPreparedStatement2.execute()).andReturn(true).once();
		
		CallableStatement mockCallableStatement2 = createStrictMock(CallableStatement.class);
		expect(mockConnection2.prepareCall(prepCall)).andReturn(mockCallableStatement2).anyTimes();
		mockCallableStatement2.clearWarnings();
		expectLastCall().once();
		
		Statement mockStatement2 = createStrictMock(Statement.class);
		expect(mockConnection2.createStatement()).andReturn(mockStatement2).anyTimes();
		mockStatement2.clearWarnings();
		expectLastCall().once();
		
		replay(mockConnection, mockPreparedStatement,mockConnection2, mockPreparedStatement2, mockCallableStatement2, mockStatement, mockStatement2);
		
		Connection con = pool.getConnection();
		count=0;

		mockDriver.setConnection(mockConnection2);
		
		PreparedStatement ps = con.prepareStatement("whatever");
		ps.setInt(1, 1);
		CallableStatement cs = con.prepareCall(prepCall);
		cs.clearWarnings();
		Statement stmt = con.createStatement();
		stmt.clearWarnings();
		ps.execute();    
		con.close();
		
		verify(mockConnection, mockPreparedStatement,mockConnection2, mockPreparedStatement2, mockCallableStatement2, mockStatement, mockStatement2);
		
		mockDriver.disable();
>>>>>>> 1c00ada06af6dca77432cf3a9142c2cfbe45d175
		
	}
	
Solution content
		handler = java.lang.reflect.Proxy.getInvocationHandler(stmt);
		assertEquals(MemorizeTransactionProxy.class, handler.getClass());

		
		// fake stuff to test for clear
		((ConnectionHandle)con).getReplayLog().add(new ReplayLog(null, null, null));
		((ConnectionHandle)con).recoveryResult.getReplaceTarget().put("test", "test1");
		con.rollback(); // should clear out log
		assertTrue(((ConnectionHandle)con).getReplayLog().isEmpty());
		assertTrue(((ConnectionHandle)con).recoveryResult.getReplaceTarget().isEmpty());

		// fake stuff to test for clear
		((ConnectionHandle)con).getReplayLog().add(new ReplayLog(null, null, null));
		((ConnectionHandle)con).recoveryResult.getReplaceTarget().put("test", "test1");
		con.commit(); // should clear out log
		assertTrue(((ConnectionHandle)con).getReplayLog().isEmpty());
		assertTrue(((ConnectionHandle)con).recoveryResult.getReplaceTarget().isEmpty());

		assertNotNull(((ConnectionHandle)con).getProxyTarget());
		mockDriver.disable();
	}
	
	static int count = 1;

	
	@Test
	public void testReplayTransaction() throws IllegalArgumentException, Throwable{
		
		count = 1;

		MockJDBCDriver mockDriver = new MockJDBCDriver(new MockJDBCAnswer() {
			
			@Override
			public Connection answer() throws SQLException {
				if (count == 1){
					return TestMemorizeTransactionProxy.this.mockConnection;
				}
				return TestMemorizeTransactionProxy.this.mockConnection2;
			}
		}); 
		
		
		CommonTestUtils.config.setTransactionRecoveryEnabled(true);
		CommonTestUtils.config.setJdbcUrl("jdbc:mock:driver");
		CommonTestUtils.config.setMinConnectionsPerPartition(2);
		CommonTestUtils.config.setMaxConnectionsPerPartition(2);
		BoneCP pool = new BoneCP(CommonTestUtils.config);
		reset(mockConnection);
		CommonTestUtils.config.setTransactionRecoveryEnabled(false);

		EasyMock.makeThreadSafe(mockConnection, true);
		String prepCall = "whatever2";
		expect(mockConnection.prepareStatement("whatever")).andReturn(mockPreparedStatement).anyTimes();
		expect(mockConnection.prepareCall(prepCall)).andReturn(mockCallableStatement).anyTimes();
		expect(mockConnection.createStatement()).andReturn(mockStatement).anyTimes();
		
		// trigger a replay
		expect(mockPreparedStatement.execute()).andThrow(new SQLException("", "08S01")).once();
		
		// This connection should be closed off
		mockConnection.close(); // remember that this is the internal connection
		expectLastCall().once();
//		.andThrow(new SQLException("just a fake exception for code coverage")).once();

		
		// we should be getting a new connection and everything replayed on it
		PreparedStatement mockPreparedStatement2 = createStrictMock(PreparedStatement.class);
		expect(mockConnection2.prepareStatement("whatever")).andReturn(mockPreparedStatement2).anyTimes();
		mockPreparedStatement2.setInt(1, 1);
		expectLastCall().once();
		expect(mockPreparedStatement2.execute()).andReturn(true).once();
		
		CallableStatement mockCallableStatement2 = createStrictMock(CallableStatement.class);
		expect(mockConnection2.prepareCall(prepCall)).andReturn(mockCallableStatement2).anyTimes();
		mockCallableStatement2.clearWarnings();
		expectLastCall().once();
		
		Statement mockStatement2 = createStrictMock(Statement.class);
		expect(mockConnection2.createStatement()).andReturn(mockStatement2).anyTimes();
		mockStatement2.clearWarnings();
		expectLastCall().once();
		
		replay(mockConnection, mockPreparedStatement,mockConnection2, mockPreparedStatement2, mockCallableStatement2, mockStatement, mockStatement2);
		
		Connection con = pool.getConnection();
		count=0;

		mockDriver.setConnection(mockConnection2);
		
		PreparedStatement ps = con.prepareStatement("whatever");
		ps.setInt(1, 1);
		CallableStatement cs = con.prepareCall(prepCall);
		cs.clearWarnings();
		Statement stmt = con.createStatement();
		stmt.clearWarnings();
		ps.execute();    
		con.close();
		
		verify(mockConnection, mockPreparedStatement,mockConnection2, mockPreparedStatement2, mockCallableStatement2, mockStatement, mockStatement2);
		
		mockDriver.disable();
		
	}
	
File
TestMemorizeTransactionProxy.java
Developer's decision
Version 2
Kind of conflict
Annotation
Attribute
Comment
Method invocation
Method signature
Variable