Example usage for com.mongodb.client MongoDatabase getCollection

List of usage examples for com.mongodb.client MongoDatabase getCollection

Introduction

In this page you can find the example usage for com.mongodb.client MongoDatabase getCollection.

Prototype

MongoCollection<Document> getCollection(String collectionName);

Source Link

Document

Gets a collection.

Usage

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 *
 * @param key// w  w w.j  av  a 2 s.  co m
 * @param value
 * @param docSort
 * @return
 */
public List<T> findRegexPagination(String key, String value, Boolean caseSensitive, Integer pageNumber,
        Integer rowsForPage, Document... docSort) {
    Document sortQuery = new Document();
    list = new ArrayList<>();

    try {

        if (docSort.length != 0) {
            sortQuery = docSort[0];

        }
        Object t = entityClass.newInstance();
        Pattern regex = Pattern.compile(value);

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable;
        if (!caseSensitive) {
            iterable = db.getCollection(collection).find(new Document(key, new Document("$regex", "^" + value)))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);
            //iterable = db.getCollection(collection).find(new Document(key, new Document("$regex", regex)));
        } else {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", "^" + value).append("$options", "i")))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);
            //               iterable = db.getCollection(collection).find(new Document(key, new Document("$regex", regex).append("$options", "si")));

        }

        list = iterableList(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findRegexPagination()", e);
    }
    return list;
}

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 *
 * @param key/*w ww .  jav a 2s.  co  m*/
 * @param value
 * @param docSort
 * @return
 */
public List<T> findRegexPagination(String key, String value, Boolean caseSensitive, String keySecond,
        String valueSecond, Integer pageNumber, Integer rowsForPage, Document... docSort) {
    Document sortQuery = new Document();
    list = new ArrayList<>();

    try {

        if (docSort.length != 0) {
            sortQuery = docSort[0];

        }
        Object t = entityClass.newInstance();
        Pattern regex = Pattern.compile(value);

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable;
        if (!caseSensitive) {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", "^" + value)).append(keySecond, valueSecond))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);
            //iterable = db.getCollection(collection).find(new Document(key, new Document("$regex", regex)));
        } else {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", "^" + value).append("$options", "i"))
                            .append(keySecond, valueSecond))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);
            //               iterable = db.getCollection(collection).find(new Document(key, new Document("$regex", regex).append("$options", "si")));

        }

        list = iterableList(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findRegexPagination()", e);
    }
    return list;
}

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 *
 * @param key/*from  w w  w. j a v a 2s  .c  om*/
 * @param value
 * @param docSort
 * @return
 */
public List<T> findRegexPagination(String key, String value, Boolean caseSensitive, String keySecond,
        String valueSecond, String keyThree, String valueThree, Integer pageNumber, Integer rowsForPage,
        Document... docSort) {
    Document sortQuery = new Document();
    list = new ArrayList<>();

    try {

        if (docSort.length != 0) {
            sortQuery = docSort[0];

        }
        Object t = entityClass.newInstance();
        Pattern regex = Pattern.compile(value);

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable;
        if (!caseSensitive) {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", "^" + value)).append(keySecond, valueSecond)
                            .append(keyThree, valueThree))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);
            //iterable = db.getCollection(collection).find(new Document(key, new Document("$regex", regex)));
        } else {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", "^" + value).append("$options", "i"))
                            .append(keySecond, valueSecond).append(keyThree, valueThree))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);
            //               iterable = db.getCollection(collection).find(new Document(key, new Document("$regex", regex).append("$options", "si")));

        }

        list = iterableList(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findRegexPagination()", e);
    }
    return list;
}

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 *
 * @param key/*  w  ww  . j  a  v  a  2s.  c om*/
 * @param value
 * @param docSort
 * @return
 */
public List<T> findRegexInTextPagination(String key, String value, Boolean caseSensitive, Integer pageNumber,
        Integer rowsForPage, Document... docSort) {
    Document sortQuery = new Document();
    list = new ArrayList<>();

    try {

        if (docSort.length != 0) {
            sortQuery = docSort[0];

        }
        Object t = entityClass.newInstance();
        Pattern regex = Pattern.compile(value);

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable;
        if (!caseSensitive) {
            iterable = db.getCollection(collection).find(new Document(key, new Document("$regex", value)))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);

        } else {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", value).append("$options", "i")))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);

        }

        list = iterableList(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findRegexInTextPagination()", e);
    }
    return list;
}

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 *
 * @param key//  w  w  w  .j  a  v a  2s .  c om
 * @param value
 * @param docSort
 * @return
 */
