Java Code Examples for org.iq80.leveldb.DB#iterator()

The following examples show how to use org.iq80.leveldb.DB#iterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectLevelDBData.java    From gsc-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void data(String dataName) {
    Options options = new Options();
    //options.createIfMissing(true);
    DB db = null;
    try {
        System.out.println("Path: " + path + dataName);
        db = factory.open(new File(path + dataName), options);

        logger.info("---------------------------------------------");
        System.out.println();
        DBIterator iterator = db.iterator();
        iterator.seekToFirst();
        int count = 0;
        while (iterator.hasNext()) {
            count++;
            switch (dataName) {
                case "properties":
                    properties(iterator.peekNext().getKey(), iterator.peekNext().getValue());
                    break;
                case "peers":
                    peers(iterator.peekNext().getKey(), iterator.peekNext().getValue());
                    break;
                case "nodes":
                    peers(iterator.peekNext().getKey(), iterator.peekNext().getValue());
                    break;
                default:
                    break;
            }
            iterator.next();
        }
        iterator.close();
        System.out.println(dataName + " Num: " + count);
        System.out.println();
        logger.info("---------------------------------------------");

        db.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: LevelDbStore.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
		Kryo kryo = new Kryo();
		kryo.setReferences(false);
		kryo.setRegistrationRequired(false);
		kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
//		kryo.register(Transaction.class);
//		kryo.register(Xid.class);
//		kryo.register(TransactionType.class);
//		kryo.register(TransactionStatus.class);
//		kryo.register(Participant.class);
		
//		Output output = new Output(new ByteArrayOutputStream());//new Output(new FileOutputStream("file.bin"));
//		
//		DefaultTransaction defaultTransaction = new DefaultTransaction();
//		defaultTransaction.setXid(new DefaultXid("1", "2", "3"));
//		
//		kryo.writeObject(output, defaultTransaction);
//		output.flush();
//		output.close();
		
		Options options = new Options();
		options.createIfMissing(true);
		options.cacheSize(100 * 1048576); // 100MB cache
		options.logger(new org.iq80.leveldb.Logger() {
			public void log(String message) {
				TransactionLog.REPOSITORY.info(message);
			}
		});
		DB db = Iq80DBFactory.factory.open(new File("txtreedb"), options);
		
//		String stats = db.getProperty("leveldb.stats");
//		System.out.println(stats);
		
		DBIterator iterator = null;
		try {
			iterator = db.iterator();
			for(iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
				String key = Iq80DBFactory.asString(iterator.peekNext().getKey());
				Transaction value = (Transaction) SerializationUtil.deserialize(iterator.peekNext().getValue());
				
				System.out.println(key+" = "+value);
			}
		} finally {
			if (iterator != null) {
				iterator.close();
			}
		}

//		String transactionId = "f282205a-e794-4bda-83a2-bb28b8839cad";
//		Input input = new Input(db.get(Iq80DBFactory.bytes(transactionId)));
//		Transaction transaction = (Transaction) kryo.readClassAndObject(input);
//		System.out.println(transaction);
	}
 
Example 3
Source File: LeveldbIterator.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Create an iterator for the specified database
 */
public LeveldbIterator(DB db) {
  iter = db.iterator();
}
 
Example 4
Source File: LeveldbIterator.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Create an iterator for the specified database
 */
public LeveldbIterator(DB db, ReadOptions options) {
  iter = db.iterator(options);
}
 
Example 5
Source File: LeveldbIterator.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Create an iterator for the specified database
 */
public LeveldbIterator(DB db) {
  iter = db.iterator();
}
 
Example 6
Source File: LeveldbIterator.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Create an iterator for the specified database
 */
public LeveldbIterator(DB db, ReadOptions options) {
  iter = db.iterator(options);
}