Java Doc for Database.java in  » Database-DBMS » perst » org » garret » perst » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » perst » org.garret.perst 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.garret.perst.Database

Database
public class Database (Code)
This class emulates relational database on top of Perst storage It maintain class extends, associated indices, prepare queries.

Inner Class :static class Table extends Persistent

Field Summary
 booleanautoRegisterTables
    
 Indexmetadata
    
 booleanmultithreaded
    
 Storagestorage
    
 HashMaptables
    

Constructor Summary
public  Database(Storage storage, boolean multithreaded)
     Constructor of database.
public  Database(Storage storage, boolean multithreaded, boolean autoRegisterTables)
     Constructor of database.
public  Database(Storage storage)
     Constructor of single threaded database.

Method Summary
public  booleanaddRecord(T record)
     Add new record to the table.
public  booleanaddRecord(Class table, T record)
     Add new record to the specified table.
public  voidbeginTransaction()
    
public  voidcommitTransaction()
    
public  booleancreateIndex(Class table, String key, boolean unique)
     Add new index to the table.
public  booleancreateIndex(Class table, String key, boolean unique, boolean caseInsensitive)
     Add new index to the table.
public  booleancreateTable(Class table)
     Create table for the specified class.
public  booleandeleteRecord(T record)
     Delete record from the table.
public  booleandeleteRecord(Class table, T record)
     Delete record from the specified table.
public  booleandropIndex(Class table, String key)
     Drop index for the specified table and key.
public  booleandropTable(Class table)
     Drop table associated with this class.
public  booleanexcludeFromIndex(IPersistent record, String key)
     Exclude record from specified index.
public  booleanexcludeFromIndex(Class table, IPersistent record, String key)
     Exclude record from specified index.
public  HashMapgetIndices(Class table)
    
public  IterableIterator<T>getRecords(Class table)
    
public  IterableIterator<T>getRecords(Class table, boolean forUpdate)
     Get iterator through all table records
Parameters:
  table - class corresponding to the table
Parameters:
  forUpdate - true if records are selected for update - in this case exclusive lock is set for the table to avoid deadlock.
public  StoragegetStorage()
    
public  booleanincludeInIndex(IPersistent record, String key)
     Include record in the specified index.
public  booleanincludeInIndex(Class table, IPersistent record, String key)
     Include record in the specified index.
public  Query<T>prepare(Class table, String predicate)
     Prepare JSQL query.
public  Query<T>prepare(Class table, String predicate, boolean forUpdate)
     Prepare JSQL query.
public  voidrollbackTransaction()
    
public  IterableIterator<T>select(Class table, String predicate)
     Select record from specified table
Parameters:
  table - class corresponding to the table
Parameters:
  predicate - search predicate
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class iterator through selected records.
public  IterableIterator<T>select(Class table, String predicate, boolean forUpdate)
     Select record from specified table
Parameters:
  table - class corresponding to the table
Parameters:
  predicate - search predicate
Parameters:
  forUpdate - true if records are selected for update - in this case exclusive lock is set for the table to avoid deadlock.
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class iterator through selected records.

Field Detail
autoRegisterTables
boolean autoRegisterTables(Code)



metadata
Index metadata(Code)



multithreaded
boolean multithreaded(Code)



storage
Storage storage(Code)



tables
HashMap tables(Code)




