@Override public Object getObject() { if (type == Value.CLOB) { return getReader(); } return getInputStream(); }
@Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException { long p = getPrecision(); if (p > Integer.MAX_VALUE || p <= 0) { p = -1; } if (type == Value.BLOB) { prep.setBinaryStream(parameterIndex, getInputStream(), (int) p); } else { prep.setCharacterStream(parameterIndex, getReader(), (int) p); } }
@Override public Value convertPrecision(long precision, boolean force) { if (this.precision <= precision) { return this; } ValueLob lob; if (type == CLOB) { lob = ValueLob.createClob(getReader(), precision); } else { lob = ValueLob.createBlob(getInputStream(), precision); } return lob; }
/** * Create an independent copy of this temporary value. * The file will not be deleted automatically. * * @return the value */ @Override public ValueLob copyToTemp() { ValueLob lob; if (type == CLOB) { lob = ValueLob.createClob(getReader(), precision); } else { lob = ValueLob.createBlob(getInputStream(), precision); } return lob; }
@Override public String getString() { int len = precision > Integer.MAX_VALUE || precision == 0 ? Integer.MAX_VALUE : (int) precision; try { if (type == Value.CLOB) { if (small != null) { return new String(small, Constants.UTF8); } return IOUtils.readStringAndClose(getReader(), len); } byte[] buff; if (small != null) { buff = small; } else { buff = IOUtils.readBytesAndClose(getInputStream(), len); } return StringUtils.convertBytesToHex(buff); } catch (IOException e) { throw DbException.convertIOException(e, fileName); } }
/** * 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) { ValueLob copy = ValueLob.createClob(getReader(), -1); return copy; } else if (t == Value.BLOB) { ValueLob copy = ValueLob.createBlob(getInputStream(), -1); return copy; } return super.convertTo(t); }
/** * Store the lob data to a file if the size of the buffer is larger than the * maximum size for an in-place lob. * * @param h the data handler */ public void convertToFileIfRequired() { try { if (small != null && small.length > getMaxLengthInplaceLob()) { int len = getBufferSize(Long.MAX_VALUE); int tabId = tableId; if (type == Value.BLOB) { createFromStream( DataUtils.newBytes(len), 0, getInputStream(), Long.MAX_VALUE); } else { createFromReader( new char[len], 0, getReader(), Long.MAX_VALUE); } Value v2 = link(tabId); if (SysProperties.CHECK && v2 != this) { DbException.throwInternalError(); } } } catch (IOException e) { throw DbException.convertIOException(e, null); } }