List of usage examples for com.mongodb DBObject put
Object put(String key, Object v);
From source file:com.aperigeek.dropvault.web.dao.MongoFileService.java
License:Open Source License
public InputStream get(String username, Resource resource, char[] password) throws IOException { DBCollection col = mongo.getDataBase().getCollection("contents"); DBObject filter = new BasicDBObject(); filter.put("resource", resource.getId()); DBObject result = col.findOne(filter); if (result.containsField("file")) { String fileName = (String) result.get("file"); File dataFile = new File(fileName); return readFile(dataFile, username, password); } else {// w ww . j a v a 2 s .co m byte[] binary = (byte[]) result.get("binary"); return new ByteArrayInputStream(binary); } }
From source file:com.apifest.oauth20.MongoDBManager.java
License:Apache License
@Override public void updateAccessTokenValidStatus(String accessToken, boolean valid) { BasicDBObject dbObject = new BasicDBObject(); dbObject.put("token", accessToken); DBCollection coll = db.getCollection(ACCESS_TOKEN_COLLECTION_NAME); List<DBObject> list = coll.find(dbObject).toArray(); if (list.size() > 0) { DBObject newObject = list.get(0); newObject.put("valid", valid); coll.findAndModify(dbObject, newObject); }/*w ww . j a va 2 s.co m*/ }
From source file:com.apifest.oauth20.MongoDBManager.java
License:Apache License
@Override public void updateAuthCodeValidStatus(String authCode, boolean valid) { BasicDBObject dbObject = new BasicDBObject(); dbObject.put("code", authCode); DBCollection coll = db.getCollection(AUTH_CODE_COLLECTION_NAME); List<DBObject> list = coll.find(dbObject).toArray(); if (list.size() > 0) { DBObject newObject = list.get(0); newObject.put("valid", valid); coll.findAndModify(dbObject, newObject); }/* ww w .j a va 2 s . c om*/ }
From source file:com.apifest.oauth20.MongoDBManager.java
License:Apache License
@Override public boolean updateClientApp(String clientId, String scope, String description, Integer status, Map<String, String> applicationDetails) { boolean updated = false; DBCollection coll = db.getCollection(CLIENTS_COLLECTION_NAME); BasicDBObject query = new BasicDBObject(ID_NAME, clientId); List<DBObject> list = coll.find(query).toArray(); if (list.size() > 0) { DBObject newObject = list.get(0); if (scope != null && scope.length() > 0) { newObject.put("scope", scope); }//from w w w. ja v a 2s.co m if (description != null && description.length() > 0) { newObject.put("descr", description); } if (status != null) { newObject.put("status", status); } if (applicationDetails != null && applicationDetails.size() > 0) { newObject.put("applicationDetails", applicationDetails); } coll.findAndModify(query, newObject); updated = true; } return updated; }
From source file:com.apifest.oauth20.persistence.mongodb.MongoDBManager.java
License:Apache License
@Override public void updateAccessTokenValidStatus(String accessToken, boolean valid) { BasicDBObject dbObject = new BasicDBObject(); dbObject.put("token", accessToken); DBCollection coll = db.getCollection(ACCESS_TOKEN_COLLECTION_NAME); DBObject newObject = coll.find(dbObject).next(); if (newObject != null) { newObject.put("valid", valid); coll.findAndModify(dbObject, newObject); }//from w w w . ja va 2s. c om }
From source file:com.apifest.oauth20.persistence.mongodb.MongoDBManager.java
License:Apache License
@Override public void updateAuthCodeValidStatus(String authCode, boolean valid) { BasicDBObject dbObject = new BasicDBObject(); dbObject.put("code", authCode); DBCollection coll = db.getCollection(AUTH_CODE_COLLECTION_NAME); DBObject newObject = coll.find(dbObject).next(); if (newObject != null) { newObject.put("valid", valid); coll.findAndModify(dbObject, newObject); }/* www . ja va 2s. c o m*/ }
From source file:com.apifest.oauth20.persistence.mongodb.MongoDBManager.java
License:Apache License
@Override public boolean updateClientApp(String clientId, String scope, String description, Integer status, Map<String, String> applicationDetails) { boolean updated = false; DBCollection coll = db.getCollection(CLIENTS_COLLECTION_NAME); BasicDBObject query = new BasicDBObject(CLIENTS_ID, clientId); List<DBObject> list = coll.find(query).toArray(); if (list.size() > 0) { DBObject newObject = list.get(0); if (scope != null && scope.length() > 0) { newObject.put("scope", scope); }/* ww w.j av a 2 s .com*/ if (description != null && description.length() > 0) { newObject.put("descr", description); } if (status != null) { newObject.put("status", status); } if (applicationDetails != null && applicationDetails.size() > 0) { newObject.put("applicationDetails", applicationDetails); } coll.findAndModify(query, newObject); updated = true; } return updated; }
From source file:com.arquivolivre.mongocom.utils.IntegerGenerator.java
License:Apache License
@Override public Integer generateValue(Class parent, DB db) { DBCollection collection = db.getCollection("values_" + parent.getSimpleName()); DBObject o = collection.findOne(); int value = 0; if (o != null) { value = (int) o.get("generatedValue"); } else {/*from w w w . ja va 2 s .com*/ o = new BasicDBObject("generatedValue", value); } o.put("generatedValue", ++value); collection.save(o); return value; }
From source file:com.avanza.ymer.FakeDocumentCollection.java
License:Apache License
@Override public void insert(DBObject dbObject) { for (DBObject object : collection) { if (object.get("_id").equals(dbObject.get("_id"))) { throw new DuplicateDocumentKeyException("_id: " + dbObject.get("_id")); }/*from w w w. j a va2 s . c o m*/ } if (dbObject.get("_id") == null) { dbObject.put("_id", "testid_" + idGenerator.incrementAndGet()); } collection.add(dbObject); }
From source file:com.avbravo.ejbjmoordb.mongodb.internal.JavaToDocument.java
@SuppressWarnings("rawtypes") public Object toDBObjectRecursive(Object object, FieldDescriptor fieldDescriptor, List<EmbeddedBeans> embeddedBeansList, List<ReferencedBeans> referencedBeansList) { if (object == null) { return null; }/*from w w w.j a v a2s .c om*/ if (fieldDescriptor.isArray()) { //Test.msg(" isArray"); if (ReflectionUtils.isSimpleClass(fieldDescriptor.getField().getType().getComponentType())) { return fieldDescriptor.getFieldValue(object); } else { Object[] array = (Object[]) fieldDescriptor.getFieldValue(object); BasicDBList fieldObj = new BasicDBList(); for (Object el : array) { fieldObj.add(toDocument(el, embeddedBeansList, referencedBeansList)); } return fieldObj; } } else if (fieldDescriptor.isIterable()) { Iterable col = (Iterable) fieldDescriptor.getFieldValue(object); BasicDBList fieldObj = new BasicDBList(); if (col != null) { for (Object el : col) { if (ReflectionUtils.isSimpleClass(el.getClass())) { fieldObj.add(el); } else { if (isEmbedded(fieldDescriptor.getName())) { fieldObj.add(toDocument(el, embeddedBeansList, referencedBeansList)); } else { if (isReferenced(fieldDescriptor.getName())) { //aris ClassDescriptor classD = cache.get(el.getClass()); for (FieldDescriptor fieldDesc : classD.getFields()) { if (fieldDesc.getName().equals(referencedBeans.getField())) { fieldObj.add(toDocumentReferenced(el, referencedBeans.getField())); } } //aris } else { //Test.msg("..........no es embebido ni referenciado"); } } } } } return fieldObj; } else if (fieldDescriptor.isObject()) { ////Test.msg(" fieldDescriptor.isObject() "); if (isEmbedded(fieldDescriptor.getName())) { //Embebido Object fieldValue = fieldDescriptor.getFieldValue(object); if (fieldValue == null) { return null; } DBObject dbObject = new BasicDBObject(); for (FieldDescriptor childDescriptor : fieldDescriptor.getChildren()) { dbObject.put(childDescriptor.getName(), toDBObjectRecursive(fieldValue, childDescriptor, embeddedBeansList, referencedBeansList)); } return dbObject; } else { if (isReferenced(fieldDescriptor.getName())) { //Referenciado Object fieldValue = fieldDescriptor.getFieldValue(object); if (fieldValue == null) { return null; } DBObject dbObject = new BasicDBObject(); for (FieldDescriptor childDescriptor : fieldDescriptor.getChildren()) { if (childDescriptor.getName().equals(referencedBeans.getField())) { dbObject.put(childDescriptor.getName(), toDBObjectRecursive(fieldValue, childDescriptor, embeddedBeansList, referencedBeansList)); } } return dbObject; } else { //Test.msg(" [No es Referenced]"); new JmoordbException( "@Embedded or @Reference is required for this field " + fieldDescriptor.getName()); return new BasicDBObject(); } } } else if (fieldDescriptor.isMap()) { //Test.msg("=========================="); //Test.msg("fieldDescriptor.isMap()"); //Test.msg("=========================="); DBObject dbObject = new BasicDBObject(); Map map = (Map) fieldDescriptor.getFieldValue(object); for (Object key : map.keySet()) { Object el = map.get(key); if (el == null || ReflectionUtils.isSimpleClass(el.getClass())) { dbObject.put(key.toString(), el); } else { dbObject.put(key.toString(), toDocument(el, embeddedBeansList, referencedBeansList)); } } return dbObject; } else { //valor del atributo que no es otra clase return fieldDescriptor.getFieldValue(object); } }