mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#575 - Refactor PathProperties, extract FetchPath interface, rename get(path) -> getProperties(path)
This commit is contained in:
1 parent
eda7fe24c1
commit
6561c118ec
18 files changed
+413
-244
No files matched your search
@@ -1,15 +1,7 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.*;
|
||||
import com.avaje.ebean.event.BeanQueryRequest;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
|
||||
import com.avaje.ebeaninternal.api.ManyWhereJoins;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
@@ -18,6 +10,13 @@ import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionValidation;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Default implementation of ExpressionList.
|
||||
*/
|
||||
@@ -173,8 +172,8 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> apply(PathProperties pathProperties) {
|
||||
return query.apply(pathProperties);
|
||||
public Query<T> apply(FetchPath fetchPath) {
|
||||
return query.apply(fetchPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.*;
|
||||
import com.avaje.ebean.Expression;
|
||||
import com.avaje.ebean.ExpressionList;
|
||||
import com.avaje.ebean.FetchPath;
|
||||
import com.avaje.ebean.FutureIds;
|
||||
import com.avaje.ebean.FutureList;
|
||||
import com.avaje.ebean.FutureRowCount;
|
||||
import com.avaje.ebean.Junction;
|
||||
import com.avaje.ebean.OrderBy;
|
||||
import com.avaje.ebean.PagedList;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.QueryEachConsumer;
|
||||
import com.avaje.ebean.QueryEachWhileConsumer;
|
||||
import com.avaje.ebean.QueryIterator;
|
||||
import com.avaje.ebean.Version;
|
||||
import com.avaje.ebean.event.BeanQueryRequest;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
|
||||
import com.avaje.ebeaninternal.api.ManyWhereJoins;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
@@ -16,6 +22,12 @@ import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionValidation;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Junction implementation.
|
||||
*/
|
||||
@@ -298,8 +310,8 @@ abstract class JunctionExpression<T> implements Junction<T>, SpiExpression, Expr
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> apply(PathProperties pathProperties) {
|
||||
return exprList.apply(pathProperties);
|
||||
public Query<T> apply(FetchPath fetchPath) {
|
||||
return exprList.apply(fetchPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -352,8 +352,8 @@ public class CQueryBuilder {
|
||||
OrmQueryDetail detail = new OrmQueryDetail();
|
||||
|
||||
// transfer PathProperties into OrmQueryDetail
|
||||
for (String path : pathProps.getPaths()) {
|
||||
detail.fetch(path, pathProps.get(path));
|
||||
for (PathProperties.Props props : pathProps.getPathProps()) {
|
||||
detail.fetch(props.getPath(), props.getProperties());
|
||||
}
|
||||
|
||||
// check if @Id property included in RawSql
|
||||
|
||||
@@ -10,11 +10,10 @@ import com.avaje.ebean.bean.PersistenceContext;
|
||||
import com.avaje.ebean.event.BeanQueryRequest;
|
||||
import com.avaje.ebean.event.readaudit.ReadEvent;
|
||||
import com.avaje.ebean.plugin.BeanType;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.api.CQueryPlanKey;
|
||||
import com.avaje.ebeaninternal.api.HashQuery;
|
||||
import com.avaje.ebeaninternal.api.ManyWhereJoins;
|
||||
import com.avaje.ebeaninternal.api.CQueryPlanKey;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionList;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionValidation;
|
||||
@@ -26,9 +25,9 @@ import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
||||
import com.avaje.ebeaninternal.server.deploy.DRawSqlSelect;
|
||||
import com.avaje.ebeaninternal.server.deploy.DeployNamedQuery;
|
||||
import com.avaje.ebeaninternal.server.deploy.TableJoin;
|
||||
import com.avaje.ebeaninternal.server.expression.DefaultExpressionList;
|
||||
import com.avaje.ebeaninternal.server.expression.SimpleExpression;
|
||||
import com.avaje.ebeaninternal.server.query.CancelableQuery;
|
||||
import com.avaje.ebeaninternal.server.expression.DefaultExpressionList;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.sql.Timestamp;
|
||||
@@ -284,8 +283,8 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> apply(PathProperties pathProperties) {
|
||||
pathProperties.apply(this);
|
||||
public Query<T> apply(FetchPath fetchPath) {
|
||||
fetchPath.apply(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,40 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import com.avaje.ebean.FetchPath;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.text.json.*;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebean.text.json.EJson;
|
||||
import com.avaje.ebean.text.json.JsonContext;
|
||||
import com.avaje.ebean.text.json.JsonIOException;
|
||||
import com.avaje.ebean.text.json.JsonReadOptions;
|
||||
import com.avaje.ebean.text.json.JsonScalar;
|
||||
import com.avaje.ebean.text.json.JsonWriteBeanVisitor;
|
||||
import com.avaje.ebean.text.json.JsonWriteOptions;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
import com.avaje.ebeaninternal.util.ParamTypeHelper;
|
||||
import com.avaje.ebeaninternal.util.ParamTypeHelper.ManyType;
|
||||
import com.avaje.ebeaninternal.util.ParamTypeHelper.TypeInfo;
|
||||
import com.fasterxml.jackson.core.*;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Default implementation of JsonContext.
|
||||
@@ -181,9 +200,9 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(Object value, JsonGenerator generator, PathProperties pathProperties) throws JsonIOException {
|
||||
public void toJson(Object value, JsonGenerator generator, FetchPath fetchPath) throws JsonIOException {
|
||||
// generator passed in so don't close it
|
||||
toJsonNoClose(value, generator, JsonWriteOptions.pathProperties(pathProperties));
|
||||
toJsonNoClose(value, generator, JsonWriteOptions.pathProperties(fetchPath));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -199,14 +218,14 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson(Object value, PathProperties pathProperties) throws JsonIOException {
|
||||
return toJson(value, JsonWriteOptions.pathProperties(pathProperties));
|
||||
public String toJson(Object value, FetchPath fetchPath) throws JsonIOException {
|
||||
return toJson(value, JsonWriteOptions.pathProperties(fetchPath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toJson(Object o, Writer writer, PathProperties pathProperties) throws JsonIOException {
|
||||
public void toJson(Object o, Writer writer, FetchPath fetchPath) throws JsonIOException {
|
||||
// close generator
|
||||
toJsonWithClose(o, createGenerator(writer), JsonWriteOptions.pathProperties(pathProperties));
|
||||
toJsonWithClose(o, createGenerator(writer), JsonWriteOptions.pathProperties(fetchPath));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -288,7 +307,7 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
|
||||
private WriteJson createWriteJson(JsonGenerator gen, JsonWriteOptions options) {
|
||||
PathProperties pathProps = (options == null) ? null : options.getPathProperties();
|
||||
FetchPath pathProps = (options == null) ? null : options.getPathProperties();
|
||||
Map<String, JsonWriteBeanVisitor<?>> visitors = (options == null) ? null : options.getVisitorMap();
|
||||
return new WriteJson(server, gen, pathProps, visitors, determineObjectMapper(options), determineInclude(options));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import com.avaje.ebean.FetchPath;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebean.text.json.JsonIOException;
|
||||
import com.avaje.ebean.text.json.JsonWriteBeanVisitor;
|
||||
import com.avaje.ebean.text.json.JsonWriter;
|
||||
@@ -26,7 +26,7 @@ public class WriteJson implements JsonWriter {
|
||||
|
||||
private final JsonGenerator generator;
|
||||
|
||||
private final PathProperties pathProperties;
|
||||
private final FetchPath fetchPath;
|
||||
|
||||
private final Map<String, JsonWriteBeanVisitor<?>> visitors;
|
||||
|
||||
@@ -41,12 +41,12 @@ public class WriteJson implements JsonWriter {
|
||||
/**
|
||||
* Construct for full bean use (normal).
|
||||
*/
|
||||
public WriteJson(SpiEbeanServer server, JsonGenerator generator, PathProperties pathProperties,
|
||||
public WriteJson(SpiEbeanServer server, JsonGenerator generator, FetchPath fetchPath,
|
||||
Map<String, JsonWriteBeanVisitor<?>> visitors, Object objectMapper, JsonConfig.Include include) {
|
||||
|
||||
this.server = server;
|
||||
this.generator = generator;
|
||||
this.pathProperties = pathProperties;
|
||||
this.fetchPath = fetchPath;
|
||||
this.visitors = visitors;
|
||||
this.objectMapper = objectMapper;
|
||||
this.include = include;
|
||||
@@ -62,7 +62,7 @@ public class WriteJson implements JsonWriter {
|
||||
this.include = include;
|
||||
this.visitors = null;
|
||||
this.server = null;
|
||||
this.pathProperties = null;
|
||||
this.fetchPath = null;
|
||||
this.objectMapper = null;
|
||||
this.parentBeans = null;
|
||||
this.pathStack = null;
|
||||
@@ -376,12 +376,12 @@ public class WriteJson implements JsonWriter {
|
||||
|
||||
String path = pathStack.peekWithNull();
|
||||
JsonWriteBeanVisitor visitor = (visitors == null) ? null : visitors.get(path);
|
||||
if (pathProperties == null) {
|
||||
if (fetchPath == null) {
|
||||
return new WriteBean(desc, bean, visitor);
|
||||
}
|
||||
|
||||
boolean explicitAllProps = false;
|
||||
Set<String> currentIncludeProps = pathProperties.get(path);
|
||||
Set<String> currentIncludeProps = fetchPath.getProperties(path);
|
||||
if (currentIncludeProps != null) {
|
||||
explicitAllProps = currentIncludeProps.contains("*");
|
||||
if (explicitAllProps || currentIncludeProps.isEmpty()) {
|
||||
@@ -503,9 +503,9 @@ public class WriteJson implements JsonWriter {
|
||||
}
|
||||
|
||||
public Boolean includeMany(String key) {
|
||||
if (pathProperties != null) {
|
||||
if (fetchPath != null) {
|
||||
String fullPath = pathStack.peekFullPath(key);
|
||||
return pathProperties.hasPath(fullPath);
|
||||
return fetchPath.hasPath(fullPath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user