mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-22 09:30:15 +00:00
Refactor method names SpiJsonReader and DocStore types
This commit is contained in:
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
|
||||
public interface SpiJsonReader {
|
||||
|
||||
PersistenceContext getPersistenceContext();
|
||||
PersistenceContext persistenceContext();
|
||||
|
||||
SpiJsonReader forJson(JsonParser moreJson);
|
||||
|
||||
@@ -20,9 +20,9 @@ public interface SpiJsonReader {
|
||||
|
||||
Object persistenceContextPutIfAbsent(Object id, EntityBean bean, BeanDescriptor<?> beanDesc);
|
||||
|
||||
ObjectMapper getObjectMapper();
|
||||
ObjectMapper mapper();
|
||||
|
||||
JsonParser getParser();
|
||||
JsonParser parser();
|
||||
|
||||
JsonToken nextToken() throws IOException;
|
||||
|
||||
@@ -34,5 +34,5 @@ public interface SpiJsonReader {
|
||||
|
||||
Object readValueUsingObjectMapper(Class<?> propertyType) throws IOException;
|
||||
|
||||
boolean isIntercept();
|
||||
boolean intercept();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public interface SpiJsonWriter extends JsonWriter {
|
||||
/**
|
||||
* Return true if the value is a parent bean.
|
||||
*/
|
||||
boolean isParentBean(Object value);
|
||||
boolean parentBean(Object value);
|
||||
|
||||
/**
|
||||
* Start an assoc one path.
|
||||
|
||||
@@ -323,7 +323,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
|
||||
this.jsonHelp = initJsonHelp();
|
||||
this.draftHelp = new BeanDescriptorDraftHelp<>(this);
|
||||
this.docStoreAdapter = owner.createDocStoreBeanAdapter(this, deploy);
|
||||
this.docStoreQueueId = docStoreAdapter.getQueueId();
|
||||
this.docStoreQueueId = docStoreAdapter.queueId();
|
||||
// Check if there are no cascade save associated beans ( subject to change
|
||||
// in initialiseOther()). Note that if we are in an inheritance hierarchy
|
||||
// then we also need to check every BeanDescriptors in the InheritInfo as
|
||||
@@ -966,7 +966,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
|
||||
*/
|
||||
@Override
|
||||
public boolean isDocStoreMapped() {
|
||||
return docStoreAdapter.isMapped();
|
||||
return docStoreAdapter.mapped();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1072,7 +1072,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
|
||||
* given the transactions requested mode.
|
||||
*/
|
||||
public DocStoreMode docStoreMode(PersistRequest.Type persistType, DocStoreMode txnMode) {
|
||||
return docStoreAdapter.getMode(persistType, txnMode);
|
||||
return docStoreAdapter.mode(persistType, txnMode);
|
||||
}
|
||||
|
||||
public void docStoreInsert(Object idValue, PersistRequestBean<T> persistRequest, DocStoreUpdateContext bulkUpdate) throws IOException {
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ class BeanDescriptorElementEmbeddedMap<T> extends BeanDescriptorElementEmbedded<
|
||||
|
||||
@Override
|
||||
public Object jsonReadCollection(SpiJsonReader readJson, EntityBean parentBean) throws IOException {
|
||||
JsonParser parser = readJson.getParser();
|
||||
JsonParser parser = readJson.parser();
|
||||
ElementCollector add = elementHelp.createCollector();
|
||||
do {
|
||||
String fieldName = parser.nextFieldName();
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ class BeanDescriptorElementScalar<T> extends BeanDescriptorElement<T> {
|
||||
|
||||
@Override
|
||||
public Object jsonReadCollection(SpiJsonReader readJson, EntityBean parentBean) throws IOException {
|
||||
JsonParser parser = readJson.getParser();
|
||||
JsonParser parser = readJson.parser();
|
||||
ElementCollector add = elementHelp.createCollector();
|
||||
do {
|
||||
JsonToken token = parser.nextToken();
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ class BeanDescriptorElementScalarMap<T> extends BeanDescriptorElement<T> {
|
||||
|
||||
@Override
|
||||
public Object jsonReadCollection(SpiJsonReader readJson, EntityBean parentBean) throws IOException {
|
||||
JsonParser parser = readJson.getParser();
|
||||
JsonParser parser = readJson.parser();
|
||||
ElementCollector add = elementHelp.createCollector();
|
||||
do {
|
||||
String fieldName = parser.nextFieldName();
|
||||
|
||||
@@ -66,7 +66,7 @@ final class BeanDescriptorJsonHelp<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T jsonRead(SpiJsonReader jsonRead, String path, boolean withInheritance, T target) throws IOException {
|
||||
JsonParser parser = jsonRead.getParser();
|
||||
JsonParser parser = jsonRead.parser();
|
||||
//noinspection StatementWithEmptyBody
|
||||
if (parser.getCurrentToken() == JsonToken.START_OBJECT) {
|
||||
// start object token read by Jackson already
|
||||
@@ -85,7 +85,7 @@ final class BeanDescriptorJsonHelp<T> {
|
||||
return jsonReadObject(jsonRead, path, target);
|
||||
}
|
||||
|
||||
ObjectNode node = jsonRead.getObjectMapper().readTree(parser);
|
||||
ObjectNode node = jsonRead.mapper().readTree(parser);
|
||||
if (node.isNull()) {
|
||||
return null;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ final class BeanDescriptorJsonHelp<T> {
|
||||
// unmapped properties, send to JsonReadBeanVisitor later
|
||||
Map<String, Object> unmappedProperties = null;
|
||||
do {
|
||||
JsonParser parser = readJson.getParser();
|
||||
JsonParser parser = readJson.parser();
|
||||
JsonToken event = parser.nextToken();
|
||||
if (JsonToken.FIELD_NAME == event) {
|
||||
String key = parser.getCurrentName();
|
||||
|
||||
@@ -1407,7 +1407,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
JsonToken event = ctx.nextToken();
|
||||
if (JsonToken.VALUE_NULL == event) {
|
||||
if (jsonDeserialize) {
|
||||
if (ctx.isIntercept()) {
|
||||
if (ctx.intercept()) {
|
||||
setValueIntercept(bean, null);
|
||||
} else {
|
||||
setValue(bean, null);
|
||||
@@ -1417,7 +1417,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
// expect to read non-null json value
|
||||
Object objValue;
|
||||
if (scalarType != null) {
|
||||
objValue = scalarType.jsonRead(ctx.getParser());
|
||||
objValue = scalarType.jsonRead(ctx.parser());
|
||||
} else {
|
||||
try {
|
||||
objValue = ctx.readValueUsingObjectMapper(propertyType);
|
||||
@@ -1430,7 +1430,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
}
|
||||
}
|
||||
if (jsonDeserialize) {
|
||||
if (ctx.isIntercept()) {
|
||||
if (ctx.intercept()) {
|
||||
setValueIntercept(bean, objValue);
|
||||
} else {
|
||||
setValue(bean, objValue);
|
||||
|
||||
@@ -355,7 +355,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
mapping.push(nested);
|
||||
targetDescriptor.docStoreMapping(mapping, fullName);
|
||||
mapping.pop();
|
||||
if (!nested.getChildren().isEmpty()) {
|
||||
if (!nested.children().isEmpty()) {
|
||||
mapping.add(nested);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -998,7 +998,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
*/
|
||||
private Object jsonReadCollection(String json) throws IOException {
|
||||
SpiJsonReader ctx = descriptor.createJsonReader(json);
|
||||
JsonParser parser = ctx.getParser();
|
||||
JsonParser parser = ctx.parser();
|
||||
JsonToken event = parser.nextToken();
|
||||
if (JsonToken.VALUE_NULL == event) {
|
||||
return null;
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ class BeanPropertyAssocManyJsonHelp {
|
||||
if (!this.many.jsonDeserialize) {
|
||||
return;
|
||||
}
|
||||
JsonParser parser = readJson.getParser();
|
||||
JsonParser parser = readJson.parser();
|
||||
JsonToken event = parser.nextToken();
|
||||
if (JsonToken.VALUE_NULL == event) {
|
||||
return;
|
||||
@@ -50,7 +50,7 @@ class BeanPropertyAssocManyJsonHelp {
|
||||
if (JsonToken.START_ARRAY != event && JsonToken.START_OBJECT != event) {
|
||||
throw new JsonParseException(parser, "Unexpected token " + event + " - expecting start array or object");
|
||||
}
|
||||
if (readJson.isIntercept()) {
|
||||
if (readJson.intercept()) {
|
||||
many.setValueIntercept(parentBean, many.jsonReadCollection(readJson, parentBean));
|
||||
} else {
|
||||
many.setValue(parentBean, many.jsonReadCollection(readJson, parentBean));
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ class BeanPropertyAssocManyJsonTransient {
|
||||
* Use Jackson ObjectMapper to read the transient 'many' property.
|
||||
*/
|
||||
void jsonReadUsingObjectMapper(BeanPropertyAssocMany<?> many, SpiJsonReader readJson, EntityBean parentBean) throws IOException {
|
||||
ObjectMapper mapper = readJson.getObjectMapper();
|
||||
ObjectMapper mapper = readJson.mapper();
|
||||
ManyType manyType = many.manyType();
|
||||
|
||||
Object value;
|
||||
@@ -29,11 +29,11 @@ class BeanPropertyAssocManyJsonTransient {
|
||||
TypeFactory typeFactory = mapper.getTypeFactory();
|
||||
JavaType target = typeFactory.constructType(many.targetType());
|
||||
MapType jacksonType = typeFactory.constructMapType(LinkedHashMap.class, TypeFactory.unknownType(), target);
|
||||
value = mapper.readValue(readJson.getParser(), jacksonType);
|
||||
value = mapper.readValue(readJson.parser(), jacksonType);
|
||||
} else {
|
||||
// read list or set using Jackson object mapper
|
||||
CollectionType jacksonType = mapper.getTypeFactory().constructCollectionType(manyType.getCollectionType(), many.targetType());
|
||||
value = mapper.readValue(readJson.getParser(), jacksonType);
|
||||
value = mapper.readValue(readJson.parser(), jacksonType);
|
||||
}
|
||||
many.setValue(parentBean, value);
|
||||
}
|
||||
|
||||
@@ -768,7 +768,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
if (value == null) {
|
||||
writeJson.writeNullField(name);
|
||||
} else {
|
||||
if (!writeJson.isParentBean(value)) {
|
||||
if (!writeJson.parentBean(value)) {
|
||||
// Hmmm, not writing complex non-entity bean
|
||||
if (value instanceof EntityBean) {
|
||||
writeJson.beginAssocOne(name, bean);
|
||||
@@ -785,7 +785,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
if (jsonDeserialize && targetDescriptor != null) {
|
||||
T target = (T) value(bean);
|
||||
T assocBean = targetDescriptor.jsonRead(readJson, name, target);
|
||||
if (readJson.isIntercept()) {
|
||||
if (readJson.intercept()) {
|
||||
setValueIntercept(bean, assocBean);
|
||||
} else {
|
||||
setValue(bean, assocBean);
|
||||
|
||||
+5
-5
@@ -33,7 +33,7 @@ public final class DeployDocPropertyOptions {
|
||||
*/
|
||||
public void setDocSortable(DocSortable doc) {
|
||||
createOptions();
|
||||
mapping.setSortable(true);
|
||||
mapping.sortable(true);
|
||||
setStore(doc.store());
|
||||
setBoost(doc.boost());
|
||||
setNullValue(doc.nullValue());
|
||||
@@ -44,7 +44,7 @@ public final class DeployDocPropertyOptions {
|
||||
*/
|
||||
public void setDocCode(DocCode doc) {
|
||||
createOptions();
|
||||
mapping.setCode(true);
|
||||
mapping.code(true);
|
||||
setStore(doc.store());
|
||||
setBoost(doc.boost());
|
||||
setNullValue(doc.nullValue());
|
||||
@@ -52,19 +52,19 @@ public final class DeployDocPropertyOptions {
|
||||
|
||||
private void setNullValue(String value) {
|
||||
if (!value.isEmpty()) {
|
||||
mapping.setNullValue(value);
|
||||
mapping.nullValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
private void setBoost(float boost) {
|
||||
if (Float.compare(boost, 1.0F) != 0) {
|
||||
mapping.setBoost(boost);
|
||||
mapping.boost(boost);
|
||||
}
|
||||
}
|
||||
|
||||
private void setStore(boolean store) {
|
||||
if (store) {
|
||||
mapping.setStore(true);
|
||||
mapping.store(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public final class DJsonBeanReader<T> implements JsonBeanReader<T> {
|
||||
|
||||
@Override
|
||||
public PersistenceContext getPersistenceContext() {
|
||||
return readJson.getPersistenceContext();
|
||||
return readJson.persistenceContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -86,7 +86,7 @@ public final class ReadJson implements SpiJsonReader {
|
||||
* Return the persistence context being used if any.
|
||||
*/
|
||||
@Override
|
||||
public PersistenceContext getPersistenceContext() {
|
||||
public PersistenceContext persistenceContext() {
|
||||
return persistenceContext;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public final class ReadJson implements SpiJsonReader {
|
||||
* Return the objectMapper used for this request.
|
||||
*/
|
||||
@Override
|
||||
public ObjectMapper getObjectMapper() {
|
||||
public ObjectMapper mapper() {
|
||||
if (objectMapper == null) {
|
||||
throw new IllegalStateException(
|
||||
"Jackson ObjectMapper required but has not set. The ObjectMapper can be set on"
|
||||
@@ -155,7 +155,7 @@ public final class ReadJson implements SpiJsonReader {
|
||||
* Return the JsonParser.
|
||||
*/
|
||||
@Override
|
||||
public JsonParser getParser() {
|
||||
public JsonParser parser() {
|
||||
return parser;
|
||||
}
|
||||
|
||||
@@ -209,14 +209,14 @@ public final class ReadJson implements SpiJsonReader {
|
||||
*/
|
||||
@Override
|
||||
public Object readValueUsingObjectMapper(Class<?> propertyType) throws IOException {
|
||||
return getObjectMapper().readValue(parser, propertyType);
|
||||
return mapper().readValue(parser, propertyType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do we have to set values via intercept or not.
|
||||
*/
|
||||
@Override
|
||||
public boolean isIntercept() {
|
||||
public boolean intercept() {
|
||||
return intercept;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ public final class WriteJson implements SpiJsonWriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParentBean(Object bean) {
|
||||
public boolean parentBean(Object bean) {
|
||||
return !parentBeans.isEmpty() && parentBeans.contains(bean);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,20 +36,20 @@ public interface DocStoreBeanAdapter<T> extends BeanDocType<T> {
|
||||
/**
|
||||
* Return true if this type is mapped for doc storage.
|
||||
*/
|
||||
boolean isMapped();
|
||||
boolean mapped();
|
||||
|
||||
/**
|
||||
* Return the unique queueId for this bean type. This is expected to be a relatively short unique
|
||||
* string (rather than a fully qualified class name).
|
||||
*/
|
||||
String getQueueId();
|
||||
String queueId();
|
||||
|
||||
/**
|
||||
* Determine and return how this persist type will be processed given the transaction mode.
|
||||
* <p>
|
||||
* Some transactions (like bulk updates) might specifically turn off indexing for example.
|
||||
*/
|
||||
DocStoreMode getMode(PersistRequest.Type persistType, DocStoreMode txnMode);
|
||||
DocStoreMode mode(PersistRequest.Type persistType, DocStoreMode txnMode);
|
||||
|
||||
/**
|
||||
* Return the index type for this bean type.
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
* Collection of document store updates that are either sent to the document store
|
||||
* or queued for future processing
|
||||
*/
|
||||
public class DocStoreUpdates {
|
||||
public final class DocStoreUpdates {
|
||||
|
||||
/**
|
||||
* Persist inserts and updates.
|
||||
@@ -87,28 +87,28 @@ public class DocStoreUpdates {
|
||||
/**
|
||||
* Return the persist insert and update requests to be sent to the document store.
|
||||
*/
|
||||
public List<DocStoreUpdate> getPersistEvents() {
|
||||
public List<DocStoreUpdate> persistEvents() {
|
||||
return persistEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return delete events.
|
||||
*/
|
||||
public List<DocStoreUpdate> getDeleteEvents() {
|
||||
public List<DocStoreUpdate> deleteEvents() {
|
||||
return deleteEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of nested update events.
|
||||
*/
|
||||
public List<DocStoreQueueEntry> getNestedEvents() {
|
||||
public List<DocStoreQueueEntry> nestedEvents() {
|
||||
return nestedEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entries for sending to the queue.
|
||||
*/
|
||||
public List<DocStoreQueueEntry> getQueueEntries() {
|
||||
public List<DocStoreQueueEntry> queueEntries() {
|
||||
return queueEntries;
|
||||
}
|
||||
|
||||
|
||||
+8
-17
@@ -12,14 +12,11 @@ import java.util.Stack;
|
||||
/**
|
||||
* Builds the DocumentMapping for a given bean type.
|
||||
*/
|
||||
public class DocMappingBuilder {
|
||||
public final class DocMappingBuilder {
|
||||
|
||||
private final PathProperties paths;
|
||||
|
||||
private final DocStore docStore;
|
||||
|
||||
private final Stack<DocPropertyMapping> properties = new Stack<>();
|
||||
|
||||
private final Map<String, DocPropertyMapping> map = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
@@ -49,12 +46,11 @@ public class DocMappingBuilder {
|
||||
* Add the property mapping.
|
||||
*/
|
||||
public void add(DocPropertyMapping docMapping) {
|
||||
|
||||
DocPropertyMapping currentParent = properties.peek();
|
||||
currentParent.addChild(docMapping);
|
||||
|
||||
String parentName = currentParent.getName();
|
||||
String fullName = SplitName.add(parentName, docMapping.getName());
|
||||
String parentName = currentParent.name();
|
||||
String fullName = SplitName.add(parentName, docMapping.name());
|
||||
map.put(fullName, docMapping);
|
||||
}
|
||||
|
||||
@@ -82,7 +78,6 @@ public class DocMappingBuilder {
|
||||
}
|
||||
|
||||
private void applyFieldMapping(DocMapping docMapping) {
|
||||
|
||||
DocPropertyMapping mapping = map.get(docMapping.name());
|
||||
if (mapping == null) {
|
||||
throw new IllegalStateException("DocMapping for [" + docMapping.name() + "] but property not included in document?");
|
||||
@@ -94,19 +89,16 @@ public class DocMappingBuilder {
|
||||
* Collect the mapping of properties to 'raw' properties for those marked as sortable.
|
||||
*/
|
||||
public Map<String, String> collectSortable() {
|
||||
|
||||
DocPropertyMapping peek = properties.peek();
|
||||
SortableVisitor visitor = new SortableVisitor();
|
||||
peek.visit(visitor);
|
||||
|
||||
return visitor.getSortableMap();
|
||||
return visitor.sortableMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the document mapping.
|
||||
*/
|
||||
public DocumentMapping create(String queueId, String indexName, String indexType) {
|
||||
|
||||
int shards = docStore.shards();
|
||||
int replicas = docStore.replicas();
|
||||
DocPropertyMapping root = properties.peek();
|
||||
@@ -119,19 +111,18 @@ public class DocMappingBuilder {
|
||||
*/
|
||||
private static class SortableVisitor extends DocPropertyAdapter {
|
||||
|
||||
private Map<String, String> sortableMap = new LinkedHashMap<>();
|
||||
private final Map<String, String> sortableMap = new LinkedHashMap<>();
|
||||
|
||||
@Override
|
||||
public void visitProperty(DocPropertyMapping property) {
|
||||
|
||||
DocPropertyOptions options = property.getOptions();
|
||||
DocPropertyOptions options = property.options();
|
||||
if (options != null && options.isSortable()) {
|
||||
String fullPath = pathStack.peekFullPath(property.getName());
|
||||
String fullPath = pathStack.peekFullPath(property.name());
|
||||
sortableMap.put(fullPath, fullPath + ".raw");
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getSortableMap() {
|
||||
private Map<String, String> sortableMap() {
|
||||
return sortableMap;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ public abstract class DocPropertyAdapter implements DocPropertyVisitor {
|
||||
|
||||
@Override
|
||||
public void visitBeginObject(DocPropertyMapping property) {
|
||||
pathStack.push(property.getName());
|
||||
pathStack.push(property.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,7 +37,7 @@ public abstract class DocPropertyAdapter implements DocPropertyVisitor {
|
||||
|
||||
@Override
|
||||
public void visitBeginList(DocPropertyMapping property) {
|
||||
pathStack.push(property.getName());
|
||||
pathStack.push(property.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+8
-12
@@ -9,15 +9,12 @@ import java.util.List;
|
||||
/**
|
||||
* Property mapping in a doc store document structure.
|
||||
*/
|
||||
public class DocPropertyMapping {
|
||||
public final class DocPropertyMapping {
|
||||
|
||||
private String name;
|
||||
|
||||
private DocPropertyType type;
|
||||
|
||||
private DocPropertyOptions options;
|
||||
|
||||
private List<DocPropertyMapping> children = new ArrayList<>();
|
||||
private final List<DocPropertyMapping> children = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Construct ROOT.
|
||||
@@ -70,7 +67,6 @@ public class DocPropertyMapping {
|
||||
}
|
||||
|
||||
private void visitChildren(DocPropertyVisitor visitor) {
|
||||
|
||||
for (DocPropertyMapping property : children) {
|
||||
property.visit(visitor);
|
||||
}
|
||||
@@ -78,41 +74,41 @@ public class DocPropertyMapping {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "name:" + name + " type:" + type + " options(" + options + ")";
|
||||
return "name:" + name + " type:" + type + " options:" + options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the property.
|
||||
*/
|
||||
public DocPropertyType getType() {
|
||||
public DocPropertyType type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of the property.
|
||||
*/
|
||||
public void setType(DocPropertyType type) {
|
||||
public void type(DocPropertyType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the property name.
|
||||
*/
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the property options.
|
||||
*/
|
||||
public DocPropertyOptions getOptions() {
|
||||
public DocPropertyOptions options() {
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the child nested properties.
|
||||
*/
|
||||
public List<DocPropertyMapping> getChildren() {
|
||||
public List<DocPropertyMapping> children() {
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
+28
-42
@@ -6,45 +6,32 @@ import io.ebean.annotation.DocProperty;
|
||||
/**
|
||||
* Options for mapping a property for document storage.
|
||||
*/
|
||||
public class DocPropertyOptions {
|
||||
public final class DocPropertyOptions {
|
||||
|
||||
private Boolean code;
|
||||
|
||||
private Boolean sortable;
|
||||
|
||||
private Boolean store;
|
||||
|
||||
private Float boost;
|
||||
|
||||
private String nullValue;
|
||||
|
||||
private Boolean includeInAll;
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
private Boolean norms;
|
||||
|
||||
private Boolean docValues;
|
||||
|
||||
private String analyzer;
|
||||
|
||||
private String searchAnalyzer;
|
||||
|
||||
private String copyTo;
|
||||
|
||||
private DocProperty.Option options;
|
||||
|
||||
/**
|
||||
* Construct with no values set.
|
||||
*/
|
||||
public DocPropertyOptions() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct as a copy of the source options.
|
||||
*/
|
||||
protected DocPropertyOptions(DocPropertyOptions source) {
|
||||
DocPropertyOptions(DocPropertyOptions source) {
|
||||
this.code = source.code;
|
||||
this.sortable = source.sortable;
|
||||
this.store = source.store;
|
||||
@@ -85,11 +72,11 @@ public class DocPropertyOptions {
|
||||
return Boolean.TRUE.equals(code);
|
||||
}
|
||||
|
||||
public Boolean getCode() {
|
||||
public Boolean code() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Boolean code) {
|
||||
public void code(Boolean code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@@ -97,91 +84,91 @@ public class DocPropertyOptions {
|
||||
return Boolean.TRUE.equals(sortable);
|
||||
}
|
||||
|
||||
public Boolean getSortable() {
|
||||
public Boolean sortable() {
|
||||
return sortable;
|
||||
}
|
||||
|
||||
public void setSortable(Boolean sortable) {
|
||||
public void sortable(Boolean sortable) {
|
||||
this.sortable = sortable;
|
||||
}
|
||||
|
||||
public Float getBoost() {
|
||||
public Float boost() {
|
||||
return boost;
|
||||
}
|
||||
|
||||
public void setBoost(Float boost) {
|
||||
public void boost(Float boost) {
|
||||
this.boost = boost;
|
||||
}
|
||||
|
||||
public String getNullValue() {
|
||||
public String nullValue() {
|
||||
return nullValue;
|
||||
}
|
||||
|
||||
public void setNullValue(String nullValue) {
|
||||
public void nullValue(String nullValue) {
|
||||
this.nullValue = nullValue;
|
||||
}
|
||||
|
||||
public Boolean getStore() {
|
||||
public Boolean store() {
|
||||
return store;
|
||||
}
|
||||
|
||||
public void setStore(Boolean store) {
|
||||
public void store(Boolean store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
public Boolean getIncludeInAll() {
|
||||
public Boolean includeInAll() {
|
||||
return includeInAll;
|
||||
}
|
||||
|
||||
public void setIncludeInAll(Boolean includeInAll) {
|
||||
public void includeInAll(Boolean includeInAll) {
|
||||
this.includeInAll = includeInAll;
|
||||
}
|
||||
|
||||
public Boolean getDocValues() {
|
||||
public Boolean docValues() {
|
||||
return docValues;
|
||||
}
|
||||
|
||||
public void setDocValues(Boolean docValues) {
|
||||
public void docValues(Boolean docValues) {
|
||||
this.docValues = docValues;
|
||||
}
|
||||
|
||||
public String getAnalyzer() {
|
||||
public String analyzer() {
|
||||
return analyzer;
|
||||
}
|
||||
|
||||
public void setAnalyzer(String analyzer) {
|
||||
public void analyzer(String analyzer) {
|
||||
this.analyzer = analyzer;
|
||||
}
|
||||
|
||||
public String getSearchAnalyzer() {
|
||||
public String searchAnalyzer() {
|
||||
return searchAnalyzer;
|
||||
}
|
||||
|
||||
public void setSearchAnalyzer(String searchAnalyzer) {
|
||||
public void searchAnalyzer(String searchAnalyzer) {
|
||||
this.searchAnalyzer = searchAnalyzer;
|
||||
}
|
||||
|
||||
public String getCopyTo() {
|
||||
public String copyTo() {
|
||||
return copyTo;
|
||||
}
|
||||
|
||||
public void setCopyTo(String copyTo) {
|
||||
public void copyTo(String copyTo) {
|
||||
this.copyTo = copyTo;
|
||||
}
|
||||
|
||||
public Boolean getEnabled() {
|
||||
public Boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
public void enabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Boolean getNorms() {
|
||||
public Boolean norms() {
|
||||
return norms;
|
||||
}
|
||||
|
||||
public void setNorms(Boolean norms) {
|
||||
public void norms(Boolean norms) {
|
||||
this.norms = norms;
|
||||
}
|
||||
|
||||
@@ -192,11 +179,11 @@ public class DocPropertyOptions {
|
||||
return options != null && options != DocProperty.Option.DEFAULT;
|
||||
}
|
||||
|
||||
public DocProperty.Option getOptions() {
|
||||
public DocProperty.Option options() {
|
||||
return options;
|
||||
}
|
||||
|
||||
public void setOptions(DocProperty.Option options) {
|
||||
public void options(DocProperty.Option options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@@ -218,7 +205,6 @@ public class DocPropertyOptions {
|
||||
* Apply the property level mapping options.
|
||||
*/
|
||||
public void apply(DocProperty docMapping) {
|
||||
|
||||
options = docMapping.options();
|
||||
if (docMapping.code()) {
|
||||
code = true;
|
||||
|
||||
+10
-16
@@ -6,20 +6,14 @@ import io.ebean.docstore.DocMapping;
|
||||
/**
|
||||
* Mapping for a document stored in a doc store (like ElasticSearch).
|
||||
*/
|
||||
public class DocumentMapping implements DocMapping {
|
||||
public final class DocumentMapping implements DocMapping {
|
||||
|
||||
protected final String queueId;
|
||||
|
||||
protected final String name;
|
||||
|
||||
protected final String type;
|
||||
|
||||
protected final FetchPath paths;
|
||||
|
||||
protected final DocPropertyMapping properties;
|
||||
|
||||
protected int shards;
|
||||
|
||||
protected int replicas;
|
||||
|
||||
public DocumentMapping(String queueId, String name, String type, FetchPath paths, DocPropertyMapping properties, int shards, int replicas) {
|
||||
@@ -42,63 +36,63 @@ public class DocumentMapping implements DocMapping {
|
||||
/**
|
||||
* Return the queueId.
|
||||
*/
|
||||
public String getQueueId() {
|
||||
public String queueId() {
|
||||
return queueId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name.
|
||||
*/
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type.
|
||||
*/
|
||||
public String getType() {
|
||||
public String type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the document structure as PathProperties.
|
||||
*/
|
||||
public FetchPath getPaths() {
|
||||
public FetchPath paths() {
|
||||
return paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the document structure with mapping details.
|
||||
*/
|
||||
public DocPropertyMapping getProperties() {
|
||||
public DocPropertyMapping properties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of shards.
|
||||
*/
|
||||
public int getShards() {
|
||||
public int shards() {
|
||||
return shards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of shards.
|
||||
*/
|
||||
public void setShards(int shards) {
|
||||
public void shards(int shards) {
|
||||
this.shards = shards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of replicas.
|
||||
*/
|
||||
public int getReplicas() {
|
||||
public int replicas() {
|
||||
return replicas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of replicas.
|
||||
*/
|
||||
public void setReplicas(int replicas) {
|
||||
public void replicas(int replicas) {
|
||||
this.replicas = replicas;
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -196,24 +196,24 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
|
||||
update = DocStoreMode.UPDATE;
|
||||
}
|
||||
}
|
||||
embeddedInvalidation.add(getEmbeddedInvalidation(queueId, path, properties));
|
||||
embeddedInvalidation.add(embeddedInvalidation(queueId, path, properties));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DsInvalidationListener based on the properties, path.
|
||||
*/
|
||||
protected DocStoreEmbeddedInvalidation getEmbeddedInvalidation(String queueId, String path, Set<String> properties) {
|
||||
protected DocStoreEmbeddedInvalidation embeddedInvalidation(String queueId, String path, Set<String> properties) {
|
||||
if (properties.contains("*")) {
|
||||
return new DocStoreEmbeddedInvalidation(queueId, path);
|
||||
} else {
|
||||
return new DocStoreEmbeddedInvalidationProperties(queueId, path, getPropertyPositions(properties));
|
||||
return new DocStoreEmbeddedInvalidationProperties(queueId, path, propertyPositions(properties));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the property names as property index positions.
|
||||
*/
|
||||
protected int[] getPropertyPositions(Set<String> properties) {
|
||||
protected int[] propertyPositions(Set<String> properties) {
|
||||
List<Integer> posList = new ArrayList<>();
|
||||
for (String property : properties) {
|
||||
BeanProperty prop = desc.beanProperty(property);
|
||||
@@ -244,10 +244,10 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
|
||||
if (pathProps == null) {
|
||||
pathProps = new PathProperties();
|
||||
}
|
||||
return getDocStructure(pathProps, includeByDefault);
|
||||
return docStructure(pathProps, includeByDefault);
|
||||
}
|
||||
|
||||
protected DocStructure getDocStructure(PathProperties pathProps, final boolean includeByDefault) {
|
||||
protected DocStructure docStructure(PathProperties pathProps, final boolean includeByDefault) {
|
||||
final DocStructure docStructure = new DocStructure(pathProps);
|
||||
BeanProperty[] properties = desc.propertiesNonTransient();
|
||||
for (BeanProperty property : properties) {
|
||||
@@ -267,35 +267,35 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
|
||||
|
||||
@Override
|
||||
public FetchPath embedded(String path) {
|
||||
return docStructure.getEmbedded(path);
|
||||
return docStructure.embedded(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchPath embeddedManyRoot(String path) {
|
||||
return docStructure.getEmbeddedManyRoot(path);
|
||||
return docStructure.embeddedManyRoot(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMapped() {
|
||||
public boolean mapped() {
|
||||
return mapped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueueId() {
|
||||
public String queueId() {
|
||||
return queueId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocStoreMode getMode(PersistRequest.Type persistType, DocStoreMode txnMode) {
|
||||
public DocStoreMode mode(PersistRequest.Type persistType, DocStoreMode txnMode) {
|
||||
if (txnMode == null) {
|
||||
return getMode(persistType);
|
||||
return mode(persistType);
|
||||
} else if (txnMode == DocStoreMode.IGNORE) {
|
||||
return DocStoreMode.IGNORE;
|
||||
}
|
||||
return mapped ? txnMode : getMode(persistType);
|
||||
return mapped ? txnMode : mode(persistType);
|
||||
}
|
||||
|
||||
private DocStoreMode getMode(PersistRequest.Type persistType) {
|
||||
private DocStoreMode mode(PersistRequest.Type persistType) {
|
||||
switch (persistType) {
|
||||
case INSERT:
|
||||
return insert;
|
||||
|
||||
+1
-2
@@ -10,10 +10,9 @@ import java.io.IOException;
|
||||
/**
|
||||
* A 'Delete by Id' request that is send to the document store.
|
||||
*/
|
||||
public class DocStoreDeleteEvent implements DocStoreUpdate {
|
||||
public final class DocStoreDeleteEvent implements DocStoreUpdate {
|
||||
|
||||
private final BeanType<?> beanType;
|
||||
|
||||
private final Object idValue;
|
||||
|
||||
public DocStoreDeleteEvent(BeanType<?> beanType, Object idValue) {
|
||||
|
||||
-1
@@ -9,7 +9,6 @@ import io.ebeanservice.docstore.api.DocStoreUpdates;
|
||||
public class DocStoreEmbeddedInvalidation {
|
||||
|
||||
protected final String queueId;
|
||||
|
||||
protected final String path;
|
||||
|
||||
public DocStoreEmbeddedInvalidation(String queueId, String path) {
|
||||
|
||||
+1
-3
@@ -10,12 +10,10 @@ import java.io.IOException;
|
||||
/**
|
||||
* A 'Delete by Id' request that is send to the document store.
|
||||
*/
|
||||
public class DocStoreIndexEvent<T> implements DocStoreUpdate {
|
||||
public final class DocStoreIndexEvent<T> implements DocStoreUpdate {
|
||||
|
||||
private final BeanType<T> beanType;
|
||||
|
||||
private final Object idValue;
|
||||
|
||||
private final T bean;
|
||||
|
||||
public DocStoreIndexEvent(BeanType<T> beanType, Object idValue, T bean) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Document structure for mapping to document store.
|
||||
*/
|
||||
public class DocStructure {
|
||||
public final class DocStructure {
|
||||
|
||||
/**
|
||||
* The full document structure.
|
||||
@@ -58,11 +58,11 @@ public class DocStructure {
|
||||
/**
|
||||
* Return the document structure for an embedded path.
|
||||
*/
|
||||
public FetchPath getEmbedded(String path) {
|
||||
public FetchPath embedded(String path) {
|
||||
return embedded.get(path);
|
||||
}
|
||||
|
||||
public FetchPath getEmbeddedManyRoot(String path) {
|
||||
public FetchPath embeddedManyRoot(String path) {
|
||||
return manyRoot.get(path);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,6 @@ public class DocStructure {
|
||||
* Add a PathProperties for an embedded 'many' property (at the root level).
|
||||
*/
|
||||
private void prepare(String prop, BeanPropertyAssoc<?> embProp) {
|
||||
|
||||
BeanDescriptor<?> targetDesc = embProp.targetDescriptor();
|
||||
|
||||
PathProperties manyRootPath = new PathProperties();
|
||||
|
||||
@@ -19,7 +19,7 @@ public final class NoneDocStoreBeanAdapter<T> extends DocStoreBeanBaseAdapter<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMapped() {
|
||||
public boolean mapped() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -18,7 +18,7 @@ public class BeanDescriptor_documentMappingTest extends BaseTest {
|
||||
|
||||
DocumentMapping documentMapping = desc.docMapping();
|
||||
|
||||
DocPropertyMapping properties = documentMapping.getProperties();
|
||||
DocPropertyMapping properties = documentMapping.properties();
|
||||
|
||||
assertThat(properties).isNotNull();
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class BeanDescriptor_documentMappingTest extends BaseTest {
|
||||
|
||||
DocumentMapping documentMapping = desc.docMapping();
|
||||
|
||||
DocPropertyMapping properties = documentMapping.getProperties();
|
||||
DocPropertyMapping properties = documentMapping.properties();
|
||||
|
||||
assertThat(properties).isNotNull();
|
||||
|
||||
@@ -46,7 +46,7 @@ public class BeanDescriptor_documentMappingTest extends BaseTest {
|
||||
|
||||
@Override
|
||||
public void visitProperty(DocPropertyMapping property) {
|
||||
sb.append(property.getName() + ",");
|
||||
sb.append(property.name() + ",");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +62,7 @@ public class BeanDescriptor_documentMappingTest extends BaseTest {
|
||||
|
||||
@Override
|
||||
public void visitBeginObject(DocPropertyMapping property) {
|
||||
sb.append(" object{" + property.getName() + ":");
|
||||
sb.append(" object{" + property.name() + ":");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,7 +72,7 @@ public class BeanDescriptor_documentMappingTest extends BaseTest {
|
||||
|
||||
@Override
|
||||
public void visitBeginList(DocPropertyMapping property) {
|
||||
sb.append(" nested{" + property.getName() + ": [");
|
||||
sb.append(" nested{" + property.name() + ": [");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DocStoreBeanBaseAdapterTest extends BaseTestCase {
|
||||
|
||||
Assertions.assertThat(adapter.indexName()).isEqualTo("order");
|
||||
Assertions.assertThat(adapter.indexType()).isEqualTo("order");
|
||||
Assertions.assertThat(adapter.getQueueId()).isEqualTo("order");
|
||||
Assertions.assertThat(adapter.queueId()).isEqualTo("order");
|
||||
}
|
||||
|
||||
static class TDAdapter<T> extends DocStoreBeanBaseAdapter<T> {
|
||||
|
||||
@@ -51,7 +51,7 @@ public class DocStoreDeleteEventTest {
|
||||
DocStoreUpdates updates = new DocStoreUpdates();
|
||||
event.addToQueue(updates);
|
||||
|
||||
List<DocStoreQueueEntry> queueEntries = updates.getQueueEntries();
|
||||
List<DocStoreQueueEntry> queueEntries = updates.queueEntries();
|
||||
assertThat(queueEntries).hasSize(1);
|
||||
|
||||
DocStoreQueueEntry entry = queueEntries.get(0);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class DocStoreIndexEventTest {
|
||||
DocStoreUpdates updates = new DocStoreUpdates();
|
||||
event.addToQueue(updates);
|
||||
|
||||
List<DocStoreQueueEntry> queueEntries = updates.getQueueEntries();
|
||||
List<DocStoreQueueEntry> queueEntries = updates.queueEntries();
|
||||
assertThat(queueEntries).hasSize(1);
|
||||
|
||||
DocStoreQueueEntry entry = queueEntries.get(0);
|
||||
|
||||
Reference in New Issue
Block a user