/**
* Find the permission descriptor for given principal and permission
*/
public PermissionDescriptor find(final Principal prpal, final Permission perm) {
final List results = new ArrayList(1);
HibernateTxFragment txFragment = new HibernateTxFragment() {
protected void txFragment(Session session) throws Exception {
StringBuffer buf = new StringBuffer();
buf.append(" from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null ");
if (prpal != null) {
buf.append(" and item.principalClass = :principalClass ");
buf.append(" and item.principalName = :principalName ");
}
buf.append("and item.permissionClass = :permissionClass and item.permissionResource = :permissionResource");
Query query = session.createQuery(buf.toString());
if (prpal != null) {
query.setString("principalClass", prpal.getClass().getName());
query.setString("principalName", prpal.getName());
}
query.setString("permissionClass", perm.getClass().getName());
query.setString("permissionResource", perm.getName());
query.setCacheable(true);
FlushMode oldFlushMode = session.getFlushMode();
session.setFlushMode(FlushMode.NEVER);
results.addAll(query.list());
session.setFlushMode(oldFlushMode);
}
};
try {
txFragment.execute();
if (!results.isEmpty())
return (PermissionDescriptor) results.get(0);
else
return null;
} catch (Exception e) {