1 22 package org.jboss.ejb.plugins.cmp.jdbc; 23 24 import java.lang.reflect.Method ; 25 import java.util.Collection ; 26 27 import javax.ejb.FinderException ; 28 import javax.ejb.ObjectNotFoundException ; 29 30 import org.jboss.ejb.EntityEnterpriseContext; 31 import org.jboss.ejb.GenericEntityObjectFactory; 32 33 44 public final class JDBCFindEntityCommand 45 { 46 private static final String NO_SUCH_ENTITY = "No such entity!"; 47 48 private final JDBCStoreManager manager; 49 50 public JDBCFindEntityCommand(JDBCStoreManager manager) 51 { 52 this.manager = manager; 53 } 54 55 public Object execute(Method finderMethod, Object [] args, EntityEnterpriseContext ctx, GenericEntityObjectFactory factory) 56 throws FinderException 57 { 58 59 JDBCQueryCommand query = manager.getQueryManager().getQueryCommand(finderMethod); 60 61 Collection result = query.execute(finderMethod, args, ctx, factory); 62 if(result.isEmpty()) 63 { 64 throw new ObjectNotFoundException (NO_SUCH_ENTITY); 65 } 66 else if(result.size() == 1) 67 { 68 return result.iterator().next(); 69 } 70 else 71 { 72 throw new FinderException ("More than one entity matches the finder criteria: " + result); 73 } 74 } 75 } 76 | Popular Tags |