mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2318 - Refactor internals - final classes in dto packages
This commit is contained in:
@@ -8,14 +8,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* Manages the query plans for a given DTO bean type.
|
||||
*/
|
||||
public class DtoBeanDescriptor<T> {
|
||||
public final class DtoBeanDescriptor<T> {
|
||||
|
||||
private final Map<Object, DtoQueryPlan> plans = new ConcurrentHashMap<>();
|
||||
|
||||
private final Class<T> dtoType;
|
||||
|
||||
private final DtoMeta meta;
|
||||
|
||||
private final Map<String, String> namedQueries;
|
||||
|
||||
DtoBeanDescriptor(Class<T> dtoType, DtoMeta meta, Map<String, String> namedQueries) {
|
||||
|
||||
@@ -10,14 +10,13 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* Manages all the DTO bean descriptors.
|
||||
*/
|
||||
public class DtoBeanManager {
|
||||
@SuppressWarnings("rawtypes")
|
||||
public final class DtoBeanManager {
|
||||
|
||||
private static final Map<String,String> EMPTY_NAMED_QUERIES = new HashMap<>();
|
||||
|
||||
private final TypeManager typeManager;
|
||||
|
||||
private final Map<Class<?>, DtoNamedQueries> namedQueries;
|
||||
|
||||
private final Map<Class, DtoBeanDescriptor> descriptorMap = new ConcurrentHashMap<>();
|
||||
|
||||
public DtoBeanManager(TypeManager typeManager, Map<Class<?>, DtoNamedQueries> namedQueries) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.dto;
|
||||
/**
|
||||
* A column in the resultSet that we want to map to a bean property.
|
||||
*/
|
||||
public class DtoColumn {
|
||||
public final class DtoColumn {
|
||||
|
||||
private final String label;
|
||||
|
||||
|
||||
@@ -8,18 +8,13 @@ import io.ebeaninternal.api.SpiDtoQuery;
|
||||
/**
|
||||
* Request to map a resultSet columns for a query into a DTO bean.
|
||||
*/
|
||||
public class DtoMappingRequest {
|
||||
public final class DtoMappingRequest {
|
||||
|
||||
private final Class type;
|
||||
|
||||
private final String label;
|
||||
|
||||
private final ProfileLocation profileLocation;
|
||||
|
||||
private final String sql;
|
||||
|
||||
private final boolean relaxedMode;
|
||||
|
||||
private final DtoColumn[] columnMeta;
|
||||
|
||||
public DtoMappingRequest(SpiDtoQuery query, String sql, DtoColumn[] columnMeta) {
|
||||
|
||||
@@ -10,23 +10,19 @@ import java.util.Map;
|
||||
*
|
||||
* Uses this to map a mapping request (columns) to a 'query plan' (constructor and setters).
|
||||
*/
|
||||
class DtoMeta {
|
||||
final class DtoMeta {
|
||||
|
||||
private final Class<?> dtoType;
|
||||
private final Map<String, DtoMetaProperty> propMap = new LinkedHashMap<>();
|
||||
|
||||
private final Map<Integer, DtoMetaConstructor> constructorMap = new LinkedHashMap<>();
|
||||
|
||||
private final DtoMetaConstructor defaultConstructor;
|
||||
private final DtoMetaConstructor maxArgConstructor;
|
||||
|
||||
DtoMeta(Class<?> dtoType, List<DtoMetaConstructor> constructors, List<DtoMetaProperty> properties) {
|
||||
this.dtoType = dtoType;
|
||||
|
||||
for (DtoMetaProperty property : properties) {
|
||||
propMap.put(property.getName().toUpperCase(), property);
|
||||
}
|
||||
|
||||
int maxArg = 0;
|
||||
|
||||
DtoMetaConstructor defaultConstructor = null;
|
||||
@@ -47,9 +43,7 @@ class DtoMeta {
|
||||
}
|
||||
|
||||
public DtoQueryPlan match(DtoMappingRequest request) {
|
||||
|
||||
DtoColumn[] cols = request.getColumnMeta();
|
||||
|
||||
int colLen = cols.length;
|
||||
DtoMetaConstructor constructor = constructorMap.get(colLen);
|
||||
if (constructor != null) {
|
||||
|
||||
@@ -15,16 +15,13 @@ import java.util.List;
|
||||
* <p>
|
||||
* Use TypeManager to map bean property types to ScalarTypes.
|
||||
*/
|
||||
class DtoMetaBuilder {
|
||||
final class DtoMetaBuilder {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DtoMetaBuilder.class);
|
||||
|
||||
private final TypeManager typeManager;
|
||||
|
||||
private final Class<?> dtoType;
|
||||
|
||||
private final List<DtoMetaProperty> properties = new ArrayList<>();
|
||||
|
||||
private final List<DtoMetaConstructor> constructorList = new ArrayList<>();
|
||||
|
||||
DtoMetaBuilder(Class<?> dtoType, TypeManager typeManager) {
|
||||
|
||||
@@ -10,22 +10,19 @@ import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.sql.SQLException;
|
||||
|
||||
class DtoMetaConstructor {
|
||||
final class DtoMetaConstructor {
|
||||
|
||||
private final Class<?>[] types;
|
||||
private final MethodHandle handle;
|
||||
|
||||
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
|
||||
private final ScalarType<?>[] scalarTypes;
|
||||
|
||||
DtoMetaConstructor(TypeManager typeManager, Constructor<?> constructor, Class<?> someClass) throws NoSuchMethodException, IllegalAccessException {
|
||||
|
||||
this.types = constructor.getParameterTypes();
|
||||
this.scalarTypes = new ScalarType[types.length];
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
scalarTypes[i] = typeManager.getScalarType(types[i]);
|
||||
}
|
||||
|
||||
this.handle = LOOKUP.findConstructor(someClass, typeFor(types));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.SQLException;
|
||||
|
||||
class DtoMetaProperty implements DtoReadSet {
|
||||
final class DtoMetaProperty implements DtoReadSet {
|
||||
|
||||
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ import java.util.Map;
|
||||
/**
|
||||
* Collection of named queries for a single Dto bean type.
|
||||
*/
|
||||
public class DtoNamedQueries {
|
||||
public final class DtoNamedQueries {
|
||||
|
||||
private Map<String, String> namedRawSql = new HashMap<>();
|
||||
private final Map<String, String> namedRawSql = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Add the named query from deployment XML.
|
||||
|
||||
@@ -7,10 +7,9 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Plan based on Constructor plus some setter methods.
|
||||
*/
|
||||
class DtoQueryPlanConPlus extends DtoQueryPlanBase {
|
||||
final class DtoQueryPlanConPlus extends DtoQueryPlanBase {
|
||||
|
||||
private final DtoMetaConstructor maxArgConstructor;
|
||||
|
||||
private final DtoReadSet[] setterProps;
|
||||
|
||||
DtoQueryPlanConPlus(DtoMappingRequest request, DtoMetaConstructor maxArgConstructor, DtoReadSet[] setterProps) {
|
||||
@@ -21,7 +20,6 @@ class DtoQueryPlanConPlus extends DtoQueryPlanBase {
|
||||
|
||||
@Override
|
||||
public Object readRow(DataReader dataReader) throws SQLException {
|
||||
|
||||
Object bean = maxArgConstructor.process(dataReader);
|
||||
for (DtoReadSet setterProp : setterProps) {
|
||||
setterProp.readSet(bean, dataReader);
|
||||
|
||||
@@ -7,10 +7,9 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Plan based on default constructor and setter methods.
|
||||
*/
|
||||
class DtoQueryPlanConSetter extends DtoQueryPlanBase {
|
||||
final class DtoQueryPlanConSetter extends DtoQueryPlanBase {
|
||||
|
||||
private final DtoMetaConstructor defaultConstructor;
|
||||
|
||||
private final DtoReadSet[] setterProps;
|
||||
|
||||
DtoQueryPlanConSetter(DtoMappingRequest request, DtoMetaConstructor defaultConstructor, DtoReadSet[] setterProps) {
|
||||
@@ -21,7 +20,6 @@ class DtoQueryPlanConSetter extends DtoQueryPlanBase {
|
||||
|
||||
@Override
|
||||
public Object readRow(DataReader dataReader) throws SQLException {
|
||||
|
||||
Object bean = defaultConstructor.defaultConstructor();
|
||||
for (DtoReadSet setterProp : setterProps) {
|
||||
setterProp.readSet(bean, dataReader);
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Plan based on mapping via single constructor only.
|
||||
*/
|
||||
class DtoQueryPlanConstructor extends DtoQueryPlanBase {
|
||||
final class DtoQueryPlanConstructor extends DtoQueryPlanBase {
|
||||
|
||||
private final DtoMetaConstructor constructor;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import io.ebean.core.type.DataReader;
|
||||
/**
|
||||
* Placeholder to skip reading a column that isn't mapped to a bean property.
|
||||
*/
|
||||
class DtoReadSetColumnSkip implements DtoReadSet {
|
||||
final class DtoReadSetColumnSkip implements DtoReadSet {
|
||||
|
||||
static final DtoReadSet INSTANCE = new DtoReadSetColumnSkip();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user