mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 15:55:55 +00:00
#343 - Remove deprecated interface BeanFinder<T> ... migrate to BeanFindController
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package com.avaje.ebean.event;
|
||||
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
|
||||
/**
|
||||
* Deprecated in favor of using BeanFindController.
|
||||
*
|
||||
* Used to override the finding implementation for a bean.
|
||||
* <p>
|
||||
* For beans that are not in a JDBC data source you can implement this handle
|
||||
* bean finding. For example, read a log file building each entry as a bean and
|
||||
* returning that.
|
||||
* </p>
|
||||
* <p>
|
||||
* There are a number of internal BeanFinders in Ebean to return meta data from
|
||||
* Ebean at runtime such as query execution statistics etc. See the beans in
|
||||
* com.avaje.ebean.meta and finders in com.avaje.ebean.server.meta.
|
||||
* </p>
|
||||
* @deprecated
|
||||
*/
|
||||
public interface BeanFinder<T> {
|
||||
|
||||
/**
|
||||
* Find a bean using its id or unique predicate.
|
||||
*/
|
||||
T find(BeanQueryRequest<T> request);
|
||||
|
||||
/**
|
||||
* Return a List, Set or Map for the given find request.
|
||||
* <p>
|
||||
* Note the returning object is cast to a List Set or Map so you do need to
|
||||
* get the return type right.
|
||||
* </p>
|
||||
*/
|
||||
BeanCollection<T> findMany(BeanQueryRequest<T> request);
|
||||
|
||||
}
|
||||
@@ -41,7 +41,6 @@ public class BootupClasses implements ClassPathSearchMatcher {
|
||||
|
||||
private ArrayList<Class<?>> transactionEventListenerList = new ArrayList<Class<?>>();
|
||||
|
||||
private ArrayList<Class<?>> beanFinderList = new ArrayList<Class<?>>();
|
||||
private ArrayList<Class<?>> beanFindControllerList = new ArrayList<Class<?>>();
|
||||
private ArrayList<Class<?>> beanQueryAdapterList = new ArrayList<Class<?>>();
|
||||
|
||||
@@ -282,13 +281,6 @@ public class BootupClasses implements ClassPathSearchMatcher {
|
||||
return transactionEventListenerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of BeanFinders found.
|
||||
*/
|
||||
public List<Class<?>> getBeanFinders() {
|
||||
return beanFinderList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of BeanListeners found.
|
||||
*/
|
||||
@@ -351,11 +343,6 @@ public class BootupClasses implements ClassPathSearchMatcher {
|
||||
interesting = true;
|
||||
}
|
||||
|
||||
if (BeanFinder.class.isAssignableFrom(cls)) {
|
||||
beanFinderList.add(cls);
|
||||
interesting = true;
|
||||
}
|
||||
|
||||
if (BeanFindController.class.isAssignableFrom(cls)) {
|
||||
beanFindControllerList.add(cls);
|
||||
interesting = true;
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.event.BeanFindController;
|
||||
import com.avaje.ebean.event.BeanFinder;
|
||||
import com.avaje.ebean.event.BeanQueryRequest;
|
||||
|
||||
/**
|
||||
* Wraps the old BeanFinder to make it implement BeanFindController.
|
||||
*/
|
||||
public class BeanFinderAdapter implements BeanFindController {
|
||||
|
||||
final BeanFinder beanFinder;
|
||||
|
||||
public BeanFinderAdapter(BeanFinder beanFinder) {
|
||||
this.beanFinder = beanFinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegisterFor(Class<?> cls) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterceptFind(BeanQueryRequest<?> request) {
|
||||
// always intercept to support old behavior
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(BeanQueryRequest<T> request) {
|
||||
return (T)beanFinder.find(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> BeanCollection<T> findMany(BeanQueryRequest<T> request) {
|
||||
return beanFinder.findMany(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInterceptFindMany(BeanQueryRequest<?> request) {
|
||||
// always intercept to support old behavior
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebean.event.BeanFindController;
|
||||
import com.avaje.ebean.event.BeanFinder;
|
||||
import com.avaje.ebeaninternal.server.core.BootupClasses;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanDescriptor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Default implementation for BeanFinderFactory.
|
||||
@@ -19,31 +15,14 @@ public class BeanFinderManager {
|
||||
|
||||
final Logger logger = LoggerFactory.getLogger(BeanFinderManager.class);
|
||||
|
||||
/**
|
||||
* Register of BeanFinder instances.
|
||||
*/
|
||||
final Map<Class<?>, BeanFinder<?>> registerFor = new HashMap<Class<?>, BeanFinder<?>>();
|
||||
|
||||
private final List<BeanFindController> list;
|
||||
|
||||
public BeanFinderManager(BootupClasses bootupClasses) {
|
||||
list = bootupClasses.getBeanFindControllers();
|
||||
|
||||
List<Class<?>> beanFinders = bootupClasses.getBeanFinders();
|
||||
for (Class<?> cls : beanFinders) {
|
||||
Class<?> entityType = getEntityClass(cls);
|
||||
try {
|
||||
BeanFinder<?> beanFinder = (BeanFinder<?>) cls.newInstance();
|
||||
registerFor.put(entityType, beanFinder);
|
||||
|
||||
} catch (Exception ex) {
|
||||
throw new PersistenceException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getRegisterCount() {
|
||||
return registerFor.size() + list.size();
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,28 +37,6 @@ public class BeanFinderManager {
|
||||
deployDesc.setBeanFinder(c);
|
||||
}
|
||||
}
|
||||
// support the deprecated BeanFinder
|
||||
BeanFinder beanFinder = registerFor.get(deployDesc.getBeanType());
|
||||
if (beanFinder != null) {
|
||||
deployDesc.setBeanFinder(new BeanFinderAdapter(beanFinder));
|
||||
logger.debug("BeanFinder on[" + deployDesc.getFullName() + "] " + beanFinder.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the entity class given the controller class.
|
||||
* <p>
|
||||
* This uses reflection to find the generics parameter type.
|
||||
* </p>
|
||||
*/
|
||||
private Class<?> getEntityClass(Class<?> controller) {
|
||||
|
||||
Class<?> cls = ParamTypeUtil.findParamType(controller, BeanFinder.class);
|
||||
|
||||
if (cls == null) {
|
||||
String msg = "Could not determine the entity class (generics parameter type) from " + controller + " using reflection.";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
return cls;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user