Java Code Examples for org.cactoos.text.Joined

The following examples show how to use org.cactoos.text.Joined. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public int executeUpdate() throws SQLException {
    final Instant start = Instant.now();
    final int updated = this.origin.executeUpdate();
    final Instant end = Instant.now();
    final long millis = Duration.between(start, end).toMillis();
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] updated a source and",
                    "returned '%d' in %dms."
                ),
                this.source,
                this.id,
                updated,
                millis
            )
        ).asString()
    );
    return updated;
}
 
Example 2
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setNull(final int index, final int type) throws SQLException {
    this.origin.setNull(index, type);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%d' value."
                ),
                this.source,
                this.id,
                index,
                type
            )
        ).asString()
    );
}
 
Example 3
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setBoolean(
    final int index,
    final boolean value
) throws SQLException {
    this.origin.setBoolean(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%s' value."
                ),
                this.source,
                this.id,
                index,
                value
            )
        ).asString()
    );
}
 
Example 4
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setByte(final int index, final byte value) throws SQLException {
    this.origin.setByte(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%d' value."
                ),
                this.source,
                this.id,
                index,
                value
            )
        ).asString()
    );
}
 
Example 5
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setShort(
    final int index,
    final short value
) throws SQLException {
    this.origin.setShort(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%d' value."
                ),
                this.source,
                this.id,
                index,
                value
            )
        ).asString()
    );
}
 
Example 6
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setInt(final int index, final int value) throws SQLException {
    this.origin.setInt(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%d' value."
                ),
                this.source,
                this.id,
                index,
                value
            )
        ).asString()
    );
}
 
Example 7
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setLong(final int index, final long value) throws SQLException {
    this.origin.setLong(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%d' value."
                ),
                this.source,
                this.id,
                index,
                value
            )
        ).asString()
    );
}
 
Example 8
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setFloat(
    final int index,
    final float value
) throws SQLException {
    this.origin.setFloat(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%f' value."
                ),
                this.source,
                this.id,
                index,
                value
            )
        ).asString()
    );
}
 
Example 9
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setDouble(
    final int index,
    final double value
) throws SQLException {
    this.origin.setDouble(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%f' value."
                ),
                this.source,
                this.id,
                index,
                value
            )
        ).asString()
    );
}
 
Example 10
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setBigDecimal(
    final int index,
    final BigDecimal value
) throws SQLException {
    this.origin.setBigDecimal(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%s' value."
                ),
                this.source,
                this.id,
                index,
                value.toString()
            )
        ).asString()
    );
}
 
Example 11
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setBytes(
    final int index,
    final byte[] values
) throws SQLException {
    this.origin.setBytes(index, values);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%d' bytes."
                ),
                this.source,
                this.id,
                index,
                values.length
            )
        ).asString()
    );
}
 
Example 12
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setDate(final int index, final Date value) throws SQLException {
    this.origin.setDate(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%s' value."
                ),
                this.source,
                this.id,
                index,
                value.toString()
            )
        ).asString()
    );
}
 
Example 13
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setTime(final int index, final Time value) throws SQLException {
    this.origin.setTime(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%s' value."
                ),
                this.source,
                this.id,
                index,
                value.toString()
            )
        ).asString()
    );
}
 
Example 14
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setTimestamp(
    final int index,
    final Timestamp value
) throws SQLException {
    this.origin.setTimestamp(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%s' value."
                ),
                this.source,
                this.id,
                index,
                value.toString()
            )
        ).asString()
    );
}
 
Example 15
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setAsciiStream(
    final int index,
    final InputStream stream,
    final int length
) throws SQLException {
    this.origin.setAsciiStream(index, stream, length);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%d' bytes."
                ),
                this.source,
                this.id,
                index,
                length
            )
        ).asString()
    );
}
 
Example 16
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
/**
 * Set a stream to Unicode.
 * @deprecated It not should be used
 * @param index Parameter index
 * @param stream InputStream
 * @param length Data length
 * @throws SQLException If fails
 */
@Deprecated
public void setUnicodeStream(
    final int index,
    final InputStream stream,
    final int length
) throws SQLException {
    this.origin.setUnicodeStream(index, stream, length);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%d' bytes."
                ),
                this.source,
                this.id,
                index,
                length
            )
        ).asString()
    );
}
 
Example 17
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setBinaryStream(
    final int index,
    final InputStream stream,
    final int length
) throws SQLException {
    this.origin.setBinaryStream(index, stream, length);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%d' bytes."
                ),
                this.source,
                this.id,
                index,
                length
            )
        ).asString()
    );
}
 
Example 18
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setObject(
    final int index,
    final Object value,
    final int type
) throws SQLException {
    this.origin.setObject(index, value, type);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%s' data and '%d' type."
                ),
                this.source,
                this.id,
                index,
                value.toString(),
                type
            )
        ).asString()
    );
}
 
Example 19
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setObject(
    final int index,
    final Object value
) throws SQLException {
    this.origin.setObject(index, value);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed at",
                    "parameter[#%d] with '%s' value."
                ),
                this.source,
                this.id,
                index,
                value.toString()
            )
        ).asString()
    );
}
 
Example 20
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setMaxFieldSize(final int max) throws SQLException {
    this.origin.setMaxFieldSize(max);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed",
                    "max field size to '%d' bytes."
                ),
                this.source,
                this.id,
                max
            )
        ).asString()
    );
}
 
Example 21
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public void setQueryTimeout(final int seconds) throws SQLException {
    this.origin.setQueryTimeout(seconds);
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] changed",
                    "timeout to '%d' seconds."
                ),
                this.source,
                this.id,
                seconds
            )
        ).asString()
    );
}
 
