Package com.mckoi.database
Class StateStore
- java.lang.Object
-
- com.mckoi.database.StateStore
-
class StateStore extends java.lang.Object
A 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 class
StateStore.StateResource
Represents a single StateResource in either a visible or delete list in this state file.
-
Field Summary
Fields Modifier and Type Field Description private boolean
del_list_change
Set to true if the delete list was changed.private long
del_p
Pointer to the delete table area in the store.private java.util.ArrayList
delete_list
The list of deleted state resources.private MutableArea
header_area
The header area of the state store.private int
MAGIC
The MAGIC value used for state header areas.private Store
store
The Store object this state store wraps around.private int
table_id
The current table identifier.private boolean
vis_list_change
Set to true if the visible list was changed.private long
vis_p
Pointer to the visible table area in the store.private java.util.ArrayList
visible_list
The 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 void
addDeleteResource(StateStore.StateResource resource)
Adds the given StateResource to the deleted table list.void
addVisibleResource(StateStore.StateResource resource)
Adds the given StateResource to the visible table list.boolean
commit()
Commits the current state to disk so that it makes a persistent change to the state.boolean
containsVisibleResource(int table_id)
Returns true if the visible list contains a state resource with the given table id value.long
convert(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.long
create()
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.void
init(long header_p)
Initializes the state store given a pointer to the header area in the store.int
nextTableID()
Returns the next table id and increments the table_id counter.private void
readStateResourceList(java.util.ArrayList list, long pointer)
Reads the state resource list from the given area in the store.void
removeDeleteResource(java.lang.String name)
Removes the resource with the given name from the deleted list.private void
removeResource(java.util.ArrayList list, java.lang.String name)
Removes the given resource from the list.void
removeVisibleResource(java.lang.String name)
Removes the resource with the given name from the visible list.private long
writeListToStore(java.util.ArrayList list)
Writes the given list to the store and returns a pointer to the area once the write has finished.private void
writeStateResourceList(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.IOException
Reads 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.IOException
Writes 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.IOException
Writes 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.IOException
Creates 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.IOException
Initializes 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.IOException
Reads 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.IOException
Returns 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.IOException
Commits 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
-
-