|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--saaps.dbt.Database
Database is the abstract base class for all saaps data classes. It provides storing and retrieving of the data defined by the classes that extend Database.
Information about the data is stored in the class MetaData
which is initialized from the *.meta file when an instance of
Database
is created.
The static method getInstance(String)
can be used to get
an instance of Database
, it will open the data file
in read-write mode.
The other static method getInstance(String, boolean)
should
be used when you want to open the data file in read only mode.
Field Summary | |
protected static java.lang.String |
baseDir
Absolute path to the database. |
static java.lang.String |
dataDirVar
An environment property name that defines the path to database. |
protected double |
dataGapValue
|
protected boolean |
isSet
Indicates if this instance of Database has valid
MetaData . |
MetaData |
meta
|
protected java.io.RandomAccessFile |
raf
Reading and writeing of data is done through a RandomAccessFile class. |
Constructor Summary | |
Database()
|
Method Summary | |
private DatabaseObject |
average(java.util.Vector vec)
Averages this data. |
private DatabaseObject[] |
average(java.util.Vector vec,
int ave)
Averages this data. |
void |
close()
Close the database. |
protected double |
getDataGapValue()
Gets the dataGapValue . |
abstract java.util.Date |
getDate(java.lang.Object obj)
Gets the date from this object. |
protected abstract MetaData |
getEmptyMetaData(java.util.Date sd,
java.util.Date ed)
Gets a MetaData object with the dates set to
the supplied dates. |
DatabaseObject |
getFirst()
Gets the first database object in the database. |
static Database |
getInstance(java.lang.String myDB)
Runs method getInstance with the default action to open database for read/write. |
static Database |
getInstance(java.lang.String myDB,
boolean readOnlyAccess)
Gets a Database object. |
DatabaseObject |
getLast()
Gets the last database object in the database |
abstract java.util.Vector |
getLatestDatabaseObjects()
Do not use this method it will be removed ! |
TimeSeries |
getResampledTimeSeries(java.util.Date sd,
java.util.Date ed,
long sampleInterval)
Gets a TimeSeries object. |
TimeSeries |
getTimeSeries(java.util.Date sd,
java.util.Date ed,
long limit)
Gets a TimeSeries object. |
protected void |
importAscii(java.lang.String inputfile)
Imports ASCII data to our database. |
boolean |
isSet()
Indicates if the MetaData is set and the data file
is open. |
protected long |
position(boolean start)
Positions in start or end of file. |
private long |
position(java.util.Date d,
boolean fromStart)
Runs position with default action to position before the search date. |
private long |
position(java.util.Date d,
boolean fromStart,
boolean before)
Positions the RandomAccessFile at the location closest
to the supplied date and returns the location of the object after this. |
abstract java.lang.Object |
read()
Gets the object at the current point in file. |
java.util.Vector |
retrieve()
Gets all objects in the database (returned in a Vector ). |
java.lang.Object |
retrieve(java.util.Date sd)
Gets the object before this date. |
java.util.Vector |
retrieve(java.util.Date sd,
java.util.Date ed)
Gets the objects between the two dates. |
java.util.Vector |
retrieve(java.util.Date sd,
java.util.Date ed,
boolean before)
Gets the DatabaseObject s between the dates. |
TimeSeries |
retrieveAVE(int fieldIndex,
java.util.Date[] events,
long start,
long end)
Retrieves a TimeSeries object containing the averaged data for the input event list. |
TimeSeries |
retrieveAVE(int fieldIndex,
java.util.Date[] events,
long start,
long end,
boolean withAdditionalInfo)
Retrieves a TimeSeries object containing the averaged data for the input event list. |
ObjectTimeSeries |
retrieveOTS(java.util.Date sd,
java.util.Date ed,
boolean before)
Gets an ObjectTimeSeries containing data between
the dates. |
TimeSeries |
retrieveSEA(int fieldIndex,
java.util.Date[] events,
long start,
long end,
boolean withAdditionalInfo)
Retrieves a TimeSeries object containing the averaged data for the input event list. |
TimeSeries |
retrieveTS(java.util.Date sd,
java.util.Date ed,
boolean before)
Gets a TimeSeries containing data between
the dates. |
TimeSeries |
retrieveTS(java.util.Date sd,
java.util.Date ed,
boolean before,
long sampleInterval)
Gets a TimeSeries containing data between
the dates, the data is resampled if needed to the sampleinterval stated. |
protected abstract MetaData |
setDefaultMeta(java.util.Date sd,
java.util.Date ed)
Sets the MetaData for the specific database and
stores it to file. |
void |
store(ObjectTimeSeries ts)
Stores DatabaseObject s to file. |
void |
store(java.util.Vector vec)
Stores DatabaseObject s to file without checking
the input data. |
abstract void |
write(java.lang.Object dbo)
Writes data at the current point in file. |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected static java.lang.String baseDir
dataDirVar
contains the name of the property
that will reset the path if it's defined.public static java.lang.String dataDirVar
public MetaData meta
protected double dataGapValue
protected boolean isSet
Database
has valid
MetaData
.protected java.io.RandomAccessFile raf
Constructor Detail |
public Database()
Method Detail |
public static Database getInstance(java.lang.String myDB)
myDB
- the database to be loadedDatabase
objectpublic static Database getInstance(java.lang.String myDB, boolean readOnlyAccess)
Database
object.
Also retrieves the MetaData
information from file and
opens the randomaccessfile (data file).
If loading of MetaData
fails, the default MetaData
is set using getEmptyMetaData(Date, Date)
.
In this case the isSet
variable is set to false.
myDB
- the database to be loadedreadOnlyAccess
- the access modeDatabase
objectpublic void close() throws java.io.IOException
Note: we don't have any open method yet so you will have to get a new instance of this database to get an open file.
public boolean isSet()
MetaData
is set and the data file
is open. If MetaData
is set by
getEmptyMetaData(Date , Date )
the parameter isSet
is false.true
if the MetaData
is setprotected final long position(boolean start) throws java.io.IOException
start
- if true
position in beginning of fileprivate final long position(java.util.Date d, boolean fromStart) throws java.io.IOException
position(Date , boolean , boolean )
.d
- the search datefromStart
- if true then serach file from beginning else proceed
from current file position.private final long position(java.util.Date d, boolean fromStart, boolean before) throws java.io.IOException
RandomAccessFile
at the location closest
to the supplied date and returns the location of the object after this.
Position will try to use MetaData
to do a faster search.
If the date is after last date in file the fileposition is left at EOF and an IOException is thrown.
d
- the date to be found.fromStart
- if true then serach file from beginning, not
using MetaData
, else proceed from current file position.before
- if true position before date else at or after datepublic DatabaseObject getFirst() throws java.io.IOException
DatabaseObject
from the databasepublic DatabaseObject getLast() throws java.io.IOException
DatabaseObject
from the databasepublic final java.util.Vector retrieve() throws java.io.IOException
Vector
).
Note: We should take care when using this so that we don't
exhaust memory.
You should use one of the other retrieve methods when you want
to load data.Vector
containing all
DatabaseObject
s.public final java.lang.Object retrieve(java.util.Date sd) throws java.io.IOException
sd
- the search datepublic final java.util.Vector retrieve(java.util.Date sd, java.util.Date ed) throws java.io.IOException
sd
- start date for searched
- end date for searchVector
containing the
DatabaseObject
s between the dates.public final java.util.Vector retrieve(java.util.Date sd, java.util.Date ed, boolean before) throws java.io.IOException
DatabaseObject
s between the dates.
If the first date is after the second date, only the object at
the first date will be returned.sd
- start date for searched
- end date for searchbefore
- if true
then the first object returned
is before the start search date.Vector
containing the
DatabaseObject
s between the dates.public final ObjectTimeSeries retrieveOTS(java.util.Date sd, java.util.Date ed, boolean before) throws java.io.IOException, IllegalTimeSeriesException
ObjectTimeSeries
containing data between
the dates.
See also retrieve(Date, Date, boolean)
sd
- start date for searched
- end date for searchbefore
- if true
then the first object returned
is before the start search date.public final TimeSeries retrieveTS(java.util.Date sd, java.util.Date ed, boolean before) throws java.io.IOException
TimeSeries
containing data between
the dates.
See also retrieve(Date, Date, boolean)
and
retrieveOTS(Date, Date, boolean)
.sd
- start date for searched
- end date for searchbefore
- if true
then the first object returned
is before the start search date.public final TimeSeries retrieveTS(java.util.Date sd, java.util.Date ed, boolean before, long sampleInterval) throws java.io.IOException, TimeSeriesException
TimeSeries
containing data between
the dates, the data is resampled if needed to the sampleinterval stated.
See also retrieve(Date, Date, boolean)
and
retrieveOTS(Date, Date, boolean)
.sd
- start date for searched
- end date for searchbefore
- if true
then the first object returned
is before the start search date.sampleInterval
- timestep that the data should have [ms]public TimeSeries retrieveAVE(int fieldIndex, java.util.Date[] events, long start, long end) throws java.io.IOException, TimeSeriesIndexException, IllegalTimeSeriesException
Every date/time in the events
list is used as time
reference for data retrieval, the start
and
end
parameters define the time window for which
data is retrieved.
If data for any of these time windows is missing an IOException
is thrown.
The data loaded for every event is averaged, time is set from the
middle of the event data. A TimeSeries
object
containing the data field indicated is created from the averaged
data.
fieldIndex
- index of the data fieldevents
- array of event timesstart
- event window starts here (normally negative [milliseconds])end
- event window ends here (normally positiv [milliseconds])TimeSeries
object with averaged
fieldName
data for start to end time for every eventTimeSeriesIndexException
- when fieldIndex
is out of boundsjava.io.IOException
- when data for any of the event times are missingpublic TimeSeries retrieveAVE(int fieldIndex, java.util.Date[] events, long start, long end, boolean withAdditionalInfo) throws java.io.IOException, TimeSeriesIndexException, IllegalTimeSeriesException
Every date/time in the events
list is used as time
reference for data retrieval, the start
and
end
parameters define the time window for which
data is retrieved.
If data for any of these time windows is missing an IOException
is thrown.
The data loaded for every event is averaged, time is set from the
middle of the event data. A TimeSeries
object
containing the data field indicated, the number of datapoints
used in the average and the standard deviation is created from
the averaged data.
fieldIndex
- index of the data fieldevents
- array of event timesstart
- event window starts here (normally negative [milliseconds])end
- event window ends here (normally positiv [milliseconds])withAdditionalInfo
- if false
run the other method
retrieveAVE(int, Date[], long, long)
.TimeSeries
object with averaged
fieldName
data for start to end time for every eventTimeSeriesIndexException
- when fieldIndex
is out of boundsjava.io.IOException
- when data for any of the event times are missingpublic TimeSeries retrieveSEA(int fieldIndex, java.util.Date[] events, long start, long end, boolean withAdditionalInfo) throws java.io.IOException, TimeSeriesIndexException, IllegalTimeSeriesException
Every date/time in the events
list is used as time
reference for data retrieval, the start
and
end
parameters define the time window for which
data is retrieved.
If data for any of these time windows is missing an IOException
is thrown.
The data field indicated is averaged over the events.
A TimeSeries
object
containing the data field indicated, the number of datapoints
used in the average and the standard deviation is created from
the averaged data.
fieldIndex
- index of the data fieldevents
- array of event timesstart
- event window starts here (normally negative [milliseconds])end
- event window ends here (normally positiv [milliseconds])withAdditionalInfo
- Not used yetTimeSeries
object with averaged
fieldName
data for every event.TimeSeriesIndexException
- when fieldIndex
is out of boundsjava.io.IOException
- when data for any of the event times are missingpublic TimeSeries getTimeSeries(java.util.Date sd, java.util.Date ed, long limit) throws java.io.IOException, MetaNotSetException, TimestepException, DatabaseException
limit
parameter will be the maximum memory
consumption of the resultimg TimeSeries
object,
in other words the data will be resampled to fit into that memory.
Note: This method only handles data with constant timestep.
sd
- start date for searched
- end date for searchlimit
- limits the size of the TimeSeries objectTimeSeries
contains data between the dates, possibly reducedpublic TimeSeries getResampledTimeSeries(java.util.Date sd, java.util.Date ed, long sampleInterval) throws java.io.IOException, MetaNotSetException, TimestepException, DatabaseException
sd
- start date for searched
- end date for searchsampleInterval
- data is resampled to this interval if needed [ms]TimeSeries
contains data between the dates, possibly reducedprivate DatabaseObject average(java.util.Vector vec)
vec
- a Vector
containing the data to be averagedDatabaseObject
with time set to
the middle of the input dataprivate DatabaseObject[] average(java.util.Vector vec, int ave) throws DatabaseException
vec
- a Vector
containing the data to be averagedave
- defines the number of objects that will be averagedVector
containing DatabaseObject
s
averaged according the ave parameterDatabaseException
- even number of elementsprotected double getDataGapValue()
dataGapValue
.dataGapValue
.public final void store(java.util.Vector vec)
DatabaseObject
s to file without checking
the input data.
Note:You should not use this version of the store method !
See store(ObjectTimeSeries)
vec
- data to be storedpublic final void store(ObjectTimeSeries ts)
DatabaseObject
s to file.
This version of store will do the necessary checks on
the ObjectTimeSeries so that it is safe to write it to
our database.
Currently it will only allow writing if the TimeSeries follows
the rules for the specific database.
Data will not be written if it's not inside the start and
end time in the MetaData
(end time can be endtime + timestep).ts
- ObjectTimeSeries
containing the data
thats about to be storedprotected void importAscii(java.lang.String inputfile)
DatabaseObject
s and then try
to store it, read again and store until it is finished or an
exception occures.
Note: Currently the buffering doesn't work ! vectors below 200Mb in size is imported correctly.
inputfile
- the file containing the data to be importedpublic abstract java.lang.Object read() throws java.io.IOException
java.io.IOException
- when reading failspublic abstract void write(java.lang.Object dbo) throws java.io.IOException
dbo
- an object containg data to be written.java.io.IOException
- when writeing failspublic abstract java.util.Date getDate(java.lang.Object obj)
DatabaseObject.getDate()
.obj
- a database objectDate
for the input objectpublic abstract java.util.Vector getLatestDatabaseObjects()
protected abstract MetaData setDefaultMeta(java.util.Date sd, java.util.Date ed) throws java.io.IOException
MetaData
for the specific database and
stores it to file.sd
- start time of data in datafileed
- end time of data in datafileMetaData
objectjava.io.IOException
- when save of MetaData
failsprotected abstract MetaData getEmptyMetaData(java.util.Date sd, java.util.Date ed)
MetaData
object with the dates set to
the supplied dates.sd
- fake start dateed
- fake end dateMetaData
object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |