FileDocCategorySizeDatePackage
BaseProcessor.javaAPI DocGlassfish v2 API12056Fri May 04 22:34:48 BST 2007com.sun.jdo.spi.persistence.support.ejb.ejbc

BaseProcessor

public abstract class BaseProcessor extends Object implements com.sun.jdo.spi.persistence.utility.database.DatabaseConstants
author
pramodg

Fields Summary
protected static final com.sun.jdo.spi.persistence.utility.logging.Logger
logger
The logger
protected static final ResourceBundle
messages
I18N message handler
protected com.sun.enterprise.deployment.Application
application
protected com.sun.enterprise.deployment.backend.DeploymentEventInfo
info
protected com.sun.enterprise.deployment.backend.DeploymentStatus
status
protected boolean
create
True if this event results in creating new tables.
protected String
cliCreateTables
protected String
cliDropAndCreateTables
protected String
cliDropTables
protected String
appRegisteredName
Name with which the application is registered.
protected String
appDeployedLocation
protected String
appGeneratedLocation
protected String
createJdbcFileName
The string name of the create jdbc ddl file.
protected String
dropJdbcFileName
The string name of the drop jdbc ddl file.
protected boolean
debug
Constructors Summary
public BaseProcessor(com.sun.enterprise.deployment.backend.DeploymentEventInfo info, boolean create, String cliCreateTables, String cliDropAndCreateTables, String cliDropTables)
Creates a new instance of BaseProcessor.

param
info the deployment info object.
param
create true if this event results in creating new tables.
param
cliCreateTables the cli string related to creating tables at deployment time.
param
cliDropAndCreateTables the cli string that indicates that old tables have to be dropped and new tables created.
param
cliDropTables the cli string to indicate that the tables have to dropped at undeploy time.

     
    
                                                                              
       
               
                
        initializeVariables(info, create, cliCreateTables,
            cliDropAndCreateTables, cliDropTables);
    
Methods Summary
protected voidcannotConnect(java.lang.String connName, java.lang.Throwable ex)
Provide a warning message to the user about inability to connect to the database. The message is created from the cmpResource's JNDI name and the exception.

param
status DeploymentStatus via which user is warned
param
cmpResource For obtaining JNDI name
param
ex Exception which is cause for inability to connect.

        logI18NWarnMessage( "ejb.BaseProcessor.cannotConnect",  
                connName,  null, ex);
    
protected static voidcloseConn(java.sql.Connection conn)
Close the connection that was opened to the database

param
conn the database connection.

        if (conn != null) {
            try {
                conn.close();
            } catch(SQLException ex) {
                // Ignore.
            }
        }
    
protected voidexecuteDDLs(java.io.File f, java.sql.Statement sql)
Open a DDL file and execute each line as a SQL statement.

throw
IOException if there is a problem with reading the file.
param
f the File object to use.
param
sql the Statement to use for execution.
throws
java.io.IOException if there is a problem with reading the file.


        BufferedReader reader = null;
        StringBuffer warningBuf = new StringBuffer();

        try {
            reader = new BufferedReader(new FileReader(f));
            String s;
            while ((s = reader.readLine()) != null) {
                try {
                    if (debug) {
                        logger.fine("ejb.BaseProcessor.executestatement", s); //NOI18N
                    }
                    sql.execute(s);

                } catch(SQLException ex) {
                    String msg = getI18NMessage("ejb.BaseProcessor.sqlexception", 
                            s, null, ex);
                    logger.warning(msg);
                    warningBuf.append("\n\t").append(msg); // NOI18N
                }
            }
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch(IOException ex) {
                    // Ignore.
                }
            }
            if (warningBuf.length() > 0) {
                String warning = 
                        getI18NMessage("ejb.BaseProcessor.tablewarning");
                warnUser(warning + warningBuf.toString());
            }
        }
    
