From 7524903aea8b31f26440d8a5c306316949804e5a Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Thu, 5 Oct 2017 00:29:43 +1300 Subject: [PATCH] #1152 - Refactor EJson internals extracting io.ebean.service.SpiJsonService --- src/main/java/io/ebean/XServiceProvider.java | 2 +- .../java/io/ebean/service/SpiJsonService.java | 125 +++++++++++++ .../{plugin => service}/SpiRawSqlService.java | 4 +- src/main/java/io/ebean/text/json/EJson.java | 65 +++---- .../io/ebeaninternal/json/DJsonService.java | 175 ++++++++++++++++++ .../json/EJsonReader.java | 6 +- .../json/EJsonWriter.java | 2 +- .../type => json}/ModifyAwareFlag.java | 2 +- .../type => json}/ModifyAwareIterator.java | 2 +- .../type => json}/ModifyAwareList.java | 2 +- .../ModifyAwareListIterator.java | 2 +- .../{server/type => json}/ModifyAwareMap.java | 2 +- .../type => json}/ModifyAwareOwner.java | 2 +- .../{server/type => json}/ModifyAwareSet.java | 2 +- .../server/rawsql/DRawSqlService.java | 2 +- .../server/type/ScalarTypeArrayList.java | 1 + .../server/type/ScalarTypeArraySet.java | 1 + .../server/type/ScalarTypeJsonCollection.java | 1 + .../server/type/ScalarTypeJsonMap.java | 1 + .../type/ScalarTypeJsonObjectMapper.java | 4 + .../server/type/ScalarTypePostgresHstore.java | 2 + .../services/io.ebean.service.SpiJsonService | 1 + ...vice => io.ebean.service.SpiRawSqlService} | 0 src/test/java/io/ebean/json/EJsonTests.java | 4 +- .../type => json}/ModifyAwareMapTest.java | 82 ++++---- .../server/type/ModifyAwareFlagTest.java | 1 + .../server/type/ModifyAwareListTest.java | 2 + .../server/type/ModifyAwareSetTest.java | 1 + .../type/ScalarTypePostgresHstoreTest.java | 1 + 29 files changed, 406 insertions(+), 91 deletions(-) create mode 100644 src/main/java/io/ebean/service/SpiJsonService.java rename src/main/java/io/ebean/{plugin => service}/SpiRawSqlService.java (81%) create mode 100644 src/main/java/io/ebeaninternal/json/DJsonService.java rename src/main/java/io/{ebean/text => ebeaninternal}/json/EJsonReader.java (97%) rename src/main/java/io/{ebean/text => ebeaninternal}/json/EJsonWriter.java (99%) rename src/main/java/io/ebeaninternal/{server/type => json}/ModifyAwareFlag.java (92%) rename src/main/java/io/ebeaninternal/{server/type => json}/ModifyAwareIterator.java (94%) rename src/main/java/io/ebeaninternal/{server/type => json}/ModifyAwareList.java (98%) rename src/main/java/io/ebeaninternal/{server/type => json}/ModifyAwareListIterator.java (96%) rename src/main/java/io/ebeaninternal/{server/type => json}/ModifyAwareMap.java (98%) rename src/main/java/io/ebeaninternal/{server/type => json}/ModifyAwareOwner.java (92%) rename src/main/java/io/ebeaninternal/{server/type => json}/ModifyAwareSet.java (98%) create mode 100644 src/main/resources/META-INF/services/io.ebean.service.SpiJsonService rename src/main/resources/META-INF/services/{io.ebean.plugin.SpiRawSqlService => io.ebean.service.SpiRawSqlService} (100%) rename src/test/java/io/ebeaninternal/{server/type => json}/ModifyAwareMapTest.java (66%) diff --git a/src/main/java/io/ebean/XServiceProvider.java b/src/main/java/io/ebean/XServiceProvider.java index 6e7ce4d98..4de4be54c 100644 --- a/src/main/java/io/ebean/XServiceProvider.java +++ b/src/main/java/io/ebean/XServiceProvider.java @@ -1,6 +1,6 @@ package io.ebean; -import io.ebean.plugin.SpiRawSqlService; +import io.ebean.service.SpiRawSqlService; import java.util.Iterator; import java.util.ServiceLoader; diff --git a/src/main/java/io/ebean/service/SpiJsonService.java b/src/main/java/io/ebean/service/SpiJsonService.java new file mode 100644 index 000000000..3536d372b --- /dev/null +++ b/src/main/java/io/ebean/service/SpiJsonService.java @@ -0,0 +1,125 @@ +package io.ebean.service; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * JSON service that Ebean is expected to provide. + * + * Supports converting between JSON content and simple java Maps/Lists. + */ +public interface SpiJsonService { + + /** + * Write the nested Map/List as json. + */ + String write(Object object) throws IOException; + + /** + * Write the nested Map/List as json to the writer. + */ + void write(Object object, Writer writer) throws IOException; + + /** + * Write the nested Map/List as json to the jsonGenerator. + */ + void write(Object object, JsonGenerator jsonGenerator) throws IOException; + + /** + * Write the collection as json array to the jsonGenerator. + */ + void writeCollection(Collection collection, JsonGenerator jsonGenerator) throws IOException; + + /** + * Parse the json and return as a Map additionally specifying if the returned map should + * be modify aware meaning that it can detect when it has been modified. + */ + Map parseObject(String json, boolean modifyAware) throws IOException; + + /** + * Parse the json and return as a Map. + */ + Map parseObject(String json) throws IOException; + + /** + * Parse the json and return as a Map taking a reader. + */ + Map parseObject(Reader reader, boolean modifyAware) throws IOException; + + /** + * Parse the json and return as a Map taking a reader. + */ + Map parseObject(Reader reader) throws IOException; + + /** + * Parse the json and return as a Map taking a JsonParser. + */ + Map parseObject(JsonParser parser) throws IOException; + + /** + * Parse the json and return as a Map taking a JsonParser and a starting token. + *

