use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class TestLobManager method testLobPeristence.
@Test
public void testLobPeristence() throws Exception {
BufferManager buffMgr = BufferManagerFactory.getStandaloneBufferManager();
FileStore fs = buffMgr.createFileStore("temp");
ClobType clob = new ClobType(new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new ReaderInputStream(new StringReader("Clob contents One"), Charset.forName(Streamable.ENCODING));
}
}, -1));
BlobType blob = new BlobType(new BlobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new ReaderInputStream(new StringReader("Blob contents Two"), Charset.forName(Streamable.ENCODING));
}
}));
BlobType blobEmpty = new BlobType(new BlobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(new byte[0]);
}
}));
FileStore fs1 = buffMgr.createFileStore("blob");
FileStoreInputStreamFactory fsisf = new FileStoreInputStreamFactory(fs1, Streamable.ENCODING);
FileStoreOutputStream fsos = fsisf.getOuputStream();
byte[] b = new byte[DataTypeManager.MAX_LOB_MEMORY_BYTES + 1];
fsos.write(b);
fsos.close();
BlobType blob1 = new BlobType(new BlobImpl(fsisf));
assertNotNull(blob1.getReferenceStreamId());
LobManager lobManager = new LobManager(new int[] { 0, 1, 2, 3 }, fs);
lobManager.setMaxMemoryBytes(4);
List<?> tuple = Arrays.asList(clob, blob, blob1, blobEmpty);
lobManager.updateReferences(tuple, ReferenceMode.CREATE);
assertNotNull(blob1.getReferenceStreamId());
lobManager.persist();
Streamable<?> lob = lobManager.getLobReference(clob.getReferenceStreamId());
assertTrue(lob.getClass().isAssignableFrom(ClobType.class));
ClobType clobRead = (ClobType) lob;
assertEquals(ClobType.getString(clob), ClobType.getString(clobRead));
assertTrue(clobRead.length() != -1);
lob = lobManager.getLobReference(blob.getReferenceStreamId());
assertTrue(lob.getClass().isAssignableFrom(BlobType.class));
BlobType blobRead = (BlobType) lob;
assertTrue(Arrays.equals(ObjectConverterUtil.convertToByteArray(blob.getBinaryStream()), ObjectConverterUtil.convertToByteArray(blobRead.getBinaryStream())));
lobManager.updateReferences(tuple, ReferenceMode.REMOVE);
assertEquals(0, lobManager.getLobCount());
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class TestConnectorWorkItem method testLobs.
@Test
public void testLobs() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final List<Object> result = Arrays.asList(AutoGenDataService.CLOB_VAL);
final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@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() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (returned) {
return null;
}
returned = true;
return result;
}
};
}
};
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector") {
public ExecutionFactory getExecutionFactory() {
return ef;
}
public Object getConnectionFactory() {
return null;
}
};
cm.start();
ef.setCopyLobs(true);
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] resutls = message.getResults();
List<?> tuple = resutls[0];
ClobType clob = (ClobType) tuple.get(0);
assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob));
assertTrue(message.supportsImplicitClose());
result.set(0, AutoGenDataService.CLOB_VAL);
ef.setCopyLobs(false);
cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
message = cwi.more();
resutls = message.getResults();
tuple = resutls[0];
clob = (ClobType) tuple.get(0);
assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob));
assertFalse(message.supportsImplicitClose());
result.set(0, new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(new byte[0]);
}
@Override
public StorageMode getStorageMode() {
// TODO: introduce an explicit streaming
return StorageMode.FREE;
}
}, -1));
requestMsg.setCopyStreamingLobs(true);
cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
message = cwi.more();
resutls = message.getResults();
tuple = resutls[0];
clob = (ClobType) tuple.get(0);
// switched from FREE to PERSISTENT
assertEquals(StorageMode.PERSISTENT, InputStreamFactory.getStorageMode(clob));
assertFalse(message.supportsImplicitClose());
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class TestFunctionMethods method regexpReplaceOkay.
@Test
public void regexpReplaceOkay() throws Exception {
assertEquals("fooXbaz", FunctionMethods.regexpReplace(null, "foobarbaz", "b..", "X"));
assertEquals("fooXX", FunctionMethods.regexpReplace(null, "foobarbaz", "b..", "X", "g"));
assertEquals("fooXarYXazY", FunctionMethods.regexpReplace(null, "foobarbaz", "b(..)", "X$1Y", "g"));
assertEquals("fooBXRbXz", FunctionMethods.regexpReplace(null, "fooBARbaz", "a", "X", "gi"));
assertEquals("xxbye Wxx", FunctionMethods.regexpReplace(TestProcessor.createCommandContext(), "Goodbye World", "[g-o].", "x", "gi"));
assertEquals(new ClobType(new ClobImpl("xxbye Wxx")), FunctionMethods.regexpReplace(TestProcessor.createCommandContext(), new ClobType(new ClobImpl("Goodbye World")), "[g-o].", "x", "gi"));
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class PreparedStatementImpl method setClob.
void setClob(Object parameterIndex, final Reader reader) throws SQLException {
if (reader == null) {
this.setObject(parameterIndex, null);
return;
}
final ReaderInputStream readerInputStream = new ReaderInputStream(reader, Charset.forName(Streamable.ENCODING));
this.setObject(parameterIndex, new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return readerInputStream;
}
}, -1));
}
use of org.teiid.core.types.ClobImpl in project teiid by teiid.
the class ResultSetImpl method getObjectDirect.
/**
* Get the value of the current row at the column index specified.
* @param column Column index
* @return Value at column, which may be null
* @throws SQLException if this result set has an exception
*/
public Object getObjectDirect(int column) throws SQLException {
checkClosed();
if (column < 1 || column > columnCount) {
// $NON-NLS-1$
throw new IllegalArgumentException(JDBCPlugin.Util.getString("ResultsImpl.Invalid_col_index", column));
}
List<?> cursorRow = batchResults.getCurrentRow();
if (cursorRow == null) {
// $NON-NLS-1$
throw new TeiidSQLException(JDBCPlugin.Util.getString("ResultsImpl.The_cursor_is_not_on_a_valid_row._1"));
}
// defect 13539 - set the currentValue (defined in MMResultSet) so that wasNull() accurately returns whether this value was null
currentValue = cursorRow.get(column - 1);
if (currentValue instanceof Streamable<?>) {
Object reference = ((Streamable<?>) currentValue).getReference();
if (reference != null) {
return reference;
}
if (currentValue instanceof ClobType) {
return new ClobImpl(createInputStreamFactory((ClobType) currentValue), ((ClobType) currentValue).getLength());
} else if (currentValue instanceof BlobType) {
InputStreamFactory isf = createInputStreamFactory((BlobType) currentValue);
isf.setLength(((BlobType) currentValue).getLength());
return new BlobImpl(isf);
} else if (currentValue instanceof XMLType) {
XMLType val = (XMLType) currentValue;
SQLXMLImpl impl = new SQLXMLImpl(createInputStreamFactory(val));
impl.setEncoding(val.getEncoding());
return impl;
}
} else if (currentValue instanceof java.util.Date) {
return TimestampWithTimezone.create((java.util.Date) currentValue, serverTimeZone, getDefaultCalendar(), currentValue.getClass());
} else if (maxFieldSize > 0 && currentValue instanceof String) {
String val = (String) currentValue;
return val.substring(0, Math.min(maxFieldSize / 2, val.length()));
} else if (currentValue instanceof BinaryType) {
BinaryType val = (BinaryType) currentValue;
return val.getBytesDirect();
}
return currentValue;
}
Aggregations