@VisibleForTesting static DBCollection prepareCollection(final MongoConnection mongoConnection) { DBCollection coll = mongoConnection.getDatabase().getCollection(COLLECTION_NAME); coll.createIndex(DBSort.asc("type"), "unique_type", true); coll.setWriteConcern(WriteConcern.JOURNALED); return coll; }
@VisibleForTesting static DBCollection prepareCollection(final MongoConnection mongoConnection) { final DB db = mongoConnection.getDatabase(); DBCollection coll = db.getCollection(COLLECTION_NAME); coll.createIndex(DBSort .asc("timestamp") .asc("producer") .asc("consumers")); coll.setWriteConcern(WriteConcern.JOURNALED); return coll; }
/** * Set the write concern for this collection. Will be used for * writes to this collection. Overrides any setting of write * concern at the DB level. See the documentation for * {@link WriteConcern} for more information. * * @param concern write concern to use */ public void setWriteConcern(WriteConcern concern) { dbCollection.setWriteConcern(concern); }
/** * Set the write concern for this collection. Will be used for * writes to this collection. Overrides any setting of write * concern at the DB level. See the documentation for * {@link WriteConcern} for more information. * * @param concern write concern to use */ public void setWriteConcern(WriteConcern concern) { dbCollection.setWriteConcern(concern); }
/** * Set the write concern for this collection. Will be used for writes to * this collection. Overrides any setting of write concern at the DB level. * See the documentation for {@link WriteConcern} for more information. * * @param concern * write concern to use */ public void setWriteConcern(WriteConcern concern) { dbCollection.setWriteConcern(concern); }
_fs = new GridFS(_db, "MyBucketName"); DBCollection col = _db.getCollection( "MyBucketName" + ".files" ); col.setWriteConcern(WriteConcern.SAFE);
/** * The default write concern is ACKNOWLEDGED, you can change it. * @param writeConcern */ protected void setWriteConcern(WriteConcern writeConcern){ getCollection().setWriteConcern(writeConcern); }
public MongoSequence(Mongo mongo, String dbName, String collName, String key) { super(); this.coll = mongo.getDB(dbName).getCollection(collName); this.key = key; this.coll.setWriteConcern(WriteConcern.SAFE); }
public static void prepareSystemDB(Mongo mongo) { DBCollection repoCollection = mongo.getDB(CMSConsts.SYS_DB).getCollection(CMSConsts.REPOSITORY_COLL); MongoUtils.ensureIndex(repoCollection, Repository.REPOSITORY_FIELD_NAME, true, false); repoCollection.setWriteConcern(WriteConcern.SAFE); }
@VisibleForTesting static DBCollection prepareCollection(final MongoConnection mongoConnection) { DBCollection coll = mongoConnection.getDatabase().getCollection(COLLECTION_NAME); coll.createIndex(DBSort.asc("type"), "unique_type", true); coll.setWriteConcern(WriteConcern.JOURNALED); return coll; }
@Override public EventStoreProvider create(KeycloakSession session) { MongoConnectionProvider connection = session.getProvider(MongoConnectionProvider.class); DBCollection collection = connection.getDB().getCollection("events"); DBCollection adminCollection = connection.getDB().getCollection("adminEvents"); collection.setWriteConcern(WriteConcern.UNACKNOWLEDGED); adminCollection.setWriteConcern(WriteConcern.UNACKNOWLEDGED); return new MongoEventStoreProvider(collection, adminCollection); }
@Override public AuditProvider create(KeycloakSession session) { MongoConnectionProvider connection = session.getProvider(MongoConnectionProvider.class); DBCollection collection = connection.getDB().getCollection("audit"); collection.setWriteConcern(WriteConcern.UNACKNOWLEDGED); return new MongoAuditProvider(collection, includedEvents); }
@VisibleForTesting static DBCollection prepareCollection(final MongoConnection mongoConnection) { final DB db = mongoConnection.getDatabase(); DBCollection coll = db.getCollection(COLLECTION_NAME); coll.createIndex(DBSort .asc("timestamp") .asc("producer") .asc("consumers")); coll.setWriteConcern(WriteConcern.JOURNALED); return coll; }
public DBCollection getDBCollection(MetaClass metadata) { DB db = getDB(); String collectionName = getDBCollectionName(metadata); DBCollection dbCol = db.getCollection(collectionName); dbCol.setReadPreference(consistentPolicy.getReadPreference()); dbCol.setWriteConcern(consistentPolicy.getWriteConcern()); return dbCol; }
@Test public void testWrapperUpdate() { MongoDataSource ds = getDataSource(); Mongo mongo = ds.getMongoInstance(); mongo.dropDatabase(DB); DBCollection coll = mongo.getDB(DB).getCollection(COLL); coll.setWriteConcern(WriteConcern.SAFE); BasicDBObject o1 = new BasicDBObject().append("name", "value"); coll.insert(o1); BasicDBObject o2 = new BasicDBObject().append("name", "newValue"); BasicDBObject update = new BasicDBObject().append("$set", o2); Assert.assertTrue(MongoUtils.wrapperUpdate(coll, o1, update)); Assert.assertEquals(1, coll.count(o2)); Assert.assertFalse(MongoUtils.wrapperUpdate(coll, o1, update)); } }
@Override public int getCollectionCount(String dbCollectionName) { CheckConditions.checkNotNull(dbCollectionName, "Collection name can't be null!"); Integer count = cacheManager.getCountFromCache(dbCollectionName); if (count == null) { DBCollection col = this.mongo.getDB(repo.getRepositoryName()).getCollection(dbCollectionName); // read from primary only col.setReadPreference(ReadPreference.primary()); col.setWriteConcern(WriteConcern.SAFE); count = (Integer) col.getStats().get("count"); if (count == null) { count = 0; } else { cacheManager.putCountToCache(dbCollectionName, count); } } return count; }
public MongoRepositoryServiceImpl(Mongo mongo, int maxCacheSize, int cacheExpiredTime, int collectionCountCacheSize, int collectionCountCacheExpiredTime, ICMSLock metadataLock, WriteConcern writeConcern) { CheckConditions.checkNotNull(mongo, "mongo can not be null"); CheckConditions.checkArgument(maxCacheSize > 0, "maximumSize can not be negtive value"); CheckConditions.checkArgument(cacheExpiredTime > 0, "expireAfterSeconds can not be negtive value"); CheckConditions.checkArgument(metadataLock != null, "metadataLock should not be null"); this.metadataLock = metadataLock; this.mongo = mongo; this.maxCacheSize = maxCacheSize; this.cacheExpiredTime = cacheExpiredTime; cache = new ExpirableCache<Repository>(maxCacheSize, cacheExpiredTime); this.collectionCountCacheSize = collectionCountCacheSize; this.collectionCountCacheExpiredTime = collectionCountCacheExpiredTime; prepareSystemDB(mongo); repoCollection = this.mongo.getDB(CMSConsts.SYS_DB).getCollection(CMSConsts.REPOSITORY_COLL); // read from primary only repoCollection.setReadPreference(ReadPreference.primary()); repoCollection.setWriteConcern(writeConcern); }
public MongoMutex(Mongo mongo, String dbName, String collName, String lockName, String clientName, int expireTime, int renewPeriod) { super(); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(dbName), "dbName should not be null or empty"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(collName), "collName should not be null or empty"); CheckConditions.checkArgument(mongo != null, "mongo should not be null"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(lockName), "lockName should not be null or empty"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(clientName), "clientName should not be null or empty"); CheckConditions.checkArgument(expireTime >= 1000, "expireTime must be larger than 1 second"); CheckConditions.checkArgument(renewPeriod >= 400, "renewPeroid must larger than 0.4 second so renew will not cost cpu alot"); CheckConditions.checkArgument(expireTime - renewPeriod >= 1000, "expireTime - renewPeriod must be larger than 1 second so client have enough time to renew"); this.lockName = lockName; this.clientName = clientName; this.expireTime = expireTime; this.renewPeriod = renewPeriod; coll = mongo.getDB(dbName).getCollection(collName); coll.setWriteConcern(WriteConcern.SAFE); createIfNotExist(coll, lockName); }
public MongoMetadataServiceImpl(Mongo mongo, int maxCacheSize, int cacheExpiredTime, int collectionCountCacheSize, int collectionCountCacheExpiredTime, Repository repo, ICMSLock metadataLock) { CheckConditions.checkNotNull(mongo, "mongo can not be null"); CheckConditions.checkNotNull(repo, "repository can not be null"); CheckConditions.checkArgument(maxCacheSize > 0, "maximumSize can not be negtive value"); CheckConditions.checkArgument(cacheExpiredTime > 0, "expireAfterSeconds can not be negtive value"); CheckConditions.checkArgument(collectionCountCacheSize > 0, "collectionCountCacheSize can not be negtive value"); CheckConditions.checkArgument(collectionCountCacheExpiredTime > 0, "collectionCountCacheExpiredTime can not be negtive value"); CheckConditions.checkArgument(metadataLock != null, "metadataLock should not be null"); this.metadataLock = metadataLock; this.maxCacheSize= maxCacheSize; this.cacheExpiredTime = cacheExpiredTime; this.mongo = mongo; this.repo = repo; this.cacheManager = new MongoMetaCacheManager(maxCacheSize, cacheExpiredTime, collectionCountCacheSize, collectionCountCacheExpiredTime); String collectionName = CMSConsts.METACLASS_COLL; collection = mongo.getDB(repo.getRepositoryName()).getCollection(collectionName); // read from primary only collection.setReadPreference(ReadPreference.primary()); collection.setWriteConcern(WriteConcern.SAFE); sequence = new MongoSequence(mongo, CMSConsts.SYS_DB, CMSConsts.SEQUENCE_COLL, CMSConsts.NEXT_FIELD_NAME_SEQ); this.getMetaClasses(new MetadataContext(true, true)); }
collection.setWriteConcern(WriteConcern.SAFE);