use of org.teiid.core.types.InputStreamFactory in project teiid by teiid.
the class TestEmbeddedServer method testSourceLobUnderTxn.
@Test
public void testSourceLobUnderTxn() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setMaxResultSetCacheStaleness(0);
MockTransactionManager tm = new MockTransactionManager();
ec.setTransactionManager(tm);
ec.setUseDisk(false);
es.start(ec);
final AtomicBoolean closed = new AtomicBoolean();
es.addTranslator("foo", new ExecutionFactory() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
return new ResultSetExecution() {
private boolean returned;
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
closed.set(true);
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (returned) {
return null;
}
returned = true;
ArrayList<Object> result = new ArrayList<Object>(1);
result.add(new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
// need to make it of a sufficient size to not be inlined
return new ByteArrayInputStream(new byte[DataTypeManager.MAX_LOB_MEMORY_BYTES + 1]);
}
}));
return result;
}
};
}
});
es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"foo\" translator-name=\"foo\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table x (y xml);]]> </metadata></model></vdb>".getBytes()));
Connection c = es.getDriver().connect("jdbc:teiid:test", null);
c.setAutoCommit(false);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from x");
rs.next();
assertFalse(closed.get());
s.close();
assertTrue(closed.get());
}
use of org.teiid.core.types.InputStreamFactory in project teiid by teiid.
the class TestJDBCSocketTransport method testGeometryStreaming.
@Test
public void testGeometryStreaming() throws Exception {
StringBuilder geomString = new StringBuilder();
for (int i = 0; i < 600; i++) {
geomString.append("100 100,");
}
geomString.append("100 100");
final GeometryType geo = GeometryUtils.geometryFromClob(new ClobType(new ClobImpl("POLYGON ((" + geomString + "))")));
long length = geo.length();
PreparedStatement s = conn.prepareStatement("select st_geomfrombinary(?)");
s.setBlob(1, new BlobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
try {
return geo.getBinaryStream();
} catch (SQLException e) {
throw new IOException(e);
}
}
}));
ResultSet rs = s.executeQuery();
rs.next();
Blob b = rs.getBlob(1);
assertEquals(length, b.length());
b.getBytes(1, (int) b.length());
toggleInline(false);
rs = s.executeQuery();
rs.next();
b = rs.getBlob(1);
assertEquals(length, b.length());
b.getBytes(1, (int) b.length());
}
Aggregations