diff --git a/conf-sso/dynamo.xml b/conf-sso/dynamo.xml index 17c3a69..3f3eb81 100644 --- a/conf-sso/dynamo.xml +++ b/conf-sso/dynamo.xml @@ -43,6 +43,17 @@ + + + mysql + com.mysql.jdbc.Driver + jdbc:mysql://localhost/venice + installer + ttfn6865611 + + + + @@ -51,6 +62,7 @@ ${code.path}/modules + srm diff --git a/conf/dynamo-venice.xml b/conf/dynamo-venice.xml index d9455ae..e88f909 100644 --- a/conf/dynamo-venice.xml +++ b/conf/dynamo-venice.xml @@ -43,6 +43,17 @@ + + + mysql + com.mysql.jdbc.Driver + jdbc:mysql://localhost/venice + installer + ttfn6865611 + + + + @@ -51,6 +62,7 @@ ${code.path}/modules + srm diff --git a/conf/venice-db-init-mysql.sql b/conf/venice-db-init-mysql.sql index 90717a8..2594800 100644 --- a/conf/venice-db-init-mysql.sql +++ b/conf/venice-db-init-mysql.sql @@ -518,6 +518,9 @@ GRANT ALL PRIVILEGES ON venice.* GRANT INSERT, DELETE, UPDATE, SELECT, LOCK TABLES ON venice.* TO veniceuser@localhost IDENTIFIED BY 'XYZZY0099'; +GRANT ALL PRIVILEGES ON venice.* + TO installer@localhost IDENTIFIED BY 'ttfn6865611'; + ############################################################################## # Initialization data ############################################################################## diff --git a/src/dynamo-framework/com/silverwrist/dynamo/module/DatabaseInstaller.java b/src/dynamo-framework/com/silverwrist/dynamo/module/DatabaseInstaller.java new file mode 100644 index 0000000..192b3fe --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/module/DatabaseInstaller.java @@ -0,0 +1,32 @@ +/* + * 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 . + * + * 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 , + * 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): + */ +package com.silverwrist.dynamo.module; + +import java.io.InputStream; +import com.silverwrist.dynamo.except.ModuleException; +import com.silverwrist.dynamo.iface.DynamoLog; + +public interface DatabaseInstaller +{ + public String getDatabaseType(); + + public void runInstallScript(InputStream script, DynamoLog log) throws ModuleException; + + public void runUninstallScript(InputStream script, DynamoLog log) throws ModuleException; + +} // end interface DatabaseInstaller diff --git a/src/dynamo-framework/com/silverwrist/dynamo/module/InstallerImpl.java b/src/dynamo-framework/com/silverwrist/dynamo/module/InstallerImpl.java new file mode 100644 index 0000000..02f4410 --- /dev/null +++ b/src/dynamo-framework/com/silverwrist/dynamo/module/InstallerImpl.java @@ -0,0 +1,231 @@ +/* + * 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 . + * + * 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 , + * 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): + */ +package com.silverwrist.dynamo.module; + +import java.io.*; +import java.sql.*; +import java.util.*; +import org.w3c.dom.*; +import com.silverwrist.util.*; +import com.silverwrist.util.xml.*; +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.iface.*; + +class InstallerImpl implements DatabaseInstaller +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private DBConnectionPool m_pool; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + InstallerImpl(DBConnectionPool pool) + { + m_pool = pool; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Internal operations + *-------------------------------------------------------------------------------- + */ + + private static final List loadCommandList(InputStream stm, DynamoLog log) throws ModuleException + { + XMLLoader loader = XMLLoader.get(); + try + { // load the script, parse it, and get the list of elements + Document doc = loader.load(stm,false); + Element elt = loader.getRootElement(doc,"database-info"); + return loader.getMatchingSubElements(elt,"command"); + + } // end try + catch (IOException e) + { // translate to a ModuleException + log.error("I/O error loading script",e); + ModuleException me = new ModuleException(InstallerImpl.class,"ModuleMessages","dbInstall.scriptIO",e); + me.setParameter(0,e.getMessage()); + throw me; + + } // end catch + catch (XMLLoadException e) + { // translate to a ModuleException + log.error("XML error loading script",e); + ModuleException me = new ModuleException(InstallerImpl.class,"ModuleMessages","dbInstall.parser",e); + me.setParameter(0,e.getMessage()); + throw me; + + } // end catch + + } // end loadCommandList + + private static final List makeInstallList(List in_list) throws ModuleException + { + LinkedList rc = new LinkedList(); + Iterator it = in_list.iterator(); + while (it.hasNext()) + { // look through each command and find the sub-element + Element elt = (Element)(it.next()); + DOMElementHelper h = new DOMElementHelper(elt); + Element t = h.getSubElement("install"); + if (t!=null) + { // get the install command + String[] dat = new String[2]; + dat[0] = h.getSubElementText("install"); + if (dat[0]!=null) + { // store the command in the list + dat[0] = dat[0].trim(); + if (t.hasAttribute("log")) + dat[1] = t.getAttribute("log"); + else + dat[1] = null; + rc.addLast(dat); + + } // end if + + } // end if + + } // end while + + return rc; + + } // end makeInstallList + + private static final List makeUninstallList(List in_list) throws ModuleException + { + LinkedList rc = new LinkedList(); + Iterator it = in_list.iterator(); + while (it.hasNext()) + { // look through each command and find the sub-element + Element elt = (Element)(it.next()); + DOMElementHelper h = new DOMElementHelper(elt); + Element t = h.getSubElement("uninstall"); + if (t!=null) + { // get the install command + String[] dat = new String[2]; + dat[0] = h.getSubElementText("uninstall"); + if (dat[0]!=null) + { // store the command in the list + dat[0] = dat[0].trim(); + if (t.hasAttribute("log")) + dat[1] = t.getAttribute("log"); + else + dat[1] = null; + rc.addFirst(dat); + + } // end if + + } // end if + + } // end while + + return rc; + + } // end makeUninstallList + + private final void execList(List cmds, DynamoLog log) throws ModuleException + { + Connection conn = null; + Statement stmt = null; + try + { // get a database connection + conn = m_pool.getConnection(); + stmt = conn.createStatement(); + + // loop through the commands + Iterator it = cmds.iterator(); + while (it.hasNext()) + { // pull out each item in turn + String[] item = (String[])(it.next()); + try + { // execute the SQL statement + stmt.executeUpdate(item[0]); + if (item[1]!=null) + log.info("Success: " + item[1]); + + } // end try + catch (SQLException e) + { // log error and throw message + log.error("Failure: " + ((item[1]==null) ? "statement execution" : item[1]),e); + log.debug("Statement: " + item[0]); + ModuleException me = new ModuleException(InstallerImpl.class,"ModuleMessages","dbInstall.exec",e); + me.setParameter(0,e.getMessage()); + throw me; + + } // end catch + + } // end while + + } // end try + catch (DatabaseException e) + { // throw exception + ModuleException me = new ModuleException(InstallerImpl.class,"ModuleMessages","dbInstall.execInit",e); + me.setParameter(0,e.getMessage()); + throw me; + + } // end catch + catch (SQLException e) + { // throw exception + ModuleException me = new ModuleException(InstallerImpl.class,"ModuleMessages","dbInstall.execInit",e); + me.setParameter(0,e.getMessage()); + throw me; + + } // end catch + finally + { // make sure we shut down the connection before we go + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(conn); + + } // end finally + + } // end execList + + /*-------------------------------------------------------------------------------- + * Implementations from interface DatabaseInstaller + *-------------------------------------------------------------------------------- + */ + + public String getDatabaseType() + { + return m_pool.getDatabaseType(); + + } // end getDatabaseType + + public void runInstallScript(InputStream script, DynamoLog log) throws ModuleException + { + List in_list = loadCommandList(script,log); + List the_list = makeInstallList(in_list); + execList(the_list,log); + + } // end runInstallScript + + public void runUninstallScript(InputStream script, DynamoLog log) throws ModuleException + { + List in_list = loadCommandList(script,log); + List the_list = makeUninstallList(in_list); + execList(the_list,log); + + } // end runUninstallScript + +} // end class InstallerImpl diff --git a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleManager.java b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleManager.java index ad07629..4a25a84 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleManager.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleManager.java @@ -153,7 +153,7 @@ public class ModuleManager implements NamedObject, ComponentInitialize, Componen public void initialize(Element config_root, ServiceProvider services) throws ConfigException { XMLLoader loader = XMLLoader.get(); - String mod_dir = null, conn_name = null, nscache_name = null; + String mod_dir = null, conn_name = null, nscache_name = null, install_conn_name = null; ConfigData cfg_data = null; try { // verify the right node name @@ -171,6 +171,10 @@ public class ModuleManager implements NamedObject, ComponentInitialize, Componen conn_name = loader.getAttribute(elt,"connection"); nscache_name = loader.getAttribute(elt,"namespaces"); + // get the name of the connection to use for database installation + elt = loader.getSubElement(config_root_h,"install"); + install_conn_name = loader.getAttribute(elt,"connection"); + // get the module configuration data elt = loader.getSubElement(config_root_h,"config-db"); cfg_data = new ConfigData(elt); @@ -190,6 +194,9 @@ public class ModuleManager implements NamedObject, ComponentInitialize, Componen // Get the database operations object. m_ops = ModuleDBOps.get(pool); + // Get the installation connection pool. + pool = GetObjectUtils.getDatabaseConnection(services,install_conn_name); + // Get the application container. ObjectProvider op = (ObjectProvider)(services.queryService(ObjectProvider.class)); m_appcon = (ApplicationContainer)(op.getObject(Namespaces.DYNAMO_APPLICATION_NAMESPACE,"__container__")); @@ -207,6 +214,7 @@ public class ModuleManager implements NamedObject, ComponentInitialize, Componen // Get the install service manager and set up the install service provider. m_instservice = new InstallServiceManager(); m_instservice.addService(ModuleConfigurationData.class,(ModuleConfigurationData)cfg_data); + m_instservice.addService(DatabaseInstaller.class,new InstallerImpl(pool)); m_install_services = m_instservice.getServiceProvider(m_appcon.getInitServices()); // Hook this into the service providers. diff --git a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleMessages.properties b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleMessages.properties index 72c4a27..786890a 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleMessages.properties +++ b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleMessages.properties @@ -24,4 +24,8 @@ jar.readError=Unable to read module file "{0}". class.noLoad=Unable to load module main class "{1}" from module file "{0}". class.noCreate=Unable to create module main class "{1}" in module file "{0}". module.noAuth=You are not permitted to install the module "{0}". -module.alreadyInit=The module "{0}" is already initialized and cannot be installed. \ No newline at end of file +module.alreadyInit=The module "{0}" is already initialized and cannot be installed. +dbInstall.scriptIO=I/O error loading the XML script: {0} +dbInstall.parser=XML error loading the script: {0} +dbInstall.exec=Error executing SQL statement: {0} +dbInstall.execInit=Error initializing database for SQL exec: {0}