Example 22
Source Project: cactoos-jdbc   Source File: Logged.java    License: MIT License 6 votes vote down vote up
@Override
public ResultSet getGeneratedKeys() throws SQLException {
    final Instant start = Instant.now();
    final ResultSet rset = this.origin.getGeneratedKeys();
    final Instant end = Instant.now();
    final long millis = Duration.between(start, end).toMillis();
    this.logger.log(
        this.level,
        new UncheckedText(
            new FormattedText(
                new Joined(
                    " ",
                    "[%s] PreparedStatement[#%d] returned",
                    "a ResultSet keys in %dms."
                ),
                this.source,
                this.id,
                millis
            )
        ).asString()
    );
    return rset;
}
 
Example 23
Source Project: cactoos-jdbc   Source File: ScriptSqlTest.java    License: MIT License 6 votes vote down vote up
@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();
}
 
Example 24
Source Project: cactoos-jdbc   Source File: ScriptSqlTest.java    License: MIT License 6 votes vote down vote up
@Test
public void mysqlServer() throws Exception {
    final Server server = new ServerMysql(
        new ScriptSql(
            new ResourceOf(
                new Joined(
                    "/",
                    "com/github/fabriciofx/cactoos/jdbc/phonebook",
                    "phonebook-mysql.sql"
                )
            )
        )
    );
    server.start();
    server.stop();
}
 
Example 25
Source Project: cactoos-jdbc   Source File: QuerySimpleTest.java    License: MIT License 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void outOfOrder() throws Exception {
    new QuerySimple(
        new Joined(
            " ",
            "INSERT INTO employee",
            "(name, birthday, address, married, salary)",
            "VALUES (:name, :birthday, :address, :married, :salary)"
        ),
        new ParamText("name", "John Wick"),
        new ParamDate("address", "1980-08-16"),
        new ParamText("birthday", "Boulevard Street, 34"),
        new ParamBool("married", false),
        new ParamDecimal("salary", "13456.00")
    ).asString();
}
 
Example 26
Source Project: jpeek   Source File: Futures.java    License: MIT License 6 votes vote down vote up
@Override
public String asString() throws IOException {
    return Logger.format(
        // @checkstyle LineLength (1 line)
        "Artifacts=%d, processors=%d, threads=%d, freeMemory=%dM, maxMemory=%dM, totalMemory=%dM, ETA=%[ms]s:\n%s\n\nThreads: %s",
        this.queue.size(),
        Runtime.getRuntime().availableProcessors(),
        Thread.getAllStackTraces().keySet().size(),
        // @checkstyle MagicNumber (3 lines)
        Runtime.getRuntime().freeMemory() / (1024L << 10),
        Runtime.getRuntime().maxMemory() / (1024L << 10),
        Runtime.getRuntime().totalMemory() / (1024L << 10),
        new AvgOf(
            this.times.toArray(new Long[this.times.size()])
        ).longValue() * (long) this.queue.size(),
        new Joined(", ", this.queue.keySet()).asString(),
        new Joined(
            ", ",
            new Mapped<>(
                Thread::getName,
                Thread.getAllStackTraces().keySet()
            )
        ).asString()
    );
}
 
Example 27
Source Project: cactoos-jdbc   Source File: PhoneSql.java    License: MIT License 6 votes vote down vote up
@Override
public void update(final Map<String, String> properties) throws Exception {
    new StatementUpdate(
        this.session,
        new QuerySimple(
            new Joined(
                " ",
                "UPDATE phone SET number = :number, carrier = :carrier",
                "WHERE (contact_id = :contact_id) AND (number = :number)"
            ),
            new ParamText("number", properties.get("number")),
            new ParamText("carrier", properties.get("carrier")),
            new ParamUuid("contact_id", this.id),
            new ParamText("number", this.num)
        )
    ).result();
}
 
Example 28
Source Project: cactoos-jdbc   Source File: ContactsSqlFiltered.java    License: MIT License 6 votes vote down vote up
/**
 * Ctor.
 * @param sssn A Session.
 * @param name Contact's name to be filtered.
 */
public ContactsSqlFiltered(final Session sssn, final String name) {
    this.session = sssn;
    this.ids = new ResultSetAsValues<>(
        new StatementSelect(
            sssn,
            new QuerySimple(
                new Joined(
                    " ",
                    "SELECT id FROM contact WHERE LOWER(name) LIKE",
                    "'%' || :name || '%'"
                ),
                new ParamText("name", new Lowered(name))
            )
        )
    );
}
 
Example 29
Source Project: cactoos-jdbc   Source File: PhonesSql.java    License: MIT License 6 votes vote down vote up
@Override
public int count() throws Exception {
    return new ResultSetAsValue<Integer>(
        new StatementSelect(
            this.session,
            new QuerySimple(
                new Joined(
                    " ",
                    "SELECT COUNT(number) FROM phone WHERE",
                    "contact_id = :contact_id"
                ),
                new ParamUuid("contact_id", this.id)
            )
        )
    ).value();
}
 
Example 30
Source Project: cactoos-jdbc   Source File: PhonesSql.java    License: MIT License 6 votes vote down vote up
@Override
public Phone get(final int index) throws Exception {
    final Scalar<String> number = new ResultSetAsValue<>(
        new StatementSelect(
            this.session,
            new QuerySimple(
                new FormattedText(
                    new Joined(
                        " ",
                        "SELECT number FROM phone WHERE",
                        "contact_id = :contact_id",
                        "FETCH FIRST %d ROWS ONLY"
                    ),
                    index
                )
            )
        )
    );
    return new PhoneSql(this.session, this.id, number.value());
}