Ontimize 5.2071EN

com.ontimize.db
Class Autonumerical

java.lang.Object
  extended bycom.ontimize.db.Autonumerical

public class Autonumerical
extends java.lang.Object

This class implements an incremental number generator. It provides methods so that the entities can obtain those numbers. Modification 20/05/2004: It has been modified to allow the use of multiple counters. The current behavior is: The table associated to the autonumerical must have the following columns: - state - general autonumerical (numeric data type) Furthermore, it can have additional columns in which an autonumerical associated to the column name is stored

Version:
1.0

Nested Class Summary
protected  class Autonumerical.SavingThread
           
 
Field Summary
protected  int[] autonumerical
           
protected  int autonumericalCountSinceLastSave
           
protected  boolean bSynchronized
           
protected  java.lang.String column
           
static java.lang.String COLUMN
           
protected  java.lang.String[] columnNames
           
protected  java.util.Properties databaseProperties
           
static boolean DEBUG
           
protected static int DEFAULT_SAVING_CICLE
           
protected  java.lang.String driver
           
protected  boolean forceDisconnection
           
static java.lang.String LOG_KEYS
           
protected  java.util.Vector logkeys
           
protected  DatabaseConnectionManager manager
           
protected  java.lang.String password
           
protected  java.util.Properties properties
           
static java.lang.String SAVING_CYCLE
           
static java.lang.String SAVING_INTERVAL
           
protected  int savingCycle
           
protected  int savingInterval
           
static java.lang.String STATE_COLUMN
           
protected  java.lang.String stateColumn
           
protected  java.sql.Connection staticCon
           
static boolean SYNCHRONIZE
           
static java.lang.String SYNCHRONIZE_VALUE
           
protected  java.lang.String table
           
static java.lang.String TABLE
           
protected  Autonumerical.SavingThread thread
           
protected  java.lang.String uRLDatabase
           
protected  java.lang.String user
           
 
Constructor Summary
Autonumerical(java.lang.String propertyFile, DatabaseConnectionManager dbConMan)
           
Autonumerical(java.net.URL propertyFile, java.sql.Connection connection)
          Creates a new Autonumerical object instance
Autonumerical(java.net.URL propertyFile, DatabaseConnectionManager dbConMan)
           
Autonumerical(java.net.URL propertyFile, java.net.URL urlDBProp)
          Creates a new Autonumerical object instance
Autonumerical(java.net.URL propertyFile, java.net.URL urlDBProp, boolean createFistConnection)
           
 
Method Summary
 void activateForceDisconnection()
           
 void disactivateForceDisconnection()
           
protected  void finalize()
           
 int getAutonumerical()
          Gets an sequential integer value to use as unique identifier.
 int getAutonumerical(java.lang.String col)
           
protected  int getColumnNameIndex(java.lang.String name)
           
protected  java.lang.String getCurrentThreadMethods(java.lang.Throwable e, int lines)
           
protected  int increment(java.lang.String column)
           
 int incrementAutonumerical(int increment)
           
 int incrementAutonumerical(int increment, java.lang.String col)
           
protected  void initAutonumerical()
           
protected  void initConnection(java.net.URL urlDBProp, boolean createFirstConnection)
           
 boolean isForceDisconnectionEnabled()
           
 boolean isSynchronized()
           
protected  void logToLogKeys(java.lang.String s)
           
protected  void logToLogKeys(java.lang.String s, boolean newLine)
           
protected  java.sql.Connection reconnection()
           
protected  void save()
           
protected  boolean saveAutonumerical()
           
protected  boolean setIncorrectState()
           
protected  void startSavingThread()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG

SYNCHRONIZE

public static boolean SYNCHRONIZE

TABLE

public static final java.lang.String TABLE
See Also:
Constant Field Values

COLUMN

public static final java.lang.String COLUMN
See Also:
Constant Field Values

STATE_COLUMN

public static final java.lang.String STATE_COLUMN
See Also:
Constant Field Values

LOG_KEYS

public static final java.lang.String LOG_KEYS
See Also:
Constant Field Values

SAVING_CYCLE

public static final java.lang.String SAVING_CYCLE
See Also:
Constant Field Values

SAVING_INTERVAL

public static final java.lang.String SAVING_INTERVAL
See Also:
Constant Field Values

SYNCHRONIZE_VALUE

public static final java.lang.String SYNCHRONIZE_VALUE
See Also:
Constant Field Values

DEFAULT_SAVING_CICLE

protected static final int DEFAULT_SAVING_CICLE
See Also:
Constant Field Values

savingInterval

protected int savingInterval

table

protected java.lang.String table

column

protected java.lang.String column

stateColumn

protected java.lang.String stateColumn

logkeys

protected java.util.Vector logkeys

savingCycle

protected int savingCycle

staticCon

protected java.sql.Connection staticCon

columnNames

protected java.lang.String[] columnNames

