alisson-gomesc / jkniv

Powering your database/repositories with Java code agnostic from JDBC and SQL
http://jkniv.sf.net
GNU Lesser General Public License v2.1
4 stars 0 forks source link

Inserting Documents in Bulk #4

Closed rodrigosantana777 closed 5 years ago

rodrigosantana777 commented 5 years ago

To allow to create and update multiple documents at the same time within a single request.

alisson-gomesc commented 5 years ago

The version 0.6.0.M42 was enhancement with a BulkCommand. For that yours parameter must be a:

        Repository repository = getRepository();
        List<Author> authors = new ArrayList<Author>();

        Author a1 = new Author();
        a1.setName("Bulk One");
        a1.setNationality("BR");
        Author a2 = new Author();
        a2.setName("Bulk Two");
        a2.setNationality("PT");
        Author a3 = new Author();
        a3.setName("Bulk Three");
        a3.setNationality("AU");

        authors.add(a1); authors.add(a2); authors.add(a3);
        Queryable q = QueryFactory.of("add", authors); // query must be named with 'add' or 'update'

        int rows = repository.add(q);
        assertThat(rows, is(3));

You must be invoke add or update repository method. whinstone-couchdb there are built-in queries: "add", "remove", "update" and "get", isn't necessary wrote in XML file.