}
protected Object invokeFind(final InterceptorContext context, final EntityBeanComponentInstance instance) throws Exception {
final CmpEntityBeanComponentInstance cmpInstance = CmpEntityBeanComponentInstance.class.cast(instance);
final CmpEntityBeanComponent cmpComponent = cmpInstance.getComponent();
try {
cmpComponent.getComponentClass().getDeclaredMethod(finderMethod.getName(), finderMethod.getParameterTypes());
return super.invokeFind(context, instance);
} catch (NoSuchMethodException ignored) {
}
final JDBCEntityPersistenceStore store = cmpComponent.getStoreManager();
final CmpEntityBeanContext entityContext = cmpInstance.getEjbContext();
// as per the spec 9.6.4, entities must be synchronized with the datastore when an ejbFind<METHOD> is called.
if (finderMethod.getName().equals("findByPrimaryKey")) {
if(finderMethod.getParameterTypes() == null) {
throw MESSAGES.nullArgumentForFindByPrimaryKey();
}
if(finderMethod.getParameterTypes().length != 1) {
throw MESSAGES.illegalNumberOfArgumentsForFindByPrimaryKey(finderMethod.getParameterTypes().length);
}
final ReadyEntityCache cache = cmpComponent.getCache();
if(cache.containsNotRemoved(context.getParameters()[0])) {
return this.localHome ? cmpComponent.getEJBLocalObject(context.getParameters()[0]) : cmpComponent.getEJBObject(context.getParameters()[0]);
}
}else if(!store.getCmpConfig().isSyncOnCommitOnly()) {
cmpComponent.synchronizeEntitiesWithinTransaction(entityContext.getTransaction());
}
final JDBCQueryCommand.EntityProxyFactory factory = new JDBCQueryCommand.EntityProxyFactory() {
public Object getEntityObject(final Object primaryKey) {
return localHome ? cmpComponent.getEJBLocalObject(primaryKey) : cmpComponent.getEJBObject(primaryKey);
}
};
if (getReturnType() == ReturnType.SINGLE) {
return store.findEntity(context.getMethod(), context.getParameters(), entityContext, factory);