com.ibm.websphere.als
Class DatabaseLogger

java.lang.Object
  |
  +--com.ibm.websphere.als.DatabaseLogger
All Implemented Interfaces:
Logger

public class DatabaseLogger
extends java.lang.Object
implements Logger

This class implements Logger interface for Database persistence. It writes LogRecords into a table in the database specified by the DataSource object. The name of the table is default to ALS without qualifying schema. The application may set the table and schema if different from the default. A record consist of the following fields:

  1. TMSTP TIMESTAMP: This field stores the date and time based on a reading of the clock when the SQL statement is executed at the database server. Each database vendor has a specific function to achieve this task. For IBM DB2, this function is CURRENT TIMESTAMP. For Oracle, this function is SYSDATE. Find a compatible function for other databases. If this function is not set, a java.sql.Timestamp of the local machine will be inserted into this column. It is up to the JDBC driver to convert this value as appropriate. The java.sql.PreparedStatement#setTimestamp indicates that the driver converts this object to an SQL TIMESTAMP value when it sends it to the database. 
  2. APPID VARCHAR(64): This field stores the application ID of this record. The ID should be 64 characters or less. 
  3. REQID CHARACTER(64) NOT NULL: This field stores the http request correlation ID. It must be a fix-length of 64 characters. The ID is internally generated. The ID is made up of 2 parts: major-minor. The major part is the session ID if the session tracking is on; otherwise, it is 0. The minor is a sequence number identifying the order of logging requests. Records with the same minor should be considered as part of the same http request. 
  4. HTTPDATA VARCHAR or compatible type: This field stores the NCSA combined format of the http request. The size of the field is recommended to be at least 256 characters. If the http data exceeds the length of the field, it will be truncated. The value could be null. 
  5. COOKIE VARCHAR or compatible type: This field stores the cookie. The size of the field is recommended to be at least 256 characters. If the cookie data exceeds the length of the field, it will be truncated. The value could be null. 
  6. APPDATA VARCHAR or compatible type: This field stores any application specific data. The size of the field is recommended to be at least 256 characters. If the app data exceeds the length of the field, it will be truncated. The value could be null.

The types of the fields may be any specific database datatype that can accept a Java String of the specified length. For example, some database may not have VARCHAR large enough to support string more than 256 characters. In such case, the application may use other compatible datatype such as CLOB.


Constructor Summary
DatabaseLogger(javax.sql.DataSource ds)
          Constructs a DatabaseLogger instance
DatabaseLogger(javax.sql.DataSource ds, java.lang.String dateFunc)
          Constructs a DatabaseLogger instance with the specified SQL date function.
DatabaseLogger(javax.sql.DataSource ds, java.lang.String dateFunc, java.lang.String schemaDotTable, java.lang.String uID, java.lang.String pwd)
          Constructs a DatabaseLogger instance with the specified SQL date function.
 
Method Summary
 java.lang.Object getStorageSource()
          Returns the DataSource.
 void write(LogRecord[] data)
          Writes the data to the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseLogger

public DatabaseLogger(javax.sql.DataSource ds)
Constructs a DatabaseLogger instance
Parameters:
ds - a javax.sql.DataSource object

DatabaseLogger

public DatabaseLogger(javax.sql.DataSource ds,
                      java.lang.String dateFunc)
Constructs a DatabaseLogger instance with the specified SQL date function. For IBM DB2, this function is CURRENT TIMESTAMP. For Oracle, this function is SYSDATE. Find a compatible function for other databases. If this function is not set, a java.sql.Timestamp of the local machine will be inserted into this column. It is up to the JDBC driver to convert this value as appropriate. The java.sql.PreparedStatement#setTimestamp indicates that the driver converts this to an SQL TIMESTAMP value when it sends it to the database. For example, new DatabaseLogger(ds, "CURRENT TIMESTAMP") creates a DatabaseLogger object for IBM DB2.

The database schema, user ID, and password are default to the system. The table name is assumed to be ALS.

Parameters:
ds - a javax.sql.DataSource object
dateFunc - a SQL date function

DatabaseLogger

public DatabaseLogger(javax.sql.DataSource ds,
                      java.lang.String dateFunc,
                      java.lang.String schemaDotTable,
                      java.lang.String uID,
                      java.lang.String pwd)
Constructs a DatabaseLogger instance with the specified SQL date function. For IBM DB2, this function is CURRENT TIMESTAMP. For Oracle, this function is SYSDATE. Find a compatible function for other databases. If this function is not set, a java.sql.Timestamp of the local machine will be inserted into this column. It is up to the JDBC driver to convert this value as appropriate. The java.sql.PreparedStatement#setTimestamp indicates that the driver converts this to an SQL TIMESTAMP value when it sends it to the database.
Parameters:
ds - a javax.sql.DataSource object
dateFunc - a SQL date function
schemaDotTable - a table name or a table name with qualifying schema such as MySchema.MYTABLE
userID - a database user ID with write-access
pwd - a password to access
Method Detail

write

public void write(LogRecord[] data)
           throws java.lang.Exception
Writes the data to the database. A connection is created for data update and closed at the end. Transaction is committed when all records have been written. For httpData, cookie, and appData, their length will automatically be truncated if longer than the size of their respective columns.
Specified by:
write in interface Logger
Parameters:
data - array of LogRecords
Throws:
java.lang.Exception - when unable to write to storage

getStorageSource

public java.lang.Object getStorageSource()
Returns the DataSource.
Specified by:
getStorageSource in interface Logger