Search in sources :

Example 31 with DatabaseObject

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

the class Load method main.

public static void main(String[] args) throws Exception {
    Database db = new DatabaseServer().get();
    DatabaseObject spa = db.create("SpaStreams");
    spa.load(Json.load(new File("tests/data-1.json")));
    spa.save();
    System.out.println(spa.toJson(new DefaultDatabaseObjectSerializer(2, 2)));
}
Also used : DefaultDatabaseObjectSerializer(com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer) Database(com.bluenimble.platform.db.Database) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) File(java.io.File)

Example 32 with DatabaseObject

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

the class UpdateOne2One method main.

public static void main(String[] args) throws DatabaseException {
    Database db = new DatabaseServer().get();
    DatabaseObject driver = db.get("Drivers", "722388b0-9a9a-459e-a583-d802653a60b0");
    driver.set("address", "Never Found");
    DatabaseObject car = (DatabaseObject) driver.get("car");
    car.set("model", "AlphaRomeo");
    driver.save();
    System.out.println();
    System.out.println("+===============================================================================+");
    System.out.println();
    System.out.println(driver.toJson(new DefaultDatabaseObjectSerializer(2, 2)));
}
Also used : DefaultDatabaseObjectSerializer(com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer) Database(com.bluenimble.platform.db.Database) DatabaseObject(com.bluenimble.platform.db.DatabaseObject)

Example 33 with DatabaseObject

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

the class OrientDatabase method bulk.

@Override
public JsonObject bulk(JsonObject data) throws DatabaseException {
    JsonObject result = (JsonObject) new JsonObject().set(Database.Fields.Total, 0);
    if (data == null || data.isEmpty()) {
        return result;
    }
    db.declareIntent(new OIntentMassiveInsert());
    try {
        Iterator<String> entities = data.keys();
        while (entities.hasNext()) {
            int count = 0;
            String entityName = entities.next();
            Object oRecords = data.get(entityName);
            if (!(oRecords instanceof JsonArray)) {
                continue;
            }
            JsonArray records = Json.getArray(data, entityName);
            for (int i = 0; i < records.count(); i++) {
                Object oRec = records.get(i);
                if (!(oRec instanceof JsonObject)) {
                    continue;
                }
                // TODO: Reuse object
                DatabaseObject entity = create(entityName);
                // TODO: REVIEW
                // set data
                entity.load((JsonObject) oRec);
                // put record
                entity.save();
                // clear object
                entity.clear();
                count++;
            }
            result.set(entityName, count);
            result.set(Database.Fields.Total, Json.getInteger(result, Database.Fields.Total, 0) + count);
        }
    } finally {
        db.declareIntent(null);
    }
    return result;
}
Also used : JsonArray(com.bluenimble.platform.json.JsonArray) JsonObject(com.bluenimble.platform.json.JsonObject) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) JsonObject(com.bluenimble.platform.json.JsonObject) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert)

Example 34 with DatabaseObject

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

the class Find method main.

public static void main(String[] args) throws DatabaseException {
    Database db = new DatabaseServer().get();
    final JsonArray records = new JsonArray();
    JsonObject result = (JsonObject) new JsonObject().set("records", records);
    db.find("Cities", new JsonQuery(new JsonObject()), new Database.Visitor() {

        @Override
        public boolean onRecord(DatabaseObject dbo) {
            try {
                dbo.set("org", "Labs");
                dbo.save();
            } catch (Exception ex) {
                throw new RuntimeException(ex.getMessage(), ex);
            }
            records.add(dbo.toJson(null));
            return false;
        }

        @Override
        public boolean optimize() {
            return true;
        }
    });
    System.out.println(result);
}
Also used : JsonArray(com.bluenimble.platform.json.JsonArray) JsonQuery(com.bluenimble.platform.db.query.impls.JsonQuery) Database(com.bluenimble.platform.db.Database) JsonObject(com.bluenimble.platform.json.JsonObject) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) DatabaseException(com.bluenimble.platform.db.DatabaseException)

Example 35 with DatabaseObject

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

the class FindOne method main.

public static void main(String[] args) throws DatabaseException {
    Database db = new DatabaseServer().get();
    DatabaseObject city = db.findOne("Cities", new JsonQuery(new JsonObject()));
    System.out.println(city.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)

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