Search in sources :

Example 6 with ServerH2

use of com.github.fabriciofx.cactoos.jdbc.server.ServerH2 in project cactoos-jdbc by fabriciofx.

the class StatementInsertTest method insert.

@Test
public void insert() throws Exception {
    try (Servers servers = new Servers(new ServerH2(), new ServerMysql(), new ServerPgsql())) {
        for (final Session session : servers.sessions()) {
            new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t01 (id INT, name VARCHAR(50),", "PRIMARY KEY (id))"))).result();
            MatcherAssert.assertThat("Can't insert into table", new ResultAsValue<>(new StatementInsert(session, new QuerySimple(new Joined(" ", "INSERT INTO t01 (id, name)", "VALUES (:id, :name)"), new ParamInt("id", 1), new ParamText("name", "Yegor Bugayenko")))), new HasValue<>(false));
        }
    }
}
Also used : ServerH2(com.github.fabriciofx.cactoos.jdbc.server.ServerH2) ServerMysql(com.github.fabriciofx.cactoos.jdbc.server.ServerMysql) Servers(com.github.fabriciofx.cactoos.jdbc.Servers) ServerPgsql(com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql) ParamInt(com.github.fabriciofx.cactoos.jdbc.param.ParamInt) ParamText(com.github.fabriciofx.cactoos.jdbc.param.ParamText) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) Joined(org.cactoos.text.Joined) Session(com.github.fabriciofx.cactoos.jdbc.Session) Test(org.junit.Test)

Example 7 with ServerH2

use of com.github.fabriciofx.cactoos.jdbc.server.ServerH2 in project cactoos-jdbc by fabriciofx.

the class StatementSelectTest method select.

@Test
public void select() throws Exception {
    try (Servers servers = new Servers(new ServerH2(), new ServerMysql(), new ServerPgsql())) {
        for (final Session session : servers.sessions()) {
            new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE employee (id INT,", "name VARCHAR(50), birthday DATE,", "address VARCHAR(100),", "married BOOLEAN, salary DECIMAL(20,2),", "PRIMARY KEY (id))"))).result();
            new StatementBatch(session, new QueryBatch(new Joined(" ", "INSERT INTO employee", "(id, name, birthday, address, married, salary)", "VALUES (:id, :name, :birthday, :address,", ":married, :salary)"), new ParamsNamed(new ParamInt("id", 1), new ParamText("name", "John Wick"), new ParamDate("birthday", "1980-08-15"), new ParamText("address", "Boulevard Street, 34"), new ParamBool("married", false), new ParamDecimal("salary", "13456.00")), new ParamsNamed(new ParamInt("id", 2), new ParamText("name", "Adam Park"), new ParamDate("birthday", "1985-07-09"), new ParamText("address", "Sunset Place, 14"), new ParamBool("married", true), new ParamDecimal("salary", "12345.00")))).result();
            MatcherAssert.assertThat(XhtmlMatchers.xhtml(new ResultSetAsXml(new StatementSelect(session, new QuerySimple("SELECT * FROM employee")), "employees", "employee").value()), XhtmlMatchers.hasXPaths("/employees/employee/id[text()='1']", "/employees/employee/name[text()='John Wick']", String.join("", "/employees/employee/address[text()=", "'Boulevard Street, 34']"), "/employees/employee/married[text()='false']", "/employees/employee/salary[text()='13456.00']", "/employees/employee/id[text()='2']", "/employees/employee/name[text()='Adam Park']", String.join("", "/employees/employee/address[text()=", "'Sunset Place, 14']"), "/employees/employee/married[text()='true']", "/employees/employee/salary[text()='12345.00']"));
        }
    }
}
Also used : ServerH2(com.github.fabriciofx.cactoos.jdbc.server.ServerH2) ParamsNamed(com.github.fabriciofx.cactoos.jdbc.params.ParamsNamed) ServerMysql(com.github.fabriciofx.cactoos.jdbc.server.ServerMysql) Servers(com.github.fabriciofx.cactoos.jdbc.Servers) ServerPgsql(com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql) ParamInt(com.github.fabriciofx.cactoos.jdbc.param.ParamInt) ParamText(com.github.fabriciofx.cactoos.jdbc.param.ParamText) ParamBool(com.github.fabriciofx.cactoos.jdbc.param.ParamBool) ParamDecimal(com.github.fabriciofx.cactoos.jdbc.param.ParamDecimal) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) QueryBatch(com.github.fabriciofx.cactoos.jdbc.query.QueryBatch) ParamDate(com.github.fabriciofx.cactoos.jdbc.param.ParamDate) Joined(org.cactoos.text.Joined) Session(com.github.fabriciofx.cactoos.jdbc.Session) ResultSetAsXml(com.github.fabriciofx.cactoos.jdbc.result.ResultSetAsXml) Test(org.junit.Test)

