@Override public void close() { cursor.close(); } }
/** * Codec used for current collection type. * @return registry */ protected final CodecRegistry codecRegistry() { return collection.getCodecRegistry(); }
private Set<String> getTableMetadataNames(String schemaName) throws TableNotFoundException { MongoDatabase db = client.getDatabase(schemaName); MongoCursor<Document> cursor = db.getCollection(schemaCollection) .find().projection(new Document(TABLE_NAME_KEY, true)).iterator(); HashSet<String> names = new HashSet<>(); while (cursor.hasNext()) { names.add((cursor.next()).getString(TABLE_NAME_KEY)); } return names; }
private static void createIndex(MongoConnection mongoConnection) { final IndexOptions indexOptions = new IndexOptions() .name(INDEX_NAME) .unique(true); mongoConnection.getMongoDatabase() .getCollection(COLLECTION_NAME) .createIndex(Indexes.ascending("name"), indexOptions); }
private boolean deleteTableMetadata(SchemaTableName schemaTableName) { String schemaName = schemaTableName.getSchemaName(); String tableName = schemaTableName.getTableName(); MongoDatabase db = client.getDatabase(schemaName); if (!collectionExists(db, tableName)) { return false; } DeleteResult result = db.getCollection(schemaCollection) .deleteOne(new Document(TABLE_NAME_KEY, tableName)); return result.getDeletedCount() == 1; }
public MongoCursor<Document> execute(MongoSplit split, List<MongoColumnHandle> columns) { Document output = new Document(); for (MongoColumnHandle column : columns) { output.append(column.getName(), 1); } MongoCollection<Document> collection = getCollection(split.getSchemaTableName()); FindIterable<Document> iterable = collection.find(buildQuery(split.getTupleDomain())).projection(output); if (cursorBatchSize != 0) { iterable.batchSize(cursorBatchSize); } return iterable.iterator(); }
@Inject public MongoDBSessionServiceImpl(MongoConnection mongoConnection) { super(mongoConnection); final MongoDatabase database = mongoConnection.getMongoDatabase(); final MongoCollection<Document> sessions = database.getCollection(MongoDbSession.COLLECTION_NAME); sessions.createIndex(Indexes.ascending(MongoDbSession.FIELD_SESSION_ID)); }
public FindIterable<Document> doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { return collection.find(query, Document.class).projection(fields); } }
protected Repository( RepositorySetup configuration, String collectionName, Class<T> type) { this.configuration = checkNotNull(configuration, "configuration"); checkNotNull(collectionName, "collectionName"); checkNotNull(type, "type"); MongoCollection<T> collection = configuration.database.getCollection(collectionName, type); this.collection = collection.withCodecRegistry(configuration.codecRegistry); this.fieldNamingStrategy = configuration.fieldNamingStrategy; }
private MongoCollection<Document> getCollection(String schema, String table) { return client.getDatabase(schema).getCollection(table); }
@Override public Integer call() { collection().insertMany(documents); return 0; // java driver for mongo returns 0 anyway } });
public boolean collectionExists(MongoDatabase db, String collectionName) { for (String name : db.listCollectionNames()) { if (name.equalsIgnoreCase(collectionName)) { return true; } } return false; }
public void dropTable(SchemaTableName tableName) { deleteTableMetadata(tableName); getCollection(tableName).drop(); tableCache.invalidate(tableName); }
@Override public void close() throws IOException { database.drop(); } });
@Override public ServerAddress getServerAddress() { return proxied.getServerAddress(); } }
@Override public void forEach(final Block<? super V> block) { iterable.forEach(new Block<U>() { @Override public void apply(final U document) { block.apply(mapper.apply(document)); } }); }
@Override public MappingIterable<U, V> batchSize(final int batchSize) { iterable.batchSize(batchSize); return this; }
private Document findOne(Document query, Document projection) { MongoCollection col = controllerService.getDatabase(databaseName).getCollection(collection); MongoCursor<Document> it = (projection != null ? col.find(query).projection(projection) : col.find(query)).iterator(); Document retVal = it.hasNext() ? it.next() : null; it.close(); return retVal; } }