jnicli
Interface Database

All Known Implementing Classes:
DatabaseJNI, DatabaseSessionClient

public interface Database

This class is used as interface to local or remote database (through RMI). In case of local connections you should create instance of DatabaseJNI class directly. In case of remote connection, it is necessary to create instance of DatabaseSessionClient class and path reference to the stub object implementing DatabaseSession interface.

Methods of this interface are mostly one-to-one mapped to methods of C++ dbDatabase class. In case of remote application, it should either open or create new database at server using Database.open method, either attach to the existing database using Database.attach method. In case of local application, Database.attach should be used by all application threads except one opened the database.

All database access errors are reported by means of CliException. In case of remote database there are also can be exceptions related with server communication.


Field Summary
static int AUTOCOMMIT
          Select flag AUTOCOMMIT: automatically commit current transaction after completion of selection
static int CLI_DETACH_COMMIT
           
static int CLI_DETACH_DEFAULT
           
static int CLI_DETACH_DESTROY_CONTEXT
           
static int CONCURRENT_READ
           
static int CONCURRENT_UPDATE
           
static int FOR_UPDATE
          Select flag FOR_UPDATE: make it possible to update selected records
static int READ_ONLY
           
static int READ_WRITE
           
 
Method Summary
 void attach()
          Attach thread to the database.
 void close()
          Close database
 void commit()
          Commit current transaction.
 int delete(java.lang.Class table, java.lang.String condition)
          Delete all objects from the table matching specified condition
 void detach(int flags)
          Detach thread to the database.
 long insert(java.lang.Object obj)
          Insert new object in the database.
 void lock()
          Lock database in exclusive mode.
 void open(int accessType, java.lang.String databaseName, java.lang.String databasePath, long initSize, int transactionCommitDelay)
          Open database
 void rollback()
          Commit current transaction Transaction is implicitly started when any database operation is perfromed.
 Cursor select(java.lang.Class table, java.lang.String condition, int flags)
          Select objects from table matching condition
 void update(long oid, java.lang.Object obj)
          Update object with soecified OID
 

Field Detail

READ_ONLY

public static final int READ_ONLY
See Also:
Constant Field Values

READ_WRITE

public static final int READ_WRITE
See Also:
Constant Field Values

CONCURRENT_READ

public static final int CONCURRENT_READ
See Also:
Constant Field Values

CONCURRENT_UPDATE

public static final int CONCURRENT_UPDATE
See Also:
Constant Field Values

FOR_UPDATE

public static final int FOR_UPDATE
Select flag FOR_UPDATE: make it possible to update selected records

See Also:
Constant Field Values

AUTOCOMMIT

public static final int AUTOCOMMIT
Select flag AUTOCOMMIT: automatically commit current transaction after completion of selection

See Also:
Constant Field Values

CLI_DETACH_COMMIT

public static final int CLI_DETACH_COMMIT
See Also:
Constant Field Values

CLI_DETACH_DESTROY_CONTEXT

public static final int CLI_DETACH_DESTROY_CONTEXT
See Also:
Constant Field Values

CLI_DETACH_DEFAULT

public static final int CLI_DETACH_DEFAULT
See Also:
Constant Field Values
Method Detail

open

public void open(int accessType,
                 java.lang.String databaseName,
                 java.lang.String databasePath,
                 long initSize,
                 int transactionCommitDelay)
Open database

Parameters:
accessType - database access type: one of READ_ONLY, READ_WRITE, CONCURRENT_READ or CONCURRENT_UPDATE
databaseName - database name
databasePath - path to the database file
initSize - initial size of database
transactionCommitDelay - transaction commit delay (specify 0 to disable)

close

public void close()
Close database


select

public Cursor select(java.lang.Class table,
                     java.lang.String condition,
                     int flags)
Select objects from table matching condition

Parameters:
table - class corresponding to the table
condition - SubSQL condition (to select all records pass empty string)
flags - combination of FOR_UPDATE and AUTOCOMMIT flags
Returns:
cursor for selected objects. Cursor can be either incremental, when records are extracted on demand or prefetched. Prefetched cursor is used for remote database and when AUTOCOMMIT flag is set. Prefetched cursor doesn't allow in place updates.

update

public void update(long oid,
                   java.lang.Object obj)
Update object with soecified OID

Parameters:
oid - OID of updated object
obj - updated object

insert

public long insert(java.lang.Object obj)
Insert new object in the database. Object will be inserted in the table with the same name as object class

Parameters:
obj - inserted object
Returns:
OID of inserted object

delete

public int delete(java.lang.Class table,
                  java.lang.String condition)
Delete all objects from the table matching specified condition

Parameters:
table - class corresponding to the table
condition - SubSQL condition (to delete all records pass empty string)
Returns:
number of deleted objects

commit

public void commit()
Commit current transaction. Transaction is implicitly started when any database operation is perfromed.


rollback

public void rollback()
Commit current transaction Transaction is implicitly started when any database operation is perfromed.


lock

public void lock()
Lock database in exclusive mode. Lock is automatically released when transaction is committed or aborted


attach

public void attach()
Attach thread to the database. All threads except the one opened the database should invoke this method before start working with database


detach

public void detach(int flags)
Detach thread to the database. All threads except the one opened the database should invoke this method before start working with database

Parameters:
flags - combination of CLI_DETACH_COMMIT and CLI_DETACH_DESTROY_CONTEXT flags