The Stardust QueryService provides a business object search method to get specific Business Objects.
BusinessObjects getAllBusinessObjects(BusinessObjectQuery query);
The business objects can be created via the BusinessObjectQuery class.
The following Stardust QueryService method returns a list of business objects for a specific business object query:
BusinessObjects getAllBusinessObjects(BusinessObjectQuery query);
/**
* Returns the business objects satisfying the query.
*
* @param query the business objects query.
*
* @return a list of business objects, possibly empty.
*
* @throws org.eclipse.stardust.common.error.WorkflowException as a wrapper for
* org.eclipse.stardust.common.error.PublicExceptions and org.eclipse.stardust.common.error.ResourceExceptions
*
* @see org.eclipse.stardust.engine.api.runtime.QueryService#getAllBusinessObjects(
* org.eclipse.stardust.engine.api.query.BusinessObjectQuery query)
*/
public org.eclipse.stardust.engine.api.query.BusinessObjects
getAllBusinessObjects(
org.eclipse.stardust.engine.api.query.BusinessObjectQuery query)
throws org.eclipse.stardust.common.error.WorkflowException
{
try
{
return ((org.eclipse.stardust.engine.api.runtime.QueryService)
service).getAllBusinessObjects(query);
}
catch(org.eclipse.stardust.common.error.PublicException e)
{
throw new org.eclipse.stardust.common.error.WorkflowException(e);
}
catch(org.eclipse.stardust.common.error.ResourceException e)
{
throw new org.eclipse.stardust.common.error.WorkflowException(e);
}
}
The BusinessObjectQuery class provides the following options to create specific Query objects for a business object search:
To create a query for finding all business objects, use findAll():
public static BusinessObjectQuery findAll()
{
return new BusinessObjectQuery();
}
The method returns the configured BusinessObjectQuery.
To create a query to find all business objects in a model with a specified model Id, use the following method:
public static BusinessObjectQuery findInModel(String modelId)
{
BusinessObjectQuery query = findAll();
query.where(MODEL_ID.isEqual(modelId));
return query;
}
To create a query to find business objects with a specific qualified business object Id, use the following method:
public static BusinessObjectQuery findForBusinessObject(String qualifiedBusinessObjectId)
{
QName qname = QName.valueOf(qualifiedBusinessObjectId);
BusinessObjectQuery query = BusinessObjectQuery.findInModel(qname.getNamespaceURI());
query.where(BUSINESS_OBJECT_ID.isEqual(qname.getLocalPart()));
return query;
}
To create a query to find business objects with a specific qualified business object Id and primary key, use the following method:
public static BusinessObjectQuery findWithPrimaryKey(String qualifiedBusinessObjectId, Object pk)
{
BusinessObjectQuery query = BusinessObjectQuery.findForBusinessObject(qualifiedBusinessObjectId);
query.where(pk instanceof Number
? PRIMARY_KEY.isEqual(((Number) pk).longValue())
: PRIMARY_KEY.isEqual(pk.toString()));
return query;
}
To create a query to find all business objects in a model with a specified model OID, use the following method:
public static BusinessObjectQuery findInModel(long modelOid)
{
BusinessObjectQuery query = findAll();
query.where(MODEL_OID.isEqual(modelOid));
return query;
}
To create a query to find business objects with a specific business object Id in a model with a specified model OID, use the following method:
public static BusinessObjectQuery findForBusinessObject(long modelOid, String businessObjectId)
{
QName qname = QName.valueOf(businessObjectId);
BusinessObjectQuery query = BusinessObjectQuery.findInModel(modelOid);
if (!StringUtils.isEmpty(qname.getNamespaceURI()))
{
query.where(MODEL_ID.isEqual(qname.getNamespaceURI()));
}
query.where(BUSINESS_OBJECT_ID.isEqual(qname.getLocalPart()));
return query;
}
To create a query to find business objects with a specific business object Id and a specific primary key, use the following method:
public static BusinessObjectQuery findWithPrimaryKey(long modelOid, String businessObjectId, Object pk)
{
BusinessObjectQuery query = BusinessObjectQuery.findForBusinessObject(modelOid, businessObjectId);
query.where(pk instanceof Number
? PRIMARY_KEY.isEqual(((Number) pk).longValue())
: PRIMARY_KEY.isEqual(pk.toString()));
return query;
}
Filtering for business object attributes is possible through several filterable attributes in the QueryService.
To define a filter on the Business Object ID (ID) use:
private static final FilterableAttribute BUSINESS_OBJECT_ID = new FilterableAttributeImpl(
BusinessObjectQuery.class, ID_ATTRIBUTE);
To define a filter on the Business Object Primary Key use:
private static final FilterableAttribute PRIMARY_KEY = new FilterableAttributeImpl(
BusinessObjectQuery.class, PK_ATTRIBUTE);
To define a filter for a specific model use:
private static final FilterableAttribute MODEL_ID = new FilterableAttributeImpl(
BusinessObjectQuery.class, MODEL_ID_ATTRIBUTE);
Note that currently only one single Operator.isEqual(modelId) term is
supported to filter for exactly one modelId.
To define a filter for a specific model use:
private static final FilterableAttribute MODEL_OID = new FilterableAttributeImpl(
BusinessObjectQuery.class, ModelAwareQueryPredicate.INTERNAL_MODEL_OID_ATTRIBUTE);
Note that currently only one single Operator.isEqual(modelOid) term is
supported to filter for exactly one modelOid.