Package com.jcabi.jdbc

Examples of com.jcabi.jdbc.JdbcSession


     * @throws IOException If an IO Exception occurs.
     */
    H2DomainStatsData(final File file) throws IOException {
        this.jdbc = String.format("jdbc:h2:file:%s", file.getAbsolutePath());
        try {
            new JdbcSession(this.connection()).sql(CREATE).execute();
        } catch (final SQLException ex) {
            throw new IOException(ex);
        }
    }
View Full Code Here


    }

    @Override
    public void put(final String domain, final Stats stats) throws IOException {
        try {
            new JdbcSession(this.connection())
                .sql(INSERT)
                .set(domain)
                .set(stats.bytesTransferred())
                .execute();
        } catch (final SQLException ex) {
View Full Code Here

    }

    @Override
    public Stats get(final String domain) throws IOException {
        try {
            final JdbcSession session = new JdbcSession(this.connection())
                .autocommit(false);
            // @checkstyle LineLength (2 lines)
            final Stats result = session
                .sql("SELECT SUM(BYTES) FROM DOMAIN_STATS WHERE DOMAIN = ? FOR UPDATE")
                .set(domain)
                .select(STATS);
            session.sql("DELETE FROM DOMAIN_STATS WHERE DOMAIN = ?")
                .set(domain)
                .execute()
                .commit();
            return result;
        } catch (final SQLException ex) {
View Full Code Here

    @Override
    @SuppressWarnings("PMD.UseConcurrentHashMap")
    public Map<String, Stats> all() throws IOException {
        try {
            final JdbcSession session = new JdbcSession(this.connection())
                .autocommit(false);
            // @checkstyle LineLength (2 lines)
            final Map<String, Stats> result = session
                .sql("SELECT DOMAIN, SUM(BYTES) FROM DOMAIN_STATS GROUP BY DOMAIN FOR UPDATE")
                .select(STATS_ALL);
            session.sql("DELETE FROM DOMAIN_STATS").execute().commit();
            return result;
        } catch (final SQLException ex) {
            throw new IOException(ex);
        }
    }
View Full Code Here

TOP

Related Classes of com.jcabi.jdbc.JdbcSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.