List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject(final String key, final Object value)
From source file:bd.DSession.java
@Override public ArrayList listar(String clave, String valor) { ArrayList datos = new ArrayList(); CSession x = new CSession(); conecion con = new conecion(table); BasicDBObject id = new BasicDBObject(clave, valor); DBCursor cursor = con.get_colletion().find(id); try {//from w w w .j a v a2 s .co m while (cursor.hasNext()) { x = new CSession(); x.set_datos((HashMap) cursor.next().toMap()); datos.add(x); } } finally { cursor.close(); } con.end(); return datos; }
From source file:bd.DVenta.java
@Override public String eliminar(Object o) { CVenta x = (CVenta) o;/*from w w w . j av a2 s .c o m*/ conecion con = new conecion(table); BasicDBObject datos = new BasicDBObject("_id", x.getId()); con.get_colletion().remove(datos); con.end(); return datos.getString("_id"); }
From source file:bd.DVenta.java
@Override public Object buscar_id(String id_find) { ArrayList datos = new ArrayList(); CVenta x = new CVenta(); conecion con = new conecion(table); BasicDBObject id = new BasicDBObject("_id", new ObjectId(id_find)); DBCursor cursor = con.get_colletion().find(id); try {/*from w w w . j av a 2s. c o m*/ while (cursor.hasNext()) { x = new CVenta(); x.set_datos((HashMap) cursor.next().toMap()); datos.add(x); } } finally { cursor.close(); } con.end(); if (datos.size() == 0) return null; return datos.get(0); }
From source file:bd.DVenta.java
@Override public ArrayList listar(String clave, String valor) { ArrayList datos = new ArrayList(); CVenta x = new CVenta(); conecion con = new conecion(table); BasicDBObject id = new BasicDBObject(clave, valor); DBCursor cursor = con.get_colletion().find(id); try {//from w w w . j av a2 s .c o m while (cursor.hasNext()) { x = new CVenta(); x.set_datos((HashMap) cursor.next().toMap()); datos.add(x); } } finally { cursor.close(); } con.end(); return datos; }
From source file:be.datablend.blueprints.impls.mongodb.MongoDBQuery.java
@Override public GraphQuery hasNot(String key) { super.hasNot(key); String operator = "$exists"; BasicDBObject queryObj = new BasicDBObject(operator, false); query.append(MongoDBUtil.createPropertyKey(key), queryObj); return this; }
From source file:be.datablend.blueprints.impls.mongodb.MongoDBQuery.java
@Override public GraphQuery has(String key) { super.has(key); String operator = "$exists"; BasicDBObject queryObj = new BasicDBObject(operator, true); query.append(MongoDBUtil.createPropertyKey(key), queryObj); return this; }
From source file:be.nille.blog.mongo.post.MongoPostService.java
@Override public List<Post> findByPageInfo(PageInfo pageInfo) { FindIterable<Document> iterable = collection.find().skip(pageInfo.getOffset()).limit(pageInfo.getLimit()) .sort(new BasicDBObject("createdDate", -1)); return getPostsByIterable(iterable); }
From source file:be.solidx.hot.data.rest.RestDataStore.java
License:Open Source License
protected Object convert(Object value) { try {/*from w w w. jav a2 s. co m*/ return conversionService.convert(value, Long.class); } catch (Exception e) { try { return conversionService.convert(value, Date.class); } catch (Exception e1) { try { return conversionService.convert(value, Boolean.class); } catch (Exception e2) { try { String decoded = URLDecoder.decode(value.toString(), "utf-8"); if (decoded.startsWith("/") && decoded.endsWith("/")) { return new BasicDBObject("$regex", StringUtils.substring(decoded, 1, -1)); } else { return decoded; } } catch (UnsupportedEncodingException e3) { return value.toString(); } } } } }
From source file:bhl.pages.database.MongoConnection.java
License:Open Source License
/** * Fetch a resource from the server via a given field value * @param collName the collection or database name * @param value the value of the field/* w w w . j av a2 s .c o m*/ * @param field the field name * @return the response as a string or null if not found */ @Override public String getFromDbByIntField(String collName, int value, String field) throws DbException { try { connect(); DBCollection coll = getCollectionFromName(collName); DBObject query = new BasicDBObject(field, value); DBObject obj = coll.findOne(query); if (obj != null) return obj.toString(); else return null; } catch (Exception e) { throw new DbException(e); } }
From source file:bhl.pages.database.MongoConnection.java
License:Open Source License
/** * Make a subset of the documents by a given subkey and value, * then retrieve all the values of the field * @param collection the collection to search * @param subKey the subKey to make the initial choice * @param subValue the value of the subKey to search for * @param fields the field names to retrieve * @return and array of field values as JSON object strings * @throws DbException //from w w w . j av a 2s . c om */ @Override public String[] listCollectionBySubKey(String collection, String subKey, String subValue, String[] fields) throws DbException { try { connect(); DBCollection coll = getCollectionFromName(collection); DBObject query = new BasicDBObject(subKey, subValue); BasicDBObject keys = new BasicDBObject(); for (int i = 0; i < fields.length; i++) keys.put(fields[i], 1); DBCursor cursor = coll.find(query, keys); if (cursor.length() > 0) { String[] array = new String[cursor.length()]; Iterator iter = cursor.iterator(); int i = 0; while (iter.hasNext()) { DBObject bson = (DBObject) iter.next(); JSONObject jobj = new JSONObject(); for (int j = 0; j < fields.length; j++) jobj.put(fields[j], bson.get(fields[j])); array[i++] = jobj.toJSONString(); } return array; } else return new String[0]; } catch (Exception e) { throw new DbException(e); } }