List<IdentityObject> results;
checkControls(controls);
PageSearchControl pageSearchControl = null;
SortByNameSearchControl sortSearchControl = null;
AttributeFilterSearchControl attributeFilterControl = null;
NameFilterSearchControl nameFilterSearchControl = null;
if (controls != null)
{
for (IdentityObjectSearchControl control : controls)
{
if (control instanceof PageSearchControl)
{
pageSearchControl = (PageSearchControl)control;
}
else if (control instanceof SortByNameSearchControl)
{
sortSearchControl = (SortByNameSearchControl)control;
}
else if (control instanceof AttributeFilterSearchControl)
{
attributeFilterControl = (AttributeFilterSearchControl)control;
}
else if (control instanceof NameFilterSearchControl)
{
nameFilterSearchControl = (NameFilterSearchControl)control;
}
}
}
boolean orderByName = false;
boolean ascending = true;
if (sortSearchControl != null)
{
orderByName = true;
ascending = sortSearchControl.isAscending();
}
try
{
org.hibernate.Query q = null;
StringBuilder hqlString = new StringBuilder("");
if (orderByName)
{
hqlString.append(" orderBy ior.toIdentityObject.name");
if (ascending)
{
hqlString.append(" asc");
}
}
if (parent)
{
hqlString.append("select ior.toIdentityObject from HibernateIdentityObjectRelationship ior where " +
"ior.toIdentityObject.name like :nameFilter and ior.type.name like :relType and ior.fromIdentityObject like :identity");
if (orderByName)
{
hqlString.append(" orderBy ior.toIdentityObject.name");
if (ascending)
{
hqlString.append(" asc");
}
}
}
else
{
hqlString.append("select ior.fromIdentityObject from HibernateIdentityObjectRelationship ior where " +
"ior.fromIdentityObject.name like :nameFilter and ior.type.name like :relType and ior.toIdentityObject like :identity");
if (orderByName)
{
hqlString.append(" orderBy ior.toIdentityObject.name");
if (ascending)
{
hqlString.append(" asc");
}
}
}
q = getHibernateEntityManager(ctx).getSession().createQuery(hqlString.toString())
.setParameter("relType", relationshipType.getName())
.setParameter("identity",hibernateObject);
if (nameFilterSearchControl != null)
{
q.setParameter("nameFilter", nameFilterSearchControl.getFilter().replaceAll("\\*", "%"));
}
else
{
q.setParameter("nameFilter", "%");
}
if (pageSearchControl != null)
{
q.setFirstResult(pageSearchControl.getOffset());
if (pageSearchControl.getLimit() > 0)
{
q.setMaxResults(pageSearchControl.getLimit());
}
}