|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gillius.realdb.model.Database
public class Database
The Database class is the main class to be used in RealDB. A Database holds a set of DataStream
objects for reading and writing data. The static factory methods or the DatabaseBuilder
can be used to obtain a Database instance.
Constructor Summary | |
---|---|
Database(BlockFile file,
MetadataSection metadata,
BlockPool pool,
DataIndexSection index,
DataSection data)
Constructs a new Database with all of the sections already loaded and configured. |
Method Summary | |
---|---|
void |
close()
Closes the database by flushing all buffers and closing any open resources. |
static Database |
createNew(BlockFile bf,
MetadataSection metadata)
Creates a new Database and formats the given BlockFile with it. |
void |
flush()
Flushes the Database, but keeps it open for further operations. |
void |
forceClose()
Forces the underlying BlockFile to be closed immediately without flushing any data remaining to be written. |
void |
format()
Clears out the database entirely by reformatting the index and data sections. |
int |
getBlockSize()
Returns the block size, in bytes, of the underlying storage. |
int |
getDataBlocksUsed()
Returns the number of data blocks used. |
MetadataSection |
getMetadata()
|
DatabaseStatistics |
getProfilingStatistics()
If this Database is enabled for profiling, returns a DatabaseStatistics , else returns
null. |
java.util.Map<java.lang.String,java.lang.Integer> |
getSectionSizes()
Returns a mapping of section names to their sizes in blocks. |
int |
getSizeInBlocks()
Returns the size of the database, in blocks. |
java.util.Collection<DataStream> |
getStreams()
Returns all of the DataStreams in this database. |
java.util.Map<java.lang.Integer,DataStream> |
getStreamsMap()
Returns a map of DataStream user ID to DataStream. |
int |
getTotalDataBlocks()
Returns the total number of data blocks. |
static Database |
load(BlockFile bf)
Loads a database from a properly constructed BlockFile. |
static Database |
load(java.io.File f)
Loads a database from the given File. |
static Database |
load(java.io.File f,
boolean profiling)
Loads a database from the given File. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Database(BlockFile file, MetadataSection metadata, BlockPool pool, DataIndexSection index, DataSection data)
file
- nullable BlockFile, used only in the close method.Method Detail |
---|
public MetadataSection getMetadata()
public java.util.Map<java.lang.String,java.lang.Integer> getSectionSizes()
public int getDataBlocksUsed()
getSectionSizes()
.
public int getTotalDataBlocks()
getSectionSizes()
.
public int getBlockSize()
public int getSizeInBlocks()
public java.util.Collection<DataStream> getStreams()
public java.util.Map<java.lang.Integer,DataStream> getStreamsMap()
public void format() throws java.io.IOException
format
in interface Formattable
java.io.IOException
- if an error occurs writing the databasepublic void flush() throws java.io.IOException
flush
in interface java.io.Flushable
java.io.IOException
public void close() throws java.io.IOException
load(java.io.File)
later.
If an IOException is thrown while trying to close the database, the underlying file, if there
is one, is forcefully closed to release this resource. In this case not all streams and
buffers were flushed properly.
close
in interface java.io.Closeable
java.io.IOException
public void forceClose()
public DatabaseStatistics getProfilingStatistics()
DatabaseStatistics
, else returns
null.
public static Database createNew(BlockFile bf, MetadataSection metadata) throws java.io.IOException
bf
- BlockFile where DB will be created or loadedmetadata
- Constructed MetadataSection
java.io.IOException
- if there is an error writing to the file. If this occurs the file may have
been partially written.public static Database load(java.io.File f) throws java.io.IOException, BadFileException
f
- non-null existing File
java.io.IOException
- if an error occurs accessing the file
BadFileException
- if the file is read, but the data is unrecoverably corruptedpublic static Database load(java.io.File f, boolean profiling) throws java.io.IOException, BadFileException
f
- non-null existing Fileprofiling
- if true, enables collection of profiling statistics (has some overhead).
java.io.IOException
- if an error occurs accessing the file
BadFileException
- if the file is read, but the data is unrecoverably corruptedpublic static Database load(BlockFile bf) throws java.io.IOException, BadFileException
bf
- non-null BlockFile
java.io.IOException
- if an error occurs accessing the file
BadFileException
- if the file is read, but the data is unrecoverably corrupted
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |