Class Hierarchy    Previous  Next  Index

Class COM.cloudscape.util.KeyGen

java.lang.Object
    |
    +----COM.cloudscape.util.KeyGen

public abstract class KeyGen
extends java.lang.Object
Copyright © 1998-2000, Informix Software, Inc. All rights reserved.

Utility class for generating unique key values.


Variable Index

 o UNIVERSAL_KEY_BIT_LEN
The length of the byte[] form of a generated universal key in bits.
 o UNIVERSAL_KEY_BYTE_LEN
The length of the byte[] form of a generated universal key in bytes.
 o UNIVERSAL_KEY_STRING_LEN
The character length of the String form of a generated universal key.

Constructor Index

 o KeyGen()
 

Method Index

 o getUniversalKeyStringValue()
Generate a unique String key value.
 o getUniversalKeyValue()
Generate a unique key value.

Field Detail

 o UNIVERSAL_KEY_BYTE_LEN
public static final int UNIVERSAL_KEY_BYTE_LEN
          The length of the byte[] form of a generated universal key in bytes.
 o UNIVERSAL_KEY_BIT_LEN
public static final int UNIVERSAL_KEY_BIT_LEN
          The length of the byte[] form of a generated universal key in bits.
 o UNIVERSAL_KEY_STRING_LEN
public static final int UNIVERSAL_KEY_STRING_LEN
          The character length of the String form of a generated universal key.

Constructor Detail

 o KeyGen
public KeyGen()

Method Detail

 o getUniversalKeyValue
public static byte[] getUniversalKeyValue()
          Generate a unique key value.

The returned key is constructed in a manner that makes it extremely unlikely a KeyGen running in another database will construct the same key. This makes the generated keys useful in distributed applications. An application running at a target (or source) database may use generated key values for primary key column values when inserting rows. The rows are unlikely to conflict with rows inserted at other databases.

Returned keys are generated in a random order. This reduces contention on a backing index, when the key values are used for primary key values in a sql table.

The example below shows a typical use of this facility to construct nonconflicting keys for a table.

create table foo(k bit(128) primary key);
insert into foo
values (class COM.cloudscape.util.KeyGen).getUniversalKeyValue();
 o getUniversalKeyStringValue
public static java.lang.String getUniversalKeyStringValue()
          Generate a unique String key value.

Like getUniversalKeyValue, the keys this generates are unlikely to conflict with keys generated at other databases. String keys are useful for applications that must display keys and depend on tools that do not correctly support bit data. String keys are twice as long as the keys generated by getUniversalKey.

The example below shows a typical use of this facility to construct nonconflicting keys for a table.

create table foo2(k char(32) primary key);
insert into foo2
values (class COM.cloudscape.util.KeyGen).getUniversalKeyStringValue();

  Class Hierarchy    Previous  Next  Index