use of org.teiid.language.Literal in project teiid by teiid.
the class TestSQLConversionVisitor method testDayOfMonth.
@Test
public void testDayOfMonth() throws Exception {
Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(117, 0, 13, 10, 5, 0, 10000000), Timestamp.class);
// $NON-NLS-1$
helpTestMod(arg1, SourceSystemFunctions.DAYOFMONTH, "day_of_month(timestamp '2017-01-13 10:05:00.01')");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestSQLConversionVisitor method testDayOfWeek.
@Test
public void testDayOfWeek() throws Exception {
Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(117, 0, 13, 10, 5, 0, 10000000), Timestamp.class);
// $NON-NLS-1$
helpTestMod(arg1, SourceSystemFunctions.DAYOFWEEK, "day_of_week(timestamp '2017-01-13 10:05:00.01')");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class JPQLUpdateExecution method handleInsert.
private Object handleInsert(Insert insert) throws TranslatorException {
try {
String entityClassName = insert.getTable().getMetadataObject().getProperty(JPAMetadataProcessor.ENTITYCLASS, false);
Object entity = ReflectionHelper.create(entityClassName, null, this.executionContext.getCommandContext().getVDBClassLoader());
List<ColumnReference> columns = insert.getColumns();
List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
if (columns.size() != values.size()) {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14007));
}
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i).getMetadataObject();
Object value = values.get(i);
// do not add the derived columns
String name = column.getProperty(JPAMetadataProcessor.KEY_ASSOSIATED_WITH_FOREIGN_TABLE, false);
if (name == null) {
if (value instanceof Literal) {
Literal literalValue = (Literal) value;
PropertiesUtils.setBeanProperty(entity, column.getName(), literalValue.getValue());
} else {
PropertiesUtils.setBeanProperty(entity, column.getName(), value);
}
}
}
return entity;
} catch (TeiidException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.language.Literal in project teiid by teiid.
the class JPQLDirectQueryExecution method execute.
@Override
public void execute() throws TranslatorException {
if (query.length() < 7) {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
}
String firstToken = query.substring(0, 7);
String jpql = query.substring(7);
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "JPA Source-Query:", jpql);
if (firstToken.equalsIgnoreCase("search;")) {
// //$NON-NLS-1$
StringBuilder buffer = new StringBuilder();
SQLStringVisitor.parseNativeQueryParts(jpql, arguments, buffer, new SQLStringVisitor.Substitutor() {
@Override
public void substitute(Argument arg, StringBuilder builder, int index) {
Literal argumentValue = arg.getArgumentValue();
builder.append(argumentValue);
}
});
jpql = buffer.toString();
Query queryCommand = this.enityManager.createQuery(jpql);
List<?> results = queryCommand.getResultList();
this.resultsIterator = results.iterator();
} else if (firstToken.equalsIgnoreCase("create;")) {
// //$NON-NLS-1$
Object entity = arguments.get(0).getArgumentValue().getValue();
this.enityManager.merge(entity);
this.resultsIterator = Arrays.asList(1).iterator();
} else if (firstToken.equalsIgnoreCase("update;") || firstToken.equalsIgnoreCase("delete;")) {
// //$NON-NLS-1$ //$NON-NLS-2$
Query queryCmd = this.enityManager.createQuery(jpql);
this.resultsIterator = Arrays.asList(queryCmd.executeUpdate()).iterator();
} else {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
}
}
use of org.teiid.language.Literal in project teiid by teiid.
the class ParmHolder method createObject.
public Object createObject(List<ColumnReference> columnList, List<Expression> valueList, CoherenceVisitor visitor, Table t) throws TranslatorException {
if (columnList.size() != valueList.size()) {
throw new TranslatorException("Error: columns.size and values.size are not the same.");
}
// create the new object that will either be added as a top level object or added to the parent container
String tableName = visitor.getNameFromTable(t);
Object newObject = createObjectFromMetadata(tableName);
for (int i = 0; i < columnList.size(); i++) {
final ColumnReference insertElement = columnList.get(i);
if (!insertElement.getMetadataObject().isUpdatable())
continue;
final String elementName = visitor.getNameFromElement(insertElement.getMetadataObject());
final Object value = valueList.get(i);
Object val;
if (value instanceof Literal) {
Literal literalValue = (Literal) value;
val = literalValue.getValue();
// .toString();
if (null != val && val instanceof String) {
// !val.isEmpty()) {
val = stripQutes((String) val);
}
} else {
val = value;
// .toString();
}
setValue(tableName, elementName, newObject, val, insertElement.getType());
}
return newObject;
}
Aggregations