com.syncbuilder.storage
Class DatabaseBase

java.lang.Object
  |
  +--com.syncbuilder.storage.DatabaseBase
Direct Known Subclasses:
DeviceDatabase, MemoryDatabase

public abstract class DatabaseBase
extends java.lang.Object
implements Database

A foundation for all implementations of databases.

DatabaseBase is assisted by DatabaseImpl, which provides the neccessary knowledge to treat databases from different applications properly. This is a delegation-/bridge pattern.

See Also:
DatabaseImpl, DeviceDatabase, MemoryDatabase, Database

Field Summary
protected  Char4 _creator
           
protected  DatabaseImpl _dbimpl
           
protected  int _dbmode
           
protected  java.lang.String _dbname
           
 
Constructor Summary
DatabaseBase()
           
 
Method Summary
abstract  void close()
          Closes the database.
 AppBlock createAppBlock()
           
 Pref createPref(int id)
           
 Pref createPref(int id, int version, boolean backed_up)
           
 Record createRecord()
          Create a new Record with an unspecified RecordID (0).
 Record createRecord(byte[] contents, RecordID id, int index, int attr, int cat)
          Create a new Record with the specified RecordID, index, attributes, and category.
 Record createRecord(RecordID id)
          Create a new Record with the specified RecordID.
 Resource createResource()
           
 Resource createResource(byte[] contents, Char4 type, int id, int index)
           
 Resource createResource(Char4 type, int id)
           
 SortBlock createSortBlock()
           
abstract  void deleteAllRecords()
          Delete ALL records in the database.
abstract  void deleteAllResources()
          Delete ALL resources.
abstract  void deleteCategory(int category)
          Delete all records from a specified category
abstract  void deleteRecord(RecordID uid)
          Delete the record with the specified UID from the database.
abstract  void deleteResource(Char4 type, int id)
           
protected  void finalize()
           
abstract  AppBlock getAppBlock()
           
abstract  DBInfo getDBInfo()
          Return meta-information about the Database Caution!
abstract  Record getNextModifiedRecord()
           
abstract  Record getNextModifiedRecord(int category)
           
abstract  Record getNextRecord(int category)
           
 Pref getPref(int id)
           
abstract  Pref getPref(int id, boolean backed_up)
          Get one of the preferences which are associated with the same app as the database.
abstract  Record getRecord(int index)
           
abstract  Record getRecord(RecordID uid)
           
abstract  int getRecordCount()
          Return the number of records in the Database
 RecordID[] getRecordIDs()
          Return the UIDs of all records in the DB, in an unsorted fashion.
 RecordID[] getRecordIDs(boolean sort)
          Return the UIDs of all records in the DB.
 RecordID[] getRecordIDs(boolean sort, int start)
          Return the UIDs of selected records in the DB.
abstract  RecordID[] getRecordIDs(boolean sort, int start, int max)
          Return the UIDs of selected records in the DB.
abstract  Resource getResource(Char4 type, int id)
           
abstract  Resource getResource(int index)
           
abstract  SortBlock getSortBlock()
           
abstract  void moveCategory(int from, int to)
           
abstract  void moveRecord(int from, int to)
          Move a record from one position to another.
abstract  void purgeRecords()
          Deletes all records which are marked as archived or deleted
abstract  void putRecord(Record record)
          Writes a record to the database.
abstract  void putResource(Resource resource)
           
abstract  void resetFlags()
          For record databases, reset all dirty flags.
abstract  void resetNext()
          Resets the "next record" index to the beginning
abstract  void setAppBlock(AppBlock appblock)
           
abstract  void setPref(Pref pref)
          Store a Pref which is associated with the same app as the database to the database.
abstract  void setSortBlock(SortBlock sortblock)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_dbimpl

protected DatabaseImpl _dbimpl

_creator

protected Char4 _creator

_dbname

protected java.lang.String _dbname

_dbmode

protected int _dbmode
Constructor Detail

DatabaseBase

public DatabaseBase()
Method Detail

getAppBlock

public abstract AppBlock getAppBlock()
                              throws DatabaseException
Specified by:
getAppBlock in interface Database

setAppBlock

public abstract void setAppBlock(AppBlock appblock)
                          throws DatabaseException
Specified by:
setAppBlock in interface Database

createAppBlock

public AppBlock createAppBlock()
Specified by:
createAppBlock in interface Database

getSortBlock

public abstract SortBlock getSortBlock()
                                throws DatabaseException
Specified by:
getSortBlock in interface Database

setSortBlock

public abstract void setSortBlock(SortBlock sortblock)
                           throws DatabaseException
Specified by:
setSortBlock in interface Database

createSortBlock

public SortBlock createSortBlock()
Specified by:
createSortBlock in interface Database

getRecord

public abstract Record getRecord(int index)
                          throws DatabaseException
Specified by:
getRecord in interface Database

getRecord

public abstract Record getRecord(RecordID uid)
                          throws DatabaseException
Specified by:
getRecord in interface Database

getNextRecord

public abstract Record getNextRecord(int category)
                              throws DatabaseException
Specified by:
getNextRecord in interface Database

getNextModifiedRecord

public abstract Record getNextModifiedRecord()
                                      throws DatabaseException
Specified by:
getNextModifiedRecord in interface Database

getNextModifiedRecord

public abstract Record getNextModifiedRecord(int category)
                                      throws DatabaseException
Specified by:
getNextModifiedRecord in interface Database

resetNext

public abstract void resetNext()
                        throws DatabaseException
Resets the "next record" index to the beginning
Specified by:
resetNext in interface Database

putRecord

public abstract void putRecord(Record record)
                        throws DatabaseException
