Search in sources :

Example 1 with ParamUuid

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

the class PhonebookSql method contact.

@Override
public Contact contact(final Map<String, String> properties) throws Exception {
    final UUID id = UUID.randomUUID();
    new StatementInsert(this.session, new QuerySimple("INSERT INTO contact (id, name) VALUES (:id, :name)", new ParamUuid("id", id), new ParamText("name", properties.get("name")))).result();
    return new ContactSql(this.session, id);
}
Also used : ParamUuid(com.github.fabriciofx.cactoos.jdbc.param.ParamUuid) ParamText(com.github.fabriciofx.cactoos.jdbc.param.ParamText) StatementInsert(com.github.fabriciofx.cactoos.jdbc.statement.StatementInsert) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) UUID(java.util.UUID)

Example 2 with ParamUuid

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

the class ContactSql method about.

@Override
public String about() throws Exception {
    final String contact = new ResultSetAsValue<String>(new StatementSelect(this.session, new QuerySimple("SELECT name FROM contact WHERE id = :id", new ParamUuid("id", this.id)))).value();
    final String phones = new ResultSetAsXmlEach(new StatementSelect(this.session, new QuerySimple(new Joined(" ", "SELECT number, carrier FROM phone WHERE", "contact_id = :contact_id"), new ParamUuid("contact_id", this.id))), "phone").value();
    final String xml;
    if (phones.isEmpty()) {
        xml = "<contact><name>%s</name></contact>";
    } else {
        xml = "<contact><name>%s</name><phones>%s</phones></contact>";
    }
    return new FormattedText(xml, contact, phones).asString();
}
Also used : ParamUuid(com.github.fabriciofx.cactoos.jdbc.param.ParamUuid) StatementSelect(com.github.fabriciofx.cactoos.jdbc.statement.StatementSelect) ResultSetAsXmlEach(com.github.fabriciofx.cactoos.jdbc.result.ResultSetAsXmlEach) QuerySimple(com.github.fabriciofx.cactoos.jdbc.query.QuerySimple) FormattedText(org.cactoos.text.FormattedText) Joined(org.cactoos.text.Joined)

Aggregations

ParamUuid (com.github.fabriciofx.cactoos.jdbc.param.ParamUuid)2 QuerySimple (com.github.fabriciofx.cactoos.jdbc.query.QuerySimple)2 ParamText (com.github.fabriciofx.cactoos.jdbc.param.ParamText)1 ResultSetAsXmlEach (com.github.fabriciofx.cactoos.jdbc.result.ResultSetAsXmlEach)1 StatementInsert (com.github.fabriciofx.cactoos.jdbc.statement.StatementInsert)1 StatementSelect (com.github.fabriciofx.cactoos.jdbc.statement.StatementSelect)1 UUID (java.util.UUID)1 FormattedText (org.cactoos.text.FormattedText)1 Joined (org.cactoos.text.Joined)1