* Platforms that support dynamic querying can override this to generate an EISInteraction.
*/
public DatasourceCall buildCallFromStatement(SQLStatement statement, DatabaseQuery query, AbstractSession session) {
if (query.isObjectLevelReadQuery()) {
ObjectLevelReadQuery readQuery = (ObjectLevelReadQuery)query;
MappedInteraction interaction = new MappedInteraction();
interaction.setProperty(OPERATION, MongoOperation.FIND);
interaction.setProperty(COLLECTION, ((EISDescriptor)query.getDescriptor()).getDataTypeName());
if (readQuery.getFirstResult() > 0) {
interaction.setProperty(SKIP, readQuery.getFirstResult());
}
if (readQuery.getMaxRows() > 0) {
interaction.setProperty(LIMIT, readQuery.getMaxRows());
}
if (readQuery.getFetchSize() > 0) {
interaction.setProperty(BATCH_SIZE, readQuery.getMaxRows());
}
DatabaseRecord row = new DatabaseRecord();
if (statement.getWhereClause() != null) {
appendExpressionToQueryRow(statement.getWhereClause(), row, query);
}
if (readQuery.hasOrderByExpressions()) {
DatabaseRecord sort = new DatabaseRecord();
for (Expression orderBy : readQuery.getOrderByExpressions()) {
appendExpressionToSortRow(orderBy, sort, query);
}
row.put(MongoRecord.SORT, sort);
}
if (readQuery.isReportQuery()) {
DatabaseRecord select = new DatabaseRecord();
for (Object field : ((SQLSelectStatement)statement).getFields()) {
if (field instanceof DatabaseField) {
select.put((DatabaseField)field, 1);
} else if (field instanceof Expression) {
Object value = extractValueFromExpression((Expression)field, readQuery);
if (!(value instanceof DatabaseField)) {
throw new EISException("Query too complex for Mongo translation, only field selects are supported in query: " + query);
}
select.put((DatabaseField)value, 1);
}
}
row.put("$select", select);
}
interaction.setInputRow(row);
return interaction;
}
throw new EISException("Query too complex for Mongo translation, only select queries are supported in query: " + query);
}