CMPProcessorpublic class CMPProcessor extends BaseProcessor If the application contains cmp 2.x beans process them. Check if
tables have to created or dropped depending on where we are called
in a deploy/undeploy case. |
Methods Summary |
---|
private void | constructJdbcFileNames(com.sun.enterprise.deployment.EjbBundleDescriptor ejbBundle)Construct the name of the create and
drop jdbc ddl files that would be
created. These name would be either
obtained from the persistence.xml file
(if the user has defined them) or we would
create default filenames
String filePrefix = EJBHelper.getDDLNamePrefix(ejbBundle);
createJdbcFileName = filePrefix + CREATE_DDL_JDBC_FILE_SUFFIX;
dropJdbcFileName = filePrefix + DROP_DDL_JDBC_FILE_SUFFIX;
| private boolean | executeDDLStatement(java.io.File fileName, java.lang.String resourceName)Get the ddl files eventually executed
against the database. This method deals
with both create and drop ddl files.
boolean result = false;
Connection conn = null;
Statement sql = null;
try {
try {
conn = DeploymentHelper.getConnection(resourceName);
sql = conn.createStatement();
result = true;
} catch (SQLException ex) {
cannotConnect(resourceName, ex);
} catch (JDOFatalUserException ex) {
cannotConnect(resourceName, ex);
}
if(result) {
executeDDLs(fileName, sql);
}
} catch (IOException e) {
fileIOError(application.getRegistrationName(), e);
} finally {
closeConn(conn);
}
return result;
| private void | executeStatements(java.lang.String fileName, java.lang.String resourceName)If the file is present, execute the corresponding statements
in the database.
File file = getDDLFile(
appGeneratedLocation + fileName, false);
if (file.exists()) {
executeDDLStatement(file, resourceName);
} else {
logI18NWarnMessage(
((create)? "ejb.BaseProcessor.cannotcreatetables" //NOI18N
: "ejb.BaseProcessor.cannotdroptables"), //NOI18N
appRegisteredName, file.getName(), null);
}
| protected boolean | getCreateTablesValue(com.sun.enterprise.deployment.ResourceReferenceDescriptor cmpResource)We need to create tables only on deploy, and
only if the CLI options cliCreateTables or
cliDropAndCreateTables are not set to false.
If those options are not set (UNDEFINED)
the value is taken from the
create-tables-at-deploy element of the
sun-ejb-jar.xml
(cmpResource.isCreateTablesAtDeploy()).
boolean createTables =
create
&& (cliCreateTables.equals(Constants.TRUE)
|| (cmpResource.isCreateTablesAtDeploy()
&& cliCreateTables.equals(Constants.UNDEFINED)));
return createTables;
| protected boolean | getDropTablesValue(com.sun.enterprise.deployment.ResourceReferenceDescriptor cmpResource)We need to drop tables on undeploy and redeploy,
if the corresponding CLI options cliDropAndCreateTables
(for redeploy) or cliDropTables (for undeploy) are
not set to false.
If the corresponding option is not set (UNDEFINED)
the value is taken from the drop-tables-at-undeploy
element of the sun-ejb-jar.xml
(cmpResource.isDropTablesAtUndeploy()).
boolean dropTables =
(!create
&& (cliDropAndCreateTables.equals(Constants.TRUE)
|| cliDropTables.equals(Constants.TRUE)
|| (cmpResource.isDropTablesAtUndeploy()
&& cliDropAndCreateTables.equals(Constants.UNDEFINED)
&& cliDropTables.equals(Constants.UNDEFINED))));
return dropTables;
| private void | processAppBundle(com.sun.enterprise.deployment.EjbBundleDescriptor bundle)This method does all the work of checking
and processing each ejb bundle descriptor.
if (!bundle.containsCMPEntity()) {
return;
}
ResourceReferenceDescriptor cmpResource =
bundle.getCMPResourceReference();
// If this bundle's beans are not created by Java2DB, then skip to
// next bundle.
if (!DeploymentHelper.isJavaToDatabase(
cmpResource.getSchemaGeneratorProperties())) {
return;
}
boolean createTables = getCreateTablesValue(cmpResource) ;
boolean dropTables = getDropTablesValue(cmpResource);
if (debug) {
logger.fine("ejb.CMPProcessor.createanddroptables", //NOI18N
new Object[] {new Boolean(createTables), new Boolean(dropTables)});
}
if (!createTables && !dropTables) {
// Nothing to do.
return;
}
// At this point of time we are sure that we would need to create
// the sql/jdbc files required to create or drop objects from the
// database. Hence setup the required directories from the info object.
setApplicationLocation();
setGeneratedLocation();
constructJdbcFileNames(bundle);
if (debug) {
logger.fine("ejb.CMPProcessor.createanddropfilenames",
createJdbcFileName, dropJdbcFileName); //NOI18N
}
String resourceName = cmpResource.getJndiName();
if (dropTables) {
executeStatements(dropJdbcFileName, resourceName);
} else {
// else can only be createTables as otherwise we'll not reach here
executeStatements(createJdbcFileName, resourceName);
}
| protected void | processApplication()The entry point into this class. Process
any ejb bundle descriptors if defined
for this application.
Collection bundleCollection = application.getEjbBundleDescriptors();
if ( bundleCollection == null) {
return;
}
Iterator bundleItr = bundleCollection.iterator();
// Process only those Bundle descriptors that contain CMP beans.
while ( bundleItr.hasNext() ) {
processAppBundle((EjbBundleDescriptor)bundleItr.next());
}
|
|