Example 8 with ServerH2

use of com.github.fabriciofx.cactoos.jdbc.server.ServerH2 in project cactoos-jdbc by fabriciofx.

the class PhonebookTest method renameContact.

@Test
public void renameContact() throws Exception {
    try (Servers servers = new Servers(new ServerH2(new ScriptSql(new ResourceOf(new Joined("/", "com/github/fabriciofx/cactoos/jdbc/phonebook", "phonebook-h2.sql")))), new ServerPgsql(new ScriptSql(new ResourceOf(new Joined("/", "com/github/fabriciofx/cactoos/jdbc/phonebook", "phonebook-pgsql.sql")))))) {
        for (final Session session : servers.sessions()) {
            final Phonebook phonebook = new PhonebookSql(session);
            final Contact contact = phonebook.filter("maria").iterator().next();
            contact.update(new MapOf<String, String>(new MapEntry<>("name", "Maria Lima")));
            MatcherAssert.assertThat(XhtmlMatchers.xhtml(new PhonebookSql(session).filter("maria").iterator().next().about()), XhtmlMatchers.hasXPaths("/contact/name[text()='Maria Lima']"));
        }
    }
}
Also used : ServerH2(com.github.fabriciofx.cactoos.jdbc.server.ServerH2) MapEntry(org.cactoos.map.MapEntry) PhonebookSql(com.github.fabriciofx.cactoos.jdbc.phonebook.sql.PhonebookSql) Servers(com.github.fabriciofx.cactoos.jdbc.Servers) ServerPgsql(com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql) Contact(com.github.fabriciofx.cactoos.jdbc.phonebook.Contact) ScriptSql(com.github.fabriciofx.cactoos.jdbc.script.ScriptSql) Phonebook(com.github.fabriciofx.cactoos.jdbc.phonebook.Phonebook) ResourceOf(org.cactoos.io.ResourceOf) Joined(org.cactoos.text.Joined) Session(com.github.fabriciofx.cactoos.jdbc.Session) Test(org.junit.Test)

Aggregations

ServerH2 (com.github.fabriciofx.cactoos.jdbc.server.ServerH2)8 Joined (org.cactoos.text.Joined)8 Test (org.junit.Test)8 Session (com.github.fabriciofx.cactoos.jdbc.Session)7 Servers (com.github.fabriciofx.cactoos.jdbc.Servers)6 ServerPgsql (com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql)6 ParamText (com.github.fabriciofx.cactoos.jdbc.param.ParamText)5 QuerySimple (com.github.fabriciofx.cactoos.jdbc.query.QuerySimple)5 ParamInt (com.github.fabriciofx.cactoos.jdbc.param.ParamInt)4 ServerMysql (com.github.fabriciofx.cactoos.jdbc.server.ServerMysql)4 ParamsNamed (com.github.fabriciofx.cactoos.jdbc.params.ParamsNamed)3 QueryBatch (com.github.fabriciofx.cactoos.jdbc.query.QueryBatch)3 ResourceOf (org.cactoos.io.ResourceOf)3 Server (com.github.fabriciofx.cactoos.jdbc.Server)2 ParamBool (com.github.fabriciofx.cactoos.jdbc.param.ParamBool)2 ParamDate (com.github.fabriciofx.cactoos.jdbc.param.ParamDate)2 ParamDecimal (com.github.fabriciofx.cactoos.jdbc.param.ParamDecimal)2 Contact (com.github.fabriciofx.cactoos.jdbc.phonebook.Contact)2 Phonebook (com.github.fabriciofx.cactoos.jdbc.phonebook.Phonebook)2 PhonebookSql (com.github.fabriciofx.cactoos.jdbc.phonebook.sql.PhonebookSql)2