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) 

Source Link

Document

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

Usage

From source file:mvm.rya.mongodb.dao.SimpleMongoDBStorageStrategy.java

License:Apache License

@Override
public void createIndices(DBCollection coll) {
    BasicDBObject doc = new BasicDBObject();
    doc.put(SUBJECT, 1);//  w  w  w. j  a v a2 s.c om
    doc.put(PREDICATE, 1);
    coll.createIndex(doc);
    doc = new BasicDBObject(PREDICATE, 1);
    doc.put(OBJECT, 1);
    doc.put(OBJECT_TYPE, 1);
    coll.createIndex(doc);
    doc = new BasicDBObject(OBJECT, 1);
    doc = new BasicDBObject(OBJECT_TYPE, 1);
    doc.put(SUBJECT, 1);
    coll.createIndex(doc);
}

From source file:net.autosauler.ballance.server.model.AbstractCatalog.java

License:Apache License

@Override
protected void onInitDbStruct(final BasicDBObject i, final DBCollection coll) {
    i.put(fieldname_fullname, 1);/* ww w . ja v a  2 s  .  com*/

    coll.createIndex(i);

}

From source file:net.autosauler.ballance.server.model.AbstractDocument.java

License:Apache License

@Override
protected void onInitDbStruct(final BasicDBObject i, final DBCollection coll) {

    i.put(fieldname_active, 1);/*w  ww  . j a v  a2  s.co m*/
    coll.createIndex(i);
}

From source file:net.autosauler.ballance.server.model.AbstractStructuredData.java

License:Apache License

/**
 * Inits the db struct.// ww w  . j ava 2  s  .  c  om
 */
private void initDBStruct() {
    DB db = Database.get(getDomain());
    if (db != null) {
        Database.retain();
        DBCollection coll = db.getCollection(getTableName());
        List<DBObject> indexes = coll.getIndexInfo();
        if (indexes.size() < 1) {
            BasicDBObject i = new BasicDBObject();
            i.put(fieldname_number, 1);
            coll.createIndex(i);

            i.put(fieldname_domain, 1);
            coll.createIndex(i);

            i.put(fieldname_trash, 1);
            coll.createIndex(i);

            onInitDbStruct(i, coll);

        }
        Database.release();
    }

}

From source file:net.autosauler.ballance.server.model.Currency.java

License:Apache License

/**
 * Creates the default records.// w  w w  .j a  va2  s . c  om
 * 
 * @param db
 *            the db
 */
public static void createDefaultRecords(DB db) {

    if (db != null) {
        DBCollection coll = db.getCollection(CURRENCYTABLE);
        if (coll.getCount() < 1) {
            if (formatter == null) {
                formatter = new SimpleDateFormat(CBRDATEFORMAT);
            }
            String day = formatter.format(new Date());
            receiveCBR(day, db);

            BasicDBObject i = new BasicDBObject();
            i.put("date", 1);
            i.put("mnemo", 1);

            coll.createIndex(i);

            i = new BasicDBObject();
            i.put("timestamp", 1);
            i.put("mnemo", 1);

            coll.createIndex(i);

        }
    }
}

From source file:net.autosauler.ballance.server.model.DocumentTablePart.java

License:Apache License

@Override
protected void onInitDbStruct(BasicDBObject i, DBCollection coll) {
    i.put(fieldname_document, 1);

    coll.createIndex(i);

}

From source file:net.autosauler.ballance.server.model.GlobalSettings.java

License:Apache License

/**
 * Creates the default records.//from  w  w  w .j a va 2 s.co m
 * 
 * @param db
 *            the db
 */
public static void createDefaultRecords(DB db) {

    if (db != null) {
        DBCollection coll = db.getCollection(SETTINGSTABLE);
        if (coll.getCount() < 1) {

            BasicDBObject rec = new BasicDBObject();
            rec.put("name", "default.record");
            rec.put("val", "default.value");
            coll.insert(rec);

            BasicDBObject i = new BasicDBObject();
            i.put("domain", 1);
            i.put("name", 1);
            coll.createIndex(i);

        }
    }
}

From source file:net.autosauler.ballance.server.model.Scripts.java

License:Apache License

/**
 * Inits the struct.//from  w w  w  . ja  va2 s.co  m
 */
private void initStruct() {
    DB db = Database.get(domain);
    if (db != null) {
        Database.retain();
        DBCollection coll = db.getCollection(TABLENAME);
        List<DBObject> indexes = coll.getIndexInfo();
        if (indexes.size() < 1) {
            BasicDBObject i = new BasicDBObject();

            i.put("domain", 1);
            i.put("name", 1);
            coll.createIndex(i);

        }
        Database.release();
    }
}

From source file:net.autosauler.ballance.server.model.UserList.java

License:Apache License

/**
 * Creates the default records if no users in database.
 * /*from   www.jav a2 s. c o  m*/
 * @param db
 *            the db
 */
public static void createDefaultRecords(DB db) {

    if (db != null) {
        DBCollection coll = db.getCollection(collectionname);
        if (coll.getCount() < 1) {
            UserRole defaultroles = new UserRole();
            defaultroles.setAdmin();

            User user = new User();
            user.setPassword("admin");
            user.setLogin("admin");
            user.setDomain("127.0.0.1");
            user.setUsername("Admin The Great");
            user.setUserrole(defaultroles);
            user.addNewUser();

            BasicDBObject i = new BasicDBObject();
            i.put("login", 1);
            i.put("domain", 1);

            coll.createIndex(i);

            i.put("istrash", 1);
            coll.createIndex(i);
        }
    }
}

From source file:net.jurre.edutil.persistence.MongoDB.java

License:Open Source License

private void checkDB() {
    DBCollection stationColl = this.db.getCollection(STATIONS_COLLECTION);
    stationColl.createIndex("name");
    stationColl.createIndex("system_id");
    stationColl.createIndex(new BasicDBObject("name", "text"));

    DBCollection systemsColl = this.db.getCollection(SYSTEMS_COLLECTION);
    systemsColl.createIndex("name");
    systemsColl.createIndex(new BasicDBObject("name", "text"));

}