List of usage examples for com.mongodb.client MongoDatabase getCollection
MongoCollection<Document> getCollection(String collectionName);
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * * @param doc/*www.j av a 2 s. c o m*/ * @param docSort * @return */ public List<T> findBy(String sql) { Document sortQuery = new Document(); Document doc = new Document(); try { list = new ArrayList<>(); QueryConverter queryConverter = new QueryConverter(sql); MongoDBQueryHolder mongoDBQueryHolder = queryConverter.getMongoQuery(); String collection = mongoDBQueryHolder.getCollection(); doc = mongoDBQueryHolder.getQuery(); Document projection = mongoDBQueryHolder.getProjection(); if (sql.toLowerCase().indexOf("order by") != -1) { sortQuery = mongoDBQueryHolder.getSort(); } MongoDatabase db = getMongoClient().getDatabase(database); FindIterable<Document> iterable = db.getCollection(collection).find(doc).sort(sortQuery); list = iterableList(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("sql() ", e); } return list; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * * @param doc/*from www . java 2s . c om*/ * @param docSort * @return */ public List<T> aggregateToEntity(List<Document> documentList) { // public List<U extends Number> aggregate(List<Document> documentList) { try { list = new ArrayList<>(); MongoDatabase db = getMongoClient().getDatabase(database); AggregateIterable<Document> iterable = db.getCollection(collection).aggregate(documentList); list = processAggregateIterable(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("aggregate() ", e); } return list; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * * @param doc//from w w w .j a v a 2s. com * @param docSort * @return */ public List<JmoordbResult> aggregateFromDocument(List<Document> documentList) { // public List<U extends Number> aggregate(List<Document> documentList) { List<JmoordbResult> list = new ArrayList<>(); try { list = new ArrayList<>(); MongoDatabase db = getMongoClient().getDatabase(database); AggregateIterable<Document> iterable = db.getCollection(collection).aggregate(documentList); list = processAggregateIterableJmoordbResult(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("aggregate() ", e); } return list; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * * @param doc//from ww w .j a v a 2s .c o m * @param docSort * @return */ public List<JmoordbResult> aggregateFromBuilder(List<Bson> builder) { // public List<U extends Number> aggregate(List<Document> documentList) { List<JmoordbResult> list = new ArrayList<>(); try { list = new ArrayList<>(); MongoDatabase db = getMongoClient().getDatabase(database); AggregateIterable<Document> iterable = db.getCollection(collection).aggregate(builder); list = processAggregateIterableJmoordbResult(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("aggregateFromBuilder ", e); } return list; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
public List<T> findBy(String key, Object value, Document... docSort) { Document sortQuery = new Document(); try {/* w ww. ja v a 2 s . com*/ if (docSort.length != 0) { sortQuery = docSort[0]; } list = new ArrayList<>(); Document doc = new Document(key, value); MongoDatabase db = getMongoClient().getDatabase(database); FindIterable<Document> iterable = db.getCollection(collection).find(doc).sort(sortQuery); list = iterableList(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("findBy() ", e); } return list; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * * @param filter//ww w. j av a 2 s.c om * @param docSort * @return */ public List<T> filters(Bson filter, Document... docSort) { Document sortQuery = new Document(); try { if (docSort.length != 0) { sortQuery = docSort[0]; } list = new ArrayList<>(); MongoDatabase db = getMongoClient().getDatabase(database); FindIterable<Document> iterable = db.getCollection(collection).find(filter).sort(sortQuery); list = iterableList(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("findBy() ", e); } return list; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * * @param filter/* w w w . j av a 2 s . c o m*/ * @param docSort * @return */ public List<T> filtersPagination(Bson filter, Integer pageNumber, Integer rowsForPage, Document... docSort) { Document sortQuery = new Document(); try { if (docSort.length != 0) { sortQuery = docSort[0]; } list = new ArrayList<>(); MongoDatabase db = getMongoClient().getDatabase(database); FindIterable<Document> iterable = db.getCollection(collection).find(filter).sort(sortQuery); list = iterableList(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("findBy() ", e); } return list; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
public List<T> findHelperSort(String predicate, Document doc, String key, String value) { try {//from ww w .j a va 2s . co m Object t = entityClass.newInstance(); list = new ArrayList<>(); MongoDatabase db = getMongoClient().getDatabase(database); FindIterable<Document> iterable = getIterable(); switch (predicate) { case "ascending": iterable = db.getCollection(collection).find(doc).sort(ascending(key, value)); break; case "descending": iterable = db.getCollection(collection).find(doc).sort(descending(key, value)); break; } list = iterableList(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("findHelperSort()", e); } return list; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
public List<T> findHelperSortPagination(String predicate, Document doc, String key, String value, Integer pageNumber, Integer rowsForPage) { try {/* ww w . j a va 2 s . c om*/ Object t = entityClass.newInstance(); list = new ArrayList<>(); MongoDatabase db = getMongoClient().getDatabase(database); FindIterable<Document> iterable = getIterable(); switch (predicate) { case "ascending": iterable = db.getCollection(collection).find(doc) .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage) .sort(ascending(key, value)); break; case "descending": iterable = db.getCollection(collection).find(doc) .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage) .sort(descending(key, value)); break; } list = iterableList(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("findHelperSort()", e); } return list; }
From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java
/** * * @param predicate eq,gt.lt/*from ww w. j ava2s.c o m*/ * @param key * @param value * @param docSort * @return */ public List<T> helpers(String predicate, String key, Object value, Document... docSort) { Document sortQuery = new Document(); try { if (docSort.length != 0) { sortQuery = docSort[0]; } Object t = entityClass.newInstance(); list = new ArrayList<>(); MongoDatabase db = getMongoClient().getDatabase(database); FindIterable<Document> iterable = getIterable(); switch (predicate) { case "eq": iterable = db.getCollection(collection).find(eq(key, value)).sort(sortQuery); break; case "lt": iterable = db.getCollection(collection).find(lt(key, value)).sort(sortQuery); break; case "gt": iterable = db.getCollection(collection).find(gt(key, value)).sort(sortQuery); break; } list = iterableList(iterable); } catch (Exception e) { Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e); exception = new Exception("helpers()", e); } return list; }