本文整理汇总了Java中org.tmatesoft.sqljet.core.table.SqlJetDb类的典型用法代码示例。如果您正苦于以下问题:Java SqlJetDb类的具体用法?Java SqlJetDb怎么用?Java SqlJetDb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlJetDb类属于org.tmatesoft.sqljet.core.table包,在下文中一共展示了SqlJetDb类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
}
开发者ID:mbrigl,项目名称:mdb2sqlite,代码行数:25,代码来源:MDB2SQLite.java
示例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();
}
}
}
开发者ID:mbrigl,项目名称:mdb2sqlite,代码行数:22,代码来源:MDB2SQLite.java
示例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);
}
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:18,代码来源:NodeStatisticsDatabase.java
示例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);
}
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:21,代码来源:NodeStatisticsDatabase.java
示例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);
}
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:22,代码来源:P2PBlobRepositoryFS.java
示例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();
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:24,代码来源:P2PBlobRepositoryFS.java
示例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();
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:SvnUtil.java
示例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);
}
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:11,代码来源:HashToPublicKeyDB.java
示例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);
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:16,代码来源:SelfRegistrationDHT.java
示例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);
}
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:28,代码来源:NodeStatisticsDatabase.java
示例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);
}
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:28,代码来源:NodeStatisticsDatabase.java
示例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;
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:31,代码来源:P2PBlobRepositoryFS.java
示例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);
}
}
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:38,代码来源:P2PBlobRepositoryFS.java
示例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);
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:15,代码来源:AbstractNodeBalanceTable.java
示例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);
}
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:34,代码来源:AbstractNodeBalanceTable.java
示例16: getDatabaseConnection
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
/**
* Get a connection to the database for the current thread. Also closes all invalid connections for the current
* thread.
* @return
* The connection or null if the connection couldn't be established.
*
* @see #connections
*/
private SqlJetDb getDatabaseConnection() {
Thread t = Thread.currentThread();
File folder = folderHolder.getKachleCacheFolder().getEffectiveFile();
File f = new File(folder, FILE_NAME);
AbstractMap.SimpleImmutableEntry<Thread, File> mapKey = new AbstractMap.SimpleImmutableEntry<>(t, f);
if (connections.containsKey(mapKey)) {
// Got a valid connection
return connections.get(mapKey);
} else {
try {
// create a new connection
SqlJetDb database = SqlJetDb.open(f, true);
// Initialize the DB if needed
if (!isDbInitialized(database)) {
initDb(database);
}
// Close all deprecated connections (should be exactly one or zero)
// Done here for synchronization reasons. This way, we never close an active connection that's
// needed elsewhere at the same moment and there's always at most one connection per thread.
for (Map.Entry<Map.Entry<Thread, File>, SqlJetDb> conn : connections.entrySet()) {
if (conn.getKey().getKey().equals(t)) {
conn.getValue().close();
connections.remove(conn.getKey());
}
}
// Now, store the new connection and return it
connections.put(mapKey, database);
return database;
} catch (SqlJetException e) {
log.error("Unable to establish the DB connection!", e);
return null;
}
}
}
开发者ID:Danstahr,项目名称:Geokuk,代码行数:47,代码来源:KachleDBManager.java
示例17: isDbInitialized
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
/**
* Checks whether the DB at the current location is initialized and ready for use.
* @param connection
* A connection to the database.
* @return
* True if its initialized, false otherwise
*/
private boolean isDbInitialized(SqlJetDb connection) {
try {
return connection.getSchema().getTableNames().contains(TABLE_NAME);
} catch (SqlJetException e) {
log.error("A database error has occurred!", e);
return false;
}
}
开发者ID:Danstahr,项目名称:Geokuk,代码行数:16,代码来源:KachleDBManager.java
示例18: populateTable
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
/**
* Populate the SQLite table
*
* @param sqlite
* @param mdbTable
* @throws SQLException
* @throws SqlJetException
*/
@SuppressWarnings("unchecked")
private static void populateTable(SqlJetDb sqlite, Table mdbTable) throws SQLException, SqlJetException {
List<Column> columns = (List<Column>) mdbTable.getColumns();
sqlite.beginTransaction(SqlJetTransactionMode.WRITE);
try {
ISqlJetTable table = sqlite.getTable(mdbTable.getName());
// Bind all the column values
for (Map<String, Object> row : mdbTable) {
List<Object> values = new ArrayList<Object>();
for (Column column : columns) {
Object value = row.get(column.getName());
// If null, just bail out early and avoid a lot of NULL checking
if (value == null) {
values.add(value);
continue;
}
// Perform any conversions
switch (column.getType()) {
case MONEY: // Store money as a string.
values.add(value.toString());
break;
case BOOLEAN: // SQLite has no booleans
values.add(((Boolean) value).booleanValue() ? "1" : 0);
break;
default:
values.add(value);
break;
}
}
table.insert(values.toArray());
}
} finally {
sqlite.commit();
}
}
开发者ID:mbrigl,项目名称:mdb2sqlite,代码行数:49,代码来源:MDB2SQLite.java
示例19: maybeDebit
import org.tmatesoft.sqljet.core.table.SqlJetDb; //导入依赖的package包/类
public boolean maybeDebit(final NodeIdentifier nodeId, final long amountToBeDebited) {
if(amountToBeDebited<0){
throw new RuntimeException("Invalid debit amount "+amountToBeDebited);
}
ISqlJetTransaction maybeDebitNodeTx=new ISqlJetTransaction() {
@Override public Object run(SqlJetDb db) throws SqlJetException {
boolean isDebitAllowed=false;
ISqlJetCursor nodeBalanceCursor = balanceTable.lookup(null, nodeId.getBytes());
if(nodeBalanceCursor.eof()){
if(negativeBalanceAllowed<amountToBeDebited){
LOGGER.info("Refused to debit {} because the autoloan amount is only {}", amountToBeDebited, negativeBalanceAllowed);
isDebitAllowed=false;
}
else{
LOGGER.info("First-time debit of {} allowed for node '{}' ", amountToBeDebited, nodeId);
balanceTable.insert(nodeId.getBytes(), -amountToBeDebited);
isDebitAllowed=true;
}
}
else{
long oldBalance=nodeBalanceCursor.getInteger(BALANCE_FN);
long newBalance=oldBalance-amountToBeDebited;
if(newBalance<0 && -newBalance>negativeBalanceAllowed){
LOGGER.info("Debit denied to node '{}' because the resulting balance would have been {}", nodeId, newBalance);
isDebitAllowed=false;
}
else{
LOGGER.info("Debit allowed to node '{}' new balance {}", nodeId, newBalance);
LOGGER.debug("Old balance: {} - debit {}", oldBalance, amountToBeDebited);
Map<String, Object> fieldsToUpdate=new HashMap<>();
fieldsToUpdate.put(BALANCE_FN, newBalance);
nodeBalanceCursor.updateByFieldNames(fieldsToUpdate);
isDebitAllowed=true;
}
}
nodeBalanceCursor.close();
return isDebitAllowed;
}
};
try {
return (boolean) db.runWriteTransaction(maybeDebitNodeTx);
} catch (SqlJetException e) {
LOGGER.error("db error", e);
throw new RuntimeException(e);
}
}
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:50,代码来源:AbstractNodeBalanceTable.java
注:本文中的org.tmatesoft.sqljet.core.table.SqlJetDb类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论