List of usage examples for com.mongodb DBCollection getIndexInfo
public List<DBObject> getIndexInfo()
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestIndex.java
License:Open Source License
/** * @param args//from ww w. j a v a 2 s . co m */ public static void main(String[] args) throws Exception { // for(int i=0; i<1000000; i++) { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port); DB db = mongo.getDB("test"); Set<String> setCollection = db.getCollectionNames(); for (String colName : setCollection) { DBCollection col = db.getCollection(colName); List<DBObject> listIndex = col.getIndexInfo(); System.out.println("[colection]" + colName); for (DBObject dbObject : listIndex) { System.out.println("\t" + dbObject); // Map<String, Integer> objMap = (Map)dbObject.get("key"); // Set<String> objMapKey = objMap.keySet(); // for (String strKey : objMapKey) { // System.out.println("[key]" + strKey + "\t [value]" + objMap.get(strKey).toString()); // } } } mongo.close(); try { Thread.sleep(1); } catch (Exception e) { } // } }
From source file:com.hangum.tadpole.mongodb.erd.core.dnd.TableTransferDropTargetListener.java
License:Open Source License
/** * table? .//w w w . ja v a 2 s . c o m * * @param strTBName * @return * @throws Exception */ public List<CollectionFieldDAO> getColumns(String strTBName) throws Exception { Mongo mongo = new Mongo(new DBAddress(userDB.getUrl())); com.mongodb.DB mongoDB = mongo.getDB(userDB.getDb()); DBCollection coll = mongoDB.getCollection(strTBName); return MongoDBTableColumn.tableColumnInfo(coll.getIndexInfo(), coll.findOne()); }
From source file:com.ikanow.infinit.e.processing.generic.GenericProcessingController.java
License:Open Source License
private static void addIndexIfNeeded(DBCollection coll, String indexToCheck, int nIndexIndex, BasicDBObject newIndex) {/*from ww w . j a v a 2s.c om*/ StringBuffer indexNameStrBuff = new StringBuffer(indexToCheck); if (0 != nIndexIndex) { indexNameStrBuff.append("_").append(nIndexIndex); } String indexName2 = indexNameStrBuff.toString(); List<DBObject> list = coll.getIndexInfo(); for (DBObject dbo : list) { String name = (String) dbo.get("name"); if (indexName2.equalsIgnoreCase(name)) { return; // no need to create a new index } } // If we're here then we didn't find the index so create a new index try { coll.ensureIndex(newIndex); } catch (Exception e) { } }
From source file:com.ikanow.infinit.e.processing.generic.GenericProcessingController.java
License:Open Source License
private static void dropIndexIfNotNeeded(DBCollection coll, String indexToCheck, int nIndexToCheckIndex, String indexToDelete, int nIndexToDeleteIndex) { StringBuffer indexNameStrBuff = new StringBuffer(indexToCheck); if (0 != nIndexToCheckIndex) { indexNameStrBuff.append("_").append(nIndexToCheckIndex); }/*www. java2 s . com*/ String indexToCheck2 = indexNameStrBuff.toString(); indexNameStrBuff.setLength(0); indexNameStrBuff.append(indexToDelete); if (0 != nIndexToDeleteIndex) { indexNameStrBuff.append("_").append(nIndexToDeleteIndex); } boolean foundIndexToDelete = false; boolean foundIndexToCheck = false; String indexToDelete2 = indexNameStrBuff.toString(); List<DBObject> list = coll.getIndexInfo(); for (DBObject dbo : list) { String name = (String) dbo.get("name"); if (indexToCheck2.equalsIgnoreCase(name)) { foundIndexToCheck = true; } else if (indexToDelete2.equalsIgnoreCase(name)) { foundIndexToDelete = true; } } if (foundIndexToCheck && foundIndexToDelete) { try { coll.dropIndex(indexToDelete2); } catch (Exception e) { } } }
From source file:com.ikanow.infinit.e.processing.generic.GenericProcessingController.java
License:Open Source License
private void dropIndexIfItExists(DBCollection coll, String indexName, int nIndexIndex) { StringBuffer indexNameStrBuff = new StringBuffer(indexName); if (0 != nIndexIndex) { indexNameStrBuff.append("_").append(nIndexIndex); }//from www . j a va2s . com String indexName2 = indexNameStrBuff.toString(); List<DBObject> list = coll.getIndexInfo(); for (DBObject dbo : list) { String name = (String) dbo.get("name"); if (indexName2.equalsIgnoreCase(name)) { try { coll.dropIndex(name); } catch (Exception e) { } } } }
From source file:com.impetus.client.mongodb.MongoDBClient.java
License:Apache License
/** * Creates the index.// w w w . j a v a 2s . c o m * * @param collectionName * the collection name * @param columnList * the column list * @param order * the order */ public void createIndex(String collectionName, List<String> columnList, int order) { DBCollection coll = mongoDb.getCollection(collectionName); List<DBObject> indexes = coll.getIndexInfo(); // List of all current // indexes on collection Set<String> indexNames = new HashSet<String>(); // List of all current // index names for (DBObject index : indexes) { BasicDBObject obj = (BasicDBObject) index.get("key"); Set<String> set = obj.keySet(); // Set containing index name which // is key indexNames.addAll(set); } // Create index if not already created for (String columnName : columnList) { if (!indexNames.contains(columnName)) { KunderaCoreUtils.printQuery("Create index on:" + columnName, showQuery); coll.createIndex(new BasicDBObject(columnName, order)); } } }
From source file:com.liferay.mongodb.hook.listeners.ExpandoColumnListener.java
License:Open Source License
protected void doOnAfterRemove(ExpandoColumn expandoColumn) throws Exception { ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getTable(expandoColumn.getTableId()); DBCollection dbCollection = MongoDBUtil.getCollection(expandoTable); for (DBObject indexDBObject : dbCollection.getIndexInfo()) { DBObject keyDBObject = (DBObject) indexDBObject.get("key"); if (keyDBObject.containsField(expandoColumn.getName())) { dbCollection.dropIndex(keyDBObject); }//from w w w .j a v a2 s. co m } DBObject operatorDBObject = new BasicDBObject(MongoOperator.UNSET, new BasicDBObject(expandoColumn.getName(), 1)); dbCollection.update(new BasicDBObject(), operatorDBObject, false, true); }
From source file:com.mebigfatguy.mongobrowser.actions.ManageIndicesAction.java
License:Apache License
private List<IndexDescription> buildIndexDescriptions(DBCollection collection) { List<IndexDescription> indices = new ArrayList<IndexDescription>(); List<DBObject> dbIndices = collection.getIndexInfo(); for (DBObject dbIndex : dbIndices) { String name = (String) dbIndex.get(MongoConstants.NAME); Map<String, Integer> srcFields = (Map<String, Integer>) dbIndex.get(MongoConstants.KEY); IndexFieldList fieldSet = new IndexFieldList(); for (Map.Entry<String, Integer> entry : srcFields.entrySet()) { fieldSet.add(entry.getKey(), MongoConstants.ASCENDING.equals(entry.getValue())); }/*w w w . j ava2s.co m*/ indices.add(new IndexDescription(name, fieldSet)); } return indices; }
From source file:com.mebigfatguy.mongobrowser.dialogs.MongoTreeCellRenderer.java
License:Apache License
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { MongoTreeNode treeNode = (MongoTreeNode) value; JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); label.setHorizontalTextPosition(JLabel.RIGHT); label.setVerticalTextPosition(JLabel.CENTER); label.setIcon(null);// w w w . ja va 2 s . co m if (treeNode.getType() == Type.KeyValue) { MongoTreeNode parentTreeNode = treeNode; do { parentTreeNode = (MongoTreeNode) parentTreeNode.getParent(); } while ((parentTreeNode != null) && (parentTreeNode.getType() != Type.Collection)); if (parentTreeNode != null) { DBCollection collection = (DBCollection) parentTreeNode.getUserObject(); List<DBObject> indices = collection.getIndexInfo(); String key = ((KV) treeNode.getUserObject()).getKey(); for (DBObject index : indices) { BasicDBObject kvIndex = (BasicDBObject) index.get(MongoConstants.KEY); if (kvIndex.get(key) != null) { label.setIcon(indexIcon); break; } } } } return label; }
From source file:com.nlp.twitterstream.MongoUtil.java
License:Open Source License
/** * Get list of indexes on a collection/* w ww. j ava 2 s . c om*/ * * @param collection * @return index List<DBObject> */ public List<DBObject> getIndexList(DBCollection collection) { List<DBObject> list = collection.getIndexInfo(); return list; }