Projects >> jdbi >>b9822e13686e0be3f7dac46f377839d9eb64c66f

Chunk
Conflicting content
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.Folder2;
import org.skife.jdbi.v2.Handle;
<<<<<<< HEAD
import org.skife.jdbi.v2.Query;
import org.skife.jdbi.v2.ResultIterator;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
=======
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
import org.skife.jdbi.v2.sqlobject.mixins.CloseMe;
import org.skife.jdbi.v2.tweak.HandleCallback;
>>>>>>> ae36615add8bda1d0ed89541eab05e92290a22f1
import org.skife.jdbi.v2.util.StringMapper;

import java.util.Iterator;
Solution content
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.Folder2;
import org.skife.jdbi.v2.Handle;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
import org.skife.jdbi.v2.sqlobject.mixins.CloseMe;
import org.skife.jdbi.v2.tweak.HandleCallback;
import org.skife.jdbi.v2.util.StringMapper;
File
TestDocumenation.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
import java.util.List;
import java.util.Map;

<<<<<<< HEAD
import static java.util.Arrays.asList;
=======
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

>>>>>>> ae36615add8bda1d0ed89541eab05e92290a22f1
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.skife.jdbi.v2.ExtraMatchers.equalsOneOf;
Solution content
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.skife.jdbi.v2.ExtraMatchers.equalsOneOf;
File
TestDocumenation.java
Developer's decision
Manual
Kind of conflict
Import
Chunk
Conflicting content
        dao.close();
    }

<<<<<<< HEAD
    @Test
    public void testMappingExample() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");
        h.execute("insert into something (id, name) values (1, 'Brian')");
        h.execute("insert into something (id, name) values (2, 'Keith')");


        Query> q =
            h.createQuery("select name from something order by id");
        Query q2 = q.map(StringMapper.FIRST);
        List rs = q2.list();

        assertThat(rs, equalTo(asList("Brian", "Keith")));

        h.close();
    }

    @Test
    public void testMappingExampleChained() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");
        h.execute("insert into something (id, name) values (1, 'Brian')");
        h.execute("insert into something (id, name) values (2, 'Keith')");


        List rs = h.createQuery("select name from something order by id")
            .map(StringMapper.FIRST)
            .list();

        assertThat(rs, equalTo(asList("Brian", "Keith")));

        h.close();
    }

    @Test
    public void testMappingExampleChainedFirst() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");
        h.execute("insert into something (id, name) values (1, 'Brian')");
                return null;
            }
        h.execute("insert into something (id, name) values (2, 'Keith')");


        String rs = h.createQuery("select name from something order by id")
            .map(StringMapper.FIRST)
            .first();

        assertThat(rs, equalTo("Brian"));

        h.close();
    }

    @Test
    public void testMappingExampleChainedIterator() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");
        h.execute("insert into something (id, name) values (1, 'Brian')");
        h.execute("insert into something (id, name) values (2, 'Keith')");


        ResultIterator rs = h.createQuery("select name from something order by id")
            .map(StringMapper.FIRST)
            .iterator();

        assertThat(rs.next(), equalTo("Brian"));
        assertThat(rs.next(), equalTo("Keith"));
        assertThat(rs.hasNext(), equalTo(false));

        rs.close();
=======

    @Test
    public void testObtainHandleViaOpen() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle handle = dbi.open();

        // make sure to close it!
        handle.close();
    }

    @Test
    public void testObtainHandleInCallback() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        dbi.withHandle(new HandleCallback()
        {
            public Void withHandle(Handle handle) throws Exception
            {
                handle.execute("create table silly (id int)");
        });
    }

    @Test
    public void testExecuteSomeStatements() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();

        h.execute("create table something (id int primary key, name varchar(100))");
        h.execute("insert into something (id, name) values (?, ?)", 3, "Patrick");

        List> rs = h.select("select id, name from something");
        assertThat(rs.size(), equalTo(1));

        Map row = rs.get(0);
        assertThat((Integer) row.get("id"), equalTo(3));
        assertThat((String) row.get("name"), equalTo("Patrick"));
>>>>>>> ae36615add8bda1d0ed89541eab05e92290a22f1

        h.close();
    }
Solution content
        dao.close();
    }


    @Test
    public void testObtainHandleViaOpen() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle handle = dbi.open();

        // make sure to close it!
        handle.close();
    }

    @Test
    public void testObtainHandleInCallback() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        dbi.withHandle(new HandleCallback()
        {
            public Void withHandle(Handle handle) throws Exception
            {
                handle.execute("create table silly (id int)");
                return null;
            }
        });
    }

    @Test
    public void testExecuteSomeStatements() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();

        h.execute("create table something (id int primary key, name varchar(100))");
        h.execute("insert into something (id, name) values (?, ?)", 3, "Patrick");

        List> rs = h.select("select id, name from something");
        assertThat(rs.size(), equalTo(1));

        Map row = rs.get(0);
        assertThat((Integer) row.get("id"), equalTo(3));
        assertThat((String) row.get("name"), equalTo("Patrick"));

        h.close();
    }
