use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataResponse method parsePayload.
private Iterator<ODataDocument> parsePayload(InputStream payload) throws TranslatorException {
try {
JsonDeserializer parser = new JsonDeserializer(false);
if (this.resultsType == ODataType.ENTITY) {
Entity entity = parser.toEntity(payload).getPayload();
ODataDocument document = ODataDocument.createDocument(entity);
return Arrays.asList(document).iterator();
} else if (this.resultsType == ODataType.ENTITY_COLLECTION) {
EntityCollection entityCollection = parser.toEntitySet(payload).getPayload();
this.nextUri = entityCollection.getNext();
ArrayList<ODataDocument> documents = new ArrayList<ODataDocument>();
for (Entity entity : entityCollection.getEntities()) {
documents.add(ODataDocument.createDocument(entity));
}
return documents.iterator();
} else {
// complex
Property property = parser.toProperty(payload).getPayload();
if (property.isCollection()) {
ArrayList<ODataDocument> documents = new ArrayList<ODataDocument>();
for (Object obj : property.asCollection()) {
ComplexValue complexValue = (ComplexValue) obj;
documents.add(ODataDocument.createDocument(complexValue));
}
return documents.iterator();
} else {
ODataDocument document = ODataDocument.createDocument(property.asComplex());
return Arrays.asList(document).iterator();
}
}
} catch (ODataDeserializerException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataSQLVisitor method visit.
@Override
public void visit(SortSpecification obj) {
if (this.orderBy.length() > 0) {
this.orderBy.append(Tokens.COMMA);
}
ColumnReference column = (ColumnReference) obj.getExpression();
try {
Column c = ODataMetadataProcessor.normalizePseudoColumn(this.metadata, column.getMetadataObject());
this.orderBy.append(c.getName());
} catch (TranslatorException e) {
this.exceptions.add(e);
}
// default is ascending
if (obj.getOrdering() == Ordering.DESC) {
this.orderBy.append(Tokens.SPACE).append(DESC.toLowerCase());
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class QueryExecutionImpl method parseDateTime.
static Object parseDateTime(String value, Class<?> type, Calendar cal) throws TranslatorException {
try {
Matcher m = dateTimePattern.matcher(value);
if (m.matches()) {
String date = m.group(1);
String time = m.group(2);
String timeZone = m.group(3);
Date d = null;
if (date == null) {
// sql times don't care about fractional seconds
int milli = time.lastIndexOf('.');
if (milli > 0) {
time = time.substring(0, milli);
}
d = Time.valueOf(time);
} else {
// $NON-NLS-1$
d = Timestamp.valueOf(date + " " + time);
}
TimeZone tz = null;
if (timeZone != null) {
if (timeZone.equals("Z")) {
// $NON-NLS-1$
// $NON-NLS-1$
tz = TimeZone.getTimeZone("GMT");
} else if (timeZone.contains(":")) {
// $NON-NLS-1$
// $NON-NLS-1$
tz = TimeZone.getTimeZone("GMT" + timeZone);
} else {
// this is probably an exceptional case
tz = TimeZone.getTimeZone(timeZone);
}
cal.setTimeZone(tz);
} else {
cal = null;
}
return TimestampWithTimezone.create(d, TimeZone.getDefault(), cal, type);
}
// $NON-NLS-1$
throw new TranslatorException(SalesForcePlugin.Util.getString("SalesforceQueryExecutionImpl.datatime.parse") + value);
} catch (IllegalArgumentException e) {
// $NON-NLS-1$
throw new TranslatorException(e, SalesForcePlugin.Util.getString("SalesforceQueryExecutionImpl.datatime.parse") + value);
}
}
use of org.teiid.translator.TranslatorException 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.translator.TranslatorException 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