• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java JdbcSession类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.jcabi.jdbc.JdbcSession的典型用法代码示例。如果您正苦于以下问题:Java JdbcSession类的具体用法?Java JdbcSession怎么用?Java JdbcSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

JdbcSession类属于com.jcabi.jdbc包,在下文中一共展示了JdbcSession类的39个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: product

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Product product(long number) {
    try {
        return new JdbcSession(this.dBase)
                .sql("SELECT * FROM product WHERE id=?")
                .set(number)
                .select((rset, stmt) -> {
                    if (!rset.next()) {
                        throw new IllegalStateException("no product");
                    }
                    return create(rset);
                });
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:17,
代码来源:ConstH2Products.java

示例2: call

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
/**
 * Wrap the body with transaction.
 *
 * @param body The body to be executed with transaction.
 * @return Result of execution.
 */
<T> T call(Function<JdbcSession, T> body) {
    JdbcSession session = new JdbcSession(this.dbase);
    try {
        session.autocommit(false);
        T result = body.apply(session);
        session.sql("COMMIT").execute();
        return result;
    } catch (Exception ex) {
        try {
            session.sql("ROLLBACK").execute();
        } catch (Exception e) {
            // noop
        }
        return ExceptionUtils.rethrow(ex);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:23,
代码来源:Txn.java

示例3: post

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Message post(final boolean asking,
    final String text) throws IOException {
    if (text.isEmpty()) {
        throw new IllegalArgumentException("text can't be empty");
    }
    try {
        new JdbcSession(this.src.get())
            // @checkstyle LineLength (1 line)
            .sql("INSERT INTO message (talk, asking, text) VALUES (?, ?, ?)")
            .set(this.number)
            .set(asking)
            .set(text)
            .insert(Outcome.VOID);
        Logger.info(this, "posted in #%d, asking=%B", this.number, asking);
        return new Message.Simple(asking, text);
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:21,
代码来源:PgMessages.java

示例4: locale

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Locale locale() throws IOException {
    try {
        return new Locale(
            new JdbcSession(this.src.get())
                .set(this.num)
                .sql(
                    Joiner.on(' ').join(
                        "SELECT locale FROM question",
                        "JOIN talk ON talk.question=question.id",
                        "WHERE talk.id=?"
                    )
                )
                .select(new SingleOutcome<String>(String.class))
        );
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:20,
代码来源:PgTalk.java

示例5: ask

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public void ask(final String text) throws IOException {
    if (text.isEmpty()) {
        throw new IllegalArgumentException("text can't be empty");
    }
    try {
        final long num = new JdbcSession(this.src.get())
            .set(this.number)
            .set(text)
            .set(this.locale(text))
            .sql(
                Joiner.on(' ').join(
                    "INSERT INTO question (asker, text, locale)",
                    "VALUES (?, ?, ?)"
                )
            )
            .insert(new SingleOutcome<Long>(Long.class, true));
        Logger.info(this, "question #%d asked by #%d", num, this.number);
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:23,
代码来源:PgHuman.java

示例6: confirm

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public void confirm(final String code) throws IOException {
    if (!PgProfile.RE_CODE.matcher(code).matches()) {
        throw new Profile.ConfirmCodeException(
            "the code always contains four digits"
        );
    }
    try {
        final int done = new JdbcSession(this.src.get())
            .sql("UPDATE human SET code='0000' WHERE id=? AND code=?")
            .set(this.number)
            .set(code)
            .update(Outcome.UPDATE_COUNT);
        if (done == 0) {
            throw new Profile.ConfirmCodeException(
                "the code doesn't match our records"
            );
        }
        Logger.info(this, "email confirmed by human #%d", this.number);
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:24,
代码来源:PgProfile.java

示例7: photo

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public byte[] photo() throws IOException {
    try {
        return new JdbcSession(this.src.get())
            .sql("SELECT photo FROM human WHERE id=?")
            .set(this.number)
            .select(
                new Outcome<byte[]>() {
                    @Override
                    public byte[] handle(final ResultSet rset,
                        final Statement stmt) throws SQLException {
                        if (!rset.next()) {
                            throw new IllegalStateException("no human");
                        }
                        return rset.getBytes(1);
                    }
                }
            );
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:23,
代码来源:PgProfile.java

示例8: remind

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public void remind(final String email, final Pocket pocket)
    throws IOException {
    try {
        final boolean exists = new JdbcSession(this.src.get())
            .sql("SELECT code FROM human WHERE email=?")
            .set(email)
            .select(Outcome.NOT_EMPTY);
        if (exists) {
            final String password = new JdbcSession(this.src.get())
                .sql("SELECT password FROM human WHERE email=?")
                .set(email)
                .select(new SingleOutcome<String>(String.class));
            pocket.put(password);
        }
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:20,
代码来源:PgBase.java

示例9: human

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Human human(final URN urn) throws IOException {
    final long number = Long.parseLong(urn.nss());
    final boolean exists;
    try {
        exists = new JdbcSession(this.src.get())
            .sql("SELECT id FROM human WHERE id=?")
            .set(number)
            .select(Outcome.NOT_EMPTY);
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
    if (!exists) {
        throw new Base.HumanNotFoundException(
            String.format("user #%d not found", number)
        );
    }
    return new PgHuman(this.src, number);
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:20,
代码来源:PgBase.java

示例10: put

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public void put(final String table, final Attributes attrs)
    throws IOException {
    try {
        JdbcSession session = new JdbcSession(this.connection());
        for (final AttributeValue value : attrs.values()) {
            session = session.set(H2Data.value(value));
        }
        session.sql(
            String.format(
                "INSERT INTO %s (%s) VALUES (%s)",
                H2Data.encodeTableName(table),
                Joiner.on(',').join(attrs.keySet()),
                Joiner.on(',').join(Collections.nCopies(attrs.size(), "?"))
            )
        );
        session.execute();
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:jcabi,
项目名称:jcabi-dynamo,
代码行数:22,
代码来源:H2Data.java

示例11: delete

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public void delete(final String table, final Attributes keys)
    throws IOException {
    try {
        JdbcSession session = new JdbcSession(this.connection());
        for (final AttributeValue value : keys.values()) {
            session = session.set(H2Data.value(value));
        }
        session.sql(
            String.format(
                "DELETE FROM %s WHERE %s",
                H2Data.encodeTableName(table),
                Joiner.on(H2Data.AND).join(
                    Iterables.transform(keys.keySet(), H2Data.WHERE)
                )
            )
        );
        session.execute();
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:jcabi,
项目名称:jcabi-dynamo,
代码行数:23,
代码来源:H2Data.java

示例12: process

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
/**
 * Process on this port.
 * @param port Port to process
 * @throws Exception If fails
 */
private void process(final int port) throws Exception {
    final Connection conn = DriverManager.getConnection(
        String.format(
            "jdbc:mysql://localhost:%d/root?user=root&password=root",
            port
        )
    );
    new JdbcSession(conn)
        .autocommit(false)
        .sql("CREATE TABLE foo (id INT)")
        .execute()
        .sql("INSERT INTO foo VALUES (1)")
        .execute()
        .sql("SELECT COUNT(*) FROM foo")
        .execute()
        .sql("DROP TABLE foo")
        .execute();
}
 

开发者ID:jcabi,
项目名称:jcabi-mysql-maven-plugin,
代码行数:24,
代码来源:ParallelITCase.java

示例13: basicMySqlManipulations

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
/**
 * MySQL works.
 * @throws Exception If something is wrong
 */
@Test
public void basicMySqlManipulations() throws Exception {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    final Connection conn = DriverManager.getConnection(
        String.format(
            "jdbc:mysql://localhost:%s/root?user=root&password=root",
            FooITCase.PORT
        )
    );
    new JdbcSession(conn)
        .autocommit(false)
        .sql("CREATE TABLE foo (id INT)")
        .execute()
        .sql("INSERT INTO foo VALUES (1)")
        .execute()
        .sql("SELECT COUNT(*) FROM foo")
        .execute()
        .sql("DROP TABLE foo")
        .execute();
}
 

开发者ID:jcabi,
项目名称:jcabi-mysql-maven-plugin,
代码行数:25,
代码来源:FooITCase.java

示例14: canReceiveConfigurationOptions

点赞 3

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
/**
 * Can use configuration options.
 * @throws Exception If something is wrong
 */
@Test
public void canReceiveConfigurationOptions() throws Exception {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    final Connection conn = DriverManager.getConnection(
        String.format(
            "jdbc:mysql://localhost:%s/root?user=root&password=root",
            WithOptionsITCase.PORT
        )
    );
    new JdbcSession(conn)
        .autocommit(false)
        .sql("CREATE TABLE foo (date DATE)")
        .execute()
        .sql("INSERT INTO foo VALUES ('2004-04-31')")
        .execute()
        .sql("SELECT * FROM foo")
        .execute()
        .sql("DROP TABLE foo")
        .execute();
}
 

开发者ID:jcabi,
项目名称:jcabi-mysql-maven-plugin,
代码行数:25,
代码来源:WithOptionsITCase.java

示例15: iterate

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public List<Product> iterate() {
    try {
        return new JdbcSession(this.dBase)
                .sql("SELECT * FROM product")
                .select(new ListOutcome<>(this::create));
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:11,
代码来源:ConstH2Products.java

示例16: name

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
private String name() {
    try {
        return new JdbcSession(dBase)
                .sql("SELECT name FROM product WHERE id=?")
                .set(this.number)
                .select(new SingleOutcome<>(String.class));
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:11,
代码来源:H2Product.java

示例17: desc

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
private String desc() {
    try {
        return new JdbcSession(dBase)
                .sql("SELECT desc FROM product WHERE id=?")
                .set(this.number)
                .select(new SingleOutcome<>(String.class));
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:11,
代码来源:H2Product.java

示例18: price

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
private MonetaryAmount price() {
    try {
        return FastMoney.of(
                new BigDecimal(
                        new JdbcSession(dBase)
                                .sql("SELECT price FROM product WHERE id=?")
                                .set(this.number)
                                .select(new SingleOutcome<>(String.class))),
                "CZK");
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:14,
代码来源:H2Product.java

示例19: update

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Product update(String name, String desc, MonetaryAmount price) {
    try {
        new JdbcSession(dBase)
                .sql("UPDATE product SET name=?, desc=?, price=? WHERE id=?")
                .set(name)
                .set(desc)
                .set(price.getNumber())
                .set(this.number)
                .update(Outcome.VOID);
        return new H2Product(dBase, this.number);
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:16,
代码来源:H2Product.java

示例20: name

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
private String name() {
    try {
        return new JdbcSession(dBase)
                .sql("SELECT name FROM category WHERE id=?")
                .set(this.number)
                .select(new SingleOutcome<>(String.class));
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:11,
代码来源:H2Category.java

示例21: parent

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
private Optional<Category> parent() {
    try {
        return Optional.ofNullable(new JdbcSession(dBase)
                .sql("SELECT parent_id FROM category WHERE id=?")
                .set(this.number)
                .select(new SingleOutcome<>(Long.class, true)))
                .filter(id -> id > 0) // null value in db
                .map(id -> new H2Category(dBase, id));
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:13,
代码来源:H2Category.java

示例22: update

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Category update(String name, Optional<Category> parent) {
    try {
        new JdbcSession(dBase)
                .sql("UPDATE category SET name=?, parent_id=? WHERE id=?")
                .set(name)
                .set(parent.map(Category::id).orElse(null))
                .set(this.number)
                .update(Outcome.VOID);
        return new H2Category(dBase, this.number);
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:15,
代码来源:H2Category.java

示例23: iterate

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public List<Product> iterate() {
    try {
        return new JdbcSession(this.dBase)
                .sql("SELECT id FROM product")
                .select(new ListOutcome<>(rSet ->
                        new H2Product(dBase, rSet.getLong(1))));
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:12,
代码来源:H2Products.java

示例24: add

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Product add(String name, String desc, MonetaryAmount price) {
    try {
        return new H2Product(dBase,
                new JdbcSession(this.dBase)
                        .sql("INSERT INTO product (name, desc, price) VALUES (?, ?, ?)")
                        .set(name)
                        .set(desc)
                        .set(price.getNumber())
                        .insert(new SingleOutcome<>(Long.class)));
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:15,
代码来源:H2Products.java

示例25: delete

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public void delete(Product product) {
    try {
        new JdbcSession(this.dBase)
                .sql("DELETE FROM product WHERE id=?")
                .set(product.number())
                .execute();
    } catch (SQLException e) {
        ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:12,
代码来源:H2Products.java

示例26: product

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Product product(long number) {
    try {
        new JdbcSession(this.dBase)
                .sql("SELECT id FROM product WHERE id=?")
                .set(number)
                .select(Outcome.NOT_EMPTY);
        // exist
        return new H2Product(dBase, number);
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:14,
代码来源:H2Products.java

示例27: iterate

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public List<Category> iterate() {
    try {
        return new JdbcSession(this.dBase)
                .sql("SELECT id FROM category")
                .select(new ListOutcome<>(rSet ->
                        new H2Category(dBase, rSet.getLong(1))));
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:12,
代码来源:H2Categories.java

示例28: add

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Category add(String name, Optional<Category> parent) {
    try {
        return new H2Category(dBase,
                new JdbcSession(this.dBase)
                        .sql("INSERT INTO category (name, parent_id) VALUES (?, ?)")
                        .set(name)
                        .set(parent.map(Category::id).orElse(null))
                        .insert(new SingleOutcome<>(Long.class)));
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:14,
代码来源:H2Categories.java

示例29: delete

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public void delete(Category category) {
    try {
        new JdbcSession(this.dBase)
                .sql("DELETE FROM category WHERE id=?")
                .set(category.id())
                .execute();
    } catch (SQLException e) {
        ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:12,
代码来源:H2Categories.java

示例30: category

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Category category(long number) {
    try {
        new JdbcSession(this.dBase)
                .sql("SELECT id FROM category WHERE id=?")
                .set(number)
                .select(Outcome.NOT_EMPTY);
        // exist
        return new H2Category(dBase, number);
    } catch (SQLException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:14,
代码来源:H2Categories.java

示例31: iterate

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public List<Product> iterate() {
    try {
        return new JdbcSession(this.dBase)
                .sql("SELECT product_id FROM category_product WHERE category_id = ?")
                .set(category.id())
                .select(new ListOutcome<>(rSet ->
                        new H2Product(dBase, rSet.getLong(1))));
    } catch (Exception e) {
        return ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:13,
代码来源:H2CategoryProducts.java

示例32: remove

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public void remove(Product product) {
    try {
        new JdbcSession(this.dBase)
                .sql("DELETE FROM category_product WHERE category_id=? AND product_id=?")
                .set(category.id())
                .set(product.number())
                .execute();
    } catch (Exception e) {
        ExceptionUtils.rethrow(e);
    }
}
 

开发者ID:yaroska,
项目名称:true_oop,
代码行数:13,
代码来源:H2CategoryProducts.java

示例33: iterate

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Iterable<Message> iterate() throws IOException {
    try {
        final Collection<Message> msgs = new JdbcSession(this.src.get())
            .set(this.number)
            .sql(
                Joiner.on(' ').join(
                    "SELECT asking, text, date FROM message",
                    "WHERE talk=? ORDER BY date DESC"
                )
            )
            .select(
                new ListOutcome<Message>(
                    new ListOutcome.Mapping<Message>() {
                        @Override
                        public Message map(final ResultSet rset)
                            throws SQLException {
                            return PgMessages.message(rset);
                        }
                    }
                )
            );
        if (!msgs.isEmpty()) {
            new JdbcSession(this.src.get())
                // @checkstyle LineLength (1 line)
                .sql("UPDATE message SET seen=now() WHERE talk=? AND seen IS NULL")
                .set(this.number)
                .update(Outcome.VOID);
            Logger.info(this, "%d seen in #%d", msgs.size(), this.number);
        }
        return msgs;
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:36,
代码来源:PgMessages.java

示例34: size

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public int size() throws IOException {
    try {
        return new JdbcSession(this.src.get())
            .sql("SELECT COUNT(id) FROM message WHERE talk=?")
            .set(this.number)
            .select(new SingleOutcome<Long>(Long.class))
            .intValue();
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:13,
代码来源:PgMessages.java

示例35: asker

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Human asker() throws IOException {
    try {
        return new PgHuman(
            this.src,
            new JdbcSession(this.src.get())
                // @checkstyle LineLength (1 line)
                .sql("SELECT asker FROM question JOIN talk ON question.id=talk.question AND talk.id=?")
                .set(this.num)
                .select(new SingleOutcome<Long>(Long.class))
        );
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:16,
代码来源:PgTalk.java

示例36: responder

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public Human responder() throws IOException {
    try {
        return new PgHuman(
            this.src,
            new JdbcSession(this.src.get())
                .sql("SELECT responder FROM talk WHERE id=?")
                .set(this.num)
                .select(new SingleOutcome<Long>(Long.class))
        );
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:15,
代码来源:PgTalk.java

示例37: question

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
@Override
public String question() throws IOException {
    try {
        return new JdbcSession(this.src.get())
            // @checkstyle LineLength (1 line)
            .sql("SELECT text FROM question JOIN talk ON talk.question=question.id WHERE talk.id=?")
            .set(this.num)
            .select(new SingleOutcome<String>(String.class));
    } catch (final SQLException ex) {
        throw new IOException(ex);
    }
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:13,
代码来源:PgTalk.java

示例38: unread

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
/**
 * Get unread talk.
 * @return Unread talk
 * @throws SQLException If fails
 */
private Collection<Talk> unread() throws SQLException {
    return new JdbcSession(this.src.get())
        .set(this.number)
        .set(this.number)
        .set(this.number)
        .sql(
            Joiner.on(' ').join(
                "SELECT talk FROM message",
                "JOIN talk ON talk.id=message.talk",
                "JOIN question q ON q.id=talk.question",
                "AND q.locale=(SELECT locale FROM human WHERE id=?)",
                "WHERE message.seen IS NULL",
                "AND ((asking=true AND responder=?)",
                "OR (asking=false AND asker=?))",
                "ORDER BY message.date DESC LIMIT 1"
            )
        )
        .select(
            new ListOutcome<Talk>(
                new ListOutcome.Mapping<Talk>() {
                    @Override
                    public Talk map(final ResultSet rset)
                        throws SQLException {
                        return new PgTalk(
                            PgHuman.this.src, rset.getLong(1)
                        );
                    }
                }
            )
        );
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:37,
代码来源:PgHuman.java

示例39: start

点赞 2

import com.jcabi.jdbc.JdbcSession; //导入依赖的package包/类
/**
 * Start new talk for the current human.
 * @return Talk
 * @throws SQLException If fails
 */
private Collection<Talk> start() throws SQLException {
    final Long question = new JdbcSession(this.src.get())
        .set(this.number)
        .set(this.number)
        .set(this.number)
        .sql(
            Joiner.on(' ').join(
                "SELECT question.id FROM question",
                "LEFT JOIN talk",
                "ON talk.question=question.id AND responder=?",
                "WHERE talk.id IS NULL AND asker != ?",
                "AND question.locale=(SELECT locale FROM human WHERE id=?)",
                "LIMIT 1"
            )
        )
        .select(new SingleOutcome<Long>(Long.class, true));
    final Collection<Talk> talks = new ArrayList<Talk>(1);
    if (question != null) {
        final Talk talk = new PgTalk(
            this.src,
            new JdbcSession(this.src.get())
                .sql("INSERT INTO talk (question, responder) VALUES (?, ?)")
                .set(question)
                .set(this.number)
                .insert(new SingleOutcome<Long>(Long.class))
        );
        talks.add(talk);
        Logger.info(
            this, "talk #%d started by #%d from question #%d",
            talk.number(), this.number, question
        );
    }
    return talks;
}
 

开发者ID:aintshy,
项目名称:hub,
代码行数:40,
代码来源:PgHuman.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)