Example usage for com.mongodb.client.model IndexOptions IndexOptions

List of usage examples for com.mongodb.client.model IndexOptions IndexOptions

Introduction

In this page you can find the example usage for com.mongodb.client.model IndexOptions IndexOptions.

Prototype

IndexOptions

Source Link

Usage

From source file:br.ufg.inf.es.saep.sandbox.persistencia.service.BasicParecerDAO.java

License:Creative Commons License

/**
 * Construtor responsvel por inicializar a coleo referente aos Parecer.
 *
 * @param mongoDatabase Instancia do banco de dados mongo.
 * @param collectionName Nome da coleo referente ao {@code Parecer}
 * @see Parecer//ww  w.j  av  a  2s.c o m
 */
public BasicParecerDAO(MongoDatabase mongoDatabase, String collectionName) {
    this.mongoDatabase = mongoDatabase;
    this.mongoCollection = this.mongoDatabase.getCollection(collectionName);

    Document index = new Document(ID, 1);
    this.mongoCollection.createIndex(index, new IndexOptions().unique(true));
}

From source file:br.ufg.inf.es.saep.sandbox.persistencia.service.BasicRadocDAO.java

License:Creative Commons License

/**
 * Construtor responsvel por inicializar a coleo referente aos Radoc.
 *
 * @param mongoDatabase Instancia do banco de dados mongo.
 * @param collectionName Nome da coleo referente ao {@code Radoc}
 * @see Radoc// w w  w  .j  a  v a 2  s  .c  o m
 */
public BasicRadocDAO(MongoDatabase mongoDatabase, String collectionName) {
    this.mongoDatabase = mongoDatabase;
    this.mongoCollection = this.mongoDatabase.getCollection(collectionName);

    Document index = new Document(ID, 1);
    this.mongoCollection.createIndex(index, new IndexOptions().unique(true));
}

From source file:br.ufg.inf.es.saep.sandbox.persistencia.service.BasicResolucaoDAO.java

License:Creative Commons License

/**
 * Construtor responsvel por inicializar a coleo referente s Resolues.
 * /*from   w w  w . j a va  2 s. c om*/
 * @param mongoDatabase Instancia do banco de dados mongo.
 * @param collectionName Nome da coleo referente  {@code Resolucao}
 * @see Resolucao
 */
public BasicResolucaoDAO(MongoDatabase mongoDatabase, String collectionName) {
    this.mongoDatabase = mongoDatabase;
    this.mongoCollection = this.mongoDatabase.getCollection(collectionName);

    Document index = new Document(ID, 1);
    this.mongoCollection.createIndex(index, new IndexOptions().unique(true));
}

From source file:br.ufg.inf.es.saep.sandbox.persistencia.service.BasicTipoDAO.java

License:Creative Commons License

/**
 * Construtor responsvel por inicializar a coleo referente aos Tipo.
 *
 * @param mongoDatabase Instancia do banco de dados mongo.
 * @param collectionName Nome da coleo referente ao {@code Tipo}
 * @see Tipo/*from  w  w  w.  j  ava  2 s. c  o  m*/
 */
public BasicTipoDAO(MongoDatabase mongoDatabase, String collectionName) {
    this.mongoDatabase = mongoDatabase;
    this.mongoCollection = this.mongoDatabase.getCollection(collectionName);

    Document index = new Document(ID, 1);
    this.mongoCollection.createIndex(index, new IndexOptions().unique(true));
}

From source file:com.bluedragon.mongo.MongoCollectionIndexEnsure.java

License:Open Source License

public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {
    MongoDatabase db = getMongoDatabase(_session, argStruct);
    String collection = getNamedStringParam(argStruct, "collection", null);
    if (collection == null)
        throwException(_session, "please specify a 'collection' parameter");

    cfData keys = getNamedParam(argStruct, "keys", null);
    if (keys == null)
        throwException(_session, "please specify 'keys' parameter");

    String index = getNamedStringParam(argStruct, "name", null);
    if (index == null)
        throwException(_session, "please specify 'index' parameter");

    try {/*w  ww.j a va 2 s .co m*/

        db.getCollection(collection).createIndex(getDocument(keys),
                new IndexOptions().background(true).unique(getNamedBooleanParam(argStruct, "unique", false)));

        return cfBooleanData.TRUE;
    } catch (Exception me) {
        throwException(_session, me.getMessage());
        return null;
    }
}

