@Test public void testSetBlobAsBytes() throws SQLException { byte[] content = "testContent".getBytes(); lobCreator.setBlobAsBytes(ps, 1, content); verify(ps).setBytes(1, content); }
this.lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) this.content); this.lobCreator.setBlobAsBytes(ps, paramIndex, ((String) this.content).getBytes()); this.lobCreator.setBlobAsBinaryStream(ps, paramIndex, (InputStream) this.content, this.length); this.lobCreator.setClobAsString(ps, paramIndex, (String) this.content); this.lobCreator.setClobAsAsciiStream(ps, paramIndex, (InputStream) this.content, this.length); this.lobCreator.setClobAsCharacterStream(ps, paramIndex, (Reader) this.content, this.length);
/** * Close the LobCreator, if any. */ @Override public void cleanup() { this.lobCreator.close(); }
@Test public void testCorrectCleanup() throws SQLException { SqlLobValue lob = new SqlLobValue("Bla", handler); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); lob.cleanup(); verify(creator).setClobAsString(preparedStatement, 1, "Bla"); verify(creator).close(); }
switch (sqlType) { case Types.CLOB: lobCreator.setClobAsString(ps, paramIndex, (String) param); break; case Types.BLOB: lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) param); break; case Types.TIME:
@Override public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, shortContext); if (longContext != null) { lobHandler.getLobCreator().setClobAsString(ps, 2, longContext); } else { ps.setNull(2, getClobTypeToUse()); } ps.setLong(3, executionId); } });
@Test public void testSetBlobAsBinaryStream() throws SQLException, IOException { InputStream bis = new ByteArrayInputStream("testContent".getBytes()); lobCreator.setBlobAsBinaryStream(ps, 1, bis, 11); verify(ps).setBinaryStream(1, bis, 11); }
@Test public void testSetClobAsCharacterStream() throws SQLException, IOException { Reader str = new StringReader("testContent"); lobCreator.setClobAsCharacterStream(ps, 1, str, 11); verify(ps).setCharacterStream(1, str, 11); }
@Test public void testSetClobAsAsciiStream() throws SQLException, IOException { InputStream bis = new ByteArrayInputStream("testContent".getBytes()); lobCreator.setClobAsAsciiStream(ps, 1, bis, 11); verify(ps).setAsciiStream(1, bis, 11); }
public void setValues(PreparedStatement ps, Object[] args, int[] argTypes, LobHandler lobHandler) throws SQLException { for (int i = 1; i <= args.length; i++) { Object arg = args[i - 1]; int argType = argTypes != null && argTypes.length >= i ? argTypes[i - 1] : SqlTypeValue.TYPE_UNKNOWN; if (argType == Types.BLOB && lobHandler != null && arg instanceof byte[]) { lobHandler.getLobCreator().setBlobAsBytes(ps, i, (byte[]) arg); } else if (argType == Types.BLOB && lobHandler != null && arg instanceof String) { lobHandler.getLobCreator().setBlobAsBytes(ps, i, arg.toString().getBytes()); } else if (argType == Types.CLOB && lobHandler != null) { lobHandler.getLobCreator().setClobAsString(ps, i, (String) arg); } else if ((argType == Types.DECIMAL || argType == Types.NUMERIC) && arg != null) { setDecimalValue(ps, i, arg, argType); } else { StatementCreatorUtils.setParameterValue(ps, i, verifyArgType(arg, argType), arg); } } }
@Override public void setValues(PreparedStatement ps, int i) throws SQLException { Long executionId = executionIdIterator.next(); String serializedContext = serializedContexts.get(executionId); String shortContext; String longContext; if (serializedContext.length() > shortContextLength) { // Overestimate length of ellipsis to be on the safe side with // 2-byte chars shortContext = serializedContext.substring(0, shortContextLength - 8) + " ..."; longContext = serializedContext; } else { shortContext = serializedContext; longContext = null; } ps.setString(1, shortContext); if (longContext != null) { lobHandler.getLobCreator().setClobAsString(ps, 2, longContext); } else { ps.setNull(2, getClobTypeToUse()); } ps.setLong(3, executionId); }
@Test public void testSetBlobAsBinaryStreamWithoutLength() throws SQLException, IOException { InputStream bis = new ByteArrayInputStream("testContent".getBytes()); lobCreator.setBlobAsBinaryStream(ps, 1, bis, -1); verify(ps).setBinaryStream(1, bis); }
@Test public void testSetClobAsCharacterStreamWithoutLength() throws SQLException, IOException { Reader str = new StringReader("testContent"); lobCreator.setClobAsCharacterStream(ps, 1, str, -1); verify(ps).setCharacterStream(1, str); }
@Test public void testSetClobAsAsciiStreamWithoutLength() throws SQLException, IOException { InputStream bis = new ByteArrayInputStream("testContent".getBytes()); lobCreator.setClobAsAsciiStream(ps, 1, bis, -1); verify(ps).setAsciiStream(1, bis); }
@Test public void test2() throws SQLException { String testString = "Bla"; SqlLobValue lob = new SqlLobValue(testString, handler); lob.setTypeValue(preparedStatement, 1, Types.BLOB, "test"); verify(creator).setBlobAsBytes(preparedStatement, 1, testString.getBytes()); }
if (sqlType == Types.BLOB) { if (this.content instanceof byte[] || this.content == null) { this.lobCreator.setBlobAsBytes(ps, paramIndex, (byte[]) this.content); this.lobCreator.setBlobAsBytes(ps, paramIndex, ((String) this.content).getBytes()); this.lobCreator.setBlobAsBinaryStream(ps, paramIndex, (InputStream) this.content, this.length); this.lobCreator.setClobAsString(ps, paramIndex, (String) this.content); this.lobCreator.setClobAsAsciiStream(ps, paramIndex, (InputStream) this.content, this.length); this.lobCreator.setClobAsCharacterStream(ps, paramIndex, (Reader) this.content, this.length);
lobHandler.getLobCreator().setBlobAsBytes(ps, i, (byte[]) arg); } else if (argType == Types.BLOB && lobHandler != null && arg instanceof String) { lobHandler.getLobCreator().setBlobAsBytes(ps, i, arg.toString().getBytes()); } else if (argType == Types.CLOB && lobHandler != null) { lobHandler.getLobCreator().setClobAsString(ps, i, (String) arg); } else if (arg!=null && argType == Types.DATE && arg instanceof Date) { Date clone = (Date) (((Date) arg).clone());
@Test public void testSetClobAsString() throws SQLException, IOException { String content = "testContent"; lobCreator.setClobAsString(ps, 1, content); verify(ps).setString(1, content); }
@Override public final Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { LobCreator lobCreator = this.lobHandler.getLobCreator(); try { setValues(ps, lobCreator); return ps.executeUpdate(); } finally { lobCreator.close(); } }
jdbcTemplate.execute( "update TABLE set BLOB = ? where PK = ?", new AbstractLobCreatingPreparedStatementCallback( lobHandler ) { @Override protected void setValues( PreparedStatement ps, LobCreator lobCreator ) throws SQLException { lobCreator.setBlobAsBinaryStream( ps, 1, stream, sizeInBytes ); ps.setLong( 2, pk ); } } );