#2318 - Refactor internals - final classes in core packages

This commit is contained in:
rbygrave
2021-08-16 23:32:05 +12:00
parent 0413d89a9e
commit 9ee63144e5
25 changed files with 24 additions and 279 deletions
@@ -17,7 +17,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
class DScriptRunner implements ScriptRunner {
final class DScriptRunner implements ScriptRunner {
private static final String NEWLINE = "\n";
@@ -26,12 +26,11 @@ import java.util.List;
/**
* Helper to handle lazy loading and refreshing of beans.
*/
class DefaultBeanLoader {
final class DefaultBeanLoader {
private static final Logger logger = LoggerFactory.getLogger(DefaultBeanLoader.class);
private final DefaultServer server;
private final boolean onIterateUseExtraTxn;
DefaultBeanLoader(DefaultServer server) {
@@ -40,17 +39,14 @@ class DefaultBeanLoader {
}
void loadMany(LoadManyRequest loadRequest) {
SpiQuery<?> query = loadRequest.createQuery(server);
executeQuery(loadRequest, query);
loadRequest.postLoad();
}
void loadMany(BeanCollection<?> bc, boolean onlyIds) {
EntityBean parentBean = bc.getOwnerBean();
String propertyName = bc.getPropertyName();
loadManyInternal(parentBean, propertyName, null, false, onlyIds);
}
@@ -59,13 +55,10 @@ class DefaultBeanLoader {
}
private void loadManyInternal(EntityBean parentBean, String propertyName, Transaction t, boolean refresh, boolean onlyIds) {
EntityBeanIntercept ebi = parentBean._ebean_getIntercept();
PersistenceContext pc = ebi.getPersistenceContext();
BeanDescriptor<?> parentDesc = server.getBeanDescriptor(parentBean.getClass());
BeanPropertyAssocMany<?> many = (BeanPropertyAssocMany<?>) parentDesc.getBeanProperty(propertyName);
BeanCollection<?> beanCollection = null;
ExpressionList<?> filterMany = null;
@@ -126,7 +119,6 @@ class DefaultBeanLoader {
}
server.findOne(query, t);
if (beanCollection != null) {
if (beanCollection.checkEmptyLazyLoad()) {
if (logger.isDebugEnabled()) {
@@ -142,7 +134,6 @@ class DefaultBeanLoader {
* Load a batch of beans for +query or +lazy loading.
*/
void loadBean(LoadBeanRequest loadRequest) {
List<EntityBeanIntercept> batch = loadRequest.getBatch();
if (batch.isEmpty()) {
throw new RuntimeException("Nothing in batch?");
@@ -190,7 +181,6 @@ class DefaultBeanLoader {
}
private void refreshBeanInternal(EntityBean bean, SpiQuery.Mode mode, int embeddedOwnerIndex) {
EntityBeanIntercept ebi = bean._ebean_getIntercept();
PersistenceContext pc = ebi.getPersistenceContext();
if (Mode.REFRESH_BEAN == mode) {
@@ -203,12 +193,10 @@ class DefaultBeanLoader {
// lazy loading on an embedded bean property
EntityBean embeddedOwner = (EntityBean) ebi.getEmbeddedOwner();
int ownerIndex = ebi.getEmbeddedOwnerIndex();
refreshBeanInternal(embeddedOwner, mode, ownerIndex);
}
Object id = desc.getId(bean);
if (pc == null) {
// a reference with no existing persistenceContext
pc = new DefaultPersistenceContext();
@@ -216,7 +204,6 @@ class DefaultBeanLoader {
ebi.setPersistenceContext(pc);
}
boolean draft = desc.isDraftInstance(bean);
if (embeddedOwnerIndex == -1) {
if (desc.lazyLoadMany(ebi)) {
return;
@@ -246,16 +233,13 @@ class DefaultBeanLoader {
query.setPersistenceContext(pc);
query.setMode(mode);
query.setId(id);
if (embeddedOwnerIndex > -1 || mode == Mode.REFRESH_BEAN) {
// make sure the query doesn't use the cache
query.setUseCache(false);
}
if (ebi.isReadOnly()) {
query.setReadOnly(true);
}
if (Mode.REFRESH_BEAN == mode) {
// explicitly state to load all properties on REFRESH.
// Lobs default to fetch lazy so this forces lobs to be
@@ -268,7 +252,6 @@ class DefaultBeanLoader {
String msg = "Bean not found during lazy load or refresh." + " id[" + id + "] type[" + desc.getBeanType() + "]";
throw new EntityNotFoundException(msg);
}
desc.resetManyProperties(dbBean);
}
}
@@ -11,7 +11,7 @@ import java.util.Set;
/**
* Default implementation of BeanState.
*/
public class DefaultBeanState implements BeanState {
public final class DefaultBeanState implements BeanState {
private final EntityBeanIntercept intercept;
@@ -8,7 +8,7 @@ import java.util.Arrays;
/**
* Default CallStackFactory where the Hash function for StackTraceElement includes the line number.
*/
public class DefaultCallOriginFactory implements CallOriginFactory {
public final class DefaultCallOriginFactory implements CallOriginFactory {
private static final int IGNORE_LEADING_ELEMENTS = 5;
@@ -12,7 +12,7 @@ import java.sql.CallableStatement;
import java.sql.SQLException;
public class DefaultCallableSql implements Serializable, SpiCallableSql {
public final class DefaultCallableSql implements Serializable, SpiCallableSql {
private static final long serialVersionUID = 8984272253185424701L;
@@ -32,7 +32,7 @@ import java.util.concurrent.locks.ReentrantLock;
/**
* Default Server side implementation of ServerFactory.
*/
public class DefaultContainer implements SpiContainer {
public final class DefaultContainer implements SpiContainer {
private static final Logger logger = LoggerFactory.getLogger("io.ebean.DB");
@@ -19,7 +19,7 @@ import java.util.List;
/**
* DefaultServer based implementation of MetaInfoManager.
*/
public class DefaultMetaInfoManager implements MetaInfoManager {
final class DefaultMetaInfoManager implements MetaInfoManager {
private final DefaultServer server;
@@ -6,7 +6,7 @@ import io.ebean.meta.MetaQueryPlan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class DefaultQueryPlanListener implements QueryPlanListener {
final class DefaultQueryPlanListener implements QueryPlanListener {
static final QueryPlanListener INSTANT = new DefaultQueryPlanListener();
@@ -9,13 +9,12 @@ import org.slf4j.LoggerFactory;
/**
* Default slow query listener implementation that logs a warning message.
*/
class DefaultSlowQueryListener implements SlowQueryListener {
final class DefaultSlowQueryListener implements SlowQueryListener {
private static final Logger log = LoggerFactory.getLogger("io.ebean.SlowQuery");
@Override
public void process(SlowQueryEvent event) {
String firstStack = "";
ObjectGraphNode node = event.getOriginNode();
if (node != null) {
@@ -12,7 +12,7 @@ import java.util.Map;
* This intentionally does not include any OneToMany or ManyToMany properties.
* </p>
*/
public class DiffHelp {
public final class DiffHelp {
private DiffHelp() {
}
@@ -28,11 +28,9 @@ public class DiffHelp {
* </p>
*/
public static Map<String, ValuePair> diff(Object newBean, Object oldBean, BeanDescriptor<?> desc) {
if (!(newBean instanceof EntityBean)) {
throw new IllegalArgumentException("First bean expected to be an enhanced EntityBean? bean:" + newBean);
}
if (oldBean != null) {
if (!(oldBean instanceof EntityBean)) {
throw new IllegalArgumentException("Second bean expected to be an enhanced EntityBean? bean:" + oldBean);
@@ -41,11 +39,9 @@ public class DiffHelp {
throw new IllegalArgumentException("Second bean not assignable to the first bean?");
}
}
if (oldBean == null) {
return ((EntityBean) newBean)._ebean_getIntercept().getDirtyValues();
}
return desc.diff((EntityBean) newBean, (EntityBean) oldBean);
}
@@ -10,14 +10,12 @@ import io.ebeaninternal.api.SpiEbeanServer;
import java.util.Comparator;
import java.util.List;
class DumpMetrics {
final class DumpMetrics {
private final SpiEbeanServer server;
private final String options;
private final String nameFormat;
private final String nameFormatTimed;
private boolean dumpHash;
private boolean dumpSql;
private boolean dumpLoc;
@@ -14,10 +14,9 @@ import java.util.List;
/**
* Dump the metrics into a list of MetricData.
*/
class DumpMetricsData {
final class DumpMetricsData {
private final Database database;
private final List<MetricData> list = new ArrayList<>();
DumpMetricsData(Database database) {
@@ -30,7 +29,6 @@ class DumpMetricsData {
}
private void collect(ServerMetrics serverMetrics) {
final List<MetaTimedMetric> timedMetrics = serverMetrics.timedMetrics();
final List<MetaCountMetric> countMetrics = serverMetrics.countMetrics();
final List<MetaQueryMetric> queryMetrics = serverMetrics.queryMetrics();
@@ -14,23 +14,18 @@ import java.io.StringWriter;
import java.util.Comparator;
import java.util.List;
class DumpMetricsJson implements ServerMetricsAsJson {
final class DumpMetricsJson implements ServerMetricsAsJson {
private final Database database;
private Appendable writer;
/**
* By default include sql and location attributes for the initial collection only.
*/
private int includeExtraAttributes = 1;
private boolean withHeader = true;
private boolean withHash = true;
private String newLine = "\n";
private Comparator<MetaTimedMetric> sortBy = SortMetric.NAME;
private int listCounter;
private int objKeyCounter;
@@ -12,10 +12,9 @@ import javax.sql.DataSource;
/**
* Initialise the main DataSource and read-only DataSource.
*/
class InitDataSource {
final class InitDataSource {
private final JndiDataSourceLookup jndiDataSourceFactory = new JndiDataSourceLookup();
private final DatabaseConfig config;
/**
@@ -14,7 +14,7 @@ import java.util.Map;
/**
* Reads the Xml deployment information.
*/
class InternalConfigXmlMap {
final class InternalConfigXmlMap {
private static final Logger log = LoggerFactory.getLogger(InternalConfigXmlMap.class);
@@ -113,7 +113,7 @@ import java.util.ServiceLoader;
* Used to extend the DatabaseConfig with additional objects used to configure and
* construct an Database.
*/
public class InternalConfiguration {
public final class InternalConfiguration {
private static final Logger logger = LoggerFactory.getLogger(InternalConfiguration.class);
@@ -9,10 +9,7 @@ import javax.sql.DataSource;
/**
* Helper to lookup a DataSource from JNDI.
*/
public class JndiDataSourceLookup {
public JndiDataSourceLookup() {
}
class JndiDataSourceLookup {
/**
* Return the DataSource by JNDI lookup.
@@ -21,7 +18,6 @@ public class JndiDataSourceLookup {
* </p>
*/
public DataSource lookup(String jndiName) {
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiName);
@@ -15,11 +15,10 @@ import java.util.logging.Logger;
/**
* DataSource supplier that changes DB catalog based on current Tenant Id.
*/
public class MultiTenantDbCatalogSupplier implements DataSourceSupplier {
final class MultiTenantDbCatalogSupplier implements DataSourceSupplier {
private final DataSource dataSource;
private final DataSource readOnlyDataSource;
private final CatalogDataSource catalogDataSource;
private final CatalogDataSource readOnly;
@@ -15,11 +15,10 @@ import java.util.logging.Logger;
/**
* DataSource supplier that changes DB schema based on current Tenant Id.
*/
class MultiTenantDbSchemaSupplier implements DataSourceSupplier {
final class MultiTenantDbSchemaSupplier implements DataSourceSupplier {
private final DataSource dataSource;
private final DataSource readOnlyDataSource;
private final SchemaDataSource schemaDataSource;
private final SchemaDataSource readOnly;
@@ -11,10 +11,9 @@ import java.sql.SQLException;
/**
* DataSource supplier based on DataSource per Tenant.
*/
class MultiTenantDbSupplier implements DataSourceSupplier {
final class MultiTenantDbSupplier implements DataSourceSupplier {
private final CurrentTenantProvider tenantProvider;
private final TenantDataSourceProvider dataSourceProvider;
MultiTenantDbSupplier(CurrentTenantProvider tenantProvider, TenantDataSourceProvider dataSourceProvider) {
@@ -6,7 +6,7 @@ import io.ebean.bean.CallStack;
/**
* A CallOriginFactory we can use when we don't use AutoTune.
*/
class NoopCallOriginFactory implements CallOriginFactory {
final class NoopCallOriginFactory implements CallOriginFactory {
private static final StackTraceElement E0 = new StackTraceElement("none", "none", "none", 0);
@@ -11,7 +11,7 @@ import io.ebeaninternal.server.deploy.id.ImportedId;
* Deferred update of a relationship where an Id value is not initially available
* so instead we execute this later as a SqlUpdate statement.
*/
public class PersistDeferredRelationship {
public final class PersistDeferredRelationship {
private final SpiEbeanServer ebeanServer;
private final BeanDescriptor<?> beanDescriptor;
@@ -1,215 +0,0 @@
package io.ebeaninternal.server.core;
/**
* Helper for performing a 'refresh' on an Entity bean.
* <p>
* Note that this does not 'refresh' any OnetoMany or ManyToMany properties. It
* refreshes all the other properties though.
* </p>
*/
public class RefreshHelp {
//
// /**
// * Helper for debug of lazy loading.
// */
// private final DebugLazyLoad debugLazyLoad;
//
// private final MAdminLoggingMBean logControl;
//
// public RefreshHelp(MAdminLoggingMBean logControl, boolean debugLazyLoad){
// this.logControl = logControl;
// this.debugLazyLoad = new DebugLazyLoad(debugLazyLoad);
// }
//
// /**
// * Refresh the bean from property values in dbBean.
// */
// public void refresh(Object o, Object dbBean, BeanDescriptor<?> desc, EntityBeanIntercept ebi, Object id, boolean isLazyLoad) {
//
// Object originalOldValues = null;
// boolean setOriginalOldValues = false;
//
// // set of properties to exclude from the refresh because it is
// // not a refresh but rather a lazyLoading event.
// Set<String> excludes = null;
//
// // turn off intercepting so lazy loading is
// // not invoked when populating the bean
// // with PropertyChangeSupport
// ebi.setIntercepting(false);
//
// boolean readOnly = ebi.isReadOnly();
// boolean sharedInstance = ebi.isSharedInstance();
//
// if (isLazyLoad){
// excludes = ebi.getLoadedProps();
// if (excludes != null){
// // lazy loading a "Partial Object"... which already
// // contains some properties and perhaps some oldValues
// // and these will need to be maintained...
// originalOldValues = ebi.getOldValues();
// setOriginalOldValues = originalOldValues != null;
// }
//
// if (logControl.isDebugLazyLoad()){
// debug(desc, ebi, id, excludes);
// }
// }
//
//
// BeanProperty[] props = desc.propertiesBaseScalar();
// for (int i = 0; i < props.length; i++) {
// BeanProperty prop = props[i];
// if (excludes != null && excludes.contains(prop.getName())){
// // ignore this property (partial bean lazy loading)
//
// } else {
// Object dbVal = prop.getValue(dbBean);
// if (isLazyLoad) {
// prop.setValue(o, dbVal);
// } else {
// prop.setValueIntercept(o, dbVal);
// }
// if (setOriginalOldValues){
// // maintain original oldValues for partially loaded bean
// prop.setValue(originalOldValues, dbVal);
// }
// }
// }
//
// BeanPropertyAssocOne<?>[] ones = desc.propertiesOne();
// for (int i = 0; i < ones.length; i++) {
// BeanProperty prop = ones[i];
// if (excludes != null && excludes.contains(prop.getName())){
// // ignore this property (partial bean lazy loading)
//
// } else {
// Object dbVal = prop.getValue(dbBean);
// if (isLazyLoad){
// prop.setValue(o, dbVal);
// } else {
// prop.setValueIntercept(o, dbVal);
// }
// if (setOriginalOldValues){
// // maintain original oldValues for partially loaded bean
// prop.setValue(originalOldValues, dbVal);
// }
// if (dbVal != null){
// if (sharedInstance){
// // propagate sharedInstance status to associated beans
// ((EntityBean)dbVal)._ebean_getIntercept().setSharedInstance();
// } else if (readOnly) {
// // propagate readOnly status to associated beans
// ((EntityBean)dbVal)._ebean_getIntercept().setReadOnly(true);
// }
// }
//
// }
// }
//
// refreshEmbedded(o, dbBean, desc, excludes, readOnly);
//
// // set a lazy loading many proxy if required
// BeanPropertyAssocMany<?>[] manys = desc.propertiesMany();
// for (int i = 0; i < manys.length; i++) {
// BeanPropertyAssocMany<?> prop = manys[i];
// if (excludes != null && excludes.contains(prop.getName())){
// // the many already existed on the bean
//
// } else {
// // set a lazy loading proxy
// prop.createReference(o, null, readOnly, sharedInstance);
// }
// }
//
// // the refreshed/lazy loaded bean is always fully
// // populated so set loadedProps to null
// ebi.setLoadedProps(null);
//
//
// // reset the loaded status
// ebi.setLoaded();
// }
//
// /**
// * Refresh the Embedded beans.
// */
// private void refreshEmbedded(Object o, Object dbBean, BeanDescriptor<?> desc, Set<String> excludes, boolean propagateReadOnly) {
//
// BeanPropertyAssocOne<?>[] embeds = desc.propertiesEmbedded();
// for (int i = 0; i < embeds.length; i++) {
// BeanPropertyAssocOne<?> prop = embeds[i];
// if (excludes != null && excludes.contains(prop.getName())){
// // ignore this property
// } else {
// // the original embedded bean
// Object oEmb = prop.getValue(o);
//
// // the new one from the database
// Object dbEmb = prop.getValue(dbBean);
//
// if (oEmb == null){
// // original embedded bean was null
// // so just replace the entire embedded bean
// prop.setValueIntercept(o, dbEmb);
// if (propagateReadOnly && dbEmb != null){
// // propagate readOnly status to embedded beans
// ((EntityBean)dbEmb)._ebean_getIntercept().setReadOnly(true);
// }
//
// } else {
// // refresh each property of the original
// // embedded bean
// if (oEmb instanceof EntityBean){
// // turn off interception to stop invoking lazy loading
// // but allow PropertyChangeSupport
// ((EntityBean) oEmb)._ebean_getIntercept().setIntercepting(false);
// }
//
// BeanProperty[] props = prop.getProperties();
// for (int j = 0; j < props.length; j++) {
// Object v = props[j].getValue(dbEmb);
// props[j].setValueIntercept(oEmb, v);
// }
//
// // No longer calling setLoaded() on embedded bean
// // as the EntityBean itself
// // .. calls setEmbeddedLoaded() on each of
// // .. its embedded beans itself.
// }
// }
// }
// }
//
//
// /**
// * Output some debug to describe the lazy loading event.
// */
// private void debug(BeanDescriptor<?> desc, EntityBeanIntercept ebi, Object id, Set<String> excludes) {
//
//
// Class<?> beanType = desc.getBeanType();
//
// StackTraceElement cause = debugLazyLoad.getStackTraceElement(beanType);
//
// String lazyLoadProperty = ebi.getLazyLoadProperty();
// String msg = "debug.lazyLoad ["+desc+"] id["+id+"] lazyLoadProperty["+lazyLoadProperty+"]";
// if (excludes != null){
// msg += " partialProps"+excludes;
// }
// if (cause != null){
// String causeLine = cause.toString();
// if (causeLine.indexOf(".groovy:") > -1){
// // eclipse console does not like finding groovy source at the moment
// causeLine = StringHelper.replaceString(causeLine, ".groovy:", ".groovy :");
// }
// msg += " at: "+causeLine;
// }
// System.err.println(msg);
// }
//
//
//
}
@@ -10,10 +10,9 @@ import java.sql.SQLException;
/**
* Simple DataSource supplier when no multi-tenancy used.
*/
class SimpleDataSourceProvider implements DataSourceSupplier {
final class SimpleDataSourceProvider implements DataSourceSupplier {
private final DataSource dataSource;
private final DataSource readOnlyDataSource;
SimpleDataSourceProvider(DataSource dataSource, DataSource readOnlyDataSource) {
@@ -8,7 +8,7 @@ import java.sql.ResultSet;
*
* These both must be closed properly when done.
*/
public class SpiResultSet {
public final class SpiResultSet {
private final PreparedStatement statement;