Example usage for com.mongodb DBCollection createIndex

List of usage examples for com.mongodb DBCollection createIndex

Introduction

In this page you can find the example usage for com.mongodb DBCollection createIndex.

Prototype

public void createIndex(final DBObject keys, final DBObject options) 

Source Link

Document

Creates an index on the field specified, if that index does not already exist.

Usage

From source file:com.cedac.security.acls.mongo.MongoAclService.java

License:Apache License

@Override
public void afterPropertiesSet() throws Exception {
    this.qualifiedObjectIdClassFieldName = this.objectIdFieldName + "." + this.classFieldName;
    this.qualifiedObjectIdIdentityFieldName = this.objectIdFieldName + "." + this.identityFieldName;
    this.qualifiedParentObjectClassFieldName = this.parentObjectFieldName + "." + this.classFieldName;
    this.qualifiedParentObjectIdentityFieldName = this.parentObjectFieldName + "." + this.identityFieldName;

    if (!this.db.collectionExists(aclCollectionName)) {
        LOG.debug(ACL, "Creating collection for name '{}'", aclCollectionName);

        DBCollection aclCollection = this.db.createCollection(aclCollectionName, new BasicDBObject());
        aclCollection.createIndex(
                new BasicDBObject(qualifiedObjectIdClassFieldName, 1).append(qualifiedObjectIdIdentityFieldName,
                        1),//w  w  w .  ja  v a 2  s. c  o  m
                new BasicDBObject("unique", 1).append("name", "acl_objectId_ix").append("background", 1));
        aclCollection.createIndex(
                new BasicDBObject(qualifiedParentObjectClassFieldName, 1)
                        .append(qualifiedParentObjectIdentityFieldName, 1),
                new BasicDBObject("name", "acl_parent_ix").append("background", 1));
    }

    this.acesField.setAccessible(true);
}

From source file:com.cedac.security.oauth2.provider.approval.MongoApprovalStore.java

License:Apache License

@Override
public void afterPropertiesSet() throws Exception {
    if (!this.db.collectionExists(approvalsCollectionName)) {
        LOG.trace(APPROVAL, "Creating {} collection", approvalsCollectionName);

        DBCollection collection = this.db.createCollection(approvalsCollectionName, new BasicDBObject());
        collection.createIndex(new BasicDBObject(clientIdFieldName, 1).append(userIdFieldName, 1),
                new BasicDBObject("name",
                        approvalsCollectionName + "_" + clientIdFieldName + "_" + userIdFieldName + "_ix")
                                .append("background", 1));

        LOG.debug(APPROVAL, "Collection {} successfully created and indexed", approvalsCollectionName);
    }//from  w w w  . j a  v a 2 s.c  om
}

From source file:com.cedac.security.oauth2.provider.client.MongoClientDetailsService.java

License:Apache License

@Override
public void afterPropertiesSet() throws Exception {
    if (!this.db.collectionExists(clientDetailsCollectionName)) {
        LOG.trace(CLIENT, "Creating {} collection", clientDetailsCollectionName);

        DBCollection collection = this.db.createCollection(clientDetailsCollectionName, new BasicDBObject());
        collection.createIndex(new BasicDBObject(clientIdFieldName, 1),
                new BasicDBObject("name", clientDetailsCollectionName + "_" + clientIdFieldName + "_ix")
                        .append("unique", 1));

        LOG.debug(CLIENT, "Collection {} successfully created and indexed", clientDetailsCollectionName);
    }//from   w ww . j  av a  2 s .  c  om
}

From source file:com.cedac.security.oauth2.provider.code.MongoAuthorizationCodeServices.java

License:Apache License

@Override
public void afterPropertiesSet() throws Exception {
    if (!this.db.collectionExists(authCodeCollectionName)) {
        LOG.trace(CODE, "Creating {} collection", authCodeCollectionName);

        DBCollection collection = this.db.createCollection(authCodeCollectionName, new BasicDBObject());
        collection.createIndex(new BasicDBObject(codeFieldName, 1),
                new BasicDBObject("name", authCodeCollectionName + "_" + codeFieldName + "_ix")
                        .append("unique", true).append("background", 1));

        LOG.debug(CODE, "Collection {} successfully created and indexed", authCodeCollectionName);
    }/*from  w  w  w.  j av a  2 s  .com*/
}

From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java

License:Apache License

@Override
public void afterPropertiesSet() throws Exception {
    if (!this.db.collectionExists(accessTokenCollectionName)) {
        LOG.trace(TOKEN, "Creating {} collection", accessTokenCollectionName);

        DBCollection collection = this.db.createCollection(accessTokenCollectionName, new BasicDBObject());
        collection.createIndex(new BasicDBObject(tokenIdFieldName, 1),
                new BasicDBObject("name", accessTokenCollectionName + "_" + tokenIdFieldName + "_ix")
                        .append("background", 1));
        collection.createIndex(new BasicDBObject(authenticationIdFieldName, 1),
                new BasicDBObject("name", accessTokenCollectionName + "_" + authenticationFieldName + "_ix")
                        .append("background", 1));

        LOG.debug(TOKEN, "Collection {} successfully created and indexed", accessTokenCollectionName);
    }/*from   w  ww  . j  a va 2  s.  c  o m*/
    if (!this.db.collectionExists(refreshTokenCollectionName)) {
        LOG.trace(TOKEN, "Creating {} collection", refreshTokenCollectionName);

        DBCollection collection = this.db.createCollection(refreshTokenCollectionName, new BasicDBObject());
        collection.createIndex(new BasicDBObject(tokenIdFieldName, 1),
                new BasicDBObject("name", refreshTokenCollectionName + "_ix"));

        LOG.debug(TOKEN, "Collection {} successfully created and indexed", accessTokenCollectionName);
    }
}

