use of org.teiid.language.NamedTable in project teiid by teiid.
the class TestSingleInsert method testDateTypes.
@Test
public void testDateTypes() throws Exception {
NamedTable table = new NamedTable("temp", null, Mockito.mock(Table.class));
ArrayList<ColumnReference> elements = new ArrayList<ColumnReference>();
elements.add(new ColumnReference(table, "one", Mockito.mock(Column.class), Integer.class));
elements.add(new ColumnReference(table, "two", Mockito.mock(Column.class), Date.class));
elements.add(new ColumnReference(table, "three", Mockito.mock(Column.class), Timestamp.class));
List<Expression> values = new ArrayList<Expression>();
values.add(new Literal(1, DataTypeManager.DefaultDataClasses.INTEGER));
values.add(new Literal(TimestampUtil.createDate(100, 01, 1), DataTypeManager.DefaultDataClasses.DATE));
values.add(new Literal(TimestampUtil.createTimestamp(100, 01, 1, 0, 4, 0, 0), DataTypeManager.DefaultDataClasses.TIMESTAMP));
ExpressionValueSource valueSource = new ExpressionValueSource(values);
Insert insert = new Insert(table, elements, valueSource);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
Mockito.stub(connection.create(Mockito.any(DataPayload.class))).toAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
DataPayload payload = (DataPayload) invocation.getArguments()[0];
List<DataPayload.Field> fields = payload.getMessageElements();
assertEquals(3, fields.size());
assertEquals(1, fields.get(0).value);
assertEquals(TimestampUtil.createDate(100, 01, 1), fields.get(1).value);
Calendar cal = (Calendar) fields.get(2).value;
assertEquals(TimeZone.getTimeZone("GMT-1"), cal.getTimeZone());
return 1;
}
});
Mockito.stub(connection.upsert(Mockito.any(DataPayload.class))).toReturn(1);
SalesForceExecutionFactory config = new SalesForceExecutionFactory();
config.setMaxBulkInsertBatchSize(1);
InsertExecutionImpl updateExecution = new InsertExecutionImpl(config, insert, connection, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class));
while (true) {
try {
updateExecution.execute();
org.junit.Assert.assertArrayEquals(new int[] { 1 }, updateExecution.getUpdateCounts());
break;
} catch (DataNotAvailableException e) {
continue;
}
}
insert.setUpsert(true);
updateExecution = new InsertExecutionImpl(config, insert, connection, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class));
while (true) {
try {
updateExecution.execute();
org.junit.Assert.assertArrayEquals(new int[] { 1 }, updateExecution.getUpdateCounts());
break;
} catch (DataNotAvailableException e) {
continue;
}
}
Mockito.verify(connection).upsert(Mockito.any(DataPayload.class));
}
use of org.teiid.language.NamedTable in project teiid by teiid.
the class TestSetQueryImpl method example2.
public static SetQuery example2() throws Exception {
// $NON-NLS-1$
NamedTable group = new NamedTable("ted", null, null);
// $NON-NLS-1$
ColumnReference element = new ColumnReference(group, "nugent", null, String.class);
DerivedColumn symbol = new DerivedColumn(null, element);
List symbols = new ArrayList();
symbols.add(symbol);
List items = new ArrayList();
items.add(group);
// $NON-NLS-1$
NamedTable group2 = new NamedTable("dave", null, null);
// $NON-NLS-1$
ColumnReference element2 = new ColumnReference(group2, "barry", null, String.class);
DerivedColumn symbol2 = new DerivedColumn(null, element2);
List symbols2 = new ArrayList();
symbols2.add(symbol2);
List items2 = new ArrayList();
items2.add(group2);
Select secondQuery = new Select(symbols2, false, items2, null, null, null, null);
Select query = new Select(symbols, false, items, null, null, null, null);
SetQuery setQuery = new SetQuery();
setQuery.setOperation(SetQuery.Operation.UNION);
setQuery.setAll(true);
setQuery.setLeftQuery(query);
setQuery.setRightQuery(secondQuery);
return setQuery;
}
use of org.teiid.language.NamedTable in project teiid by teiid.
the class IdentifierFunctionModifier method translate.
public List<?> translate(Function function) {
List<Object> objs = new ArrayList<Object>();
List<Expression> parms = function.getParameters();
objs.add(function.getName().substring(function.getName().indexOf('_') + 1));
objs.add(SQLConstants.Tokens.LPAREN);
for (Iterator<Expression> iter = parms.iterator(); iter.hasNext(); ) {
Expression expr = iter.next();
if (expr instanceof ColumnReference) {
boolean dotAll = false;
boolean useSelector = false;
ColumnReference cr = (ColumnReference) expr;
Column c = cr.getMetadataObject();
if (c != null) {
if ("\"mode:properties\"".equalsIgnoreCase(c.getSourceName())) {
// $NON-NLS-1$
dotAll = true;
useSelector = true;
} else if ("\"jcr:path\"".equalsIgnoreCase(c.getSourceName())) {
// $NON-NLS-1$
useSelector = true;
}
}
if (useSelector) {
NamedTable nt = ((ColumnReference) expr).getTable();
if (nt.getCorrelationName() != null) {
objs.add(nt.getCorrelationName());
} else {
objs.add(nt);
}
} else {
objs.add(expr);
}
if (dotAll) {
// $NON-NLS-1$
objs.add(".*");
}
} else {
objs.add(expr);
}
if (iter.hasNext()) {
// $NON-NLS-1$
objs.add(", ");
}
}
objs.add(SQLConstants.Tokens.RPAREN);
return objs;
}
use of org.teiid.language.NamedTable in project teiid by teiid.
the class TestGroup method getGroup.
// ################ TEST GROUP METADATAID ######################
public Table getGroup(String groupName, TranslationUtility transUtil) throws Exception {
// $NON-NLS-1$
Select query = (Select) transUtil.parseCommand("SELECT 1 FROM " + groupName);
NamedTable group = (NamedTable) query.getFrom().get(0);
return group.getMetadataObject();
}
use of org.teiid.language.NamedTable in project teiid by teiid.
the class TestMetadataObject method getGroupID.
// ################ TEST GROUP METADATAID ######################
public Table getGroupID(String groupName, TranslationUtility transUtil) {
// $NON-NLS-1$
Select query = (Select) transUtil.parseCommand("SELECT 1 FROM " + groupName);
NamedTable group = (NamedTable) query.getFrom().get(0);
return group.getMetadataObject();
}
Aggregations