Search in sources :

Example 1 with LobHandler

use of org.springframework.jdbc.support.lob.LobHandler in project spring-framework by spring-projects.

the class LobSupportTests method testCreatingPreparedStatementCallback.

@Test
public void testCreatingPreparedStatementCallback() throws SQLException {
    LobHandler handler = mock(LobHandler.class);
    LobCreator creator = mock(LobCreator.class);
    PreparedStatement ps = mock(PreparedStatement.class);
    given(handler.getLobCreator()).willReturn(creator);
    given(ps.executeUpdate()).willReturn(3);
    class SetValuesCalled {

        boolean b = false;
    }
    final SetValuesCalled svc = new SetValuesCalled();
    AbstractLobCreatingPreparedStatementCallback psc = new AbstractLobCreatingPreparedStatementCallback(handler) {

        @Override
        protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException, DataAccessException {
            svc.b = true;
        }
    };
    assertEquals(Integer.valueOf(3), psc.doInPreparedStatement(ps));
    assertTrue(svc.b);
    verify(creator).close();
    verify(handler).getLobCreator();
    verify(ps).executeUpdate();
}
Also used : PreparedStatement(java.sql.PreparedStatement) LobHandler(org.springframework.jdbc.support.lob.LobHandler) LobCreator(org.springframework.jdbc.support.lob.LobCreator) Test(org.junit.Test)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 Test (org.junit.Test)1 LobCreator (org.springframework.jdbc.support.lob.LobCreator)1 LobHandler (org.springframework.jdbc.support.lob.LobHandler)1