diff --git a/build.xml b/build.xml index bcbd14d..b5ba908 100644 --- a/build.xml +++ b/build.xml @@ -317,6 +317,7 @@ + diff --git a/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMain.java b/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMain.java index 0e715e1..70a31c6 100644 --- a/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMain.java +++ b/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMain.java @@ -17,11 +17,14 @@ */ package com.silverwrist.venice.conf.module; +import java.io.*; import java.security.Principal; import java.util.*; +import com.silverwrist.util.*; import com.silverwrist.dynamo.Namespaces; import com.silverwrist.dynamo.except.*; import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.module.DatabaseInstaller; import com.silverwrist.dynamo.module.ModuleConfigurationData; import com.silverwrist.dynamo.security.SecurityReferenceMonitor; import com.silverwrist.dynamo.util.*; @@ -45,6 +48,7 @@ public class ModuleMain implements ModuleFunctions, UseCount private static final QualifiedNameKey NAME = new QualifiedNameKey(ConfNamespaces.CONFERENCING_NAMESPACE,"Venice.conferencing"); private static final String RESOURCES = "com.silverwrist.venice.conf.module.ModuleMessages"; + private static final String INITSCRIPT = "database-init-${name}.xml"; /*-------------------------------------------------------------------------------- * Attributes @@ -66,6 +70,29 @@ public class ModuleMain implements ModuleFunctions, UseCount { // do nothing } // end constructor + /*-------------------------------------------------------------------------------- + * Internal operations + *-------------------------------------------------------------------------------- + */ + + private static final InputStream getInstallScript(DatabaseInstaller dinst, DynamoLog log) throws ModuleException + { + String resname = StringUtils.replaceOnce(INITSCRIPT,"${name}",dinst.getDatabaseType()); + log.debug("Loading database init script " + resname); + InputStream script = ModuleMain.class.getResourceAsStream(resname); + if (script==null) + { // whoops! script isn't there! + log.error("Unable to find database init script " + resname); + ModuleException me = new ModuleException(ModuleMain.class,"ModuleMessages","no.db.script"); + me.setParameter(0,resname); + throw me; + + } // end if + + return script; + + } // end getInstallScript + /*-------------------------------------------------------------------------------- * Implementations from interface ModuleFunctions *-------------------------------------------------------------------------------- @@ -157,6 +184,11 @@ public class ModuleMain implements ModuleFunctions, UseCount ResourceBundle bun = ResourceBundle.getBundle(RESOURCES); + // Install the database tables we need. + DatabaseInstaller dinst = (DatabaseInstaller)(services.queryService(DatabaseInstaller.class)); + dinst.runInstallScript(getInstallScript(dinst,log),log); + log.info("Database install script executed successfully"); + try { // Install our community menu options. CommunityMenuInstaller comm_menu = new CommunityMenuInstaller(services); @@ -244,6 +276,11 @@ public class ModuleMain implements ModuleFunctions, UseCount } // end catch + // Uninstall our database tables. + DatabaseInstaller dinst = (DatabaseInstaller)(services.queryService(DatabaseInstaller.class)); + dinst.runUninstallScript(getInstallScript(dinst,log),log); + log.info("Database uninstall script executed successfully"); + } // end uninstall public DynamicObject getProvidedObject(String namespace, String name) throws ModuleException diff --git a/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMessages.properties b/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMessages.properties index cc537af..eb0a9f3 100644 --- a/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMessages.properties +++ b/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMessages.properties @@ -21,3 +21,4 @@ install.service.fail=Failed to install community service object: {0} uninstall.service.fail=Failed to uninstall community service object: {0} install.cmenu.fail=Failed to install community menu items: {0} uninstall.cmenu.fail=Failed to uninstall community menu items: {0} +no.db.script=Unable to find the database initialization script "{0}." diff --git a/src/conferencing-module/com/silverwrist/venice/conf/module/database-init-mysql.xml b/src/conferencing-module/com/silverwrist/venice/conf/module/database-init-mysql.xml new file mode 100644 index 0000000..93b172a --- /dev/null +++ b/src/conferencing-module/com/silverwrist/venice/conf/module/database-init-mysql.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/dynamo-framework/com/silverwrist/dynamo/module/InstallerImpl.java b/src/dynamo-framework/com/silverwrist/dynamo/module/InstallerImpl.java index 02f4410..2d33754 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/module/InstallerImpl.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/module/InstallerImpl.java @@ -195,7 +195,15 @@ class InstallerImpl implements DatabaseInstaller finally { // make sure we shut down the connection before we go SQLUtils.shutdown(stmt); - SQLUtils.shutdown(conn); + try + { // return this connection to the pool + if (conn!=null) + m_pool.releaseConnection(conn); + + } // end try + catch (DatabaseException e) + { // ignore the error + } // end catch } // end finally