use of com.mongodb.DBCollection in project cas by apereo.
the class MongoDbTicketRegistry method getTicketCollectionInstance.
private DBCollection getTicketCollectionInstance(final String mapName) {
try {
final DBCollection inst = this.mongoTemplate.getCollection(mapName);
LOGGER.debug("Located MongoDb collection instance [{}]", mapName);
return inst;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
use of com.mongodb.DBCollection in project vcell by virtualcell.
the class ServerManageConsole method getQueryResultTable.
/**
* Return the QueryResultTable property value.
* @return cbit.vcell.messaging.admin.sorttable.JSortTable
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private JSortTable getQueryResultTable() {
if (ivjQueryResultTable == null) {
try {
ivjQueryResultTable = new JSortTable();
ivjQueryResultTable.setName("QueryResultTable");
ivjQueryResultTable.setModel(new JobTableModel());
ivjQueryResultTable.disableUneditableForeground();
final JPopupMenu popup = new JPopupMenu();
JMenuItem viewMongoMenuItem = new JMenuItem("View Mongo Log Info...");
popup.add(viewMongoMenuItem);
viewMongoMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Number simID = (Number) ivjQueryResultTable.getModel().getValueAt(ivjQueryResultTable.getSelectedRow(), JobTableModel.columnIndex_SimID);
String userid = (String) ivjQueryResultTable.getModel().getValueAt(ivjQueryResultTable.getSelectedRow(), JobTableModel.columnIndex_UserID);
System.out.println("----- user=" + userid + " simID=" + simID);
String mongoDbHost = PropertyLoader.getRequiredProperty(PropertyLoader.mongodbHostInternal);
// default 27017
int mongoDbPort = Integer.parseInt(PropertyLoader.getRequiredProperty(PropertyLoader.mongodbPortInternal));
Mongo m = new Mongo(mongoDbHost, mongoDbPort);
String mongoDbDatabaseName = PropertyLoader.getRequiredProperty(PropertyLoader.mongodbDatabase);
DB db = m.getDB(mongoDbDatabaseName);
String mongoDbLoggingCollectionName = PropertyLoader.getRequiredProperty(PropertyLoader.mongodbLoggingCollection);
DBCollection dbCollection = db.getCollection(mongoDbLoggingCollectionName);
BasicDBObject query = new BasicDBObject();
query.put(VCMongoMessage.MongoMessage_simId, simID.intValue() + "");
DBCursor cur = dbCollection.find(query);
TreeMap<String, Integer> mapKeyToColumnIndex = new TreeMap<String, Integer>();
Vector<DBObject> dbObjV = new Vector<DBObject>();
while (cur.hasNext()) {
DBObject dbObject = cur.next();
dbObjV.add(dbObject);
Set<String> keys = dbObject.keySet();
Iterator<String> iter = keys.iterator();
while (iter.hasNext()) {
String key = iter.next();
Integer columnIndex = mapKeyToColumnIndex.get(key);
if (columnIndex == null) {
columnIndex = mapKeyToColumnIndex.size();
mapKeyToColumnIndex.put(key, columnIndex);
}
}
}
int msgTimeColumnIndex = -1;
if (mapKeyToColumnIndex.size() > 0) {
String[] columnNames = new String[mapKeyToColumnIndex.size()];
Iterator<String> keyIter = mapKeyToColumnIndex.keySet().iterator();
while (keyIter.hasNext()) {
String key = keyIter.next();
int columnIndex = mapKeyToColumnIndex.get(key);
columnNames[columnIndex] = key;
if (key.equals(VCMongoMessage.MongoMessage_msgTime)) {
msgTimeColumnIndex = columnIndex;
}
}
// //Ask which columns to view
// Object[][] colrowdata = new Object[columnNames.length][1];
// for (int i = 0; i < colrowdata.length; i++) {
// colrowdata[i][0] = columnNames[i];
// }
// int[] showcolArr =
// DialogUtils.showComponentOKCancelTableList(ServerManageConsole.this, "Select Columns to View...", new String[] {"Column Names"}, colrowdata, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
Object[][] rowData = new Object[dbObjV.size()][columnNames.length];
for (int i = 0; i < rowData.length; i++) {
DBObject dbObj = dbObjV.get(i);
Set<String> keys = dbObj.keySet();
Iterator<String> iter = keys.iterator();
while (iter.hasNext()) {
String key = iter.next();
rowData[i][mapKeyToColumnIndex.get(key)] = dbObj.get(key);
}
}
// sort by msgtime
final int msgTimeColumnIndexFinal = msgTimeColumnIndex;
if (msgTimeColumnIndex != -1) {
Arrays.sort(rowData, new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
Long o1Long = (Long) o1[msgTimeColumnIndexFinal];
Long o2Long = (Long) o2[msgTimeColumnIndexFinal];
int result = (int) (o2Long - o1Long);
return result;
}
});
}
DialogUtils.showComponentOptionsTableList(ServerManageConsole.this, "Mongo Log Info (" + rowData.length + ") " + userid + " " + simID, columnNames, rowData, ListSelectionModel.SINGLE_SELECTION, null, null, null, null, false);
} else {
DialogUtils.showWarningDialog(ServerManageConsole.this, "No Mongo Log Info found for simID=" + simID.intValue());
}
} catch (UserCancelException uce) {
// ignore
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
ivjQueryResultTable.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
JTable source = (JTable) e.getSource();
int row = source.rowAtPoint(e.getPoint());
int column = source.columnAtPoint(e.getPoint());
if (!source.isRowSelected(row))
source.changeSelection(row, column, false, false);
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjQueryResultTable;
}
use of com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVMaintenance method doFindUnreferencedDocuments.
private long[] doFindUnreferencedDocuments(String collection, long expiry, TimeUnit unit) {
long maxTime = getMaxTime(expiry, unit);
//fetch the OIDs of all documents older than the expiry time
DBCollection collDocs = _db.getDB().getCollection(collection);
DBCursor docs = collDocs.find(new BasicDBObject(MongoDBConstants.TIMESTAMP, //also include docs without a timestamp
new BasicDBObject("$not", new BasicDBObject("$gte", maxTime))), new BasicDBObject(MongoDBConstants.ID, 1));
IdSet oids = new IdHashSet(docs.count());
for (DBObject o : docs) {
oids.add((Long) o.get(MongoDBConstants.ID));
}
//iterate through all commits and eliminate referenced documents
DBCollection collCommits = _db.getDB().getCollection(MongoDBConstants.COLLECTION_COMMITS);
for (DBObject o : collCommits.find()) {
Commit c = Tree.deserializeCommit(o);
Map<String, IdMap> allObjs = c.getObjects();
IdMap objs = allObjs.get(collection);
if (objs != null) {
//eliminate OIDs referenced by this commit
IdMapIterator mi = objs.iterator();
while (mi.hasNext()) {
mi.advance();
oids.remove(mi.value());
}
}
}
//the remaining OIDs must be the unreferenced ones
return oids.toArray();
}
use of com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVBranch method commit.
@Override
public long commit() {
Index idx = getIndex();
//clone dirty objects because we clear them below
Map<String, IdMap> dos = new HashMap<String, IdMap>(idx.getDirtyObjects());
Commit head = getHeadCommit();
Commit c = new Commit(_db.getCounter().getNextId(), head.getCID(), _rootCid, dos);
_tree.addCommit(c);
updateHead(c);
//mark deleted objects as deleted in the database
DB db = _db.getDB();
String lifetimeAttr = MongoDBConstants.LIFETIME + "." + getRootCid();
for (Map.Entry<String, IdSet> e : idx.getDeletedOids().entrySet()) {
DBCollection dbc = db.getCollection(e.getKey());
IdSetIterator li = e.getValue().iterator();
while (li.hasNext()) {
long oid = li.next();
//save the CID of the commit where the object has been deleted
dbc.update(new BasicDBObject(MongoDBConstants.ID, oid), new BasicDBObject("$set", new BasicDBObject(lifetimeAttr, head.getCID())));
}
}
//mark dirty objects as inserted
String instimeAttr = MongoDBConstants.LIFETIME + ".i" + getRootCid();
for (Map.Entry<String, IdMap> e : dos.entrySet()) {
DBCollection dbc = db.getCollection(e.getKey());
IdMap m = e.getValue();
IdMapIterator li = m.iterator();
while (li.hasNext()) {
li.advance();
long oid = li.value();
if (oid == -1) {
//do not save time of insertion
continue;
}
//save the CID of the commit where the object has been inserted
dbc.update(new BasicDBObject(MongoDBConstants.ID, oid), new BasicDBObject("$set", new BasicDBObject(instimeAttr, head.getCID())));
}
}
//reset index
idx.clearDirtyObjects();
//update named branch's head
if (_name != null) {
//and then update it
synchronized (this) {
//check for conflicts (i.e. if another thread has already updated the branch's head)
if (_tree.resolveBranch(_name).getCID() != c.getParentCID()) {
throw new VException("Branch " + _name + " has already been " + "updated by another commit");
}
_tree.updateBranchHead(_name, c.getCID());
}
}
return c.getCID();
}
use of com.mongodb.DBCollection in project meclipse by flaper87.
the class Filter method getCollection.
@Override
public DBCollection getCollection() {
TreeParent treeObj = getParent();
while (!(treeObj instanceof Collection)) treeObj = treeObj.getParent();
Collection coll = (Collection) treeObj;
return coll.getCollection();
}
Aggregations