|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
Object storage
| Field Summary | |
static int |
COOPERATIVE_TRANSACTION
Cooperative mode; all threads share the same transaction. |
static int |
DEFAULT_PAGE_POOL_SIZE
Constant specifying default pool size |
static int |
EXCLUSIVE_TRANSACTION
Exclusive per-thread transaction: each thread access database in exclusive mode |
static int |
INFINITE_PAGE_POOL
Constant specifying that page pool should be dynamically extended to conatins all database file pages |
static int |
REPLICATION_SLAVE_TRANSACTION
Read only transaction which can be started at replicastion slave node. |
static int |
SERIALIZABLE_TRANSACTION
Serializable per-thread transaction. |
| Method Summary | |
void |
backup(java.io.OutputStream out)
Backup current state of database |
void |
beginThreadTransaction(int mode)
Begin per-thread transaction. |
void |
close()
Commit transaction (if needed) and close the storage |
void |
commit()
Commit changes done by the last transaction. |
BitIndex |
createBitIndex()
Create new bit index. |
Blob |
createBlob()
Create new BLOB. |
FieldIndex |
createFieldIndex(java.lang.Class type,
java.lang.String[] fieldNames,
boolean unique)
Create new mutlifield index |
FieldIndex |
createFieldIndex(java.lang.Class type,
java.lang.String fieldName,
boolean unique)
Create new field index |
Index |
createIndex(java.lang.Class[] types,
boolean unique)
Create new compound index |
Index |
createIndex(java.lang.Class type,
boolean unique)
Create new index |
Link |
createLink()
Create one-to-many link. |
Link |
createLink(int initialSize)
Create one-to-many link with specified initially allocated size. |
PatriciaTrie |
createPatriciaTrie()
Create PATRICIA trie (Practical Algorithm To Retrieve Information Coded In Alphanumeric) Tries are a kind of tree where each node holds a common part of one or more keys. |
Query |
createQuery()
Create JSQL query. |
Relation |
createRelation(IPersistent owner)
Create relation object. |
IPersistentSet |
createScalableSet()
Create new scalable set references to persistent objects. |
IPersistentSet |
createScalableSet(int initialSize)
Create new scalable set references to persistent objects. |
IPersistentSet |
createSet()
Create new peristent set |
SortedCollection |
createSortedCollection(boolean unique)
Create new sorted collection. |
SortedCollection |
createSortedCollection(PersistentComparator comparator,
boolean unique)
Create new sorted collection with specified comparator |
SpatialIndex |
createSpatialIndex()
Create new spatial index with integer coordinates |
SpatialIndexR2 |
createSpatialIndexR2()
Create new R2 spatial index |
Index |
createThickIndex(java.lang.Class type)
Create new thick index (index with large number of duplicated keys) |
TimeSeries |
createTimeSeries(java.lang.Class blockClass,
long maxBlockTimeInterval)
Create new time series object. |
void |
deallocateObject(IPersistent obj)
|
void |
endThreadTransaction()
End per-thread transaction started by beginThreadTransaction method. |
void |
endThreadTransaction(int maxDelay)
End per-thread cooperative transaction with specified maximal delay of transaction commit. |
void |
exportXML(java.io.Writer writer)
Export database in XML format |
int |
gc()
Explicit start of garbage collector |
java.lang.ClassLoader |
getClassLoader()
Get class loader used to locate classes for loaded class descriptors. |
long |
getDatabaseSize()
Get size of the database |
java.util.HashMap |
getMemoryDump()
Get database memory dump. |
IPersistent |
getObjectByOID(int oid)
Retrieve object by OID. |
java.util.Properties |
getProperties()
Get all set properties |
java.lang.Object |
getProperty(java.lang.String name)
Get property value. |
IPersistent |
getRoot()
Get storage root. |
long |
getUsedSize()
Get total size of all allocated objects in the database |
void |
importXML(java.io.Reader reader)
Import data from XML file |
boolean |
isOpened()
Check if database is opened |
java.util.Iterator |
join(java.util.Iterator[] selections)
Join results of several index searches. |
void |
loadObject(IPersistent obj)
|
void |
lockObject(IPersistent obj)
|
int |
makePersistent(IPersistent obj)
Explicitely make object peristent. |
java.util.Iterator |
merge(java.util.Iterator[] selections)
Merge results of several index searches. |
void |
modifyObject(IPersistent obj)
|
void |
open(IFile file)
Open the storage with default page pool size |
void |
open(IFile file,
int pagePoolSize)
Open the storage |
void |
open(java.lang.String filePath)
Open the storage with default page pool size |
void |
open(java.lang.String filePath,
int pagePoolSize)
Open the storage |
void |
open(java.lang.String filePath,
int pagePoolSize,
java.lang.String cipherKey)
Open the encrypted storage |
void |
rollback()
Rollback changes made by the last transaction |
void |
rollbackThreadTransaction()
Rollback per-thread transaction. |
java.lang.ClassLoader |
setClassLoader(java.lang.ClassLoader loader)
Set class loader. |
void |
setGcThreshold(long allocatedDelta)
Set threshold for initiation of garbage collection. |
StorageListener |
setListener(StorageListener listener)
Set storage listener. |
void |
setProperties(java.util.Properties props)
Set database properties. |
void |
setProperty(java.lang.String name,
java.lang.Object value)
Set database property. |
void |
setRoot(IPersistent root)
Set new storage root object. |
void |
storeFinalizedObject(IPersistent obj)
|
void |
storeObject(IPersistent obj)
|
void |
throwObject(IPersistent obj)
|
| Field Detail |
public static final int COOPERATIVE_TRANSACTION
public static final int DEFAULT_PAGE_POOL_SIZE
public static final int EXCLUSIVE_TRANSACTION
public static final int INFINITE_PAGE_POOL
public static final int REPLICATION_SLAVE_TRANSACTION
public static final int SERIALIZABLE_TRANSACTION
| Method Detail |
public void backup(java.io.OutputStream out)
throws java.io.IOException
out - output stream to which backup is done
java.io.IOExceptionpublic void beginThreadTransaction(int mode)
IPersistent.store() method in
serializable transactions. That is why it is also not possible to use Index and FieldIndex
containers (since them are based on B-Tree and B-Tree directly access database pages
and use store() method to assign OID to inserted object.
You should use SortedCollection based on T-Tree instead or alternative
B-Tree implemenataion (set "perst.alternative.btree" property).
mode - EXCLUSIVE_TRANSACTION, COOPERATIVE_TRANSACTION,
SERIALIZABLE_TRANSACTION or REPLICATION_SLAVE_TRANSACTIONpublic void close()
public void commit()
public BitIndex createBitIndex()
public Blob createBlob()
public FieldIndex createFieldIndex(java.lang.Class type,
java.lang.String[] fieldNames,
boolean unique)
type - objects of which type (or derived from which type) will be included in the indexfieldNames - names of the index fields. Fields with such name should be present in specified class typeunique - whether index is unique (duplicate value of keys are not allowed)
StorageError(StorageError.INDEXED_FIELD_NOT_FOUND) - if there is no such field in specified class,
public FieldIndex createFieldIndex(java.lang.Class type,
java.lang.String fieldName,
boolean unique)
type - objects of which type (or derived from which type) will be included in the indexfieldName - name of the index field. Field with such name should be present in specified class typeunique - whether index is unique (duplicate value of keys are not allowed)
StorageError(StorageError.INDEXED_FIELD_NOT_FOUND) - if there is no such field in specified class,
public Index createIndex(java.lang.Class[] types,
boolean unique)
types - types of the index compound key componentsunique - whether index is unique (duplicate value of keys are not allowed)
StorageError(StorageError.UNSUPPORTED_INDEX_TYPE) - exception if
specified key type is not supported by implementation.
public Index createIndex(java.lang.Class type,
boolean unique)
type - type of the index key (you should path here String.class,
int.class, ...)unique - whether index is unique (duplicate value of keys are not allowed)
StorageError(StorageError.UNSUPPORTED_INDEX_TYPE) - exception if
specified key type is not supported by implementation.public Link createLink()
public Link createLink(int initialSize)
initialSize - initial size of array
public PatriciaTrie createPatriciaTrie()
public Query createQuery()
public Relation createRelation(IPersistent owner)
owner - owner of the relation
public IPersistentSet createScalableSet()
public IPersistentSet createScalableSet(int initialSize)
initialSize - initial size of the set
public IPersistentSet createSet()
public SortedCollection createSortedCollection(boolean unique)
java.lang.Comparable interface and make it possible to compare collection members
with each other as well as with serch key.
unique - whether index is collection (members with the same key value are not allowed)
public SortedCollection createSortedCollection(PersistentComparator comparator,
boolean unique)
comparator - comparator class specifying order in the collectionunique - whether index is collection (members with the same key value are not allowed)
public SpatialIndex createSpatialIndex()
public SpatialIndexR2 createSpatialIndexR2()
public Index createThickIndex(java.lang.Class type)
type - type of the index key (you should path here String.class,
int.class, ...)
StorageError(StorageError.UNSUPPORTED_INDEX_TYPE) - exception if
specified key type is not supported by implementation.
public TimeSeries createTimeSeries(java.lang.Class blockClass,
long maxBlockTimeInterval)
blockClass - class derived from TimeSeries.BlockmaxBlockTimeInterval - maximal difference in milliseconds between timestamps
of the first and the last elements in a block.
If value of this parameter is too small, then most blocks will contains less elements
than preallocated.
If it is too large, then searching of block will be inefficient, because index search
will select a lot of extra blocks which do not contain any element from the
specified range.
Usually the value of this parameter should be set as
(number of elements in block)*(tick interval)*2.
Coefficient 2 here is used to compencate possible holes in time series.
For example, if we collect stocks data, we will have data only for working hours.
If number of element in block is 100, time series period is 1 day, then
value of maxBlockTimeInterval can be set as 100*(24*60*60*1000)*2
public void deallocateObject(IPersistent obj)
public void endThreadTransaction()
public void endThreadTransaction(int maxDelay)
maxDelay - maximal delay in milliseconds of committing transaction. Please notice, that Perst could
not force other threads to commit their cooperative transactions when this timeout is expired. It will only
block new cooperative transactions to make it possible to current transaction to complete their work.
If maxDelay is 0, current thread will be blocked until all other cooperative trasnaction are also finished
and changhes will be committed to the database.
public void exportXML(java.io.Writer writer)
throws java.io.IOException
writer - writer for generated XML document
java.io.IOExceptionpublic int gc()
public java.lang.ClassLoader getClassLoader()
setClassLoader
method or null if not specified.public long getDatabaseSize()
public java.util.HashMap getMemoryDump()
Storage class. Size of class descriptors - with java.lang.Class class.
This method traverse the storage as garbage collection do - starting from the root object and recursively visiting all reachable objects. So it reports statistic only for visible objects. If total database size is significantly larger than total size of all instances reported by this method, it means that there is garbage in the database. You can explicitly invoke garbage collector in this case.
public IPersistent getObjectByOID(int oid)
oid - object oid
public java.util.Properties getProperties()
public java.lang.Object getProperty(java.lang.String name)
name - property name
null if property was not setpublic IPersistent getRoot()
null if root is not specified (storage is not yet initialized)public long getUsedSize()
public void importXML(java.io.Reader reader)
throws XMLImportException
reader - XML document reader
XMLImportExceptionpublic boolean isOpened()
true if database was opened by open method,
false otherwisepublic java.util.Iterator join(java.util.Iterator[] selections)
selections - selections to be merged
public void loadObject(IPersistent obj)
public void lockObject(IPersistent obj)
public int makePersistent(IPersistent obj)
obj - object to be made persistent
public java.util.Iterator merge(java.util.Iterator[] selections)
selections - selections to be merged
public void modifyObject(IPersistent obj)
public void open(IFile file)
file - user specific implementation of IFile interface
public void open(IFile file,
int pagePoolSize)
file - user specific implementation of IFile interfacepagePoolSize - size of page pool (in bytes). Page pool should contain
at least ten 4kb pages, so minimal page pool size should be at least 40Kb.
But larger page pool ussually leads to better performance (unless it could not fit
in memory and cause swapping).public void open(java.lang.String filePath)
filePath - path to the database file
public void open(java.lang.String filePath,
int pagePoolSize)
filePath - path to the database filepagePoolSize - size of page pool (in bytes). Page pool should contain
at least ten 4kb pages, so minimal page pool size should be at least 40Kb.
But larger page pool usually leads to better performance (unless it could not fit
in memory and cause swapping). Value 0 of this paremeter corresponds to infinite
page pool (all pages are cashed in memory). It is especially useful for in-memory
database, when storage is created with NullFile.
public void open(java.lang.String filePath,
int pagePoolSize,
java.lang.String cipherKey)
filePath - path to the database filepagePoolSize - size of page pool (in bytes). Page pool should contain
at least ten 4kb pages, so minimal page pool size should be at least 40Kb.
But larger page pool ussually leads to better performance (unless it could not fit
in memory and cause swapping).cipherKey - cipher keypublic void rollback()
public void rollbackThreadTransaction()
public java.lang.ClassLoader setClassLoader(java.lang.ClassLoader loader)
Thread.getContextClassLoader().loadClass() method
will be used to get class for the specified name.
loader - class loader
public void setGcThreshold(long allocatedDelta)
allocatedDelta - delta between total size of allocated and deallocated object since last GC
or storage openingpublic StorageListener setListener(StorageListener listener)
listener - new storage listener (may be null)
public void setProperties(java.util.Properties props)
setProperty command.
All not recognized properties are ignored.
public void setProperty(java.lang.String name,
java.lang.Object value)
| Property name | Parameter type | Default value | Description |
|---|---|---|---|
perst.implicit.values | Boolean | false | Treate any class not derived from IPersistent as value.
This object will be embedded inside persistent object containing reference to this object.
If this object is referenced from N persistent object, N instances of this object
will be stored in the database and after loading there will be N instances in memory.
As well as persistent capable classes, value classes should have default constructor (constructor
with empty list of parameters) or has no constructors at all. For example Integer
class can not be stored as value in PERST because it has no such constructor. In this case
serialization mechanism can be used (see below)
|
perst.serialize.transient.objects | Boolean | false | Serialize any class not derived from IPersistent or IValue using standard Java serialization
mechanism. Packed object closure is stored in database as byte array. Latter the same mechanism is used
to unpack the objects. To be able to use this mechanism object and all objects referenced from it
should implement java.io.Serializable interface and should not contain references
to persistent objects. If such object is referenced from N persistent object, N instances of this object
will be stored in the database and after loading there will be N instances in memory.
|
perst.object.cache.kind | String | "lru" | Kind of object cache. The following values are supported:
"strong", "weak", "soft", "lru". String cache uses strong (normal)
references to refer persistent objects. Thus none of loaded persistent objects
can be deallocated by GC. Weak cache use weak references and
soft cache - soft references. The main difference between soft and weak references is
that garbage collector is not required to remove soft referenced objects immediately
when object is detected to be soft referenced, so it may improve caching of objects.
But it also may increase amount of memory
used by application, and as far as persistent object requires finalization
it can cause memory overflow even though garbage collector is required
to clear all soft references before throwing OutOfMemoryException. But Java specification says nothing about the policy used by GC for soft references (except the rule mentioned above). Unlike it lru cache provide determined behavior, pinning most recently used objects in memory. Number of pinned objects is determined for lru cache by perst.object.index.init.size parameter (it can be 0).
|
perst.object.cache.init.size | Integer | 1319 | Initial size of object cache |
perst.object.index.init.size | Integer | 1024 | Initial size of object index (specifying large value increase initial size of database, but reduce number of index reallocations) |
perst.extension.quantum | Long | 1048576 | Object allocation bitmap extension quantum. Memory is allocate by scanning bitmap. If there is no large enough hole, then database is extended by the value of dbDefaultExtensionQuantum. This parameter should not be smaller than 64Kb. |
perst.gc.threshold | Long | Long.MAX_VALUE | Threshold for initiation of garbage collection. If it is set to the value different from Long.MAX_VALUE, GC will be started each time when delta between total size of allocated and deallocated objects exceeds specified threashold OR after reaching end of allocation bitmap in allocator. |
perst.lock.file | Boolean | false | Lock database file to prevent concurrent access to the database by more than one application. |
perst.file.readonly | Boolean | false | Database file should be opened in read-only mode. |
perst.file.noflush | Boolean | false | Do not flush file during transaction commit. It will greatly increase performance because eliminate synchronous write to the disk (when program has to wait until all changed are actually written to the disk). But it can cause database corruption in case of OS or power failure (but abnormal termination of application itself should not cause the problem, because all data which were written to the file, but is not yet saved to the disk is stored in OS file buffers and sooner or later them will be written to the disk) |
perst.alternative.btree | Boolean | false | Use aternative implementation of B-Tree (not using direct access to database file pages). This implementation should be used in case of serialized per thread transctions. New implementation of B-Tree will be used instead of old implementation if "perst.alternative.btree" property is set. New B-Tree has incompatible format with old B-Tree, so you could not use old database or XML export file with new indices. Alternative B-Tree is needed to provide serializable transaction (old one could not be used). Also it provides better performance (about 3 times comaring with old implementation) because of object caching. And B-Tree supports keys of user defined types. |
perst.background.gc | Boolean | false | Perform garbage collection in separate thread without blocking the main application. |
perst.string.encoding | String | null | Specifies encoding of storing strings in the database. By default Perst stores strings as sequence of chars (two bytes per char). If all strings in application are in the same language, then using encoding can signifficantly reduce space needed to store string (about two times). But please notice, that this option has influence on all strings stored in database. So if you already have some data in the storage and then change encoding, then it can cause incorrect fetching of strings and even database crash. |
perst.replication.ack | Boolean | false | Request acknowledgement from slave that it receives all data before transaction commit. If this option is not set, then replication master node just writes data to the socket not warring whether it reaches slave node or not. When this option is set to true, master not will wait during each transaction commit acknowledgement from slave node. Please notice that this option should be either set or not set both at slave and master node. If it is set only on one of this nodes then behavior of the system is unpredicted. This option can be used both in synchronous and asynchronous replication mode. The only difference is that in first case main application thread will be blocked waiting for acknowledgment, while in the asynchronous mode special replication thread will be blocked allowing thread performing commit to proceed. |
perst.concurrent.iterator | Boolean | false | By default iterator will throw ConcurrentModificationException if iterated collection was changed outside iterator, when the value of this property is true then iterator will try to restore current position and continue iteration |
perst.slave.connection.timeout | Integer | 60 | Timeout in seconds during which mastr node will try to establish connection with slave node. If connection can not be established within specified time, then master will not perform replication to this slave node |
perst.force.store | Boolean | true | When the value of this parameter is true Storage.makePersistent method cause immediate storing of object in the storage, otherwise object is assigned OID and is marked as modified. Storage.makePersistent method is mostly used when object is inserted in B-Tree. If application put in index object referencing a large number of other objects which also has to be made persistent, then marking object as modified instead of immediate storing may cause memory overflow because garbage collector and finalization threads will store objects with less speed than application creates new ones. But if object will be updated after been placed in B-Tree, then immediate store will just cause cause extra overhead, because object has to be stored twice. |
name - name of the propertyvalue - value of the property (for boolean properties pass java.lang.Boolean.TRUE
and java.lang.Boolean.FALSEpublic void setRoot(IPersistent root)
root - object to become new storage root. If it is not persistent yet, it is made
persistent and stored in the storagepublic void storeFinalizedObject(IPersistent obj)
public void storeObject(IPersistent obj)
public void throwObject(IPersistent obj)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||