use of org.teiid.core.types.BlobType in project teiid by teiid.
the class TestFunctionLibrary method testToChars1.
@Test
public void testToChars1() throws Exception {
// $NON-NLS-1$
Clob result = (Clob) helpInvokeMethod("to_chars", new Class<?>[] { DefaultDataClasses.BLOB, DefaultDataClasses.STRING }, new Object[] { new BlobType(new SerialBlob("hello world".getBytes("ASCII"))), "BASE64" }, null);
String string = result.getSubString(1, (int) result.length());
assertEquals("hello world", new String(Base64.decode(string), "ASCII"));
}
use of org.teiid.core.types.BlobType in project teiid by teiid.
the class TestFunctionLibrary method testCastWithNonRuntimeTypes.
@Test
public void testCastWithNonRuntimeTypes() throws Exception {
// $NON-NLS-1$
helpInvokeMethod("cast", new Object[] { new java.util.Date(0), "time" }, new Time(24 * 60 * 60 * 1000));
// $NON-NLS-1$
helpInvokeMethod("cast", new Object[] { new byte[0], "blob" }, new BlobType(BlobType.createBlob(new byte[0])));
}
use of org.teiid.core.types.BlobType 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;
}
use of org.teiid.core.types.BlobType in project teiid by teiid.
the class S3ProcedureExecution method saveFile.
// should use chunking based save, but it is little complex
// see http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-examples-using-sdks.html
// for example.
private BinaryWSProcedureExecution saveFile(List<Argument> arguments) throws TranslatorException {
String name = (String) arguments.get(0).getArgumentValue().getValue();
String bucket = (String) arguments.get(1).getArgumentValue().getValue();
String region = (String) arguments.get(2).getArgumentValue().getValue();
this.endpoint = (String) arguments.get(3).getArgumentValue().getValue();
String accessKey = (String) arguments.get(4).getArgumentValue().getValue();
String secretKey = (String) arguments.get(5).getArgumentValue().getValue();
if (bucket == null) {
bucket = this.ef.getBucket();
}
if (region == null) {
region = this.ef.getRegion();
}
if (endpoint == null) {
if (region.equals("us-east-1")) {
endpoint = "https://s3.amazonaws.com/" + bucket + "/" + name;
} else {
endpoint = "https://s3-" + region + ".amazonaws.com/" + bucket + "/" + name;
}
}
if (accessKey == null) {
accessKey = this.ef.getAccesskey();
}
if (secretKey == null) {
secretKey = this.ef.getSecretkey();
}
Object file = command.getArguments().get(6).getArgumentValue().getValue();
if (file == null) {
// $NON-NLS-1$
throw new TranslatorException(S3ExecutionFactory.UTIL.getString("non_null"));
}
try {
long length = 0;
byte[] contents = null;
if (file instanceof XMLType) {
length = ((XMLType) file).length();
contents = ObjectConverterUtil.convertToByteArray(((XMLType) file).getBinaryStream());
} else if (file instanceof Clob) {
length = ((Clob) file).length();
contents = ObjectConverterUtil.convertToByteArray(((Clob) file).getAsciiStream());
} else if (file instanceof Blob) {
length = ((Blob) file).length();
contents = ObjectConverterUtil.convertToByteArray(((Blob) file).getBinaryStream());
} else if (file instanceof String) {
length = ((String) file).length();
contents = ((String) file).getBytes();
} else {
// $NON-NLS-1$
throw new TranslatorException(S3ExecutionFactory.UTIL.getString("unknown_type"));
}
byte[] contentHash = AWS4SignerBase.hash(contents);
String contentHashString = BinaryUtils.toHex(contentHash);
Map<String, String> headers = new HashMap<String, String>();
headers.put("x-amz-content-sha256", contentHashString);
headers.put("content-length", "" + length);
headers.put("x-amz-storage-class", "STANDARD");
if (accessKey != null) {
AWS4SignerForAuthorizationHeader signer = new AWS4SignerForAuthorizationHeader(new URL(endpoint), "PUT", "s3", region);
String authorization = signer.computeSignature(headers, null, contentHashString, accessKey, secretKey);
headers.put("Authorization", authorization);
}
headers.put("Content-Type", "application/octet-stream");
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_WS, "Saving", endpoint);
return invokeHTTP("PUT", endpoint, new BlobType(contents), headers);
} catch (SQLException | IOException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.core.types.BlobType in project teiid by teiid.
the class CouchbaseDirectQueryExecution method next.
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
ArrayList<Object[]> returns = new ArrayList<>(1);
ArrayList<Object> result = new ArrayList<>(1);
if (this.results != null && this.results.hasNext()) {
final N1qlQueryRow row = this.results.next();
InputStreamFactory isf = new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(row.byteValue());
}
};
result.add(new BlobType(new BlobImpl(isf)));
returns.add(result.toArray());
return returns;
} else {
return null;
}
}
Aggregations