package com.hammurapi.store;

/**
 * Backing store can be used by object store to 
 * load and store objects. In this case the object store role is manipulation and
 * backing store role is persistence.
 * @author Pavel Vlasov
 *
 */
public interface BackingStore<T, PK> {
	
	/**
	 * @return Iterable to load objects to the object store.
	 */
	Iterable<T> load();
	
	/**
	 * This method is invoked only if the object store
	 * getByPrimaryKey() is invoked and the primary key is not 
	 * present in the object store. This method can be used if the 
	 * object store is used as a memory sensitive cache.
	 * @param primaryKey
	 * @return
	 */
	T load(PK primaryKey);
	
	/**
	 * Adds object to the backing store.
	 * @param primaryKey Primary key value, if object store is configured
	 * with primary key extractor, null otherwise.
	 * @param obj Object to store.
	 */
	void add(PK primaryKey, T obj);

	/**
	 * Removes object from the backing store.
	 * @param primaryKey Primary key value, if object store is configured
	 * with primary key extractor, null otherwise.
	 * @param obj Object to remove.
	 */
	void remove(PK primaryKey, T obj);
	
	/**
	 * Updates object in the backing store.
	 * @param primaryKey Primary key value, if object store is configured
	 * with primary key extractor, null otherwise.
	 * @param obj Object to update.
	 */
	void update(PK primaryKey, T obj);	
}
