added initial database install script to conferencing module; debugged database

installer system
This commit is contained in:
Eric J. Bowersox 2003-06-24 19:57:30 +00:00
parent cb7b327da8
commit 4a305dcd91
5 changed files with 127 additions and 1 deletions

View File

@ -317,6 +317,7 @@
</javac>
<copy todir="workingarea/conferencing-module">
<fileset dir="src/conferencing-module" includes="**/*.properties"/>
<fileset dir="src/conferencing-module" includes="**/*.xml"/>
</copy>
<mkdir dir="workingarea/conferencing-module/resources"/>
<copy todir="workingarea/conferencing-module/resources">

View File

@ -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

View File

@ -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}."

View File

@ -0,0 +1,79 @@
<?xml version="1.0"?>
<!--
The contents of this file are subject to the Mozilla Public License Version 1.1
(the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
WARRANTY OF ANY KIND, either express or implied. See the License for the specific
language governing rights and limitations under the License.
The Original Code is the Venice Web Communities System.
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
Contributor(s):
-->
<database-info>
<command>
<install log="Creating conference table"><![CDATA[
CREATE TABLE conferences (
confid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
createdate DATETIME NOT NULL,
lastupdate DATETIME NULL,
aclid INT NOT NULL DEFAULT -1,
highest_topic SMALLINT NOT NULL DEFAULT 0,
name VARCHAR(128) NOT NULL,
INDEX by_name (name)
);
]]></install>
<uninstall log="Dropping conference table"><![CDATA[
DROP TABLE conferences;
]]></uninstall>
</command>
<command>
<install log="Creating conference properties table"><![CDATA[
CREATE TABLE conf_props (
confid INT NOT NULL,
nsid INT NOT NULL,
prop_name VARCHAR(255) BINARY NOT NULL,
prop_value VARCHAR(255),
PRIMARY KEY (confid, nsid, prop_name)
);
]]></install>
<uninstall log="Dropping conference properties table"><![CDATA[
DROP TABLE conf_props;
]]></uninstall>
</command>
<command>
<install log="Creating conference linking table"><![CDATA[
CREATE TABLE conf_links (
cid INT NOT NULL,
confid INT NOT NULL,
sequence INT NOT NULL,
hide TINYINT NOT NULL DEFAULT 0,
PRIMARY KEY (cid, confid),
UNIQUE INDEX reverse (confid, cid),
INDEX by_display (cid, sequence)
);
]]></install>
<uninstall log="Dropping conference linking table"><![CDATA[
DROP TABLE conf_links;
]]></uninstall>
</command>
<command>
<install log="Creating conference aliases table"><![CDATA[
CREATE TABLE conf_alias (
confid INT NOT NULL,
alias VARCHAR(64) NOT NULL PRIMARY KEY,
prime TINYINT NOT NULL DEFAULT 0,
INDEX by_confid (confid)
);
]]></install>
<uninstall log="Dropping conference aliases table"><![CDATA[
DROP TABLE conf_alias;
]]></uninstall>
</command>
</database-info>

View File

@ -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