#2318 - Refactor internals - final classes in server packages

This commit is contained in:
rbygrave committed 2021-08-17 18:24:28 +12:00
1 parent cd407ee467
commit b4f4ef3c1b
42 files changed
+48 -142

No files matched your search

@@ -8,7 +8,7 @@ import io.ebeaninternal.server.core.DefaultContainer;
/**
* Default container factory found via service loader.
*/
public class DContainerFactory implements SpiContainerFactory {
public final class DContainerFactory implements SpiContainerFactory {
@Override
public SpiContainer create(ContainerConfig containerConfig) {
@@ -23,12 +23,10 @@ import java.util.concurrent.locks.ReentrantLock;
/**
* ToOne bean load context.
*/
class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext {
final class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext {
private final boolean cache;
private List<LoadBuffer> bufferList;
private LoadBuffer currentBuffer;
DLoadBeanContext(DLoadContext parent, BeanDescriptor<?> desc, String path, OrmQueryProperties queryProps) {
@@ -31,17 +31,13 @@ import java.util.Map;
/**
* Default implementation of LoadContext.
*/
public class DLoadContext implements LoadContext {
public final class DLoadContext implements LoadContext {
private final SpiEbeanServer ebeanServer;
private final BeanDescriptor<?> rootDescriptor;
private final Map<String, DLoadBeanContext> beanMap = new HashMap<>();
private final Map<String, DLoadManyContext> manyMap = new HashMap<>();
private final DLoadBeanContext rootBeanContext;
private final boolean asDraft;
private final Timestamp asOf;
private final Boolean readOnly;
@@ -60,13 +56,9 @@ public class DLoadContext implements LoadContext {
private final String planLabel;
private final ProfileLocation profileLocation;
private final ProfilingListener profilingListener;
private final Map<String, ObjectGraphNode> nodePathMap = new HashMap<>();
private PersistenceContext persistenceContext;
private List<OrmQueryProperties> secQuery;
private Object tenantId;
/**
@@ -21,14 +21,11 @@ import java.util.concurrent.locks.ReentrantLock;
/**
* ToMany bean load context.
*/
class DLoadManyContext extends DLoadBaseContext implements LoadManyContext {
protected final BeanPropertyAssocMany<?> property;
final class DLoadManyContext extends DLoadBaseContext implements LoadManyContext {
private final BeanPropertyAssocMany<?> property;
private final boolean docStoreMapped;
private List<LoadBuffer> bufferList;
private LoadBuffer currentBuffer;
DLoadManyContext(DLoadContext parent, BeanPropertyAssocMany<?> property, String path, OrmQueryProperties queryProps) {
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.logger;
import io.ebeaninternal.api.SpiLogManager;
import io.ebeaninternal.api.SpiLogger;
public class DLogManager implements SpiLogManager {
public final class DLogManager implements SpiLogManager {
private final SpiLogger sql;
private final SpiLogger summary;
@@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory;
/**
* Default SpiLoggerFactory implementation.
*/
public class DLoggerFactory implements SpiLoggerFactory {
public final class DLoggerFactory implements SpiLoggerFactory {
/**
* Just use a standard slf4j Logger.
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.logger;
import io.ebeaninternal.api.SpiLogger;
import org.slf4j.Logger;
public class DSpiLogger implements SpiLogger {
public final class DSpiLogger implements SpiLogger {
private final Logger logger;
@@ -9,10 +9,9 @@ import java.util.concurrent.atomic.LongAdder;
/**
* Used to collect counter metrics.
*/
class DCountMetric implements CountMetric {
final class DCountMetric implements CountMetric {
private final String name;
private final LongAdder count = new LongAdder();
DCountMetric(String name) {
@@ -10,7 +10,7 @@ import io.ebean.metric.TimedMetricMap;
/**
* Default metric factory implementation.
*/
public class DMetricFactory implements MetricFactory {
public final class DMetricFactory implements MetricFactory {
@Override
public TimedMetricMap createTimedMetricMap(String name) {
@@ -13,7 +13,6 @@ class DProfileLocation implements ProfileLocation {
private String fullLocation;
private String location;
private String label;
private final int lineNumber;
private int traceCount;
@@ -8,7 +8,7 @@ import io.ebean.service.SpiProfileLocationFactory;
/**
* Default implementation of the profile location factory.
*/
public class DProfileLocationFactory implements SpiProfileLocationFactory {
public final class DProfileLocationFactory implements SpiProfileLocationFactory {
@Override
public ProfileLocation create() {
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.profile;
import io.ebean.ProfileLocation;
import io.ebeaninternal.server.util.Md5;
class DQueryPlanMeta {
final class DQueryPlanMeta {
private final Class<?> type;
private final String label;
@@ -6,7 +6,7 @@ import io.ebean.metric.QueryPlanMetric;
import io.ebean.metric.TimedMetric;
import io.ebean.metric.TimedMetricStats;
class DQueryPlanMetric implements QueryPlanMetric {
final class DQueryPlanMetric implements QueryPlanMetric {
private final DQueryPlanMeta meta;
private final DTimedMetric metric;
@@ -5,13 +5,12 @@ import io.ebean.metric.TimedMetricStats;
/**
* Snapshot of the current statistics for a Counter or TimeCounter.
*/
class DTimeMetricStats implements TimedMetricStats {
final class DTimeMetricStats implements TimedMetricStats {
private final boolean collected;
private final long count;
private final long total;
private final long max;
private String name;
private String location;
@@ -12,16 +12,12 @@ import java.util.concurrent.atomic.LongAdder;
* It is intended for high concurrent updates to the statistics and relatively infrequent reads.
* </p>
*/
class DTimedMetric implements TimedMetric {
final class DTimedMetric implements TimedMetric {
private final String name;
private final LongAdder count = new LongAdder();
private final LongAdder total = new LongAdder();
private final LongAccumulator max = new LongAccumulator(Math::max, Long.MIN_VALUE);
private boolean collected;
DTimedMetric(String name) {
@@ -7,14 +7,11 @@ import io.ebean.metric.TimedMetricStats;
/**
* Default profile location that uses stack trace.
*/
class DTimedProfileLocation extends DProfileLocation implements TimedProfileLocation {
final class DTimedProfileLocation extends DProfileLocation implements TimedProfileLocation {
private final String label;
private final TimedMetric timedMetric;
private final boolean overrideMetricName;
private String fullName;
DTimedProfileLocation(int lineNumber, String label, TimedMetric timedMetric) {
@@ -7,7 +7,7 @@ import java.util.List;
/**
* Global registry of the TimedProfileLocation instances created.
*/
public class TimedProfileLocationRegistry {
public final class TimedProfileLocationRegistry {
private static final List<TimedProfileLocation> list = Collections.synchronizedList(new ArrayList<>());
@@ -37,7 +37,6 @@ public final class BeanPropertiesReader {
try {
Field field = clazz.getField("_ebean_props");
return (String[]) field.get(null);
} catch (Exception e) {
throw new IllegalStateException("Error getting _ebean_props field on type " + clazz, e);
}
@@ -9,23 +9,20 @@ public final class EnhanceBeanPropertyAccess implements BeanPropertyAccess {
private static final int CACHE_SIZE = 30;
private final BeanPropertyGetter[] getters = initGetters(CACHE_SIZE);
private final BeanPropertySetter[] setters = initSetters(CACHE_SIZE);
private final BeanPropertyGetter[] getters = initGetters();
private final BeanPropertySetter[] setters = initSetters();
public EnhanceBeanPropertyAccess() {
}
private BeanPropertyGetter[] initGetters(int count) {
BeanPropertyGetter[] getters = new BeanPropertyGetter[count];
for (int i = 0; i < count; i++) {
private BeanPropertyGetter[] initGetters() {
BeanPropertyGetter[] getters = new BeanPropertyGetter[CACHE_SIZE];
for (int i = 0; i < CACHE_SIZE; i++) {
getters[i] = new Getter(i);
}
return getters;
}
private BeanPropertySetter[] initSetters(int count) {
BeanPropertySetter[] setters = new BeanPropertySetter[count];
for (int i = 0; i < count; i++) {
private BeanPropertySetter[] initSetters() {
BeanPropertySetter[] setters = new BeanPropertySetter[CACHE_SIZE];
for (int i = 0; i < CACHE_SIZE; i++) {
setters[i] = new Setter(i);
}
return setters;
@@ -8,9 +8,7 @@ import java.sql.ResultSet;
public final class DRawSql implements SpiRawSql {
private final ResultSet resultSet;
private final Sql sql;
private final ColumnMapping columnMapping;
/**
@@ -22,7 +20,7 @@ public final class DRawSql implements SpiRawSql {
this.columnMapping = new ColumnMapping(propertyNames);
}
protected DRawSql(ResultSet resultSet, Sql sql, ColumnMapping columnMapping) {
DRawSql(ResultSet resultSet, Sql sql, ColumnMapping columnMapping) {
this.resultSet = resultSet;
this.sql = sql;
this.columnMapping = columnMapping;
@@ -5,12 +5,10 @@ import io.ebean.RawSqlBuilder;
import java.sql.ResultSet;
public class DRawSqlBuilder implements RawSqlBuilder {
public final class DRawSqlBuilder implements RawSqlBuilder {
private final ResultSet resultSet;
private final SpiRawSql.Sql sql;
private final SpiRawSql.ColumnMapping columnMapping;
DRawSqlBuilder(SpiRawSql.Sql sql, SpiRawSql.ColumnMapping columnMapping) {
@@ -17,7 +17,6 @@ final class DRawSqlColumnsParser {
private static final Pattern COLINFO_SPLIT = Pattern.compile("\\s(?=[^\\)]*(?:\\(|$))");
private final String sqlSelect;
private int indexPos;
public static ColumnMapping parse(String sqlSelect) {
@@ -7,20 +7,15 @@ import io.ebeaninternal.server.rawsql.SpiRawSql.Sql;
* Parses sql-select queries to try and determine the location where WHERE and
* HAVING clauses can be added dynamically to the sql.
*/
class DRawSqlParser {
final class DRawSqlParser {
private static final String $_AND_HAVING = "${andHaving}";
private static final String $_HAVING = "${having}";
private static final String $_AND_WHERE = "${andWhere}";
private static final String $_WHERE = "${where}";
private final SimpleTextParser textParser;
private String sql;
private int placeHolderWhere;
private int placeHolderAndWhere;
private int placeHolderHaving;
@@ -11,7 +11,7 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
public class DRawSqlService implements SpiRawSqlService {
final class DRawSqlService implements SpiRawSqlService {
@Override
public RawSql resultSet(ResultSet resultSet, String... propertyNames) {
@@ -20,10 +20,8 @@ public class DRawSqlService implements SpiRawSqlService {
@Override
public RawSqlBuilder parsed(String sql) {
SpiRawSql.Sql sql2 = DRawSqlParser.parse(sql);
String select = sql2.getPreFrom();
SpiRawSql.ColumnMapping mapping = DRawSqlColumnsParser.parse(select);
return new DRawSqlBuilder(sql2, mapping);
}
@@ -36,7 +34,6 @@ public class DRawSqlService implements SpiRawSqlService {
@Override
public SqlRow sqlRow(ResultSet resultSet, String dbTrueValue, boolean binaryOptimizedUUID) throws SQLException {
ResultSetMetaData meta = resultSet.getMetaData();
int estCap = (int) (meta.getColumnCount() / 0.7f) + 1;
DefaultSqlRow ret = new DefaultSqlRow(estCap, 0.75f, dbTrueValue, binaryOptimizedUUID);
@@ -77,7 +74,6 @@ public class DRawSqlService implements SpiRawSqlService {
* Combine schema table and column names allowing for null schema and table.
*/
String combine(String schemaName, String tableName, String name) {
StringBuilder sb = new StringBuilder();
if (schemaName != null) {
sb.append(schemaName).append(".");
@@ -15,10 +15,9 @@ import java.io.IOException;
* This is used such that a load context and persistence context can be used to span multiple marshalling requests.
* </p>
*/
public class DJsonBeanReader<T> implements JsonBeanReader<T> {
public final class DJsonBeanReader<T> implements JsonBeanReader<T> {
private final BeanDescriptor<T> desc;
private final SpiJsonReader readJson;
public DJsonBeanReader(BeanDescriptor<T> desc, SpiJsonReader readJson) {
@@ -43,18 +43,14 @@ import java.util.Set;
/**
* Default implementation of JsonContext.
*/
public class DJsonContext implements SpiJsonContext {
public final class DJsonContext implements SpiJsonContext {
private static final PrettyPrinter PRETTY_PRINTER = new Pretty();
private final SpiEbeanServer server;
private final JsonFactory jsonFactory;
private final Object defaultObjectMapper;
private final JsonConfig.Include defaultInclude;
private final DJsonScalar jsonScalar;
private static class Pretty extends DefaultPrettyPrinter {
@@ -10,7 +10,7 @@ import java.util.List;
/**
* Default implementation of JsonScalar.
*/
public class DJsonScalar {
public final class DJsonScalar {
private final TypeManager typeManager;
@@ -20,7 +20,6 @@ public class DJsonScalar {
@SuppressWarnings({ "unchecked", "rawtypes" })
public void write(JsonGenerator gen, Object value) throws IOException {
if (value instanceof String) {
gen.writeString((String) value);
@@ -2,10 +2,9 @@ package io.ebeaninternal.server.text.json;
import io.ebeaninternal.server.util.ArrayStack;
public class PathStack extends ArrayStack<String> {
public final class PathStack extends ArrayStack<String> {
public String peekFullPath(String key) {
String prefix = peekWithNull();
if (prefix != null) {
return prefix + "." + key;
@@ -15,7 +14,6 @@ public class PathStack extends ArrayStack<String> {
}
public void pushPathKey(String key) {
String prefix = peekWithNull();
if (prefix != null) {
key = prefix + "." + key;
@@ -20,42 +20,28 @@ import java.util.Map;
/**
* Context for JSON read processing.
*/
public class ReadJson implements SpiJsonReader {
public final class ReadJson implements SpiJsonReader {
private final BeanDescriptor<?> rootDesc;
/**
* Jackson parser.
*/
private final JsonParser parser;
/**
* Stack of the path - used to find the appropriate JsonReadBeanVisitor.
*/
private final PathStack pathStack;
/**
* Map of the JsonReadBeanVisitor keyed by path.
*/
private final Map<String, JsonReadBeanVisitor<?>> visitorMap;
private final Object objectMapper;
private final PersistenceContext persistenceContext;
private final LoadContext loadContext;
/**
* Construct with parser and readOptions.
*/
public ReadJson(BeanDescriptor<?> desc, JsonParser parser, JsonReadOptions readOptions, Object objectMapper) {
this.rootDesc = desc;
this.parser = parser;
this.objectMapper = objectMapper;
this.persistenceContext = initPersistenceContext(readOptions);
this.loadContext = initLoadContext(desc, readOptions);
// only create visitorMap, pathStack if needed ...
this.visitorMap = (readOptions == null) ? null : readOptions.getVisitorMap();
this.pathStack = (visitorMap == null && loadContext == null) ? null : new PathStack();
@@ -119,7 +105,6 @@ public class ReadJson implements SpiJsonReader {
*/
@Override
public <T> void persistenceContextPut(Object beanId, T currentBean) {
persistenceContextPutIfAbsent(beanId, (EntityBean) currentBean, rootDesc);
}
@@ -129,16 +114,13 @@ public class ReadJson implements SpiJsonReader {
*/
@Override
public Object persistenceContextPutIfAbsent(Object id, EntityBean bean, BeanDescriptor<?> beanDesc) {
if (persistenceContext == null) {
// no persistenceContext means no lazy loading either
return null;
}
Object existing = beanDesc.contextPutIfAbsent(persistenceContext, id, bean);
if (existing != null) {
beanDesc.merge(bean, (EntityBean) existing);
} else {
if (loadContext != null) {
EntityBeanIntercept ebi = bean._ebean_getIntercept();
@@ -21,22 +21,15 @@ import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class WriteJson implements SpiJsonWriter {
public final class WriteJson implements SpiJsonWriter {
private final SpiEbeanServer server;
private final JsonGenerator generator;
private final FetchPath fetchPath;
private final Map<String, JsonWriteBeanVisitor<?>> visitors;
private final PathStack pathStack;
private final ArrayStack<Object> parentBeans;
private final Object objectMapper;
private final JsonConfig.Include include;
/**
@@ -6,10 +6,8 @@ import java.util.List;
/**
* Stack based on ArrayList.
*
* @author rbygrave
*/
public class ArrayStack<E> {
public final class ArrayStack<E> {
private final List<E> list;
@@ -15,19 +15,16 @@ import java.util.Collection;
* This is a thread safe implementation.
* </p>
*/
public class BindParamsParser {
public final class BindParamsParser {
private static final String ENCRYPTKEY_PREFIX = "encryptkey_";
private static final String ENCRYPTKEY_GAP = "___";
private static final int ENCRYPTKEY_PREFIX_LEN = ENCRYPTKEY_PREFIX.length();
private static final int ENCRYPTKEY_GAP_LEN = ENCRYPTKEY_GAP.length();
/**
* Used to parse sql looking for named parameters.
*/
private static final String quote = "'";
/**
* Used to parse sql looking for named parameters.
*/
@@ -35,7 +32,6 @@ public class BindParamsParser {
private final BindParams params;
private final String sql;
private final BeanDescriptor<?> beanDescriptor;
public static String parse(BindParams params, String sql) {
@@ -9,9 +9,7 @@ import java.util.Set;
public final class DSelectColumnsParser {
private final int end;
private final String selectClause;
private int pos;
public static Set<String> parse(String sqlSelect) {
@@ -5,7 +5,7 @@ package io.ebeaninternal.server.util;
* <p>
* Predicts a decent buffer size to append the strings into.
*/
public class Str {
public final class Str {
/**
* Append strings together.
@@ -6,13 +6,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
public class ParamTypeHelper {
public final class ParamTypeHelper {
public enum ManyType {
LIST, SET, MAP, NONE
}
public static class TypeInfo {
public static final class TypeInfo {
private final ManyType manyType;
private final Class<?> beanType;
@@ -46,11 +46,9 @@ public class ParamTypeHelper {
}
public static TypeInfo getTypeInfo(Type genericType) {
if (genericType instanceof ParameterizedType) {
return getParamTypeInfo((ParameterizedType) genericType);
}
Class<?> entityType = getBeanType(genericType);
if (entityType != null) {
return new TypeInfo(ManyType.NONE, entityType);
@@ -62,16 +60,12 @@ public class ParamTypeHelper {
* For Lists Sets and Maps of beans.
*/
private static TypeInfo getParamTypeInfo(ParameterizedType paramType) {
Type rawType = paramType.getRawType();
ManyType manyType = getManyType(rawType);
if (ManyType.NONE == manyType) {
return null;
}
Type[] typeArguments = paramType.getActualTypeArguments();
if (typeArguments.length == 1) {
Type argType = typeArguments[0];
Class<?> beanType = getBeanType(argType);
@@ -79,7 +73,6 @@ public class ParamTypeHelper {
return new TypeInfo(manyType, beanType);
}
}
return null;
}
@@ -10,23 +10,19 @@ import java.util.List;
* Primarily used to support sorting of Lists.
* </p>
*/
public class SortByClause {
public final class SortByClause {
static final String NULLSHIGH = "nullshigh";
static final String NULLSLOW = "nullslow";
/**
* The ascending keyword.
*/
static final String ASC = "asc";
/**
* The descending keyword.
*/
static final String DESC = "desc";
private final List<Property> properties = new ArrayList<>();
/**
@@ -8,13 +8,12 @@ import java.net.URLConnection;
/**
* Helper to open URL content without file descriptor caching (by underlying JDK JarURLConnection).
*/
public class UrlHelper {
public final class UrlHelper {
/**
* Open the URL content without using caching returning the resulting InputStream.
*/
public static InputStream openNoCache(URL url) throws IOException {
URLConnection urlConnection = url.openConnection();
urlConnection.setUseCaches(false);
return urlConnection.getInputStream();
@@ -3,7 +3,7 @@ package io.ebeaninternal.util;
import java.math.BigDecimal;
import java.net.URL;
public class ValueUtil {
public final class ValueUtil {
/**
* Helper method to check if two objects are equal.