本文整理汇总了Java中org.tmatesoft.sqljet.core.table.SqlJetDb类的典型用法代码示例。如果您正苦于以下问题:Java SqlJetDb类的具体用法?Java SqlJetDb怎么用?Java SqlJetDb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlJetDb类属于org.tmatesoft.sqljet.core.table包,在下文中一共展示了SqlJetDb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: export
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
/**
* Export the Access database to the given SQLite database. The referenced
* SQLite database should be empty.
*
* @param mdbFile The MS Access file.
* @param sqliteFile The SQLite file.
* @throws SQLException
* @throws SqlJetException
*/
public static void export(File mdbFile, File sqliteFile) throws Exception {
Database mdb = DatabaseBuilder.open(mdbFile);
SqlJetDb sqlite = SqlJetDb.open(sqliteFile, true);
sqlite.getOptions().setAutovacuum(true);
sqlite.beginTransaction(SqlJetTransactionMode.WRITE);
// Create the tables
MDB2SQLite.createTables(mdb, sqlite);
// Populate the tables
for (String tableName : mdb.getTableNames()) {
MDB2SQLite.populateTable(sqlite, mdb.getTable(tableName));
}
}
示例2: createTables
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
/**
* Iterate over the MDB database and create SQLite tables for every table
* defined in the MS Access database.
*
* @param jdbc The SQLite database JDBC connection
*/
@SuppressWarnings("unchecked")
private static void createTables(Database mdb, SqlJetDb sqlite) throws Exception {
for (String tableName : mdb.getTableNames()) {
Table table = mdb.getTable(tableName);
sqlite.beginTransaction(SqlJetTransactionMode.WRITE);
try {
sqlite.createTable(MDB2SQLite.createTableStatement(table));
for (Index index : (List<Index>) table.getIndexes()) {
sqlite.createIndex(MDB2SQLite.createIndexStatement(index));
}
} finally {
sqlite.commit();
}
}
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: P2PBlobRepositoryFS
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
public P2PBlobRepositoryFS(File repositoryDirectory) throws Exception {
this.repositoryDirectory=repositoryDirectory;
if(repositoryDirectory.exists()==false){
repositoryDirectory.mkdirs();
}
try {
File dbFile=new File(repositoryDirectory, REPOSITORY_DB_FILENAME);
boolean schemaNeedsToBeCreated=dbFile.exists()==false;
db = new SqlJetDb(dbFile, true);
db.open();
maybeCreateSchema(schemaNeedsToBeCreated);
} catch (SqlJetException e) {
throw new RuntimeException(e);
}
for(File nonRepositoryFile:repositoryDirectory.listFiles(nonRepositoryFilenameFilter)){
importFileIntoRepository(nonRepositoryFile);
}
}
示例6: insertStoredBlobMetaData
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
protected void insertStoredBlobMetaData(final P2PBlobStoredBlob theBlob) throws SqlJetException {
final P2PBlobBlockLayout blockLayout = theBlob.getBlockLayout();
final ByteBuf concatenatedHashes=Unpooled.buffer(blockLayout.getNumberOfBlocks()*P2PBlobHashList.HASH_BYTE_SIZE);
for(HashIdentifier hashBlock:theBlob.getHashList()){
concatenatedHashes.writeBytes(hashBlock.getBytes());
}
ISqlJetTransaction insertTx=new ISqlJetTransaction() {
@Override public Object run(SqlJetDb db) throws SqlJetException {
long newRow = blobMetaTable.insert(
theBlob.getHashList().getTopLevelHash().getBytes(),
concatenatedHashes.array(),
blockLayout.getNumberOfBlocks(),
null,
blockLayout.getLengthOfBlob(),
blockLayout.getLengthOfEvenBlock());
LOGGER.debug("Added topHash/hashList={}", newRow);
return null;
}
};
db.runWriteTransaction(insertTx);
concatenatedHashes.release();
}
示例7: close
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
private static void close(@Nullable SqlJetDb db) {
if (db != null) {
try {
db.close();
}
catch (SqlJetException e) {
notifyDatabaseError();
}
}
}
示例8: HashToPublicKeyDB
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
public HashToPublicKeyDB() {
super(UnsignedLong.ONE); // FIXME Get the db version number from SQL
try {
db = new SqlJetDb(SqlJetDb.IN_MEMORY, true);
db.open();
maybeCreateSchema();
} catch (SqlJetException e) {
throw new RuntimeException(e);
}
}
示例9: SelfRegistrationDHT
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
public SelfRegistrationDHT(ServerMain serverMain) throws Exception {
super(serverMain);
setEntryTimeToLive(1, TimeUnit.DAYS);
setEntryMaximumCardinality(1000);
setEntryOverflowHandling(OverflowHandling.LIFO); //LIFO or FIFO
File serverFile=serverMain.getConfig().getFileRelativeFromConfigDirectory(DHT_FILENAME);
boolean dbExists=serverFile.exists();
db = new SqlJetDb(serverFile, true);
db.open();
if(dbExists==false){
createSchema();
}
dhtValueTable=db.getTable(DHT_VALUE_TABLE_NAME);
}
示例10: mapNodeIdToAddress
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
public void mapNodeIdToAddress(final NodeIdentifier nodeIdentifier, final InetSocketAddress nodeSocketAddress) {
// NodeMetaData info = new NodeMetaData(NodeIdentifier, nodeSocketAddress);
LOGGER.debug("Mapped {} to {}", nodeIdentifier, nodeSocketAddress);
// idToPeer.put(NodeIdentifier, info);
ISqlJetTransaction updateEndpointTx=new ISqlJetTransaction() {
@Override public Object run(SqlJetDb db) throws SqlJetException {
ISqlJetCursor nodeInfoCursor = nodeInfoTable.lookup(null, nodeIdentifier.getBytes());
if(nodeInfoCursor.eof()){
nodeInfoTable.insert(nodeIdentifier.getBytes(), nodeSocketAddress.getHostString(), nodeSocketAddress.getPort());
}
else{
Map<String, Object> fieldsToUpdate=new HashMap<>();
fieldsToUpdate.put(ENDPOINT_ADDRESS_FN, nodeSocketAddress.getHostString());
fieldsToUpdate.put(ENDPOINT_PORT_FN, nodeSocketAddress.getPort());
nodeInfoCursor.updateByFieldNames(fieldsToUpdate);
}
nodeInfoCursor.close();
return null;
}
};
try {
db.runWriteTransaction(updateEndpointTx);
} catch (SqlJetException e) {
LOGGER.error("Db error", e);
throw new RuntimeException(e);
}
}
示例11: 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);
}
}
示例12: importFileIntoRepository
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
public HashIdentifier importFileIntoRepository(final File nonRepositoryFile) throws Exception {
final P2PBlobHashList fileHashList=P2PBlobHashList.createFromFile(nonRepositoryFile);
final HashIdentifier topHash=fileHashList.getTopLevelHash();
final ByteBuf concatenatedHashes=Unpooled.buffer(fileHashList.size()*P2PBlobHashList.HASH_BYTE_SIZE);
for(HashIdentifier hashBlock:fileHashList){
concatenatedHashes.writeBytes(hashBlock.getBytes());
}
ISqlJetTransaction insertTx=new ISqlJetTransaction() {
@Override public Object run(SqlJetDb db) throws SqlJetException {
long newRow = blobMetaTable.insert(
topHash.getBytes(),
concatenatedHashes.array(),
fileHashList.size(),
null,
nonRepositoryFile.length(),
P2PBlobApplication.DEFAULT_BLOCK_SIZE);
LOGGER.debug("Added topHash/hashList={}", newRow);
return null;
}
};
db.runWriteTransaction(insertTx);
concatenatedHashes.release();
File hashedFileName=new File(nonRepositoryFile.getParentFile(), topHash.toString()+".blob");
if(nonRepositoryFile.renameTo(hashedFileName)==false){
throw new Exception("failed to rename "+nonRepositoryFile+" to "+hashedFileName);
}
return topHash;
}
示例13: 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);
}
}
}
示例14: 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);
}
示例15: creditNode
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
public long creditNode(final NodeIdentifier nodeId, final long creditAmount) {
if(creditAmount<0){
throw new RuntimeException("Invalid credit amount "+creditAmount);
}
ISqlJetTransaction creditNodeTx=new ISqlJetTransaction() {
@Override public Object run(SqlJetDb db) throws SqlJetException {
ISqlJetCursor nodeBalanceCursor = balanceTable.lookup(null, nodeId.getBytes());
long newBalance;
if(nodeBalanceCursor.eof()){
LOGGER.info("First time credit of {} for node '{}'", creditAmount, nodeId);
balanceTable.insert(nodeId.getBytes(), creditAmount);
newBalance=creditAmount;
}
else{
Map<String, Object> fieldsToUpdate=new HashMap<>();
long oldBalance=nodeBalanceCursor.getInteger(BALANCE_FN);
newBalance=oldBalance+creditAmount;
LOGGER.info("Node '{}' has new balance of {}", nodeId, newBalance);
fieldsToUpdate.put(BALANCE_FN, newBalance);
nodeBalanceCursor.updateByFieldNames(fieldsToUpdate);
}
nodeBalanceCursor.close();
return newBalance;
}
};
try {
return (long) db.runWriteTransaction(creditNodeTx);
} catch (SqlJetException e) {
LOGGER.error("db error", e);
throw new RuntimeException(e);
}
}