public void execute() throws Exception {
// Create table if necessary
if (jawsEntity.getCreateTable())
{
// first check if the table already exists...
boolean created = SQLUtil.tableExists(jawsEntity.getTableName(), jawsEntity.getDataSource());
// Try to create it
boolean infoEnabled = log.isInfoEnabled();
boolean debug = log.isDebugEnabled();
if(created) {
if (infoEnabled)
log.info("Table '"+jawsEntity.getTableName()+"' already exists");
} else {
try
{
// since we use the pools, we have to do this within a transaction
factory.getContainer().getTransactionManager().begin ();
jdbcExecute(null);
factory.getContainer().getTransactionManager().commit ();
// Create successful, log this
if (infoEnabled)
log.info("Created table '"+jawsEntity.getTableName()+"' successfully.");
if (jawsEntity.getPrimKeyField() != null)
if (debug)
log.debug("Primary key of table '"+jawsEntity.getTableName()+"' is '"
+jawsEntity.getPrimKeyField()+"'.");
else {
String flds = "[";
for (Iterator i = jawsEntity.getPkFields();i.hasNext();) {
flds += ((PkFieldMetaData)i.next()).getName();
flds += i.hasNext()?",":"";
}
flds += "]";
if (debug)
log.debug("Primary key of table '"+jawsEntity.getTableName()+"' is " + flds);
}
} catch (Exception e)
{
if (debug)
log.debug("Could not create table " +
jawsEntity.getTableName(), e);
try
{
factory.getContainer().getTransactionManager().rollback ();
}
catch (Exception _e)
{
log.error("Could not roll back transaction", _e);
}
}
}
}
}
|