use of java.sql.Blob in project teiid by teiid.
the class S3ProcedureExecution method next.
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (this.command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.SAVEFILE) || this.command.getProcedureName().equalsIgnoreCase(S3ExecutionFactory.DELETEFILE)) {
return null;
}
if (this.execution == null || this.execution.getResponseCode() < 200 || this.execution.getResponseCode() > 300) {
return null;
}
Blob contents = (Blob) execution.getOutputParameterValues().get(0);
BlobInputStreamFactory isf = new BlobInputStreamFactory(contents);
String length = getHeader("Content-Length");
if (length != null) {
isf.setLength(Long.parseLong(length));
}
Object value = null;
if (isText) {
ClobImpl clob = new ClobImpl(isf, -1);
clob.setCharset(Charset.forName(this.ef.getEncoding()));
value = new ClobType(clob);
if (!streaming) {
value = new InputStreamFactory.ClobInputStreamFactory(clob);
}
} else {
if (streaming) {
value = new BlobType(contents);
} else {
value = isf;
}
}
String lastModified = getHeader("Last-Modified");
ArrayList<Object> result = new ArrayList<Object>(2);
result.add(value);
if (!isList) {
result.add(endpoint);
try {
SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss zzz");
result.add(lastModified == null ? null : new Timestamp(df.parse(lastModified).getTime()));
} catch (ParseException e) {
result.add(null);
}
result.add(getHeader("ETag"));
result.add(length);
}
this.execution = null;
return result;
}
use of java.sql.Blob in project teiid by teiid.
the class Evaluator method evaluateParameter.
private Object evaluateParameter(List<?> tuple, DerivedColumn passing) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
if (passing.getExpression() instanceof Function) {
Function f = (Function) passing.getExpression();
// narrow optimization of json based documents to allow for lower overhead streaming
if (f.getName().equalsIgnoreCase(SourceSystemFunctions.JSONTOXML)) {
String rootName = (String) this.evaluate(f.getArg(0), tuple);
Object lob = this.evaluate(f.getArg(1), tuple);
if (rootName == null || lob == null) {
return null;
}
try {
if (lob instanceof Blob) {
return XMLSystemFunctions.jsonToXml(context, rootName, (Blob) lob, true);
}
return XMLSystemFunctions.jsonToXml(context, rootName, (Clob) lob, true);
} catch (IOException e) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
} catch (SQLException e) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
} catch (TeiidProcessingException e) {
throw new FunctionExecutionException(QueryPlugin.Event.TEIID30384, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30384, f.getFunctionDescriptor().getName()));
}
}
} else if (passing.getExpression() instanceof XMLParse) {
XMLParse xmlParse = (XMLParse) passing.getExpression();
xmlParse.setWellFormed(true);
}
Object value = this.evaluate(passing.getExpression(), tuple);
return value;
}
use of java.sql.Blob in project teiid by teiid.
the class GeometryUtils method geometryToEwkb.
/**
* We'll take the wkb format and add the extended flag/srid
* @param geometry
* @return
*/
public static BlobType geometryToEwkb(final GeometryType geometry) {
final Blob b = geometry.getReference();
BlobImpl blobImpl = new BlobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
PushbackInputStream pbis;
try {
pbis = new PushbackInputStream(b.getBinaryStream(), 9);
} catch (SQLException e) {
throw new IOException(e);
}
int byteOrder = pbis.read();
if (byteOrder == -1) {
return pbis;
}
byte[] typeInt = new byte[4];
int bytesRead = pbis.read(typeInt);
if (bytesRead == 4) {
int srid = geometry.getSrid();
byte[] sridInt = new byte[4];
ByteOrderValues.putInt(srid, sridInt, byteOrder == 0 ? ByteOrderValues.BIG_ENDIAN : ByteOrderValues.LITTLE_ENDIAN);
pbis.unread(sridInt);
typeInt[byteOrder == 0 ? 0 : 3] |= 0x20;
}
pbis.unread(typeInt, 0, bytesRead);
pbis.unread(byteOrder);
return pbis;
}
});
return new BlobType(blobImpl);
}
use of java.sql.Blob in project teiid by teiid.
the class StringAgg method writeValue.
private void writeValue(Object val) throws TeiidProcessingException {
try {
if (binary) {
if (val instanceof BinaryType) {
result.getOuputStream().write(((BinaryType) val).getBytesDirect());
return;
}
Blob b = (Blob) val;
InputStream binaryStream = b.getBinaryStream();
try {
ObjectConverterUtil.write(result.getOuputStream(), binaryStream, -1, false);
} finally {
binaryStream.close();
}
} else {
if (val instanceof String) {
result.getWriter().write((String) val);
return;
}
Clob c = (Clob) val;
Reader characterStream = c.getCharacterStream();
try {
ObjectConverterUtil.write(result.getWriter(), characterStream, -1, false);
} finally {
characterStream.close();
}
}
} catch (IOException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30422, e);
} catch (SQLException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30423, e);
}
}
use of java.sql.Blob in project teiid by teiid.
the class EntityCollectionResponse method getPropertyValueInternal.
private static Object getPropertyValueInternal(SingletonPrimitiveType expectedType, boolean isArray, Object value) throws TransformationException, SQLException, IOException {
Class<?> sourceType = DataTypeManager.getRuntimeType(value.getClass());
if (sourceType.isAssignableFrom(expectedType.getDefaultType())) {
return value;
}
if (expectedType instanceof EdmDate && sourceType == Date.class) {
return value;
} else if (expectedType instanceof EdmDateTimeOffset && sourceType == Timestamp.class) {
return value;
} else if (expectedType instanceof EdmTimeOfDay && sourceType == Time.class) {
return value;
} else if (expectedType instanceof EdmBinary) {
// there could be memory implications here, should have been modeled as EdmStream
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_ODATA, "Possible OOM when inlining the stream based values");
if (sourceType == ClobType.class) {
return ClobType.getString((Clob) value).getBytes();
}
if (sourceType == SQLXML.class) {
return ((SQLXML) value).getString().getBytes();
}
if (sourceType == BlobType.class) {
return ObjectConverterUtil.convertToByteArray(((Blob) value).getBinaryStream());
}
if (value instanceof Serializable) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(value);
oos.close();
bos.close();
return bos.toByteArray();
}
}
Class<?> targetType = DataTypeManager.getDataTypeClass(ODataTypeManager.teiidType(expectedType, isArray));
if (sourceType != targetType) {
Transform t = DataTypeManager.getTransform(sourceType, targetType);
value = t != null ? t.transform(value, targetType) : value;
}
return value;
}
Aggregations