use of org.teiid.language.Expression in project teiid by teiid.
the class ConcatFunctionModifier method translate.
@Override
public List<?> translate(Function function) {
Expression a = function.getParameters().get(0);
Expression b = function.getParameters().get(1);
List<Condition> crits = new ArrayList<Condition>();
Literal nullValue = langFactory.createLiteral(null, TypeFacility.RUNTIME_TYPES.STRING);
if (isNull(a)) {
return Arrays.asList(nullValue);
} else if (!isNotNull(a)) {
crits.add(langFactory.createIsNullCriteria(a, false));
}
if (isNull(b)) {
return Arrays.asList(nullValue);
} else if (!isNotNull(b)) {
crits.add(langFactory.createIsNullCriteria(b, false));
}
Condition crit = null;
if (crits.isEmpty()) {
return null;
} else if (crits.size() == 1) {
crit = crits.get(0);
} else {
crit = langFactory.createAndOr(Operator.OR, crits.get(0), crits.get(1));
}
List<SearchedWhenClause> cases = Arrays.asList(langFactory.createSearchedWhenCondition(crit, nullValue));
return Arrays.asList(langFactory.createSearchedCaseExpression(cases, function, TypeFacility.RUNTIME_TYPES.STRING));
}
use of org.teiid.language.Expression in project teiid by teiid.
the class MonthOrDayNameFunctionModifier method translate.
@Override
public List<?> translate(Function function) {
List<Expression> args = function.getParameters();
Function func = // $NON-NLS-1$
langFactory.createFunction(// $NON-NLS-1$
"TO_CHAR", Arrays.asList(args.get(0), langFactory.createLiteral(format, TypeFacility.RUNTIME_TYPES.STRING)), TypeFacility.RUNTIME_TYPES.STRING);
// For some reason, these values have trailing spaces
Function trimFunc = langFactory.createFunction(SourceSystemFunctions.RTRIM, Arrays.asList(func), TypeFacility.RUNTIME_TYPES.STRING);
return Arrays.asList(trimFunc);
}
use of org.teiid.language.Expression 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.Expression in project teiid by teiid.
the class CoherenceUpdateExecution method updateChildObject.
private void updateChildObject(Table t) throws TranslatorException {
List<ForeignKey> fks = t.getForeignKeys();
ForeignKey fk = fks.get(0);
Table parentTable = fk.getParent();
// the name of the method to obtain the collection is the nameInSource of the foreginKey
String parentToChildMethod = fk.getNameInSource();
if (parentToChildMethod == null) {
// $NON-NLS-1$
final String msg = CoherencePlugin.Util.getString("CoherenceUpdateExecution.noNameInSourceForForeingKey", new Object[] { fk.getName() });
throw new TranslatorException(msg);
}
// there must only be 1 column in the primary key
String parentColName = visitor.getNameFromElement(fk.getPrimaryKey().getColumns().get(0));
List<SetClause> updateList = ((Update) command).getChanges();
Condition criteria = ((Update) command).getWhere();
ColumnReference leftElement;
Expression rightExpr;
String nameLeftElement;
Object valueRightExpr;
// API).
for (int i = 0; i < updateList.size(); i++) {
SetClause setClause = updateList.get(i);
// trust that connector API is right and left side
// will always be an IElement
leftElement = setClause.getSymbol();
// call utility method to get NameInSource/Name for element
nameLeftElement = visitor.getNameFromElement(leftElement.getMetadataObject());
// get right expression - if it is not a literal we
// can't handle that so throw an exception
rightExpr = setClause.getValue();
// if (!(rightExpr instanceof Literal)) {
// final String msg = CoherencePlugin.Util.getString("LDAPUpdateExecution.valueNotLiteralError",nameLeftElement); //$NON-NLS-1$
// throw new TranslatorException(msg);
// }
valueRightExpr = ((Literal) rightExpr).getValue();
// add in the modification as a replacement - meaning
// any existing value(s) for this attribute will
// be replaced by the new value. If the attribute
// didn't exist, it will automatically be created
// TODO - since null is a valid attribute
// value, we don't do any special handling of it right
// now. But maybe null should mean to delete an
// attribute?
}
}
use of org.teiid.language.Expression in project teiid by teiid.
the class CoherenceVisitor method visit.
public void visit(Comparison obj) {
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing Comparison criteria.");
try {
Comparison.Operator op = ((Comparison) obj).getOperator();
Expression lhs = ((Comparison) obj).getLeftExpression();
Expression rhs = ((Comparison) obj).getRightExpression();
String lhsString = getExpressionString(lhs);
String rhsString = getExpressionString(rhs);
if (lhsString == null || rhsString == null) {
// $NON-NLS-1$
final String msg = CoherencePlugin.Util.getString("CoherenceVisitor.missingComparisonExpression");
exception = new TranslatorException(msg);
}
if (rhs instanceof Literal || lhs instanceof Literal) {
if (rhs instanceof Literal) {
Literal literal = (Literal) rhs;
addCompareCriteria(lhsString, literal.getValue(), op, literal.getType());
// filter = CoherenceFilterUtil.createCompareFilter(lhsString, literal.getValue(), op, literal.getType() );
} else {
Literal literal = (Literal) lhs;
addCompareCriteria(rhsString, literal.getValue(), op, literal.getType());
// filter = CoherenceFilterUtil.createCompareFilter(rhsString, literal.getValue(), op, literal.getType() );
}
}
} catch (TranslatorException t) {
exception = t;
}
}
Aggregations