@Override public void initialize(String blobProviderId, Map<String, String> properties) throws IOException { super.initialize(blobProviderId, properties); this.properties = properties; if (StringUtils.isNotBlank(properties.get(SERVER_PROPERTY)) || StringUtils.isNotBlank(properties.get(DBNAME_PROPERTY))) { throw new NuxeoException("Unable to initialize GridFS Binary Manager, properties " + SERVER_PROPERTY + " and " + DBNAME_PROPERTY + " has been removed. Please configure a connection!"); } String bucket = properties.get(BUCKET_PROPERTY); if (StringUtils.isBlank(bucket)) { bucket = blobProviderId + ".fs"; } MongoDBConnectionService mongoService = Framework.getService(MongoDBConnectionService.class); MongoDatabase database = mongoService.getDatabase(BLOB_PROVIDER_CONNECTION_PREFIX + blobProviderId); gridFSBucket = GridFSBuckets.create(database, bucket); filesColl = database.getCollection(bucket + ".files"); garbageCollector = new GridFSBinaryGarbageCollector(bucket); }
public MongoDBRepository(ConnectionManager cm, MongoDBRepositoryDescriptor descriptor) { super(cm, descriptor.name, descriptor); MongoDBConnectionService mongoService = Framework.getService(MongoDBConnectionService.class); // prefix with repository/ to group repository connection MongoDatabase database = mongoService.getDatabase(REPOSITORY_CONNECTION_PREFIX + descriptor.name); coll = database.getCollection(descriptor.name); countersColl = database.getCollection(descriptor.name + ".counters"); if (Boolean.TRUE.equals(descriptor.nativeId)) { idKey = MONGODB_ID; } else { idKey = KEY_ID; } useCustomId = KEY_ID.equals(idKey); if (idType == IdType.sequence || DEBUG_UUIDS) { Integer sbs = descriptor.sequenceBlockSize; sequenceBlockSize = sbs == null ? 1 : sbs.longValue(); sequenceLeft = 0; } converter = new MongoDBConverter(useCustomId ? null : KEY_ID); cursorService = new CursorService<>(ob -> (String) ob.get(converter.keyToBson(KEY_ID))); initRepository(); }
database = mongoService.getDatabase(DIRECTORY_CONNECTION_PREFIX + getName()); collection = database.getCollection(getName()); String countersCollectionName = getName() + ".counters";