Create and Update API
save
Saves the entity passed as input to the database
DSApi.save(String className, Object entity)
or
DSApi.save(String className, Object entity, String auditMsg)
Parameters
className: the name of class as created using the workbench
(correspond to the table)
entity:
auditMsg:
Sample Code
String className = "shared.common.product";
Map<String, Object> entity = new HashMap<>();
entity.put("productName", "table");
entity.put("description", "foldable table");
entity.put("prices", 620);
Object res = DSApi.save(className, entity);
Returns
If the object is found then it return a Java Map,
else Result with failed status and message.
saveMany
Saves the list of entities to the database
DSApi.saveMany(String className, Iterable<Object> entities)
or
DSApi.saveMany(String className, Iterable<Object> entities, String auditMsg)
Parameters
className: the name of class as created using the workbench
(correspond to the table)
entity:
Sample Code
String className = "shared.common.product";
ArrayList<Map<String, Object>> entities = new ArrayList<>();
Map<String, Object> entity = new HashMap<>();
entity.put("productName", "table");
entity.put("description", "foldable table");
entity.put("price", 620);
entities.add(entity);
Object res = DSApi.save(className, entities);
Returns
If the object is found then it return a Java Map,
else Result with failed status and message.
Update
Updates the attribute name with the provided value
DSApi.update(String className, String id, String attrName, Object value)
or
DSApi.update(String className, String id, String attrName, Object value, String auditMsg)
Parameters
className: the name of class as created using the workbench
(correspond to the table)
id:
attrName:
value:
auditMsg:
Sample Code
String className = "shared.common.product";
String id = "12";
String attrName = "price";
Integer value = 700;
Object res = DSApi.update(className, id, attrName, value);
Returns
UpdateMany
Update many records at a time. The class name is provided that indirectly represents a table. β
DSApi.updateMany(String className, List<String> ids, String attrName, Object value)
or
DSApi.updateMany(String className, List<String> ids, String attrName, Object value, String auditMsg)
Parameters
className: the name of class as created using the workbench
(correspond to the table)
ids: rows needed to be modified
attrName: the name of the column
value: the value of inside the column for the specific row
auditMsg: any informational message
Sample Code
String className = "shared.common.product";
List<String> ids = new ArrayList<>();
ids.add("12");
ids.add("15");
String attrName = "price";
Integer value = 700;
Object res = DSApi.updateMany(className, ids, attrName, value);
Returns
UpdateByQuery
Update by executing a query on the table. βit takes partial query which is the embellished with where clauses.
DSApi.updateByQuery(String className, String query, Map<String, Object> updateAttrs)
or
DSApi.updateByQuery(String className, String query, Map<String, Object> updateAttrs, String auditMsg)
Parameters
className: the name of class as created using the workbench
(correspond to the table)
query: represents the filtering criteria
updateAttrs: update map for the attributes
auditMsg: informational message
Sample Code
String className = "shared.common.product";
Map<String, Object> updateParam = new HashMap<>();
updateParam.put("deleted", true);
Object res = DSApi.updateByQuery(className, "", updateParam);
Returns
executeSqlWriteStatement
Execute a stored procedure or SQL string. The statement is prepared for execution.β Use this method when you're specifying the full statement.
DSApi.executeSqlWriteStatement(String dsName, String sqlStatement,
Map<String, Object> params)
Parameters
dsName: the name of the data source
sqlStatement: SQL String
params: parameter values to be replaced inside the string
Returns
Success or Failed depending on the execution status of the statement
Last updated
Was this helpful?