FileDocCategorySizeDatePackage
AbstractTableAccessObject.javaAPI DocGlassfish v2 API9665Mon Jul 30 15:12:20 BST 2007com.sun.enterprise.admin.monitor.callflow

AbstractTableAccessObject

public abstract class AbstractTableAccessObject extends Object implements TableAccessObject
author
Harpreet Singh

Fields Summary
private static final Logger
logger
private static final String
SYSTEM_PROPERTY
public boolean
traceOn
private static final String
TABLE_EXISTS_SQL_ERROR_CODE
Connection
con
String
tableName
private static final String
DEFAULT_SERVER_NAME
private long
totalEntriesProcessed
private String
name
private static final String
INVALID_TABLE_NAME_CHARACTER_DASH
private static final String
INVALID_TABLE_NAME_CHARACTER_DOT
private static final String
INVALID_TABLE_NAME_REPLACEMENT_STRING
private static final String
OVERRIDE_DEFAULT_REPLACEMENT_STRING
Constructors Summary
Methods Summary
public voidaddTotalEntriesProcessed(int totalEntriesProcessed)

        this.totalEntriesProcessed += totalEntriesProcessed;
    
booleancreateStatmentAndExecuteUpdate(java.lang.String oldsql, java.lang.String tableNameWithoutServerInstance)

        
        
   
      
            
       
        String sql = updateSqlWithTableName (oldsql, tableNameWithoutServerInstance);
        boolean result = false;
        Statement stmt = null;
        try{
            if (con != null){
                stmt = con.createStatement();
                stmt.executeUpdate(sql);
                result = true;
            }
        } catch (java.sql.SQLException se) {
            // log it
            logger.log(Level.WARNING, "Error accessing CallFlow tables!", se);
            result = false;
        } finally {
            if(stmt != null){
                try{
                    stmt.close();
                }catch(java.sql.SQLException s){
                    // log it
                }
            }
            stmt = null;
        }
        return result;
   
public abstract booleancreateTable(java.sql.Connection connection)

booleancreateTable(java.lang.String oldsql, java.lang.String tableNameWithoutServerInstance)
This method is used to create a database table. If the table already exists, it logs a message and returns successfully. As there is no mechanism to actually test if the database exists, it creates the table and if there is an exception, it assumes it is due to table being present.

       
        String sql = updateSqlWithTableName (oldsql, tableNameWithoutServerInstance);
        boolean result = false;
        Statement stmt = null;
        try{
            if (con != null){
                stmt = con.createStatement();
                stmt.executeUpdate(sql);
                result = true;
            }
        } catch (java.sql.SQLException se) {
            // log it
            if (se.getSQLState().equalsIgnoreCase (TABLE_EXISTS_SQL_ERROR_CODE)){
                logger.log (Level.FINE, "callflow.table_already_exists_error", 
                        tableNameWithoutServerInstance);               
            } else {
                logger.log(Level.WARNING, "callflow.table_creation_error", 
                        tableNameWithoutServerInstance); 
                logger.log(Level.WARNING, "callflow.table_creation_error", se);
            }
            result = true;
        } finally {
            if(stmt != null){
                try{
                    stmt.close();
                }catch(java.sql.SQLException s){
                    // log it
                }
            }
            stmt = null;
        }
        return result;
   
public booleandelete(java.sql.PreparedStatement pstmt, java.lang.String[] requestId)

        if (pstmt == null)
            return false;
        
        boolean result = false;
        try{
            for (int i = 0 ; i<requestId.length; i++) {
                pstmt.setString(1, requestId[i]);
                pstmt.addBatch();
            }
            int[] updated = pstmt.executeBatch();
            result =  (updated.length == requestId.length)? true : false;
            if (result == false){
                logger.log (Level.WARNING, "callflow.error_delete_row");                
            }
        }  catch(BatchUpdateException bue) {
            // log it
            logger.log (Level.WARNING, "callflow.error_delete_row");
            logger.log(Level.FINE, "Error data into CallFlow tables", bue);
            result = false;
        }catch (SQLException se) {
            // log it
            logger.log (Level.WARNING, "callflow.error_delete_row");
            logger.log(Level.FINE, "Error inserting data into CallFlow tables", se);
            result = false;
        }
        return result;        
        
    
public abstract booleandropTable(java.sql.Connection connection)

public java.lang.StringgetName()

        return name;
    
public java.lang.StringgetServerInstanceName()

       // get the server name from config
       String server = DEFAULT_SERVER_NAME;
       ServerContext sc = ApplicationServer.getServerContext();
        if (sc != null) {
           server = removeInvalidCharactersFromTableName(sc.getInstanceName());
        } 
        return "__" + server;
   
public longgetTotalEntriesProcessed()

        return totalEntriesProcessed;
    
public booleanisTraceOn()

        return traceOn;
    
public java.lang.StringremoveInvalidCharactersFromTableName(java.lang.String instanceName)

       
       String overrideString = null; 
       overrideString = System.getProperty(OVERRIDE_DEFAULT_REPLACEMENT_STRING);
       if (overrideString == null){
        overrideString = this.INVALID_TABLE_NAME_REPLACEMENT_STRING;
       }
       String tmp = instanceName.replace(INVALID_TABLE_NAME_CHARACTER_DOT, overrideString);
       String modifiedInstanceName = tmp.replace (INVALID_TABLE_NAME_CHARACTER_DASH,
               overrideString);
       return modifiedInstanceName;
   
public voidsetName(java.lang.String name)

        this.name = name;
    
java.lang.StringupdateSqlWithTableName(java.lang.String oldsql, java.lang.String table)
Adds the server instance name to the table names in the SQL statements for create/delete and insert. All creates and deletes need to call them before they submit the query to be executed

param
String complete sql that has the table name without the server instance name
param
String Name of the table, this table name will be appended by a "__" and server name

       String newsql = new String(oldsql);
       newsql = newsql.replaceAll(table, tableName);
       
        return newsql;