From source file:com.edgytech.umongo.CollectionPanel.java

License:Apache License

public void createIndex(final ButtonBase button) {
    final CollectionNode node = getCollectionNode();
    final DBCollection col = getCollectionNode().getCollection();
    CreateIndexDialog dia = (CreateIndexDialog) button.getDialog();
    final DBObject keys = dia.getKeys();
    final DBObject opts = dia.getOptions();

    if (!UMongo.instance.getGlobalStore().confirmLockingOperation()) {
        return;//from www  . j ava2s  .com
    }

    new DbJob() {
        @Override
        public Object doRun() throws IOException {
            //                opts.put("key", keys);
            //                return col.getDB().getCollection("system.indexes").insert(opts);
            //                col.ensureIndex(keys, opts);
            col.createIndex(keys, opts);
            return new BasicDBObject("ok", 1);
        }

        @Override
        public String getNS() {
            return col.getFullName();
        }

        @Override
        public String getShortName() {
            return "Ensure Index";
        }

        @Override
        public void wrapUp(Object res) {
            super.wrapUp(res);
            node.structureComponent();
        }

        @Override
        public ButtonBase getButton() {
            return button;
        }

        @Override
        public DBObject getRoot(Object result) {
            BasicDBObject obj = new BasicDBObject("keys", keys);
            obj.put("options", opts);
            return obj;
        }
    }.addJob();
}

From source file:com.enitalk.configs.MongoInit.java

@PostConstruct
public void init() {
    DBCollection coll3 = getCollection("teachers");
    coll3.createIndex(new BasicDBObject("i", 1), new BasicDBObject("unique", false));
    coll3.createIndex(new BasicDBObject("dest.sendTo", 1), new BasicDBObject("unique", false));
    coll3.createIndex(new BasicDBObject("visible", 1), new BasicDBObject("unique", false));

    DBCollection coll5 = getCollection("leads");
    coll5.createIndex(new BasicDBObject("userId", 1), new BasicDBObject("unique", false));
    coll5.createIndex(new BasicDBObject("want", 1), new BasicDBObject("unique", false));
    coll5.createIndex(new BasicDBObject("dest.sendTo", 1), new BasicDBObject("unique", false));
    coll5.createIndex(new BasicDBObject("confirmCode", 1), new BasicDBObject("unique", false));
    coll5.createIndex(new BasicDBObject("email", 1), new BasicDBObject("unique", false));
    coll5.createIndex(new BasicDBObject("eniword.words", 1), new BasicDBObject("unique", false));
    coll5.createIndex(new BasicDBObject("eniword.point", 1), new BasicDBObject("unique", false));
    coll5.createIndex(new BasicDBObject("eniword.nextPing", 1), new BasicDBObject("unique", false));
    coll5.createIndex(new BasicDBObject("eniword.disabled", 1), new BasicDBObject("unique", false));

    DBCollection coll6 = getCollection("events");
    coll6.createIndex(new BasicDBObject("student.dest.sendTo", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("student.email", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("teacher.email", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("teacher.dest.sendTo", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("teacher.i", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("student.paypal.ppToken", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("status", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("ii", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("sessionId", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("video", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("check", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("checkDate", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("dd", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("endDate", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("f", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("opentok.id", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("invId", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("reminderDate", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("reminded", 1), new BasicDBObject("unique", false));
    coll6.createIndex(new BasicDBObject("createDate", 1), new BasicDBObject("unique", false));

    //        DBCollection history = getCollection("eniword_history");
    //        history.createIndex(new BasicDBObject("dest.sendTo", 1), new BasicDBObject("unique", false));
    //        history.createIndex(new BasicDBObject("insertDate", 1), new BasicDBObject("unique", false));
    //        /*from   w ww.j a  v  a 2 s.  c  om*/
    //        DBCollection words = getCollection("words");
    //        words.createIndex(new BasicDBObject("i", 1), new BasicDBObject("unique", false));
    //        words.createIndex(new BasicDBObject("id", 1), new BasicDBObject("unique", false));
    //        words.createIndex(new BasicDBObject("type", 1), new BasicDBObject("unique", false));

}

From source file:com.gigaspaces.persistency.metadata.IndexBuilder.java

License:Open Source License

private void createIndex(String typeSimpleName, String routing, SpaceIndexType type,
        BasicDBObjectBuilder option) {// ww w  .j  a  v a 2s . c  o m
    DBCollection c = client.getCollection(typeSimpleName);

    DBObject key;

    if (type == SpaceIndexType.BASIC) {
        key = BasicDBObjectBuilder.start(routing, "hashed").get();
    } else {
        key = BasicDBObjectBuilder.start(routing, 1).get();
    }

    c.createIndex(key, option.get());
}

From source file:com.images3.data.impl.MongoDBAccessProvider.java

License:Apache License

private void initTemplate(DB db) {
    DBCollection coll = db.getCollection("Template");
    coll.createIndex(new BasicDBObject().append("imagePlantId", 1).append("nameKey", 1),
            new BasicDBObject("unique", true));
    coll.createIndex(new BasicDBObject().append("imagePlantId", 1).append("isArchived", 1));
}

From source file:com.images3.data.impl.MongoDBAccessProvider.java

License:Apache License

private void initImage(DB db) {
    DBCollection coll = db.getCollection("Image");
    coll.createIndex(new BasicDBObject().append("imagePlantId", 1).append("id", 1),
            new BasicDBObject("unique", true));
    coll.createIndex(new BasicDBObject().append("imagePlantId", 1).append("version.templateName", 1)
            .append("version.originalImageId", 1));
}