Search in sources :

Example 1 with MongoOperation

use of org.wso2.dss.connectors.mongodb.MongoDBDSConstants.MongoOperation in project wso2-dss-connectors by wso2-attic.

the class MongoDBDataSource method decodeQuery.

private Object[] decodeQuery(String query) throws DataServiceFault {
    int i1 = query.indexOf('.');
    if (i1 == -1) {
        throw new DataServiceFault("The MongoDB Collection not specified in the query '" + query + "'");
    }
    String collection = query.substring(0, i1).trim();
    int i2 = query.indexOf('(', i1);
    if (i2 == -1 || i2 - i1 <= 1) {
        throw new DataServiceFault("Invalid MongoDB operation in the query '" + query + "'");
    }
    String operation = query.substring(i1 + 1, i2).trim();
    int i3 = query.lastIndexOf(')');
    if (i3 == -1) {
        throw new DataServiceFault("Invalid MongoDB operation in the query '" + query + "'");
    }
    String opQuery = null;
    if (i3 - i2 > 1) {
        opQuery = query.substring(i2 + 1, i3).trim();
    }
    MongoOperation mongoOp = this.convertToMongoOp(operation);
    if (mongoOp == MongoOperation.UPDATE) {
        List<Object> result = new ArrayList<Object>();
        result.add(collection);
        result.add(mongoOp);
        result.addAll(parseInsertQuery(opQuery));
        return result.toArray();
    } else {
        return new Object[] { collection, mongoOp, this.checkAndCleanOpQuery(opQuery) };
    }
}
Also used : MongoOperation(org.wso2.dss.connectors.mongodb.MongoDBDSConstants.MongoOperation) DataServiceFault(org.wso2.carbon.dataservices.core.DataServiceFault) ArrayList(java.util.ArrayList) DBObject(com.mongodb.DBObject)

Aggregations

DBObject (com.mongodb.DBObject)1 ArrayList (java.util.ArrayList)1 DataServiceFault (org.wso2.carbon.dataservices.core.DataServiceFault)1 MongoOperation (org.wso2.dss.connectors.mongodb.MongoDBDSConstants.MongoOperation)1