Search in sources :

Example 1 with ServerPgsql

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

the class StatementInsertTest method insertWithKeysPsql.

@Test
public void insertWithKeysPsql() throws Exception {
    try (Server server = new ServerPgsql()) {
        server.start();
        final Session session = server.session();
        new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t02 (id SERIAL,", "name VARCHAR(50), PRIMARY KEY (id))"))).result();
        MatcherAssert.assertThat("Can't insert with an integer keys", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed("INSERT INTO t02 (name) VALUES (:name)", new ParamText("name", "Jeff Malony")))), new HasValue<>(1));
    }
}
Also used : ParamText(com.github.fabriciofx.cactoos.jdbc.param.ParamText) Server(com.github.fabriciofx.cactoos.jdbc.Server) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) ServerPgsql(com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql) Joined(org.cactoos.text.Joined) QueryKeyed(com.github.fabriciofx.cactoos.jdbc.query.QueryKeyed) Session(com.github.fabriciofx.cactoos.jdbc.Session) Test(org.junit.Test)

Example 2 with ServerPgsql

use of com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql 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 3 with ServerPgsql

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

the class PhonebookTest method addContact.

@Test
public void addContact() 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.contact(new MapOf<String, String>(new MapEntry<>("name", "Donald Knuth")));
            contact.phones().add(new MapOf<String, String>(new MapEntry<>("number", "99991234"), new MapEntry<>("carrier", "TIM")));
            contact.phones().add(new MapOf<String, String>(new MapEntry<>("number", "98812564"), new MapEntry<>("carrier", "Oi")));
            MatcherAssert.assertThat(XhtmlMatchers.xhtml(contact.about()), XhtmlMatchers.hasXPaths("/contact/name[text()='Donald Knuth']", "/contact/phones/phone/number[text()='99991234']", "/contact/phones/phone/carrier[text()='TIM']", "/contact/phones/phone/number[text()='98812564']", "/contact/phones/phone/carrier[text()='Oi']"));
        }
    }
}
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)

Example 4 with ServerPgsql

use of com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql 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 5 with ServerPgsql

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

Aggregations

Session (com.github.fabriciofx.cactoos.jdbc.Session)7 ServerPgsql (com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql)7 Joined (org.cactoos.text.Joined)7 Test (org.junit.Test)7 Servers (com.github.fabriciofx.cactoos.jdbc.Servers)6 ServerH2 (com.github.fabriciofx.cactoos.jdbc.server.ServerH2)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 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 ScriptSql (com.github.fabriciofx.cactoos.jdbc.script.ScriptSql)2 ResourceOf (org.cactoos.io.ResourceOf)2