Search in sources :

Example 1 with StatementSelect

use of com.github.fabriciofx.cactoos.jdbc.statement.StatementSelect 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)1 QuerySimple (com.github.fabriciofx.cactoos.jdbc.query.QuerySimple)1 ResultSetAsXmlEach (com.github.fabriciofx.cactoos.jdbc.result.ResultSetAsXmlEach)1 StatementSelect (com.github.fabriciofx.cactoos.jdbc.statement.StatementSelect)1 FormattedText (org.cactoos.text.FormattedText)1 Joined (org.cactoos.text.Joined)1