當前位置: 首頁>>代碼示例>>Java>>正文


Java DB類代碼示例

本文整理匯總了Java中org.iq80.leveldb.DB的典型用法代碼示例。如果您正苦於以下問題:Java DB類的具體用法?Java DB怎麽用?Java DB使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DB類屬於org.iq80.leveldb包,在下文中一共展示了DB類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createCachePool

import org.iq80.leveldb.DB; //導入依賴的package包/類
@Override
public CachePool createCachePool(String poolName, int cacheSize,
		int expireSeconds) {
 	  Options options = new Options();
 	  options.cacheSize(cacheSize * 1048576);//cacheSize M 大小
 	  options.createIfMissing(true);
 	  DB db =null;
 	  try {
 		 db=factory.open(new File("leveldb\\"+poolName), options);
 	    // Use the db in here....
 	  } catch (Exception e) {
 	    // Make sure you close the db to shutdown the 
 	    // database and avoid resource leaks.
 	   // db.close();
 	  }
  return new LevelDBPool(poolName,db,cacheSize);
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:18,代碼來源:LevelDBCachePooFactory.java

示例2: getDB

import org.iq80.leveldb.DB; //導入依賴的package包/類
static DB getDB(String path) throws IOException{
	if(databaseCache.containsKey(path)){
		return databaseCache.get(path);
	}
	DB db = null;
	File home = new File(path);
	if(!home.exists()){
		home.mkdirs();
	}
	try {
		db = JniDBFactory.factory.open(home, options);
	} catch (Exception e) {
		if(checkLock(home)){
			JniDBFactory.factory.repair(home, options);
		}
		db = JniDBFactory.factory.open(home, options);
	}
	databaseCache.put(path, db);
	return db;
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:21,代碼來源:LevelTable.java

示例3: replace

import org.iq80.leveldb.DB; //導入依賴的package包/類
public static <T extends D_Level> void replace(String cluster, Class<T> clazz, List<T> data) throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	WriteBatch write = db.createWriteBatch();
	try {
		iterator.seekToFirst();
		iterator.forEachRemaining(entry ->{
			byte[] key = entry.getKey();
			write.delete(key);
		});
		data.forEach(t->{
			write.put(t.key().getBytes(), t.value());
		});
		db.write(write, new WriteOptions().sync(true));
	} finally {
		iterator.close();
		write.close();
	}
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:21,代碼來源:LevelTable.java

示例4: last

import org.iq80.leveldb.DB; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static <T extends D_TimeLine> T last(String cluster, Class<T> clazz) throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	try {
		iterator.seekToLast();
		if(!iterator.hasNext()){
			return null;
		}
		Entry<byte[], byte[]> entry = iterator.next();
		byte[] v = entry.getValue();
		return (T)D_Level.deserialize(clazz, v);
	} finally {
		iterator.close();
	}
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:18,代碼來源:LevelTable.java

示例5: getAll

import org.iq80.leveldb.DB; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static <T extends D_Level> List<T> getAll(String cluster, Class<T> clazz)throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	List<T> list = new ArrayList<T>();
	try {
		iterator.seekToFirst();
		iterator.forEachRemaining(entry ->{
			byte[] v = entry.getValue();
			list.add((T)D_Level.deserialize(clazz, v));
		});
	} finally {
		iterator.close();
	}
	return list;
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:18,代碼來源:LevelTable.java

示例6: prevWith

import org.iq80.leveldb.DB; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static <T extends D_TimeLine> void prevWith(String cluster, Class<T> clazz, Long start, Consumer<T> action) throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	try {
		iterator.seek((start + "").getBytes());
		while(iterator.hasPrev()){
			Entry<byte[], byte[]> entry = iterator.prev();
			byte[] v = entry.getValue();
			action.accept((T)D_Level.deserialize(clazz, v));
		}
	} finally {
		iterator.close();
	}
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:17,代碼來源:LevelTable.java

示例7: deletePrev

import org.iq80.leveldb.DB; //導入依賴的package包/類
public static <T extends D_TimeLine> void deletePrev(String cluster, Class<T> clazz, Long start) throws IOException {
	DB db = getDB(path(cluster, clazz));
	ReadOptions readOptions = new ReadOptions().snapshot(db.getSnapshot());
	DBIterator iterator = db.iterator(readOptions);
	WriteBatch write = db.createWriteBatch();
	try {
		iterator.seek((start + "").getBytes());
		while(iterator.hasPrev()){
			byte[] key = iterator.prev().getKey();
			write.delete(key);
		}
		db.write(write, new WriteOptions().sync(true));
	} finally {
		iterator.close();
		write.close();
	}
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:18,代碼來源:LevelTable.java

示例8: createCachePool

import org.iq80.leveldb.DB; //導入依賴的package包/類
@Override
public CachePool createCachePool(String poolName, int cacheSize,
                                 int expireSeconds) {
    Options options = new Options();
    options.cacheSize(1048576L * cacheSize); //cacheSize M
    options.createIfMissing(true);
    DB db = null;
    String filePath = "leveldb\\" + poolName;
    try {
        db = factory.open(new File(filePath), options);
        // Use the db in here....
    } catch (IOException e) {
        LOGGER.info("factory try to open file " + filePath + " failed ");
        // Make sure you close the db to shutdown the
        // database and avoid resource leaks.
        // db.close();
    }
    return new LevelDBPool(poolName, db, cacheSize);
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:20,代碼來源:LevelDBCachePooFactory.java

示例9: getEntity

import org.iq80.leveldb.DB; //導入依賴的package包/類
@Override
public TimelineEntity getEntity(String entityId, String entityType,
    EnumSet<Field> fields) throws IOException {
  Long revStartTime = getStartTimeLong(entityId, entityType);
  if (revStartTime == null) {
    return null;
  }
  byte[] prefix = KeyBuilder.newInstance().add(entityType)
      .add(writeReverseOrderedLong(revStartTime)).add(entityId)
      .getBytesForLookup();

  DBIterator iterator = null;
  try {
    DB db = entitydb.getDBForStartTime(revStartTime);
    if (db == null) {
      return null;
    }
    iterator = db.iterator();
    iterator.seek(prefix);

    return getEntity(entityId, entityType, revStartTime, fields, iterator,
        prefix, prefix.length);
  } finally {
    IOUtils.cleanup(LOG, iterator);
  }
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:27,代碼來源:RollingLevelDBTimelineStore.java

示例10: scheduleOldDBsForEviction

import org.iq80.leveldb.DB; //導入依賴的package包/類
private synchronized void scheduleOldDBsForEviction() {
  // keep at least time to live amount of data
  long evictionThreshold = computeCurrentCheckMillis(currentTimeMillis()
      - getTimeToLive());

  LOG.info("Scheduling " + getName() + " DBs older than "
      + fdf.format(evictionThreshold) + " for eviction");
  Iterator<Entry<Long, DB>> iterator = rollingdbs.entrySet().iterator();
  while (iterator.hasNext()) {
    Entry<Long, DB> entry = iterator.next();
    // parse this in gmt time
    if (entry.getKey() < evictionThreshold) {
      LOG.info("Scheduling " + getName() + " eviction for "
          + fdf.format(entry.getKey()));
      iterator.remove();
      rollingdbsToEvict.put(entry.getKey(), entry.getValue());
    }
  }
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:20,代碼來源:RollingLevelDB.java

示例11: evictOldDBs

import org.iq80.leveldb.DB; //導入依賴的package包/類
public synchronized void evictOldDBs() {
  LOG.info("Evicting " + getName() + " DBs scheduled for eviction");
  Iterator<Entry<Long, DB>> iterator = rollingdbsToEvict.entrySet()
      .iterator();
  while (iterator.hasNext()) {
    Entry<Long, DB> entry = iterator.next();
    IOUtils.cleanup(LOG, entry.getValue());
    String dbName = fdf.format(entry.getKey());
    Path path = new Path(rollingDBPath, getName() + "." + dbName);
    try {
      LOG.info("Removing old db directory contents in " + path);
      lfs.delete(path, true);
    } catch (IOException ioe) {
      LOG.warn("Failed to evict old db " + path, ioe);
    }
    iterator.remove();
  }
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:19,代碼來源:RollingLevelDB.java

示例12: testInsertAfterRollPeriodRollsDB

import org.iq80.leveldb.DB; //導入依賴的package包/類
@Test
public void testInsertAfterRollPeriodRollsDB() throws Exception {

  rollingLevelDB.init(conf);
  long now = rollingLevelDB.currentTimeMillis();
  DB db = rollingLevelDB.getDBForStartTime(now);
  long startTime = rollingLevelDB.getStartTimeFor(db);
  Assert.assertEquals("Received level db for incorrect start time",
      rollingLevelDB.computeCurrentCheckMillis(now),
      startTime);
  now = rollingLevelDB.getNextRollingTimeMillis();
  rollingLevelDB.setCurrentTimeMillis(now);
  db = rollingLevelDB.getDBForStartTime(now);
  startTime = rollingLevelDB.getStartTimeFor(db);
  Assert.assertEquals("Received level db for incorrect start time",
      rollingLevelDB.computeCurrentCheckMillis(now),
      startTime);
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:19,代碼來源:TestRollingLevelDB.java

示例13: main

import org.iq80.leveldb.DB; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
  String path = args[0];
  
  Options options = new Options();
  options.createIfMissing(true);
  options.verifyChecksums(true);
  options.paranoidChecks(true);

  DB db = null;

  try {
    db = JniDBFactory.factory.open(new File(path), options);
  } catch (UnsatisfiedLinkError ule) {
    db = Iq80DBFactory.factory.open(new File(path), options);
  }      
  
  db.close();
}
 
開發者ID:cityzendata,項目名稱:warp10-platform,代碼行數:19,代碼來源:WarpInit.java

示例14: _readEntry

import org.iq80.leveldb.DB; //導入依賴的package包/類
private static XImgPreviewGen.PreviewElement _readEntry(byte[] md5b, XImg.PreviewType type) throws XImgPreviewGen.RecordNotFoundException, IOException, ClassNotFoundException {
    if (XImg.getDB(type) == null) throw new IOException("database not opened;");
    
    final DB db = XImg.getDB(type);
    byte[] retnc;
    synchronized (db) {
        retnc = db.get(md5b);
        if (retnc == null ) throw new XImgPreviewGen.RecordNotFoundException("");
    }
    
    final byte[] ret = dsCrypto.decrypt(retnc);
    if (ret == null ) throw new IOException("Decrypt() return null value;");
    
    final ByteArrayInputStream bais = new ByteArrayInputStream(ret);
    final ObjectInputStream oos = new ObjectInputStream(bais);
    final XImgPreviewGen.PreviewElement retVal = (XImgPreviewGen.PreviewElement) oos.readObject();
    if (retVal == null ) throw new IOException("readObject() return null value;");
    
    return retVal;
}
 
開發者ID:konachan700,項目名稱:JNekoImageDB,代碼行數:21,代碼來源:XImgDatastore.java

示例15: openDatabase

import org.iq80.leveldb.DB; //導入依賴的package包/類
protected DB openDatabase() throws Exception {
  Path storeRoot = createStorageDir();
  Options options = new Options();
  options.createIfMissing(false);
  options.logger(new LeveldbLogger());
  LOG.info("Using state database at " + storeRoot + " for recovery");
  File dbfile = new File(storeRoot.toString());
  try {
    db = JniDBFactory.factory.open(dbfile, options);
  } catch (NativeDB.DBException e) {
    if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
      LOG.info("Creating state database at " + dbfile);
      options.createIfMissing(true);
      try {
        db = JniDBFactory.factory.open(dbfile, options);
        // store version
        storeVersion();
      } catch (DBException dbErr) {
        throw new IOException(dbErr.getMessage(), dbErr);
      }
    } else {
      throw e;
    }
  }
  return db;
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:27,代碼來源:LeveldbRMStateStore.java


注:本文中的org.iq80.leveldb.DB類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。