List of usage examples for com.mongodb WriteConcern JOURNALED
WriteConcern JOURNALED
To view the source code for com.mongodb WriteConcern JOURNALED.
Click Source Link
From source file:in.mtap.iincube.mongoapi.MongoUpdater.java
License:Apache License
/** Uses {@link WriteConcern#JOURNALED} */ public WriteResult execute() { return execute(WriteConcern.JOURNALED); }
From source file:laboratorio_2_sd.Laboratorio_2_SD.java
public static void main(String[] args) throws Exception { //archivo de configuracion File archivo = new File("config.ini"); FileReader fr = new FileReader(archivo); BufferedReader br = new BufferedReader(fr); String linea = br.readLine(); int cantParticiones = Integer.parseInt(linea); linea = br.readLine();/* w w w. jav a2s. c om*/ String[] data = linea.split("\n"); String rutaDocumentos = data[0]; linea = br.readLine(); data = linea.split("\n"); String rutaStopwords = data[0]; if (imprime) System.out.println("Se configura con:\n- Particiones: " + cantParticiones + "\n- Ruta Documentos: '" + rutaDocumentos + "'\n- Ruta StopWords: '" + rutaStopwords + "'\n"); //Archivo stopwords File archivo3 = new File(rutaStopwords); FileReader fr3 = new FileReader(archivo3); BufferedReader br3 = new BufferedReader(fr3); ArrayList<String> stopwords = new ArrayList<>(); if (imprime) { System.out.println("StopWords: \n"); int contador = 0; while ((linea = br3.readLine()) != null && linea.length() != 0) {//mientras no sea EOF stopwords.add(linea); if (contador < 9) { System.out.print(linea + " "); contador++; } else if (contador == 9) { contador = 0; System.out.println(linea); } } System.out.println(""); } //Crea db y tablas MongoClient mongoClient = new MongoClient("localhost", 27017); mongoClient.dropDatabase("indexDB"); DB db = mongoClient.getDB("indexDB"); mongoClient.setWriteConcern(WriteConcern.JOURNALED); db.setWriteConcern(WriteConcern.JOURNALED); DBCollection colDocumentos = db.getCollection("Documentos"); DBCollection colIndiceInvertido = db.getCollection("IndiceInvertido"); DBCollection colVocabulario = db.getCollection("Vocabulario"); colDocumentos.createIndex(new BasicDBObject("idDoc", 1)); colIndiceInvertido.createIndex(new BasicDBObject("idPalabra", 1)); colVocabulario.createIndex(new BasicDBObject("palabra", 1)); //Archivo de documentos File archivo2 = new File(rutaDocumentos); FileReader fr2 = new FileReader(archivo2); BufferedReader br2 = new BufferedReader(fr2); int idDoc = 0; int idPalabraActual = 0; while ((linea = br2.readLine()) != null && !linea.contains("</mediawiki>")) {//mientras no sea EOF while (!linea.contains("<page>")) { linea = br2.readLine(); } //guarda el titulo linea = br2.readLine(); int indice = linea.indexOf(">"); String sub = linea.substring(indice + 1); indice = sub.indexOf("<"); String titulo = sub.substring(0, indice); //guarda el username while (!linea.contains("<username>")) { linea = br2.readLine(); } indice = linea.indexOf(">"); sub = linea.substring(indice + 1); indice = sub.indexOf("<"); String username = sub.substring(0, indice); while (linea.contains("<text") == false) { linea = br2.readLine(); } //Aqui comienza a leer el contenido del documento ArrayList<String> palabrasTemp = new ArrayList<String>(); while (linea.contains("</text>") == false) { linea = br2.readLine(); if (!linea.contains("</text>")) { StringTokenizer st = new StringTokenizer(linea, " #%_-*.,;:|/\\(){}[]=&+'\"?!"); while (st.hasMoreTokens()) { String palabra = st.nextToken(); palabra = palabra.toLowerCase(); if (palabra.length() > 1 && !stopwords.contains(palabra)) { palabrasTemp.add(palabra); } } } } Documento docTemp = new Documento(idDoc, palabrasTemp, titulo, username); if (imprime) docTemp.print(); //Se agrega el documento directamente a la coleccion documentos colDocumentos.insert(docTemp.toDBObject()); for (int i = 0; i < docTemp.cantPalabras; i++) { String palabra = docTemp.palabras.get(i); if (imprime) System.out.println("***********************"); if (imprime) System.out.println("Palabra: " + palabra); //revisa si la palabra esta en la coleccion vocabulario DBCursor cursor = colVocabulario.find((DBObject) new BasicDBObject("palabra", palabra)); if (cursor.hasNext()) { //si esta if (imprime) System.out.println("Esta en vocabulario"); Vocabulario vocTemp = new Vocabulario((BasicDBObject) cursor.next()); if (imprime) System.out.println("idPalabra: " + vocTemp.idPalabra); DBCursor cursor2 = colIndiceInvertido .find((DBObject) new BasicDBObject("idPalabra", vocTemp.idPalabra)); BasicDBObject find = (BasicDBObject) cursor2.next(); IndiceInvertido indiceTemp = new IndiceInvertido(find); //revisa si ya est ingresado el documento actual en el indiceInvertido int contador = 0; int frec = 0; for (int j = 0; j < indiceTemp.frecuencias.size(); j++) { if (indiceTemp.frecuencias.get(j).idDocumento == idDoc) { contador = 1; frec = indiceTemp.frecuencias.get(j).frecuencia; break; } } if (contador == 1) { //si encontro el id del documento actual if (imprime) System.out.println("Esta en indice invertido"); //actualizar frecuencia en indice Invertido indiceTemp.ActualizarFrecuencias(frec + 1, idDoc); colIndiceInvertido.update(find, indiceTemp.toDBObject(), false, true); if (imprime) indiceTemp.print(); } else {//si no est if (imprime) System.out.println("No est en indice invertido"); //actualizar la cantidad de documentos del vocabulario vocTemp.cantDocumentos++; colVocabulario.insert(vocTemp.toDBObject()); if (imprime) vocTemp.print(); //agregar nueva tupla de frecuencia/idDoc a indice indiceTemp.ActualizarFrecuencias(1, idDoc); if (imprime) indiceTemp.print(); colIndiceInvertido.insert(indiceTemp.toDBObject()); } } else {//no esta if (imprime) System.out.println("No esta en vocabulario\nInserta nuevo elemento"); if (idDoc == 0 && i == 0) { //no se ha insertado ningun dato //inserta palabra en vocabulario Vocabulario vocTemp = new Vocabulario(palabra, 0, 1); colVocabulario.insert(vocTemp.toDBObject()); if (imprime) vocTemp.print(); //inserta entrada en indice invertido IndiceInvertido indiceTemp = new IndiceInvertido(vocTemp.idPalabra, 1, idDoc); colIndiceInvertido.insert(indiceTemp.toDBObject()); if (imprime) indiceTemp.print(); idPalabraActual++; } else { //se obtiene un nuevo id //se inserta a vocabulario Vocabulario vocTemp = new Vocabulario(palabra, idPalabraActual, 1); colVocabulario.insert(vocTemp.toDBObject()); if (imprime) vocTemp.print(); //se inserta a indice invertido IndiceInvertido indiceTemp = new IndiceInvertido(vocTemp.idPalabra, 1, idDoc); if (imprime) indiceTemp.print(); colIndiceInvertido.insert(indiceTemp.toDBObject()); idPalabraActual++; } } } idDoc++; while (!linea.contains("</page>")) { linea = br2.readLine(); } pasarGarbageCollector(); } }
From source file:net.acesinc.nifi.processors.mongodb.PartialUpdateMongo.java
protected WriteConcern getWriteConcern(final ProcessContext context) { final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue(); WriteConcern writeConcern = null;/*from w w w .j ava2s . c o m*/ switch (writeConcernProperty) { case WRITE_CONCERN_ACKNOWLEDGED: writeConcern = WriteConcern.ACKNOWLEDGED; break; case WRITE_CONCERN_UNACKNOWLEDGED: writeConcern = WriteConcern.UNACKNOWLEDGED; break; case WRITE_CONCERN_FSYNCED: writeConcern = WriteConcern.FSYNCED; break; case WRITE_CONCERN_JOURNALED: writeConcern = WriteConcern.JOURNALED; break; case WRITE_CONCERN_REPLICA_ACKNOWLEDGED: writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED; break; case WRITE_CONCERN_MAJORITY: writeConcern = WriteConcern.MAJORITY; break; default: writeConcern = WriteConcern.ACKNOWLEDGED; } return writeConcern; }
From source file:org.apache.drill.exec.store.mongo.config.MongoPersistentStoreProvider.java
License:Apache License
@Override public void start() throws IOException { MongoClientURI clientURI = new MongoClientURI(mongoURL); client = new MongoClient(clientURI); MongoDatabase db = client.getDatabase(clientURI.getDatabase()); collection = db.getCollection(clientURI.getCollection()).withWriteConcern(WriteConcern.JOURNALED); Bson index = Indexes.ascending(pKey); collection.createIndex(index);/* w ww. j ava 2s. co m*/ }
From source file:org.apache.drill.exec.store.mongo.config.MongoPStoreProvider.java
License:Apache License
@Override public void start() throws IOException { MongoClientURI clientURI = new MongoClientURI(mongoURL); client = new MongoClient(clientURI); DB db = client.getDB(clientURI.getDatabase()); collection = db.getCollection(clientURI.getCollection()); collection.setWriteConcern(WriteConcern.JOURNALED); DBObject index = new BasicDBObject(1).append(pKey, Integer.valueOf(1)); collection.createIndex(index);/*ww w.j a v a2s. c o m*/ }
From source file:org.apache.nifi.mongodb.AbstractMongoDBControllerService.java
License:Apache License
protected WriteConcern getWriteConcern(final ConfigurationContext context) { final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue(); WriteConcern writeConcern = null;//from w w w . ja v a2 s. c om switch (writeConcernProperty) { case WRITE_CONCERN_ACKNOWLEDGED: writeConcern = WriteConcern.ACKNOWLEDGED; break; case WRITE_CONCERN_UNACKNOWLEDGED: writeConcern = WriteConcern.UNACKNOWLEDGED; break; case WRITE_CONCERN_FSYNCED: writeConcern = WriteConcern.FSYNCED; break; case WRITE_CONCERN_JOURNALED: writeConcern = WriteConcern.JOURNALED; break; case WRITE_CONCERN_REPLICA_ACKNOWLEDGED: writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED; break; case WRITE_CONCERN_MAJORITY: writeConcern = WriteConcern.MAJORITY; break; default: writeConcern = WriteConcern.ACKNOWLEDGED; } return writeConcern; }
From source file:org.eclipse.linuxtools.tmf.totalads.dbms.DBMS.java
License:Open Source License
/** * Connects with MongoDB/* w w w .ja v a2 s .c o m*/ * @param host Host name * @param port Port number * @return Returns an empty message if connection is made with the database, else returns the error message * @throws UnknownHostException */ public String connect(String host, Integer port) { String message = ""; try { if (isConnected) // Don't open multiple connections closeConnection(); mongoClient = new MongoClient(host, port); mongoClient.setWriteConcern(WriteConcern.JOURNALED); mongoClient.getDatabaseNames(); // if this doesn't work then there is no running DB. // Unfortunately,mongoClient doesn't tell whether there is a DB or not } catch (UnknownHostException ex) { isConnected = false; message = ex.getMessage(); notifyObservers(); return message; } catch (Exception ex) { // Just capture an exception and don't let the system crash when db is not there isConnected = false; message = "Unable to connect to MongoDB."; notifyObservers(); return message; } isConnected = true;// if it reaches here then it is connected notifyObservers(); return message; }
From source file:org.eclipse.linuxtools.tmf.totalads.dbms.DBMS.java
License:Open Source License
/** * Connects with MongoDB using authentication mecahinsm * @param host Host name//from w w w .j a v a 2s. c o m * @param port Port name * @param username User name * @param password Password * @return Empty message if connected or error message * @throws UnknownHostException */ public String connect(String host, Integer port, String username, String password, String database) { String message = ""; try { if (isConnected) // Don't open multiple connections closeConnection(); mongoClient = new MongoClient(host, port); mongoClient.setWriteConcern(WriteConcern.JOURNALED); mongoClient.getDatabaseNames(); // if this doesn't work then there is no running DB. // Unfortunately,mongoClient doesn't tell whether there is a DB or not } catch (UnknownHostException ex) { isConnected = false; message = ex.getMessage(); //notifyObservers(); //return message; } catch (Exception ex) { // Just capture an exception and don't let the system crash when db is not there isConnected = false; message = "Unable to connect to MongoDB."; //notifyObservers(); //return message; } finally { if (message.isEmpty()) { // if there is a running db then check this DB db = mongoClient.getDB(database); if (db.authenticate(username, password.toCharArray()) == false) { isConnected = false; message = "Authentication failed with MongoDB using user id " + username + " and database " + database + "."; } else { isConnected = true;// if it reaches here then everything is fine } } notifyObservers(); } return message; }
From source file:org.eclipse.tracecompass.totalads.dbms.MongoDBMS.java
License:Open Source License
@Override public String connect(String host, Integer port) { String message = ""; //$NON-NLS-1$ synchronized (this) { try {//w w w .ja v a 2 s . c om mongoClient = new MongoClient(host, port); mongoClient.setWriteConcern(WriteConcern.JOURNALED); mongoClient.getDatabaseNames(); // if this doesn't work then // there is no running DB. // Unfortunately,mongoClient // doesn't tell whether there is // a DB or not } catch (UnknownHostException ex) { isConnected = false; message = ex.getMessage(); notifyObservers(); return message; } catch (Exception ex) { // Just capture an exception and don't let // the system crash when db is not there isConnected = false; message = Messages.MongoDBMS_NoConn; notifyObservers(); return message; } isConnected = true;// if it reaches here then it is connected notifyObservers(); } return message; }
From source file:org.eclipse.tracecompass.totalads.dbms.MongoDBMS.java
License:Open Source License
@Override public String connect(String host, Integer port, String username, String password, String database) { String message = ""; //$NON-NLS-1$ synchronized (this) { try {//w w w. ja v a 2s . c o m mongoClient = new MongoClient(host, port); mongoClient.setWriteConcern(WriteConcern.JOURNALED); DB db = mongoClient.getDB(database); if (db.authenticate(username, password.toCharArray()) == false) { isConnected = false; message = NLS.bind(Messages.MongoDBMS_AuthFailed, username, database); } else { isConnected = true;// if it reaches here then everything is // fine } } catch (UnknownHostException ex) { isConnected = false; message = ex.getMessage(); } catch (Exception ex) { // Just capture an exception and don't let // the system crash when db is not there isConnected = false; message = "Unable to connect to MongoDB"; //$NON-NLS-1$ } finally { notifyObservers(); } } return message; }