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.
Parameters
Sample Code
Returns
queryOne - sqlQuery
Gets an object using SQL query. If multiple are found then the first is returned.
Parameters
Sample Code
Returns
queryMany - whereClause (includeDeleted)
Gets all objects of the given class by the condition provided in the where clause.
Parameters
Sample Code
Returns
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.
Parameters
Sample Code
Returns
tenantByName
Retrieve the tenant details by searching its name.
Parameters
Sample Code
Returns
tenantByQuery
get the tenant details by executing a query.
Parameters
Sample Code
Returns
getUser
Returns user information by its ID
Parameters
Sample Code
Returns
userByEmail
Returns the user information with associated email
Parameters
Sample Code
Returns
userByUserId
Returns the user with the ID
Parameters
Sample Code
Returns
valueByKey
Returns the value of the key associated with the provided type
DSApi.queryOne(className, whereClause)
or
DSApi.queryOne(className, whereClause, includeDeleted)
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.
# fetch one product information from the product table using where filter
className = 'shared.common.product'
whereClause = 'prices is not null'
includeDeleted = True
res = DSApi.queryOne(className, whereClause)
res2 = DSApi.queryOne(className, whereClause, includeDeleted)
A dictionary containing the queried record.
DSApi.queryOne(sqlQuery)
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.
# fetch top 1 product information from the product table using query
sqlQuery = 'Select id, prices from product_tbl where prices is not null'
res2 = DSApi.queryOne(String sqlQuery)
A dictionary containing the queried record.
DSApi.queryMany(className, whereClause)
or
DSApi.queryMany(className, whereClause, includeDeleted)
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.
# fetch all product information from the product table using query
className = 'shared.common.product'
whereClause = 'prices is not null'
includeDeleted = True
res = DSApi.queryMany(className, whereClause)
res2 = DSApi.queryMany(className, whereClause, includeDeleted)
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.
DSApi.queryMany(sqlQuery)
sqlQuery: SQL statement as str type.
# fetch many product information from the product table using query
sqlQuery = 'Select id, prices from product_tbl where prices is not null'
res2 = DSApi.queryMany(sqlQuery)
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.
DSApi.tenantByName(tenantName)
tenantName: str name of the tenant
# fetch tenant results based on tenantName
tenantName = '<tenantName>'
res2 = DSApi.tenantByName(tenantName)
A Result object containing the tenant information.
DSApi.tenantByName(query)
query: str query to be executed
# fetch results based on tenantName
tenantName = '<tenantName>'
res2 = DSApi.tenantByName(tenantName)
A Result object containing the tenant information.
DSApi.getUser(id)
id: str id of the user
# fetch user details using id of user
id = 'abc'
res = DSApi.getUser(id)
A dictionary containing the user information.
DSApi.userByEmail(email)
email: email of the user as str
# fetch user details using email
email = 'abc@gmail.com'
res = DSApi.userByEmail(email)
A dictionary containing the user information.
DSApi.userByUserId(userId)
userId: str
# get user details using the userId
userId = '{ID_OF_USER}'
res = DSApi.userByUserId(userId)
A dictionary containing the user information.
DSApi.valueByKey(key, type)
key: str
type: str
# fetch value associated with a provided type
key = '{KEY}'
type = '{TYPE}'
res = DSApi.valueByKey(key, type)