added database installer service to module install services (built-in)
This commit is contained in:
parent
f8bba8b124
commit
278ad880bb
|
@ -43,6 +43,17 @@
|
||||||
<initialize test="true"/>
|
<initialize test="true"/>
|
||||||
</dbconnection>
|
</dbconnection>
|
||||||
|
|
||||||
|
<!-- Special connection used to install database tables -->
|
||||||
|
<dbconnection name="install" classname="com.silverwrist.dynamo.db.DatabaseConnectionPool">
|
||||||
|
<dbtype>mysql</dbtype>
|
||||||
|
<driver>com.mysql.jdbc.Driver</driver>
|
||||||
|
<uri>jdbc:mysql://localhost/venice</uri>
|
||||||
|
<username>installer</username>
|
||||||
|
<password>ttfn6865611</password>
|
||||||
|
<connections initial="1" max="1" busywait="true"/>
|
||||||
|
<initialize test="true"/>
|
||||||
|
</dbconnection>
|
||||||
|
|
||||||
<!-- Infrastructure objects -->
|
<!-- Infrastructure objects -->
|
||||||
<object name="connector" classname="com.silverwrist.dynamo.app.ConnectionManager" priority="0">
|
<object name="connector" classname="com.silverwrist.dynamo.app.ConnectionManager" priority="0">
|
||||||
<connection-point name="srm_proxy" interface="com.silverwrist.dynamo.db.UserProxyManagement"/>
|
<connection-point name="srm_proxy" interface="com.silverwrist.dynamo.db.UserProxyManagement"/>
|
||||||
|
@ -51,6 +62,7 @@
|
||||||
<object name="module-manager" classname="com.silverwrist.dynamo.module.ModuleManager" priority="2">
|
<object name="module-manager" classname="com.silverwrist.dynamo.module.ModuleManager" priority="2">
|
||||||
<module-directory>${code.path}/modules</module-directory>
|
<module-directory>${code.path}/modules</module-directory>
|
||||||
<database connection="data" namespaces="nscache"/>
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<install connection="install"/>
|
||||||
<config-db>
|
<config-db>
|
||||||
<item ns="http://www.silverwrist.com/NS/dynamo/2002/12/07/dynamo.objects" name="security">srm</item>
|
<item ns="http://www.silverwrist.com/NS/dynamo/2002/12/07/dynamo.objects" name="security">srm</item>
|
||||||
</config-db>
|
</config-db>
|
||||||
|
|
|
@ -43,6 +43,17 @@
|
||||||
<initialize test="true"/>
|
<initialize test="true"/>
|
||||||
</dbconnection>
|
</dbconnection>
|
||||||
|
|
||||||
|
<!-- Special connection used to install database tables -->
|
||||||
|
<dbconnection name="install" classname="com.silverwrist.dynamo.db.DatabaseConnectionPool">
|
||||||
|
<dbtype>mysql</dbtype>
|
||||||
|
<driver>com.mysql.jdbc.Driver</driver>
|
||||||
|
<uri>jdbc:mysql://localhost/venice</uri>
|
||||||
|
<username>installer</username>
|
||||||
|
<password>ttfn6865611</password>
|
||||||
|
<connections initial="1" max="1" busywait="true"/>
|
||||||
|
<initialize test="true"/>
|
||||||
|
</dbconnection>
|
||||||
|
|
||||||
<!-- Infrastructure objects -->
|
<!-- Infrastructure objects -->
|
||||||
<object name="connector" classname="com.silverwrist.dynamo.app.ConnectionManager" priority="0">
|
<object name="connector" classname="com.silverwrist.dynamo.app.ConnectionManager" priority="0">
|
||||||
<connection-point name="srm_proxy" interface="com.silverwrist.dynamo.db.UserProxyManagement"/>
|
<connection-point name="srm_proxy" interface="com.silverwrist.dynamo.db.UserProxyManagement"/>
|
||||||
|
@ -51,6 +62,7 @@
|
||||||
<object name="module-manager" classname="com.silverwrist.dynamo.module.ModuleManager" priority="2">
|
<object name="module-manager" classname="com.silverwrist.dynamo.module.ModuleManager" priority="2">
|
||||||
<module-directory>${code.path}/modules</module-directory>
|
<module-directory>${code.path}/modules</module-directory>
|
||||||
<database connection="data" namespaces="nscache"/>
|
<database connection="data" namespaces="nscache"/>
|
||||||
|
<install connection="install"/>
|
||||||
<config-db>
|
<config-db>
|
||||||
<item ns="http://www.silverwrist.com/NS/dynamo/2002/12/07/dynamo.objects" name="security">srm</item>
|
<item ns="http://www.silverwrist.com/NS/dynamo/2002/12/07/dynamo.objects" name="security">srm</item>
|
||||||
</config-db>
|
</config-db>
|
||||||
|
|
|
@ -518,6 +518,9 @@ GRANT ALL PRIVILEGES ON venice.*
|
||||||
GRANT INSERT, DELETE, UPDATE, SELECT, LOCK TABLES ON venice.*
|
GRANT INSERT, DELETE, UPDATE, SELECT, LOCK TABLES ON venice.*
|
||||||
TO veniceuser@localhost IDENTIFIED BY 'XYZZY0099';
|
TO veniceuser@localhost IDENTIFIED BY 'XYZZY0099';
|
||||||
|
|
||||||
|
GRANT ALL PRIVILEGES ON venice.*
|
||||||
|
TO installer@localhost IDENTIFIED BY 'ttfn6865611';
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Initialization data
|
# Initialization data
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
|
@ -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 <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):
|
||||||
|
*/
|
||||||
|
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
|
|
@ -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 <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):
|
||||||
|
*/
|
||||||
|
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 <command/> 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 <install/> 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 <uninstall/> 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
|
|
@ -153,7 +153,7 @@ public class ModuleManager implements NamedObject, ComponentInitialize, Componen
|
||||||
public void initialize(Element config_root, ServiceProvider services) throws ConfigException
|
public void initialize(Element config_root, ServiceProvider services) throws ConfigException
|
||||||
{
|
{
|
||||||
XMLLoader loader = XMLLoader.get();
|
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;
|
ConfigData cfg_data = null;
|
||||||
try
|
try
|
||||||
{ // verify the right node name
|
{ // verify the right node name
|
||||||
|
@ -171,6 +171,10 @@ public class ModuleManager implements NamedObject, ComponentInitialize, Componen
|
||||||
conn_name = loader.getAttribute(elt,"connection");
|
conn_name = loader.getAttribute(elt,"connection");
|
||||||
nscache_name = loader.getAttribute(elt,"namespaces");
|
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
|
// get the module configuration data
|
||||||
elt = loader.getSubElement(config_root_h,"config-db");
|
elt = loader.getSubElement(config_root_h,"config-db");
|
||||||
cfg_data = new ConfigData(elt);
|
cfg_data = new ConfigData(elt);
|
||||||
|
@ -190,6 +194,9 @@ public class ModuleManager implements NamedObject, ComponentInitialize, Componen
|
||||||
// Get the database operations object.
|
// Get the database operations object.
|
||||||
m_ops = ModuleDBOps.get(pool);
|
m_ops = ModuleDBOps.get(pool);
|
||||||
|
|
||||||
|
// Get the installation connection pool.
|
||||||
|
pool = GetObjectUtils.getDatabaseConnection(services,install_conn_name);
|
||||||
|
|
||||||
// Get the application container.
|
// Get the application container.
|
||||||
ObjectProvider op = (ObjectProvider)(services.queryService(ObjectProvider.class));
|
ObjectProvider op = (ObjectProvider)(services.queryService(ObjectProvider.class));
|
||||||
m_appcon = (ApplicationContainer)(op.getObject(Namespaces.DYNAMO_APPLICATION_NAMESPACE,"__container__"));
|
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.
|
// Get the install service manager and set up the install service provider.
|
||||||
m_instservice = new InstallServiceManager();
|
m_instservice = new InstallServiceManager();
|
||||||
m_instservice.addService(ModuleConfigurationData.class,(ModuleConfigurationData)cfg_data);
|
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());
|
m_install_services = m_instservice.getServiceProvider(m_appcon.getInitServices());
|
||||||
|
|
||||||
// Hook this into the service providers.
|
// Hook this into the service providers.
|
||||||
|
|
|
@ -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.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}".
|
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.noAuth=You are not permitted to install the module "{0}".
|
||||||
module.alreadyInit=The module "{0}" is already initialized and cannot be installed.
|
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}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user