use of javax.sql.rowset.serial.SerialBlob in project jdk8u_jdk by JetBrains.
the class SerialBlobTests method test22.
/*
* Validate that setBytes will properly write a set of bytes to the
* specified location in the SerialBlob and the correct count is returned
* for bytes written
*/
@Test
public void test22() throws Exception {
byte[] diff = new byte[] { 7, 8, 9 };
byte[] expected = new byte[] { 1, 7, 8, 9, 5 };
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(2, diff);
assertEquals(written, diff.length);
assertTrue(Arrays.equals(sb.getBytes(1, (int) sb.length()), expected), "arrays do not match ");
}
use of javax.sql.rowset.serial.SerialBlob in project jdk8u_jdk by JetBrains.
the class BaseRowSetTests method testAdvancedParameters.
/*
* DataProvider used to set advanced parameters for types that are supported
*/
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {
byte[] bytes = new byte[10];
Ref aRef = new SerialRef(new StubRef("INTEGER", query));
Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
Blob aBlob = new SerialBlob(new StubBlob());
Clob aClob = new SerialClob(new StubClob());
Reader rdr = new StringReader(query);
InputStream is = new StringBufferInputStream(query);
;
brs = new StubBaseRowSet();
brs.setBytes(1, bytes);
brs.setAsciiStream(2, is, query.length());
brs.setRef(3, aRef);
brs.setArray(4, aArray);
brs.setBlob(5, aBlob);
brs.setClob(6, aClob);
brs.setBinaryStream(7, is, query.length());
brs.setUnicodeStream(8, is, query.length());
brs.setCharacterStream(9, rdr, query.length());
return new Object[][] { { 1, bytes }, { 2, is }, { 3, aRef }, { 4, aArray }, { 5, aBlob }, { 6, aClob }, { 7, is }, { 8, is }, { 9, rdr } };
}
use of javax.sql.rowset.serial.SerialBlob in project teiid by teiid.
the class TestBlobValue method testBlobCompare.
public void testBlobCompare() throws Exception {
// $NON-NLS-1$
String testString = "this is test clob";
SerialBlob blob = new SerialBlob(testString.getBytes());
BlobType bv = new BlobType(blob);
SerialBlob blob1 = new SerialBlob(testString.getBytes());
BlobType bv1 = new BlobType(blob1);
assertEquals(0, bv1.compareTo(bv));
}
use of javax.sql.rowset.serial.SerialBlob in project teiid by teiid.
the class TestBlobValue method testBlobValuePersistence.
public void testBlobValuePersistence() throws Exception {
// $NON-NLS-1$
String testString = "this is test clob";
SerialBlob blob = new SerialBlob(testString.getBytes());
BlobType bv = new BlobType(blob);
String key = bv.getReferenceStreamId();
// now force to serialize
BlobType read = UnitTestUtil.helpSerialize(bv);
// make sure we have kept the reference stream id
assertEquals(key, read.getReferenceStreamId());
// and lost the original object
assertNull(read.getReference());
}
use of javax.sql.rowset.serial.SerialBlob in project teiid by teiid.
the class LobManager method persistLob.
public static void persistLob(final Streamable<?> lob, final FileStore store, byte[] bytes, boolean inlineLobs, int maxMemoryBytes) throws TeiidComponentException {
long byteLength = Integer.MAX_VALUE;
try {
byteLength = lob.length() * (lob instanceof ClobType ? 2 : 1);
} catch (SQLException e) {
// just ignore for now - for a single read resource computing the length invalidates
// TODO - inline small persisted lobs
}
try {
// inline
if (lob.getReferenceStreamId() == null || (inlineLobs && (byteLength <= maxMemoryBytes))) {
lob.setReferenceStreamId(null);
if (InputStreamFactory.getStorageMode(lob) == StorageMode.MEMORY) {
return;
}
if (lob instanceof BlobType) {
BlobType b = (BlobType) lob;
byte[] blobBytes = b.getBytes(1, (int) byteLength);
b.setReference(new SerialBlob(blobBytes));
} else if (lob instanceof ClobType) {
ClobType c = (ClobType) lob;
// $NON-NLS-1$
String s = "";
// some clob impls return null for 0 length
if (byteLength != 0) {
s = c.getSubString(1, (int) (byteLength >>> 1));
}
c.setReference(new ClobImpl(s));
} else {
XMLType x = (XMLType) lob;
String s = x.getString();
x.setReference(new SQLXMLImpl(s));
}
return;
}
InputStream is = null;
if (lob instanceof BlobType) {
is = new BlobInputStreamFactory((Blob) lob).getInputStream();
} else if (lob instanceof ClobType) {
is = new ClobInputStreamFactory((Clob) lob).getInputStream();
} else {
is = new SQLXMLInputStreamFactory((SQLXML) lob).getInputStream();
}
long offset = store.getLength();
OutputStream fsos = store.createOutputStream();
byteLength = ObjectConverterUtil.write(fsos, is, bytes, -1);
// re-construct the new lobs based on the file store
final long lobOffset = offset;
final long lobLength = byteLength;
/*
* Using an inner class here will hold a reference to the LobManager
* which prevents the removal of the FileStore until all of the
* lobs have been gc'd
*/
InputStreamFactory isf = new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return store.createInputStream(lobOffset, lobLength);
}
@Override
public StorageMode getStorageMode() {
return StorageMode.PERSISTENT;
}
};
isf.setLength(byteLength);
if (lob instanceof BlobType) {
((BlobType) lob).setReference(new BlobImpl(isf));
} else if (lob instanceof ClobType) {
long length = -1;
try {
length = ((ClobType) lob).length();
} catch (SQLException e) {
// could be streaming
}
((ClobType) lob).setReference(new ClobImpl(isf, length));
} else {
((XMLType) lob).setReference(new SQLXMLImpl(isf));
}
} catch (SQLException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30037, e);
} catch (IOException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30036, e);
}
}
Aggregations