Package com.mckoi.database
Class StateStore
- java.lang.Object
-
- com.mckoi.database.StateStore
-
class StateStore extends java.lang.ObjectA store that manages the current state of all tables in a Conglomerate. It persistantly manages three pieces of information about a conglomerate - the tables that are visible, the tables that are deleted, and a table_id value assigned to new tables that are created.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classStateStore.StateResourceRepresents a single StateResource in either a visible or delete list in this state file.
-
Field Summary
Fields Modifier and Type Field Description private booleandel_list_changeSet to true if the delete list was changed.private longdel_pPointer to the delete table area in the store.private java.util.ArrayListdelete_listThe list of deleted state resources.private MutableAreaheader_areaThe header area of the state store.private intMAGICThe MAGIC value used for state header areas.private StorestoreThe Store object this state store wraps around.private inttable_idThe current table identifier.private booleanvis_list_changeSet to true if the visible list was changed.private longvis_pPointer to the visible table area in the store.private java.util.ArrayListvisible_listThe list of visible state resources.
-
Constructor Summary
Constructors Constructor Description StateStore(Store store)Constructs the StateStore.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDeleteResource(StateStore.StateResource resource)Adds the given StateResource to the deleted table list.voidaddVisibleResource(StateStore.StateResource resource)Adds the given StateResource to the visible table list.booleancommit()Commits the current state to disk so that it makes a persistent change to the state.booleancontainsVisibleResource(int table_id)Returns true if the visible list contains a state resource with the given table id value.longconvert(java.io.File legacy_sf, DebugLogger debug)Reads a legacy state file (pre version 1) and converts it to a state store format compatible with this store.longcreate()Creates the state store in the store and returns a pointer to the header used later for initializing the state.StateStore.StateResource[]getDeleteList()Returns a list of all table resources that are currently in the deleted list.StateStore.StateResource[]getVisibleList()Returns a list of all table resources that are currently in the visible list.voidinit(long header_p)Initializes the state store given a pointer to the header area in the store.intnextTableID()Returns the next table id and increments the table_id counter.private voidreadStateResourceList(java.util.ArrayList list, long pointer)Reads the state resource list from the given area in the store.voidremoveDeleteResource(java.lang.String name)Removes the resource with the given name from the deleted list.private voidremoveResource(java.util.ArrayList list, java.lang.String name)Removes the given resource from the list.voidremoveVisibleResource(java.lang.String name)Removes the resource with the given name from the visible list.private longwriteListToStore(java.util.ArrayList list)Writes the given list to the store and returns a pointer to the area once the write has finished.private voidwriteStateResourceList(java.util.ArrayList list, java.io.DataOutputStream d_out)Writes the state resource list to the given area in the store.
-
-
-
Field Detail
-
MAGIC
private int MAGIC
The MAGIC value used for state header areas.
-
store
private Store store
The Store object this state store wraps around.
-
table_id
private int table_id
The current table identifier.
-
header_area
private MutableArea header_area
The header area of the state store. The format of the header area is; MAGIC(4) - RESERVED(4) - TABLE_ID(8) - VISIBLE_TABLES_POINTER(8) - DELETED_TABLES_POINTER(8)
-
vis_p
private long vis_p
Pointer to the visible table area in the store.
-
del_p
private long del_p
Pointer to the delete table area in the store.
-
visible_list
private java.util.ArrayList visible_list
The list of visible state resources.
-
delete_list
private java.util.ArrayList delete_list
The list of deleted state resources.
-
vis_list_change
private boolean vis_list_change
Set to true if the visible list was changed.
-
del_list_change
private boolean del_list_change
Set to true if the delete list was changed.
-
-
Constructor Detail
-
StateStore
public StateStore(Store store)
Constructs the StateStore.
-
-
Method Detail
-
removeResource
private void removeResource(java.util.ArrayList list, java.lang.String name)Removes the given resource from the list.
-
readStateResourceList
private void readStateResourceList(java.util.ArrayList list, long pointer) throws java.io.IOExceptionReads the state resource list from the given area in the store.- Throws:
java.io.IOException
-
writeStateResourceList
private void writeStateResourceList(java.util.ArrayList list, java.io.DataOutputStream d_out) throws java.io.IOExceptionWrites the state resource list to the given area in the store.- Throws:
java.io.IOException
-
writeListToStore
private long writeListToStore(java.util.ArrayList list) throws java.io.IOExceptionWrites the given list to the store and returns a pointer to the area once the write has finished.- Throws:
java.io.IOException
-
create
public long create() throws java.io.IOExceptionCreates the state store in the store and returns a pointer to the header used later for initializing the state.- Throws:
java.io.IOException
-
init
public void init(long header_p) throws java.io.IOExceptionInitializes the state store given a pointer to the header area in the store.- Throws:
java.io.IOException
-
convert
public long convert(java.io.File legacy_sf, DebugLogger debug) throws java.io.IOExceptionReads a legacy state file (pre version 1) and converts it to a state store format compatible with this store. Fortunately the conversion is fairly straight-forward. This is otherwise the same as using the 'create' method.- Throws:
java.io.IOException
-
nextTableID
public int nextTableID() throws java.io.IOExceptionReturns the next table id and increments the table_id counter.- Throws:
java.io.IOException
-
getVisibleList
public StateStore.StateResource[] getVisibleList()
Returns a list of all table resources that are currently in the visible list.
-
getDeleteList
public StateStore.StateResource[] getDeleteList()
Returns a list of all table resources that are currently in the deleted list.
-
containsVisibleResource
public boolean containsVisibleResource(int table_id)
Returns true if the visible list contains a state resource with the given table id value.
-
addVisibleResource
public void addVisibleResource(StateStore.StateResource resource)
Adds the given StateResource to the visible table list. This does not persist the state. To persist this change a call to 'commit' must be called.
-
addDeleteResource
public void addDeleteResource(StateStore.StateResource resource)
Adds the given StateResource to the deleted table list. This does not persist the state. To persist this change a call to 'commit' must be called.
-
removeVisibleResource
public void removeVisibleResource(java.lang.String name)
Removes the resource with the given name from the visible list. This does not persist the state. To persist this change a call to 'commit' must be called.
-
removeDeleteResource
public void removeDeleteResource(java.lang.String name)
Removes the resource with the given name from the deleted list. This does not persist the state. To persist this change a call to 'commit' must be called.
-
commit
public boolean commit() throws java.io.IOExceptionCommits the current state to disk so that it makes a persistent change to the state. A further call to 'synch()' will synchronize the file. This will only commit changes if there were modifications to the state. Returns true if this commit caused any changes to the persistant state.- Throws:
java.io.IOException
-
-