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(className, id)
Parameters
className: the str 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 className ='shared.common.product'id='12'res = DSApi.get(className, id)
Returns
A dictionary containing the retrieved data.
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.
DSApi.queryOne(className, whereClause)
or
DSApi.queryOne(className, whereClause, includeDeleted)
Parameters
className: the str 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 filterclassName ='shared.common.product'whereClause ='prices is not null'includeDeleted =Trueres = DSApi.queryOne(className, whereClause)res2 = DSApi.queryOne(className, whereClause, includeDeleted)
Returns
A dictionary containing the queried record.
queryOne - sqlQuery
Gets an object using SQL query. If multiple are found then the first is returned.
DSApi.queryOne(sqlQuery)
Parameters
sqlQuery: str type 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 querysqlQuery ='Select id, prices from product_tbl where prices is not null'res2 = DSApi.queryOne(String sqlQuery)
Returns
A dictionary containing the queried record.
queryMany - whereClause (includeDeleted)
Gets all objects of the given class by the condition provided in the where clause.
DSApi.queryMany(className, whereClause)
or
DSApi.queryMany(className, whereClause, includeDeleted)
Parameters
className: the str name of class as created using the workbench
(correspond to the table)
whereClause: where-clause of the SQL query as str.
includeDeleted: boolean type. consider records marked deleted if a value of 'true is passed.
Sample Code
# fetch all product information from the product table using queryclassName ='shared.common.product'whereClause ='prices is not null'includeDeleted =Trueres = DSApi.queryMany(className, whereClause)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(sqlQuery)
Parameters
sqlQuery: SQL statement as str type.
Sample Code
# fetch many product information from the product table using querysqlQuery ='Select id, prices from product_tbl where prices is not null'res2 = DSApi.queryMany(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(tenantName)
Parameters
tenantName: str name of the tenant
Sample Code
# fetch tenant results based on tenantNametenantName ='<tenantName>'res2 = DSApi.tenantByName(tenantName)
Returns
A Result object containing the tenant information.
tenantByQuery
get the tenant details by executing a query.
DSApi.tenantByName(query)
Parameters
query: str query to be executed
Sample Code
# fetch results based on tenantNametenantName ='<tenantName>'res2 = DSApi.tenantByName(tenantName)
Returns
A Result object containing the tenant information.
getUser
Returns user information by its ID
DSApi.getUser(id)
Parameters
id: str id of the user
Sample Code
# fetch user details using id of userid='abc'res = DSApi.getUser(id)
Returns
A dictionary containing the user information.
userByEmail
Returns the user information with associated email
DSApi.userByEmail(email)
Parameters
email: email of the user as str
Sample Code
# fetch user details using emailemail ='abc@gmail.com'res = DSApi.userByEmail(email)
Returns
A dictionary containing the user information.
userByUserId
Returns the user with the ID
DSApi.userByUserId(userId)
Parameters
userId: str
Sample Code
# get user details using the userIduserId ='{ID_OF_USER}'res = DSApi.userByUserId(userId)
Returns
A dictionary containing the user information.
valueByKey
Returns the value of the key associated with the provided type
DSApi.valueByKey(key, type)
Parameters
key: str
type: str
Sample Code
# fetch value associated with a provided typekey ='{KEY}'type='{TYPE}'res = DSApi.valueByKey(key, type)