use of org.teiid.core.types.SQLXMLImpl in project teiid by teiid.
the class MongoDBExecutionFactory method retrieveValue.
/**
* @param field
* @param expectedClass
* @return
* @throws TranslatorException
*/
public Object retrieveValue(Object value, Class<?> expectedClass, DB mongoDB, String fqn, String colName) throws TranslatorException {
if (value == null) {
return null;
}
if (value.getClass().equals(expectedClass)) {
return value;
}
if (value instanceof DBRef) {
Object obj = ((DBRef) value).getId();
if (obj instanceof BasicDBObject) {
BasicDBObject bdb = (BasicDBObject) obj;
return bdb.get(colName);
}
return obj;
} else if (value instanceof java.util.Date && expectedClass.equals(java.sql.Date.class)) {
return new java.sql.Date(((java.util.Date) value).getTime());
} else if (value instanceof java.util.Date && expectedClass.equals(java.sql.Timestamp.class)) {
return new java.sql.Timestamp(((java.util.Date) value).getTime());
} else if (value instanceof java.util.Date && expectedClass.equals(java.sql.Time.class)) {
return new java.sql.Time(((java.util.Date) value).getTime());
} else if (value instanceof String && expectedClass.equals(BigDecimal.class)) {
return new BigDecimal((String) value);
} else if (value instanceof String && expectedClass.equals(BigInteger.class)) {
return new BigInteger((String) value);
} else if (value instanceof String && expectedClass.equals(Character.class)) {
return new Character(((String) value).charAt(0));
} else if (value instanceof String && expectedClass.equals(BinaryType.class)) {
return new BinaryType(((String) value).getBytes());
} else if (value instanceof String && expectedClass.equals(Blob.class)) {
GridFS gfs = new GridFS(mongoDB, fqn);
final GridFSDBFile resource = gfs.findOne((String) value);
if (resource == null) {
return null;
}
return new BlobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return resource.getInputStream();
}
});
} else if (value instanceof String && expectedClass.equals(Clob.class)) {
GridFS gfs = new GridFS(mongoDB, fqn);
final GridFSDBFile resource = gfs.findOne((String) value);
if (resource == null) {
return null;
}
return new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return resource.getInputStream();
}
}, -1);
} else if (value instanceof String && expectedClass.equals(SQLXML.class)) {
GridFS gfs = new GridFS(mongoDB, fqn);
final GridFSDBFile resource = gfs.findOne((String) value);
if (resource == null) {
return null;
}
return new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return resource.getInputStream();
}
});
} else if (value instanceof BasicDBList) {
BasicDBList arrayValues = (BasicDBList) value;
// array
if (expectedClass.isArray() && !(arrayValues.get(0) instanceof BasicDBObject)) {
Class arrayType = expectedClass.getComponentType();
Object array = Array.newInstance(arrayType, arrayValues.size());
for (int i = 0; i < arrayValues.size(); i++) {
Object arrayItem = retrieveValue(arrayValues.get(i), arrayType, mongoDB, fqn, colName);
Array.set(array, i, arrayItem);
}
value = array;
}
} else if (value instanceof org.bson.types.ObjectId) {
org.bson.types.ObjectId id = (org.bson.types.ObjectId) value;
value = id.toHexString();
} else {
Transform transform = DataTypeManager.getTransform(value.getClass(), expectedClass);
if (transform != null) {
try {
value = transform.transform(value, expectedClass);
} catch (TransformationException e) {
throw new TranslatorException(e);
}
}
}
return value;
}
use of org.teiid.core.types.SQLXMLImpl in project teiid by teiid.
the class WSProcedureExecution method getOutputParameterValues.
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
Object result = returnValue;
if (returnValue != null && (returnValue instanceof StAXSource) && procedure.getArguments().size() > 4 && procedure.getArguments().get(4).getDirection() == Direction.IN && Boolean.TRUE.equals(procedure.getArguments().get(4).getArgumentValue().getValue())) {
SQLXMLImpl sqlXml = new StAXSQLXML((StAXSource) returnValue);
XMLType xml = new XMLType(sqlXml);
xml.setType(Type.DOCUMENT);
result = xml;
} else if (returnValue != null && returnValue instanceof DOMSource) {
final DOMSource xmlSource = (DOMSource) returnValue;
SQLXMLImpl sqlXml = new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Result outputTarget = new StreamResult(outputStream);
try {
TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
} catch (Exception e) {
throw new IOException(e);
}
return new ByteArrayInputStream(outputStream.toByteArray());
}
});
XMLType xml = new XMLType(sqlXml);
xml.setType(Type.DOCUMENT);
result = xml;
}
return Arrays.asList(result);
}
use of org.teiid.core.types.SQLXMLImpl in project teiid by teiid.
the class WSWSDLProcedureExecution method getOutputParameterValues.
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
Object result = returnValue;
if (returnValue != null && procedure.getArguments().size() > 1 && Boolean.TRUE.equals(procedure.getArguments().get(1).getArgumentValue().getValue())) {
SQLXMLImpl sqlXml = new StAXSQLXML(returnValue);
XMLType xml = new XMLType(sqlXml);
xml.setType(Type.DOCUMENT);
result = xml;
}
return Arrays.asList(result);
}
use of org.teiid.core.types.SQLXMLImpl in project teiid by teiid.
the class SaxonXQueryExpression method createXMLType.
public XMLType createXMLType(final SequenceIterator iter, BufferManager bufferManager, boolean emptyOnEmpty, CommandContext context) throws XPathException, TeiidComponentException, TeiidProcessingException {
final Item item = iter.next();
if (item == null && !emptyOnEmpty) {
return null;
}
XMLType.Type type = Type.CONTENT;
if (item instanceof NodeInfo) {
NodeInfo info = (NodeInfo) item;
type = getType(info);
}
final Item next = iter.next();
if (next != null) {
type = Type.CONTENT;
}
SQLXMLImpl xml = XMLSystemFunctions.saveToBufferManager(bufferManager, new XMLTranslator() {
@Override
public void translate(Writer writer) throws TransformerException, IOException {
QueryResult.serializeSequence(new PushBackSequenceIterator(iter, item, next), config, writer, DEFAULT_OUTPUT_PROPERTIES);
}
}, context);
XMLType value = new XMLType(xml);
value.setType(type);
return value;
}
use of org.teiid.core.types.SQLXMLImpl in project teiid by teiid.
the class StatementImpl method executeShow.
ResultsFuture<Boolean> executeShow(Matcher match) throws SQLException {
String show = match.group(1);
show = unescapeId(show);
if (show.equalsIgnoreCase("PLAN")) {
// $NON-NLS-1$
List<ArrayList<Object>> records = new ArrayList<ArrayList<Object>>(1);
PlanNode plan = driverConnection.getCurrentPlanDescription();
String connDebugLog = driverConnection.getDebugLog();
if (plan != null || connDebugLog != null) {
ArrayList<Object> row = new ArrayList<Object>(3);
if (plan != null) {
row.add(DataTypeTransformer.getClob(plan.toString()));
row.add(new SQLXMLImpl(plan.toXml()));
} else {
row.add(null);
row.add(null);
}
row.add(DataTypeTransformer.getClob(connDebugLog));
records.add(row);
}
createResultSet(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
records, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new String[] { "PLAN_TEXT", "PLAN_XML", "DEBUG_LOG" }, new String[] { DataTypeManager.DefaultDataTypes.CLOB, DataTypeManager.DefaultDataTypes.XML, DataTypeManager.DefaultDataTypes.CLOB });
return booleanFuture(true);
}
if (show.equalsIgnoreCase("ANNOTATIONS")) {
// $NON-NLS-1$
List<ArrayList<Object>> records = new ArrayList<ArrayList<Object>>(1);
Collection<Annotation> annos = driverConnection.getAnnotations();
for (Annotation annotation : annos) {
ArrayList<Object> row = new ArrayList<Object>(4);
row.add(annotation.getCategory());
row.add(annotation.getPriority().name());
row.add(annotation.getAnnotation());
row.add(annotation.getResolution());
records.add(row);
}
createResultSet(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
records, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "CATEGORY", "PRIORITY", "ANNOTATION", "RESOLUTION" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
return booleanFuture(true);
}
if (show.equalsIgnoreCase("ALL")) {
// $NON-NLS-1$
List<ArrayList<Object>> records = new ArrayList<ArrayList<Object>>(1);
for (String key : driverConnection.getExecutionProperties().stringPropertyNames()) {
ArrayList<Object> row = new ArrayList<Object>(4);
row.add(key);
row.add(driverConnection.getExecutionProperties().get(key));
records.add(row);
}
createResultSet(// $NON-NLS-1$ //$NON-NLS-2$
records, // $NON-NLS-1$ //$NON-NLS-2$
new String[] { "NAME", "VALUE" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
return booleanFuture(true);
}
if (show.equalsIgnoreCase("transaction isolation level")) {
// $NON-NLS-1$
List<ArrayList<Object>> records = new ArrayList<ArrayList<Object>>(1);
ArrayList<Object> row = new ArrayList<Object>(1);
switch(driverConnection.getTransactionIsolation()) {
case Connection.TRANSACTION_READ_COMMITTED:
// $NON-NLS-1$
row.add("READ COMMITTED");
break;
case Connection.TRANSACTION_READ_UNCOMMITTED:
// $NON-NLS-1$
row.add("READ UNCOMMITTED");
break;
case Connection.TRANSACTION_REPEATABLE_READ:
// $NON-NLS-1$
row.add("REPEATABLE READ");
break;
case Connection.TRANSACTION_SERIALIZABLE:
// $NON-NLS-1$
row.add("SERIALIZABLE");
break;
default:
// $NON-NLS-1$
row.add("UNKNOWN");
}
records.add(row);
createResultSet(// $NON-NLS-1$
records, // $NON-NLS-1$
new String[] { "TRANSACTION ISOLATION" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
return booleanFuture(true);
}
List<List<String>> records = Collections.singletonList(Collections.singletonList(driverConnection.getExecutionProperty(show)));
createResultSet(records, new String[] { show }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
return booleanFuture(true);
}
Aggregations