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);
}
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();
}
Aggregations