Search in sources :

Example 1 with ParamsNamed

use of com.github.fabriciofx.cactoos.jdbc.params.ParamsNamed in project cactoos-jdbc by fabriciofx.

the class StatementSelectTest method any.

@Test
public void any() 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 person (id INT, name VARCHAR(30),", "created_at DATE, city VARCHAR(20),", "working BOOLEAN, height DECIMAL(20,2),", "PRIMARY KEY (id))"))).result();
            new StatementBatch(session, new QueryBatch(new Joined(" ", "INSERT INTO person", "(id, name, created_at, city, working, height)", "VALUES (:id, :name, :created_at, :city,", ":working, :height)"), new ParamsNamed(new ParamInt("id", 1), new ParamText("name", "Rob Pike"), new ParamDate("created_at", LocalDate.now()), new ParamText("city", "San Francisco"), new ParamBool("working", true), new ParamDecimal("height", "1.86")), new ParamsNamed(new ParamInt("id", 2), new ParamText("name", "Ana Pivot"), new ParamDate("created_at", LocalDate.now()), new ParamText("city", "Washington"), new ParamBool("working", false), new ParamDecimal("height", "1.62")))).result();
            MatcherAssert.assertThat("Can't select a person name", new ResultSetAsValue<>(new StatementSelect(session, new QuerySimple("SELECT name FROM person"))), new HasValue<>("Rob Pike"));
        }
    }
}
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) Test(org.junit.Test)

Example 2 with ParamsNamed

use of com.github.fabriciofx.cactoos.jdbc.params.ParamsNamed in project cactoos-jdbc by fabriciofx.

the class StatementBatchTest method batch.

@Test
public void batch() 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 client (id INT,", "name VARCHAR(50), age INT, PRIMARY KEY (id))"))).result();
            new StatementBatch(session, new QueryBatch(new Joined(" ", "INSERT INTO client (id, name, age)", "VALUES (:id, :name, :age)"), new ParamsNamed(new ParamInt("id", 1), new ParamText("name", "Jeff Bridges"), // @checkstyle MagicNumber (1 line)
            new ParamInt("age", 34)), new ParamsNamed(new ParamInt("id", 2), new ParamText("name", "Anna Miller"), // @checkstyle MagicNumber (1 line)
            new ParamInt("age", 26)), new ParamsNamed(// @checkstyle MagicNumber (3 lines)
            new ParamInt("id", 3), new ParamText("name", "Michal Douglas"), new ParamInt("age", 32)))).result();
        }
    }
}
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) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) QueryBatch(com.github.fabriciofx.cactoos.jdbc.query.QueryBatch) Joined(org.cactoos.text.Joined) Session(com.github.fabriciofx.cactoos.jdbc.Session) Test(org.junit.Test)

Example 3 with ParamsNamed

use of com.github.fabriciofx.cactoos.jdbc.params.ParamsNamed 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)

Aggregations

Servers (com.github.fabriciofx.cactoos.jdbc.Servers)3 Session (com.github.fabriciofx.cactoos.jdbc.Session)3 ParamInt (com.github.fabriciofx.cactoos.jdbc.param.ParamInt)3 ParamText (com.github.fabriciofx.cactoos.jdbc.param.ParamText)3 ParamsNamed (com.github.fabriciofx.cactoos.jdbc.params.ParamsNamed)3 QueryBatch (com.github.fabriciofx.cactoos.jdbc.query.QueryBatch)3 QuerySimple (com.github.fabriciofx.cactoos.jdbc.query.QuerySimple)3 ServerH2 (com.github.fabriciofx.cactoos.jdbc.server.ServerH2)3 ServerMysql (com.github.fabriciofx.cactoos.jdbc.server.ServerMysql)3 ServerPgsql (com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql)3 Joined (org.cactoos.text.Joined)3 Test (org.junit.Test)3 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 ResultSetAsXml (com.github.fabriciofx.cactoos.jdbc.result.ResultSetAsXml)1