From source file:com.centurylink.mdw.mongo.MongoDocumentDb.java

License:Apache License

public static void createMongoDocIdIndex(String collectionName) {
    IndexOptions indexOptions = new IndexOptions().unique(true).background(true);
    MongoCollection<org.bson.Document> collection = mongoClient.getDatabase("mdw")
            .getCollection(collectionName);
    String indexName = collection.createIndex(Indexes.ascending("document_id"), indexOptions);
    LoggerUtil.getStandardLogger()/*from  ww w.  j av a 2 s . c om*/
            .mdwDebug("Created Index : " + indexName + " on collection : " + collectionName);
    collectionDocIdIndexed.putIfAbsent(collectionName, Boolean.valueOf(true));
}

From source file:com.epam.dlab.backendapi.dao.IndexCreator.java

License:Apache License

@Override
public void start() {
    mongoService.getCollection(USER_INSTANCES).createIndex(
            new BasicDBObject(USER, 1).append(EXPLORATORY_NAME, 2), new IndexOptions().unique(true));
    // TODO: Make refactoring and append indexes for other mongo collections
}

From source file:com.epam.dlab.mongo.MongoDbConnection.java

License:Apache License

/**
 * Create index on billing collection./*from   w w w .ja va  2 s .  c o m*/
 *
 * @param indexName the name of index.
 * @param index     the index options.
 */
private void createBillingIndexes(String indexName, Bson index) {
    MongoCollection<Document> collection = database.getCollection(MongoConstants.COLLECTION_BILLING);
    IndexOptions options = new IndexOptions().name(MongoConstants.COLLECTION_BILLING + indexName);
    try {
        collection.createIndex(index, options);
    } catch (Exception e) {
        LOGGER.warn("Cannot create index {} on collection {}. {}", options.getName(),
                MongoConstants.COLLECTION_BILLING, e.getLocalizedMessage(), e);
    }
}

From source file:com.facebook.presto.mongodb.MongoSession.java

License:Apache License

private Document getTableMetadata(SchemaTableName schemaTableName) throws TableNotFoundException {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();

    MongoDatabase db = client.getDatabase(schemaName);
    MongoCollection<Document> schema = db.getCollection(schemaCollection);

    Document doc = schema.find(new Document(TABLE_NAME_KEY, tableName)).first();

    if (doc == null) {
        if (!collectionExists(db, tableName)) {
            throw new TableNotFoundException(schemaTableName);
        } else {//from w  ww.  j a v a  2 s .  c  o m
            Document metadata = new Document(TABLE_NAME_KEY, tableName);
            metadata.append(FIELDS_KEY, guessTableFields(schemaTableName));

            schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
            schema.insertOne(metadata);

            return metadata;
        }
    }

    return doc;
}

From source file:com.facebook.presto.mongodb.MongoSession.java

License:Apache License

private void createTableMetadata(SchemaTableName schemaTableName, List<MongoColumnHandle> columns)
        throws TableNotFoundException {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();

    MongoDatabase db = client.getDatabase(schemaName);
    Document metadata = new Document(TABLE_NAME_KEY, tableName);

    ArrayList<Document> fields = new ArrayList<>();
    if (!columns.stream().anyMatch(c -> c.getName().equals("_id"))) {
        fields.add(new MongoColumnHandle("_id", OBJECT_ID, true).getDocument());
    }//from ww  w.ja  va2 s  .c  o m

    fields.addAll(columns.stream().map(MongoColumnHandle::getDocument).collect(toList()));

    metadata.append(FIELDS_KEY, fields);

    MongoCollection<Document> schema = db.getCollection(schemaCollection);
    schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
    schema.insertOne(metadata);
}