Search in sources :

Example 1 with Server

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

the class StatementInsertTest method insertWithKeysH2.

@Test
public // @checkstyle MethodNameCheck (1 line)
void insertWithKeysH2() throws Exception {
    try (Server server = new ServerH2()) {
        server.start();
        final Session session = server.session();
        new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t02 (id INT AUTO_INCREMENT,", "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 : ServerH2(com.github.fabriciofx.cactoos.jdbc.server.ServerH2) ParamText(com.github.fabriciofx.cactoos.jdbc.param.ParamText) Server(com.github.fabriciofx.cactoos.jdbc.Server) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) 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 Server

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

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

the class ResultAsValueTest method insertWithKeys.

@Test
public void insertWithKeys() throws Exception {
    try (Server server = new ServerMysql()) {
        server.start();
        final Session session = server.session();
        new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE contact (", "id INT AUTO_INCREMENT,", "name VARCHAR(50) NOT NULL,", "CONSTRAINT pk_contact PRIMARY KEY(id))"))).result();
        MatcherAssert.assertThat("Can't get a generated key value", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed(() -> "INSERT INTO contact (name) VALUES (:name)", "id", new ParamText("name", "Leonardo da Vinci")))), new HasValue<>(BigInteger.ONE));
    }
}
Also used : StatementInsertKeyed(com.github.fabriciofx.cactoos.jdbc.statement.StatementInsertKeyed) ParamText(com.github.fabriciofx.cactoos.jdbc.param.ParamText) Server(com.github.fabriciofx.cactoos.jdbc.Server) StatementUpdate(com.github.fabriciofx.cactoos.jdbc.statement.StatementUpdate) ServerMysql(com.github.fabriciofx.cactoos.jdbc.server.ServerMysql) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) 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 4 with Server

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

the class ScriptSqlTest method h2Server.

@Test
public void h2Server() throws Exception {
    final Server server = new ServerH2(new ScriptSql(new ResourceOf(new Joined("/", "com/github/fabriciofx/cactoos/jdbc/phonebook", "phonebook-h2.sql"))));
    server.start();
    server.stop();
}
Also used : ServerH2(com.github.fabriciofx.cactoos.jdbc.server.ServerH2) Server(com.github.fabriciofx.cactoos.jdbc.Server) ResourceOf(org.cactoos.io.ResourceOf) Joined(org.cactoos.text.Joined) Test(org.junit.Test)

Example 5 with Server

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

the class StatementInsertTest method insertWithKeysMysql.

@Test
public void insertWithKeysMysql() throws Exception {
    try (Server server = new ServerMysql()) {
        server.start();
        final Session session = server.session();
        new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t02 (id INT AUTO_INCREMENT,", "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)", "id", new ParamText("name", "Jeff Malony")))), new HasValue<>(BigInteger.ONE));
    }
}
Also used : ParamText(com.github.fabriciofx.cactoos.jdbc.param.ParamText) Server(com.github.fabriciofx.cactoos.jdbc.Server) ServerMysql(com.github.fabriciofx.cactoos.jdbc.server.ServerMysql) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) Joined(org.cactoos.text.Joined) QueryKeyed(com.github.fabriciofx.cactoos.jdbc.query.QueryKeyed) Session(com.github.fabriciofx.cactoos.jdbc.Session) Test(org.junit.Test)

Aggregations

Server (com.github.fabriciofx.cactoos.jdbc.Server)6 Joined (org.cactoos.text.Joined)6 Test (org.junit.Test)6 Session (com.github.fabriciofx.cactoos.jdbc.Session)4 ParamText (com.github.fabriciofx.cactoos.jdbc.param.ParamText)4 QueryKeyed (com.github.fabriciofx.cactoos.jdbc.query.QueryKeyed)4 QuerySimple (com.github.fabriciofx.cactoos.jdbc.query.QuerySimple)4 ServerMysql (com.github.fabriciofx.cactoos.jdbc.server.ServerMysql)3 ServerH2 (com.github.fabriciofx.cactoos.jdbc.server.ServerH2)2 ResourceOf (org.cactoos.io.ResourceOf)2 ServerPgsql (com.github.fabriciofx.cactoos.jdbc.server.ServerPgsql)1 StatementInsertKeyed (com.github.fabriciofx.cactoos.jdbc.statement.StatementInsertKeyed)1 StatementUpdate (com.github.fabriciofx.cactoos.jdbc.statement.StatementUpdate)1