use of com.mongodb.BasicDBList in project teiid by teiid.
the class MongoDBSelectVisitor method visit.
@Override
public void visit(Array array) {
append(array.getExpressions());
BasicDBList values = new BasicDBList();
for (int i = 0; i < array.getExpressions().size(); i++) {
values.add(0, this.onGoingExpression.pop());
}
this.onGoingExpression.push(values);
}
use of com.mongodb.BasicDBList in project teiid by teiid.
the class MongoDBSelectVisitor method visitDerivedExpression.
private void visitDerivedExpression(Comparison obj) {
append(obj.getLeftExpression());
Object leftExpr = this.onGoingExpression.pop();
append(obj.getRightExpression());
Object rightExpr = this.onGoingExpression.pop();
BasicDBList values = new BasicDBList();
values.add(0, leftExpr);
values.add(1, rightExpr);
switch(obj.getOperator()) {
case EQ:
// $NON-NLS-1$
this.onGoingExpression.push(new BasicDBObject("$eq", values));
break;
case NE:
// $NON-NLS-1$
this.onGoingExpression.push(new BasicDBObject("$ne", values));
break;
case LT:
// $NON-NLS-1$
this.onGoingExpression.push(new BasicDBObject("$lt", values));
break;
case LE:
// $NON-NLS-1$
this.onGoingExpression.push(new BasicDBObject("$lte", values));
break;
case GT:
// $NON-NLS-1$
this.onGoingExpression.push(new BasicDBObject("$gt", values));
break;
case GE:
// $NON-NLS-1$
this.onGoingExpression.push(new BasicDBObject("$gte", values));
break;
}
}
use of com.mongodb.BasicDBList in project teiid by teiid.
the class MongoDBSelectVisitor method buildNE.
private BasicDBObject buildNE(Object leftExpr, Object rightExpr) {
BasicDBList values = new BasicDBList();
values.add(0, leftExpr);
values.add(1, rightExpr);
return new BasicDBObject("$ne", values);
}
use of com.mongodb.BasicDBList in project teiid by teiid.
the class MongoDBSelectVisitor method buildGeoNearFunction.
private DBObject buildGeoNearFunction(Function function) throws TranslatorException {
List<Expression> args = function.getParameters();
// Column Name
int paramIndex = 0;
ColumnDetail column = getExpressionAlias(args.get(paramIndex++));
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
builder.push(column.documentFieldName);
builder.push(function.getName());
append(args.get(paramIndex++));
Object object = this.onGoingExpression.pop();
if (object instanceof GeometryType) {
convertGeometryToJson(builder, (GeometryType) object);
} else {
// $NON-NLS-1$
builder.push("$geometry");
// $NON-NLS-1$
builder.add("type", SpatialType.Point.name());
// walk the co-ordinates
BasicDBList coordinates = new BasicDBList();
coordinates.add(object);
// $NON-NLS-1$
builder.add("coordinates", coordinates);
}
// maxdistance
append(args.get(paramIndex++));
BasicDBObjectBuilder b = builder.pop();
// $NON-NLS-1$
b.add("$maxDistance", this.onGoingExpression.pop());
if (this.executionFactory.getVersion().compareTo(MongoDBExecutionFactory.TWO_6) >= 0) {
// mindistance
append(args.get(paramIndex++));
// $NON-NLS-1$
b.add("$minDistance", this.onGoingExpression.pop());
}
return builder.get();
}
use of com.mongodb.BasicDBList in project teiid by teiid.
the class MongoDBSelectVisitor method buildGeoFunction.
private DBObject buildGeoFunction(Function function) throws TranslatorException {
List<Expression> args = function.getParameters();
// Column Name
int paramIndex = 0;
ColumnDetail column = getExpressionAlias(args.get(paramIndex++));
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
builder.push(column.documentFieldName);
builder.push(function.getName());
append(args.get(paramIndex++));
Object object = this.onGoingExpression.pop();
if (object instanceof GeometryType) {
convertGeometryToJson(builder, (GeometryType) object);
} else {
// Type: Point, LineString, Polygon..
SpatialType type = SpatialType.valueOf((String) object);
append(args.get(paramIndex++));
// $NON-NLS-1$
builder.push("$geometry");
// $NON-NLS-1$
builder.add("type", type.name());
// walk the co-ordinates
BasicDBList coordinates = new BasicDBList();
coordinates.add(this.onGoingExpression.pop());
// $NON-NLS-1$
builder.add("coordinates", coordinates);
}
return builder.get();
}
Aggregations