use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class OrientDatabasePlugin method createPool.
private OPartitionedDatabasePool createPool(String name, ApiSpace space, JsonObject spec) {
String factoryKey = createFactoryKey(name, space);
if (space.containsRecyclable(factoryKey)) {
return null;
}
JsonObject auth = Json.getObject(spec, Spec.Auth);
if (Json.isNullOrEmpty(auth)) {
return null;
}
OPartitionedDatabasePool pool = new OPartitionedDatabasePool(createUrl(spec), Json.getString(auth, Spec.User), Json.getString(auth, Spec.Password), weight, weight);
space.addRecyclable(factoryKey, new RecyclablePool(pool));
return pool;
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class DatabaseObjectImpl method toJson.
@SuppressWarnings({ "unchecked", "rawtypes" })
private JsonObject toJson(DatabaseObjectImpl dbo, DatabaseObjectSerializer serializer, int level) {
if (serializer == null) {
serializer = DatabaseObjectSerializer.Default;
}
String entity = dbo.entity();
Fields fields = serializer.fields(level);
if (fields == null || Fields.None.equals(fields)) {
return null;
}
String[] fieldNames = null;
if (Fields.All.equals(fields)) {
fieldNames = dbo.document.fieldNames();
} else {
fieldNames = MinimalFields;
}
JsonObject json = serializer.create(entity, level);
if (json == null) {
return null;
}
for (String f : fieldNames) {
Object v = dbo.get(f);
if (v == null) {
continue;
}
if (v instanceof Date) {
v = Lang.toUTC((Date) v);
} else if (v instanceof Map) {
v = new JsonObject((Map<String, Object>) v, true);
} else if (v instanceof List) {
List<Object> list = (List<Object>) v;
if (list.isEmpty()) {
continue;
}
JsonArray arr = new JsonArray();
for (Object o : list) {
if (o == null) {
continue;
}
if (o instanceof DatabaseObjectImpl) {
arr.add(toJson((DatabaseObjectImpl) o, serializer, level + 1));
} else {
if (o instanceof Date) {
arr.add(Lang.toUTC((Date) o));
} else if (Map.class.isAssignableFrom(o.getClass())) {
arr.add(new JsonObject((Map) o, true));
} else {
arr.add(o);
}
}
}
v = arr;
} else if (v instanceof DatabaseObjectImpl) {
v = toJson((DatabaseObjectImpl) v, serializer, level + 1);
}
serializer.set(entity, json, f, v);
}
return json;
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class DatabaseObjectImpl method load.
@Override
public void load(JsonObject data) throws DatabaseException {
if (data == null) {
return;
}
data.shrink();
if (Json.isNullOrEmpty(data)) {
return;
}
Iterator<String> keys = data.keys();
while (keys.hasNext()) {
String key = keys.next();
Object value = data.get(key);
if (value == null || value.equals(Null) || Undefined.class.equals(value.getClass())) {
document.removeField(key);
continue;
}
set(key, data.get(key));
}
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class Update method main.
public static void main(String[] args) throws DatabaseException {
Database db = new DatabaseServer().get();
DatabaseObject employee = db.get("Employees", "e0e296f0-1937-4b7c-b077-1d7fe50e2482");
employee.set("age", 43);
employee.set("salary", 200.54);
employee.set("contact", new JsonObject().set("phone", "4089786532").set("email", "alpha@beta.com"));
DatabaseObject city = db.create("Cities");
city.set("name", "Sunnyvale");
employee.set("city", city);
employee.save();
System.out.println(employee.toJson(new DefaultDatabaseObjectSerializer(2, 2)));
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class DataSourcePlugin method createDataSources.
private void createDataSources(ApiSpace space) throws PluginRegistryException {
// create factories
JsonObject dbFeature = Json.getObject(space.getFeatures(), feature);
if (dbFeature == null || dbFeature.isEmpty()) {
return;
}
Iterator<String> keys = dbFeature.keys();
while (keys.hasNext()) {
String key = keys.next();
JsonObject source = Json.getObject(dbFeature, key);
if (!this.getName().equalsIgnoreCase(Json.getString(source, ApiSpace.Features.Provider))) {
continue;
}
JsonObject spec = Json.getObject(source, ApiSpace.Features.Spec);
if (spec == null) {
continue;
}
createDataSource(key, space, spec);
}
}
Aggregations