List of usage examples for com.mongodb Mongo Mongo
Mongo(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation)
From source file:Frames.AddUser.java
/** * Creates new form AddUser//from w w w .j a v a2s.co m */ public AddUser() { try { Mongo mongo = new Mongo("localhost", 27017); BasedeDatos = mongo.getDB("ska"); coleccion = BasedeDatos.getCollection("Usuario"); System.out.println("coneccion de base de datos exitosa"); } catch (Exception e) { } initComponents(); setLocationRelativeTo(null); }
From source file:Frames.Login.java
/** * Creates new form Login/*from w w w .jav a 2 s . c om*/ */ public Login() { try { Mongo mongo = new Mongo("localhost", 27017); BasedeDatos = mongo.getDB("ska"); coleccion = BasedeDatos.getCollection("skatabla"); System.out.println("coneccion de base de datos exitosa"); } catch (Exception e) { } initComponents(); setLocationRelativeTo(null); }
From source file:framework.classes.Mongo_BD.java
/** * OPEN CONNECTION//from w w w .j ava 2 s . co m * @return */ public static Mongo connect() { try { client = new Mongo(getMachine(), Integer.parseInt(getPort())); db = client.getDB(getNom_bd()); collection = db.getCollection(getNom_table()); } catch (Exception e) { System.out.println("Unable to open client"); e.printStackTrace(); if (client != null) { try { client.close(); } catch (Exception ex) { System.out.println("Unable to close client"); ex.printStackTrace(); } } } return client; }
From source file:framework.clss.MongoDB.java
/**connect * Open a client with mongo data base/* w w w.jav a2 s . c o m*/ * * @return Mongo */ public static Mongo connect() { try { client = new Mongo(getMachine(), Integer.parseInt(getPort())); singletonGen.db = client.getDB(getNom_bd()); singletonGen.collection = singletonGen.db.getCollection(getNom_table()); } catch (Exception e) { System.out.println("Unable to open client"); e.printStackTrace(); if (client != null) { try { client.close(); } catch (Exception ex) { System.out.println("Unable to close client"); ex.printStackTrace(); } } } return client; }
From source file:getquantityvolume.ReadPropertiesForMongo.java
public DBCollection getCollection() { DBCollection datosvisu = null;//w w w. ja v a 2s . c o m try { mongo = new Mongo(host, port); System.out.println("conectado a " + mongo.getAddress()); DB db = mongo.getDB("DBVisualizador"); datosvisu = db.getCollection("DatosVisu"); } catch (UnknownHostException ex) { Logger.getLogger(ReadPropertiesForMongo.class.getName()).log(Level.SEVERE, null, ex); } return datosvisu; }
From source file:guardar.en.base.de.datos.MainServidor.java
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException { Mongo mongo = new Mongo("localhost", 27017); // nombre de la base de datos DB database = mongo.getDB("paginas"); // coleccion de la db DBCollection collection = database.getCollection("indice"); DBCollection collection_textos = database.getCollection("tabla"); ArrayList<String> lista_textos = new ArrayList(); try {//from w w w. j a va2s . co m ServerSocket servidor = new ServerSocket(4545); // Crear un servidor en pausa hasta que un cliente llegue. while (true) { String aux = new String(); lista_textos.clear(); Socket clienteNuevo = servidor.accept();// Si llega se acepta. // Queda en pausa otra vez hasta que un objeto llegue. ObjectInputStream entrada = new ObjectInputStream(clienteNuevo.getInputStream()); JSONObject request = (JSONObject) entrada.readObject(); String b = (String) request.get("id"); //hacer una query a la base de datos con la palabra que se quiere obtener BasicDBObject query = new BasicDBObject("palabra", b); DBCursor cursor = collection.find(query); ArrayList<DocumentosDB> lista_doc = new ArrayList<>(); // de la query tomo el campo documentos y los agrego a una lista try { while (cursor.hasNext()) { //System.out.println(cursor.next()); BasicDBList campo_documentos = (BasicDBList) cursor.next().get("documentos"); // en el for voy tomando uno por uno los elementos en el campo documentos for (Iterator<Object> it = campo_documentos.iterator(); it.hasNext();) { BasicDBObject dbo = (BasicDBObject) it.next(); //DOC tiene id y frecuencia DocumentosDB doc = new DocumentosDB(); doc.makefn2(dbo); //int id = (int)doc.getId_documento(); //int f = (int)doc.getFrecuencia(); lista_doc.add(doc); //******************************************* //******************************************** //QUERY A LA COLECCION DE TEXTOS /* BasicDBObject query_textos = new BasicDBObject("id", doc.getId_documento());//query DBCursor cursor_textos = collection_textos.find(query_textos); try { while (cursor_textos.hasNext()) { DBObject obj = cursor_textos.next(); String titulo = (String) obj.get("titulo"); titulo = titulo + "\n\n"; String texto = (String) obj.get("texto"); String texto_final = titulo + texto; aux = texto_final; lista_textos.add(texto_final); } } finally { cursor_textos.close(); }*/ //System.out.println(doc.getId_documento()); //System.out.println(doc.getFrecuencia()); } // end for } //end while query } finally { cursor.close(); } // ordeno la lista de menor a mayor Collections.sort(lista_doc, new Comparator<DocumentosDB>() { @Override public int compare(DocumentosDB o1, DocumentosDB o2) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. return o1.getFrecuencia().compareTo(o2.getFrecuencia()); } }); int tam = lista_doc.size() - 1; for (int j = tam; j >= 0; j--) { BasicDBObject query_textos = new BasicDBObject("id", (int) lista_doc.get(j).getId_documento().intValue());//query DBCursor cursor_textos = collection_textos.find(query_textos);// lo busco try { while (cursor_textos.hasNext()) { DBObject obj = cursor_textos.next(); String titulo = "*******************************"; titulo += (String) obj.get("titulo"); int f = (int) lista_doc.get(j).getFrecuencia().intValue(); String strinf = Integer.toString(f); titulo += "******************************* frecuencia:" + strinf; titulo = titulo + "\n\n"; String texto = (String) obj.get("texto"); String texto_final = titulo + texto + "\n\n"; aux = aux + texto_final; //lista_textos.add(texto_final); } } finally { cursor_textos.close(); } } //actualizar el cache try { Socket cliente_cache = new Socket("localhost", 4500); // nos conectamos con el servidor ObjectOutputStream mensaje_cache = new ObjectOutputStream(cliente_cache.getOutputStream()); // get al output del servidor, que es cliente : socket del cliente q se conecto al server JSONObject actualizacion_cache = new JSONObject(); actualizacion_cache.put("actualizacion", 1); actualizacion_cache.put("busqueda", b); actualizacion_cache.put("respuesta", aux); mensaje_cache.writeObject(actualizacion_cache); // envio el msj al servidor } catch (Exception ex) { } //RESPONDER DESDE EL SERVIDORIndex al FRONT ObjectOutputStream resp = new ObjectOutputStream(clienteNuevo.getOutputStream());// obtengo el output del cliente para mandarle un msj resp.writeObject(aux); System.out.println("msj enviado desde el servidor"); } } catch (IOException ex) { Logger.getLogger(MainServidor.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:guardar.en.base.de.datos.SaxManejadordb.java
public SaxManejadordb() throws UnknownHostException { mongo = new Mongo("localhost", 27017); // nombre de la base de datos database = mongo.getDB("paginas"); // coleccion de la db collection = database.getCollection("tabla"); }
From source file:guardar.en.base.de.datos.SaxManejadorIndice.java
public SaxManejadorIndice() throws UnknownHostException, IOException { mongo = new Mongo("localhost", 27017); // nombre de la base de datos database = mongo.getDB("paginas"); // coleccion de la db collection = database.getCollection("indice"); ArrayList lee = new ArrayList<>(); lee = lista();//ww w . j a v a 2 s .c o m listaStopWords = StopWordsArray((String) lee.get(1)); //collection.createIndex(new Document("palabra", 1)); }
From source file:HAL.libraries.blackboard_client.data_classes.MongoDBConnection.java
License:Open Source License
/** * Creates a new Mongo client for the specified address. * @param address The ServerAddress where the host resides. * @throws GeneralMongoException Connecting to the database server failed. **//* w ww. j av a 2 s .c o m*/ private MongoDBConnection(ServerAddress address) throws GeneralMongoException { try { //Logger.log(LogLevel.NOTIFICATION, "Starting a new mongoclient."); MongoOptions mongoOptions = new MongoOptions(); mongoOptions.connectionsPerHost = Configuration.getPropertyInt(ConfigurationFiles.MONGO_DB_PROPERTIES, "connectionsPerHost"); mongoOptions.threadsAllowedToBlockForConnectionMultiplier = Configuration.getPropertyInt( ConfigurationFiles.MONGO_DB_PROPERTIES, "threadsAllowedToBlockForConnectionMultiplier"); mongoClient = new Mongo(address, mongoOptions); mongoClient.setWriteConcern(WriteConcern.SAFE); } catch (MongoException mongoException) { throw new GeneralMongoException("A mongo exception occurred while connecting.", mongoException); } this.address = address; }
From source file:in.tum.de.ase.db.EnvironmentInitializer.java
License:Apache License
/** * Initializes the Application Environment with the provided * {@link Configuration}//from w ww . ja va 2 s . c o m * * @param configuration * the actual provided configuration to be used for * initialization */ @SuppressWarnings("deprecation") public void setUp(final Configuration configuration) { Preconditions.checkNotNull(configuration); // Local Database Initialization { this.mongo = new Mongo(configuration.getServer(), configuration.getPort()); this.db = this.mongo.getDB(configuration.getDb()); // Registering JDK8 Module for parsing JDK8 classes final Builder tmpMapper = new JacksonMapper.Builder(); for (final Module module : ObjectMapper.findModules()) { tmpMapper.registerModule(module); } tmpMapper.enable(MapperFeature.AUTO_DETECT_GETTERS); tmpMapper.registerModule(new JSR310Module()).registerModule(new Jdk8Module()); this.jongo = new Jongo(this.db, tmpMapper.build()); this.collection = this.jongo.getCollection(configuration.getCollection()); } // initialize the Parse Component Parse.initialize(configuration.getApplicationId(), configuration.getApplicationRestApiId()); }