/** * INTERNAL: * Used by Oracle platforms during reading of ResultSet to free temporary LOBs. */ public void freeTemporaryObject(Object value) throws SQLException { if (value instanceof oracle.sql.CLOB && ((oracle.sql.CLOB)value).isTemporary()) { ((oracle.sql.CLOB)value).freeTemporary(); } else if (value instanceof oracle.sql.BLOB && ((oracle.sql.BLOB)value).isTemporary()) { ((oracle.sql.BLOB)value).freeTemporary(); } } }
/** * Returns the bytes from a result set * * @param res * The ResultSet to read from * @param columnName * The name of the column to read from * * @return The byte value from the column */ public byte[] getBytesFromClob(Clob clob_) { // read the bytes from an oracle blob // oracle.sql.CLOB clob = ((OracleResultSet) res).getBLOB(columnName); oracle.sql.CLOB clob = (CLOB)clob_; byte[] content = clob.getBytes(); return content; }
/** * INTERNAL: * Write LOB value - only on Oracle8 and up */ @SuppressWarnings("deprecation") public void writeLOB(DatabaseField field, Object value, ResultSet resultSet, AbstractSession session) throws SQLException { if (isBlob(field.getType())) { //change for 338585 to use getName instead of getNameDelimited oracle.sql.BLOB blob = (oracle.sql.BLOB)resultSet.getObject(field.getName()); //we could use the jdk 1.4 java.nio package and use channel/buffer for the writing //for the time being, simply use Oracle api. blob.putBytes(1, (byte[])value); //impose the locallization session.log(SessionLog.FINEST, SessionLog.SQL, "write_BLOB", Long.valueOf(blob.length()), field.getName()); } else if (isClob(field.getType())) { //change for 338585 to use getName instead of getNameDelimited oracle.sql.CLOB clob = (oracle.sql.CLOB)resultSet.getObject(field.getName()); //we could use the jdk 1.4 java.nio package and use channel/buffer for the writing //for the time being, simply use Oracle api. clob.putString(1, (String)value); //impose the locallization session.log(SessionLog.FINEST, SessionLog.SQL, "write_CLOB", Long.valueOf(clob.length()), field.getName()); } else { //do nothing for now, open to BFILE or NCLOB types } }
if (clob != null) clob.putString(1, value);
@Test public void shouldReturnContentsOfClobIFAllOkay() throws SQLException { CLOB clob = mock(CLOB.class); when(clob.length()).thenReturn(Long.valueOf("CLOB contents".length())); when(clob.getChars(eq(1l), eq(10000), any(char[].class))).thenReturn("CLOB contents".length()); // can't do this as we don't fill up the passed buffer //assertEquals("CLOB contents", new OracleClobNormaliser().normalise(clob)); new OracleClobNormaliser().transform(clob); } }
@Test public void shouldThrowCorrectExceptionIfClobIsLargerThanMaximum() throws SQLException { CLOB clob = mock(CLOB.class); when(clob.length()).thenReturn(10001l); expectedEx.expect(UnsupportedOperationException.class); expectedEx.expectMessage("Clobs larger than 10000 bytes are not supported by DBFIT"); new OracleClobNormaliser().transform(clob); }
wr = clob.getCharacterOutputStream(); if(content instanceof String)
"'"); pstmt = conn.prepareStatement(sql.toString()); pstmt.setClob(1, CLOB.empty_lob());
return CLOB.createTemporary( c3p0ProxyCon, cache, duration ); else throw new SQLException("Cannot create an oracle CLOB from a Connection that is neither an oracle.jdbc.driver.Connection, " +
if (clob != null) clob.putString(1, value); // Deprecated but what can you do
wr = clob.getCharacterOutputStream(); if(content instanceof String)
/** * Returns the bytes from a result set * * @param res * The ResultSet to read from * @param columnName * The name of the column to read from * * @return The byte value from the column */ public String getStringFromClob(Clob clob_) { // read the bytes from an oracle blob // oracle.sql.CLOB clob = ((OracleResultSet) res).getBLOB(columnName); oracle.sql.CLOB clob = (CLOB)clob_; byte[] content = clob.getBytes(); String ret = new String(content); return ret; }