All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class de.tudarmstadt.ito.xmldbms.helpers.KeyGeneratorImpl

java.lang.Object
   |
   +----de.tudarmstadt.ito.xmldbms.helpers.KeyGeneratorImpl

public class KeyGeneratorImpl
extends Object
implements KeyGenerator
Default KeyGenerator implementation.

This key generator assumes that there is a table named XMLDBMSKey in the database with an INTEGER column named HighKey. It constructs keys from a high key value and a low key value: the high key value forms the upper 24 bits of the key and the low key value forms the lower 8 bits of the key. The high key value is retrieved from the XMLDBMSKey table, which is then incremented by 1. The low key value is initialized to 0 and incremented by 1 each time generateKey() is called; when it reaches 255, a new high key value is retrieved. Thus, KeyGeneratorImpl can generate 256 unique key values with a single database access.

For example, the following code instantiates KeyGeneratorImpl and passes it to DOMToDBMS, which uses it to generate keys.

    // Instantiate KeyGeneratorImpl and initialize it with a Connection.
    KeyGenerator keyGenerator = new KeyGeneratorImpl();
    keyGenerator.initialize(conn);
// Pass the key generator to DOMToDBMS. domToDBMS = new DOMToDBMS(map, keyGenerator, null);

Version:
1.01
Author:
Ronald Bourret, Technical University of Darmstadt

Constructor Index

 o KeyGeneratorImpl(Connection)
Construct a new KeyGeneratorImpl object.

Method Index

 o generateKey()
 o initialize()
Initialize the KeyGeneratorImpl object.

Constructors

 o KeyGeneratorImpl
 public KeyGeneratorImpl(Connection conn)
Construct a new KeyGeneratorImpl object.

Parameters:
conn - A connection to the database containing the XMLDBMSKey table. Note that this connection must be different from the connection used by the Map object. The reason for this is that each commits transactions at different times and using the same connection for both objects would lead to statements being committed prematurely.

Methods

 o initialize
 public void initialize() throws KeyException
Initialize the KeyGeneratorImpl object.

Throws: KeyException
Thrown if an error occurred initializing the database. Usually, this will be an error setting the auto-commit or transaction isolation level.
 o generateKey
 public Object[] generateKey() throws KeyException

All Packages  Class Hierarchy  This Package  Previous  Next  Index