use of org.teiid.metadata.Column in project teiid by teiid.
the class CriteriaVisitor method isIdColumn.
protected boolean isIdColumn(Expression expression) {
boolean result = false;
if (expression instanceof ColumnReference) {
Column element = ((ColumnReference) expression).getMetadataObject();
String nameInSource = element.getSourceName();
if (nameInSource.equalsIgnoreCase("id")) {
// $NON-NLS-1$
result = true;
}
}
return result;
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class CriteriaVisitor method isMultiSelectColumn.
protected boolean isMultiSelectColumn(Expression expression) {
boolean result = false;
if (expression instanceof ColumnReference) {
Column element = ((ColumnReference) expression).getMetadataObject();
String nativeType = element.getNativeType();
if (MULTIPICKLIST.equalsIgnoreCase(nativeType) || RESTRICTEDMULTISELECTPICKLIST.equalsIgnoreCase(nativeType)) {
result = true;
}
}
return result;
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class CriteriaVisitor method generateMultiSelect.
private void generateMultiSelect(Function func, String funcName) throws TranslatorException {
List<Expression> expressions = func.getParameters();
validateFunction(expressions);
Expression columnExpression = expressions.get(0);
Column column = ((ColumnReference) columnExpression).getMetadataObject();
criteriaBuffer.add(column.getSourceName());
criteriaBuffer.add(SPACE);
criteriaBuffer.add(funcName);
criteriaBuffer.add(OPEN);
String fullParam = ((Literal) expressions.get(1)).toString();
// $NON-NLS-1$
String[] params = fullParam.split(",");
for (int i = 0; i < params.length; i++) {
String token = params[i];
if (i != 0) {
criteriaBuffer.add(COMMA);
}
criteriaBuffer.add(Util.addSingleQuotes(token));
}
criteriaBuffer.add(CLOSE);
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class JoinQueryVisitor method visit.
// Has to be a left outer join of only 2 tables. criteria must be a compare
@Override
public void visit(Join join) {
try {
TableReference left = join.getLeftItem();
NamedTable leftGroup = (NamedTable) left;
leftTableInJoin = leftGroup.getMetadataObject();
loadColumnMetadata(leftGroup);
TableReference right = join.getRightItem();
NamedTable rightGroup = (NamedTable) right;
rightTableInJoin = rightGroup.getMetadataObject();
loadColumnMetadata((NamedTable) right);
Comparison criteria = (Comparison) join.getCondition();
Expression lExp = criteria.getLeftExpression();
Expression rExp = criteria.getRightExpression();
if (isIdColumn(rExp) || isIdColumn(lExp)) {
Column rColumn = ((ColumnReference) rExp).getMetadataObject();
String rTableName = rColumn.getParent().getSourceName();
Column lColumn = ((ColumnReference) lExp).getMetadataObject();
String lTableName = lColumn.getParent().getSourceName();
if (leftTableInJoin.getSourceName().equals(rTableName) || leftTableInJoin.getSourceName().equals(lTableName) && rightTableInJoin.getSourceName().equals(rTableName) || rightTableInJoin.getSourceName().equals(lTableName) && !rTableName.equals(lTableName)) {
// This is the join criteria, the one that is the ID is the parent.
Expression fKey = !isIdColumn(lExp) ? lExp : rExp;
ColumnReference columnReference = (ColumnReference) fKey;
table = childTable = (Table) columnReference.getMetadataObject().getParent();
String name = columnReference.getMetadataObject().getSourceName();
if (StringUtil.endsWithIgnoreCase(name, "id")) {
this.parentName = name.substring(0, name.length() - 2);
} else if (name.endsWith("__c")) {
// $NON-NLS-1$
// $NON-NLS-1$
this.parentName = name.substring(0, name.length() - 1) + "r";
}
Table parent = leftTableInJoin;
if (isChildToParentJoin()) {
parent = rightTableInJoin;
}
for (ForeignKey fk : childTable.getForeignKeys()) {
if (fk.getColumns().get(0).equals(columnReference.getMetadataObject()) && fk.getReferenceKey().equals(parent.getPrimaryKey())) {
foreignKey = fk;
break;
}
}
// inner joins require special handling as relationship queries are outer by default
if (join.getJoinType() == JoinType.INNER_JOIN) {
if (!isChildToParentJoin()) {
// flip the relationship
Table t = leftTableInJoin;
this.leftTableInJoin = rightTableInJoin;
this.rightTableInJoin = t;
}
// add is null criteria
addCriteria(new Comparison(fKey, new Literal(null, fKey.getType()), Comparison.Operator.NE));
}
} else {
// Only add the criteria to the query if it is not the join criteria.
// The join criteria is implicit in the salesforce syntax.
// TODO: not valid
super.visit(criteria);
}
} else {
// TODO: not valid
super.visit(criteria);
}
} catch (TranslatorException ce) {
exceptions.add(ce);
}
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class SelectVisitor method visit.
@Override
public void visit(Select query) {
super.visitNodes(query.getFrom());
Condition condition = query.getWhere();
if (this.implicitCondition != null) {
if (condition != null) {
condition = LanguageFactory.INSTANCE.createAndOr(Operator.AND, condition, this.implicitCondition);
} else {
condition = implicitCondition;
}
}
super.visitNode(condition);
super.visitNode(query.getGroupBy());
if (query.getHaving() != null) {
// since the base is a criteria hierarchy visitor,
// we must separately visit the having clause
// TODO: if further uses of criteria come up, we should not use hierarchy visitor as the base
Condition c = query.getHaving();
CriteriaVisitor cv = new CriteriaVisitor(this.metadata);
cv.visitNode(c);
cv.addCriteriaString(SQLConstants.Reserved.HAVING, this.havingClause);
if (this.havingClause.length() > 0) {
this.havingClause.append(SPACE);
}
}
super.visitNode(query.getLimit());
if (query.isDistinct()) {
// $NON-NLS-1$
exceptions.add(new TranslatorException(SalesForcePlugin.Util.getString("SelectVisitor.distinct.not.supported")));
}
selectSymbols = query.getDerivedColumns();
selectSymbolCount = selectSymbols.size();
for (int index = 0; index < selectSymbols.size(); index++) {
DerivedColumn symbol = selectSymbols.get(index);
// get the name in source
Expression expression = symbol.getExpression();
selectSymbolIndexToElement.put(index, expression);
if (expression instanceof ColumnReference) {
Column element = ((ColumnReference) expression).getMetadataObject();
String nameInSource = element.getSourceName();
if (nameInSource.equalsIgnoreCase("id")) {
// $NON-NLS-1$
idIndex = index;
}
}
}
}
Aggregations