use of org.teiid.query.sql.symbol.XMLSerialize in project teiid by teiid.
the class TeiidServiceHandler method handleLobResult.
private void handleLobResult(String charSet, Object result, ServiceResponse response) throws SQLException {
if (result == null) {
// or should this be an empty result?
return;
}
if (result instanceof SQLXML) {
if (charSet != null) {
XMLSerialize serialize = new XMLSerialize();
// $NON-NLS-1$
serialize.setTypeString("blob");
serialize.setDeclaration(true);
serialize.setEncoding(charSet);
serialize.setDocument(true);
try {
InputStream content = ((BlobType) XMLSystemFunctions.serialize(serialize, new XMLType((SQLXML) result))).getBinaryStream();
response.writeContent(content, 200, false);
response.writeOK(ContentType.APPLICATION_OCTET_STREAM);
} catch (TransformationException e) {
throw new SQLException(e);
}
} else {
InputStream content = ((SQLXML) result).getBinaryStream();
response.writeContent(content, 200, false);
response.writeOK(ContentType.APPLICATION_XML);
}
} else if (result instanceof Blob) {
InputStream content = ((Blob) result).getBinaryStream();
response.writeContent(content, 200, false);
response.writeOK(ContentType.APPLICATION_OCTET_STREAM);
} else if (result instanceof Clob) {
InputStream content = new ReaderInputStream(((Clob) result).getCharacterStream(), charSet == null ? Charset.defaultCharset() : Charset.forName(charSet));
response.writeContent(content, 200, false);
response.writeOK(ContentType.TEXT_PLAIN);
} else {
InputStream content = new ByteArrayInputStream(result.toString().getBytes(charSet == null ? Charset.defaultCharset() : Charset.forName(charSet)));
response.writeContent(content, 200, false);
response.writeOK(ContentType.APPLICATION_OCTET_STREAM);
}
}
use of org.teiid.query.sql.symbol.XMLSerialize in project teiid by teiid.
the class TestFunctionResolving method testXMLSerialize_1.
@Test(expected = QueryResolverException.class)
public void testXMLSerialize_1() throws Exception {
// $NON-NLS-1$
String sql = "xmlserialize(DOCUMENT 1 as clob)";
XMLSerialize xs = (XMLSerialize) getExpression(sql);
assertEquals(DataTypeManager.DefaultDataClasses.CLOB, xs.getType());
}
use of org.teiid.query.sql.symbol.XMLSerialize in project teiid by teiid.
the class TeiidRSProvider method handleResult.
private InputStream handleResult(String charSet, Object result) throws SQLException {
if (result == null) {
// or should this be an empty result?
return null;
}
if (result instanceof SQLXML) {
if (charSet != null) {
XMLSerialize serialize = new XMLSerialize();
// $NON-NLS-1$
serialize.setTypeString("blob");
serialize.setDeclaration(true);
serialize.setEncoding(charSet);
serialize.setDocument(true);
try {
return ((BlobType) XMLSystemFunctions.serialize(serialize, new XMLType((SQLXML) result))).getBinaryStream();
} catch (TransformationException e) {
throw new SQLException(e);
}
}
return ((SQLXML) result).getBinaryStream();
} else if (result instanceof Blob) {
return ((Blob) result).getBinaryStream();
} else if (result instanceof Clob) {
return new ReaderInputStream(((Clob) result).getCharacterStream(), charSet == null ? Charset.defaultCharset() : Charset.forName(charSet));
}
return new ByteArrayInputStream(result.toString().getBytes(charSet == null ? Charset.defaultCharset() : Charset.forName(charSet)));
}
use of org.teiid.query.sql.symbol.XMLSerialize in project teiid by teiid.
the class TestFunctionResolving method testXMLSerialize.
@Test
public void testXMLSerialize() throws Exception {
// $NON-NLS-1$
String sql = "xmlserialize(DOCUMENT '<a/>' as clob)";
XMLSerialize xs = (XMLSerialize) getExpression(sql);
assertEquals(DataTypeManager.DefaultDataClasses.CLOB, xs.getType());
}
Aggregations