List of usage examples for com.mongodb DBObject get
Object get(String key);
From source file:cn.b2b.index.product.create.ProductDataFromDB.java
public ProductBean getProductData(DBObject obj) { if (obj == null) { return null; }//ww w.ja v a2 s .c o m ProductBean product = new ProductBean(); product.setId(toInt(obj.get("_id"))); int userid = toInt(obj.get("uid")); product.setUserid(userid); product.setState((byte) toInt(obj.get("ss"))); if (companyMap.get(userid) != null && companyMap.get(userid).getAuditState() == 0) { product.setState((byte) 0); } product.setAuditstate((byte) toInt(obj.get("wait"))); String title = String.valueOf(obj.get("titl")); if (title != null) { product.setTitle(title); } else { product.setTitle(""); } String content = toString(obj.get("con")); if (content != null) { if (content.length() > 500) { product.setContent(content.substring(0, 500)); } else { product.setContent(content); } } else { product.setContent(""); } product.setIndustryid(toInt(obj.get("inid"))); String tradeid = this.getTrade(toInt(obj.get("tr1"))); product.setTradeid(tradeid); product.setKeyword1(toString(obj.get("k1"))); product.setKeyword2(toString(obj.get("k2"))); product.setKeyword3(toString(obj.get("k3"))); product.setProvince(toInt(obj.get("prov"))); product.setCity(toInt(obj.get("city"))); String pic = toString(obj.get("pic1")); if (pic != null && pic.trim().length() > 0) { product.setHaspic(true); product.setPic("http://files.b2b.cn/product/ProductImages/" + pic); } else { product.setPic("http://img.b2b.cn/default/20120217/images/nop2.png"); product.setHaspic(false); } product.setPrice(toString(obj.get("pric"))); String p_property = toString(obj.get("pro")); String t_property = toString(obj.get("tpro")); DBObject json_p_property = null; try { json_p_property = (DBObject) JSON.parse(p_property); } catch (Exception ex) { product.setNotfindproperties(1); ex.printStackTrace(); } DBObject json_t_property = null; try { json_t_property = (DBObject) JSON.parse(t_property); } catch (Exception ex) { product.setNotfindproperties(1); ex.printStackTrace(); } product.setBrand(this.getProperty(json_p_property, "P1")); product.setSpec(this.getProperty(json_p_property, "P3")); product.setUnit(this.getProperty(json_t_property, "T35")); product.setMincount(this.getProperty(json_t_property, "T1")); product.setInsertdate(toDatetime(toInt(obj.get("atim")))); product.setUpdatedate(toDatetime(toInt(obj.get("utim")))); product.setOuttime(toDatetime(toInt(obj.get("utim")))); product.setUrl("http://detail.b2b.cn/product/" + product.getId() + ".html"); if (certiMap.get(userid) != null) { product.setLicense(1); } else { product.setLicense(0); } if (companyMap.get(userid) != null) { product.setCompany(companyMap.get(userid)); } else { product.setCompany(null); } product.setDatatype(2); product.setBuslincese(linceseMap.get(userid) == null ? 0 : 1); return product; }
From source file:cn.b2b.index.product.create.ProductDataFromDB.java
private String getProperty(DBObject object, String key) { if (object == null) return ""; return toString(object.get(key));// .get("P1")); }
From source file:cn.cnic.bigdatalab.flume.sink.mongodb.MongoSink.java
License:Apache License
/** * {@inheritDoc}/*w w w . ja va 2s . c o m*/ */ @Override public Status process() throws EventDeliveryException { log.debug("Executing MongoSink.process()..."); Status status = Status.READY; Channel channel = getChannel(); Transaction txn = channel.getTransaction(); try { txn.begin(); int count; List<Event> eventList = new ArrayList<Event>(); for (count = 0; count < batchSize; ++count) { Event event = channel.take(); if (event == null) { break; } eventList.add(event); } if (count <= 0) { sinkCounter.incrementBatchEmptyCount(); counterGroup.incrementAndGet("channel.underflow"); status = Status.BACKOFF; } else { if (count < batchSize) { sinkCounter.incrementBatchUnderflowCount(); status = Status.BACKOFF; } else { sinkCounter.incrementBatchCompleteCount(); } for (Event event : eventList) { final DBObject document = this.eventParser.parse(event); if (this.updateInsteadReplace && document.get("_id") != null) { // update requires '_id' field to match document BasicDBObject searchQuery = new BasicDBObject().append("_id", document.get("_id")); // update by _id BasicDBObject updatedDocument = new BasicDBObject().append("$set", document); getDBCollection(event).update(searchQuery, updatedDocument, true, false); } else { getDBCollection(event).save(document); } } sinkCounter.addToEventDrainAttemptCount(eventList.size()); } txn.commit(); sinkCounter.addToEventDrainSuccessCount(count); counterGroup.incrementAndGet("transaction.success"); } catch (ChannelException e) { log.error("Unexpected error while executing MongoSink.process", e); txn.rollback(); status = Status.BACKOFF; this.sinkCounter.incrementConnectionFailedCount(); } catch (Throwable t) { log.error("Unexpected error while executing MongoSink.process", t); txn.rollback(); status = Status.BACKOFF; if (t instanceof Error) { throw new MongoSinkException(t); } } finally { txn.close(); } return status; }
From source file:cn.vlabs.clb.server.storage.mongo.extend.MyGridFSDBFile.java
License:Apache License
byte[] getChunk(int i) { if (_fs == null) { throw new RuntimeException("no gridfs!"); }/* w w w. ja va 2 s . c o m*/ DBObject chunk = _fs._chunkCollection .findOne(BasicDBObjectBuilder.start("files_id", _id).add("n", i).get()); if (chunk == null) throw new MongoException("can't find a chunk! file id: " + _id + " chunk: " + i); return (byte[]) chunk.get("data"); }
From source file:cn.vlabs.clb.server.storage.mongo.extend.MyGridFSFile.java
License:Apache License
public void validate() { if (_fs == null) throw new MongoException("no _fs"); if (_md5 == null) throw new MongoException("no _md5 stored"); DBObject cmd = new BasicDBObject("filemd5", _id); cmd.put("root", _fs._bucketName); DBObject res = _fs._db.command(cmd); if (res != null && res.containsField("md5")) { String m = res.get("md5").toString(); if (m.equals(_md5)) return; throw new MongoException("md5 differ. mine [" + _md5 + "] theirs [" + m + "]"); }//from www.j a v a2 s.c o m // no md5 from the server throw new MongoException("no md5 returned from server: " + res); }
From source file:cn.vlabs.clb.server.storage.mongo.MongoStorageService.java
License:Apache License
private FileMeta findFileMeta(String storageKey, String tableName) { DB db = options.getCollection(TABLE_TEMP_KEY).getDB(); DBObject query = new BasicDBObject(); query.put(FIELD_STORAGE_KEY, new ObjectId(storageKey)); DBCollection c = db.getCollection(tableName + ".files"); DBObject r = c.findOne(query); if (r != null) { FileMeta fm = new FileMeta(); fm.setId(r.get("_id").toString()); fm.setAppid((int) r.get("appid")); fm.setContentType((String) r.get("contentType")); fm.setFilename((String) r.get("filename")); fm.setLength((long) r.get("length")); fm.setDocid((int) r.get("docid")); fm.setMd5((String) r.get("md5")); fm.setStorageKey(new ObjectId(r.get("storageKey").toString())); fm.setUploadDate((Date) r.get("uploadDate")); fm.setVid((String) r.get("vid")); return fm; }/*from ww w . j a v a2 s . c o m*/ return null; }
From source file:cn.vlabs.clb.server.storage.mongo.MongoStorageService.java
License:Apache License
private Set<Integer> queryChunkMap(String storageKey, String tableName) { DB db = options.getCollection(TABLE_TEMP_KEY).getDB(); DBObject query = new BasicDBObject(); query.put("storageKey", new ObjectId(storageKey)); Set<Integer> result = new HashSet<Integer>(); DBCollection chunkTable = db.getCollection(tableName + ".chunks"); DBObject ref = new BasicDBObject(); ref.put("files_id", new ObjectId(storageKey)); DBObject keys = new BasicDBObject(); keys.put("n", 1); DBCursor cursor = chunkTable.find(ref, keys); while (cursor.hasNext()) { DBObject o = cursor.next(); result.add(Integer.parseInt(o.get("n").toString())); }/* w ww. j ava 2s. c o m*/ return result; }
From source file:cn.vlabs.clb.server.storage.mongo.MongoStorageService.java
License:Apache License
public String queryMd5(String storageKey, String tableName) { DB db = options.getCollection(TABLE_TEMP_KEY).getDB(); DBObject query = new BasicDBObject(); query.put("storageKey", new ObjectId(storageKey)); DBCollection fileTable = db.getCollection(tableName + ".files"); DBCursor cursor = fileTable.find(query); if (cursor.hasNext()) { DBObject o = cursor.next(); return o.get("md5").toString(); }//from www. ja va 2 s . c o m return ""; }
From source file:co.edu.udea.runtwebapp.model.entities.Person.java
public static Person entityFromDBObject(DBObject dbObject) { Person person = null;// w w w .j av a 2s. c om if (dbObject != null) { person = new Person(); if (dbObject.containsField(ID)) { person.setId(dbObject.get(ID).toString().trim()); } if (dbObject.containsField(DOCUMENT_TYPE)) { person.setDocumentType((String) dbObject.get(DOCUMENT_TYPE)); } if (dbObject.containsField(ID_NUMBER)) { person.setIdNumber((String) dbObject.get(ID_NUMBER)); } if (dbObject.containsField(NAME)) { person.setName((String) dbObject.get(NAME)); } if (dbObject.containsField(LASTNAME)) { person.setLastName((String) dbObject.get(LASTNAME)); } if (dbObject.containsField(BIRTHDATE)) { person.setBirthDate((Date) dbObject.get(BIRTHDATE)); } if (dbObject.containsField(EMAIL)) { person.setEmail((String) dbObject.get(EMAIL)); } if (dbObject.containsField(LICENSE_NUMBER)) { person.setLicenseNumber((String) dbObject.get(LICENSE_NUMBER)); } if (dbObject.containsField(VEHICLES)) { BasicDBList basicDBbList = (BasicDBList) dbObject.get(VEHICLES); person.setVehicles(new ArrayList<Vehicle>()); for (Object object : basicDBbList) { person.getVehicles().add(Vehicle.entityFromDBObject((BasicDBObject) object)); } } } return person; }
From source file:co.edu.uniandes.cloud.simuladorcredito.persistencia.AdministradorDAO.java
public Administrador leer(Long llave) { DBObject doc = super.leerBD("id", llave); Administrador a = new Administrador(); a.setId((Long) doc.get("id")); a.setApellidos((String) doc.get("apellidos")); a.setEmail((String) doc.get("email")); a.setNombres((String) doc.get("nombres")); a.setPassword((String) doc.get("password")); return a;/* w ww .ja v a 2 s. c o m*/ }