mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#394 - ENH: Add plugin API SpiServer, SpiBeanType ... migrate plugins towards using this API, migrate away from direct use of BeanDescriptor etc.
This commit is contained in:
@@ -12,6 +12,7 @@ import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.cache.ServerCacheManager;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.meta.MetaInfoManager;
|
||||
import com.avaje.ebean.plugin.SpiServer;
|
||||
import com.avaje.ebean.text.csv.CsvReader;
|
||||
import com.avaje.ebean.text.json.JsonContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -128,6 +129,11 @@ public interface EbeanServer {
|
||||
*/
|
||||
MetaInfoManager getMetaInfoManager();
|
||||
|
||||
/**
|
||||
* Return the extended API intended for use by plugins.
|
||||
*/
|
||||
SpiServer getPluginApi();
|
||||
|
||||
/**
|
||||
* Return the BeanState for a given entity bean.
|
||||
* <p>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.avaje.ebean.plugin;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.IdType;
|
||||
import com.avaje.ebean.event.BeanFindController;
|
||||
import com.avaje.ebean.event.BeanPersistController;
|
||||
import com.avaje.ebean.event.BeanPersistListener;
|
||||
import com.avaje.ebean.event.BeanQueryAdapter;
|
||||
|
||||
/**
|
||||
* Information and methods on BeanDescriptors made available to plugins.
|
||||
*/
|
||||
public interface SpiBeanType<T> {
|
||||
|
||||
/**
|
||||
* Return the class type this BeanDescriptor describes.
|
||||
*/
|
||||
Class<T> getBeanType();
|
||||
|
||||
/**
|
||||
* Return the base table this bean type maps to.
|
||||
*/
|
||||
String getBaseTable();
|
||||
|
||||
/**
|
||||
* Return the id value for the given bean.
|
||||
*/
|
||||
Object getBeanId(T bean);
|
||||
|
||||
/**
|
||||
* Return the bean persist controller.
|
||||
*/
|
||||
BeanPersistController getPersistController();
|
||||
|
||||
/**
|
||||
* Return the bean persist listener.
|
||||
*/
|
||||
BeanPersistListener getPersistListener();
|
||||
|
||||
/**
|
||||
* Return the beanFinder. Usually null unless overriding the finder.
|
||||
*/
|
||||
BeanFindController getFindController();
|
||||
|
||||
/**
|
||||
* Return the BeanQueryAdapter or null if none is defined.
|
||||
*/
|
||||
BeanQueryAdapter getQueryAdapter();
|
||||
|
||||
/**
|
||||
* Return the identity generation type.
|
||||
*/
|
||||
IdType getIdType();
|
||||
|
||||
/**
|
||||
* Return the sequence name associated to this entity bean type (if there is one).
|
||||
*/
|
||||
String getSequenceName();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.avaje.ebean.plugin;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Extensions to EbeanServer API made available to plugins.
|
||||
*/
|
||||
public interface SpiServer extends EbeanServer {
|
||||
|
||||
/**
|
||||
* Return the DatabasePlatform for this server.
|
||||
*/
|
||||
DatabasePlatform getDatabasePlatform();
|
||||
|
||||
/**
|
||||
* Return all the bean types registered on this server instance.
|
||||
*/
|
||||
List<? extends SpiBeanType<?>> getBeanTypes();
|
||||
|
||||
/**
|
||||
* Return the bean type for a given entity bean class.
|
||||
*/
|
||||
<T> SpiBeanType<T> getBeanType(Class<T> beanClass);
|
||||
|
||||
/**
|
||||
* Return the bean types mapped to the given base table.
|
||||
*/
|
||||
List<? extends SpiBeanType<?>> getBeanTypes(String baseTableName);
|
||||
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.event.BeanPersistController;
|
||||
import com.avaje.ebean.event.BeanQueryAdapter;
|
||||
import com.avaje.ebean.meta.MetaInfoManager;
|
||||
import com.avaje.ebean.plugin.SpiBeanType;
|
||||
import com.avaje.ebean.plugin.SpiServer;
|
||||
import com.avaje.ebean.text.csv.CsvReader;
|
||||
import com.avaje.ebean.text.json.JsonContext;
|
||||
import com.avaje.ebeaninternal.api.LoadBeanRequest;
|
||||
@@ -86,7 +88,7 @@ import java.util.concurrent.FutureTask;
|
||||
/**
|
||||
* The default server side implementation of EbeanServer.
|
||||
*/
|
||||
public final class DefaultServer implements SpiEbeanServer {
|
||||
public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DefaultServer.class);
|
||||
|
||||
@@ -310,6 +312,11 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
return metaInfoManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpiServer getPluginApi() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BackgroundExecutor getBackgroundExecutor() {
|
||||
return backgroundExecutor;
|
||||
}
|
||||
@@ -1937,6 +1944,28 @@ public final class DefaultServer implements SpiEbeanServer {
|
||||
return beanDescriptorManager.getBeanDescriptors(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the SPI BeanTypes.
|
||||
*/
|
||||
public List<? extends SpiBeanType<?>> getBeanTypes() {
|
||||
return getBeanDescriptors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the SPI bean types mapped to the given table.
|
||||
*/
|
||||
public List<? extends SpiBeanType<?>> getBeanTypes(String tableName) {
|
||||
return beanDescriptorManager.getBeanTypes(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the SPI bean types for the given bean class.
|
||||
*/
|
||||
@Override
|
||||
public <T> SpiBeanType<T> getBeanType(Class<T> beanType) {
|
||||
return getBeanDescriptor(beanType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BeanDescriptor using its unique id.
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.avaje.ebean.event.changelog.ChangeLogFilter;
|
||||
import com.avaje.ebean.event.changelog.ChangeType;
|
||||
import com.avaje.ebean.meta.MetaBeanInfo;
|
||||
import com.avaje.ebean.meta.MetaQueryPlanStatistic;
|
||||
import com.avaje.ebean.plugin.SpiBeanType;
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlan;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
@@ -73,7 +74,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* Describes Beans including their deployment information.
|
||||
*/
|
||||
public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
public class BeanDescriptor<T> implements MetaBeanInfo, SpiBeanType<T> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BeanDescriptor.class);
|
||||
|
||||
@@ -1353,6 +1354,11 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
return (idProperty == null) ? null : idProperty.getValue(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getBeanId(T bean) {
|
||||
return getId((EntityBean)bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default order by that may need to be added if a many property is
|
||||
* included in the query.
|
||||
@@ -1630,12 +1636,20 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the beanFinder. Usually null unless overriding the finder.
|
||||
* Return the beanFinder (Migrate over to getFindController).
|
||||
*/
|
||||
public BeanFindController getBeanFinder() {
|
||||
return beanFinder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the find controller (SPI interface).
|
||||
*/
|
||||
@Override
|
||||
public BeanFindController getFindController() {
|
||||
return beanFinder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BeanQueryAdapter or null if none is defined.
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.avaje.ebean.event.changelog.ChangeLogFilter;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogListener;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogPrepare;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogRegister;
|
||||
import com.avaje.ebean.plugin.SpiBeanType;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable;
|
||||
import com.avaje.ebeaninternal.server.core.BootupClasses;
|
||||
@@ -346,6 +347,13 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
return tableToDescMap.get(tableName.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BeanDescriptors mapped to the table.
|
||||
*/
|
||||
public List<? extends SpiBeanType<?>> getBeanTypes(String tableName) {
|
||||
return tableToDescMap.get(tableName.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a map of table names to BeanDescriptors.
|
||||
* <p>
|
||||
|
||||
Reference in New Issue
Block a user