Contents Index Changing the encryption key for a database Adding synchronization to your application

UltraLite Static Java User's Guide
  Adding Non Data Access Features to UltraLite Applications
    Configuring and managing database storage

Defragmenting UltraLite databases


The UltraLite store is designed to efficiently reuse free space, so explicit defragmentation is not required under normal circumstances. This section describes a technique to explicitly defragment UltraLite databases, for use by applications with extremely strict space requirements.

UltraLite provides a defragmentation step function, which defragments a small part of the database. To defragment the entire database at once, call the defragmentation step function in a loop until it returns ul_true. This can be an expensive operation, and SQLCODE must also be checked to detect errors (an error here usually indicates a file I/O error).

Explicit defragmentation occurs incrementally under application control during idle time. Each step is a small operation.

For more information, see Class JdbcDefragIterator.

To defragment an UltraLite database

  1. Cast a Connection to a JdbcConnection object. For example,

    ...
    Connection conn = db.connect();
    JdbcConnection jconn = (JdbcConnection)conn ;

    UltraLite provides a defragmentation step function, which defragments a small part of the database. To defragment the entire database at once, call the defragmentation step function in a loop until it returns ul_true. This can be an expensive operation, and SQLCODE must also be checked to detect errors (an error here usually indicates a file I/O error).

  2. Call getDefragIterator() to obtain a JdbcDefragIterator object. For example:

    JdbcDefragIterator defrag = jconn.getDefragIterator();
  3. During idle time, call ulStoreDefragStep() to defragment a piece of the database.

    defrag.ulStoreDefragStep();

Contents Index Changing the encryption key for a database Adding synchronization to your application