本文整理汇总了Java中org.tmatesoft.sqljet.core.table.SqlJetDb.runReadTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java SqlJetDb.runReadTransaction方法的具体用法?Java SqlJetDb.runReadTransaction怎么用?Java SqlJetDb.runReadTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.tmatesoft.sqljet.core.table.SqlJetDb
的用法示例。
在下文中一共展示了SqlJetDb.runReadTransaction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: size
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入方法依赖的package包/类
public long size() {
try {
ISqlJetTransaction getCountTx=new ISqlJetTransaction() {
@Override
public Object run(SqlJetDb db) throws SqlJetException {
ISqlJetCursor allRowsCursor = nodeInfoTable.scope(null, null, null);
long count=allRowsCursor.getRowCount();
allRowsCursor.close();
return count;
}
};
return (long) db.runReadTransaction(getCountTx);
} catch (SqlJetException e) {
LOGGER.error("Db error", e);
throw new RuntimeException(e);
}
}
示例2: getEndpointByNodeIdentifier
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入方法依赖的package包/类
public InetSocketAddress getEndpointByNodeIdentifier(final NodeIdentifier remoteID) {
try {
ISqlJetTransaction getEndpointTx=new ISqlJetTransaction() {
@Override public Object run(SqlJetDb db) throws SqlJetException {
ISqlJetCursor nodeInfoCursor = nodeInfoTable.lookup(null, remoteID.getBytes());
InetSocketAddress endpoint=null;
if(nodeInfoCursor.eof()==false){
endpoint=new InetSocketAddress(nodeInfoCursor.getString(ENDPOINT_ADDRESS_FN),
(int) nodeInfoCursor.getInteger(ENDPOINT_PORT_FN));
}
nodeInfoCursor.close();
return endpoint;
}
};
return (InetSocketAddress) db.runReadTransaction(getEndpointTx);
} catch (SqlJetException e) {
LOGGER.error("db error", e);
throw new RuntimeException(e);
}
}
示例3: getAllNodeInformation
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<NodeMetaData> getAllNodeInformation(final int maxNumberOfNodes){
ISqlJetTransaction getAllNodesTx=new ISqlJetTransaction() {
@Override public Object run(SqlJetDb db) throws SqlJetException {
ArrayList<NodeMetaData> listOfNodeInfo=new ArrayList<>();
ISqlJetCursor allNodesCursor = nodeInfoTable.scope(nodeInfoTable.getPrimaryKeyIndexName(), null, null);
for(int i=0; i<maxNumberOfNodes && allNodesCursor.eof()==false; i++){
InetSocketAddress endPoint=new InetSocketAddress(allNodesCursor.getString(ENDPOINT_ADDRESS_FN),
(int) allNodesCursor.getInteger(ENDPOINT_PORT_FN));
NodeIdentifier nodeId=new NodeIdentifier(allNodesCursor.getBlobAsArray(NODE_ID_FN));
NodeMetaData currentBNI=new NodeMetaData(nodeId, endPoint);
listOfNodeInfo.add(currentBNI);
allNodesCursor.next();
}
allNodesCursor.close();
return listOfNodeInfo;
}
};
try {
return (List<NodeMetaData>) db.runReadTransaction(getAllNodesTx);
} catch (SqlJetException e) {
LOGGER.error("DB error", e);
throw new RuntimeException(e);
}
}
示例4: getStoredBlob
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入方法依赖的package包/类
@Override
public P2PBlobStoredBlob getStoredBlob(final HashIdentifier blobId) throws Exception{
synchronized(cachedTransitStatus){
P2PBlobStoredBlobRepositoryFS transitStatus = cachedTransitStatus.get(blobId);
if(transitStatus!=null){
return transitStatus;
}
ISqlJetTransaction getStoredBlockTx=new ISqlJetTransaction() {
@Override public Object run(SqlJetDb db) throws SqlJetException {
ISqlJetCursor blobMetaCursor = blobMetaTable.lookup(BLOB_META_BLOBHASH_IDX, blobId.getBytes());
if(blobMetaCursor.eof()){
return null;
}
long blobByteSize=blobMetaCursor.getInteger("blobByteSize");
int blockByteSize=(int) blobMetaCursor.getInteger("blockByteSize");
String localBlockRangeStr=blobMetaCursor.getString("rangeLocalBlock");
P2PBlobRangeSet localBlockRange=null;
if(localBlockRangeStr!=null){
localBlockRange=new P2PBlobRangeSet(localBlockRangeStr);
}
P2PBlobHashList hashList=new P2PBlobHashList(blobMetaCursor.getBlobAsArray("blocksHash"));
File blobFile = getBlobFile(blobId);
P2PBlobStoredBlobRepositoryFS status=new P2PBlobStoredBlobRepositoryFS(blobFile,blobId, hashList, localBlockRange, blobByteSize, blockByteSize);
cachedTransitStatus.put(blobId, status);
return status;
}
};
try {
return (P2PBlobStoredBlob) db.runReadTransaction(getStoredBlockTx);
} catch (SqlJetException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
示例5: getBalanceForNode
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入方法依赖的package包/类
public long getBalanceForNode(final NodeIdentifier nodeId) throws SqlJetException {
ISqlJetTransaction getBalanceTx=new ISqlJetTransaction() {
@Override public Object run(SqlJetDb db) throws SqlJetException {
ISqlJetCursor nodeAccountCursor = balanceTable.lookup(null, nodeId.getBytes());
long balance=0;
if(nodeAccountCursor.eof()==false){
balance=nodeAccountCursor.getInteger(BALANCE_FN);
}
nodeAccountCursor.close();
return balance;
}
};
return (long) db.runReadTransaction(getBalanceTx);
}