User: dsundstrom
Date: 01/06/23 20:23:14
Added: src/main/org/jboss/ejb/plugins/cmp/bmp
CustomFindByEntitiesCommand.java
Log:
Initial revision of EJB 2.0 CMP.
Revision Changes Path
1.1
jboss/src/main/org/jboss/ejb/plugins/cmp/bmp/CustomFindByEntitiesCommand.java
Index: CustomFindByEntitiesCommand.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.cmp.bmp;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Collections;
import javax.ejb.FinderException;
import org.jboss.ejb.EntityEnterpriseContext;
import org.jboss.ejb.plugins.cmp.FindEntitiesCommand;
import org.jboss.logging.Logger;
import org.jboss.metadata.BeanMetaData;
import org.jboss.util.FinderResults;
/**
* CMPStoreManager CustomFindByEntitiesCommand.
* Implements bridge for custom implemented finders in container managed entity
beans.
* These methods are called ejbFindX in the EJB implementation class, where X can be
* anything. Such methods are called findX in the Home interface. The EJB
implementation
* must return a Collection of primary keys.
*
* @see org.jboss.ejb.plugins.cmp.jdbc.JDBCFindEntitiesCommand
* @author <a href="mailto:[EMAIL PROTECTED]">Michel de Groot</a>
* @version $Revision: 1.1 $
*/
public class CustomFindByEntitiesCommand implements FindEntitiesCommand {
// Attributes ----------------------------------------------------
/**
* method that implements the finder
*/
protected Method finderImplMethod;
// Constructors --------------------------------------------------
/**
* Constructs a command which can handle multiple entity finders
* that are BMP implemented.
* @param finderMethod the EJB finder method implementation
*/
public CustomFindByEntitiesCommand(Method finderMethod) {
finderImplMethod = finderMethod;
Logger.debug("Finder: Custom finder " + finderMethod.getName());
}
// FindEntitiesCommand implementation -------------------------
public FinderResults execute(Method finderMethod,
Object[] args,
EntityEnterpriseContext ctx)
throws java.rmi.RemoteException, FinderException
{
try {
// invoke implementation method on ejb instance
Object result = finderImplMethod.invoke(ctx.getInstance(),
args);
// if expected return type is Collection, return as is
// if expected return type is not Collection, wrap result in
Collection
if(!(result instanceof Collection)) {
result = Collections.singleton(result);
}
return new FinderResults((Collection)result, null, null, null);
} catch (IllegalAccessException e1) {
throw new FinderException("Unable to access finder
implementation: " + finderImplMethod.getName());
} catch (IllegalArgumentException e2) {
throw new FinderException("Illegal arguments for finder
implementation: " + finderImplMethod.getName());
} catch (InvocationTargetException e3) {
throw new FinderException("Exception in finder implementation:
" + finderImplMethod.getName());
} catch (ExceptionInInitializerError e5) {
throw new FinderException("Unable to initialize finder
implementation: " + finderImplMethod.getName());
}
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development