You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gora.apache.org by dr...@apache.org on 2015/01/14 23:52:42 UTC
gora git commit: GORA-388: Fix handling of Utf8 type in MongoStore
local filters.
Repository: gora
Updated Branches:
refs/heads/master 2b48955ff -> 8ce063466
GORA-388: Fix handling of Utf8 type in MongoStore local filters.
- Fix handling of Utf8 type in MongoStore local filters.
- Some more documentation and tests for DefaultFactory
This closes apache/gora#14 PR.
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/8ce06346
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/8ce06346
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/8ce06346
Branch: refs/heads/master
Commit: 8ce063466a2c833efa7324540a9c5b780f56ee48
Parents: 2b48955
Author: Damien Raude-Morvan <dr...@drazzib.com>
Authored: Wed Jan 14 23:49:46 2015 +0100
Committer: Damien Raude-Morvan <dr...@drazzib.com>
Committed: Wed Jan 14 23:52:13 2015 +0100
----------------------------------------------------------------------
CHANGES.txt | 2 ++
.../gora/mongodb/filters/DefaultFactory.java | 19 ++++++++++++++++++-
.../gora/mongodb/filters/DefaultFactoryTest.java | 17 +++++++++++++++++
3 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/8ce06346/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 048eb9c..6f7cdfe 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@
Current Development 0.6-SNAPSHOT
+* GORA-388 MongoStore: Fix handling of Utf8 in filters (drazzib)
+
* GORA-375 Upgrade HBase to 0.98 (Talat UYARER via lewismc)
* GORA-389 MongoStore: Document or List mapping change cause NPE in clearDirty() (drazzib)
http://git-wip-us.apache.org/repos/asf/gora/blob/8ce06346/gora-mongodb/src/main/java/org/apache/gora/mongodb/filters/DefaultFactory.java
----------------------------------------------------------------------
diff --git a/gora-mongodb/src/main/java/org/apache/gora/mongodb/filters/DefaultFactory.java b/gora-mongodb/src/main/java/org/apache/gora/mongodb/filters/DefaultFactory.java
index 54cbdfd..1e697f2 100644
--- a/gora-mongodb/src/main/java/org/apache/gora/mongodb/filters/DefaultFactory.java
+++ b/gora-mongodb/src/main/java/org/apache/gora/mongodb/filters/DefaultFactory.java
@@ -115,7 +115,8 @@ public class DefaultFactory<K, T extends PersistentBase> extends
}
protected QueryBuilder appendToBuilder(final QueryBuilder builder,
- final FilterOp filterOp, final List<Object> operands) {
+ final FilterOp filterOp, final List<Object> rawOperands) {
+ List<String> operands = convertOperandsToString(rawOperands);
switch (filterOp) {
case EQUALS:
if (operands.size() == 1) {
@@ -150,4 +151,20 @@ public class DefaultFactory<K, T extends PersistentBase> extends
return builder;
}
+ /**
+ * Transform all Utf8 into String before preparing MongoDB query.
+ * <p>Otherwise, you'll get <tt>RuntimeException: json can't serialize type : Utf8</tt></p>
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/GORA-388">GORA-388</a>
+ */
+ private List<String> convertOperandsToString(List<Object> rawOperands) {
+ List<String> operands = new ArrayList<String>(rawOperands.size());
+ for (Object rawOperand : rawOperands) {
+ if (rawOperand != null) {
+ operands.add(rawOperand.toString());
+ }
+ }
+ return operands;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/gora/blob/8ce06346/gora-mongodb/src/test/java/org/apache/gora/mongodb/filters/DefaultFactoryTest.java
----------------------------------------------------------------------
diff --git a/gora-mongodb/src/test/java/org/apache/gora/mongodb/filters/DefaultFactoryTest.java b/gora-mongodb/src/test/java/org/apache/gora/mongodb/filters/DefaultFactoryTest.java
index 43631ef..b6642b9 100644
--- a/gora-mongodb/src/test/java/org/apache/gora/mongodb/filters/DefaultFactoryTest.java
+++ b/gora-mongodb/src/test/java/org/apache/gora/mongodb/filters/DefaultFactoryTest.java
@@ -121,6 +121,23 @@ public class DefaultFactoryTest {
dbObject.toString());
}
+ /**
+ * Check that <a href="https://issues.apache.org/jira/browse/GORA-388">GORA-388</a> is fixed.
+ * @see <a href="https://issues.apache.org/jira/browse/GORA-388">GORA-388</a>
+ */
+ @Test
+ public void testCreateFilter_handlingUtf8() throws Exception {
+ SingleFieldValueFilter<String, WebPage> filter = new SingleFieldValueFilter<String, WebPage>();
+ filter.setFieldName(WebPage.Field.URL.toString());
+ filter.setFilterOp(FilterOp.EQUALS);
+ filter.getOperands().add(new Utf8("http://www.example.com"));
+ filter.setFilterIfMissing(true);
+
+ DBObject dbObject = filterFactory.createFilter(filter, store);
+ assertEquals("{ \"url\" : \"http://www.example.com\"}",
+ dbObject.toString());
+ }
+
private MapFieldValueFilter<String, WebPage> createHeadersFilter() {
MapFieldValueFilter<String, WebPage> filter = new MapFieldValueFilter<String, WebPage>();
filter.setFieldName(WebPage.Field.HEADERS.toString());