public List<T> findRegexInTextPagination(String key, String value, Boolean caseSensitive, String keySecond,
        String valueSecond, Integer pageNumber, Integer rowsForPage, Document... docSort) {
    Document sortQuery = new Document();
    list = new ArrayList<>();

    try {

        if (docSort.length != 0) {
            sortQuery = docSort[0];

        }
        Object t = entityClass.newInstance();
        Pattern regex = Pattern.compile(value);

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable;
        if (!caseSensitive) {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", value)).append(keySecond, valueSecond))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);

        } else {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", value).append("$options", "i"))
                            .append(keySecond, valueSecond))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);

        }

        list = iterableList(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findRegexInTextPagination()", e);
    }
    return list;
}

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 *
 * @param key//from   w  w w.j  a  v a  2  s .com
 * @param value
 * @param docSort
 * @return
 */
public List<T> findRegexInTextPagination(String key, String value, Boolean caseSensitive, String keySecond,
        String valueSecond, String keyThree, String valueThree, Integer pageNumber, Integer rowsForPage,
        Document... docSort) {
    Document sortQuery = new Document();
    list = new ArrayList<>();

    try {

        if (docSort.length != 0) {
            sortQuery = docSort[0];

        }
        Object t = entityClass.newInstance();
        Pattern regex = Pattern.compile(value);

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable;
        if (!caseSensitive) {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", value)).append(keySecond, valueSecond)
                            .append(keyThree, valueThree))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);

        } else {
            iterable = db.getCollection(collection)
                    .find(new Document(key, new Document("$regex", value).append("$options", "i"))
                            .append(keySecond, valueSecond).append(keyThree, valueThree))
                    .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage)
                    .sort(sortQuery);

        }

        list = iterableList(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findRegexInTextPagination()", e);
    }
    return list;
}

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 *
 * @param document/*from w w w .ja v a2  s .  c  o m*/
 * @return
 */
public List<JmoordbResult> unknown(String database, String collection, Document... doc) {
    List<JmoordbResult> list = new ArrayList<>();
    Document docQuery = new Document();
    try {
        if (doc.length != 0) {
            docQuery = doc[0];

        }

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable = db.getCollection(collection).find(docQuery);

        list = processUnknownIterableJmoordbResult(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findAll() ", e);
        new JmoordbException("findAll()");
    }

    return list;
}

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 *
 * @param document/*from   ww  w .  j a  va 2  s. c o m*/
 * @return
 */
public List<JmoordbResult> unknownSort(String database, String collection, Document doc, Document... docSort) {
    List<JmoordbResult> list = new ArrayList<>();
    Document sortQuery = new Document();
    try {
        if (docSort.length != 0) {
            sortQuery = docSort[0];

        }

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable = db.getCollection(collection).find(doc).sort(sortQuery);

        list = processUnknownIterableJmoordbResult(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findAll() ", e);
        new JmoordbException("findAll()");
    }

    return list;
}

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 *
 * @param document// w w  w. j a va 2  s .c  o m
 * @return
 */
public List<JmoordbResult> unknown(String database, String collection, Bson filter, Document... docSort) {
    List<JmoordbResult> list = new ArrayList<>();
    Document sortQuery = new Document();
    try {
        if (docSort.length != 0) {
            sortQuery = docSort[0];

        }

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable = db.getCollection(collection).find(filter).sort(sortQuery);

        list = processUnknownIterableJmoordbResult(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findAll() ", e);
        new JmoordbException("findAll()");
    }

    return list;
}

From source file:com.avbravo.ejbjmoordb.mongodb.repository.Repository.java

/**
 * Busca con paginacion en una coleccion
 *
 * @param document//w  w  w  . j av  a2  s . c  o  m
 * @return
 */
public List<JmoordbResult> unknownPagination(String database, String collection, Integer pageNumber,
        Integer rowsForPage, Document... doc) {
    List<JmoordbResult> list = new ArrayList<>();
    Document sortQuery = new Document();
    try {
        if (doc.length != 0) {
            sortQuery = doc[0];

        }

        MongoDatabase db = getMongoClient().getDatabase(database);
        FindIterable<Document> iterable = db.getCollection(collection).find(sortQuery)
                .skip(pageNumber > 0 ? ((pageNumber - 1) * rowsForPage) : 0).limit(rowsForPage);
        list = processUnknownIterableJmoordbResult(iterable);

    } catch (Exception e) {
        Logger.getLogger(Repository.class.getName()).log(Level.SEVERE, null, e);
        exception = new Exception("findPagination() ", e);
        new JmoordbException("findPagination()");
    }

    return list;
}