public Object execute(Method finderMethod,
Object[] args,
EntityEnterpriseContext ctx) throws Exception {
if (finderMethod.getName().equals("findByPrimaryKey"))
{
Object id = args[0];
if (preloadByPrimaryKey != null)
{
Collection result =
preloadByPrimaryKey.execute(finderMethod, args, ctx);
if (result.size() == 0)
{
throw new ObjectNotFoundException("No such entity!");
}
return id;
}
else if (beanExistsCommand.execute(id))
{
return id;
}
else
{
throw new ObjectNotFoundException("Object with primary key " + id +
" not found in storage");
}
}
else
{
Collection result =
(Collection)findEntitiesCommand.execute(finderMethod, args, ctx);
if (result.size() == 0)
{
throw new ObjectNotFoundException("No such entity!");
} else if (result.size() == 1)
{
Object [] objects = result.toArray();
return objects[0];
} else
{
throw new FinderException("More than one entity matches the " +
"finder criteria.");
}
}
}
|