List of usage examples for com.mongodb DBObject get
Object get(String key);
From source file:br.com.ifspsaocarlos.gastock.models.MCombustivel.java
@Override public Combustivel get(int combustivelId) throws Exception { DBObject dados = this.banco.buscaRegistro(new BasicDBObject("cod", combustivelId)); Combustivel result = new Combustivel((int) dados.get("cod"), dados.get("nome").toString(), Double.parseDouble(dados.get("preco").toString())); return result; }
From source file:br.com.ifspsaocarlos.gastock.models.MFrentista.java
@Override public Frentista get(int frentistaId) throws Exception { DBObject dados = this.banco.buscaRegistro(new BasicDBObject("cod", frentistaId)); Frentista result = new Frentista((int) dados.get("cod"), dados.get("nome").toString(), dados.get("senha").toString(), dados.get("tipo").toString(), Double.parseDouble(dados.get("salario").toString())); return result; }
From source file:br.com.ifspsaocarlos.gastock.models.MRelatorio.java
@Override public Relatorio get(int relatorioId) throws Exception { DBObject dados = this.banco.buscaRegistro(new BasicDBObject("cod", relatorioId)); Relatorio result = new Relatorio((int) dados.get("cod"), dados.get("dataAtual").toString(), dados.get("combustivel").toString(), (int) dados.get("bomba"), Double.parseDouble(dados.get("quantidade").toString()), Double.parseDouble(dados.get("precoTotal").toString())); return result; }
From source file:br.com.ifspsaocarlos.gastock.models.MTanque.java
@Override public Tanque get(int tanqueId) throws Exception { DBObject dados = this.banco.buscaRegistro(new BasicDBObject("cod", tanqueId)); Tanque result = new Tanque((int) dados.get("cod"), dados.get("combustivel").toString(), Double.parseDouble(dados.get("quantidade").toString()), Double.parseDouble(dados.get("preco").toString())); return result; }
From source file:br.edu.unifesspa.lcc.indexer.GerarIndice.java
private void DownloadInfo() throws InterruptedException { //Verifica se j existe um banco de demanda criado no Mongo List<String> dbs = mongo.getDatabaseNames(); if (!dbs.contains(assunto.toString())) {//Se o banco no existe, faz o download RestTemplate rt = new RestTemplate(); DB territorios = mongo.getDB("territorios"); DBCollection colTerritorios = territorios.getCollection("territorio"); HttpEntity<String> entity = new HttpEntity<>("parameters", Processar.headers); BasicDBObject insert = new BasicDBObject(); BasicDBObject insertDemanda = new BasicDBObject(); DBCollection colDaDemanda = dbAssunto.getCollection(assunto.toString()); System.out.println("db =" + dbAssunto); DBCollection k_classe = dbAssunto.getCollection("k"); //K_CLASSES ----------------------------------------------------------------------------------------------- try {/*from www. j a v a 2 s. c om*/ ResponseEntity<domain.K_classes[]> kClasse = rt.exchange( "http://xingu.lcc.unifesspa.edu.br:8080/api/k_classess?idassunto=" + assunto, HttpMethod.GET, entity, domain.K_classes[].class); System.out.println("K-classe tamanho: " + kClasse.getBody().length); //System.out.println("Tamanho body:" + kClasse.getBody().length); for (domain.K_classes k : kClasse.getBody()) { insert.append("k_ordem", k.getk_ordem()); insert.append("k_classes_id", k.getId()); insert.append("ck", Integer.parseInt(k.getk_codigo())); insert.append("dk", k.getk_descricao()); k_classe.insert(insert); insert.clear(); } System.out.println("DEVERIA TER INSERIDO O K"); } catch (Exception e) { e.printStackTrace(); insert.clear(); } //FIM K-CLASSES E COMEO INPUT_PRESENTES -------------------------------------------------------------------------------------------------------- BasicDBObject insertCI = new BasicDBObject(); try { System.out.println("Comeando a inserir os Inputs do assunto: " + assunto); ResponseEntity<domain.Input_presenteDTO[]> input = rt.exchange( "http://xingu.lcc.unifesspa.edu.br:8080/api/input_presentes/getInputPresenteByAssantoId/" + assunto, HttpMethod.GET, entity, Input_presenteDTO[].class); System.out.println("Fez o download do assunto: " + assunto); System.out.println("Tamano input: " + input.getBody().length + " Assunto: " + assunto); DBCollection colInput_presente = dbAssunto.getCollection("i"); // inserir assunto na base BasicDBObject search2 = new BasicDBObject(); // int cont = 0; for (Input_presenteDTO Input2 : input.getBody()) { // System.out.println("Entrou"); //Para a coleo "i" search2.append("ci", Integer.parseInt(Input2.getCodigo())); DBObject aux = colInput_presente.findOne(search2); if (aux != null) { search2.clear(); // System.out.println("ja tem esse territorio inserido"); } else { DBCursor cursor = colTerritorios.find(search2); while (cursor.hasNext()) { aux = cursor.next(); // System.out.println("AUX: " + aux.toString()); if (Integer.parseInt(aux.get("ci").toString()) == Integer.parseInt(Input2.getCodigo()) && Integer.parseInt(aux.get("ano").toString()) == Integer .parseInt(Input2.getAno_ref())) { // insertCI.append("uf_sigla", aux.get("uf_sigla")); insertCI.append("longitude", Double.parseDouble(aux.get("longitude").toString())); insertCI.append("latitude", Double.parseDouble(aux.get("latitude").toString())); // System.out.println("Achou Territorio"); } } insertCI.append("ci", Integer.parseInt(Input2.getI_codigo_amc())); insertCI.append("di", Input2.getTerritorio_nome()); insertCI.append("ano_ref", Integer.parseInt(aux.get("ano").toString())); search2.clear(); colInput_presente.insert(insertCI); insertCI.clear(); } //Para a coleo com o mesmo nome da base insertDemanda.append("ci", Integer.parseInt(Input2.getI_codigo_amc())); insertDemanda.append("di", Input2.getTerritorio_nome()); insertDemanda.append("ck", Integer.parseInt(Input2.getK_classesK_codigo())); insertDemanda.append("quant_valor", Double.parseDouble(Input2.getX_valor())); insertDemanda.append("ano", Integer.parseInt(Input2.getAno_ref())); //Aqui se acha a descrio da K-Classe envolvida, atravs do "k_classesK_codigo" search2.append("ck", Integer.parseInt(Input2.getK_classesK_codigo())); aux = k_classe.findOne(search2); insertDemanda.append("dk", (String) aux.get("dk")); search2.clear(); // colDaDemanda.insert(insertDemanda); insertDemanda.clear(); // cont++; // System.out.println(cont); } System.out.println("Inseriu input_presente do assunto: " + assunto); //Preparar banco------------------ System.out.println("Preparando o assunto: " + assunto); datadao.prepareDatabase(false, dbAssunto); System.out.println("Fim preparar banco do assunto: " + assunto); //Fim preparar Banco---------- } catch (Exception e) { e.printStackTrace(); insert.clear(); insertCI.clear(); } } else { BasicDBObject search = new BasicDBObject(); DB aux = mongo.getDB("demandas"); DBCollection colDemandaAtiva = aux.getCollection("demandas_ativas"); search.append("demanda", assunto.toString()); boolean situacao = false; while (situacao == false) { DBCursor demanAtiva = colDemandaAtiva.find(search); if (demanAtiva.size() >= 1) { situacao = true; } Thread.currentThread().sleep(5000); } } }
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public String add(String tableName, String json) { if (tableName == null || tableName.equals("") || json == null || json.equals("")) { return "501"; }/* w ww .ja v a 2s. c o m*/ DBCollection table = db.getCollection(tableName); DBObject dbObject = (DBObject) JSON.parse(json); WriteResult wRes = table.insert(dbObject); return ((ObjectId) dbObject.get("_id")).toString(); }
From source file:br.ufabc.impress.mongo.manager.DBHelper.java
@Override public String addDefault(String tableName, String json) { if (tableName == null || tableName.equals("") || json == null || json.equals("")) { return "501"; }// w ww . j av a 2 s. c o m DBCollection table = db.getCollection(tableName); DBObject dbObject = (DBObject) JSON.parse(json); dbObject.put("status", "active"); dbObject.put("createDate", System.currentTimeMillis() + ""); dbObject.put("updateDate", System.currentTimeMillis() + ""); WriteResult wRes = table.insert(dbObject); return ((ObjectId) dbObject.get("_id")).toString(); }
From source file:BusinessLogic.Service.RestaurantService.java
public Restaurant getBy(String name) { ArrayList restaurantConsult = new ArrayList(); MongoConnection dbSingleton = MongoConnection.getInstance(); DB db = dbSingleton.getTestdb();/* www . j a va 2s. com*/ DBCollection coll = db.getCollection(collName); BasicDBObject whereQuery = new BasicDBObject(); // Sentence to search one account number whereQuery.put("name", name); DBCursor cursor = coll.find(whereQuery); while (cursor.hasNext()) { DBObject consultDocument = cursor.next(); restaurantConsult.add(consultDocument.get("name")); restaurantConsult.add(consultDocument.get("direccion")); restaurantConsult.add(consultDocument.get("phone")); } Restaurant rs = new Restaurant(whereQuery); String response = ""; response = "Name:" + restaurantConsult.get(0) + " ,Address: " + restaurantConsult.get(1) + " ,Phone: " + restaurantConsult.get(2); System.out.println(rs); return rs; }
From source file:buysell.shopping.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: try {//from w w w . j ava2 s . co m MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("buysale"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("assetes"); System.out.println("Collection created successfully"); //String name = jTextField1.getText().toString(); //String email = jTextField2.getText().toString(); //String phoneno = jTextField3.getText().toString(); // String price= jTextField4.getText().toString(); //String photourl = jTextField5.getText().toString(); String check = jCheckBox1.getText().toString(); System.out.println(check); String type = jComboBox1.getSelectedItem().toString(); BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("type", type); DBCursor cursor = coll.find(searchQuery); int i = 0; while (cursor.hasNext() && i != 1) { i++; DBObject obj = cursor.next(); String name = (String) obj.get("name"); String email = (String) obj.get("email"); String phoneno = (String) obj.get("phoneno"); String price = (String) obj.get("price"); String url = (String) obj.get("photourl"); jTextField1.setText(name); jTextField2.setText(email); jTextField3.setText(phoneno); jTextField4.setText(price); jLabel3.setIcon(new javax.swing.ImageIcon(url)); } System.out.println("Document inserted successfully"); } catch (NumberFormatException e) { System.out.println(); } }
From source file:ca.mariusbogoevici.springxd.mongo.source.TupleReadConverter.java
License:Apache License
@Override public Tuple convert(DBObject source) { TupleBuilder tupleBuilder = new TupleBuilder(); for (String key : source.keySet()) { if ("_id".equals(key)) { tupleBuilder.put("id", source.get(key)); } else {// w ww. j a v a 2 s . c om tupleBuilder.put(key, source.get(key)); } } return tupleBuilder.build(); }