autonumerical

protected int[] autonumerical

properties

protected java.util.Properties properties

databaseProperties

protected java.util.Properties databaseProperties

thread

protected Autonumerical.SavingThread thread

user

protected java.lang.String user

password

protected java.lang.String password

driver

protected java.lang.String driver

uRLDatabase

protected java.lang.String uRLDatabase

autonumericalCountSinceLastSave

protected int autonumericalCountSinceLastSave

bSynchronized

protected boolean bSynchronized

manager

protected DatabaseConnectionManager manager

forceDisconnection

protected boolean forceDisconnection
Constructor Detail

Autonumerical

public Autonumerical(java.net.URL propertyFile,
                     java.sql.Connection connection)
              throws java.lang.Exception
Creates a new Autonumerical object instance

Parameters:
propertyFile - In the property file 'propertyFile' the following parameters are included::
- Table: Table: Name of the table the last autonumerical is stored in
- Column : Name of the column the number is stored in
- StateColumn: Name of the column the state is stored in. Possible states: '1' correct, '0' incorrect.
- SavingCycle: Time in milliseconds between each update of the autonumerical in the table
connection - Database connection
Throws:
java.lang.Exception

Autonumerical

public Autonumerical(java.net.URL propertyFile,
                     java.net.URL urlDBProp)
              throws java.lang.Exception
Creates a new Autonumerical object instance

Parameters:
propertyFile - In the property file 'propertyFile' the following parameters are included::
- Table: Name of the table the last autonumerical is stored in
- Column : Name of the column the number is stored in
- StateColumn: Name of the column the state is stored in. Possible states: '1' correct, '0' incorrect.
- LogKeys: Name of the logs which the object operations are written in. If no log is specified, no log is made.
- SavingCycle: Time in milliseconds between each update of the autonumerical in the table
-SavingInterval: Number of autonumericals provided before storing the value in the table.
urlDBProp - This parameter specifies the DB connection property file. It will have the following parameters::
- driver: JDBC driver class
- url: database url connection.
- user: database user name
- password: database password for the specified user.
Throws:
java.lang.Exception

Autonumerical

public Autonumerical(java.net.URL propertyFile,
                     java.net.URL urlDBProp,
                     boolean createFistConnection)
              throws java.lang.Exception

Autonumerical

public Autonumerical(java.net.URL propertyFile,
                     DatabaseConnectionManager dbConMan)
              throws java.lang.Exception

Autonumerical

public Autonumerical(java.lang.String propertyFile,
                     DatabaseConnectionManager dbConMan)
              throws java.lang.Exception
Method Detail

initAutonumerical

protected void initAutonumerical()

getColumnNameIndex

protected int getColumnNameIndex(java.lang.String name)

startSavingThread

protected void startSavingThread()

initConnection

protected void initConnection(java.net.URL urlDBProp,
                              boolean createFirstConnection)
                       throws java.lang.Exception
Throws:
java.lang.Exception

getAutonumerical

public int getAutonumerical()
Gets an sequential integer value to use as unique identifier. To ensure that the last generated value is stored successfully in the database tablePara executes the following mechanism:
- After 'n' requests database it updates the databse table and sets the state as correct
- In the first request of the next 'n' autonumerical values, the states column sets as incorrect.
- When the class is created checks if the state is correct or not. If the state column has incorrect value automatically it sum a value to the autonumerical number column

Returns:

getAutonumerical

public int getAutonumerical(java.lang.String col)

incrementAutonumerical

public int incrementAutonumerical(int increment)

incrementAutonumerical

public int incrementAutonumerical(int increment,
                                  java.lang.String col)

saveAutonumerical

protected boolean saveAutonumerical()

increment

protected int increment(java.lang.String column)
                 throws java.lang.Exception
Throws:
java.lang.Exception

save

protected void save()
             throws java.lang.Exception
Throws:
java.lang.Exception

setIncorrectState

protected boolean setIncorrectState()

reconnection

protected java.sql.Connection reconnection()
                                    throws java.lang.Exception
Throws:
java.lang.Exception

finalize

protected void finalize()
                 throws java.lang.Throwable
Throws:
java.lang.Throwable

logToLogKeys

protected void logToLogKeys(java.lang.String s)

logToLogKeys

protected void logToLogKeys(java.lang.String s,
                            boolean newLine)

getCurrentThreadMethods

protected java.lang.String getCurrentThreadMethods(java.lang.Throwable e,
                                                   int lines)

activateForceDisconnection

public void activateForceDisconnection()
                                throws java.lang.Exception
Throws:
java.lang.Exception

disactivateForceDisconnection

public void disactivateForceDisconnection()
                                   throws java.lang.Exception
Throws:
java.lang.Exception

isForceDisconnectionEnabled

public boolean isForceDisconnectionEnabled()

isSynchronized

public boolean isSynchronized()

Ontimize