@Inject public IndexFailureServiceImpl(MongoConnection mongoConnection) { super(mongoConnection); // Make sure that the index failures collection is always created capped. final String collectionName = IndexFailureImpl.class.getAnnotation(CollectionName.class).value(); if (!mongoConnection.getDatabase().collectionExists(collectionName)) { final DBObject options = BasicDBObjectBuilder.start() .add("capped", true) .add("size", 52428800) // 50MB max size. .get(); final DBCollection collection = mongoConnection.getDatabase().createCollection(collectionName, options); collection.createIndex(new BasicDBObject("timestamp", 1)); collection.createIndex(new BasicDBObject("letter_id", 1)); } }
Mongo mongo = new Mongo("127.0.0.1"); DB db = mongo.getDB("mydbid"); DBCollection collection; if (db.collectionExists("mycollection")) { collection = db.getCollection("mycollection"); } else { DBObject options = BasicDBObjectBuilder.start().add("capped", true).add("size", 2000000000l).get(); collection = db.createCollection("mycollection", options); } }
if (!db.collectionExists(tableInfo.getTableName())) if (!db.collectionExists(tableInfo.getTableName() + MongoDBUtils.FILES)) tableInfo.getTableName()); if (!db.collectionExists(tableInfo.getTableName() + MongoDBUtils.CHUNKS))
if (tableInfo.getLobColumnInfo().isEmpty()) if (!db.collectionExists(tableInfo.getTableName())) if (!db.collectionExists(tableInfo.getTableName() + MongoDBUtils.FILES)) if (!db.collectionExists(tableInfo.getTableName() + MongoDBUtils.CHUNKS))
if (db.collectionExists(tableInfo.getTableName())) if (db.collectionExists(tableInfo.getTableName() + MongoDBUtils.FILES)) if (db.collectionExists(tableInfo.getTableName() + MongoDBUtils.CHUNKS))
protected DBCollection createCollection(String name) { if (db.collectionExists(name)) { throw new RuntimeException("Failed to create collection {0}: collection already exists"); } DBCollection col = db.getCollection(name); log.debugv("Created collection {0}", name); return col; }
private void dropCollectionByName(final String collectionName, final DB mongoDb) { if (mongoDb.collectionExists(collectionName)) { dropCollection(mongoDb.getCollection(collectionName)); } }
MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mydb"); if (db.collectionExists("myCollection")) { DBCollection myCollection = db.getCollection("myCollection"); myCollection.drop(); }
@Override public void markAsUnused( Iterable<BinaryKey> keys ) { for (BinaryKey key : keys) { // silently ignore if content does not exist if (db.collectionExists(key.toString())) { DBCollection content = db.getCollection(key.toString()); setAttribute(content, FIELD_UNUSED, true); setAttribute(content, FIELD_UNUSED_SINCE, System.currentTimeMillis()); } } }
/** {@inheritDoc} */ @Override public void createSchema() { if (!mongoClient.getDB(dbName).collectionExists(collectionName)) { BasicDBObject options = new BasicDBObject(); options.put("size", 10000); mongoClient.getDB(dbName).createCollection(collectionName, options); } propertiesCollection = mongoClient.getDB(dbName).getCollection(collectionName); }
/** {@inheritDoc} */ @Override public void createSchema() { if (!mongoClient.getDB(dbName).collectionExists(collectionName)) { BasicDBObject options = new BasicDBObject(); options.put("size", 10000); featuresCollection = mongoClient.getDB(dbName).createCollection(collectionName, options); } featuresCollection = mongoClient.getDB(dbName).getCollection(collectionName); }
@Override public void markAsUsed( Iterable<BinaryKey> keys ) { for (BinaryKey key : keys) { if (db.collectionExists(key.toString())) { DBCollection content = db.getCollection(key.toString()); setAttribute(content, FIELD_UNUSED, false); setAttribute(content, FIELD_UNUSED_SINCE, null); } } }
@Override public void markAsUsed( Iterable<BinaryKey> keys ) { for (BinaryKey key : keys) { if (db.collectionExists(key.toString())) { DBCollection content = db.getCollection(key.toString()); setAttribute(content, FIELD_UNUSED, false); setAttribute(content, FIELD_UNUSED_SINCE, null); } } }
@Override public InputStream getInputStream( BinaryKey key ) throws BinaryStoreException { if (!db.collectionExists(key.toString())) { throw new BinaryStoreException(JcrI18n.unableToFindBinaryValue.text(key, db.getName())); } return new ChunkInputStream(db.getCollection(key.toString())); }
@Override public void storeExtractedText( BinaryValue source, String extractedText ) throws BinaryStoreException { if (!db.collectionExists(source.getKey().toString())) { throw new BinaryStoreException(JcrI18n.unableToFindBinaryValue.text(source.getKey(), db.getName())); } DBCollection content = db.getCollection(source.getKey().toString()); setAttribute(content, FIELD_EXTRACTED_TEXT, extractedText); }
@Override protected void storeMimeType( BinaryValue source, String mimeType ) throws BinaryStoreException { if (db.collectionExists(source.getKey().toString())) { DBCollection content = db.getCollection(source.getKey().toString()); setAttribute(content, FIELD_MIME_TYPE, mimeType); } else { throw new BinaryStoreException(JcrI18n.unableToFindBinaryValue.text(source.getKey(), db.getName())); } }
@Override public String getExtractedText( BinaryValue source ) throws BinaryStoreException { if (!db.collectionExists(source.getKey().toString())) { throw new BinaryStoreException(JcrI18n.unableToFindBinaryValue.text(source.getKey(), db.getName())); } DBCollection content = db.getCollection(source.getKey().toString()); return (String)getAttribute(content, FIELD_EXTRACTED_TEXT); }
@Override protected void storeMimeType( BinaryValue source, String mimeType ) throws BinaryStoreException { if (db.collectionExists(source.getKey().toString())) { DBCollection content = db.getCollection(source.getKey().toString()); setAttribute(content, FIELD_MIME_TYPE, mimeType); } else { throw new BinaryStoreException(JcrI18n.unableToFindBinaryValue.text(source.getKey(), db.getName())); } }
@Override protected String getStoredMimeType( BinaryValue source ) throws BinaryStoreException { if (!db.collectionExists(source.getKey().toString())) { throw new BinaryStoreException(JcrI18n.unableToFindBinaryValue.text(source.getKey(), db.getName())); } DBCollection content = db.getCollection(source.getKey().toString()); return (String)getAttribute(content, FIELD_MIME_TYPE); }
@Override public void storeExtractedText( BinaryValue source, String extractedText ) throws BinaryStoreException { if (!db.collectionExists(source.getKey().toString())) { throw new BinaryStoreException(JcrI18n.unableToFindBinaryValue.text(source.getKey(), db.getName())); } DBCollection content = db.getCollection(source.getKey().toString()); setAttribute(content, FIELD_EXTRACTED_TEXT, extractedText); }