All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.yanfanvip.interfaces.Database Maven / Gradle / Ivy

The newest version!
package com.gitee.yanfanvip.interfaces;

import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.rocksdb.RocksDBException;

import com.gitee.yanfanvip.model.Row;

public interface Database extends AutoCloseable{
	
	/**
	 * 是否存在某个数据
	 * @param keyspaces keyspaces
	 * @param key key
	 * @return 是否存在
	 * @throws RocksDBException error
	 */
	public boolean containsKey(String keyspaces, String key)throws RocksDBException;
	/**
	 * 获取数据内容
	 * @param keyspaces keyspaces
	 * @param key key
	 * @return 值内容
	 * @throws RocksDBException error
	 */
	public byte[] get(String keyspaces, String key)throws RocksDBException;
	/**
	 * 循环某个keyspaces
	 * @param keyspaces keyspaces
	 * @param consumer consumer
	 * @throws RocksDBException error
	 */
	public void forEach(String keyspaces, BiConsumer consumer)throws RocksDBException;
	/**
	 * 循环全部keyspaces
	 * @param consumer consumer
	 * @throws RocksDBException error
	 */
	public void forEach(Consumer consumer)throws RocksDBException;
	/**
	 * put数据
	 * @param keyspaces keyspaces
	 * @param key key
	 * @param value value
	 * @throws RocksDBException error
	 */
	public void put(String keyspaces, String key, byte[] value) throws RocksDBException;
	/**
	 * 如果数据不存在或者数据的内容有变化,则插入数据, 同时返回插入状态
	 * 如果数据存在, 并且值未发生改变, 则返回false
	 * @param keyspaces keyspaces
	 * @param key key
	 * @param value value
	 * @return 是否成功更新, 如果值未发生改变的情况下, 返回false
	 * @throws RocksDBException error
	 */
	public boolean putIfChanged(String keyspaces, String key, byte[] value) throws RocksDBException;
	/**
	 * 批量插入数据
	 * @param keyspaces keyspaces
	 * @param datas datas as list
	 * @throws RocksDBException error
	 */
	public void putAll(String keyspaces, Map datas) throws RocksDBException;
	/**
	 * 批量插入数据, 返回变化的数据
	 * @param keyspaces keyspaces
	 * @param datas datas as list
	 * @return 变化的数据内容
	 * @throws RocksDBException error
	 */
	public Map putAllIfChanged(String keyspaces, Map datas) throws RocksDBException;
	/**
	 * 获取最后一条数据
	 * @param keyspaces keyspaces
	 * @return 数据库中最后一条数据
	 * @throws RocksDBException error
	 */
	public Row getLastData(String keyspaces) throws RocksDBException;
	/**
	 * 删除数据
	 * @param keyspaces keyspaces
	 * @param key key
	 * @throws RocksDBException error
	 */
	public void remove(String keyspaces, String key)throws RocksDBException;
	/**
	 * 删除数据并返回删除状态
	 * @param keyspaces keyspaces
	 * @param key key
	 * @return 是否删除,如果不存在该数据,则返回false
	 * @throws RocksDBException error
	 */
	public boolean removeIfExist(String keyspaces, String key)throws RocksDBException;
	/**
	 * 清空keyspaces
	 * @param keyspaces keyspaces
	 * @throws RocksDBException error
	 */
	public void clear(String keyspaces)throws RocksDBException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy