package org.bdware.sc.blockdb;

import org.bdware.sc.commParser.BDLedger.Transaction;
import org.rocksdb.Options;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;

import java.io.File;
import java.util.Map;

public class RocksDBUtil implements DBRepository{
	private static RocksDB rocksdb;
	static {
		RocksDB.loadLibrary();
	}

	public static RocksDB loadDB(String path, String readOnly) {
		try {
			Options options = new Options();
			options.setCreateIfMissing(true);
			RocksDB rocksDB;
			File lockFile = new File(path,"LOCK");
			lockFile.delete();
			if (readOnly != null && readOnly.equals("true")) {
				rocksDB = RocksDB.openReadOnly(options, path);
			} else
				rocksDB = RocksDB.open(options, path);
			rocksdb = rocksDB;
			return rocksDB;

		} catch (RocksDBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public String Get(Map<String, Object> condition) {
		// TODO Auto-generated method stub
		if(condition.containsKey("start")&&condition.containsKey("end")) {
			int start = (int)condition.get("start");
			int end = (int)condition.get("end");
		}
		return null;
	}

	@Override
	public boolean Put(Transaction trans) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean Delete(String hash) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean Create_DB() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean Open_DB() {
		// TODO Auto-generated method stub
		return false;
	}
	
}
