- An experimental project of database
DatabaseDriver.INSTANCE.connect(new DatabaseClient(new DatabaseData("127.0.0.1", 2139, new DatabaseUser("root", "none"))), new ConnectCallback() {
@Override
public void success(DatabaseClient databaseClient) {
System.out.println("Connected!");
}
@Override
public void error(Throwable cause) {
System.err.println("Exception thrown!");
}
});
final Collection collection = database.getCollection("test");
collection.insert(Document.parse("{\"nickname\":\"abc123\"}"));
final Collection collection = database.getCollection("test");
collection.update(new KeyData("nickname", "abc123"), Document.parse("{\"nickname\":\"cba321\"}"));
final long startTime = System.currentTimeMillis();
collection.findAsync().setFutureListener((documents) -> {
DatabaseDriver.INSTANCE.getLogger().info("Found " + documents.size() + " documents in " + (System.currentTimeMillis() - startTime) + " ms.");
});
collection.findAsync(new KeyData("nickname", "cba321")).setFutureListener((document) -> {
System.out.println("found: " + (Objects.nonNull(document) ? document.toString() : "null"));
});