@Override public void unlink(DataHandler database) { if (small == null && tableId != LobStorage.TABLE_ID_SESSION_VARIABLE) { database.getLobStorage().setTable(this, LobStorage.TABLE_ID_SESSION_VARIABLE); tableId = LobStorage.TABLE_ID_SESSION_VARIABLE; } }
/** * Create a Clob value from this reader. * * @param x the reader * @param length the length (if smaller or equal than 0, all data until the * end of file is read) * @return the value */ public Value createClob(Reader x, long length) { if (x == null) { return ValueNull.INSTANCE; } if (length <= 0) { length = -1; } Value v = session.getDataHandler().getLobStorage().createClob(x, length); return v; }
/** * Create a Blob value from this input stream. * * @param x the input stream * @param length the length (if smaller or equal than 0, all data until the * end of file is read) * @return the value */ public Value createBlob(InputStream x, long length) { if (x == null) { return ValueNull.INSTANCE; } if (length <= 0) { length = -1; } Value v = session.getDataHandler().getLobStorage().createBlob(x, length); return v; }
/** * Create an independent copy of this value, * that will be bound to a result. * * @return the value (this for small objects) */ @Override public ValueLob copyToResult() { if (handler == null) { return this; } LobStorage s = handler.getLobStorage(); if (s.isReadOnly()) { return this; } return s.copyLob(this, LobStorage.TABLE_RESULT, getPrecision()); }
/** * Create a new empty Clob object. * * @return the object */ @Override public Clob createClob() throws SQLException { try { int id = getNextTraceId(TraceObject.CLOB); debugCodeAssign("Clob", TraceObject.CLOB, id, "createClob()"); checkClosed(); Value v = session.getDataHandler().getLobStorage() .createClob(new InputStreamReader(new ByteArrayInputStream(Utils.EMPTY_BYTES)), 0); return new JdbcClob(this, v, id); } catch (Exception e) { throw logAndConvert(e); } }
@Override public InputStream getInputStream() { if (small != null) { return new ByteArrayInputStream(small); } else if (fileName != null) { FileStorage fileStorage = handler.openFile(fileName, "r", true); boolean alwaysClose = SysProperties.LOB_CLOSE_BETWEEN_READS; return new BufferedInputStream(new FileStorageInputStream(fileStorage, handler, false, alwaysClose), Constants.IO_BUFFER_SIZE); } long byteCount = (type == Value.BLOB) ? precision : -1; try { return handler.getLobStorage().getInputStream(this, hmac, byteCount); } catch (IOException e) { throw DbException.convertIOException(e, toString()); } }
/** * Create a new empty NClob object. * * @return the object */ // ## Java 1.6 ## @Override public NClob createNClob() throws SQLException { try { int id = getNextTraceId(TraceObject.CLOB); debugCodeAssign("NClob", TraceObject.CLOB, id, "createNClob()"); checkClosed(); Value v = session.getDataHandler().getLobStorage() .createClob(new InputStreamReader(new ByteArrayInputStream(Utils.EMPTY_BYTES)), 0); return new JdbcClob(this, v, id); } catch (Exception e) { throw logAndConvert(e); } }
@Override public void close() { if (fileName != null) { if (tempFile != null) { tempFile.stopAutoDelete(); } // synchronize on the database, to avoid concurrent temp file // creation / deletion / backup synchronized (handler.getLobSyncObject()) { FileUtils.delete(fileName); } } if (handler != null) { handler.getLobStorage().removeLob(this); } }
@Override public Value link(DataHandler database, int tabId) { if (small == null) { if (tableId == LobStorage.TABLE_TEMP) { database.getLobStorage().setTable(this, tabId); this.tableId = tabId; } else { return handler.getLobStorage().copyLob(this, tabId, getPrecision()); } } else if (small.length > database.getMaxLengthInplaceLob()) { LobStorage s = database.getLobStorage(); Value v; if (type == Value.BLOB) { v = s.createBlob(getInputStream(), getPrecision()); } else { v = s.createClob(getReader(), getPrecision()); } return v.link(database, tabId); } return this; }
/** * Convert a lob to another data type. The data is fully read in memory * except when converting to BLOB or CLOB. * * @param t the new type * @return the converted value */ @Override public Value convertTo(int t) { if (t == type) { return this; } else if (t == Value.CLOB) { if (handler != null) { Value copy = handler.getLobStorage().createClob(getReader(), -1); return copy; } else if (small != null) { return ValueLob.createSmallLob(t, small); } } else if (t == Value.BLOB) { if (handler != null) { Value copy = handler.getLobStorage().createBlob(getInputStream(), -1); return copy; } else if (small != null) { return ValueLob.createSmallLob(t, small); } } return super.convertTo(t); }
/** * Create a new empty Blob object. * * @return the object */ @Override public Blob createBlob() throws SQLException { try { int id = getNextTraceId(TraceObject.BLOB); debugCodeAssign("Blob", TraceObject.BLOB, id, "createClob()"); checkClosed(); Value v = session.getDataHandler().getLobStorage().createBlob(new ByteArrayInputStream(Utils.EMPTY_BYTES), 0); return new JdbcBlob(this, v, id); } catch (Exception e) { throw logAndConvert(e); } }
v = ValueNull.INSTANCE; } else { v = session.getDataHandler().getLobStorage().createClob(new BufferedReader(in), -1); InputStream in = rs.getBinaryStream(columnIndex); v = (in == null) ? (Value) ValueNull.INSTANCE : session.getDataHandler().getLobStorage().createBlob(in, -1);
} else if (x instanceof java.io.Reader) { Reader r = new BufferedReader((java.io.Reader) x); return session.getDataHandler().getLobStorage().createClob(r, -1); } else if (x instanceof java.sql.Clob) { try { Reader r = new BufferedReader(((java.sql.Clob) x).getCharacterStream()); return session.getDataHandler().getLobStorage().createClob(r, -1); } catch (SQLException e) { throw DbException.convert(e); return session.getDataHandler().getLobStorage().createBlob((java.io.InputStream) x, -1); } else if (x instanceof java.sql.Blob) { try { return session.getDataHandler().getLobStorage().createBlob(((java.sql.Blob) x).getBinaryStream(), -1); } catch (SQLException e) { throw DbException.convert(e);
transfer.verifyLobMac(hmac, lobId); if (in.getPos() != offset) { LobStorage lobStorage = session.getDataHandler().getLobStorage();