This page describes different Java APIs to retrieve a record (also referred to as object) by primary key, queries.
In the following APIs description when the Result class object is returned, buy default it means the result of failed API invocation. If the Result returns success, it will be noted.
Get
Gets an object of the given class by its primary key (id).
DSApi.get(String className, String id)
Parameters
className: the name of class as created using the workbench
(correspond to the table)
id: primary key (pass stringified value of the BigInteger/ long value)
Sample Code
//fetch product information from the product table String className ="shared.common.product";String id ="12";Object res =DSApi.get(className, id);
Returns
If the object is found then it return a Java Map,
else Result with failed status and message.
queryOne - whereClause (includeDeleted)
Gets an object of the given class by the condition provided in the where clause (constructed with the columns of the same table. For complex SQL queries, use the API with SQL query as a parameter). If multiple are found then the first is returned.
className: the name of class as created using the workbench
(correspond to the table)
whereClause: where-clause of the SQL query.
includeDeleted: consider records marked deleted if a value of 'true is passed.
Sample Code
//fetch one product information from the product table using where filterString className ="shared.common.product";String whereClause ="prices is not null";Boolean includeDeleted =true;Object res =DSApi.queryOne(className, whereClause);Object res2 =DSApi.queryOne(className, whereClause, includeDeleted);
Returns
If the object is found then it return a Java Map,
else Result.
queryOne - sqlQuery
Gets an object using SQL query. If multiple are found then the first is returned.
DSApi.queryOne(String sqlQuery)
Parameters
sqlQuery: SQL statement. In an SQL statement, actual table name is specified
(it is typically <className>_tbl). When in doubt, check it using the workbench
API.
Sample Code
//fetch top 1 product information from the product table using queryString sqlQuery ="Select id, prices from product_tbl where prices is not null";Object res2 =DSApi.queryOne(String sqlQuery)
Returns
If the object is found then it return a Java Map,
else Result.
queryMany - whereClause (includeDeleted)
Gets all objects of the given class by the condition provided in the where clause.
className: the name of class as created using the workbench
(correspond to the table)
whereClause: where-clause of the SQL query.
includeDeleted: consider records marked deleted if a value of 'true is passed.
Sample Code
//fetch all product information from the product table using queryString className ="shared.common.product";String whereClause ="prices is not null";Boolean includeDeleted =true;Object res =DSApi.queryMany(className, whereClause);Object res2 =DSApi.queryMany(className, whereClause, includeDeleted);
Returns
Returns a list of objects including zero length error.
If there is an error in the SQL object or any other system error,
Result object is returned.
queryMany (SQL)
Gets all objects returned by the SQL query. This API should be used when you expect the result to be small (up to a few thousand). For a larger data set, use the DataIterator.
DSApi.queryMany(String sqlQuery)
Parameters
sqlQuery: SQL statement.
Sample Code
//fetch many product information from the product table using queryString sqlQuery ="Select id, prices from product_tbl where prices is not null";Object res2 =DSApi.queryMany(String sqlQuery)
Returns
Returns a list of objects including zero length error.
If there is an error in the SQL object or any other system error,
Result object is returned.
tenantByName
Retrieve the tenant details by searching its name.
DSApi.tenantByName(String tenantName)
Parameters
tenantName: name of the tenant
Sample Code
//fetch tenant results based on tenantNameString tenantName ="<tenantName>";Object res2 =DSApi.tenantByName(String tenantName)
Returns
the object representing the details
tenantByQuery
get the tenant details by executing a query.
DSApi.tenantByName(String query)
Parameters
query: query to be executed
Sample Code
//fetch results based on tenantNameString tenantName ="<tenantName>";Object res2 =DSApi.tenantByName(String tenantName)
Returns
tenant details
getUser
Returns user information by its ID
DSApi.getUser(String id)
Parameters
id: id of the user
Sample Code
//fetch user details using id of userString id ="abc";Object res =DSApi.getUser(String id)
Returns
user object
userByEmail
Returns the user information with associated email
DSApi.userByEmail(String email)
Parameters
email: email of the user
Sample Code
//fetch user details using emailString email ="abc@gmail.com";Object res =DSApi.userByEmail(String email)
Returns
user object
userByUserId
Returns the user with the ID
DSApi.userByUserId(String userId)
Parameters
userId:
Sample Code
//get user details using the userIdString userId ="{ID_OF_USER}";Object res =DSApi.userByUserId(String userId);
Returns
user object
valueByKey
Returns the value of the key associated with the provided type
DSApi.valueByKey(String key, String type)
Parameters
key:
type:
Sample Code
//fetch value associated with a provided typeString key ="{KEY}";String type ="{TYPE}";Object res =DSApi.valueByKey(key, type);