protected voidfileIOError(java.lang.String regName, java.lang.Throwable ex)

        logI18NWarnMessage("ejb.BaseProcessor.ioexception",  
                regName,  null, ex);
    
protected java.io.FilegetDDLFile(java.lang.String fileName, boolean create)
Read the ddl file from the disk location.

param
fileName the string name of the file.
param
create true if this event results in creating tables.
return
the jdbc ddl file.

        File file = null;        
        try {
            file = new File(fileName);   
            if (debug) {
                logger.fine(
                    ((create)? "ejb.BaseProcessor.createfilename" //NOI18N
                    : "ejb.BaseProcessor.dropfilename"), //NOI18N
                    file.getName());
            }
        } catch (Exception e) {
            logI18NWarnMessage(
                 "Exception caught in BaseProcessor.getDDLFile()", 
                appRegisteredName, null, e);
        }
        return file;        
    
protected java.lang.StringgetI18NMessage(java.lang.String errorCode)

param
errorCode
return

        return getI18NMessage(
             errorCode, null, null, null);
    
protected java.lang.StringgetI18NMessage(java.lang.String errorCode, java.lang.String regName, java.lang.String fileName, java.lang.Throwable ex)

        String msg = null;
        if(null != ex)
               msg = I18NHelper.getMessage(
                    messages, errorCode,  regName,  ex.toString());
        else if(null != fileName )
            msg = I18NHelper.getMessage(
                    messages, errorCode,  regName,  fileName); 
        else            
             msg = I18NHelper.getMessage(messages, errorCode);
        
        return msg;
    
private voidinitializeVariables(com.sun.enterprise.deployment.backend.DeploymentEventInfo info, boolean create, java.lang.String cliCreateTables, java.lang.String cliDropAndCreateTables, java.lang.String cliDropTables)

        this.info = info;
        this.application = this.info.getApplicationDescriptor();
        this.appRegisteredName = this.application.getRegistrationName();
        this.status = 
                this.info.getDeploymentRequest().getCurrentDeploymentStatus();
        
        this.create = create;
        this.cliCreateTables = cliCreateTables;
        this.cliDropAndCreateTables = cliDropAndCreateTables;
        this.cliDropTables = cliDropTables;  
    
protected voidlogI18NInfoMessage(java.lang.String errorCode, java.lang.String regName, java.lang.String fileName, java.lang.Throwable ex)

        String msg = getI18NMessage(errorCode, 
                regName, fileName, ex);
        logger.info(msg);
    
protected voidlogI18NWarnMessage(java.lang.String errorCode, java.lang.String regName, java.lang.String fileName, java.lang.Throwable ex)

        String msg = getI18NMessage(errorCode, 
                regName, fileName, ex);
        logger.warning(msg);
        warnUser(msg);        
    
protected abstract voidprocessApplication()

protected voidsetApplicationLocation()
The location where the application has been deployed. This would ideally be the domains/domain1/applications directory. This information is obtained from the DeploymentEventListener object that is passed in.

        if(null != this.appDeployedLocation)
            return;
        
        this.appDeployedLocation =        
            info.getDeploymentRequest().getDeployedDirectory().getAbsolutePath() 
            + File.separator; 
    
protected voidsetGeneratedLocation()
The location where files have been generated as part of the application deployment cycle. This is where we write out the sql/jdbc files used to create or drop objects from the database. This information is obtained from the DeploymentEventListener object that is passed in.

        if(null != this.appGeneratedLocation)
            return;
        this.appGeneratedLocation =
                info.getStubsDir().getAbsolutePath() + File.separator;
    
protected voidwarnUser(java.lang.String msg)
Provide a warning message to the user. The message is appended to any already-existing warning message text.

param
status DeploymentStatus via which user is warned
param
msg Message for user.

        status.setStageStatus(DeploymentStatus.WARNING);
        status.setStageStatusMessage(
                status.getStageStatusMessage() + "\n" + msg); // NOI18N