[gora] 04/07: GORA-649: Use org.bson.Document as container

2020-03-23 Thread drazzib
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git

commit e419e11c80dca011ed62631050c5ec1454a7bf00
Author: Damien Raude-Morvan 
AuthorDate: Mon Mar 23 21:56:26 2020 +0100

GORA-649: Use org.bson.Document as container
---
 .../apache/gora/mongodb/utils/BSONDecorator.java   | 85 +++---
 .../gora/mongodb/utils/TestBSONDecorator.java  | 44 +--
 2 files changed, 63 insertions(+), 66 deletions(-)

diff --git 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/BSONDecorator.java 
b/gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/BSONDecorator.java
index ac98096..56680a9 100644
--- 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/BSONDecorator.java
+++ 
b/gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/BSONDecorator.java
@@ -17,35 +17,34 @@
  */
 package org.apache.gora.mongodb.utils;
 
-import com.mongodb.BasicDBList;
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBObject;
 import org.apache.avro.util.Utf8;
-import org.bson.BSONObject;
+import org.bson.Document;
+import org.bson.types.Binary;
 
 import java.nio.ByteBuffer;
 import java.util.Date;
+import java.util.List;
 
 /**
- * Utility class to build {@link DBObject} used by MongoDB in an easy way by
+ * Utility class to build {@link Document} used by MongoDB in an easy way by
  * directly specifying the fully qualified names of fields.
  *
  * @author Fabien Poulard fpoul...@dictanova.com
  */
 public class BSONDecorator {
 
-  final private DBObject myBson;
+  final private Document myBson;
 
-  public BSONDecorator(final DBObject obj) {
+  public BSONDecorator(final Document obj) {
 myBson = obj;
   }
 
   /**
-   * Access the decorated {@link BSONObject}.
+   * Access the decorated {@link Document}.
*
-   * @return the decorated {@link DBObject} in its actual state
+   * @return the decorated {@link Document} in its actual state
*/
-  public DBObject asDBObject() {
+  public Document asDocument() {
 return myBson;
   }
 
@@ -56,45 +55,45 @@ public class BSONDecorator {
*
* @param fieldName fully qualified name of the field
* @return true if the field and all its parents exists in the decorated
-   * {@link DBObject}, false otherwise
+   * {@link Document}, false otherwise
*/
   public boolean containsField(String fieldName) {
 // Prepare for in depth setting
 String[] fields = fieldName.split("\\.");
 int i = 0;
-DBObject intermediate = myBson;
+Document intermediate = myBson;
 
 // Set intermediate parents
 while (i < (fields.length - 1)) {
-  if (!intermediate.containsField(fields[i]))
+  if (!intermediate.containsKey(fields[i]))
 return false;
-  intermediate = (DBObject) intermediate.get(fields[i]);
+  intermediate = (Document) intermediate.get(fields[i]);
   i++;
 }
 
 // Check final field
-return intermediate.containsField(fields[fields.length - 1]);
+return intermediate.containsKey(fields[fields.length - 1]);
   }
 
   /**
-   * Access field as a {@link BasicDBObject}.
+   * Access field as a {@link Document}.
*
* @param fieldName fully qualified name of the field to be accessed
-   * @return value of the field as a {@link BasicDBObject}
+   * @return value of the field as a {@link Document}
*/
-  public BasicDBObject getDBObject(String fieldName) {
-return (BasicDBObject) getFieldParent(fieldName)
+  public Document getDBObject(String fieldName) {
+return (Document) getFieldParent(fieldName)
 .get(getLeafName(fieldName));
   }
 
   /**
-   * Access field as a {@link BasicDBList}.
+   * Access field as a {@link List}.
*
* @param fieldName fully qualified name of the field to be accessed
-   * @return value of the field as a {@link BasicDBList}
+   * @return value of the field as a {@link List}
*/
-  public BasicDBList getDBList(String fieldName) {
-return (BasicDBList) getFieldParent(fieldName).get(getLeafName(fieldName));
+  public List getDBList(String fieldName) {
+return (List) 
getFieldParent(fieldName).get(getLeafName(fieldName));
   }
 
   /**
@@ -104,9 +103,9 @@ public class BSONDecorator {
* @return value of the field as a boolean
*/
   public Boolean getBoolean(String fieldName) {
-BasicDBObject parent = getFieldParent(fieldName);
+Document parent = getFieldParent(fieldName);
 String lf = getLeafName(fieldName);
-return parent.containsField(lf) ? parent.getBoolean(lf) : null;
+return parent.containsKey(lf) ? parent.getBoolean(lf) : null;
   }
 
   /**
@@ -116,9 +115,9 @@ public class BSONDecorator {
* @return value of the field as a double
*/
   public Double getDouble(String fieldName) {
-BasicDBObject parent = getFieldParent(fieldName);
+Document parent = getFieldParent(fieldName);
 String lf = 

[gora] 02/07: GORA-649 MongoDBQuery: Use Filters and Projections helper

2020-03-23 Thread drazzib
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git

commit 4b6f6bc74a15ac3224758fc1388c6ed185ffd7c0
Author: Damien Raude-Morvan 
AuthorDate: Mon Mar 23 21:50:45 2020 +0100

GORA-649 MongoDBQuery: Use Filters and Projections helper
---
 .../apache/gora/mongodb/query/MongoDBQuery.java| 55 --
 1 file changed, 31 insertions(+), 24 deletions(-)

diff --git 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBQuery.java 
b/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBQuery.java
index 0c2f22f..762d782 100644
--- a/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBQuery.java
+++ b/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBQuery.java
@@ -17,14 +17,24 @@
  */
 package org.apache.gora.mongodb.query;
 
+import com.mongodb.client.model.Projections;
 import org.apache.gora.mongodb.store.MongoMapping;
 import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.Query;
 import org.apache.gora.query.impl.QueryBase;
 import org.apache.gora.store.DataStore;
+import org.bson.Document;
+import org.bson.conversions.Bson;
 
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBObject;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static com.mongodb.client.model.Filters.and;
+import static com.mongodb.client.model.Filters.eq;
+import static com.mongodb.client.model.Filters.gte;
+import static com.mongodb.client.model.Filters.lte;
 
 /**
  * MongoDB specific implementation of the {@link Query} interface.
@@ -44,40 +54,37 @@ public class MongoDBQuery 
extends QueryBase {
   /**
* Compute the query itself. Only make use of the keys for querying.
* 
-   * @return a {@link DBObject} corresponding to the query
+   * @return a {@link Document} corresponding to the query
*/
-  public static DBObject toDBQuery(Query query) {
-BasicDBObject q = new BasicDBObject();
+  public static Bson toDBQuery(Query query) {
+
 if ((query.getStartKey() != null) && (query.getEndKey() != null)
 && query.getStartKey().equals(query.getEndKey())) {
-  q.put("_id", query.getStartKey());
+  return eq("_id", query.getStartKey());
 } else {
-  if (query.getStartKey() != null)
-q.put("_id", new BasicDBObject("$gte", query.getStartKey()));
-  if (query.getEndKey() != null)
-q.put("_id", new BasicDBObject("$lte", query.getEndKey()));
+  List filters = new ArrayList<>();
+  if (query.getStartKey() != null) {
+filters.add(gte("_id", query.getStartKey()));
+  }
+  if (query.getEndKey() != null) {
+filters.add(lte("_id", query.getEndKey()));
+  }
+  return filters.isEmpty() ? new Document() : and(filters);
 }
-
-return q;
   }
 
   /**
* Compute the projection of the query, that is the fields that will be
* retrieved from the database.
* 
-   * @return a {@link DBObject} corresponding to the list of field to be
+   * @return a {@link Document} corresponding to the list of field to be
* retrieved with the associated boolean
*/
-  public static DBObject toProjection(String[] fields, MongoMapping mapping) {
-BasicDBObject proj = new BasicDBObject();
-
-for (String k : fields) {
-  String dbFieldName = mapping.getDocumentField(k);
-  if (dbFieldName != null && dbFieldName.length() > 0) {
-proj.put(dbFieldName, true);
-  }
-}
-
-return proj;
+  public static Bson toProjection(String[] fields, MongoMapping mapping) {
+List dbFields = Stream.of(fields)
+.map(mapping::getDocumentField)
+.filter(dbField -> dbField != null && !dbField.isEmpty())
+.collect(Collectors.toList());
+return Projections.include(dbFields);
   }
 }



[gora] 03/07: GORA-649 MongoStoreParameters: improve Javadoc

2020-03-23 Thread drazzib
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git

commit 0128a100a6dbbf50af8f7a3694cb6ee3064912f6
Author: Damien Raude-Morvan 
AuthorDate: Mon Mar 23 21:55:05 2020 +0100

GORA-649 MongoStoreParameters: improve Javadoc
---
 .../org/apache/gora/mongodb/store/MongoStoreParameters.java   | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStoreParameters.java
 
b/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStoreParameters.java
index b278b89..e939785 100644
--- 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStoreParameters.java
+++ 
b/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStoreParameters.java
@@ -17,7 +17,6 @@
  */
 package org.apache.gora.mongodb.store;
 
-import com.mongodb.DB;
 import org.apache.hadoop.conf.Configuration;
 
 import java.util.Properties;
@@ -92,14 +91,14 @@ public class MongoStoreParameters {
   private final String writeConcern;
 
   /**
-   * @param mappingFile
-   * @param servers
+   * @param mappingFileConfiguration file for mapping.
+   * @param serversCollection of seeds servers.
* @param dbname Name of database to connect to.
* @param authenticationType Authentication type to login
-   * @param login  Optionnal login for remote database.
+   * @param login  Optional login for remote database.
* @param secret Optional secret for remote database.
-   * @param readPreference
-   * @param writeConcern   @return a {@link DB} instance from 
mongoClient or null if
+   * @param readPreference Optional {@link com.mongodb.ReadPreference}.
+   * @param writeConcern   Optional {@link com.mongodb.WriteConcern}.
*/
   private MongoStoreParameters(String mappingFile, String servers, String 
dbname, String authenticationType, String login, String secret, String 
readPreference, String writeConcern) {
 this.mappingFile = mappingFile;



[gora] 06/07: GORA-649 Use Codec interface instead of DefaultDBEncoder

2020-03-23 Thread drazzib
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git

commit 890af43708d7121266330e55911f09a38542701c
Author: Damien Raude-Morvan 
AuthorDate: Mon Mar 23 21:58:52 2020 +0100

GORA-649 Use Codec interface instead of DefaultDBEncoder
---
 .../utils/{GoraDBEncoder.java => Utf8Codec.java}   | 42 +-
 1 file changed, 16 insertions(+), 26 deletions(-)

diff --git 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/GoraDBEncoder.java 
b/gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/Utf8Codec.java
similarity index 54%
rename from 
gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/GoraDBEncoder.java
rename to 
gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/Utf8Codec.java
index 587968a..60d5b31 100644
--- 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/GoraDBEncoder.java
+++ b/gora-mongodb/src/main/java/org/apache/gora/mongodb/utils/Utf8Codec.java
@@ -17,40 +17,30 @@
  */
 package org.apache.gora.mongodb.utils;
 
-import java.nio.ByteBuffer;
-
 import org.apache.avro.util.Utf8;
-
-import com.mongodb.DBEncoder;
-import com.mongodb.DBEncoderFactory;
-import com.mongodb.DefaultDBEncoder;
+import org.bson.BsonReader;
+import org.bson.BsonWriter;
+import org.bson.codecs.Codec;
+import org.bson.codecs.DecoderContext;
+import org.bson.codecs.EncoderContext;
 
 /**
- * BSON encoder for BSONObject instances.
+ * BSON encoder for {@link Utf8} instances.
  */
-public class GoraDBEncoder extends DefaultDBEncoder {
+public class Utf8Codec implements Codec {
 
-  public static DBEncoderFactory FACTORY = new DefaultFactory();
-
-  @Override
-  protected boolean putSpecial(String name, Object val) {
-if (val instanceof Utf8) {
-  putString(name, val.toString());
-  return true;
-} else if (val instanceof ByteBuffer) {
-  putBinary(name, ((ByteBuffer) val).array());
-  return true;
-} else {
-  return super.putSpecial(name, val);
+@Override
+public Utf8 decode(BsonReader reader, DecoderContext decoderContext) {
+return new Utf8(reader.readString());
 }
-  }
-
-  static class DefaultFactory implements DBEncoderFactory {
 
 @Override
-public DBEncoder create() {
-  return new GoraDBEncoder();
+public void encode(BsonWriter writer, Utf8 value, EncoderContext 
encoderContext) {
+writer.writeString(value.toString());
 }
-  }
 
+@Override
+public Class getEncoderClass() {
+return Utf8.class;
+}
 }



[gora] 07/07: GORA-649 Use new MongoDatabase and MongoCollection API

2020-03-23 Thread drazzib
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git

commit c2807e60cbea4faecfa9c70c29a993716533c512
Author: Damien Raude-Morvan 
AuthorDate: Mon Mar 23 22:00:53 2020 +0100

GORA-649 Use new MongoDatabase and MongoCollection API
---
 .../org/apache/gora/mongodb/store/MongoStore.java  | 313 ++---
 .../apache/gora/mongodb/store/TestMongoStore.java  |  14 +-
 2 files changed, 158 insertions(+), 169 deletions(-)

diff --git 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java 
b/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java
index 82657e3..26680a5 100644
--- a/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java
+++ b/gora-mongodb/src/main/java/org/apache/gora/mongodb/store/MongoStore.java
@@ -17,31 +17,16 @@
  */
 package org.apache.gora.mongodb.store;
 
-import static com.mongodb.AuthenticationMechanism.GSSAPI;
-import static com.mongodb.AuthenticationMechanism.MONGODB_CR;
-import static com.mongodb.AuthenticationMechanism.MONGODB_X509;
-import static com.mongodb.AuthenticationMechanism.PLAIN;
-import static com.mongodb.AuthenticationMechanism.SCRAM_SHA_1;
-
-import java.io.IOException;
-import java.net.UnknownHostException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.TimeZone;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.xml.bind.DatatypeConverter;
-
+import com.google.common.base.Splitter;
+import com.mongodb.*;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+import com.mongodb.client.MongoIterable;
+import com.mongodb.client.model.CountOptions;
+import com.mongodb.client.model.CreateCollectionOptions;
+import com.mongodb.client.model.UpdateOptions;
+import com.mongodb.client.result.DeleteResult;
 import org.apache.avro.Schema;
 import org.apache.avro.Schema.Field;
 import org.apache.avro.Schema.Type;
@@ -52,7 +37,7 @@ import org.apache.gora.mongodb.query.MongoDBQuery;
 import org.apache.gora.mongodb.query.MongoDBResult;
 import org.apache.gora.mongodb.store.MongoMapping.DocumentFieldType;
 import org.apache.gora.mongodb.utils.BSONDecorator;
-import org.apache.gora.mongodb.utils.GoraDBEncoder;
+import org.apache.gora.mongodb.utils.Utf8Codec;
 import org.apache.gora.persistency.impl.BeanFactoryImpl;
 import org.apache.gora.persistency.impl.DirtyListWrapper;
 import org.apache.gora.persistency.impl.DirtyMapWrapper;
@@ -65,26 +50,25 @@ import org.apache.gora.store.impl.DataStoreBase;
 import org.apache.gora.util.AvroUtils;
 import org.apache.gora.util.ClassLoadingUtils;
 import org.apache.gora.util.GoraException;
+import org.bson.Document;
+import org.bson.codecs.configuration.CodecRegistries;
+import org.bson.codecs.configuration.CodecRegistry;
+import org.bson.conversions.Bson;
 import org.bson.types.ObjectId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Splitter;
-import com.mongodb.BasicDBList;
-import com.mongodb.BasicDBObject;
-import com.mongodb.Bytes;
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-import com.mongodb.Mongo;
-import com.mongodb.MongoClient;
-import com.mongodb.MongoClientOptions;
-import com.mongodb.MongoCredential;
-import com.mongodb.ReadPreference;
-import com.mongodb.ServerAddress;
-import com.mongodb.WriteConcern;
-import com.mongodb.WriteResult;
+import javax.xml.bind.DatatypeConverter;
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.StreamSupport;
+
+import static com.mongodb.AuthenticationMechanism.*;
+import static com.mongodb.client.model.Filters.and;
 
 /**
  * Implementation of a MongoDB data store to be used by gora.
@@ -111,9 +95,9 @@ DataStoreBase {
*/
   private static ConcurrentHashMap mapsOfClients = new 
ConcurrentHashMap<>();
 
-  private DB mongoClientDB;
+  private MongoDatabase mongoClientDB;
 
-  private DBCollection mongoClientColl;
+  private MongoCollection mongoClientColl;
 
   /**
* Mapping definition for MongoDB
@@ -172,42 +156,49 @@ DataStoreBase {
*/
   private MongoClient getClient(MongoStoreParameters params)
   throws UnknownHostException {
+
+// Utf8 serialization!
+CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
+MongoClient.getDefaultCodecRegistry(),
+

[gora] 05/07: GORA-649 MongoFilterUtil: Avoid changing query passed as reference

2020-03-23 Thread drazzib
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git

commit cfb563cc55e0b85ba9b723c9f6e03a1c2910fda8
Author: Damien Raude-Morvan 
AuthorDate: Mon Mar 23 21:58:26 2020 +0100

GORA-649 MongoFilterUtil: Avoid changing query passed as reference

Return an Optional<> with subfilter to apply
---
 .../gora/mongodb/filters/DefaultFactory.java   | 83 ++
 .../apache/gora/mongodb/filters/FilterFactory.java |  7 +-
 .../gora/mongodb/filters/MongoFilterUtil.java  | 28 
 .../gora/mongodb/filters/DefaultFactoryTest.java   | 41 ++-
 4 files changed, 76 insertions(+), 83 deletions(-)

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 597f7e9..bd26209 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
@@ -17,19 +17,21 @@
  */
 package org.apache.gora.mongodb.filters;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.gora.filter.*;
 import org.apache.gora.mongodb.store.MongoMapping;
 import org.apache.gora.mongodb.store.MongoStore;
 import org.apache.gora.persistency.impl.PersistentBase;
+import org.bson.Document;
+import org.bson.conversions.Bson;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
 
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBObject;
-import com.mongodb.QueryBuilder;
+import static com.mongodb.client.model.Filters.*;
 
 public class DefaultFactory extends
 BaseFactory {
@@ -45,8 +47,8 @@ public class DefaultFactory 
extends
   }
 
   @Override
-  public DBObject createFilter(final Filter filter,
-  final MongoStore store) {
+  public Bson createFilter(final Filter filter,
+   final MongoStore store) {
 
 if (filter instanceof FilterList) {
   FilterList filterList = (FilterList) filter;
@@ -64,19 +66,17 @@ public class DefaultFactory 
extends
 }
   }
 
-  protected DBObject transformListFilter(final FilterList filterList,
-  final MongoStore store) {
-BasicDBObject query = new BasicDBObject();
-for (Filter filter : filterList.getFilters()) {
-  boolean succeeded = getFilterUtil().setFilter(query, filter, store);
-  if (!succeeded) {
-return null;
-  }
-}
-return query;
+  protected Bson transformListFilter(final FilterList filterList,
+ final MongoStore store) {
+List filters = filterList.getFilters().stream()
+.map(filter -> getFilterUtil().setFilter(filter, store))
+.filter(Optional::isPresent)
+.map(Optional::get)
+.collect(Collectors.toList());
+return filters.isEmpty() ? new Document() : and(filters);
   }
 
-  protected DBObject transformFieldFilter(
+  protected Bson transformFieldFilter(
   final SingleFieldValueFilter fieldFilter,
   final MongoStore store) {
 MongoMapping mapping = store.getMapping();
@@ -85,17 +85,16 @@ public class DefaultFactory 
extends
 FilterOp filterOp = fieldFilter.getFilterOp();
 List operands = fieldFilter.getOperands();
 
-QueryBuilder builder = QueryBuilder.start(dbFieldName);
-builder = appendToBuilder(builder, filterOp, operands);
+Bson filter = appendToBuilder(dbFieldName, filterOp, operands);
 if (!fieldFilter.isFilterIfMissing()) {
   // If false, the find query will pass if the column is not found.
-  DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get();
-  builder = QueryBuilder.start().or(notExist, builder.get());
+  Bson notExist = exists(dbFieldName, false);
+  filter = or(notExist, filter);
 }
-return builder.get();
+return filter;
   }
 
-  protected DBObject transformMapFilter(
+  protected Bson transformMapFilter(
   final MapFieldValueFilter mapFilter, final MongoStore store) 
{
 MongoMapping mapping = store.getMapping();
 String dbFieldName = mapping.getDocumentField(mapFilter.getFieldName())
@@ -104,51 +103,43 @@ public class DefaultFactory 
extends
 FilterOp filterOp = mapFilter.getFilterOp();
 List operands = mapFilter.getOperands();
 
-QueryBuilder builder = QueryBuilder.start(dbFieldName);
-builder = appendToBuilder(builder, filterOp, operands);
+Bson filter = appendToBuilder(dbFieldName, filterOp, operands);
 if (!mapFilter.isFilterIfMissing()) {
   // If false, the find query will pass if the column is not found.
-  DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get();
-  

[gora] 01/07: GORA-649 MongoDBResult: pass `cursor` and `size` as constructor args

2020-03-23 Thread drazzib
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git

commit 68fbf52d00783703b53d49d806139f0f5527c399
Author: Damien Raude-Morvan 
AuthorDate: Mon Mar 23 21:49:20 2020 +0100

GORA-649 MongoDBResult: pass `cursor` and `size` as constructor args
---
 .../apache/gora/mongodb/query/MongoDBResult.java   | 35 --
 1 file changed, 12 insertions(+), 23 deletions(-)

diff --git 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBResult.java 
b/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBResult.java
index 3965333..c2ba04e 100644
--- 
a/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBResult.java
+++ 
b/gora-mongodb/src/main/java/org/apache/gora/mongodb/query/MongoDBResult.java
@@ -17,16 +17,15 @@
  */
 package org.apache.gora.mongodb.query;
 
-import java.io.IOException;
-
+import com.mongodb.client.MongoCursor;
 import org.apache.gora.mongodb.store.MongoStore;
 import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.Query;
 import org.apache.gora.query.impl.ResultBase;
 import org.apache.gora.store.DataStore;
+import org.bson.Document;
 
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
+import java.io.IOException;
 
 /**
  * MongoDB specific implementation of the {@link org.apache.gora.query.Result}
@@ -41,15 +40,17 @@ public class MongoDBResult 
extends
   /**
* Reference to the cursor pointing to the results
*/
-  private DBCursor cursor;
-  private int size;
+  private MongoCursor cursor;
+  private long size;
 
-  public MongoDBResult(DataStore dataStore, Query query) {
+  public MongoDBResult(DataStore dataStore, Query query, 
MongoCursor cursor, long size) {
 super(dataStore, query);
+this.cursor = cursor;
+this.size = size;
   }
 
   @Override
-  public float getProgress() throws IOException {
+  public float getProgress() {
 if (cursor == null) {
   return 0;
 } else if (size == 0) {
@@ -60,7 +61,7 @@ public class MongoDBResult 
extends
   }
 
   @Override
-  public void close() throws IOException {
+  public void close() {
 if (cursor != null) {
   cursor.close();
 }
@@ -72,27 +73,15 @@ public class MongoDBResult 
extends
   return false;
 }
 
-DBObject obj = cursor.next();
+Document obj = cursor.next();
 key = (K) obj.get("_id");
 persistent = ((MongoStore) getDataStore()).newInstance(obj,
 getQuery().getFields());
 return persistent != null;
   }
 
-  /**
-   * Save the reference to the cursor that holds the actual results.
-   *
-   * @param cursor
-   *  {@link DBCursor} obtained from a query execution and that holds
-   *  the actual results
-   */
-  public void setCursor(DBCursor cursor) {
-this.cursor = cursor;
-this.size = cursor.size();
-  }
-
   @Override
   public int size() {
-return size;
+return (int) size;
   }
 }



[gora] branch GORA-649-replace-deprecated-mongo-api created (now c2807e6)

2020-03-23 Thread drazzib
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a change to branch GORA-649-replace-deprecated-mongo-api
in repository https://gitbox.apache.org/repos/asf/gora.git.


  at c2807e6  GORA-649 Use new MongoDatabase and MongoCollection API

This branch includes the following new commits:

 new 68fbf52  GORA-649 MongoDBResult: pass `cursor` and `size` as 
constructor args
 new 4b6f6bc  GORA-649 MongoDBQuery: Use Filters and Projections helper
 new 0128a10  GORA-649 MongoStoreParameters: improve Javadoc
 new e419e11  GORA-649: Use org.bson.Document as container
 new cfb563c  GORA-649 MongoFilterUtil: Avoid changing query passed as 
reference
 new 890af43  GORA-649 Use Codec interface instead of DefaultDBEncoder
 new c2807e6  GORA-649 Use new MongoDatabase and MongoCollection API

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




[gora] branch GORA-647-test-containers-mongo updated: GORA-647 Add apache licence headers

2020-03-23 Thread drazzib
This is an automated email from the ASF dual-hosted git repository.

drazzib pushed a commit to branch GORA-647-test-containers-mongo
in repository https://gitbox.apache.org/repos/asf/gora.git


The following commit(s) were added to refs/heads/GORA-647-test-containers-mongo 
by this push:
 new 9c511f0  GORA-647 Add apache licence headers
9c511f0 is described below

commit 9c511f091683549edf7ce60f0fad282daf15
Author: Damien Raude-Morvan 
AuthorDate: Mon Mar 23 16:22:46 2020 +0100

GORA-647 Add apache licence headers
---
 .../org/apache/gora/mongodb/MongoContainer.java| 22 ++
 1 file changed, 22 insertions(+)

diff --git 
a/gora-mongodb/src/test/java/org/apache/gora/mongodb/MongoContainer.java 
b/gora-mongodb/src/test/java/org/apache/gora/mongodb/MongoContainer.java
index 9890377..9abf2a9 100644
--- a/gora-mongodb/src/test/java/org/apache/gora/mongodb/MongoContainer.java
+++ b/gora-mongodb/src/test/java/org/apache/gora/mongodb/MongoContainer.java
@@ -1,8 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.gora.mongodb;
 
 import com.mongodb.ServerAddress;
 import org.testcontainers.containers.FixedHostPortGenericContainer;
 
+/**
+ * Use {@link FixedHostPortGenericContainer}
+ * from https://www.testcontainers.org/;>Testcontainers.org 
project
+ * to handle a MongoDB docker container.
+ */
 public class MongoContainer extends 
FixedHostPortGenericContainer {
 
 public static final int MONGO_PORT = 27017;



[gora] branch master updated: GORA-546 Hazelcast Jet execution engine support (#175)

2020-03-23 Thread djkevincr
This is an automated email from the ASF dual-hosted git repository.

djkevincr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/gora.git


The following commit(s) were added to refs/heads/master by this push:
 new 392b264  GORA-546 Hazelcast Jet execution engine support (#175)
392b264 is described below

commit 392b264fdb0da86556a632be5a12d41da3512f49
Author: Lahiru Jayasekara 
AuthorDate: Mon Mar 23 15:37:47 2020 +0530

GORA-546 Hazelcast Jet execution engine support (#175)

* Add hazelcast jet source initial impls

* Add HazelcastJet Source Vertex with distributed execution support

* Rename class name

* Improve test cases

* Add gora-jet sink connector implementations

* Refactor code and moved into gora-jet module

* Fix Indentation to 2 spaces

* Fix injecting datastore key into jet source

* Fix JetSource data partitioning

* Add Apache License

* Remove printStackTrace

* Add java doc comments

* Fix test cases via hbase testing utilities

* Remove printStackTrace

* Resolve hazelcast dependency conflict

* Resolve issues from review

* Add LogAnalyticsJet tutorial class

* Move gora-jet module up in pom.xml

* Change snapshot version in gora-jet module

* Add license header
---
 gora-jet/conf/gora-aerospike-mapping.xml   |  44 +
 gora-jet/conf/gora-cassandra-mapping.xml   |  51 ++
 gora-jet/conf/gora-couchdb-mapping.xml |  41 +
 gora-jet/conf/gora-hbase-mapping.xml   |  55 ++
 gora-jet/conf/gora-solr-mapping.xml|  43 +
 gora-jet/conf/gora-sql-mapping.xml |  43 +
 gora-jet/conf/gora.properties  |  66 ++
 gora-jet/conf/hazelcast-client.xml |  31 +
 gora-jet/conf/hazelcast.xml|  34 +
 gora-jet/pom.xml   | 131 +++
 .../main/java/org/apache/gora/jet/JetEngine.java   |  51 ++
 .../org/apache/gora/jet/JetInputOutputFormat.java  |  50 ++
 .../src/main/java/org/apache/gora/jet/JetSink.java |  91 +++
 .../main/java/org/apache/gora/jet/JetSource.java   | 109 +++
 gora-jet/src/test/avro/pageview.json   |  15 +
 gora-jet/src/test/avro/resultPageView.json |  10 +
 .../src/test/java/org/apache/gora/jet/JetTest.java | 150 
 .../org/apache/gora/jet/generated/Pageview.java| 881 +
 .../apache/gora/jet/generated/ResultPageView.java  | 468 +++
 gora-tutorial/pom.xml  |   5 +
 .../apache/gora/tutorial/log/LogAnalyticsJet.java  | 108 +++
 pom.xml|  16 +-
 22 files changed, 2492 insertions(+), 1 deletion(-)

diff --git a/gora-jet/conf/gora-aerospike-mapping.xml 
b/gora-jet/conf/gora-aerospike-mapping.xml
new file mode 100644
index 000..5506880
--- /dev/null
+++ b/gora-jet/conf/gora-aerospike-mapping.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+  
+  
+
+  
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+
+  
+
+
diff --git a/gora-jet/conf/gora-cassandra-mapping.xml 
b/gora-jet/conf/gora-cassandra-mapping.xml
new file mode 100644
index 000..bb0275f
--- /dev/null
+++ b/gora-jet/conf/gora-cassandra-mapping.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+  
+
+
+
+  
+  
+  
+
+  
+
+  
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+
+  
+
+
diff --git a/gora-jet/conf/gora-couchdb-mapping.xml 
b/gora-jet/conf/gora-couchdb-mapping.xml
new file mode 100644
index 000..2cbee77
--- /dev/null
+++ b/gora-jet/conf/gora-couchdb-mapping.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+  
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+
+  
+
+
diff --git a/gora-jet/conf/gora-hbase-mapping.xml 
b/gora-jet/conf/gora-hbase-mapping.xml
new file mode 100644
index 000..9722144
--- /dev/null
+++ b/gora-jet/conf/gora-hbase-mapping.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+   
+ 
+
+
+  
+
+   
+ 
+  
+
+  
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+
+  
+
+  
+
+
+
+  
+
diff --git a/gora-jet/conf/gora-solr-mapping.xml 
b/gora-jet/conf/gora-solr-mapping.xml
new file mode 100644
index 000..5fe10fb
--- /dev/null
+++ b/gora-jet/conf/gora-solr-mapping.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+  
+
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+
+
+  
+
+
+
diff --git a/gora-jet/conf/gora-sql-mapping.xml 
b/gora-jet/conf/gora-sql-mapping.xml
new file mode 100644
index 000..90f1cfc
--- /dev/null
+++ b/gora-jet/conf/gora-sql-mapping.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+  
+
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+
+
+  
+
+
+
diff --git a/gora-jet/conf/gora.properties b/gora-jet/conf/gora.properties
new file mode 100644
index 000..ddce0ed
--- /dev/null
+++