use of com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer 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)));
}
}
use of com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer 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)));
}
}
use of com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer in project serverless by bluenimble.
the class QueryEntitySpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String sEntity = (String) request.get(CommonSpec.Entity);
String serializer = (String) request.get(CommonSpec.Serializer);
String[] levels = Lang.split(serializer, Lang.COMMA);
int allStopLevel = 2;
if (levels != null && levels.length > 0) {
try {
allStopLevel = Integer.valueOf(levels[0]);
} catch (Exception ex) {
}
}
int minStopLevel = 3;
if (levels != null && levels.length > 0) {
try {
minStopLevel = Integer.valueOf(levels[1]);
} catch (Exception ex) {
}
}
JsonObject payload = (JsonObject) request.get(ApiRequest.Payload);
payload.set(Database.Fields.Entity, sEntity);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
List<DatabaseObject> records = null;
try {
Database db = space.feature(Database.class, provider, request);
records = db.find(null, new JsonQuery(payload), null);
} catch (DatabaseException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
JsonObject result = new JsonObject();
JsonArray aRecords = new JsonArray();
result.set(Output.Records, aRecords);
if (records == null || records.isEmpty()) {
return new JsonApiOutput(result);
}
for (int i = 0; i < records.size(); i++) {
aRecords.add(records.get(i).toJson(new DefaultDatabaseObjectSerializer(allStopLevel, minStopLevel)));
}
return new JsonApiOutput(result);
}
use of com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer in project serverless by bluenimble.
the class FindOne2One method main.
public static void main(String[] args) throws Exception {
String query = "{ }";
Database db = new DatabaseServer().get();
List<DatabaseObject> drivers = db.find("Drivers", new JsonQuery(new JsonObject(query)), null);
for (DatabaseObject driver : drivers) {
System.out.println(driver.toJson(new DefaultDatabaseObjectSerializer(2, 2)));
}
}
use of com.bluenimble.platform.db.impls.DefaultDatabaseObjectSerializer in project serverless by bluenimble.
the class Get method main.
public static void main(String[] args) throws DatabaseException {
Database db = new DatabaseServer().get();
DatabaseObject employee = db.get("Employees", "5aa4192e5e6726413c7db45a");
System.out.println(employee.toJson(new DefaultDatabaseObjectSerializer(2, 2)));
}
Aggregations