com.mongodb.client.ListIndexesIterable Java Examples
The following examples show how to use
com.mongodb.client.ListIndexesIterable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoIndex.java From presto with Apache License 2.0 | 6 votes |
public static List<MongoIndex> parse(ListIndexesIterable<Document> indexes) { ImmutableList.Builder<MongoIndex> builder = ImmutableList.builder(); for (Document index : indexes) { // TODO: v, ns, sparse fields Document key = (Document) index.get("key"); String name = index.getString("name"); boolean unique = index.getBoolean("unique", false); if (key.containsKey("_fts")) { // Full Text Search continue; } builder.add(new MongoIndex(name, parseKey(key), unique)); } return builder.build(); }
Example #2
Source File: MongoCompensableLogger.java From ByteTCC with GNU Lesser General Public License v3.0 | 5 votes |
private void createTransactionsGlobalTxKeyIndexIfNecessary() { String databaseName = CommonUtils.getApplication(this.endpoint).replaceAll("\\W", "_"); MongoDatabase database = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> transactions = database.getCollection(CONSTANTS_TB_TRANSACTIONS); ListIndexesIterable<Document> transactionIndexList = transactions.listIndexes(); boolean transactionIndexExists = false; MongoCursor<Document> transactionCursor = null; try { transactionCursor = transactionIndexList.iterator(); while (transactionIndexExists == false && transactionCursor.hasNext()) { Document document = transactionCursor.next(); Boolean unique = document.getBoolean("unique"); Document key = (Document) document.get("key"); boolean globalExists = key.containsKey(CONSTANTS_FD_GLOBAL); boolean lengthEquals = key.size() == 1; transactionIndexExists = lengthEquals && globalExists; if (transactionIndexExists && (unique == null || unique == false)) { throw new IllegalStateException(); } } } finally { IOUtils.closeQuietly(transactionCursor); } if (transactionIndexExists == false) { Document index = new Document(CONSTANTS_FD_GLOBAL, 1); transactions.createIndex(index, new IndexOptions().unique(true)); } }
Example #3
Source File: MongoCompensableLock.java From ByteTCC with GNU Lesser General Public License v3.0 | 5 votes |
private void createLocksIndexIfNecessary() { String databaseName = CommonUtils.getApplication(this.endpoint).replaceAll("\\W", "_"); MongoDatabase database = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> locks = database.getCollection(CONSTANTS_TB_LOCKS); ListIndexesIterable<Document> lockIndexList = locks.listIndexes(); boolean transactionIndexExists = false; MongoCursor<Document> lockCursor = null; try { lockCursor = lockIndexList.iterator(); while (transactionIndexExists == false && lockCursor.hasNext()) { Document document = lockCursor.next(); Boolean unique = document.getBoolean("unique"); Document key = (Document) document.get("key"); boolean globalExists = key.containsKey(CONSTANTS_FD_GLOBAL); boolean lengthEquals = key.size() == 1; transactionIndexExists = lengthEquals && globalExists; if (transactionIndexExists && (unique == null || unique == false)) { throw new IllegalStateException(); } } } finally { IOUtils.closeQuietly(lockCursor); } if (transactionIndexExists == false) { Document index = new Document(CONSTANTS_FD_GLOBAL, 1); locks.createIndex(index, new IndexOptions().unique(true)); } }
Example #4
Source File: CmdIdxAccessStats.java From mongodb-slow-operations-profiler with GNU Affero General Public License v3.0 | 5 votes |
private HashMap<String, Document> getIndexesProperties(MongoCollection collection){ final HashMap<String, Document> result = new HashMap<>(); final ListIndexesIterable<Document> currentIndexes = collection.listIndexes(); for(Document doc: currentIndexes){ String indexName = doc.getString("name"); if(indexName != null){ result.put(indexName, doc); } } return result; }