Writes a record to the database. If the Record had an unspecified RecordID (0) before it will be assigned a valid RecordID.
Specified by:
putRecord in interface Database

createRecord

public Record createRecord()
Create a new Record with an unspecified RecordID (0).
Specified by:
createRecord in interface Database

createRecord

public Record createRecord(RecordID id)
Create a new Record with the specified RecordID.
Specified by:
createRecord in interface Database

createRecord

public Record createRecord(byte[] contents,
                           RecordID id,
                           int index,
                           int attr,
                           int cat)
Create a new Record with the specified RecordID, index, attributes, and category.
Specified by:
createRecord in interface Database

deleteRecord

public abstract void deleteRecord(RecordID uid)
                           throws DatabaseException
Delete the record with the specified UID from the database.
Specified by:
deleteRecord in interface Database
Parameters:
uid - the UID (not the index!) of the record

deleteAllRecords

public abstract void deleteAllRecords()
                               throws DatabaseException
Delete ALL records in the database.
Use with caution!
Specified by:
deleteAllRecords in interface Database

deleteCategory

public abstract void deleteCategory(int category)
                             throws DatabaseException
Delete all records from a specified category
Specified by:
deleteCategory in interface Database
Parameters:
category - the category

moveCategory

public abstract void moveCategory(int from,
                                  int to)
                           throws DatabaseException
Specified by:
moveCategory in interface Database

getRecordIDs

public RecordID[] getRecordIDs()
                        throws DatabaseException
Return the UIDs of all records in the DB, in an unsorted fashion.
Specified by:
getRecordIDs in interface Database

getRecordIDs

public RecordID[] getRecordIDs(boolean sort)
                        throws DatabaseException
Return the UIDs of all records in the DB. If you ask for a sorted list of UIDs, then the application on the Palm device will be asked to sort the records before their UIDs are returned.
Specified by:
getRecordIDs in interface Database

getRecordIDs

public RecordID[] getRecordIDs(boolean sort,
                               int start)
                        throws DatabaseException
Return the UIDs of selected records in the DB. If you ask for a sorted list of UIDs, then the application on the Palm device will be asked to sort the records before their UIDs are returned.
Specified by:
getRecordIDs in interface Database

getRecordIDs

public abstract RecordID[] getRecordIDs(boolean sort,
                                        int start,
                                        int max)
                                 throws DatabaseException
Return the UIDs of selected records in the DB. If you ask for a sorted list of UIDs, then the application on the Palm device will be asked to sort the records before their UIDs are returned.
Specified by:
getRecordIDs in interface Database

purgeRecords

public abstract void purgeRecords()
                           throws DatabaseException
Deletes all records which are marked as archived or deleted
Specified by:
purgeRecords in interface Database

moveRecord

public abstract void moveRecord(int from,
                                int to)
                         throws DatabaseException
Move a record from one position to another.

Caution: The DL protocol has no official means to accomplish this! This method therefore uses some undocumented magic (RPC), which is broken when being used with Network HotSync, and may be even more broken with future devices!!!


createResource

public Resource createResource()
Specified by:
createResource in interface Database

createResource

public Resource createResource(Char4 type,
                               int id)
Specified by:
createResource in interface Database

createResource

public Resource createResource(byte[] contents,
                               Char4 type,
                               int id,
                               int index)
Specified by:
createResource in interface Database

getResource

public abstract Resource getResource(int index)
                              throws DatabaseException
Specified by:
getResource in interface Database

getResource

public abstract Resource getResource(Char4 type,
                                     int id)
                              throws DatabaseException
Specified by:
getResource in interface Database

putResource

public abstract void putResource(Resource resource)
                          throws DatabaseException
Specified by:
putResource in interface Database

deleteResource

public abstract void deleteResource(Char4 type,
                                    int id)
                             throws DatabaseException
Specified by:
deleteResource in interface Database

deleteAllResources

public abstract void deleteAllResources()
                                 throws DatabaseException
Delete ALL resources.
Use with caution!
Specified by:
deleteAllResources in interface Database

getPref

public Pref getPref(int id)
             throws DatabaseException,
                    NoCreatorException
Specified by:
getPref in interface Database

getPref

public abstract Pref getPref(int id,
                             boolean backed_up)
                      throws DatabaseException,
                             NoCreatorException
Get one of the preferences which are associated with the same app as the database.
Specified by:
getPref in interface Database

setPref

public abstract void setPref(Pref pref)
                      throws DatabaseException
Store a Pref which is associated with the same app as the database to the database. Since the Creator ID is taken from the Pref object and not from the database object, this method will also happily write preferences which belong to a different application.
Specified by:
setPref in interface Database

createPref

public Pref createPref(int id)
Specified by:
createPref in interface Database

createPref

public Pref createPref(int id,
                       int version,
                       boolean backed_up)
Specified by:
createPref in interface Database

close

public abstract void close()
                    throws DatabaseException
Closes the database. The Database-object shall no longer be used after the invocation of this method!
Specified by:
close in interface Database

resetFlags

public abstract void resetFlags()
                         throws DatabaseException
For record databases, reset all dirty flags. For both record and resource databases, set the last sync time to now.
Specified by:
resetFlags in interface Database

getRecordCount

public abstract int getRecordCount()
                            throws DatabaseException
Return the number of records in the Database
Specified by:
getRecordCount in interface Database

getDBInfo

public abstract DBInfo getDBInfo()
                          throws DatabaseException
Return meta-information about the Database Caution! This is an expensive operation on devices which are running Palm OS below version 3.0.
Specified by:
getDBInfo in interface Database

finalize

protected void finalize()
                 throws DatabaseException
Overrides:
finalize in class java.lang.Object


This material is Copyrighted (C) 1999 by Tilo Christ. All Rights Reserved.