use of org.teiid.language.Literal in project teiid by teiid.
the class TestPathFunctionModifier method test1.
public void test1() throws Exception {
// $NON-NLS-1$
Literal arg1 = LANG_FACTORY.createLiteral("car", String.class);
// $NON-NLS-1$
helpTestMod(arg1, "PATH('car')", "PATH");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class MongoDBDirectQueryExecution method execute.
@Override
public void execute() throws TranslatorException {
StringBuilder buffer = new StringBuilder();
SQLStringVisitor.parseNativeQueryParts(query, arguments, buffer, new SQLStringVisitor.Substitutor() {
@Override
public void substitute(Argument arg, StringBuilder builder, int index) {
Literal argumentValue = arg.getArgumentValue();
builder.append(argumentValue.getValue());
}
});
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(buffer.toString(), ";");
String collectionName = st.nextToken();
// $NON-NLS-1$
boolean shellOperation = collectionName.equalsIgnoreCase("$ShellCmd");
String shellOperationName = null;
if (shellOperation) {
collectionName = st.nextToken();
shellOperationName = st.nextToken();
}
DBCollection collection = this.mongoDB.getCollection(collectionName);
if (collection == null) {
throw new TranslatorException(MongoDBPlugin.Event.TEIID18020, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18020, collectionName));
}
if (shellOperation) {
ArrayList<Object> operations = new ArrayList<Object>();
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (token.startsWith("{")) {
// $NON-NLS-1$
operations.add(JSON.parse(token));
} else {
operations.add(token);
}
}
try {
ReflectionHelper helper = new ReflectionHelper(DBCollection.class);
Method method = helper.findBestMethodOnTarget(shellOperationName, operations.toArray(new Object[operations.size()]));
Object result = method.invoke(collection, operations.toArray(new Object[operations.size()]));
if (result instanceof Cursor) {
this.results = (Cursor) result;
} else if (result instanceof WriteResult) {
WriteResult wr = (WriteResult) result;
if (!wr.wasAcknowledged()) {
// throw error for unacknowledged write
throw new TranslatorException(wr.toString());
}
}
} catch (NoSuchMethodException e) {
throw new TranslatorException(MongoDBPlugin.Event.TEIID18034, e, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18034, buffer.toString()));
} catch (SecurityException e) {
throw new TranslatorException(MongoDBPlugin.Event.TEIID18034, e, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18034, buffer.toString()));
} catch (IllegalAccessException e) {
throw new TranslatorException(MongoDBPlugin.Event.TEIID18034, e, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18034, buffer.toString()));
} catch (IllegalArgumentException e) {
throw new TranslatorException(MongoDBPlugin.Event.TEIID18034, e, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18034, buffer.toString()));
} catch (InvocationTargetException e) {
throw new TranslatorException(MongoDBPlugin.Event.TEIID18034, e.getTargetException(), MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18034, buffer.toString()));
}
} else {
ArrayList<DBObject> operations = new ArrayList<DBObject>();
while (st.hasMoreTokens()) {
String token = st.nextToken();
operations.add((DBObject) JSON.parse(token));
}
if (operations.isEmpty()) {
throw new TranslatorException(MongoDBPlugin.Event.TEIID18021, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18021, collectionName));
}
this.results = collection.aggregate(operations, this.executionFactory.getOptions(this.executionContext.getBatchSize()));
}
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestQueryExecution method testMultiAttribute.
@Test
public void testMultiAttribute() throws NamingException {
Column c = new Column();
c.setDefaultValue(LDAPQueryExecution.MULTIVALUED_CONCAT);
Attribute a = LDAPUpdateExecution.createBasicAttribute("x", new Literal("a?b?c", String.class), c);
assertEquals(3, a.size());
assertEquals("b", Collections.list(a.getAll()).get(1));
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestMongoDBDirectQueryExecution method testShellDirect.
@Test
public void testShellDirect() throws Exception {
Command cmd = this.utility.parseCommand("SELECT * FROM Customers");
MongoDBConnection connection = Mockito.mock(MongoDBConnection.class);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
DBCollection dbCollection = Mockito.mock(DBCollection.class);
DB db = Mockito.mock(DB.class);
Mockito.stub(db.getCollection("MyTable")).toReturn(dbCollection);
Mockito.stub(db.collectionExists(Mockito.anyString())).toReturn(true);
Mockito.stub(connection.getDatabase()).toReturn(db);
Argument arg = new Argument(Direction.IN, null, String.class, null);
arg.setArgumentValue(new Literal("$ShellCmd;MyTable;remove;{ qty: { $gt: 20 }}", String.class));
ResultSetExecution execution = this.translator.createDirectExecution(Arrays.asList(arg), cmd, context, this.utility.createRuntimeMetadata(), connection);
execution.execute();
Mockito.verify(dbCollection).remove(QueryBuilder.start("qty").greaterThan(20).get());
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestSybaseIQConvertModifier method testTimestampToDate.
@Test
public void testTimestampToDate() throws Exception {
Literal c = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(89, 2, 3, 7, 8, 12, 99999), Timestamp.class);
Function func = // $NON-NLS-1$
LANG_FACTORY.createFunction(// $NON-NLS-1$
"convert", new Expression[] { c, // $NON-NLS-1$
LANG_FACTORY.createLiteral("date", String.class) }, java.sql.Date.class);
// $NON-NLS-1$
helpGetString1(func, "cast(CAST('1989-03-03 07:08:12.0' AS TIMESTAMP) AS date)");
}
Aggregations