use of org.springframework.jdbc.support.lob.LobCreator in project otter by alibaba.
the class DbDialectIntegration method doPreparedStatement.
private void doPreparedStatement(PreparedStatement ps, final DbDialect dbDialect, final Integer[] columnTypes, final String[] columnValues) throws SQLException {
LobCreator lobCreator = null;
for (int i = 0; i < columnTypes.length; i++) {
int paramIndex = i + 1;
String sqlValue = columnValues[i];
int sqlType = columnTypes[i];
Object param = SqlUtils.stringToSqlValue(sqlValue, sqlType, SqlUtils.isTextType(sqlType), dbDialect.isEmptyStringNulled());
switch(sqlType) {
case Types.CLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setClobAsString(ps, paramIndex, (String) param);
break;
case Types.BLOB:
if (lobCreator == null) {
lobCreator = dbDialect.getLobHandler().getLobCreator();
}
lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param);
break;
default:
StatementCreatorUtils.setParameterValue(ps, paramIndex, sqlType, null, param);
break;
}
}
}
use of org.springframework.jdbc.support.lob.LobCreator 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();
}
Aggregations