001package com.hammurapi.store; 002 003/** 004 * Backing store can be used by object store to 005 * load and store objects. In this case the object store role is manipulation and 006 * backing store role is persistence. 007 * @author Pavel Vlasov 008 * 009 */ 010public interface BackingStore<T, PK> { 011 012 /** 013 * @return Iterable to load objects to the object store. 014 */ 015 Iterable<T> load(); 016 017 /** 018 * This method is invoked only if the object store 019 * getByPrimaryKey() is invoked and the primary key is not 020 * present in the object store. This method can be used if the 021 * object store is used as a memory sensitive cache. 022 * @param primaryKey 023 * @return 024 */ 025 T load(PK primaryKey); 026 027 /** 028 * Adds object to the backing store. 029 * @param primaryKey Primary key value, if object store is configured 030 * with primary key extractor, null otherwise. 031 * @param obj Object to store. 032 */ 033 void add(PK primaryKey, T obj); 034 035 /** 036 * Removes object from the backing store. 037 * @param primaryKey Primary key value, if object store is configured 038 * with primary key extractor, null otherwise. 039 * @param obj Object to remove. 040 */ 041 void remove(PK primaryKey, T obj); 042 043 /** 044 * Updates object in the backing store. 045 * @param primaryKey Primary key value, if object store is configured 046 * with primary key extractor, null otherwise. 047 * @param obj Object to update. 048 */ 049 void update(PK primaryKey, T obj); 050}