Example usage for com.mongodb DBCollection rename

List of usage examples for com.mongodb DBCollection rename

Introduction

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

Prototype

public DBCollection rename(final String newName) 

Source Link

Document

Change the name of an existing collection.

Usage

From source file:com.liferay.mongodb.hook.service.impl.MongoExpandoTableLocalServiceImpl.java

License:Open Source License

@Override
public ExpandoTable updateTable(long tableId, String name) throws PortalException {

    ExpandoTable expandoTable = super.getTable(tableId);

    DB db = MongoDBUtil.getDB(expandoTable.getCompanyId());

    String collectionName = MongoDBUtil.getCollectionName(expandoTable.getClassName(), expandoTable.getName());
    String newCollectionName = MongoDBUtil.getCollectionName(expandoTable.getClassName(), name);

    if (db.collectionExists(newCollectionName)) {
        throw new DuplicateTableNameException(name);
    }/* ww w.j a va  2  s . c o  m*/

    expandoTable = super.updateTable(tableId, name);

    if (db.collectionExists(collectionName)) {
        DBCollection dbCollection = db.getCollection(collectionName);

        dbCollection.rename(newCollectionName);
    } else {
        db.createCollection(newCollectionName, null);
    }

    return expandoTable;
}

From source file:net.sf.okapi.lib.tmdb.mongodb.Repository.java

License:Open Source License

/**
 * Renames TM/*from  w w w .j  a v  a2 s  .c  o m*/
 * @param currentName
 * @param newName
 */
void renameTm(String currentName, String newName) {
    tm_coll = repository.getCollection(Repository.TM_COLL);

    BasicDBObject query = new BasicDBObject();
    query.put(Repository.TM_COL_NAME, newName);

    DBObject obj = tm_coll.findOne(query);

    if (obj != null) {
        throw new RuntimeException(String.format("TM '%s' already exists. Cannot rename.", newName));
    }

    query = new BasicDBObject();
    query.put(Repository.TM_COL_NAME, currentName);

    obj = tm_coll.findOne(query);

    if (obj == null) {
        throw new RuntimeException(String.format("TM '%s' does not exists.", currentName));
    }

    BasicDBObject set = new BasicDBObject("$set", new BasicDBObject("name", newName));
    tm_coll.update(query, set);

    DBCollection segList = repository.getCollection(currentName + "_SEG");
    segList.rename(newName + "_SEG");
}

From source file:org.alfresco.provision.Mongo.java

License:Open Source License

public void renameMirror(String fromAlfrescoHost, String toAlfrescoHost, String mirror) {
    String fromCollectionName = collectionName(fromAlfrescoHost, mirror);
    String toCollectionName = collectionName(toAlfrescoHost, mirror);
    if (db.collectionExists(toCollectionName)) {
        throw new RuntimeException(toCollectionName + " exists");
    }/*from w  w w . ja v a2  s  .c o  m*/
    if (db.collectionExists(fromCollectionName)) {
        DBCollection fromCollection = db.getCollection(fromCollectionName);
        logger.debug("Renaming " + fromCollectionName + " to " + toCollectionName);
        fromCollection.rename(toCollectionName);
    } else {
        throw new RuntimeException(fromCollectionName + " doesn't exist");
    }
}