Constructor Detail
Database
public Database(Storage storage, boolean multithreaded)(Code)
Constructor of database. This method initialize database if it not initialized yet. Starting from 2.72 version of Perst.Net, it supports automatic creation of table descriptors when Database class is used. So now it is not necessary to explicitly create tables and indices - the Database class will create them itself on demand. Indexable attribute should be used to mark key fields for which index should be created. Table descriptor is created when instance of the correspondent class is first time stored in the database. Perst creates table descriptors for all derived classes up to the root java.lang.Object class.
Parameters:
  storage - opened storage. Storage should be either empty (non-initialized, eitherpreviously initialized by the this method. It is not possible to open storage with root object other than table index created by this constructor.
Parameters:
  multithreaded - true if database should support concurrent accessto the data from multiple threads.



Database
public Database(Storage storage, boolean multithreaded, boolean autoRegisterTables)(Code)
Constructor of database. This method initialize database if it not initialized yet.
Parameters:
  storage - opened storage. Storage should be either empty (non-initialized, eitherpreviously initialized by the this method. It is not possible to open storage with root object other than table index created by this constructor.
Parameters:
  multithreaded - true if database should support concurrent accessto the data from multiple threads.
Parameters:
  autoRegisterTables - automatically create tables descriptors for instances of new classes inserted in the database



Database
public Database(Storage storage)(Code)
Constructor of single threaded database. This method initialize database if it not initialized yet.
Parameters:
  storage - opened storage. Storage should be either empty (non-initialized, eitherpreviously 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
addRecord
public boolean addRecord(T record)(Code)
Add new record to the table. Record is inserted in table corresponding to the class of the object. Record will be automatically added to all indices existed for this table. If there is not table associated with class of this object, then database will search for table associated with superclass and so on...
Parameters:
  record - object to be inserted in the table true if record was successfully added to the table, falseif there is already such record (object with the same ID) in the table or there is some record with the same value of unique key field
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to record class



addRecord
public boolean addRecord(Class table, T record)(Code)
Add new record to the specified table. Record is inserted in table corresponding to the specified class. Record will be automatically added to all indices existed for this table.
Parameters:
  table - class corresponding to the table
Parameters:
  record - object to be inserted in the table true if record was successfully added to the table, falseif there is already such record (object with the same ID) in the table or there is some record with the same value of unique key field
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to record class



beginTransaction
public void beginTransaction()(Code)
Begin transaction



commitTransaction
public void commitTransaction()(Code)
Commit transaction



createIndex
public boolean createIndex(Class table, String key, boolean unique)(Code)
Add new index to the table. If such index already exists this method does nothing.
Parameters:
  table - class corresponding to the table
Parameters:
  key - field of the class to be indexed
Parameters:
  unique - if index is unique or not
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class true if index is created, false if indexalready exists



createIndex
public boolean createIndex(Class table, String key, boolean unique, boolean caseInsensitive)(Code)
Add new index to the table. If such index already exists this method does nothing.
Parameters:
  table - class corresponding to the table
Parameters:
  key - field of the class to be indexed
Parameters:
  unique - if index is unique or not
Parameters:
  caseInsensitive - if string index is case insensitive
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class true if index is created, false if indexalready exists



createTable
public boolean createTable(Class table)(Code)
Create table for the specified class. This function does nothing if table for such class already exists
Parameters:
  table - class corresponding to the table true if table is created, false if table alreay exists



deleteRecord
public boolean deleteRecord(T record)(Code)
Delete record from the table. Record is removed from the table corresponding to the class of the object. Record will be automatically added to all indices existed for this table. If there is not table associated with class of this object, then database will search for table associated with superclass and so on... Object represented the record will be also deleted from the storage.
Parameters:
  record - object to be deleted from the table true if record was successfully deleted from the table, falseif there is not such record (object with the same ID) in the table
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to record class



deleteRecord
public boolean deleteRecord(Class table, T record)(Code)
Delete record from the specified table. Record is removed from the table corresponding to the specified class. Record will be automatically added to all indices existed for this table. Object represented the record will be also deleted from the storage.
Parameters:
  table - class corresponding to the table
Parameters:
  record - object to be deleted from the table true if record was successfully deleted from the table, falseif there is not such record (object with the same ID) in the table
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to specified class



dropIndex
public boolean dropIndex(Class table, String key)(Code)
Drop index for the specified table and key. Does nothing if there is no such index.
Parameters:
  table - class corresponding to the table
Parameters:
  key - field of the class to be indexed
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class true if index is deleted, false if index is not found



dropTable
public boolean dropTable(Class table)(Code)
Drop table associated with this class. Do nothing if there is no such table in the database.
Parameters:
  table - class corresponding to the table true if table is deleted, false if table is not found



excludeFromIndex
public boolean excludeFromIndex(IPersistent record, String key)(Code)
Exclude record from specified index. This method is needed to perform update of indexed field (key). Before updating the record, it is necessary to exclude it from indices which keys are affected. After updating the field, record should be reinserted in these indices using includeInIndex method.

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.
Parameters:
  record - object to be excluded from the specified index
Parameters:
  key - name of the indexed field
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to record class true if record is excluded from index, false if there is no such index




excludeFromIndex
public boolean excludeFromIndex(Class table, IPersistent record, String key)(Code)
Exclude record from specified index. This method is needed to perform update of indexed field (key). Before updating the record, it is necessary to exclude it from indices which keys are affected. After updating the field, record should be reinserted in these indices using includeInIndex method.

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.
Parameters:
  table - class corresponding to the table
Parameters:
  record - object to be excluded from the specified index
Parameters:
  key - name of the indexed field
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class true if record is excluded from index, false if there is no such index




getIndices
public HashMap getIndices(Class table)(Code)
Get indices for the specified table
Parameters:
  table - class corresponding to the table map of table indices



getRecords
public IterableIterator<T> getRecords(Class table)(Code)
Get iterator through all table records
Parameters:
  table - class corresponding to the table iterator through all table records.
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class



getRecords
public IterableIterator<T> getRecords(Class table, boolean forUpdate)(Code)
Get iterator through all table records
Parameters:
  table - class corresponding to the table
Parameters:
  forUpdate - true if records are selected for update - in this case exclusive lock is set for the table to avoid deadlock. iterator through all table records.
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class



getStorage
public Storage getStorage()(Code)
Get storage associated with this database underlying storage



includeInIndex
public boolean includeInIndex(IPersistent record, String key)(Code)
Include record in the specified index. This method is needed to perform update of indexed field (key). Before updating the record, it is necessary to exclude it from indices which keys are affected using excludeFromIndex method. After updating the field, record should be reinserted in these indices using this method.

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.
Parameters:
  record - object to be excluded from the specified index
Parameters:
  key - name of the indexed field
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class true if record is included in index, false if there is no such index




includeInIndex
public boolean includeInIndex(Class table, IPersistent record, String key)(Code)
Include record in the specified index. This method is needed to perform update of indexed field (key). Before updating the record, it is necessary to exclude it from indices which keys are affected using excludeFromIndex method. After updating the field, record should be reinserted in these indices using this method.

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.
Parameters:
  table - class corresponding to the table
Parameters:
  record - object to be excluded from the specified index
Parameters:
  key - name of the indexed field
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class true if record is included in index, false if there is no such index




prepare
public Query<T> prepare(Class table, String predicate)(Code)
Prepare JSQL query. Prepare is needed for queries with parameters. Also preparing query can improve speed if query will be executed multiple times (using prepare, it is compiled only once).

To execute prepared query, you should use Query.execute(db.getRecords(XYZ.class)) method
Parameters:
  table - class corresponding to the table
Parameters:
  predicate - search predicate
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class
exception:
  CompileError - exception is thrown if predicate is not valid JSQL exception




prepare
public Query<T> prepare(Class table, String predicate, boolean forUpdate)(Code)
Prepare JSQL query. Prepare is needed for queries with parameters. Also preparing query can improve speed if query will be executed multiple times (using prepare, it is compiled only once).

To execute prepared query, you should use Query.execute(db.getRecords(XYZ.class)) method
Parameters:
  table - class corresponding to the table
Parameters:
  predicate - search predicate
Parameters:
  forUpdate - true if records are selected for update - in this case exclusive lock is set for the table to avoid deadlock.
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class
exception:
  CompileError - exception is thrown if predicate is not valid JSQL exception




rollbackTransaction
public void rollbackTransaction()(Code)
Rollback transaction



select
public IterableIterator<T> select(Class table, String predicate)(Code)
Select record from specified table
Parameters:
  table - class corresponding to the table
Parameters:
  predicate - search predicate
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class iterator through selected records. This iterator doesn't support remove() method
exception:
  CompileError - exception is thrown if predicate is not valid JSQL exception
exception:
  JSQLRuntimeException - exception is thrown if there is runtime error during query execution



select
public IterableIterator<T> select(Class table, String predicate, boolean forUpdate)(Code)
Select record from specified table
Parameters:
  table - class corresponding to the table
Parameters:
  predicate - search predicate
Parameters:
  forUpdate - true if records are selected for update - in this case exclusive lock is set for the table to avoid deadlock.
exception:
  StorageError - (CLASS_NOT_FOUND) exception is thrown if there is no table corresponding to the specified class iterator through selected records. This iterator doesn't support remove() method
exception:
  CompileError - exception is thrown if predicate is not valid JSQL exception
exception:
  JSQLRuntimeException - exception is thrown if there is runtime error during query execution



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.