+ * Used when the first token is checked to see if the value is null prior to calling this. + *

+ */ + Map parseObject(JsonParser parser, JsonToken token) throws IOException; + + /** + * Parse the json and return as a modify aware List. + */ + List parseList(String json, boolean modifyAware) throws IOException; + + /** + * Parse the json and return as a List. + */ + List parseList(String json) throws IOException; + + /** + * Parse the json and return as a List taking a Reader. + */ + List parseList(Reader reader) throws IOException; + + /** + * Parse the json and return as a List taking a JsonParser. + */ + List parseList(JsonParser parser) throws IOException; + + /** + * Parse the json returning as a List taking into account the current token. + */ + List parseList(JsonParser parser, JsonToken currentToken) throws IOException; + + /** + * Parse the json and return as a List or Map. + */ + Object parse(String json) throws IOException; + + /** + * Parse the json and return as a List or Map. + */ + Object parse(Reader reader) throws IOException; + + /** + * Parse the json and return as a List or Map. + */ + Object parse(JsonParser parser) throws IOException; + + /** + * Parse the json returning a Set that might be modify aware. + */ + Set parseSet(String json, boolean modifyAware) throws IOException; + + /** + * Parse the json returning as a Set taking into account the current token. + */ + Set parseSet(JsonParser parser, JsonToken currentToken) throws IOException; +} diff --git a/src/main/java/io/ebean/plugin/SpiRawSqlService.java b/src/main/java/io/ebean/service/SpiRawSqlService.java similarity index 81% rename from src/main/java/io/ebean/plugin/SpiRawSqlService.java rename to src/main/java/io/ebean/service/SpiRawSqlService.java index 67254a6f2..aa668486a 100644 --- a/src/main/java/io/ebean/plugin/SpiRawSqlService.java +++ b/src/main/java/io/ebean/service/SpiRawSqlService.java @@ -1,4 +1,4 @@ -package io.ebean.plugin; +package io.ebean.service; import io.ebean.RawSql; import io.ebean.RawSqlBuilder; @@ -6,7 +6,7 @@ import io.ebean.RawSqlBuilder; import java.sql.ResultSet; /** - * Service provided for parsing and column mapping raw SQL queries. + * Service provided by Ebean for parsing and column mapping raw SQL queries. */ public interface SpiRawSqlService { diff --git a/src/main/java/io/ebean/text/json/EJson.java b/src/main/java/io/ebean/text/json/EJson.java index 93b007625..b33b26dcb 100644 --- a/src/main/java/io/ebean/text/json/EJson.java +++ b/src/main/java/io/ebean/text/json/EJson.java @@ -1,17 +1,18 @@ package io.ebean.text.json; -import io.ebeaninternal.server.type.ModifyAwareList; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import io.ebean.service.SpiJsonService; import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.util.Collection; -import java.util.LinkedHashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.ServiceLoader; import java.util.Set; /** @@ -19,32 +20,43 @@ import java.util.Set; */ public class EJson { + private static SpiJsonService plugin = init(); + + private static SpiJsonService init() { + + Iterator loader = ServiceLoader.load(SpiJsonService.class).iterator(); + if (loader.hasNext()) { + return loader.next(); + } + throw new IllegalStateException("No service implementation found for SpiJsonService?"); + } + /** * Write the nested Map/List as json. */ public static String write(Object object) throws IOException { - return EJsonWriter.write(object); + return plugin.write(object); } /** * Write the nested Map/List as json to the writer. */ public static void write(Object object, Writer writer) throws IOException { - EJsonWriter.write(object, writer); + plugin.write(object, writer); } /** * Write the nested Map/List as json to the jsonGenerator. */ public static void write(Object object, JsonGenerator jsonGenerator) throws IOException { - EJsonWriter.write(object, jsonGenerator); + plugin.write(object, jsonGenerator); } /** * Write the collection as json array to the jsonGenerator. */ public static void writeCollection(Collection collection, JsonGenerator jsonGenerator) throws IOException { - EJsonWriter.writeCollection(collection, jsonGenerator); + plugin.writeCollection(collection, jsonGenerator); } /** @@ -52,35 +64,35 @@ public class EJson { * be modify aware meaning that it can detect when it has been modified. */ public static Map parseObject(String json, boolean modifyAware) throws IOException { - return EJsonReader.parseObject(json, modifyAware); + return plugin.parseObject(json, modifyAware); } /** * Parse the json and return as a Map. */ public static Map parseObject(String json) throws IOException { - return EJsonReader.parseObject(json); + return plugin.parseObject(json); } /** * Parse the json and return as a Map taking a reader. */ public static Map parseObject(Reader reader, boolean modifyAware) throws IOException { - return EJsonReader.parseObject(reader, modifyAware); + return plugin.parseObject(reader, modifyAware); } /** * Parse the json and return as a Map taking a reader. */ public static Map parseObject(Reader reader) throws IOException { - return EJsonReader.parseObject(reader); + return plugin.parseObject(reader); } /** * Parse the json and return as a Map taking a JsonParser. */ public static Map parseObject(JsonParser parser) throws IOException { - return EJsonReader.parseObject(parser); + return plugin.parseObject(parser); } /** @@ -90,35 +102,35 @@ public class EJson { *

*/ public static Map parseObject(JsonParser parser, JsonToken token) throws IOException { - return EJsonReader.parseObject(parser, token); + return plugin.parseObject(parser, token); } /** * Parse the json and return as a modify aware List. */ public static List parseList(String json, boolean modifyAware) throws IOException { - return EJsonReader.parseList(json, modifyAware); + return plugin.parseList(json, modifyAware); } /** * Parse the json and return as a List. */ public static List parseList(String json) throws IOException { - return EJsonReader.parseList(json); + return plugin.parseList(json); } /** * Parse the json and return as a List taking a Reader. */ public static List parseList(Reader reader) throws IOException { - return EJsonReader.parseList(reader); + return plugin.parseList(reader); } /** * Parse the json and return as a List taking a JsonParser. */ public static List parseList(JsonParser parser) throws IOException { - return EJsonReader.parseList(parser, false); + return plugin.parseList(parser); } /** @@ -126,50 +138,41 @@ public class EJson { */ @SuppressWarnings("unchecked") public static List parseList(JsonParser parser, JsonToken currentToken) throws IOException { - return (List) EJsonReader.parse(parser, currentToken, false); + return plugin.parseList(parser, currentToken); } /** * Parse the json and return as a List or Map. */ public static Object parse(String json) throws IOException { - return EJsonReader.parse(json); + return plugin.parse(json); } /** * Parse the json and return as a List or Map. */ public static Object parse(Reader reader) throws IOException { - return EJsonReader.parse(reader); + return plugin.parse(reader); } /** * Parse the json and return as a List or Map. */ public static Object parse(JsonParser parser) throws IOException { - return EJsonReader.parse(parser); + return plugin.parse(parser); } /** * Parse the json returning a Set that might be modify aware. */ public static Set parseSet(String json, boolean modifyAware) throws IOException { - List list = parseList(json, modifyAware); - if (list == null) { - return null; - } - - if (modifyAware) { - return ((ModifyAwareList) list).asSet(); - } else { - return new LinkedHashSet(list); - } + return plugin.parseSet(json, modifyAware); } /** * Parse the json returning as a Set taking into account the current token. */ public static Set parseSet(JsonParser parser, JsonToken currentToken) throws IOException { - return new LinkedHashSet(parseList(parser, currentToken)); + return plugin.parseSet(parser, currentToken); } } diff --git a/src/main/java/io/ebeaninternal/json/DJsonService.java b/src/main/java/io/ebeaninternal/json/DJsonService.java new file mode 100644 index 000000000..8310041b0 --- /dev/null +++ b/src/main/java/io/ebeaninternal/json/DJsonService.java @@ -0,0 +1,175 @@ +package io.ebeaninternal.json; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import io.ebean.service.SpiJsonService; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Utility that converts between JSON content and simple java Maps/Lists. + */ +public class DJsonService implements SpiJsonService { + + /** + * Write the nested Map/List as json. + */ + public String write(Object object) throws IOException { + return EJsonWriter.write(object); + } + + /** + * Write the nested Map/List as json to the writer. + */ + public void write(Object object, Writer writer) throws IOException { + EJsonWriter.write(object, writer); + } + + /** + * Write the nested Map/List as json to the jsonGenerator. + */ + public void write(Object object, JsonGenerator jsonGenerator) throws IOException { + EJsonWriter.write(object, jsonGenerator); + } + + /** + * Write the collection as json array to the jsonGenerator. + */ + public void writeCollection(Collection collection, JsonGenerator jsonGenerator) throws IOException { + EJsonWriter.writeCollection(collection, jsonGenerator); + } + + /** + * Parse the json and return as a Map additionally specifying if the returned map should + * be modify aware meaning that it can detect when it has been modified. + */ + public Map parseObject(String json, boolean modifyAware) throws IOException { + return EJsonReader.parseObject(json, modifyAware); + } + + /** + * Parse the json and return as a Map. + */ + public Map parseObject(String json) throws IOException { + return EJsonReader.parseObject(json); + } + + /** + * Parse the json and return as a Map taking a reader. + */ + public Map parseObject(Reader reader, boolean modifyAware) throws IOException { + return EJsonReader.parseObject(reader, modifyAware); + } + + /** + * Parse the json and return as a Map taking a reader. + */ + public Map parseObject(Reader reader) throws IOException { + return EJsonReader.parseObject(reader); + } + + /** + * Parse the json and return as a Map taking a JsonParser. + */ + public Map parseObject(JsonParser parser) throws IOException { + return EJsonReader.parseObject(parser); + } + + /** + * Parse the json and return as a Map taking a JsonParser and a starting token. + *

+ * Used when the first token is checked to see if the value is null prior to calling this. + *

+ */ + public Map parseObject(JsonParser parser, JsonToken token) throws IOException { + return EJsonReader.parseObject(parser, token); + } + + /** + * Parse the json and return as a modify aware List. + */ + public List parseList(String json, boolean modifyAware) throws IOException { + return EJsonReader.parseList(json, modifyAware); + } + + /** + * Parse the json and return as a List. + */ + public List parseList(String json) throws IOException { + return EJsonReader.parseList(json); + } + + /** + * Parse the json and return as a List taking a Reader. + */ + public List parseList(Reader reader) throws IOException { + return EJsonReader.parseList(reader); + } + + /** + * Parse the json and return as a List taking a JsonParser. + */ + public List parseList(JsonParser parser) throws IOException { + return EJsonReader.parseList(parser, false); + } + + /** + * Parse the json returning as a List taking into account the current token. + */ + @SuppressWarnings("unchecked") + public List parseList(JsonParser parser, JsonToken currentToken) throws IOException { + return (List) EJsonReader.parse(parser, currentToken, false); + } + + /** + * Parse the json and return as a List or Map. + */ + public Object parse(String json) throws IOException { + return EJsonReader.parse(json); + } + + /** + * Parse the json and return as a List or Map. + */ + public Object parse(Reader reader) throws IOException { + return EJsonReader.parse(reader); + } + + /** + * Parse the json and return as a List or Map. + */ + public Object parse(JsonParser parser) throws IOException { + return EJsonReader.parse(parser); + } + + /** + * Parse the json returning a Set that might be modify aware. + */ + public Set parseSet(String json, boolean modifyAware) throws IOException { + List list = parseList(json, modifyAware); + if (list == null) { + return null; + } + + if (modifyAware) { + return ((ModifyAwareList) list).asSet(); + } else { + return new LinkedHashSet(list); + } + } + + /** + * Parse the json returning as a Set taking into account the current token. + */ + public Set parseSet(JsonParser parser, JsonToken currentToken) throws IOException { + return new LinkedHashSet<>(parseList(parser, currentToken)); + } +} diff --git a/src/main/java/io/ebean/text/json/EJsonReader.java b/src/main/java/io/ebeaninternal/json/EJsonReader.java similarity index 97% rename from src/main/java/io/ebean/text/json/EJsonReader.java rename to src/main/java/io/ebeaninternal/json/EJsonReader.java index 8b2992976..2b36f54f5 100644 --- a/src/main/java/io/ebean/text/json/EJsonReader.java +++ b/src/main/java/io/ebeaninternal/json/EJsonReader.java @@ -1,9 +1,5 @@ -package io.ebean.text.json; +package io.ebeaninternal.json; -import io.ebeaninternal.server.type.ModifyAwareFlag; -import io.ebeaninternal.server.type.ModifyAwareList; -import io.ebeaninternal.server.type.ModifyAwareMap; -import io.ebeaninternal.server.type.ModifyAwareOwner; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; diff --git a/src/main/java/io/ebean/text/json/EJsonWriter.java b/src/main/java/io/ebeaninternal/json/EJsonWriter.java similarity index 99% rename from src/main/java/io/ebean/text/json/EJsonWriter.java rename to src/main/java/io/ebeaninternal/json/EJsonWriter.java index 2e9d7b87c..1c110c077 100644 --- a/src/main/java/io/ebean/text/json/EJsonWriter.java +++ b/src/main/java/io/ebeaninternal/json/EJsonWriter.java @@ -1,4 +1,4 @@ -package io.ebean.text.json; +package io.ebeaninternal.json; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; diff --git a/src/main/java/io/ebeaninternal/server/type/ModifyAwareFlag.java b/src/main/java/io/ebeaninternal/json/ModifyAwareFlag.java similarity index 92% rename from src/main/java/io/ebeaninternal/server/type/ModifyAwareFlag.java rename to src/main/java/io/ebeaninternal/json/ModifyAwareFlag.java index d7e827f39..45b6d9ab9 100644 --- a/src/main/java/io/ebeaninternal/server/type/ModifyAwareFlag.java +++ b/src/main/java/io/ebeaninternal/json/ModifyAwareFlag.java @@ -1,4 +1,4 @@ -package io.ebeaninternal.server.type; +package io.ebeaninternal.json; /** * Detects when content has been modified and as such needs to be persisted (included in an update). diff --git a/src/main/java/io/ebeaninternal/server/type/ModifyAwareIterator.java b/src/main/java/io/ebeaninternal/json/ModifyAwareIterator.java similarity index 94% rename from src/main/java/io/ebeaninternal/server/type/ModifyAwareIterator.java rename to src/main/java/io/ebeaninternal/json/ModifyAwareIterator.java index 22814c873..848395782 100644 --- a/src/main/java/io/ebeaninternal/server/type/ModifyAwareIterator.java +++ b/src/main/java/io/ebeaninternal/json/ModifyAwareIterator.java @@ -1,4 +1,4 @@ -package io.ebeaninternal.server.type; +package io.ebeaninternal.json; import java.util.Iterator; diff --git a/src/main/java/io/ebeaninternal/server/type/ModifyAwareList.java b/src/main/java/io/ebeaninternal/json/ModifyAwareList.java similarity index 98% rename from src/main/java/io/ebeaninternal/server/type/ModifyAwareList.java rename to src/main/java/io/ebeaninternal/json/ModifyAwareList.java index 4862081bc..8119bf015 100644 --- a/src/main/java/io/ebeaninternal/server/type/ModifyAwareList.java +++ b/src/main/java/io/ebeaninternal/json/ModifyAwareList.java @@ -1,4 +1,4 @@ -package io.ebeaninternal.server.type; +package io.ebeaninternal.json; import java.util.Collection; import java.util.Iterator; diff --git a/src/main/java/io/ebeaninternal/server/type/ModifyAwareListIterator.java b/src/main/java/io/ebeaninternal/json/ModifyAwareListIterator.java similarity index 96% rename from src/main/java/io/ebeaninternal/server/type/ModifyAwareListIterator.java rename to src/main/java/io/ebeaninternal/json/ModifyAwareListIterator.java index 81732d44f..9b57442f3 100644 --- a/src/main/java/io/ebeaninternal/server/type/ModifyAwareListIterator.java +++ b/src/main/java/io/ebeaninternal/json/ModifyAwareListIterator.java @@ -1,4 +1,4 @@ -package io.ebeaninternal.server.type; +package io.ebeaninternal.json; import java.util.ListIterator; diff --git a/src/main/java/io/ebeaninternal/server/type/ModifyAwareMap.java b/src/main/java/io/ebeaninternal/json/ModifyAwareMap.java similarity index 98% rename from src/main/java/io/ebeaninternal/server/type/ModifyAwareMap.java rename to src/main/java/io/ebeaninternal/json/ModifyAwareMap.java index c028af31d..efea112ff 100644 --- a/src/main/java/io/ebeaninternal/server/type/ModifyAwareMap.java +++ b/src/main/java/io/ebeaninternal/json/ModifyAwareMap.java @@ -1,4 +1,4 @@ -package io.ebeaninternal.server.type; +package io.ebeaninternal.json; import java.util.Collection; import java.util.LinkedHashSet; diff --git a/src/main/java/io/ebeaninternal/server/type/ModifyAwareOwner.java b/src/main/java/io/ebeaninternal/json/ModifyAwareOwner.java similarity index 92% rename from src/main/java/io/ebeaninternal/server/type/ModifyAwareOwner.java rename to src/main/java/io/ebeaninternal/json/ModifyAwareOwner.java index 47976986e..6d3b048d5 100644 --- a/src/main/java/io/ebeaninternal/server/type/ModifyAwareOwner.java +++ b/src/main/java/io/ebeaninternal/json/ModifyAwareOwner.java @@ -1,4 +1,4 @@ -package io.ebeaninternal.server.type; +package io.ebeaninternal.json; import java.io.Serializable; diff --git a/src/main/java/io/ebeaninternal/server/type/ModifyAwareSet.java b/src/main/java/io/ebeaninternal/json/ModifyAwareSet.java similarity index 98% rename from src/main/java/io/ebeaninternal/server/type/ModifyAwareSet.java rename to src/main/java/io/ebeaninternal/json/ModifyAwareSet.java index 70147b99f..d7e31597a 100644 --- a/src/main/java/io/ebeaninternal/server/type/ModifyAwareSet.java +++ b/src/main/java/io/ebeaninternal/json/ModifyAwareSet.java @@ -1,4 +1,4 @@ -package io.ebeaninternal.server.type; +package io.ebeaninternal.json; import java.util.Collection; import java.util.Iterator; diff --git a/src/main/java/io/ebeaninternal/server/rawsql/DRawSqlService.java b/src/main/java/io/ebeaninternal/server/rawsql/DRawSqlService.java index 12207fc1a..fe33d1bbc 100644 --- a/src/main/java/io/ebeaninternal/server/rawsql/DRawSqlService.java +++ b/src/main/java/io/ebeaninternal/server/rawsql/DRawSqlService.java @@ -2,7 +2,7 @@ package io.ebeaninternal.server.rawsql; import io.ebean.RawSql; import io.ebean.RawSqlBuilder; -import io.ebean.plugin.SpiRawSqlService; +import io.ebean.service.SpiRawSqlService; import java.sql.ResultSet; diff --git a/src/main/java/io/ebeaninternal/server/type/ScalarTypeArrayList.java b/src/main/java/io/ebeaninternal/server/type/ScalarTypeArrayList.java index ceb0de3b7..2548fe60b 100644 --- a/src/main/java/io/ebeaninternal/server/type/ScalarTypeArrayList.java +++ b/src/main/java/io/ebeaninternal/server/type/ScalarTypeArrayList.java @@ -2,6 +2,7 @@ package io.ebeaninternal.server.type; import io.ebean.text.json.EJson; +import io.ebeaninternal.json.ModifyAwareList; import io.ebeanservice.docstore.api.mapping.DocPropertyType; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; diff --git a/src/main/java/io/ebeaninternal/server/type/ScalarTypeArraySet.java b/src/main/java/io/ebeaninternal/server/type/ScalarTypeArraySet.java index 8181ba46c..d12cea509 100644 --- a/src/main/java/io/ebeaninternal/server/type/ScalarTypeArraySet.java +++ b/src/main/java/io/ebeaninternal/server/type/ScalarTypeArraySet.java @@ -4,6 +4,7 @@ package io.ebeaninternal.server.type; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import io.ebean.text.json.EJson; +import io.ebeaninternal.json.ModifyAwareSet; import io.ebeanservice.docstore.api.mapping.DocPropertyType; import javax.persistence.PersistenceException; diff --git a/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java b/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java index 534ce2d48..27f12b84a 100644 --- a/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java +++ b/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.type; +import io.ebeaninternal.json.ModifyAwareOwner; import io.ebeanservice.docstore.api.mapping.DocPropertyType; import java.io.DataInput; diff --git a/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java b/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java index 9e6f4cc84..d67faa659 100644 --- a/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java +++ b/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java @@ -3,6 +3,7 @@ package io.ebeaninternal.server.type; import io.ebean.config.dbplatform.DbPlatformType; import io.ebean.text.TextException; import io.ebean.text.json.EJson; +import io.ebeaninternal.json.ModifyAwareOwner; import io.ebeaninternal.util.EncodeUtil; import io.ebeanservice.docstore.api.mapping.DocPropertyType; import com.fasterxml.jackson.core.JsonGenerator; diff --git a/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java b/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java index 4e8b8e4ed..fa2e61837 100644 --- a/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java +++ b/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java @@ -1,6 +1,10 @@ package io.ebeaninternal.server.type; import io.ebean.config.dbplatform.DbPlatformType; +import io.ebeaninternal.json.ModifyAwareList; +import io.ebeaninternal.json.ModifyAwareMap; +import io.ebeaninternal.json.ModifyAwareOwner; +import io.ebeaninternal.json.ModifyAwareSet; import io.ebeanservice.docstore.api.mapping.DocPropertyType; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; diff --git a/src/main/java/io/ebeaninternal/server/type/ScalarTypePostgresHstore.java b/src/main/java/io/ebeaninternal/server/type/ScalarTypePostgresHstore.java index 060000b8e..0f5984bdf 100644 --- a/src/main/java/io/ebeaninternal/server/type/ScalarTypePostgresHstore.java +++ b/src/main/java/io/ebeaninternal/server/type/ScalarTypePostgresHstore.java @@ -3,6 +3,8 @@ package io.ebeaninternal.server.type; import io.ebean.config.dbplatform.DbPlatformType; import io.ebean.text.TextException; import io.ebean.text.json.EJson; +import io.ebeaninternal.json.ModifyAwareMap; +import io.ebeaninternal.json.ModifyAwareOwner; import io.ebeanservice.docstore.api.mapping.DocPropertyType; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; diff --git a/src/main/resources/META-INF/services/io.ebean.service.SpiJsonService b/src/main/resources/META-INF/services/io.ebean.service.SpiJsonService new file mode 100644 index 000000000..607dda3ae --- /dev/null +++ b/src/main/resources/META-INF/services/io.ebean.service.SpiJsonService @@ -0,0 +1 @@ +io.ebeaninternal.json.DJsonService diff --git a/src/main/resources/META-INF/services/io.ebean.plugin.SpiRawSqlService b/src/main/resources/META-INF/services/io.ebean.service.SpiRawSqlService similarity index 100% rename from src/main/resources/META-INF/services/io.ebean.plugin.SpiRawSqlService rename to src/main/resources/META-INF/services/io.ebean.service.SpiRawSqlService diff --git a/src/test/java/io/ebean/json/EJsonTests.java b/src/test/java/io/ebean/json/EJsonTests.java index b3d311c7c..2de0dd6b6 100644 --- a/src/test/java/io/ebean/json/EJsonTests.java +++ b/src/test/java/io/ebean/json/EJsonTests.java @@ -1,8 +1,8 @@ package io.ebean.json; import io.ebean.text.json.EJson; -import io.ebeaninternal.server.type.ModifyAwareMap; -import io.ebeaninternal.server.type.ModifyAwareOwner; +import io.ebeaninternal.json.ModifyAwareMap; +import io.ebeaninternal.json.ModifyAwareOwner; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import org.junit.Test; diff --git a/src/test/java/io/ebeaninternal/server/type/ModifyAwareMapTest.java b/src/test/java/io/ebeaninternal/json/ModifyAwareMapTest.java similarity index 66% rename from src/test/java/io/ebeaninternal/server/type/ModifyAwareMapTest.java rename to src/test/java/io/ebeaninternal/json/ModifyAwareMapTest.java index c654dc633..48611e1c7 100644 --- a/src/test/java/io/ebeaninternal/server/type/ModifyAwareMapTest.java +++ b/src/test/java/io/ebeaninternal/json/ModifyAwareMapTest.java @@ -1,5 +1,8 @@ -package io.ebeaninternal.server.type; +package io.ebeaninternal.json; + +import org.assertj.core.api.Assertions; +import org.junit.Assert; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -13,9 +16,6 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; - public class ModifyAwareMapTest { private ModifyAwareMap createMap() { @@ -37,56 +37,56 @@ public class ModifyAwareMapTest { public void testToString() throws Exception { ModifyAwareMap map = createMap(); - assertEquals(map.map.toString(), map.toString()); + Assert.assertEquals(map.map.toString(), map.toString()); } @Test public void testIsMarkedDirty() throws Exception { ModifyAwareMap map = createMap(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); map.put("A", "change"); - assertTrue(map.isMarkedDirty()); + Assert.assertTrue(map.isMarkedDirty()); } @Test public void testMarkAsModified() throws Exception { ModifyAwareMap map = createMap(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); map.markAsModified(); - assertTrue(map.isMarkedDirty()); + Assert.assertTrue(map.isMarkedDirty()); } @Test public void testSize() throws Exception { ModifyAwareMap map = createMap(); - assertEquals(5, map.size()); + Assert.assertEquals(5, map.size()); } @Test public void testIsEmpty() throws Exception { - assertFalse(createMap().isEmpty()); - assertTrue(createEmptyMap().isEmpty()); + Assert.assertFalse(createMap().isEmpty()); + Assert.assertTrue(createEmptyMap().isEmpty()); } @Test public void testContainsKey() throws Exception { ModifyAwareMap map = createMap(); - assertTrue(map.containsKey("A")); - assertFalse(map.containsKey("Z")); + Assert.assertTrue(map.containsKey("A")); + Assert.assertFalse(map.containsKey("Z")); } @Test public void testContainsValue() throws Exception { ModifyAwareMap map = createMap(); - assertTrue(map.containsValue("one")); - assertFalse(map.containsValue("junk")); + Assert.assertTrue(map.containsValue("one")); + Assert.assertFalse(map.containsValue("junk")); } @Test @@ -94,86 +94,86 @@ public class ModifyAwareMapTest { ModifyAwareMap map = createMap(); - assertEquals("two", map.get("B")); - assertNull(map.get("Z")); - assertFalse(map.isMarkedDirty()); + Assert.assertEquals("two", map.get("B")); + Assert.assertNull(map.get("Z")); + Assert.assertFalse(map.isMarkedDirty()); } @Test public void testPut() throws Exception { ModifyAwareMap map = createMap(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); map.put("A", "mod"); - assertTrue(map.isMarkedDirty()); + Assert.assertTrue(map.isMarkedDirty()); } @Test public void testRemove() throws Exception { ModifyAwareMap map = createMap(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); map.remove("A"); - assertTrue(map.isMarkedDirty()); + Assert.assertTrue(map.isMarkedDirty()); } @Test public void testPutAllWithEmpty() throws Exception { ModifyAwareMap map = createMap(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); Map other = new HashMap<>(); map.putAll(other); - assertTrue(map.isMarkedDirty()); + Assert.assertTrue(map.isMarkedDirty()); } @Test public void testPutAll() throws Exception { ModifyAwareMap map = createMap(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); Map other = new HashMap<>(); other.put("A", "one"); map.putAll(other); - assertTrue(map.isMarkedDirty()); + Assert.assertTrue(map.isMarkedDirty()); } @Test public void testClear() throws Exception { ModifyAwareMap map = createMap(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); map.clear(); - assertTrue(map.isMarkedDirty()); + Assert.assertTrue(map.isMarkedDirty()); } @Test public void testKeySet() throws Exception { ModifyAwareMap map = createMap(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); Set keys = map.keySet(); - assertEquals(map.size(), keys.size()); - assertTrue(keys.contains("A")); - assertFalse(map.isMarkedDirty()); + Assert.assertEquals(map.size(), keys.size()); + Assert.assertTrue(keys.contains("A")); + Assert.assertFalse(map.isMarkedDirty()); } @Test public void testValues() throws Exception { ModifyAwareMap map = createMap(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); Collection values = map.values(); - assertEquals(map.size(), values.size()); - assertTrue(values.contains("one")); - assertFalse(map.isMarkedDirty()); + Assert.assertEquals(map.size(), values.size()); + Assert.assertTrue(values.contains("one")); + Assert.assertFalse(map.isMarkedDirty()); } @Test @@ -182,10 +182,10 @@ public class ModifyAwareMapTest { ModifyAwareMap map = createMap(); Set> entries = map.entrySet(); - assertFalse(map.isMarkedDirty()); + Assert.assertFalse(map.isMarkedDirty()); - assertEquals(map.size(), entries.size()); - assertFalse(map.isMarkedDirty()); + Assert.assertEquals(map.size(), entries.size()); + Assert.assertFalse(map.isMarkedDirty()); } @Test @@ -204,6 +204,6 @@ public class ModifyAwareMapTest { @SuppressWarnings("unchecked") ModifyAwareMap read = (ModifyAwareMap)ois.readObject(); - assertThat(read).hasSize(orig.size()); + Assertions.assertThat(read).hasSize(orig.size()); } } diff --git a/src/test/java/io/ebeaninternal/server/type/ModifyAwareFlagTest.java b/src/test/java/io/ebeaninternal/server/type/ModifyAwareFlagTest.java index 84312de65..9fbdc324c 100644 --- a/src/test/java/io/ebeaninternal/server/type/ModifyAwareFlagTest.java +++ b/src/test/java/io/ebeaninternal/server/type/ModifyAwareFlagTest.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.type; +import io.ebeaninternal.json.ModifyAwareFlag; import org.junit.Test; import java.io.ByteArrayInputStream; diff --git a/src/test/java/io/ebeaninternal/server/type/ModifyAwareListTest.java b/src/test/java/io/ebeaninternal/server/type/ModifyAwareListTest.java index ba4143a92..76a11b190 100644 --- a/src/test/java/io/ebeaninternal/server/type/ModifyAwareListTest.java +++ b/src/test/java/io/ebeaninternal/server/type/ModifyAwareListTest.java @@ -1,5 +1,7 @@ package io.ebeaninternal.server.type; +import io.ebeaninternal.json.ModifyAwareList; +import io.ebeaninternal.json.ModifyAwareSet; import org.junit.Test; import java.io.ByteArrayInputStream; diff --git a/src/test/java/io/ebeaninternal/server/type/ModifyAwareSetTest.java b/src/test/java/io/ebeaninternal/server/type/ModifyAwareSetTest.java index 5371b14e9..f3f4023c7 100644 --- a/src/test/java/io/ebeaninternal/server/type/ModifyAwareSetTest.java +++ b/src/test/java/io/ebeaninternal/server/type/ModifyAwareSetTest.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.type; +import io.ebeaninternal.json.ModifyAwareSet; import org.junit.Test; import java.io.ByteArrayInputStream; diff --git a/src/test/java/io/ebeaninternal/server/type/ScalarTypePostgresHstoreTest.java b/src/test/java/io/ebeaninternal/server/type/ScalarTypePostgresHstoreTest.java index 4a055adc6..7ca187dc2 100644 --- a/src/test/java/io/ebeaninternal/server/type/ScalarTypePostgresHstoreTest.java +++ b/src/test/java/io/ebeaninternal/server/type/ScalarTypePostgresHstoreTest.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import io.ebeaninternal.json.ModifyAwareMap; import org.junit.Test; import java.io.IOException;