use of org.teiid.core.types.InputStreamFactory.StorageMode in project teiid by teiid.
the class LobManager method updateReferences.
@SuppressWarnings("unchecked")
public void updateReferences(List<?> tuple, ReferenceMode mode) throws TeiidComponentException {
for (int i = 0; i < lobIndexes.length; i++) {
Object anObj = tuple.get(lobIndexes[i]);
if (!(anObj instanceof Streamable<?>)) {
continue;
}
Streamable lob = (Streamable) anObj;
String id = lob.getReferenceStreamId();
LobHolder lobHolder = this.lobReferences.get(id);
switch(mode) {
case REMOVE:
if (lobHolder != null) {
lobHolder.referenceCount--;
if (lobHolder.referenceCount < 1) {
this.lobReferences.remove(id);
}
}
break;
case ATTACH:
if (lob.getReference() == null) {
if (lobHolder == null) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30033, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30033));
}
lob.setReference(lobHolder.lob.getReference());
}
break;
case CREATE:
try {
StorageMode storageMode = InputStreamFactory.getStorageMode(lob);
if (lob.getReferenceStreamId() == null || (inlineLobs && (storageMode == StorageMode.MEMORY || (storageMode != StorageMode.FREE && lob.length() * (lob instanceof ClobType ? 2 : 1) <= maxMemoryBytes)))) {
lob.setReferenceStreamId(null);
// since this is untracked at this point, we must detach if possible
if (inlineLobs && storageMode == StorageMode.OTHER) {
persistLob(lob, null, null, true, maxMemoryBytes);
}
continue;
}
} catch (SQLException e) {
// presumably the lob is bad, but let it slide for now
}
if (lob.getReference() == null) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30034, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30034));
}
if (lobHolder == null) {
this.lobReferences.put(id, new LobHolder(lob));
} else {
lobHolder.referenceCount++;
}
break;
}
}
}
use of org.teiid.core.types.InputStreamFactory.StorageMode in project teiid by teiid.
the class XMLSystemFunctions method convertReader.
private static void convertReader(Writer writer, XMLEventWriter eventWriter, Reader r, Type type, XMLType xml) throws XMLStreamException, IOException, FactoryConfigurationError, SQLException {
switch(type) {
case CONTENT:
case ELEMENT:
case PI:
case COMMENT:
{
// write the value directly to the writer
eventWriter.flush();
StorageMode storageMode = InputStreamFactory.getStorageMode(xml);
if ((storageMode == StorageMode.PERSISTENT || storageMode == StorageMode.OTHER) && writer instanceof ExtendedWriter) {
ExtendedWriter ew = (ExtendedWriter) writer;
if (ew.include(xml)) {
break;
}
}
char[] buf = new char[1 << 13];
int read = -1;
if (r == null) {
r = xml.getCharacterStream();
}
while ((read = r.read(buf)) != -1) {
writer.write(buf, 0, read);
}
break;
}
// assume a document
case UNKNOWN:
case // filter the doc declaration
DOCUMENT:
XMLEventReader eventReader = null;
XMLInputFactory inputFactory = XMLType.getXmlInputFactory();
if (r != null) {
if (!(r instanceof BufferedReader)) {
r = new BufferedReader(r);
}
eventReader = inputFactory.createXMLEventReader(r);
} else {
StAXSource staxSource = xml.getSource(StAXSource.class);
eventReader = staxSource.getXMLEventReader();
if (eventReader == null) {
eventReader = inputFactory.createXMLEventReader(staxSource.getXMLStreamReader());
}
}
eventReader = inputFactory.createFilteredReader(eventReader, declarationOmittingFilter);
eventWriter.add(eventReader);
break;
case TEXT:
if (r == null) {
r = xml.getCharacterStream();
}
XMLEventFactory eventFactory = threadLocalEventtFactory.get();
char[] buf = new char[1 << 13];
int read = -1;
while ((read = r.read(buf)) != -1) {
eventWriter.add(eventFactory.createCharacters(new String(buf, 0, read)));
}
break;
}
}
use of org.teiid.core.types.InputStreamFactory.StorageMode in project teiid by teiid.
the class XMLSystemFunctions method convertValue.
static void convertValue(Writer writer, XMLEventWriter eventWriter, XMLEventFactory eventFactory, Object object) throws IOException, FactoryConfigurationError, XMLStreamException, TransformerException {
if (object == null) {
return;
}
Reader r = null;
try {
if (object instanceof XMLType) {
XMLType xml = (XMLType) object;
Type type = xml.getType();
convertReader(writer, eventWriter, null, type, xml);
} else if (object instanceof ClobType) {
ClobType clob = (ClobType) object;
StorageMode storageMode = InputStreamFactory.getStorageMode(clob);
if ((storageMode == StorageMode.PERSISTENT || storageMode == StorageMode.OTHER) && writer instanceof ExtendedWriter) {
ExtendedWriter ew = (ExtendedWriter) writer;
if (ew.include(clob)) {
return;
}
}
r = clob.getCharacterStream();
convertReader(writer, eventWriter, r, Type.TEXT, null);
} else if (object instanceof BlobType) {
BlobType blob = (BlobType) object;
StorageMode storageMode = InputStreamFactory.getStorageMode(blob);
ClobType clob = FunctionMethods.toChars(blob, CharsetUtils.BASE64_NAME, true);
if ((storageMode == StorageMode.PERSISTENT || storageMode == StorageMode.OTHER) && writer instanceof ExtendedWriter) {
ExtendedWriter ew = (ExtendedWriter) writer;
if (ew.include(clob)) {
return;
}
}
r = clob.getCharacterStream();
convertReader(writer, eventWriter, r, Type.TEXT, null);
} else if (object instanceof BinaryType) {
BinaryType binary = (BinaryType) object;
ClobType clob = FunctionMethods.toChars(new BlobType(binary.getBytesDirect()), CharsetUtils.BASE64_NAME, true);
r = clob.getCharacterStream();
convertReader(writer, eventWriter, r, Type.TEXT, null);
} else {
String val = XQueryEvaluator.convertToAtomicValue(object).getStringValue();
eventWriter.add(eventFactory.createCharacters(val));
}
} catch (SQLException e) {
throw new IOException(e);
} finally {
if (r != null) {
r.close();
}
}
// TODO: blob - with base64 encoding
}
Aggregations