Author: bdaw
Date: 2009-05-11 07:57:05 -0400 (Mon, 11 May 2009)
New Revision: 490
Added:
idm/trunk/example/simple/
Removed:
idm/trunk/example/maven2/
Modified:
idm/trunk/assembly/pom.xml
idm/trunk/distro/scripts/assembly-deploy-artifacts.xml
idm/trunk/example/simple/pom.xml
idm/trunk/example/simple/src/test/resources/hibernate-jboss-identity-classes.cfg.xml
idm/trunk/idm-api/pom.xml
idm/trunk/idm-auth/pom.xml
idm/trunk/idm-cache/pom.xml
idm/trunk/idm-common/pom.xml
idm/trunk/idm-core/pom.xml
idm/trunk/idm-hibernate/pom.xml
idm/trunk/idm-ldap/pom.xml
idm/trunk/idm-spi/pom.xml
idm/trunk/idm-testsuite/pom.xml
idm/trunk/integration/jboss5/pom.xml
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMService.java
idm/trunk/integration/jboss5/src/main/resources/jboss.idm.hibernate.cfg.xml
idm/trunk/integration/pom.xml
idm/trunk/parent/pom.xml
idm/trunk/pom.xml
Log:
- changes in IDMService
- maven groupId change to org.jboss.identity.idm
- example dir/artifact rename
- attache examples to the main build
Modified: idm/trunk/assembly/pom.xml
===================================================================
--- idm/trunk/assembly/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/assembly/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,12 +1,12 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-assemply</artifactId>
<packaging>pom</packaging>
<name>JBoss Identity IDM - Assembly</name>
Modified: idm/trunk/distro/scripts/assembly-deploy-artifacts.xml
===================================================================
--- idm/trunk/distro/scripts/assembly-deploy-artifacts.xml 2009-05-10 19:15:26 UTC (rev
489)
+++ idm/trunk/distro/scripts/assembly-deploy-artifacts.xml 2009-05-11 11:57:05 UTC (rev
490)
@@ -72,10 +72,26 @@
<outputDirectory>src</outputDirectory>
</fileSet>
<fileSet>
- <directory>../idm/src/main/java</directory>
+ <directory>../idm-core/src/main/java</directory>
<outputDirectory>src</outputDirectory>
</fileSet>
<fileSet>
+ <directory>../idm-hibernate/src/main/java</directory>
+ <outputDirectory>src</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>../idm-ldap/src/main/java</directory>
+ <outputDirectory>src</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>../idm-cache/src/main/java</directory>
+ <outputDirectory>src</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>../idm-auth/src/main/java</directory>
+ <outputDirectory>src</outputDirectory>
+ </fileSet>
+ <fileSet>
<directory>../integration/jboss5/src/main/java</directory>
<outputDirectory>src</outputDirectory>
</fileSet>
Copied: idm/trunk/example/simple (from rev 485, idm/trunk/example/maven2)
Modified: idm/trunk/example/simple/pom.xml
===================================================================
--- idm/trunk/example/maven2/pom.xml 2009-05-09 11:10:49 UTC (rev 485)
+++ idm/trunk/example/simple/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,10 +1,10 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm.example</groupId>
<version>1.0.0-SNAPSHOT</version>
- <artifactId>idm-maven2-example</artifactId>
+ <artifactId>example-simple</artifactId>
<packaging>jar</packaging>
- <name>JBoss Identity IDM Maven2 example project</name>
+ <name>Simple JBoss Identity IDM Maven2 example project</name>
<
url>http://labs.jboss.org/portal/jbosssecurity/</url>
<description>Example maven2 project using JBoss Identity IDM
component.</description>
<licenses>
@@ -42,11 +42,26 @@
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
- <artifactId>idm</artifactId>
+ <groupId>org.jboss.identity.idm</groupId>
+ <artifactId>idm-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.jboss.identity.idm</groupId>
+ <artifactId>idm-hibernate</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.identity.idm</groupId>
+ <artifactId>idm-ldap</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.identity.idm</groupId>
+ <artifactId>idm-cache</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
Modified:
idm/trunk/example/simple/src/test/resources/hibernate-jboss-identity-classes.cfg.xml
===================================================================
---
idm/trunk/example/maven2/src/test/resources/hibernate-jboss-identity-classes.cfg.xml 2009-05-09
11:10:49 UTC (rev 485)
+++
idm/trunk/example/simple/src/test/resources/hibernate-jboss-identity-classes.cfg.xml 2009-05-11
11:57:05 UTC (rev 490)
@@ -53,6 +53,7 @@
<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectAttribute"/>
<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectTextAttribute"/>
<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectBinaryAttribute"/>
+ <mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectBinaryAttributeValue"/>
<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectType"/>
<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectRelationship"/>
<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectRelationshipType"/>
Modified: idm/trunk/idm-api/pom.xml
===================================================================
--- idm/trunk/idm-api/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/idm-api/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,6 +1,6 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
@@ -28,7 +28,7 @@
</scm>
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-common</artifactId>
<version>${project.version}</version>
</dependency>
Modified: idm/trunk/idm-auth/pom.xml
===================================================================
--- idm/trunk/idm-auth/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/idm-auth/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,6 +1,6 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
@@ -28,12 +28,12 @@
</scm>
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-api</artifactId>
<version>${project.version}</version>
</dependency>
Modified: idm/trunk/idm-cache/pom.xml
===================================================================
--- idm/trunk/idm-cache/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/idm-cache/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,6 +1,6 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
@@ -29,7 +29,7 @@
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-core</artifactId>
<version>${project.version}</version>
</dependency>
Modified: idm/trunk/idm-common/pom.xml
===================================================================
--- idm/trunk/idm-common/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/idm-common/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,6 +1,6 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
Modified: idm/trunk/idm-core/pom.xml
===================================================================
--- idm/trunk/idm-core/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/idm-core/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,6 +1,6 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
@@ -29,17 +29,17 @@
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-spi</artifactId>
<version>${project.version}</version>
</dependency>
Modified: idm/trunk/idm-hibernate/pom.xml
===================================================================
--- idm/trunk/idm-hibernate/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/idm-hibernate/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,6 +1,6 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
@@ -29,7 +29,7 @@
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-core</artifactId>
<version>${project.version}</version>
</dependency>
Modified: idm/trunk/idm-ldap/pom.xml
===================================================================
--- idm/trunk/idm-ldap/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/idm-ldap/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,6 +1,6 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
@@ -29,7 +29,7 @@
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-core</artifactId>
<version>${project.version}</version>
</dependency>
Modified: idm/trunk/idm-spi/pom.xml
===================================================================
--- idm/trunk/idm-spi/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/idm-spi/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,6 +1,6 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
@@ -28,7 +28,7 @@
</scm>
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-common</artifactId>
<version>${project.version}</version>
</dependency>
Modified: idm/trunk/idm-testsuite/pom.xml
===================================================================
--- idm/trunk/idm-testsuite/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/idm-testsuite/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,6 +1,6 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
@@ -29,23 +29,23 @@
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-cache</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-hibernate</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-ldap</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-core</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
Modified: idm/trunk/integration/jboss5/pom.xml
===================================================================
--- idm/trunk/integration/jboss5/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/integration/jboss5/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -11,7 +11,7 @@
<version>1.0.0-SNAPSHOT</version>
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-integration</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
@@ -23,31 +23,41 @@
<dependencies>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-core</artifactId>
<version>${version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-hibernate</artifactId>
<version>${version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-ldap</artifactId>
<version>${version}</version>
</dependency>
<dependency>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-cache</artifactId>
<version>${version}</version>
</dependency>
<dependency>
+ <groupId>org.jboss.portal.common</groupId>
+ <artifactId>common-common</artifactId>
+ <version>1.2.3</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-system-jmx</artifactId>
<version>${jboss.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>bsh</groupId>
+ <artifactId>bsh</artifactId>
+ <version>1.3.0</version>
+ </dependency>
</dependencies>
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-05-10
19:15:26 UTC (rev 489)
+++
idm/trunk/integration/jboss5/src/main/java/org/jboss/identity/idm/integration/jboss5/IDMService.java 2009-05-11
11:57:05 UTC (rev 490)
@@ -11,21 +11,44 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.DatabaseMetaData;
import java.util.logging.Logger;
+import java.util.Iterator;
+import java.util.Collection;
+import java.lang.reflect.Method;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.jboss.aop.microcontainer.aspects.jmx.JMX;
import org.jboss.identity.idm.api.IdentitySessionFactory;
+import org.jboss.identity.idm.api.cfg.IdentityConfiguration;
import org.jboss.identity.idm.impl.configuration.IdentityConfigurationImpl;
+import org.jboss.portal.common.util.LoaderResource;
+import org.jboss.portal.common.util.CLResourceLoader;
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.net.URLTools;
+import org.hibernate.Session;
+import org.hibernate.Query;
+import org.hibernate.SessionFactory;
+import org.hibernate.dialect.DialectFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.tool.hbm2ddl.SchemaUpdate;
+import org.hibernate.exception.SQLGrammarException;
+import org.hibernate.metadata.ClassMetadata;
+import bsh.Interpreter;
+import bsh.EvalError;
/**
* Start the {@link IdentitySessionFactory}, and register it in the JNDI.
*
* @author Jeff Yu
- *
+ * @author Boleslaw Dawidowicz
+ * @author Julien Viet
*/
@JMX(exposedInterface=IDMServiceMBean.class,
name="jboss.identity:service=IDMService")
public class IDMService implements IDMServiceMBean {
@@ -33,20 +56,54 @@
public final static String DEFAULT_JNDI = "java:/IdentitySessionFactory";
private static Logger logger = Logger.getLogger(IDMService.class.getName());
-
+
+ /** doCheck result - schema ok */
+ private static final int RESULT_NONE = 0;
+
+ /** doCheck result - schema need updates */
+ private static final int RESULT_UPDATE = 1;
+
+ /** doCheck result - schema not exist */
+ private static final int RESULT_CREATE = 2;
+
+ /** Hibernate config - if specified will be used to create SessionFactory*/
+ private String hibernateConfigLocation;
+
+ /** If hibernateConfigLocation option is present created SessionFactory will be
registered in IdentityConfigurationRegistry
+ * with this name*/
+ private String hibernateSessionFactoryRegistryName;
+
+ /** If hibernateConfigLocation option is present created SessionFactory will be
registered in JNDI with this name*/
+ private String hibernateSessionFactoryJNDIName;
+
+ /** BSH script. If "doChecking" option is set and schema need to be created
provided script will be invoked. This will
+ * happen after IdentitySessionFactory is created. hibernateSessionFactory and
identitySessionFactory object
+ * are accessible in the script. */
+ private String setupLocation;
+
+ /** If true checks the schema existence on start and create it if necessary. */
+ private boolean doChecking;
+
private String idmConfigFile;
private String idmSessionFactoryJNDI;
private String SQLScript;
- private IdentitySessionFactory sessionFactory;
-
+ private IdentitySessionFactory identitySessionFactory;
+
+ private SessionFactory hibernateSessionFactory;
+
private String exitSQL;
private String datasource;
-
- public IDMService(String idmConfigFile) {
+
+ /** The hibernate configuration object. */
+ protected Configuration config;
+
+
+
+ public IDMService(String idmConfigFile) {
this.idmConfigFile = idmConfigFile;
this.idmSessionFactoryJNDI = DEFAULT_JNDI;
}
@@ -70,30 +127,157 @@
public void setSQLScript(String script) {
SQLScript = script;
}
-
-
- public void start() throws Exception {
+
+ public String getHibernateConfigLocation()
+ {
+ return hibernateConfigLocation;
+ }
+
+ public void setHibernateConfigLocation(String hibernateConfigLocation)
+ {
+ this.hibernateConfigLocation = hibernateConfigLocation;
+ }
+
+ public String getSetupLocation()
+ {
+ return setupLocation;
+ }
+
+ public void setSetupLocation(String setupLocation)
+ {
+ this.setupLocation = setupLocation;
+ }
+
+ public boolean isDoChecking()
+ {
+ return doChecking;
+ }
+
+ public void setDoChecking(boolean doChecking)
+ {
+ this.doChecking = doChecking;
+ }
+
+ public String getHibernateSessionFactoryRegistryName()
+ {
+ return hibernateSessionFactoryRegistryName;
+ }
+
+ public void setHibernateSessionFactoryRegistryName(String
hibernateSessionFactoryRegistryName)
+ {
+ this.hibernateSessionFactoryRegistryName = hibernateSessionFactoryRegistryName;
+ }
+
+ public String getHibernateSessionFactoryJNDIName()
+ {
+ return hibernateSessionFactoryJNDIName;
+ }
+
+ public void setHibernateSessionFactoryJNDIName(String
hibernateSessionFactoryJNDIName)
+ {
+ this.hibernateSessionFactoryJNDIName = hibernateSessionFactoryJNDIName;
+ }
+
+ public void start() throws Exception {
logger.info("Starting the JBoss Identity Management Service");
if (needToInitializeDB()) {
initializeDB();
}
- sessionFactory = new
IdentityConfigurationImpl().configure(getIdmConfigFile()).buildIdentitySessionFactory();
- InitialContext context = new InitialContext();
- context.bind(getIdmSessionFactoryJNDI(), sessionFactory);
+
+ InitialContext context = new InitialContext();
+
+ IdentityConfiguration identityConfiguration = new
IdentityConfigurationImpl().configure(getIdmConfigFile());
+
+ // If hibernate config is present than create SessionFactory manually and register
it into identity config
+ if (hibernateConfigLocation != null)
+ {
+ URL configURL =
Thread.currentThread().getContextClassLoader().getResource(hibernateConfigLocation);
+ if (configURL == null)
+ {
+ throw new Exception("The config " + hibernateConfigLocation +
" does not exist");
+ }
+
+ if (!URLTools.exists(configURL))
+ {
+ throw new Exception("The config " + configURL + " does not
exist");
+ }
+
+ config = new AnnotationConfiguration().configure(configURL);
+
+ createHibernateSessionFactory();
+
+// if (getHibernateSessionFactoryJNDIName() != null)
+// {
+// context.bind(getHibernateSessionFactoryJNDIName(),
hibernateSessionFactory);
+// }
+
+ if (getHibernateSessionFactoryRegistryName() != null)
+ {
+ identityConfiguration.getIdentityConfigurationRegistry().
+ register(hibernateSessionFactory,
getHibernateSessionFactoryRegistryName());
+ }
+
+ identitySessionFactory = identityConfiguration.buildIdentitySessionFactory();
+ }
+
+ int check = RESULT_NONE;
+
+ if (doChecking)
+ {
+ //check the schema
+ check = doCheck();
+ switch (check)
+ {
+ case RESULT_NONE:
+ break;
+ case RESULT_UPDATE:
+ updateSchema();
+ break;
+ case RESULT_CREATE:
+ createSchema();
+ break;
+ }
+ }
+
+ identitySessionFactory = identityConfiguration.buildIdentitySessionFactory();
+
+ // If schema was created than
+ if (check == RESULT_CREATE)
+ {
+ createContent();
+ }
+
+
+ context.bind(getIdmSessionFactoryJNDI(), identitySessionFactory);
logger.info("Started the JBoss Identity Management Service");
}
-
- public void stop() throws Exception {
+
+
+
+ public void stop() throws Exception {
logger.info("Stopping the JBoss Identity Management Service");
}
public void destroy() throws Exception {
- sessionFactory.close();
+ identitySessionFactory.close();
InitialContext context = new InitialContext();
context.unbind(getIdmSessionFactoryJNDI());
+ if (hibernateSessionFactory != null)
+ {
+ if (getHibernateSessionFactoryJNDIName() != null)
+ {
+ context.unbind(getHibernateSessionFactoryJNDIName());
+
+ }
+
+ hibernateSessionFactory.close();
+ }
+
logger.info("Stopped the JBoss Identity Management Service");
}
+
+
public String getExitSQL() {
return exitSQL;
}
@@ -158,7 +342,7 @@
{
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
+ sql = sql.replaceAll("(?m)^SessionFactory --([^\n]+)?$", ""); //
Remove all commented lines
final String[] statements ;
statements = sql.split(";");
@@ -201,4 +385,224 @@
}
+ private void createHibernateSessionFactory() throws Exception
+ {
+
+ // Force transaction manager lookup class and JTA env
+// setPropertyIfAbsent("transaction.auto_close_session",
"true");
+// setPropertyIfAbsent("transaction.flush_before_completion",
"true");
+// setPropertyIfAbsent("hibernate.transaction.flush_before_completion",
"true");
+// setPropertyIfAbsent("hibernate.transaction.factory_class",
"org.hibernate.transaction.JTATransactionFactory");
+// setPropertyIfAbsent("hibernate.transaction.manager_lookup_class",
"org.hibernate.transaction.JBossTransactionManagerLookup");
+
+ // Set JNDI name if present and absent
+ if (getHibernateSessionFactoryJNDIName() != null)
+ {
+ setPropertyIfAbsent("hibernate.session_factory_name",
getHibernateSessionFactoryJNDIName());
+ }
+
+ // Detect the dialect if necessary
+ String dialectName = config.getProperty(Environment.DIALECT);
+ if (dialectName == null)
+ {
+ String dataSourceJNDI = config.getProperty(Environment.DATASOURCE);
+ logger.finer("Detecting dialect with datasource " + dataSourceJNDI +
" ...");
+ DataSource ds = (DataSource)new InitialContext().lookup(dataSourceJNDI);
+ Connection conn = null;
+ try
+ {
+ conn = ds.getConnection();
+ DatabaseMetaData meta = conn.getMetaData();
+ String databaseName = meta.getDatabaseProductName();
+ int databaseMajorVersion = getDatabaseMajorVersion(meta);
+ dialectName = DialectFactory.determineDialect(databaseName,
databaseMajorVersion).getClass().getName();
+ config.setProperty(Environment.DIALECT, dialectName);
+ logger.finer("Detected dialect " + dialectName + ", database
is (" + databaseName + "," + databaseMajorVersion + ")");
+ }
+ finally
+ {
+ IOTools.safeClose(conn);
+ }
+ }
+ logger.finer("Using dialect " + dialectName);
+ if ("org.hibernate.dialect.HSQLDialect".equals(dialectName))
+ {
+ logger.info("You are using the file based HSQL database, this is not
recommended on a production environment and will not work properly on a clustered
environment.");
+ }
+
+ hibernateSessionFactory = config.buildSessionFactory();
+
+
+
+ }
+
+
+
+ private void setPropertyIfAbsent(String name, String value)
+ {
+ if (config.getProperty(name) == null)
+ {
+ config.setProperty(name, value);
+ }
+ }
+
+ public int doCheck()
+ {
+ Session session = null;
+ int numOfChecks = 0;
+ int bad = 0;
+ try
+ {
+ session = hibernateSessionFactory.openSession();
+ Collection values = hibernateSessionFactory.getAllClassMetadata().values();
+ numOfChecks = values.size();
+ for (Iterator i = values.iterator(); i.hasNext();)
+ {
+ ClassMetadata cmd = (ClassMetadata)i.next();
+ Query query = session.createQuery("from " + cmd.getEntityName());
+ query.setFirstResult(0);
+ query.setMaxResults(0);
+ try
+ {
+ query.list();
+ }
+ catch (SQLGrammarException e)
+ {
+ // We consider that exception means that the schema does not exist
+ bad++;
+ }
+ }
+ }
+ finally
+ {
+ IOTools.safeClose(session);
+ }
+ // There was no sql grammar exception - schema is ok!
+ if (bad == 0)
+ {
+ logger.finer("The schema was checked as valid");
+ //do nothing
+ return RESULT_NONE;
+ }
+ // There is no existing valid schema;
+ else if (bad == numOfChecks)
+ {
+ logger.finer("The schema was checked as not exists");
+ // Totaly invalid schema
+ return RESULT_CREATE;
+ }
+ // Schema is partialy corrupted
+ else if (bad < numOfChecks)
+ {
+ // Schema needs updates;
+ logger.finer("The schema was checked as need updates");
+ return RESULT_UPDATE;
+ }
+
+ // If here something gone wrong...
+ logger.finer("The schema was checked as need to be created");
+ return RESULT_CREATE;
+ }
+
+
+ public void createSchema()
+ {
+ logger.finer("Creating database schema");
+ try
+ {
+ SchemaExport export = new SchemaExport(config);
+ export.create(false, true);
+ }
+ catch (Exception e)
+ {
+ logger.fine("Cannot create schema: " + e);
+ }
+ }
+
+ public void destroySchema()
+ {
+ logger.finer("Destroying database schema");
+ try
+ {
+ SchemaExport export = new SchemaExport(config);
+ export.drop(false, true);
+ }
+ catch (Exception e)
+ {
+ logger.finer("Cannot destroy schema:" + e);
+ }
+ }
+
+ public void createContent()
+ {
+
+ LoaderResource setupResource = null;
+
+ //
+ if (setupLocation != null && setupResource == null)
+ {
+ setupResource = new CLResourceLoader().getResource(setupLocation);
+ }
+
+ if (setupResource != null)
+ {
+ if (setupResource.exists())
+ {
+ try
+ {
+ logger.fine("Creating database content");
+ String script = setupResource.asString("UTF-8");
+
+ // Create an interpreter and configures it
+ Interpreter interpreter = new Interpreter();
+
interpreter.setClassLoader(Thread.currentThread().getContextClassLoader());
+ interpreter.setOut(System.out);
+ interpreter.set("hibernateSessionFactory",
hibernateSessionFactory);
+ interpreter.set("identitySessionFactory",
identitySessionFactory);
+ interpreter.eval(script);
+ }
+ catch (EvalError e)
+ {
+ logger.finer("Error in the bsh script:" + e);
+ }
+ catch (IllegalStateException e)
+ {
+ logger.finer("Cannot load setup script:" + e);
+ }
+ }
+ else
+ {
+ logger.fine("There is a setup URL but the not valid " +
setupResource);
+ }
+ }
+ }
+
+
+
+ public void updateSchema()
+ {
+ logger.finer("Updating database schema");
+ SchemaUpdate update = new SchemaUpdate(config);
+ update.execute(false, true);
+ }
+
+
+ private int getDatabaseMajorVersion(DatabaseMetaData meta)
+ {
+ try
+ {
+ Method gdbmvMethod =
DatabaseMetaData.class.getMethod("getDatabaseMajorVersion", null);
+ return ((Integer)gdbmvMethod.invoke(meta, null)).intValue();
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ return 0;
+ }
+ catch (Throwable t)
+ {
+ logger.finer("could not get database version from JDBC metadata");
+ return 0;
+ }
+ }
+
}
Modified: idm/trunk/integration/jboss5/src/main/resources/jboss.idm.hibernate.cfg.xml
===================================================================
--- idm/trunk/integration/jboss5/src/main/resources/jboss.idm.hibernate.cfg.xml 2009-05-10
19:15:26 UTC (rev 489)
+++ idm/trunk/integration/jboss5/src/main/resources/jboss.idm.hibernate.cfg.xml 2009-05-11
11:57:05 UTC (rev 490)
@@ -52,6 +52,7 @@
<!--<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectAttribute"/>-->
<!--<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectTextAttribute"/>-->
<!--<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectBinaryAttribute"/>-->
+ <!--<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectBinaryAttributeValue"/>-->
<!--<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectType"/>-->
<!--<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectRelationship"/>-->
<!--<mapping
class="org.jboss.identity.idm.impl.model.hibernate.HibernateIdentityObjectRelationshipType"/>-->
Modified: idm/trunk/integration/pom.xml
===================================================================
--- idm/trunk/integration/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/integration/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -5,13 +5,13 @@
<name>JBoss Identity IDM Integration</name>
<description>JBoss Identity IDM Integration</description>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-integration</artifactId>
<packaging>pom</packaging>
<!-- Parent -->
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
Modified: idm/trunk/parent/pom.xml
===================================================================
--- idm/trunk/parent/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/parent/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -5,7 +5,7 @@
<version>3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
Modified: idm/trunk/pom.xml
===================================================================
--- idm/trunk/pom.xml 2009-05-10 19:15:26 UTC (rev 489)
+++ idm/trunk/pom.xml 2009-05-11 11:57:05 UTC (rev 490)
@@ -1,12 +1,12 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>idm-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>org.jboss.identity</groupId>
+ <groupId>org.jboss.identity.idm</groupId>
<artifactId>jboss-identity-idm-pom</artifactId>
<packaging>pom</packaging>
<name>JBoss Identity - Aggregator</name>
@@ -26,6 +26,7 @@
<module>idm-testsuite</module>
<module>integration</module>
<module>assembly</module>
+ <module>example/simple</module>
</modules>