Author: jeff.yuchang
Date: 2009-04-23 11:09:40 -0400 (Thu, 23 Apr 2009)
New Revision: 456
Added:
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-hsql-jboss-beans.xml
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-mysql-jboss-beans.xml
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-oracle-jboss-beans.xml
Modified:
idm/trunk/distro/scripts/antrun-installer.xml
idm/trunk/distro/src/main/resources/installer/install-definition.xml
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMService.java
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMServiceMBean.java
idm/trunk/integration/jboss5/src/main/resources/META-INF/idm-service-jboss-beans.xml
Log:
Add the schema export into db in IDMService.
(finish the integration)
Modified: idm/trunk/distro/scripts/antrun-installer.xml
===================================================================
--- idm/trunk/distro/scripts/antrun-installer.xml 2009-04-23 10:55:39 UTC (rev 455)
+++ idm/trunk/distro/scripts/antrun-installer.xml 2009-04-23 15:09:40 UTC (rev 456)
@@ -111,6 +111,12 @@
<copy todir="${deploy.artifacts.dir}/resources/datasources">
<fileset
dir="${output.dir}/config.tool.tmp/resolved/jboss/datasource"/>
</copy>
+
+ <!-- copy the idm-service configuration file-->
+ <mkdir dir="${deploy.artifacts.dir}/resources/idm-service-configuration"
/>
+ <copy
todir="${deploy.artifacts.dir}/resources/idm-service-configuration">
+ <fileset
dir="${output.dir}/config.tool.tmp/resolved/jboss/idm-service"/>
+ </copy>
<condition property="database.is.hsqldb" value="true"
else="false">
<equals arg1="${database}" arg2="hsqldb"/>
Added:
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-hsql-jboss-beans.xml
===================================================================
---
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-hsql-jboss-beans.xml
(rev 0)
+++
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-hsql-jboss-beans.xml 2009-04-23
15:09:40 UTC (rev 456)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!--
+ IDM Service
+ -->
+ <bean name="jboss.identity.IDMService"
+ class="org.jboss.identity.idm.integration.jboss5.IDMService">
+ <constructor>
+ <parameter>jboss-idm.xml</parameter>
+ </constructor>
+ <property
name="idmSessionFactoryJNDI">java:/IdentitySessionFactory</property>
+ <property
name="SQLScript">idm-sql/jboss.idm.hsqldb.create.sql</property>
+ <property name="datasource">java:jbossidmDS</property>
+ <property name="exitSQL">select * from jbid_io</property>
+ <depends>jboss.jca:service=DataSourceBinding,name=jbossidmDS</depends>
+ </bean>
+
+</deployment>
\ No newline at end of file
Added:
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-mysql-jboss-beans.xml
===================================================================
---
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-mysql-jboss-beans.xml
(rev 0)
+++
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-mysql-jboss-beans.xml 2009-04-23
15:09:40 UTC (rev 456)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!--
+ IDM Service
+ -->
+ <bean name="jboss.identity.IDMService"
+ class="org.jboss.identity.idm.integration.jboss5.IDMService">
+ <constructor>
+ <parameter>jboss-idm.xml</parameter>
+ </constructor>
+ <property
name="idmSessionFactoryJNDI">java:/IdentitySessionFactory</property>
+ <property
name="SQLScript">idm-sql/jboss.idm.mysql.create.sql</property>
+ <property name="datasource">java:jbossidmDS</property>
+ <property name="exitSQL">select * from jbid_io</property>
+ <depends>jboss.jca:service=DataSourceBinding,name=jbossidmDS</depends>
+ </bean>
+
+</deployment>
\ No newline at end of file
Added:
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-oracle-jboss-beans.xml
===================================================================
---
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-oracle-jboss-beans.xml
(rev 0)
+++
idm/trunk/distro/src/main/resources/config-tool/jboss/idm-service/idm-service-oracle-jboss-beans.xml 2009-04-23
15:09:40 UTC (rev 456)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!--
+ IDM Service
+ -->
+ <bean name="jboss.identity.IDMService"
+ class="org.jboss.identity.idm.integration.jboss5.IDMService">
+ <constructor>
+ <parameter>jboss-idm.xml</parameter>
+ </constructor>
+ <property
name="idmSessionFactoryJNDI">java:/IdentitySessionFactory</property>
+ <property
name="SQLScript">idm-sql/jboss.idm.oracle.create.sql</property>
+ <property name="datasource">java:jbossidmDS</property>
+ <property name="exitSQL">select * from jbid_io</property>
+ <depends>jboss.jca:service=DataSourceBinding,name=jbossidmDS</depends>
+ </bean>
+
+</deployment>
\ No newline at end of file
Modified: idm/trunk/distro/src/main/resources/installer/install-definition.xml
===================================================================
--- idm/trunk/distro/src/main/resources/installer/install-definition.xml 2009-04-23
10:55:39 UTC (rev 455)
+++ idm/trunk/distro/src/main/resources/installer/install-definition.xml 2009-04-23
15:09:40 UTC (rev 456)
@@ -96,14 +96,14 @@
-->
<pack name="jbossIdm Installation Files" required="yes"
preselected="yes">
- <description>Installation directory containing libs, dbscripts, modules and
sources</description>
+ <description>Installation directory containing libs, db.scripts, modules,
resources and source</description>
<!-- jbossidm/doc-->
<file src="(a){deploy.artifacts.dir}/jboss.eula.txt"
targetdir="$INSTALL_PATH" override="true" />
<file src="(a){deploy.artifacts.dir}/license.txt"
targetdir="$INSTALL_PATH" override="true" />
<!-- jbossidm-->
- <fileset dir="(a){deploy.artifacts.dir}/db.scripts"
targetdir="$INSTALL_PATH/db" />
+ <fileset dir="(a){deploy.artifacts.dir}/db.scripts"
targetdir="$INSTALL_PATH/db.scripts" />
<fileset dir="(a){deploy.artifacts.dir}/resources"
targetdir="$INSTALL_PATH/resources" />
<fileset dir="(a){deploy.artifacts.dir}/modules"
targetdir="$INSTALL_PATH/modules" />
<fileset dir="(a){deploy.artifacts.dir}/src"
targetdir="$INSTALL_PATH/src" />
@@ -140,7 +140,10 @@
Database configurations
==============================
-->
-
+ <!-- copy the sql scripts -->
+ <fileset dir="(a){deploy.artifacts.dir}/db.scripts"
+
targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/idm/idm-service.sar/idm-sql"
/>
+
<!-- Database Hypersonic -->
<file
src="(a){deploy.artifacts.dir}/resources/datasources/jbidm-hsqldb-ds.xml"
targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/idm"
@@ -153,7 +156,12 @@
condition="isHypersonic">
<include name="jbossidm.*" />
</fileset>
-
+ <singlefile
src="@{deploy.artifacts.dir}/resources/idm-service-configuration/idm-service-hsql-jboss-beans.xml"
+
target="${jbossInstallPath}/server/${jbossTargetServer}/deploy/idm/idm-service.sar/META-INF/idm-service-jboss-beans.xml"
+ override="true"
+ condition="isHypersonic"
+ />
+
<!-- Database MySQL -->
<file
src="(a){deploy.artifacts.dir}/resources/datasources/jbidm-mysql-ds.xml"
targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/idm"
@@ -167,7 +175,13 @@
condition="isMySQL">
<include name="mysql-connector-java.jar" />
</fileset>
+ <singlefile
src="@{deploy.artifacts.dir}/resources/idm-service-configuration/idm-service-mysql-jboss-beans.xml"
+
target="${jbossInstallPath}/server/${jbossTargetServer}/deploy/idm/idm-service.sar/META-INF/idm-service-jboss-beans.xml"
+ override="true"
+ condition="isMySQL"
+ />
+
<!-- Database Oracle -->
<file
src="(a){deploy.artifacts.dir}/resources/datasources/jbidm-oracle-ds.xml"
targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/idm"
@@ -175,6 +189,11 @@
<fileset dir="(a){deploy.artifacts.dir}/resources/jbidm-oracle-config"
targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/idm/idm-service.sar"
condition="isOracle" />
+ <singlefile
src="@{deploy.artifacts.dir}/resources/idm-service-configuration/idm-service-oracle-jboss-beans.xml"
+
target="${jbossInstallPath}/server/${jbossTargetServer}/deploy/idm/idm-service.sar/META-INF/idm-service-jboss-beans.xml"
+ override="true"
+ condition="isOracle"
+ />
<!-- NOTE: oracle driver needs to be provided manually -->
</pack>
Modified:
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMService.java
===================================================================
---
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMService.java 2009-04-23
10:55:39 UTC (rev 455)
+++
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMService.java 2009-04-23
15:09:40 UTC (rev 456)
@@ -3,9 +3,18 @@
*/
package org.jboss.identity.idm.integration.jboss5;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.logging.Logger;
import javax.naming.InitialContext;
+import javax.sql.DataSource;
import org.jboss.aop.microcontainer.aspects.jmx.JMX;
import org.jboss.identity.idm.api.IdentitySessionFactory;
@@ -33,9 +42,13 @@
private IdentitySessionFactory sessionFactory;
+ private String exitSQL;
+
+ private String datasource;
+
public IDMService(String idmConfigFile) {
this.idmConfigFile = idmConfigFile;
-
+ this.idmSessionFactoryJNDI = DEFAULT_JNDI;
}
public String getIdmConfigFile() {
@@ -61,14 +74,13 @@
public void start() throws Exception {
logger.info("Starting the JBoss Identity Management Service");
- startIdentitySessionFactory();
- logger.info("Started the JBoss Identity Management Service");
- }
-
- private void startIdentitySessionFactory() throws Exception {
+ if (needToInitializeDB()) {
+ initializeDB();
+ }
sessionFactory = new
IdentityConfigurationImpl().configure(getIdmConfigFile()).buildIdentitySessionFactory();
InitialContext context = new InitialContext();
context.bind(getIdmSessionFactoryJNDI(), sessionFactory);
+ logger.info("Started the JBoss Identity Management Service");
}
public void stop() throws Exception {
@@ -82,4 +94,111 @@
logger.info("Stopped the JBoss Identity Management Service");
}
+ public String getExitSQL() {
+ return exitSQL;
+ }
+
+ public void setExitSQL(String exitSQL) {
+ this.exitSQL = exitSQL;
+ }
+
+ public String getDatasource() {
+ return datasource;
+ }
+
+ public void setDatasource(String datasource) {
+ this.datasource = datasource;
+ }
+
+
+ private boolean needToInitializeDB() {
+ if (this.getDatasource() != null &&
+ this.getSQLScript() != null &&
+ this.getExitSQL() != null) {
+ return true;
+ }
+ return false;
+ }
+
+
+ private void initializeDB() throws Exception {
+ DataSource ds = (DataSource)new InitialContext().lookup(datasource);
+ Connection conn = ds.getConnection();
+ boolean load = false;
+
+ Statement st = conn.createStatement();
+ ResultSet rs = null;
+ try
+ {
+ rs = st.executeQuery(exitSQL.trim());
+ rs.close();
+ }
+ catch (SQLException e)
+ {
+ load = true;
+ }
+ st.close();
+ if (!load)
+ {
+ logger.info(datasource + " datasource is already initialized");
+ return;
+ }
+
+ logger.info("Initializing " + datasource + " from listed sql
files");
+
+ String[] list = SQLScript.split(",");
+ for (String sql : list)
+ {
+ executeSql(sql.trim(), conn);
+ }
+
+ }
+
+ private void executeSql(String resource, Connection conn) throws Exception
+ {
+ URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
+ String sql = new String(readStream(url.openStream()) , "UTF-8");
+ sql = sql.replaceAll("(?m)^--([^\n]+)?$", ""); // Remove all
commented lines
+ final String[] statements ;
+ statements = sql.split(";");
+
+ for (String statement : statements)
+ {
+ if ((statement == null) || ("".equals(statement.trim()))) {
+ } else {
+ Statement sqlStatement = conn.createStatement();
+ try
+ {
+ sqlStatement.executeUpdate(statement);
+ }
+ finally
+ {
+ sqlStatement.close();
+ }
+ }
+ }
+ }
+
+
+ private byte[] readStream(InputStream stream) {
+ if(stream == null) {
+ throw new IllegalArgumentException("null 'stream' arg passed in method
call.");
+ }
+
+ ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
+ byte[] buffer = new byte[256];
+ int readCount = 0;
+
+ try {
+ while((readCount = stream.read(buffer)) != -1) {
+ outBuffer.write(buffer, 0, readCount);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Error reading stream.", e);
+ }
+
+ return outBuffer.toByteArray();
+ }
+
+
}
Modified:
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMServiceMBean.java
===================================================================
---
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMServiceMBean.java 2009-04-23
10:55:39 UTC (rev 455)
+++
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMServiceMBean.java 2009-04-23
15:09:40 UTC (rev 456)
@@ -3,11 +3,8 @@
*/
package org.jboss.identity.idm.integration.jboss5;
-import javax.management.ObjectName;
-import org.jboss.mx.util.ObjectNameFactory;
-
/**
*
* Interface for exposing JMX operations.
@@ -17,12 +14,14 @@
*/
public interface IDMServiceMBean {
- ObjectName OBJECT_NAME =
ObjectNameFactory.create("jboss.identity:service=IDMService");
-
String getIdmConfigFile() ;
String getIdmSessionFactoryJNDI();
+ String getDatasource();
+
String getSQLScript();
+
+ String getExitSQL();
}
Modified:
idm/trunk/integration/jboss5/src/main/resources/META-INF/idm-service-jboss-beans.xml
===================================================================
---
idm/trunk/integration/jboss5/src/main/resources/META-INF/idm-service-jboss-beans.xml 2009-04-23
10:55:39 UTC (rev 455)
+++
idm/trunk/integration/jboss5/src/main/resources/META-INF/idm-service-jboss-beans.xml 2009-04-23
15:09:40 UTC (rev 456)
@@ -5,13 +5,15 @@
<!--
IDM Service
-->
- <bean name="jboss.identity:service=IDMService"
+ <bean name="jboss.identity.IDMService"
class="org.jboss.identity.idm.integration.jboss5.IDMService">
<constructor>
<parameter>jboss-idm.xml</parameter>
</constructor>
<property
name="idmSessionFactoryJNDI">java:/IdentitySessionFactory</property>
- <property
name="SQLScript">hsql/idm.create.hsqldb.sql</property>
+ <property
name="SQLScript">idm-sql/jboss.idm.hsql.create.sql</property>
+ <property name="datasource">java:jbossidmDS</property>
+ <property name="exitSQL">select * from jbid_io</property>
<depends>jboss.jca:service=DataSourceBinding,name=jbossidmDS</depends>
</bean>