protected <T> void ensureIndex(final DBCollection dbColl,
final String name, final BasicDBObject fields,
final boolean unique, final boolean dropDupsOnCreate,
final boolean background, final boolean sparse,
final int expireAfterSeconds) {
final BasicDBObjectBuilder keyOpts = new BasicDBObjectBuilder();
if (name != null && name.length() != 0) {
keyOpts.add("name", name);
}
if (unique) {
keyOpts.add("unique", true);
if (dropDupsOnCreate) {
keyOpts.add("dropDups", true);
}
}
if (background) {
keyOpts.add("background", true);
}
if (sparse) {
keyOpts.add("sparse", true);
}
if (expireAfterSeconds > -1) {
keyOpts.add("expireAfterSeconds", expireAfterSeconds);
}
final BasicDBObject opts = (BasicDBObject) keyOpts.get();
if (opts.isEmpty()) {
LOG.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields);
dbColl.createIndex(fields);
} else {
LOG.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields + " and opts:" + opts);