Search in sources :

Example 1 with NullLocationException

use of com.iplanet.log.NullLocationException in project OpenAM by OpenRock.

the class DBHandler method configure.

private void configure() throws NullLocationException, FormatterInitException {
    setFilter(null);
    try {
        setEncoding("UTF-8");
    } catch (UnsupportedEncodingException e) {
        Debug.error(tableName + ":DBHandler: unsupportedEncodingException ", e);
    }
    String bufferSize = lmanager.getProperty(LogConstants.BUFFER_SIZE);
    if (bufferSize != null && bufferSize.length() > 0) {
        try {
            recCountLimit = Integer.parseInt(bufferSize);
        } catch (NumberFormatException nfe) {
            Debug.warning(tableName + ":DBHandler: NumberFormatException ", nfe);
            if (Debug.messageEnabled()) {
                Debug.message(tableName + ":DBHandler: Setting buffer size to 1");
            }
            recCountLimit = 1;
        }
    } else {
        Debug.warning(tableName + ":DBHandler: Invalid buffer size: " + bufferSize);
        if (Debug.messageEnabled()) {
            Debug.message(tableName + ":DBHandler: Setting buffer size to 1");
        }
        recCountLimit = 1;
    }
    String recMaxDBMemStr = lmanager.getProperty(LogConstants.DB_MEM_MAX_RECS);
    if (recMaxDBMemStr != null && recMaxDBMemStr.length() > 0) {
        try {
            recMaxDBMem = Integer.parseInt(recMaxDBMemStr);
        } catch (NumberFormatException nfe) {
            Debug.warning(tableName + ":DBHandler:recMaxDBMem (" + recMaxDBMemStr + "): NumberFormatException ", nfe);
            if (Debug.messageEnabled()) {
                Debug.message(tableName + ":DBHandler: Setting Max DB Mem Buffer Size to 2x (" + 2 * recCountLimit + ") the Buffer Size (" + recCountLimit + ")");
            }
            recMaxDBMem = 2 * recCountLimit;
        }
    } else {
        Debug.warning(tableName + ":DBHandler: Invalid buffer size: " + bufferSize);
        if (Debug.messageEnabled()) {
            Debug.message(tableName + ":DBHandler: Defaulting Max DB Mem Buffer Size to 2x Buffer Size");
        }
        recMaxDBMem = 2 * recCountLimit;
    }
    if (recMaxDBMem < recCountLimit) {
        Debug.warning(tableName + ":DBHandler:Maximum DB memory buffer size < Buffer Size, " + "setting to buffer size (" + recCountLimit + ")");
        recMaxDBMem = recCountLimit;
    }
    String status = lmanager.getProperty(LogConstants.TIME_BUFFERING_STATUS);
    if (status != null && status.equalsIgnoreCase("ON")) {
        timeBufferingEnabled = true;
    }
    oraDataType = lmanager.getProperty(LogConstants.ORA_DBDATA_FIELDTYPE);
    mysqlDataType = lmanager.getProperty(LogConstants.MYSQL_DBDATA_FIELDTYPE);
    databaseURL = lmanager.getProperty(LogConstants.LOG_LOCATION);
    if ((databaseURL == null) || (databaseURL.length() == 0)) {
        throw new NullLocationException("Database URL location is null");
    }
    String strFormatter = com.sun.identity.log.LogManager.FORMATTER;
    if ((strFormatter == null) || (strFormatter.length() == 0)) {
        throw new FormatterInitException("Unable To Initialize DBFormatter");
    }
    userName = lmanager.getProperty(LogConstants.DB_USER);
    if ((userName == null) || (userName.length() == 0)) {
        throw new NullLocationException("userName is null");
    }
    password = lmanager.getProperty(LogConstants.DB_PASSWORD);
    if ((password == null) || (password.length() == 0)) {
        throw new NullLocationException("password not provided");
    }
    driver = lmanager.getProperty(LogConstants.DB_DRIVER);
    if ((driver == null) || (driver.length() == 0)) {
        throw new NullLocationException("driver not provided");
    }
    //
    if (driver.toLowerCase().indexOf("oracle") != -1) {
        isMySQL = false;
    } else if (driver.toLowerCase().indexOf("mysql") != -1) {
        isMySQL = true;
    } else {
        isMySQL = false;
        Debug.warning(tableName + ":DBHandler:configure:assuming driver: '" + driver + "' is Oracle-compatible.");
    }
    try {
        Class clz = Class.forName(strFormatter);
        Formatter formatter = (Formatter) clz.newInstance();
        setFormatter(formatter);
    } catch (Exception e) {
        // should be Invalid Formatter Exception
        Debug.error(tableName + ":DBHandler: Could not load Formatter", e);
        throw new FormatterInitException("Unable To Initialize DBFormatter " + e.getMessage());
    }
}
Also used : Formatter(java.util.logging.Formatter) NullLocationException(com.iplanet.log.NullLocationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NullLocationException(com.iplanet.log.NullLocationException) ConnectionException(com.iplanet.log.ConnectionException) DriverLoadException(com.iplanet.log.DriverLoadException) SQLException(java.sql.SQLException) AMLogException(com.sun.identity.log.AMLogException) ThreadPoolException(com.iplanet.am.util.ThreadPoolException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1 ConnectionException (com.iplanet.log.ConnectionException)1 DriverLoadException (com.iplanet.log.DriverLoadException)1 NullLocationException (com.iplanet.log.NullLocationException)1 AMLogException (com.sun.identity.log.AMLogException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SQLException (java.sql.SQLException)1 Formatter (java.util.logging.Formatter)1