Search in sources :

Example 16 with DatabaseObject

use of com.bluenimble.platform.db.DatabaseObject in project serverless by bluenimble.

the class FindLike method main.

public static void main(String[] args) throws Exception {
    String query = "{ where: { name: { op: like, value: m } } }";
    Database db = new DatabaseServer().get();
    List<DatabaseObject> employees = db.find("Employees", new JsonQuery(new JsonObject(query)), null);
    for (DatabaseObject employee : employees) {
        System.out.println(employee.toJson(new DefaultDatabaseObjectSerializer(2, 2)));
    }
}
Also used : JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) DefaultDatabaseObjectSerializer(com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer) Database(com.bluenimble.platform.db.Database) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) JsonObject(com.bluenimble.platform.json.JsonObject)

Example 17 with DatabaseObject

use of com.bluenimble.platform.db.DatabaseObject in project serverless by bluenimble.

the class FindNotLike method main.

public static void main(String[] args) throws Exception {
    String query = "{ where: { name: { op: nlike, value: m } } }";
    Database db = new DatabaseServer().get();
    List<DatabaseObject> employees = db.find("Employees", new JsonQuery(new JsonObject(query)), null);
    for (DatabaseObject employee : employees) {
        System.out.println(employee.toJson(new DefaultDatabaseObjectSerializer(2, 2)));
    }
}
Also used : JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) DefaultDatabaseObjectSerializer(com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer) Database(com.bluenimble.platform.db.Database) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) JsonObject(com.bluenimble.platform.json.JsonObject)

Example 18 with DatabaseObject

use of com.bluenimble.platform.db.DatabaseObject in project serverless by bluenimble.

the class Create method main.

public static void main(String[] args) throws DatabaseException {
    Database db = new DatabaseServer().get();
    DatabaseObject employee = db.create("Employees");
    JsonArray names = new JsonArray();
    names.add(new JsonObject().set("number", "4098776623").set("weight", 40));
    employee.set("name", "New-1");
    employee.set("age", 27);
    employee.set("active", true);
    employee.set("salary", 48.50);
    employee.set("names", names);
    employee.save();
    System.out.println(employee.toJson(null));
}
Also used : JsonArray(com.bluenimble.platform.json.JsonArray) Database(com.bluenimble.platform.db.Database) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) JsonObject(com.bluenimble.platform.json.JsonObject)

Example 19 with DatabaseObject

use of com.bluenimble.platform.db.DatabaseObject in project serverless by bluenimble.

the class CreateOne2One method main.

public static void main(String[] args) throws DatabaseException {
    Database db = new DatabaseServer().get();
    // create driver
    DatabaseObject driver = db.create("Drivers");
    driver.set("name", "One2One-New-2");
    driver.set("info", new JsonObject().set("x", "40987").set("y", 76623));
    driver.set("salary", 48.50);
    // create car
    DatabaseObject car = db.create("Cars");
    car.set("model", "Honda");
    car.set("year", "2040");
    driver.set("car", car);
    driver.save();
    System.out.println(driver.toJson(null));
}
Also used : Database(com.bluenimble.platform.db.Database) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) JsonObject(com.bluenimble.platform.json.JsonObject)

Example 20 with DatabaseObject

use of com.bluenimble.platform.db.DatabaseObject in project serverless by bluenimble.

the class DatabaseObjectImpl method save.

@Override
public void save() throws DatabaseException {
    // if no changes to persistent object
    if (persistent && (update == null || update.isEmpty())) {
        return;
    }
    // save refs first
    if (refs != null) {
        for (String ref : refs) {
            DatabaseObject refObject = ((DatabaseObject) get(ref));
            refObject.save();
            Document dRef = new Document().append(ObjectEntityKey, refObject.entity()).append(ObjectIdKey, refObject.getId());
            if (persistent) {
                markForUpdate(ref, dRef);
            } else {
                document.append(ref, dRef);
            }
        }
    }
    // save
    if (persistent) {
        if (update != null && !update.isEmpty()) {
            db.getInternal().getCollection(entity).updateOne(eq(ObjectIdKey, getId()), update);
            update.clear();
        }
    } else {
        db.getInternal().getCollection(entity).insertOne(document);
        persistent = true;
    }
    // restore 1-1 refs
    if (refs != null) {
        for (String ref : refs) {
            DatabaseObject refObject = ((DatabaseObject) get(ref));
            document.append(ref, refObject);
        }
    }
}
Also used : DatabaseObject(com.bluenimble.platform.db.DatabaseObject) Document(org.bson.Document)

Aggregations

DatabaseObject (com.bluenimble.platform.db.DatabaseObject)42 Database (com.bluenimble.platform.db.Database)37 JsonObject (com.bluenimble.platform.json.JsonObject)29 DefaultDatabaseObjectSerializer (com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer)20 JsonQuery (com.bluenimble.platform.db.query.impls.JsonQuery)16 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)9 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)9 DatabaseException (com.bluenimble.platform.db.DatabaseException)6 JsonArray (com.bluenimble.platform.json.JsonArray)6 ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)4 ApiOutput (com.bluenimble.platform.api.ApiOutput)4 ApiSpace (com.bluenimble.platform.api.ApiSpace)4 Date (java.util.Date)4 HashMap (java.util.HashMap)3 Config (com.bluenimble.platform.api.impls.im.LoginServiceSpi.Config)2 ApiAuthenticationException (com.bluenimble.platform.api.security.ApiAuthenticationException)2 Messenger (com.bluenimble.platform.messaging.Messenger)2 JsonRecipient (com.bluenimble.platform.messaging.impls.JsonRecipient)2 JsonSender (com.bluenimble.platform.messaging.impls.JsonSender)2 OIntentMassiveInsert (com.orientechnologies.orient.core.intent.OIntentMassiveInsert)1