use of org.teiid.core.types.TransformationException in project teiid by teiid.
the class Request method createCommandContext.
protected void createCommandContext() {
if (this.context != null) {
return;
}
// Create command context, used in rewriting, planning, and processing
// Identifies a "group" of requests on a per-connection basis to allow later
// cleanup of all resources in the group on connection shutdown
String groupName = workContext.getSessionId();
this.context = new CommandContext(groupName, workContext.getUserName(), requestMsg.getExecutionPayload(), workContext.getVdbName(), workContext.getVdbVersion(), this.requestMsg.getShowPlan() != ShowPlan.OFF || LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE));
this.context.setProcessorBatchSize(bufferManager.getProcessorBatchSize());
this.context.setGlobalTableStore(this.globalTables);
boolean autoCleanLobs = true;
if (this.workContext.getSession().isEmbedded()) {
Object value = this.workContext.getSession().getSessionVariables().get(CLEAN_LOBS_ONCLOSE);
if (value != null) {
value = DataTypeManager.convertToRuntimeType(value, false);
try {
value = DataTypeManager.transformValue(value, value.getClass(), DataTypeManager.DefaultDataClasses.BOOLEAN);
if (!(Boolean) value) {
autoCleanLobs = false;
}
} catch (TransformationException e) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_DQP, e, "Improper value for", CLEAN_LOBS_ONCLOSE);
}
}
}
if (!autoCleanLobs) {
context.disableAutoCleanLobs();
}
context.setExecutor(this.executor);
context.setAuthoriziationValidator(authorizationValidator);
context.setTempTableStore(tempTableStore);
context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(this.bufferManager, this.processorDataManager, this.capabilitiesFinder, idGenerator, metadata));
context.setMetadata(this.metadata);
context.setBufferManager(this.bufferManager);
context.setPreparedPlanCache(planCache);
context.setResultSetCacheEnabled(this.resultSetCacheEnabled);
context.setUserRequestSourceConcurrency(this.userRequestConcurrency);
context.setSubject(workContext.getSubject());
this.context.setOptions(options);
this.context.setSession(workContext.getSession());
this.context.setRequestId(this.requestId);
this.context.setDQPWorkContext(this.workContext);
this.context.setTransactionService(this.transactionService);
this.context.setVDBClassLoader(workContext.getVDB().getAttachment(ClassLoader.class));
}
use of org.teiid.core.types.TransformationException 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.TransformationException in project teiid by teiid.
the class MongoDBSelectVisitor method convertGeometryToJson.
private void convertGeometryToJson(BasicDBObjectBuilder builder, GeometryType object) throws TranslatorException {
try {
ClobType clob = GeometryUtils.geometryToGeoJson(object);
ClobToStringTransform clob2str = new ClobToStringTransform();
String geometry = (String) clob2str.transform(clob, String.class);
builder.add("$geometry", geometry);
} catch (FunctionExecutionException | TransformationException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.core.types.TransformationException in project teiid by teiid.
the class ParmHolder method setValue.
private Object setValue(ParmHolder holder, Object cachedObject, Object value, int level) throws TranslatorException {
// if there are muliple nameNodes,
// then do "get" for all but the last node, then set
// if a "container" type object is encountered, then create the object type for the table and add it to the container
// if a map, do a put
// if a collection, do an add
final String columnName = holder.nameNodes.get(level);
boolean atTheBottom = false;
if (holder.nodeSize == (level + 1))
atTheBottom = true;
if (!atTheBottom) {
final Object containerObject = ObjectSourceMethodManager.getValue("get" + columnName, cachedObject);
if (containerObject.getClass().isArray() || containerObject instanceof Collection || containerObject instanceof Map) {
return cachedObject;
}
}
ArrayList argTypes = new ArrayList(1);
argTypes.add(holder.attributeType);
Method m = ObjectSourceMethodManager.getMethod(cachedObject.getClass(), "set" + columnName, argTypes);
Class[] setTypes = m.getParameterTypes();
Object newValue = null;
if (value instanceof Collection || value instanceof Map || value.getClass().isArray()) {
newValue = value;
} else {
try {
newValue = DataTypeManager.transformValue(value, setTypes[0]);
} catch (TransformationException e) {
// TODO Auto-generated catch block
throw new TranslatorException(e);
}
}
ObjectSourceMethodManager.executeMethod(m, cachedObject, new Object[] { newValue });
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Set value " + newValue);
return newValue;
}
use of org.teiid.core.types.TransformationException in project teiid by teiid.
the class XQueryEvaluator method evaluate.
public static Object evaluate(XMLType value, XMLCast expression, CommandContext context) throws ExpressionEvaluationException {
Configuration config = new Configuration();
Type t = value.getType();
try {
Item i = null;
switch(t) {
case CONTENT:
// content could map to an array value, but we aren't handling that case here yet - only in xmltable
case COMMENT:
case PI:
throw new FunctionExecutionException();
case TEXT:
i = new StringValue(value.getString());
break;
case UNKNOWN:
case DOCUMENT:
case ELEMENT:
StreamSource ss = value.getSource(StreamSource.class);
try {
i = config.buildDocument(ss);
} finally {
if (ss.getInputStream() != null) {
ss.getInputStream().close();
}
if (ss.getReader() != null) {
ss.getReader().close();
}
}
break;
default:
// $NON-NLS-1$
throw new AssertionError("Unknown xml value type " + t);
}
return XMLTableNode.getValue(expression.getType(), i, config, context);
} catch (IOException e) {
throw new FunctionExecutionException(e);
} catch (ValidationException e) {
throw new FunctionExecutionException(e);
} catch (TransformationException e) {
throw new FunctionExecutionException(e);
} catch (XPathException e) {
throw new FunctionExecutionException(e);
} catch (SQLException e) {
throw new FunctionExecutionException(e);
}
}
Aggregations