|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.garret.perst.Database
This class emulates relational database on top of Perst storage It maintain class extends, associated indices, prepare queries.
| Constructor Summary | |
Database(Storage storage)
Constructor of database. |
|
| Method Summary | |
boolean |
addRecord(java.lang.Class table,
IPersistent record)
Add new record to the specified table. |
boolean |
addRecord(IPersistent record)
Add new record to the table. |
boolean |
createIndex(java.lang.Class table,
java.lang.String key,
boolean unique)
Add new index to the table. |
boolean |
createTable(java.lang.Class table)
Create table for the specified class. |
boolean |
deleteRecord(java.lang.Class table,
IPersistent record)
Delete record from the specified table. |
boolean |
deleteRecord(IPersistent record)
Delete record from the table. |
boolean |
dropIndex(java.lang.Class table,
java.lang.String key)
Drop index for the specified table and key. |
boolean |
dropTable(java.lang.Class table)
Drop table associated with this class. |
boolean |
excludeFromIndex(java.lang.Class table,
IPersistent record,
java.lang.String key)
Exclude record from specified index. |
boolean |
excludeFromIndex(IPersistent record,
java.lang.String key)
Exclude record from specified index. |
java.util.Iterator |
getRecords(java.lang.Class table)
Get iterator through all table records |
Storage |
getStorage()
Get storage associated with this database |
boolean |
includeInIndex(java.lang.Class table,
IPersistent record,
java.lang.String key)
Include record in the specified index. |
boolean |
includeInIndex(IPersistent record,
java.lang.String key)
Include record in the specified index. |
Query |
prepare(java.lang.Class table,
java.lang.String predicate)
Prepare JSQL query. |
java.util.Iterator |
select(java.lang.Class table,
java.lang.String predicate)
Select record from specified table |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Database(Storage storage)
storage - opened storage. Storage should be either empty (non-initialized, either
previously initialized by the this method. It is not possible to open storage with
root object other than table index created by this constructor.| Method Detail |
public boolean addRecord(java.lang.Class table,
IPersistent record)
table - class corresponding to the tablerecord - object to be inserted in the table
true if record was successfully added to the table, false
if there is already such record (object with the same ID) in the table
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
record classpublic boolean addRecord(IPersistent record)
record - object to be inserted in the table
true if record was successfully added to the table, false
if there is already such record (object with the same ID) in the table
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
record class
public boolean createIndex(java.lang.Class table,
java.lang.String key,
boolean unique)
table - class corresponding to the tablekey - field of the class to be indexedunique - if index is unique or not
true if index is created, false if index
already exists
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
the specified classpublic boolean createTable(java.lang.Class table)
table - class corresponding to the table
true if table is created, false if table
alreay exists
public boolean deleteRecord(java.lang.Class table,
IPersistent record)
table - class corresponding to the tablerecord - object to be deleted from the table
true if record was successfully deleted from the table, false
if there is not such record (object with the same ID) in the table
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
specified classpublic boolean deleteRecord(IPersistent record)
record - object to be deleted from the table
true if record was successfully deleted from the table, false
if there is not such record (object with the same ID) in the table
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
record class
public boolean dropIndex(java.lang.Class table,
java.lang.String key)
table - class corresponding to the tablekey - field of the class to be indexed
true if index is deleted, false if index
is not found
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
the specified classpublic boolean dropTable(java.lang.Class table)
table - class corresponding to the table
true if table is deleted, false if table
is not found
public boolean excludeFromIndex(java.lang.Class table,
IPersistent record,
java.lang.String key)
If there is not table associated with class of this object, then database will search for table associated with superclass and so on...
This method does nothing if there is no index for the specified field.
table - class corresponding to the tablerecord - object to be excluded from the specified indexkey - name of the indexed field
true if record is excluded from index, false if
there is no such index
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
the specified class
public boolean excludeFromIndex(IPersistent record,
java.lang.String key)
If there is not table associated with class of this object, then database will search for table associated with superclass and so on...
This method does nothing if there is no index for the specified field.
record - object to be excluded from the specified indexkey - name of the indexed field
true if record is excluded from index, false if
there is no such index
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
record classpublic java.util.Iterator getRecords(java.lang.Class table)
table - class corresponding to the table
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
the specified classpublic Storage getStorage()
public boolean includeInIndex(java.lang.Class table,
IPersistent record,
java.lang.String key)
If there is not table associated with class of this object, then database will search for table associated with superclass and so on...
This method does nothing if there is no index for the specified field.
table - class corresponding to the tablerecord - object to be excluded from the specified indexkey - name of the indexed field
true if record is included in index, false if
there is no such index
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
the specified class
public boolean includeInIndex(IPersistent record,
java.lang.String key)
If there is not table associated with class of this object, then database will search for table associated with superclass and so on...
This method does nothing if there is no index for the specified field.
record - object to be excluded from the specified indexkey - name of the indexed field
true if record is included in index, false if
there is no such index
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
the specified class
public Query prepare(java.lang.Class table,
java.lang.String predicate)
To execute prepared query, you should use Query.execute(db.getRecords(XYZ.class)) method
table - class corresponding to the tablepredicate - search predicate
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
the specified class
CompileError - exception is thrown if predicate is not valid JSQL exception
public java.util.Iterator select(java.lang.Class table,
java.lang.String predicate)
table - class corresponding to the tablepredicate - search predicate
StorageError(CLASS_NOT_FOUND) - exception is thrown if there is no table corresponding to
the specified class
CompileError - exception is thrown if predicate is not valid JSQL exception
JSQLRuntimeException - exception is thrown if there is runtime error during query execution
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||