File
TestDocumenation.java
Developer's decision
Version 2
Kind of conflict
Annotation
Method declaration
Method invocation
Method signature
Variable
Chunk
Conflicting content
        h.close();
    }

<<<<<<< HEAD

    @Test
    public void testMappingExampleChainedIterator2() throws Exception
=======
    @Test
    public void testFluentUpdate() throws Exception
>>>>>>> ae36615add8bda1d0ed89541eab05e92290a22f1
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
Solution content
        h.close();
    }

    @Test
    public void testFluentUpdate() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
File
TestDocumenation.java
Developer's decision
Version 2
Kind of conflict
Annotation
Method signature
Chunk
Conflicting content
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");
<<<<<<< HEAD
        h.execute("insert into something (id, name) values (1, 'Brian')");
        h.execute("insert into something (id, name) values (2, 'Keith')");


        Iterator rs = h.createQuery("select name from something order by id")
            .map(StringMapper.FIRST)
            .iterator();

        assertThat(rs.next(), equalTo("Brian"));
        assertThat(rs.next(), equalTo("Keith"));
        assertThat(rs.hasNext(), equalTo(false));
=======

        h.createStatement("insert into something(id, name) values (:id, :name)")
         .bind("id", 4)
         .bind("name", "Martin")
         .execute();
>>>>>>> ae36615add8bda1d0ed89541eab05e92290a22f1

        h.close();
    }
Solution content
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");

        h.createStatement("insert into something(id, name) values (:id, :name)")
         .bind("id", 4)
         .bind("name", "Martin")
         .execute();

        h.close();
    }
File
TestDocumenation.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content
    }

    @Test
<<<<<<< HEAD
    public void testMappingExampleChainedIterator3() throws Exception
=======
    public void testFold() throws Exception
>>>>>>> ae36615add8bda1d0ed89541eab05e92290a22f1
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
Solution content
    }

    @Test
    public void testFold() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
File
TestDocumenation.java
Developer's decision
Version 2
Kind of conflict
Method signature
Chunk
Conflicting content
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");
<<<<<<< HEAD
        h.execute("insert into something (id, name) values (1, 'Brian')");
        h.execute("insert into something (id, name) values (2, 'Keith')");

        for (String name : h.createQuery("select name from something order by id").map(StringMapper.FIRST))
        {
            assertThat(name, equalsOneOf("Brian", "Keith"));
        }

        h.close();
    }


=======
        h.execute("insert into something (id, name) values (7, 'Mark')");
        h.execute("insert into something (id, name) values (8, 'Tatu')");


        StringBuilder rs = h.createQuery("select name from something order by id")
                            .map(StringMapper.FIRST)
                            .fold(new StringBuilder(), new Folder2()
                            {
                                public StringBuilder fold(StringBuilder acc, ResultSet rs, StatementContext ctx) throws SQLException
                                {
                                    acc.append(rs.getString(1)).append(", ");
                                    return acc;
                                }
                            });
        rs.delete(rs.length() - 2, rs.length()); // trim the extra ", "
        assertThat(rs.toString(), equalTo("Mark, Tatu"));
        h.close();
    }
>>>>>>> ae36615add8bda1d0ed89541eab05e92290a22f1
}
Solution content
    {
        h.close();
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");
        h.execute("insert into something (id, name) values (7, 'Mark')");
        h.execute("insert into something (id, name) values (8, 'Tatu')");


        StringBuilder rs = h.createQuery("select name from something order by id")
                            .map(StringMapper.FIRST)
                            .fold(new StringBuilder(), new Folder2()
                            {
                                public StringBuilder fold(StringBuilder acc, ResultSet rs, StatementContext ctx) throws SQLException
                                {
                                    acc.append(rs.getString(1)).append(", ");
                                    return acc;
                                }
                            });
        rs.delete(rs.length() - 2, rs.length()); // trim the extra ", "
        assertThat(rs.toString(), equalTo("Mark, Tatu"));
        h.close();
    }


    @Test
    public void testMappingExampleChainedIterator2() throws Exception
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");
        h.execute("insert into something (id, name) values (1, 'Brian')");
        h.execute("insert into something (id, name) values (2, 'Keith')");


        Iterator rs = h.createQuery("select name from something order by id")
            .map(StringMapper.FIRST)
            .iterator();

        assertThat(rs.next(), equalTo("Brian"));
        assertThat(rs.next(), equalTo("Keith"));
        assertThat(rs.hasNext(), equalTo(false));

    }

    @Test
    public void testMappingExampleChainedIterator3() throws Exception
    {
        DBI dbi = new DBI("jdbc:h2:mem:test");
        Handle h = dbi.open();
        h.execute("create table something (id int primary key, name varchar(100))");
        h.execute("insert into something (id, name) values (1, 'Brian')");
        h.execute("insert into something (id, name) values (2, 'Keith')");

        for (String name : h.createQuery("select name from something order by id").map(StringMapper.FIRST))
        {
            assertThat(name, equalsOneOf("Brian", "Keith"));
        }

        h.close();
    }

}
File
TestDocumenation.java
Developer's decision
Manual
Kind of conflict
Comment
For statement
Method invocation
Variable