本文整理汇总了Java中nxt.util.DbUtils类的典型用法代码示例。如果您正苦于以下问题:Java DbUtils类的具体用法?Java DbUtils怎么用?Java DbUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DbUtils类属于nxt.util包,在下文中一共展示了DbUtils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransactionIterator
import nxt.util.DbUtils; //导入依赖的package包/类
public static DbIterator<? extends Transaction> getTransactionIterator(
Long accountId, TransactionType[] recipientTypes,
TransactionType[] senderTypes, int timestamp, Boolean orderAscending,
Object referencedTransaction) {
Connection con = null;
try {
con = Db.getConnection();
PreparedStatement pstmt = createTransactionStatement(con, accountId,
recipientTypes, senderTypes, timestamp, orderAscending,
referencedTransaction, false);
DbIterator<? extends Transaction> iterator = Nxt.getBlockchain()
.getTransactions(con, pstmt);
return iterator;
}
catch (SQLException e) {
logger.error("SQL Error", e);
if (con != null) {
DbUtils.close(con);
}
}
return null;
}
示例2: getGeneratedBlocks
import nxt.util.DbUtils; //导入依赖的package包/类
public static List<Block> getGeneratedBlocks(Long accountId) {
Connection con = null;
try {
con = Db.getConnection();
PreparedStatement pstmt = con
.prepareStatement("SELECT * FROM block WHERE generator_id = ? ORDER BY db_id ASC");
pstmt.setLong(1, accountId);
List<Block> result = new ArrayList<Block>();
DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(con,
pstmt);
while (iterator.hasNext()) {
result.add(iterator.next());
}
return result;
}
catch (SQLException e) {
DbUtils.close(con);
throw new RuntimeException(e.toString(), e);
}
}
示例3: getAllBlocks
import nxt.util.DbUtils; //导入依赖的package包/类
public DbIterator<BlockImpl> getAllBlocks()
{
Connection localConnection = null;
try
{
localConnection = Db.getConnection();
PreparedStatement localPreparedStatement = localConnection.prepareStatement("SELECT * FROM block ORDER BY db_id ASC");
new DbIterator(localConnection, localPreparedStatement, new DbIterator.ResultSetReader()
{
public BlockImpl get(Connection paramAnonymousConnection, ResultSet paramAnonymousResultSet)
throws NxtException.ValidationException
{
return BlockDb.findBlock(paramAnonymousConnection, paramAnonymousResultSet);
}
});
}
catch (SQLException localSQLException)
{
DbUtils.close(new AutoCloseable[] { localConnection });
throw new RuntimeException(localSQLException.toString(), localSQLException);
}
}
示例4: getAllTransactions
import nxt.util.DbUtils; //导入依赖的package包/类
public DbIterator<TransactionImpl> getAllTransactions()
{
Connection localConnection = null;
try
{
localConnection = Db.getConnection();
PreparedStatement localPreparedStatement = localConnection.prepareStatement("SELECT * FROM transaction ORDER BY db_id ASC");
new DbIterator(localConnection, localPreparedStatement, new DbIterator.ResultSetReader()
{
public TransactionImpl get(Connection paramAnonymousConnection, ResultSet paramAnonymousResultSet)
throws NxtException.ValidationException
{
return TransactionDb.findTransaction(paramAnonymousConnection, paramAnonymousResultSet);
}
});
}
catch (SQLException localSQLException)
{
DbUtils.close(new AutoCloseable[] { localConnection });
throw new RuntimeException(localSQLException.toString(), localSQLException);
}
}
示例5: getTransactions
import nxt.util.DbUtils; //导入依赖的package包/类
public static LazyList getTransactions(Boolean orderAscending, INxtService nxt) {
Connection con = null;
/* Count number of records */
int available = Nxt.getBlockchain().getTransactionCount();
/* Create the record iterator */
try {
con = Db.getConnection();
StringBuilder buf = new StringBuilder();
buf.append("SELECT * FROM transaction ");
if (orderAscending != null) {
if (Boolean.TRUE.equals(orderAscending)) {
buf.append("ORDER BY db_id ASC");
}
else if (Boolean.FALSE.equals(orderAscending)) {
buf.append("ORDER BY db_id DESC");
}
}
PreparedStatement pstmt = con.prepareStatement(buf.toString());
DbIterator<? extends Transaction> iterator = Nxt.getBlockchain()
.getTransactions(con, pstmt);
LazyList lazyList = new LazyList(iterator, available, nxt);
return lazyList;
}
catch (SQLException e) {
logger.error("SQL Error", e);
if (con != null) {
DbUtils.close(con);
}
}
return null;
}
示例6: getBlocks
import nxt.util.DbUtils; //导入依赖的package包/类
public static LazyList getBlocks(Boolean orderAscending, INxtService nxt) {
Connection con = null;
/* Count number of records */
// int available = nxt.getSmartBlockCount();
int available = Nxt.getBlockchain().getBlockCount();
/* Create the record iterator */
try {
con = Db.getConnection();
StringBuilder buf = new StringBuilder();
buf.append("SELECT * FROM block ");
if (orderAscending != null) {
if (Boolean.TRUE.equals(orderAscending)) {
buf.append("ORDER BY db_id ASC");
}
else if (Boolean.FALSE.equals(orderAscending)) {
buf.append("ORDER BY db_id DESC");
}
}
PreparedStatement pstmt = con.prepareStatement(buf.toString());
DbIterator<? extends Block> iterator = Nxt.getBlockchain().getBlocks(con,
pstmt);
LazyList lazyList = new LazyList(iterator, available);
return lazyList;
}
catch (SQLException e) {
logger.error("SQL Error", e);
if (con != null) {
DbUtils.close(con);
}
}
return null;
}
示例7: getAllBlocks
import nxt.util.DbUtils; //导入依赖的package包/类
@Override
public DbIterator<BlockImpl> getAllBlocks() {
Connection con = null;
try {
con = Db.getConnection();
PreparedStatement pstmt = con.prepareStatement("SELECT * FROM block ORDER BY db_id ASC");
return getBlocks(con, pstmt);
} catch (SQLException e) {
DbUtils.close(con);
throw new RuntimeException(e.toString(), e);
}
}
示例8: getBlocks
import nxt.util.DbUtils; //导入依赖的package包/类
@Override
public DbIterator<BlockImpl> getBlocks(Account account, int timestamp) {
Connection con = null;
try {
con = Db.getConnection();
PreparedStatement pstmt = con.prepareStatement("SELECT * FROM block WHERE timestamp >= ? AND generator_id = ? ORDER BY db_id ASC");
pstmt.setInt(1, timestamp);
pstmt.setLong(2, account.getId());
return getBlocks(con, pstmt);
} catch (SQLException e) {
DbUtils.close(con);
throw new RuntimeException(e.toString(), e);
}
}
示例9: getAllTransactions
import nxt.util.DbUtils; //导入依赖的package包/类
@Override
public DbIterator<TransactionImpl> getAllTransactions() {
Connection con = null;
try {
con = Db.getConnection();
PreparedStatement pstmt = con.prepareStatement("SELECT * FROM transaction ORDER BY db_id ASC");
return getTransactions(con, pstmt);
} catch (SQLException e) {
DbUtils.close(con);
throw new RuntimeException(e.toString(), e);
}
}
示例10: getTransactions
import nxt.util.DbUtils; //导入依赖的package包/类
@Override
public DbIterator<TransactionImpl> getTransactions(Account account, byte type, byte subtype, int timestamp, Boolean orderAscending) {
Connection con = null;
try {
StringBuilder buf = new StringBuilder();
if (orderAscending != null) {
buf.append("SELECT * FROM (");
}
buf.append("SELECT * FROM transaction WHERE recipient_id = ? ");
if (timestamp > 0) {
buf.append("AND timestamp >= ? ");
}
if (type >= 0) {
buf.append("AND type = ? ");
if (subtype >= 0) {
buf.append("AND subtype = ? ");
}
}
buf.append("UNION SELECT * FROM transaction WHERE sender_id = ? ");
if (timestamp > 0) {
buf.append("AND timestamp >= ? ");
}
if (type >= 0) {
buf.append("AND type = ? ");
if (subtype >= 0) {
buf.append("AND subtype = ? ");
}
}
if (Boolean.TRUE.equals(orderAscending)) {
buf.append(") ORDER BY timestamp ASC");
} else if (Boolean.FALSE.equals(orderAscending)) {
buf.append(") ORDER BY timestamp DESC");
}
con = Db.getConnection();
PreparedStatement pstmt;
int i = 0;
pstmt = con.prepareStatement(buf.toString());
pstmt.setLong(++i, account.getId());
if (timestamp > 0) {
pstmt.setInt(++i, timestamp);
}
if (type >= 0) {
pstmt.setByte(++i, type);
if (subtype >= 0) {
pstmt.setByte(++i, subtype);
}
}
pstmt.setLong(++i, account.getId());
if (timestamp > 0) {
pstmt.setInt(++i, timestamp);
}
if (type >= 0) {
pstmt.setByte(++i, type);
if (subtype >= 0) {
pstmt.setByte(++i, subtype);
}
}
return getTransactions(con, pstmt);
} catch (SQLException e) {
DbUtils.close(con);
throw new RuntimeException(e.toString(), e);
}
}