List of usage examples for com.mongodb WriteConcern ACKNOWLEDGED
WriteConcern ACKNOWLEDGED
To view the source code for com.mongodb WriteConcern ACKNOWLEDGED.
Click Source Link
From source file:org.hbird.business.archive.dao.mongo.SubclassAwareMongoTemplate.java
License:Apache License
public SubclassAwareMongoTemplate(MongoDbFactory dbFactory, MongoConverter mongoConverter) { super(dbFactory, mongoConverter); setWriteConcern(WriteConcern.ACKNOWLEDGED); hierarchy = super.getCollection(HIERARCHY_COLLECTION_NAME); metadata = super.getCollection(METADATA_COLLECTION_NAME); knownClasses = new HashSet<String>(); subclassRelation = new HashMap<String, Set<String>>(); classloaderCache = new HashMap<String, Class<?>>(); LOG.info("Initializing"); if (metadata.count() == 0) { LOG.info("Metadata collection is empty, creating version marker"); writeVersionToDB();/* w w w. j a va 2 s .c om*/ } else { LOG.info("Version marker found"); updateCacheFromDB(); LOG.info("Hierarchy version: " + version); } }
From source file:org.hibernate.ogm.perftest.mongodb.nativeapi.NativeApiBenchmarkBase.java
License:LGPL
protected static MongoClient getMongoClient() throws UnknownHostException { ServerAddress serverAddress = new ServerAddress(properties.getProperty("host"), 27017); MongoClientOptions.Builder optionsBuilder = new MongoClientOptions.Builder(); optionsBuilder.connectTimeout(1000); optionsBuilder.writeConcern(WriteConcern.ACKNOWLEDGED); optionsBuilder.readPreference(ReadPreference.primary()); MongoClientOptions clientOptions = optionsBuilder.build(); MongoClient mongo = new MongoClient(serverAddress, clientOptions); return mongo; }
From source file:org.jooby.mongodb.MongoRx.java
License:Apache License
static MongoClientSettings.Builder settings(final ConnectionString cstr, final Config conf) { MongoClientSettings.Builder settings = MongoClientSettings.builder(); settings.clusterSettings(cluster(cstr, conf)); settings.connectionPoolSettings(pool(cstr, conf)); settings.heartbeatSocketSettings(socket("heartbeat", cstr, conf)); withStr("readConcern", conf, v -> settings.readConcern(Match(v.toUpperCase()) .option(Case("DEFAULT", ReadConcern.DEFAULT), Case("LOCAL", ReadConcern.LOCAL), Case("MAJORITY", ReadConcern.MAJORITY)) .getOrElseThrow(() -> new IllegalArgumentException("readConcern=" + v)))); withStr("readPreference", conf, v -> settings.readPreference(ReadPreference.valueOf(v))); settings.serverSettings(server(conf)); settings.socketSettings(socket("socket", cstr, conf)); settings.sslSettings(ssl(cstr, conf)); withStr("writeConcern", conf, v -> settings.writeConcern(Match(v.toUpperCase()) .option(Case("W1", WriteConcern.W1), Case("W2", WriteConcern.W2), Case("W3", WriteConcern.W3), Case("ACKNOWLEDGED", WriteConcern.ACKNOWLEDGED), Case("JOURNALED", WriteConcern.JOURNALED), Case("MAJORITY", WriteConcern.MAJORITY)) .getOrElseThrow(() -> new IllegalArgumentException("writeConcern=" + v)))); return settings; }
From source file:org.jumpmind.symmetric.io.MongoDatabaseWriter.java
License:Open Source License
protected LoadStatus upsert(CsvData data) { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); try {/*from w ww . jav a 2 s.co m*/ DB db = clientManager.getDB(objectMapper.mapToDatabase(this.targetTable)); DBCollection collection = db.getCollection(objectMapper.mapToCollection(this.targetTable)); String[] columnNames = sourceTable.getColumnNames(); Map<String, String> newData = data.toColumnNameValuePairs(columnNames, CsvData.ROW_DATA); Map<String, String> oldData = data.toColumnNameValuePairs(columnNames, CsvData.OLD_DATA); Map<String, String> pkData = data.toKeyColumnValuePairs(this.sourceTable); DBObject query = objectMapper.mapToDBObject(sourceTable, newData, oldData, pkData, true); DBObject object = objectMapper.mapToDBObject(sourceTable, newData, oldData, pkData, false); WriteResult results = collection.update(query, object, true, false, WriteConcern.ACKNOWLEDGED); if (results.getN() == 1) { return LoadStatus.SUCCESS; } else { throw new SymmetricException("Failed to write data: " + object.toString()); } } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS); } }
From source file:org.jumpmind.symmetric.io.MongoDatabaseWriter.java
License:Open Source License
@Override protected LoadStatus delete(CsvData data, boolean useConflictDetection) { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); try {//from w w w . j a v a 2 s.c o m DB db = clientManager.getDB(objectMapper.mapToDatabase(this.targetTable)); DBCollection collection = db.getCollection(objectMapper.mapToCollection(this.targetTable)); String[] columnNames = sourceTable.getColumnNames(); Map<String, String> newData = data.toColumnNameValuePairs(columnNames, CsvData.ROW_DATA); Map<String, String> oldData = data.toColumnNameValuePairs(columnNames, CsvData.OLD_DATA); Map<String, String> pkData = data.toKeyColumnValuePairs(this.sourceTable); DBObject query = objectMapper.mapToDBObject(sourceTable, newData, oldData, pkData, true); WriteResult results = collection.remove(query, WriteConcern.ACKNOWLEDGED); if (results.getN() != 1) { log.warn("Attempted to remove a single object" + query.toString() + ". Instead removed: " + results.getN()); } return LoadStatus.SUCCESS; } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS); } }
From source file:org.jumpmind.symmetric.io.SimpleMongoClientManager.java
License:Open Source License
@Override public DB getDB(String name) { if (currentDB == null || !currentDB.getName().equals(name)) { currentDB = get().getDB(name);/*from w w w . j a v a 2 s . c o m*/ /** * TODO make this a property */ currentDB.setWriteConcern(WriteConcern.ACKNOWLEDGED); String username = null; char[] password = null; if (parameterService != null) { username = parameterService.getString(name + MongoConstants.USERNAME, username); String passwordString = parameterService.getString(name + MongoConstants.PASSWORD, null); if (passwordString != null) { password = passwordString.toCharArray(); } } if (username != null && !currentDB.authenticate(username, password)) { throw new SymmetricException("Failed to authenticate with the mongo database: " + name); } } return currentDB; }
From source file:org.kaaproject.kaa.server.common.nosql.mongo.dao.MongoDataLoader.java
License:Apache License
public static void loadData() throws IOException { InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(DATA_FILE); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); String jsonLine = ""; while ((jsonLine = reader.readLine()) != null) { if (StringUtils.isNotBlank(jsonLine)) { String currentLine = jsonLine.trim(); if (jsonLine.startsWith(COLLECTION_NAME_LINE)) { setCollectionFromName(currentLine); } else { currentCollection.insert((DBObject) JSON.parse(jsonLine), WriteConcern.ACKNOWLEDGED); }/* w ww .j a v a2 s . c om*/ } } input.close(); LOG.info("Load data finished."); }
From source file:org.lucee.mongodb.support.ObjectSupport.java
License:Open Source License
public WriteConcern toWriteConcern(Object obj, WriteConcern defaultValue) { if (obj instanceof WriteConcern) return (WriteConcern) obj; if (decision.isSimpleValue(obj)) { String str = caster.toString(obj, ""); str = str.trim().toUpperCase();/*from w w w. ja va2 s . c o m*/ if ("ACKNOWLEDGED".equals(str)) return WriteConcern.ACKNOWLEDGED; else if ("ACKNOWLEDGED".equals(str)) return WriteConcern.FSYNC_SAFE; else if ("FSYNC_SAFE".equals(str) || "FSYNCSAFE".equals(str)) return WriteConcern.FSYNCED; else if ("JOURNAL_SAFE".equals(str) || "JOURNALSAFE".equals(str)) return WriteConcern.JOURNAL_SAFE; else if ("JOURNALED".equals(str)) return WriteConcern.JOURNALED; else if ("MAJORITY".equals(str)) return WriteConcern.MAJORITY; else if ("NORMAL".equals(str)) return WriteConcern.NORMAL; else if ("REPLICA_ACKNOWLEDGED".equals(str) || "REPLICAACKNOWLEDGED".equals(str)) return WriteConcern.REPLICA_ACKNOWLEDGED; else if ("REPLICAS_SAFE".equals(str) || "REPLICASSAFE".equals(str)) return WriteConcern.REPLICAS_SAFE; else if ("SAFE".equals(str)) return WriteConcern.SAFE; else if ("UNACKNOWLEDGED".equals(str)) return WriteConcern.UNACKNOWLEDGED; } return defaultValue; }
From source file:org.obiba.magma.datasource.mongodb.MongoDBDatasource.java
License:Open Source License
DBObject asDBObject() { if (dbObject == null) { dbObject = getDatasourceCollection().findOne(BasicDBObjectBuilder.start() // .add("name", getName()) // .get());/*from w ww . j a v a 2 s. c o m*/ if (dbObject == null) { dbObject = BasicDBObjectBuilder.start() // .add("name", getName()) // .add(TIMESTAMPS_FIELD, createTimestampsObject()).get(); getDatasourceCollection().insert(dbObject, WriteConcern.ACKNOWLEDGED); } } return dbObject; }
From source file:org.obiba.magma.datasource.mongodb.MongoDBDatasource.java
License:Open Source License
@Override public void renameTable(String tableName, String newName) { if (hasValueTable(newName)) throw new MagmaRuntimeException("A table already exists with the name: " + newName); MongoDBValueTable valueTable = (MongoDBValueTable) getValueTable(tableName); valueTable.asDBObject().put("name", newName); ((BSONObject) valueTable.asDBObject().get(TIMESTAMPS_FIELD)).put("updated", new Date()); getValueTableCollection().save(valueTable.asDBObject(), WriteConcern.ACKNOWLEDGED); removeValueTable(valueTable);/*from ww w. jav a 2 s .c o m*/ MongoDBValueTable newTable = new MongoDBValueTable(this, newName); Initialisables.initialise(newTable); addValueTable(newTable); }