use of fr.romitou.mongosk.elements.MongoSKDatabase in project MongoSK by Romitou.
the class ExprAllMongoDatabases method get.
@Override
protected MongoSKDatabase[] get(@Nonnull final Event e) {
MongoSKServer mongoSKServer = exprMongoSKServer.getSingle(e);
if (mongoSKServer == null)
return new MongoSKDatabase[0];
SubscriberHelpers.ObservableSubscriber<Document> observableSubscriber = new SubscriberHelpers.OperationSubscriber<>();
mongoSKServer.getMongoClient().listDatabases().subscribe(observableSubscriber);
return observableSubscriber.get().stream().map(doc -> doc.getString("name")).map(name -> mongoSKServer.getMongoClient().getDatabase(name)).map(MongoSKDatabase::new).toArray(MongoSKDatabase[]::new);
}
use of fr.romitou.mongosk.elements.MongoSKDatabase in project MongoSK by Romitou.
the class ExprMongoCommandResult method get.
@Override
protected MongoSKDocument[] get(@Nonnull Event e) {
String jsonString = exprJsonString.getSingle(e);
MongoSKDatabase mongoSKDatabase = exprMongoSKDatabase.getSingle(e);
if (mongoSKDatabase == null)
return new MongoSKDocument[0];
SubscriberHelpers.ObservableSubscriber<Document> documentObservableSubscriber = new SubscriberHelpers.OperationSubscriber<>();
try {
mongoSKDatabase.getMongoDatabase().runCommand(Document.parse(jsonString).toBsonDocument()).subscribe(documentObservableSubscriber);
} catch (BSONException | JsonParseException ex) {
LoggerHelper.severe("An error occurred when changing the document's JSON: " + ex.getMessage(), "Provided JSON: " + jsonString, "Please check its validity on https://jsonlint.com.");
}
// Nobody has subscribed. :(
if (documentObservableSubscriber.getSubscription() == null)
return new MongoSKDocument[0];
return documentObservableSubscriber.get().stream().map(MongoSKDocument::new).toArray(MongoSKDocument[]::new);
}
use of fr.romitou.mongosk.elements.MongoSKDatabase in project MongoSK by Romitou.
the class ExprMongoCollection method get.
@Override
protected MongoSKCollection[] get(@Nonnull final Event e) {
String collectionName = exprCollectionName.getSingle(e);
MongoSKDatabase mongoSKDatabase = exprMongoSKDatabase.getSingle(e);
if (collectionName == null || mongoSKDatabase == null)
return new MongoSKCollection[0];
MongoCollection<Document> mongoCollection = mongoSKDatabase.getMongoDatabase().getCollection(collectionName);
if (mongoCollection == null)
return new MongoSKCollection[0];
return new MongoSKCollection[] { new MongoSKCollection(mongoCollection) };
}
use of fr.romitou.mongosk.elements.MongoSKDatabase in project MongoSK by Romitou.
the class ExprMongoDatabase method get.
@Override
protected MongoSKDatabase[] get(@Nonnull final Event e) {
String databaseName = exprDatabaseName.getSingle(e);
MongoSKServer mongoSKServer = exprMongoSKServer.getSingle(e);
if (databaseName == null || mongoSKServer == null)
return new MongoSKDatabase[0];
MongoDatabase mongoDatabase = mongoSKServer.getMongoClient().getDatabase(databaseName);
if (mongoDatabase == null)
return new MongoSKDatabase[0];
return new MongoSKDatabase[] { new MongoSKDatabase(mongoDatabase) };
}
use of fr.romitou.mongosk.elements.MongoSKDatabase in project MongoSK by Romitou.
the class EffCreateMongoCollection method execute.
@Override
protected void execute(@Nonnull Event e) {
String databaseName = exprCollectionName.getSingle(e);
MongoSKDatabase mongoSKDatabase = exprMongoSKDatabase.getSingle(e);
if (databaseName == null || mongoSKDatabase == null)
return;
SubscriberHelpers.ObservableSubscriber<Void> voidSubscriber = new SubscriberHelpers.OperationSubscriber<>();
mongoSKDatabase.getMongoDatabase().createCollection(databaseName).subscribe(voidSubscriber);
voidSubscriber.await();
}
Aggregations