List of usage examples for com.mongodb.util JSONParseException getMessage
@Override
public String getMessage()
From source file:org.exist.mongodb.xquery.mongodb.collection.Group.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/*from w w w. java 2 s .co m*/ // Verify clientid and get client String mongodbClientId = args[0].itemAt(0).getStringValue(); MongodbClientStore.getInstance().validate(mongodbClientId); MongoClient client = MongodbClientStore.getInstance().get(mongodbClientId); // Get parameters String dbname = args[1].itemAt(0).getStringValue(); String collection = args[2].itemAt(0).getStringValue(); BasicDBObject key = (BasicDBObject) JSON.parse(args[3].itemAt(0).getStringValue()); BasicDBObject condition = (BasicDBObject) JSON.parse(args[4].itemAt(0).getStringValue()); BasicDBObject initial = (BasicDBObject) JSON.parse(args[5].itemAt(0).getStringValue()); String reduce = args[6].itemAt(0).getStringValue(); // The finalize can be null String finalize = (args.length >= 8) ? args[7].itemAt(0).getStringValue() : null; // Get database DB db = client.getDB(dbname); DBCollection dbcol = db.getCollection(collection); // Propare groupcommand GroupCommand command = new GroupCommand(dbcol, key, condition, initial, reduce, finalize); System.out.println(command.toDBObject().toString()); if (LOG.isDebugEnabled()) { LOG.debug(command.toDBObject().toString()); } // Execute, finalize can have value null DBObject result = dbcol.group(command); // Execute query Sequence retVal = new StringValue(result.toString()); return retVal; } catch (JSONParseException ex) { LOG.error(ex.getMessage()); throw new XPathException(this, MongodbModule.MONG0004, ex.getMessage()); } catch (XPathException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, ex.getMessage(), ex); } catch (MongoException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0002, ex.getMessage()); } catch (Throwable ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0003, ex.getMessage()); } }
From source file:org.exist.mongodb.xquery.mongodb.collection.MapReduce.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/*from w ww .jav a 2s. c o m*/ // Verify clientid and get client String mongodbClientId = args[0].itemAt(0).getStringValue(); MongodbClientStore.getInstance().validate(mongodbClientId); MongoClient client = MongodbClientStore.getInstance().get(mongodbClientId); // Get parameters String dbname = args[1].itemAt(0).getStringValue(); String collection = args[2].itemAt(0).getStringValue(); String map = args[3].itemAt(0).getStringValue(); String reduce = args[4].itemAt(0).getStringValue(); // output-target can have value null String outputTarget = args[5].isEmpty() ? null : args[5].itemAt(0).getStringValue(); OutputType outputType = args[6].isEmpty() ? OutputType.INLINE : OutputType.valueOf(args[6].itemAt(0).getStringValue().toUpperCase(Locale.US)); DBObject query = (BasicDBObject) JSON.parse(args[7].itemAt(0).getStringValue()); // Get collection in database DB db = client.getDB(dbname); DBCollection dbcol = db.getCollection(collection); // Execute query MapReduceOutput output = dbcol.mapReduce(map, reduce, outputTarget, outputType, query); // Parse results Sequence retVal = new ValueSequence(); for (DBObject result : output.results()) { retVal.add(new StringValue(result.toString())); } return retVal; } catch (JSONParseException ex) { LOG.error(ex.getMessage()); throw new XPathException(this, MongodbModule.MONG0004, ex.getMessage()); } catch (XPathException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, ex.getMessage(), ex); } catch (MongoCommandException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0005, ex.getMessage()); } catch (MongoException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0002, ex.getMessage()); } catch (Throwable ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0003, ex.getMessage()); } }
From source file:org.exist.mongodb.xquery.mongodb.collection.Remove.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/*from w w w. ja v a 2s . c o m*/ // Verify clientid and get client String mongodbClientId = args[0].itemAt(0).getStringValue(); MongodbClientStore.getInstance().validate(mongodbClientId); MongoClient client = MongodbClientStore.getInstance().get(mongodbClientId); // Get parameters String dbname = args[1].itemAt(0).getStringValue(); String collection = args[2].itemAt(0).getStringValue(); BasicDBObject query = (args.length >= 4) ? (BasicDBObject) JSON.parse(args[3].itemAt(0).getStringValue()) : null; // Get collection in database DB db = client.getDB(dbname); DBCollection dbcol = db.getCollection(collection); // Execute query WriteResult result = dbcol.remove(query); return new StringValue(result.toString()); } catch (JSONParseException ex) { LOG.error(ex.getMessage()); throw new XPathException(this, MongodbModule.MONG0004, ex.getMessage()); } catch (XPathException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, ex.getMessage(), ex); } catch (MongoException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0002, ex.getMessage()); } catch (Throwable ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0003, ex.getMessage()); } }