use of com.mongodb.MongoException in project spring-cloud-connectors by spring-cloud.
the class MongoDbFactoryCreator method create.
@Override
public MongoDbFactory create(MongoServiceInfo serviceInfo, ServiceConnectorConfig config) {
try {
MongoClientOptions.Builder mongoOptionsToUse = getMongoOptions((MongoDbFactoryConfig) config);
SimpleMongoDbFactory mongoDbFactory = createMongoDbFactory(serviceInfo, mongoOptionsToUse);
return configure(mongoDbFactory, (MongoDbFactoryConfig) config);
} catch (UnknownHostException e) {
throw new ServiceConnectorCreationException(e);
} catch (MongoException e) {
throw new ServiceConnectorCreationException(e);
}
}
use of com.mongodb.MongoException in project meclipse by flaper87.
the class Collection method makeActions.
private void makeActions() {
insert = new Action(getCaption("collection.insertDoc")) {
@Override
public void run() {
FileDialog dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
dialog.setFilterExtensions(new String[] { "*.json" });
String result = dialog.open();
if (result != null) {
try {
String jsonText = IOUtils.readFile(new File(result));
JSONObject jsonObj = new JSONObject(jsonText);
col.insert(JSONUtils.toDBObject(jsonObj));
} catch (Exception ex) {
UIUtils.openErrorDialog(view.getSite().getShell(), ex.toString());
}
}
}
};
rename = new Action(getCaption("collection.renameColl")) {
@Override
public void run() {
InputDialog dialog = new InputDialog(view.getSite().getShell(), getCaption("collection.renameColl"), getCaption("collection.msg.newCollName"), col.getName(), new RequiredInputValidator(getCaption("collection.msg.inputCollName")));
if (dialog.open() == InputDialog.OK) {
try {
col.rename(dialog.getValue());
} catch (MongoException ex) {
UIUtils.openErrorDialog(view.getSite().getShell(), ex.toString());
}
view.getViewer().refresh(getParent());
}
}
};
delete = new Action(getCaption("collection.deleteColl")) {
@Override
public void run() {
if (MessageDialog.openConfirm(view.getSite().getShell(), getCaption("confirm"), String.format(getCaption("collection.msg.reallyDeleteColl"), col.getName()))) {
col.drop();
view.getViewer().refresh(getParent());
}
}
};
}
use of com.mongodb.MongoException in project meclipse by flaper87.
the class Connection method getMongo.
// public TreeObject [] getChildren() {
// loadDatabases();
// return super.getChildren();
// }
/**
* In the style of lazy-loading, this is where we actually initiate the
* connection to a MongoDB instance - and this is where a user would 1st
* request to see data obtained via the connection.
*
* @return
*/
public Mongo getMongo() {
MongoInstance mongoInstance = MeclipsePlugin.getDefault().getMongoInstance(this.getName());
Exception ex;
if (mongoInstance.getMongo() == null) {
Mongo mongo;
try {
mongo = new Mongo(mongoInstance.getHost(), mongoInstance.getPort());
mongo.getDatabaseNames();
// add the active Mongo instance
mongoInstance.setMongo(mongo);
// to the plug-in's state
isDown = false;
return mongo;
/* catch some possible exceptions */
} catch (MongoException e) {
ex = e;
} catch (UnknownHostException e) {
ex = e;
}
if (!isDown) {
this.showMessage(String.format(getCaption("connection.connectionError"), this.getName(), mongoInstance.getHost(), ex));
isDown = true;
}
return null;
} else {
return mongoInstance.getMongo();
}
}
use of com.mongodb.MongoException in project GNS by MobilityFirst.
the class MongoRecords method contains.
@Override
public boolean contains(String collectionName, String guid) throws FailedDBOperationException {
db.requestStart();
try {
String primaryKey = mongoCollectionSpecs.getCollectionSpec(collectionName).getPrimaryKey().getName();
db.requestEnsureConnection();
DBCollection collection = db.getCollection(collectionName);
BasicDBObject query = new BasicDBObject(primaryKey, guid);
DBCursor cursor = collection.find(query);
return cursor.hasNext();
} catch (MongoException e) {
DatabaseConfig.getLogger().log(Level.FINE, "{0} contains failed: {1}", new Object[] { dbName, e.getMessage() });
throw new FailedDBOperationException(collectionName, guid, "Original mongo exception:" + e.getMessage());
} finally {
db.requestDone();
}
}
use of com.mongodb.MongoException in project GNS by MobilityFirst.
the class MongoRecords method lookupEntireRecord.
private JSONObject lookupEntireRecord(String collectionName, String guid, boolean explain) throws RecordNotFoundException, FailedDBOperationException {
long startTime = System.currentTimeMillis();
db.requestStart();
try {
String primaryKey = mongoCollectionSpecs.getCollectionSpec(collectionName).getPrimaryKey().getName();
db.requestEnsureConnection();
DBCollection collection = db.getCollection(collectionName);
BasicDBObject query = new BasicDBObject(primaryKey, guid);
DBCursor cursor = collection.find(query);
if (explain) {
System.out.println(cursor.explain().toString());
}
if (cursor.hasNext()) {
DBObject obj = cursor.next();
// arun: optimized for the common case of Map
@SuppressWarnings("unchecked") JSONObject json = obj instanceof Map ? DiskMapRecords.recursiveCopyMap((Map<String, ?>) obj) : new JSONObject(obj.toString());
// instrumentation
DelayProfiler.updateDelay("lookupEntireRecord", startTime);
// older style
int lookupTime = (int) (System.currentTimeMillis() - startTime);
if (lookupTime > 20) {
DatabaseConfig.getLogger().log(Level.FINE, "{0} mongoLookup Long delay {1}", new Object[] { dbName, lookupTime });
}
return json;
} else {
throw new RecordNotFoundException(guid);
}
} catch (JSONException e) {
DatabaseConfig.getLogger().log(Level.WARNING, "{0} Unable to parse JSON: {1}", new Object[] { dbName, e.getMessage() });
return null;
} catch (MongoException e) {
DatabaseConfig.getLogger().log(Level.FINE, "{0} lookupEntireRecord failed: {1}", new Object[] { dbName, e.getMessage() });
throw new FailedDBOperationException(collectionName, guid, "Original mongo exception:" + e.getMessage());
} finally {
db.requestDone();
}
}
Aggregations