You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by je...@apache.org on 2010/05/02 19:03:00 UTC
svn commit: r940263 [5/16] - in /ode/trunk: ./ axis2-war/
axis2-war/src/main/assembly/
axis2-war/src/main/webapp/WEB-INF/conf.hib-derby/
axis2-war/src/main/webapp/WEB-INF/conf.jpa-derby/
axis2-war/src/main/webapp/WEB-INF/conf/ axis2-war/src/test/java/o...
Modified: ode/trunk/dao-hibernate-db/pom.xml
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate-db/pom.xml?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-hibernate-db/pom.xml (original)
+++ ode/trunk/dao-hibernate-db/pom.xml Sun May 2 17:02:51 2010
@@ -21,7 +21,7 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.ode</groupId>
- <artifactId>ode-dao-hibernate-db</artifactId>
+ <artifactId>ode-dao-hib-db</artifactId>
<name>ODE :: Hibernate DAO DDL Generation</name>
<parent>
@@ -32,8 +32,8 @@
<dependencies>
<dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
@@ -43,88 +43,87 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
- </dependency>
- <dependency>
+ </dependency>
+ <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbytools</artifactId>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derbytools</artifactId>
+ </dependency>
</dependencies>
<build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-antrun-plugin</artifactId>
- <version>1.0</version>
- <executions>
- <execution>
- <id>schemagen</id>
- <phase>generate-sources</phase>
- <configuration>
- <tasks>
- <property name="maven.runtime.classpath" refid="maven.compile.classpath"/>
- <ant antfile="build.xml" target="create-schema" inheritRefs="true"/>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>sql-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>create-derby-db</id>
- <phase>process-resources</phase>
- <goals>
- <goal>execute</goal>
- </goals>
- <configuration>
- <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
- <url>jdbc:derby:${basedir}/target/derby/hibdb;create=true</url>
- <username>sa</username>
- <password />
- <autocommit>true</autocommit>
- <onError>continue</onError>
- <srcFiles>
- <srcFile>target/derby.sql</srcFile>
- </srcFiles>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <id>zip-derby-db</id>
- <phase>package</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <tasks>
- <property name="ode.version" value="${project.version}"/>
- <ant antfile="build.xml" target="zip-derby-db" />
- </tasks>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create-db-schemas</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <property name="maven.runtime.classpath" refid="maven.compile.classpath"/>
+ <ant antfile="build.xml" target="create-schema" inheritRefs="true"/>
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>sql-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create-derby-db</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
+ <url>jdbc:derby:${basedir}/target/ode-db-hib;create=true</url>
+ <username>sa</username>
+ <password />
+ <autocommit>true</autocommit>
+ <onError>continue</onError>
+ <srcFiles>
+ <srcFile>target/scripts/derby-hib.sql</srcFile>
+ </srcFiles>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <finalName>ode-db-derby-hib-${project.version}</finalName>
+ <appendAssemblyId>false</appendAssemblyId>
+ <descriptors>
+ <descriptor>src/main/assembly/bin.xml</descriptor>
+ </descriptors>
+ <tarLongFileMode>gnu</tarLongFileMode>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
- </build>
+ </build>
</project>
Added: ode/trunk/dao-hibernate-db/src/main/assembly/bin.xml
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate-db/src/main/assembly/bin.xml?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate-db/src/main/assembly/bin.xml (added)
+++ ode/trunk/dao-hibernate-db/src/main/assembly/bin.xml Sun May 2 17:02:51 2010
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<assembly>
+ <!-- id typically identifies the "type" (src vs bin etc) of the assembly -->
+ <id></id>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <fileSets>
+ <fileSet>
+ <outputDirectory>/</outputDirectory>
+ <directory>target</directory>
+ <includes>
+ <include>scripts/*.sql</include>
+ <include>ode-db-hib/**</include>
+ </includes>
+ <excludes>
+ <exclude>partial.*.sql</exclude>
+ </excludes>
+ </fileSet>
+ </fileSets>
+
+
+</assembly>
Modified: ode/trunk/dao-hibernate-db/src/main/sql/ode.derby.properties
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate-db/src/main/sql/ode.derby.properties?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-hibernate-db/src/main/sql/ode.derby.properties (original)
+++ ode/trunk/dao-hibernate-db/src/main/sql/ode.derby.properties Sun May 2 17:02:51 2010
@@ -42,7 +42,7 @@ hibernate.hbm2ddl.auto = update
# Hibernate / JTA Session Management Conifguration
hibernate.current_session_context_class=jta
-hibernate.transaction.manager_lookup_class=org.apache.ode.daohib.HibernateTransactionManagerLookup
+hibernate.transaction.manager_lookup_class=org.apache.ode.dao.hib.HibernateTransactionManagerLookup
# see Query Language Changes http://www.hibernate.org/250.html: here to prevent
Modified: ode/trunk/dao-hibernate-db/src/main/sql/ode.firebird.properties
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate-db/src/main/sql/ode.firebird.properties?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-hibernate-db/src/main/sql/ode.firebird.properties (original)
+++ ode/trunk/dao-hibernate-db/src/main/sql/ode.firebird.properties Sun May 2 17:02:51 2010
@@ -43,7 +43,7 @@ hibernate.hbm2ddl.auto = update
# Hibernate / JTA Session Management Conifguration
hibernate.current_session_context_class=jta
-hibernate.transaction.manager_lookup_class=org.apache.ode.daohib.HibernateTransactionManagerLookup
+hibernate.transaction.manager_lookup_class=org.apache.ode.dao.hib.HibernateTransactionManagerLookup
# see Query Language Changes http://www.hibernate.org/250.html: here to prevent
Modified: ode/trunk/dao-hibernate-db/src/main/sql/ode.hsql.properties
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate-db/src/main/sql/ode.hsql.properties?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-hibernate-db/src/main/sql/ode.hsql.properties (original)
+++ ode/trunk/dao-hibernate-db/src/main/sql/ode.hsql.properties Sun May 2 17:02:51 2010
@@ -42,7 +42,7 @@ hibernate.hbm2ddl.auto = update
# Hibernate / JTA Session Management Conifguration
hibernate.current_session_context_class=jta
-hibernate.transaction.manager_lookup_class=org.apache.ode.daohib.HibernateTransactionManagerLookup
+hibernate.transaction.manager_lookup_class=org.apache.ode.dao.hib.HibernateTransactionManagerLookup
# see Query Language Changes http://www.hibernate.org/250.html: here to prevent
Modified: ode/trunk/dao-hibernate-db/src/main/sql/ode.mysql.properties
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate-db/src/main/sql/ode.mysql.properties?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-hibernate-db/src/main/sql/ode.mysql.properties (original)
+++ ode/trunk/dao-hibernate-db/src/main/sql/ode.mysql.properties Sun May 2 17:02:51 2010
@@ -42,7 +42,7 @@ hibernate.hbm2ddl.auto = update
# Hibernate / JTA Session Management Conifguration
hibernate.current_session_context_class=jta
-hibernate.transaction.manager_lookup_class=org.apache.ode.daohib.HibernateTransactionManagerLookup
+hibernate.transaction.manager_lookup_class=org.apache.ode.dao.hib.HibernateTransactionManagerLookup
# see Query Language Changes http://www.hibernate.org/250.html: here to prevent
Modified: ode/trunk/dao-hibernate-db/src/main/sql/ode.oracle.properties
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate-db/src/main/sql/ode.oracle.properties?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-hibernate-db/src/main/sql/ode.oracle.properties (original)
+++ ode/trunk/dao-hibernate-db/src/main/sql/ode.oracle.properties Sun May 2 17:02:51 2010
@@ -42,7 +42,7 @@ hibernate.hbm2ddl.auto = update
# Hibernate / JTA Session Management Conifguration
hibernate.current_session_context_class=jta
-hibernate.transaction.manager_lookup_class=org.apache.ode.daohib.HibernateTransactionManagerLookup
+hibernate.transaction.manager_lookup_class=org.apache.ode.dao.hib.HibernateTransactionManagerLookup
# see Query Language Changes http://www.hibernate.org/250.html: here to prevent
Modified: ode/trunk/dao-hibernate-db/src/main/sql/ode.postgres.properties
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate-db/src/main/sql/ode.postgres.properties?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-hibernate-db/src/main/sql/ode.postgres.properties (original)
+++ ode/trunk/dao-hibernate-db/src/main/sql/ode.postgres.properties Sun May 2 17:02:51 2010
@@ -42,7 +42,7 @@ hibernate.hbm2ddl.auto = update
# Hibernate / JTA Session Management Conifguration
hibernate.current_session_context_class=jta
-hibernate.transaction.manager_lookup_class=org.apache.ode.daohib.HibernateTransactionManagerLookup
+hibernate.transaction.manager_lookup_class=org.apache.ode.dao.hib.HibernateTransactionManagerLookup
# see Query Language Changes http://www.hibernate.org/250.html: here to prevent
Modified: ode/trunk/dao-hibernate-db/src/main/sql/ode.sqlserver.properties
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate-db/src/main/sql/ode.sqlserver.properties?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-hibernate-db/src/main/sql/ode.sqlserver.properties (original)
+++ ode/trunk/dao-hibernate-db/src/main/sql/ode.sqlserver.properties Sun May 2 17:02:51 2010
@@ -42,7 +42,7 @@ hibernate.hbm2ddl.auto = update
# Hibernate / JTA Session Management Conifguration
hibernate.current_session_context_class=jta
-hibernate.transaction.manager_lookup_class=org.apache.ode.daohib.HibernateTransactionManagerLookup
+hibernate.transaction.manager_lookup_class=org.apache.ode.dao.hib.HibernateTransactionManagerLookup
# see Query Language Changes http://www.hibernate.org/250.html: here to prevent
Modified: ode/trunk/dao-hibernate/pom.xml
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/pom.xml?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/pom.xml (original)
+++ ode/trunk/dao-hibernate/pom.xml Sun May 2 17:02:51 2010
@@ -19,11 +19,11 @@
-->
<project>
- <groupId>org.apache.ode</groupId>
- <artifactId>ode-dao-hibernate</artifactId>
- <name>ODE :: Hibernate DAO Implementation</name>
- <packaging>jar</packaging>
- <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.ode</groupId>
+ <artifactId>ode-dao-hibernate</artifactId>
+ <name>ODE :: Hibernate DAO Implementation</name>
+ <packaging>jar</packaging>
+ <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.ode</groupId>
@@ -43,10 +43,7 @@
<dependency>
<groupId>org.apache.ode</groupId>
<artifactId>ode-il-common</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
-
+ </dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
@@ -58,68 +55,57 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
- <version>${slf4j.version}</version>
- <scope>test</scope>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>xdoclet-maven-plugin</artifactId>
- <executions>
- <execution>
- <phase>generate-sources</phase>
- <goals>
- <goal>xdoclet</goal>
- </goals>
- <configuration>
- <tasks>
- <hibernatedoclet excludedTags="@version,@author,@todo" verbose="true"
- destdir="${project.build.outputDirectory}" force="true">
- <hibernate version="3.0"/>
- <fileset dir="${project.build.sourceDirectory}" includes="org/apache/ode/daohib/bpel/hobj/*.java"/>
- </hibernatedoclet>
- </tasks>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <!--doclet does not support not-found="ignore" -->
- <groupId>org.codehaus.groovy.maven</groupId>
- <artifactId>gmaven-plugin</artifactId>
- <executions>
- <execution>
- <phase>process-sources</phase>
- <goals>
- <goal>execute</goal>
- </goals>
- <configuration>
- <source>
- import java.io.File
- def process_instance_hbm_file = new File('${project.build.outputDirectory}', 'org/apache/ode/daohib/bpel/hobj/HProcessInstance.hbm.xml')
- def contents = process_instance_hbm_file.text
- if (!contents.contains('not-found="ignore"')) {
- process_instance_hbm_file.text = contents.replace('class="org.apache.ode.daohib.bpel.hobj.HProcess"',
- 'not-found="ignore" class="org.apache.ode.daohib.bpel.hobj.HProcess"')
- }
- </source>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>xdoclet-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>xdoclet</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <hibernatedoclet excludedTags="@version,@author,@todo" verbose="true"
+ destdir="${project.build.outputDirectory}" force="true">
+ <hibernate version="3.0"/>
+ <fileset dir="${project.build.sourceDirectory}" includes="org/apache/ode/dao/hib/bpel/hobj/*.java,org/apache/ode/dao/hib/store/hobj/*.java"/>
+ </hibernatedoclet>
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <!--doclet does not support not-found="ignore" -->
+ <groupId>org.codehaus.groovy.maven</groupId>
+ <artifactId>gmaven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <source>
+ import java.io.File
+ def process_instance_hbm_file = new File(project.build.outputDirectory, 'org/apache/ode/dao/hib/bpel/hobj/HProcessInstance.hbm.xml')
+ def contents = process_instance_hbm_file.text
+ if (!contents.contains('not-found="ignore"')) {
+ process_instance_hbm_file.text = contents.replace('class="org.apache.ode.dao.hib.bpel.hobj.HProcess"',
+ 'not-found="ignore" class="org.apache.ode.dao.hib.bpel.hobj.HProcess"')
+ }
+ </source>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
+
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/DataSourceConnectionProvider.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/DataSourceConnectionProvider.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/DataSourceConnectionProvider.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/DataSourceConnectionProvider.java Sun May 2 17:02:51 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.hib;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.ode.utils.DbIsolation;
+
+import org.hibernate.HibernateException;
+import org.hibernate.connection.ConnectionProvider;
+
+public class DataSourceConnectionProvider implements ConnectionProvider {
+
+ private Properties _props;
+
+ public DataSourceConnectionProvider() {
+ }
+
+ public void configure(Properties props) throws HibernateException {
+ _props = props;
+ }
+
+ public Connection getConnection() throws SQLException {
+ Connection c = SessionManager.getConnection(_props);
+ DbIsolation.setIsolationLevel(c);
+ return c;
+ }
+
+ public void closeConnection(Connection con) throws SQLException {
+ con.close();
+ }
+
+ public void close() throws HibernateException {
+
+ }
+
+ public boolean supportsAggressiveRelease() {
+ return true;
+ }
+
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/HibernateTransactionManagerLookup.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/HibernateTransactionManagerLookup.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/HibernateTransactionManagerLookup.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/HibernateTransactionManagerLookup.java Sun May 2 17:02:51 2010
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.hib;
+
+import java.util.Properties;
+
+import javax.transaction.TransactionManager;
+import javax.transaction.Transaction;
+
+import org.hibernate.HibernateException;
+import org.hibernate.transaction.TransactionManagerLookup;
+
+/**
+ * Implementation of the {@link org.hibernate.transaction.TransactionManagerLookup} interface that
+ * uses {@link SessionManager} to obtain the JTA {@link TransactionManager} object.
+ */
+public class HibernateTransactionManagerLookup implements TransactionManagerLookup {
+
+ /** Constructor. */
+ public HibernateTransactionManagerLookup() {
+ super();
+ }
+
+ public TransactionManager getTransactionManager(Properties props)
+ throws HibernateException {
+ return SessionManager.getTransactionManager(props);
+ }
+
+ public String getUserTransactionName() {
+ return null;
+ }
+
+ public Object getTransactionIdentifier(Transaction transaction) {
+ return transaction;
+ }
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/JotmTransaction.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/JotmTransaction.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/JotmTransaction.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/JotmTransaction.java Sun May 2 17:02:51 2010
@@ -0,0 +1,360 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.apache.ode.dao.hib;
+
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.Transaction;
+import org.hibernate.TransactionException;
+import org.hibernate.jdbc.JDBCContext;
+import org.hibernate.transaction.TransactionFactory;
+import org.hibernate.util.JTAHelper;
+
+/**
+ * {@link Transaction} implementation based on transaction management through
+ * a JTA {@link UserTransaction}. Similar to {@link CMTTransaction}, except
+ * here we are actually managing the transactions through the Hibernate
+ * transaction mechanism.
+ *
+ * @author Gavin King
+ * @author Steve Ebersole
+ * @author Les Hazlewood
+ *
+ * Scraped from org.hibernate
+ */
+public class JotmTransaction implements Transaction {
+ private static final Log log = LogFactory.getLog( JotmTransaction.class );
+
+ private final JDBCContext jdbcContext;
+ private final TransactionFactory.Context transactionContext;
+
+ private UserTransaction userTransaction;
+ private boolean newTransaction;
+ private boolean begun;
+ private boolean commitFailed;
+ private boolean commitSucceeded;
+ private boolean callback;
+
+ public JotmTransaction(
+ UserTransaction userTransaction,
+ JDBCContext jdbcContext,
+ TransactionFactory.Context transactionContext) {
+ this.jdbcContext = jdbcContext;
+ this.transactionContext = transactionContext;
+ this.userTransaction = userTransaction;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void begin() throws HibernateException {
+ if ( begun ) {
+ return;
+ }
+ if ( commitFailed ) {
+ throw new TransactionException( "cannot re-start transaction after failed commit" );
+ }
+
+ log.debug( "begin" );
+
+ try {
+ newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION;
+ if ( newTransaction ) {
+ userTransaction.begin();
+ log.debug( "Began a new JTA transaction" );
+ }
+ }
+ catch ( Exception e ) {
+ log.error( "JTA transaction begin failed", e );
+ throw new TransactionException( "JTA transaction begin failed", e );
+ }
+
+ /*if (newTransaction) {
+ // don't need a synchronization since we are committing
+ // or rolling back the transaction ourselves - assuming
+ // that we do no work in beforeTransactionCompletion()
+ synchronization = false;
+ }*/
+
+ boolean synchronization = jdbcContext.registerSynchronizationIfPossible();
+
+ if ( !newTransaction && !synchronization ) {
+ log.warn( "You should set hibernate.transaction.manager_lookup_class if cache is enabled" );
+ }
+
+ if ( !synchronization ) {
+ //if we could not register a synchronization,
+ //do the before/after completion callbacks
+ //ourself (but we need to let jdbcContext
+ //know that this is what we are going to
+ //do, so it doesn't keep trying to register
+ //synchronizations)
+ callback = jdbcContext.registerCallbackIfNecessary();
+ }
+
+ begun = true;
+ commitSucceeded = false;
+
+ jdbcContext.afterTransactionBegin( this );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void commit() throws HibernateException {
+ if ( !begun ) {
+ throw new TransactionException( "Transaction not successfully started" );
+ }
+
+ log.debug( "commit" );
+
+ boolean flush = !transactionContext.isFlushModeNever()
+ && ( callback || !transactionContext.isFlushBeforeCompletionEnabled() );
+
+ if ( flush ) {
+ transactionContext.managedFlush(); //if an exception occurs during flush, user must call rollback()
+ }
+
+ if ( callback && newTransaction ) {
+ jdbcContext.beforeTransactionCompletion( this );
+ }
+
+ closeIfRequired();
+
+ if ( newTransaction ) {
+ try {
+ userTransaction.commit();
+ commitSucceeded = true;
+ log.debug( "Committed JTA UserTransaction" );
+ }
+ catch ( Exception e ) {
+ commitFailed = true; // so the transaction is already rolled back, by JTA spec
+ log.error( "JTA commit failed", e );
+ throw new TransactionException( "JTA commit failed: ", e );
+ }
+ finally {
+ afterCommitRollback();
+ }
+ }
+ else {
+ // this one only really needed for badly-behaved applications!
+ // (if the TransactionManager has a Sychronization registered,
+ // its a noop)
+ // (actually we do need it for downgrading locks)
+ afterCommitRollback();
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void rollback() throws HibernateException {
+ if ( !begun && !commitFailed ) {
+ throw new TransactionException( "Transaction not successfully started" );
+ }
+
+ log.debug( "rollback" );
+
+ try {
+ closeIfRequired();
+ }
+ catch ( Exception e ) {
+ // swallow it, and continue to roll back JTA transaction
+ log.error( "could not close session during rollback", e );
+ }
+
+ try {
+ if ( newTransaction ) {
+ if ( !commitFailed ) {
+ userTransaction.rollback();
+ log.debug( "Rolled back JTA UserTransaction" );
+ }
+ }
+ else {
+ userTransaction.setRollbackOnly();
+ log.debug( "set JTA UserTransaction to rollback only" );
+ }
+ }
+ catch ( Exception e ) {
+ log.error( "JTA rollback failed", e );
+ throw new TransactionException( "JTA rollback failed", e );
+ }
+ finally {
+ afterCommitRollback();
+ }
+ }
+
+ private static final int NULL = Integer.MIN_VALUE;
+
+ private void afterCommitRollback() throws TransactionException {
+
+ begun = false;
+ // this method is a noop if there is a Synchronization!
+ if ( callback ) {
+ if ( !newTransaction ) {
+ log.warn( "You should set hibernate.transaction.manager_lookup_class if cache is enabled" );
+ }
+ int status = NULL;
+ try {
+ status = userTransaction.getStatus();
+ }
+ catch ( Exception e ) {
+ log.error( "Could not determine transaction status after commit", e );
+ throw new TransactionException( "Could not determine transaction status after commit", e );
+ }
+ finally {
+ jdbcContext.afterTransactionCompletion( status == Status.STATUS_COMMITTED, this );
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean wasRolledBack() throws TransactionException {
+ final int status;
+ try {
+ status = userTransaction.getStatus();
+ }
+ catch ( SystemException se ) {
+ log.error( "Could not determine transaction status", se );
+ throw new TransactionException( "Could not determine transaction status", se );
+ }
+ if ( status == Status.STATUS_UNKNOWN ) {
+ throw new TransactionException( "Could not determine transaction status" );
+ }
+ else {
+ return JTAHelper.isRollback( status );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean wasCommitted() throws TransactionException {
+ final int status;
+ try {
+ status = userTransaction.getStatus();
+ }
+ catch ( SystemException se ) {
+ log.error( "Could not determine transaction status", se );
+ throw new TransactionException( "Could not determine transaction status: ", se );
+ }
+ if ( status == Status.STATUS_UNKNOWN ) {
+ throw new TransactionException( "Could not determine transaction status" );
+ }
+ else {
+ return status == Status.STATUS_COMMITTED;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isActive() throws TransactionException {
+ if ( !begun || commitFailed || commitSucceeded ) {
+ return false;
+ }
+
+ final int status;
+ try {
+ status = userTransaction.getStatus();
+ }
+ catch ( SystemException se ) {
+ log.error( "Could not determine transaction status", se );
+ throw new TransactionException( "Could not determine transaction status: ", se );
+ }
+ if ( status == Status.STATUS_UNKNOWN ) {
+ throw new TransactionException( "Could not determine transaction status" );
+ }
+ else {
+ return status == Status.STATUS_ACTIVE;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registerSynchronization(Synchronization sync) throws HibernateException {
+ if ( getTransactionManager() == null ) {
+ throw new IllegalStateException( "JTA TransactionManager not available" );
+ }
+ else {
+ try {
+ getTransactionManager().getTransaction().registerSynchronization( sync );
+ }
+ catch ( Exception e ) {
+ throw new TransactionException( "could not register synchronization", e );
+ }
+ }
+ }
+
+ /**
+ * Getter for property 'transactionManager'.
+ *
+ * @return Value for property 'transactionManager'.
+ */
+ private TransactionManager getTransactionManager() {
+ return transactionContext.getFactory().getTransactionManager();
+ }
+
+ private void closeIfRequired() throws HibernateException {
+ boolean close = callback &&
+ transactionContext.shouldAutoClose() &&
+ !transactionContext.isClosed();
+ if ( close ) {
+ transactionContext.managedClose();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setTimeout(int seconds) {
+ try {
+ userTransaction.setTransactionTimeout( seconds );
+ }
+ catch ( SystemException se ) {
+ throw new TransactionException( "could not set transaction timeout", se );
+ }
+ }
+
+ /**
+ * Getter for property 'userTransaction'.
+ *
+ * @return Value for property 'userTransaction'.
+ */
+ protected UserTransaction getUserTransaction() {
+ return userTransaction;
+ }
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/JotmTransactionFactory.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/JotmTransactionFactory.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/JotmTransactionFactory.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/JotmTransactionFactory.java Sun May 2 17:02:51 2010
@@ -0,0 +1,309 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.apache.ode.dao.hib;
+
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.HibernateException;
+import org.hibernate.Transaction;
+import org.hibernate.TransactionException;
+import org.hibernate.jdbc.JDBCContext;
+import org.hibernate.cfg.Environment;
+import org.hibernate.transaction.TransactionFactory;
+import org.hibernate.transaction.TransactionManagerLookup;
+import org.hibernate.transaction.TransactionManagerLookupFactory;
+import org.hibernate.util.NamingHelper;
+import org.hibernate.util.JTAHelper;
+
+/**
+ * Factory for {@link JotmTransaction} instances.
+ * <p/>
+ * To be completely accurate to the JTA spec, JTA implementations should
+ * publish their contextual {@link UserTransaction} reference into JNDI.
+ * However, in practice there are quite a few <tt>stand-alone</tt>
+ * implementations intended for use outside of J2EE/JEE containers and
+ * which therefore do not publish their {@link UserTransaction} references
+ * into JNDI but which otherwise follow the aspects of the JTA specification.
+ * This {@link TransactionFactory} implementation can support both models.
+ * <p/>
+ * For complete JTA implementations (including dependence on JNDI), the
+ * {@link UserTransaction} reference is obtained by a call to
+ * {@link #resolveInitialContext}. Hibernate will then attempt to locate the
+ * {@link UserTransaction} within this resolved
+ * {@link InitialContext} based on the namespace returned by
+ * {@link #resolveUserTransactionName}.
+ * <p/>
+ * For the so-called <tt>stand-alone</tt> implementations, we do not care at
+ * all about the JNDI aspects just described. Here, the implementation would
+ * have a specific manner to obtain a reference to its contextual
+ * {@link UserTransaction}; usually this would be a static code reference, but
+ * again it varies. Anyway, for each implementation the integration would need
+ * to override the {@link #getUserTransaction} method and return the appropriate
+ * thing.
+ *
+ * @author Gavin King
+ * @author Steve Ebersole
+ * @author Les Hazlewood
+ *
+ * Scraped from org.hibernate
+ */
+public class JotmTransactionFactory implements TransactionFactory {
+ public static final String DEFAULT_USER_TRANSACTION_NAME = "java:comp/UserTransaction";
+ private static final Log log = LogFactory.getLog( JotmTransactionFactory.class );
+
+ protected InitialContext initialContext;
+ protected String userTransactionName;
+
+ private TransactionManager txManager;
+
+ /**
+ * Configure this transaction factory. Specifically here we are attempting to
+ * resolve both an {@link #getInitialContext InitialContext} as well as the
+ * {@link #getUserTransactionName() JNDI namespace} for the {@link UserTransaction}.
+ *
+ * @param props The configuration properties
+ *
+ * @exception HibernateException
+ */
+ public void configure(Properties props) throws HibernateException {
+ this.initialContext = resolveInitialContext( props );
+ this.userTransactionName = resolveUserTransactionName( props );
+ log.debug( "Configured JTATransactionFactory to use [" + userTransactionName + "] for UserTransaction JDNI namespace" );
+ txManager = new HibernateTransactionManagerLookup().getTransactionManager(props);
+ }
+
+ /**
+ * Given the lot of Hibernate configuration properties, resolve appropriate
+ * reference to JNDI {@link InitialContext}.
+ * <p/>
+ * In general, the properties in which we are interested here all begin with
+ * <tt>hibernate.jndi</tt>. Especially important depending on your
+ * environment are {@link Environment#JNDI_URL hibernate.jndi.url} and
+ * {@link Environment#JNDI_CLASS hibernate.jndi.class}
+ *
+ * @param properties The Hibernate config properties.
+ * @return The resolved InitialContext.
+ */
+ protected final InitialContext resolveInitialContext(Properties properties) {
+ try {
+ return NamingHelper.getInitialContext( properties );
+ }
+ catch ( NamingException ne ) {
+ throw new HibernateException( "Could not obtain initial context", ne );
+ }
+ }
+
+ /**
+ * Given the lot of Hibernate configuration properties, resolve appropriate
+ * JNDI namespace to use for {@link UserTransaction} resolution.
+ * <p/>
+ * We determine the namespace to use by<ol>
+ * <li>Any specified {@link Environment#USER_TRANSACTION jta.UserTransaction} config property</li>
+ * <li>If a {@link TransactionManagerLookup} was indicated, use its
+ * {@link TransactionManagerLookup#getUserTransactionName}</li>
+ * <li>finally, as a last resort, we use {@link #DEFAULT_USER_TRANSACTION_NAME}</li>
+ * </ol>
+ *
+ * @param properties The Hibernate config properties.
+ * @return The resolved {@link UserTransaction} namespace
+ */
+ protected final String resolveUserTransactionName(Properties properties) {
+ String utName = properties.getProperty( Environment.USER_TRANSACTION );
+ if ( utName == null ) {
+ TransactionManagerLookup lookup = TransactionManagerLookupFactory.getTransactionManagerLookup( properties );
+ if ( lookup != null ) {
+ utName = lookup.getUserTransactionName();
+ }
+ }
+ return utName == null ? DEFAULT_USER_TRANSACTION_NAME : utName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Transaction createTransaction(JDBCContext jdbcContext, Context transactionContext)
+ throws HibernateException {
+ /*
+ * JTA TransactionManager returns a JTA transaction. We need a user transaction to use
+ * hibernate's JTATransactionFactory.
+ */
+ // UserTransaction ut = getUserTransaction();
+ UserTransaction ut;
+ try {
+ ut = new UserTransaction() {
+ javax.transaction.Transaction transaction = txManager.getTransaction();
+ public void begin() throws NotSupportedException, SystemException {
+ // TODO Auto-generated method stub
+ }
+
+ public void commit() throws HeuristicMixedException,
+ HeuristicRollbackException, IllegalStateException,
+ RollbackException, SecurityException, SystemException {
+ transaction.commit();
+ }
+
+ public int getStatus() throws SystemException {
+ // TODO Auto-generated method stub
+ return transaction.getStatus();
+ }
+
+ public void rollback() throws IllegalStateException,
+ SecurityException, SystemException {
+ // TODO Auto-generated method stub
+ transaction.rollback();
+ }
+
+ public void setRollbackOnly() throws IllegalStateException,
+ SystemException {
+ // TODO Auto-generated method stub
+ transaction.setRollbackOnly();
+ }
+
+ public void setTransactionTimeout(int i) throws SystemException {
+ // TODO Auto-generated method stub
+ }
+ };
+ } catch (SystemException e) {
+ throw new HibernateException(e);
+ }
+
+ return new JotmTransaction( ut, jdbcContext, transactionContext );
+ }
+
+ /**
+ * Get the {@link UserTransaction} reference.
+ *
+ * @return The appropriate {@link UserTransaction} reference.
+ */
+ protected UserTransaction getUserTransaction() {
+ final String utName = getUserTransactionName();
+ log.debug( "Attempting to locate UserTransaction via JNDI [" + utName + "]");
+
+ try {
+ UserTransaction ut = ( UserTransaction ) getInitialContext().lookup( utName );
+ if ( ut == null ) {
+ throw new TransactionException( "Naming service lookup for UserTransaction returned null [" + utName +"]" );
+ }
+
+ log.trace( "Obtained UserTransaction" );
+
+ return ut;
+ }
+ catch ( NamingException ne ) {
+ throw new TransactionException( "Could not find UserTransaction in JNDI [" + utName + "]", ne );
+ }
+ }
+
+ /**
+ * Getter for property 'initialContext'.
+ *
+ * @return Value for property 'initialContext'.
+ */
+ protected InitialContext getInitialContext() {
+ return initialContext;
+ }
+
+ /**
+ * Getter for property 'userTransactionName'.
+ * The algorithm here is
+ *
+ * @return Value for property 'userTransactionName'.
+ */
+ protected String getUserTransactionName() {
+ return userTransactionName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ConnectionReleaseMode getDefaultReleaseMode() {
+ return ConnectionReleaseMode.AFTER_STATEMENT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isTransactionManagerRequired() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean areCallbacksLocalToHibernateTransactions() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isTransactionInProgress(
+ JDBCContext jdbcContext,
+ Context transactionContext,
+ Transaction transaction) {
+ try {
+ // Essentially:
+ // 1) If we have a local (Hibernate) transaction in progress
+ // and it already has the UserTransaction cached, use that
+ // UserTransaction to determine the status.
+ // 2) If a transaction manager has been located, use
+ // that transaction manager to determine the status.
+ // 3) Finally, as the last resort, try to lookup the
+ // UserTransaction via JNDI and use that to determine the
+ // status.
+ if ( transaction != null ) {
+ UserTransaction ut = ( ( JotmTransaction ) transaction ).getUserTransaction();
+ if ( ut != null ) {
+ return JTAHelper.isInProgress( ut.getStatus() );
+ }
+ }
+
+ if ( jdbcContext.getFactory().getTransactionManager() != null ) {
+ return JTAHelper.isInProgress( jdbcContext.getFactory().getTransactionManager().getStatus() );
+ }
+ else {
+ UserTransaction ut = getUserTransaction();
+ return ut != null && JTAHelper.isInProgress( ut.getStatus() );
+ }
+ }
+ catch ( SystemException se ) {
+ throw new TransactionException( "Unable to check transaction status", se );
+ }
+ }
+
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/SessionManager.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/SessionManager.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/SessionManager.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/SessionManager.java Sun May 2 17:02:51 2010
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.hib;
+
+import org.apache.ode.dao.hib.bpel.hobj.*;
+import org.apache.ode.utils.uuid.UUID;
+import org.hibernate.HibernateException;
+import org.hibernate.MappingException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.apache.ode.dao.hib.store.hobj.DeploymentUnitDaoImpl;
+import org.apache.ode.dao.hib.store.hobj.ProcessConfDaoImpl;
+import org.apache.ode.dao.hib.store.hobj.VersionTrackerDAOImpl;
+
+/**
+ * Manages hibernate sessions, and their association with
+ * a transaction thread. Uses a ThreadLocal strategy for
+ * managing sessions.
+ */
+public class SessionManager {
+
+ private static final String PROP_GUID = "ode.hibernate.guid";
+ private static final Map<String, TransactionManager> _txManagers =
+ Collections.synchronizedMap(new HashMap<String, TransactionManager>());
+ private static final Map<String, DataSource> _dataSources =
+ Collections.synchronizedMap(new HashMap<String, DataSource>());
+ private static final String[] CANNOT_JOIN_FOR_UPDATE_DIALECTS = {"org.hibernate.dialect.IngresDialect"};
+ private final String _uuid = new UUID().toString();
+ private final TransactionManager _txManager;
+ private final TxContext _ctx;
+ private final SessionFactory _sessionFactory;
+ private boolean _canJoinForUpdate = true;
+
+ public SessionManager(Properties env, DataSource ds, TransactionManager tx) throws HibernateException {
+ this(getDefaultConfiguration(), env, ds, tx);
+ }
+
+ public SessionManager(Configuration conf, Properties env, DataSource ds, TransactionManager tx) throws HibernateException {
+ if (tx!=null){
+ _ctx = new HibernateJtaTxContext();
+ }else{
+ _ctx = new HibernateNonTxContext();
+ }
+
+ _txManager = tx;
+ _txManagers.put(_uuid, tx);
+ _dataSources.put(_uuid, ds);
+
+ _sessionFactory = conf.setProperties(env).setProperty(PROP_GUID, _uuid).buildSessionFactory();
+ /*
+ Some Hibernate dialects (like IngresDialect) do not support update for join.
+ We need to distinguish them and explicitly define subqueries, otherwise Hibernate
+ implicitly generates joins which causes problems during update for such DBMS.
+ See org.apache.ode.dao.hib.bpel.CorrelatorDaoImpl for instance.
+ */
+ String currentHibDialect = env.getProperty(Environment.DIALECT);
+ for (String dialect : CANNOT_JOIN_FOR_UPDATE_DIALECTS) {
+ if (dialect.equals(currentHibDialect)) {
+ _canJoinForUpdate = false;
+ }
+ }
+ }
+
+ public TransactionManager getTransactionManager() {
+ return _txManager;
+ }
+
+ /**
+ * Returns flag which shows whether " where .. join ... for update" kind of queries can be used (supported
+ * by currently effective {@link org.hibernate.dialect.Dialect}. If it's {@code false} than sub-query fallback
+ * should be invoked instead.
+ *
+ * @return currently returns false only for {@link org.hibernate.dialect.IngresDialect}
+ */
+ public boolean canJoinForUpdate() {
+ return _canJoinForUpdate;
+ }
+
+ /**
+ * Get the current Hibernate Session.
+ */
+ public Session getSession() {
+ return _sessionFactory.getCurrentSession();
+ }
+
+ /**
+ * Returns a hibernate configuration with hibernate DAO objects added as resources.
+ * @return
+ * @throws MappingException
+ */
+ public static Configuration getDefaultConfiguration() throws MappingException {
+ return new Configuration() //Bpel classes
+ .addClass(HProcess.class).addClass(HProcessInstance.class).addClass(HCorrelator.class).addClass(HCorrelatorMessage.class).addClass(HCorrelationProperty.class).addClass(HCorrelatorSelector.class).addClass(HMessageExchange.class).addClass(HMessage.class).addClass(HPartnerLink.class).addClass(HScope.class).addClass(HCorrelationSet.class).addClass(HXmlData.class).addClass(HVariableProperty.class).addClass(HBpelEvent.class).addClass(HFaultData.class).addClass(HActivityRecovery.class).addClass(HResourceRoute.class).addClass(HLargeData.class).addClass(HMessageExchangeProperty.class).addClass(HContextValue.class) //Store classes
+ .addClass(DeploymentUnitDaoImpl.class).addClass(ProcessConfDaoImpl.class).addClass(VersionTrackerDAOImpl.class);
+ }
+
+ public void shutdown() {
+ _sessionFactory.close();
+ }
+
+ public boolean isClosed() {
+ return _sessionFactory.isClosed();
+ }
+
+ public static TransactionManager getTransactionManager(Properties props) {
+ String guid = props.getProperty(PROP_GUID);
+ return _txManagers.get(guid);
+ }
+
+ public static Connection getConnection(Properties props) throws SQLException {
+ String guid = props.getProperty(PROP_GUID);
+ return _dataSources.get(guid).getConnection();
+ }
+
+ public void begin(){
+ _ctx.begin();
+ }
+
+ public void commit(){
+ _ctx.commit();
+ }
+
+ public void rollback(){
+ _ctx.rollback();
+ }
+
+ public interface TxContext {
+
+ public void begin();
+
+ public void commit();
+
+ public void rollback();
+ }
+
+ public class HibernateNonTxContext implements TxContext {
+
+ public void begin() {
+ getSession().beginTransaction();
+ }
+
+ public void commit() {
+ getSession().getTransaction().commit();
+ }
+
+ public void rollback() {
+ getSession().getTransaction().rollback();
+ }
+ }
+
+ public class HibernateJtaTxContext implements TxContext {
+
+ public void begin() {
+ }
+
+ public void commit() {
+ }
+
+ public void rollback() {
+ }
+ }
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ActivityRecoveryDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ActivityRecoveryDaoImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ActivityRecoveryDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ActivityRecoveryDaoImpl.java Sun May 2 17:02:51 2010
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.hib.bpel;
+
+import org.apache.ode.dao.bpel.ActivityRecoveryDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HActivityRecovery;
+import org.apache.ode.utils.DOMUtils;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * Hibernate based {@link ActivityRecoveryDao} implementation
+ */
+public class ActivityRecoveryDaoImpl extends HibernateDao implements ActivityRecoveryDAO {
+
+
+ HActivityRecovery _self;
+
+ public ActivityRecoveryDaoImpl(SessionManager sm, HActivityRecovery recovery) {
+ super(sm, recovery);
+ entering("ActivityRecoveryDaoImpl.ActivityRecoveryDaoImpl");
+ _self = recovery;
+ }
+
+ public long getActivityId() {
+ return _self.getActivityId();
+ }
+
+ public String getChannel() {
+ return _self.getChannel();
+ }
+
+ public String getReason() {
+ return _self.getReason();
+ }
+
+ public Date getDateTime() {
+ return _self.getDateTime();
+ }
+
+ public Element getDetails() {
+ entering("ActivityRecoveryDaoImpl.getDetails");
+ if (_self.getDetails() == null) return null;
+ try {
+ return DOMUtils.stringToDOM(_self.getDetails().getText());
+ } catch (SAXException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public String getActions() {
+ return _self.getActions();
+ }
+
+ public String[] getActionsList() {
+ return _self.getActions().split(" ");
+ }
+
+ public int getRetries() {
+ return _self.getRetries();
+ }
+
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/BpelDAOConnectionFactoryImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/BpelDAOConnectionFactoryImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/BpelDAOConnectionFactoryImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/BpelDAOConnectionFactoryImpl.java Sun May 2 17:02:51 2010
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.hib.bpel;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.dao.bpel.BpelDAOConnection;
+import org.apache.ode.dao.hib.DataSourceConnectionProvider;
+import org.apache.ode.dao.hib.HibernateTransactionManagerLookup;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.bpel.BpelDAOConnectionFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.resolver.DialectFactory;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.util.Properties;
+import java.util.Enumeration;
+import javax.transaction.TransactionManager;
+import org.apache.ode.il.config.OdeConfigProperties;
+import org.hibernate.cfg.Configuration;
+
+
+
+/**
+ * Hibernate-based {@link org.apache.ode.dao.bpel.BpelDAOConnectionFactory}
+ * implementation.
+ */
+public class BpelDAOConnectionFactoryImpl implements BpelDAOConnectionFactory {
+ private static final Log __log = LogFactory.getLog(BpelDAOConnectionFactoryImpl.class);
+
+ protected SessionManager _sessionManager;
+ protected TransactionManager _txm;
+ protected DataSource _ds;
+
+
+ /**
+ * Constructor.
+ */
+ public BpelDAOConnectionFactoryImpl() {
+ }
+
+ public BpelDAOConnection getConnection() {
+ try {
+ return new BpelDAOConnectionImpl(_sessionManager);
+ } catch (HibernateException e) {
+ __log.error("DbError", e);
+ throw e;
+ }
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.BpelDAOConnectionFactory#init(java.util.Properties)
+ */
+ @SuppressWarnings("unchecked")
+ public void init(Properties initialProps, TransactionManager mgr, Object env) {
+ _txm=mgr;
+ _ds=(DataSource)env;
+ if (_txm == null){
+ __log.error("Hibernate BpelDAOConnectionFactoryImpl requires a JTA Transaction Manager to be set.");
+ }
+ _sessionManager = setupSessionManager(initialProps, _txm, _ds);
+
+
+ }
+
+ public static SessionManager setupSessionManager(Properties initialProps, TransactionManager mgr, DataSource ds){
+ return setupSessionManager(SessionManager.getDefaultConfiguration(), initialProps, mgr, ds);
+ }
+
+ public static SessionManager setupSessionManager(Configuration conf, Properties initialConfig, TransactionManager mgr, DataSource ds){
+ // Don't want to pollute original properties
+ Properties properties = new Properties();
+ if (initialConfig != null) {
+ for (Object prop : initialConfig.keySet()) {
+ properties.put(prop, initialConfig.get(prop));
+ }
+ }
+
+ // Note that we don't allow the following properties to be overriden by
+ // the client.
+ /*
+ if (properties.containsKey(Environment.CONNECTION_PROVIDER))
+ __log.warn("Ignoring user-specified Hibernate property: " + Environment.CONNECTION_PROVIDER);
+ if (properties.containsKey(Environment.TRANSACTION_MANAGER_STRATEGY))
+ __log.warn("Ignoring user-specified Hibernate property: " + Environment.TRANSACTION_MANAGER_STRATEGY);
+ if (properties.containsKey(Environment.SESSION_FACTORY_NAME))
+ __log.warn("Ignoring user-specified Hibernate property: " + Environment.SESSION_FACTORY_NAME);
+ */
+ if (ds!=null){
+ properties.put(Environment.CONNECTION_PROVIDER, DataSourceConnectionProvider.class.getName());
+ // Guess Hibernate dialect if not specified in hibernate.properties
+ if (properties.get(Environment.DIALECT) == null) {
+ try {
+ properties.put(Environment.DIALECT, guessDialect(ds));
+ } catch (Exception ex) {
+ String errmsg = "Unable to detect Hibernate dialect!";
+
+ if (__log.isDebugEnabled())
+ __log.debug(errmsg, ex);
+
+ __log.error(errmsg);
+ }
+ }
+ }
+
+ if (mgr!=null){
+ properties.put(Environment.TRANSACTION_MANAGER_STRATEGY, HibernateTransactionManagerLookup.class.getName());
+ /*
+ * Since Hibernate 3.2.6, Hibernate JTATransaction requires User Transaction bound on JNDI. Let's work around
+ * by implementing Hibernate JTATransactionFactory that hooks up to the JTATransactionManager(ODE uses geronimo
+ * by default).
+ */
+ //properties.put(Environment.TRANSACTION_STRATEGY, "org.hibernate.transaction.JTATransactionFactory");
+ properties.put(Environment.TRANSACTION_STRATEGY, "org.apache.ode.dao.hib.JotmTransactionFactory");
+ properties.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta");
+ }else{
+ properties.put(Environment.TRANSACTION_STRATEGY,"org.hibernate.transaction.JDBCTransactionFactory");
+ properties.put(Environment.CURRENT_SESSION_CONTEXT_CLASS,"thread");
+ }
+
+ // Isolation levels override
+ if (System.getProperty("ode.connection.isolation") != null) {
+ String level = System.getProperty("ode.connection.isolation", "2");
+ properties.put(Environment.ISOLATION, level);
+ }
+
+ if (Boolean.valueOf(initialConfig.getProperty(OdeConfigProperties.PROP_DB_EMBEDDED_CREATE, "true"))) {
+ properties.put(Environment.HBM2DDL_AUTO, "create-drop");
+ }
+
+ if (__log.isDebugEnabled()) {
+ Enumeration names = properties.propertyNames();
+ __log.debug("Properties passed to Hibernate:");
+ while (names.hasMoreElements()) {
+ String name = (String) names.nextElement();
+ __log.debug(name + "=" + properties.getProperty(name));
+ }
+ }
+
+ return new SessionManager(conf, properties, ds,mgr);
+
+ }
+
+
+
+ public void shutdown() {
+ _sessionManager.shutdown();
+ }
+
+ private static final String DEFAULT_HIBERNATE_DIALECT = "org.hibernate.dialect.DerbyDialect";
+
+ public static String guessDialect(DataSource dataSource) throws Exception {
+
+ String dialect = null;
+ // Open a connection and use that connection to figure out database
+ // product name/version number in order to decide which Hibernate
+ // dialect to use.
+ Connection conn = dataSource.getConnection();
+ try {
+ Dialect d = DialectFactory.buildDialect(new Properties(), conn);
+ dialect=d.getClass().getName();
+ } finally {
+ conn.close();
+ }
+
+ if (dialect == null) {
+ __log.info("Cannot determine hibernate dialect for this database: using the default one.");
+ dialect = DEFAULT_HIBERNATE_DIALECT;
+ }
+
+ return dialect;
+
+ }
+
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/BpelDAOConnectionImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/BpelDAOConnectionImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/BpelDAOConnectionImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/BpelDAOConnectionImpl.java Sun May 2 17:02:51 2010
@@ -0,0 +1,365 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.hib.bpel;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.BpelEventFilter;
+import org.apache.ode.bpel.common.InstanceFilter;
+import org.apache.ode.dao.bpel.*;
+import org.apache.ode.bpel.evt.BpelEvent;
+import org.apache.ode.bpel.evt.ScopeEvent;
+import org.apache.ode.bpel.iapi.ProcessConf.CLEANUP_CATEGORY;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.*;
+import org.apache.ode.dao.hib.bpel.ql.HibernateInstancesQueryCompiler;
+import org.apache.ode.ql.eval.skel.CommandEvaluator;
+import org.apache.ode.ql.tree.Builder;
+import org.apache.ode.ql.tree.BuilderFactory;
+import org.apache.ode.ql.tree.nodes.Query;
+import org.apache.ode.utils.SerializableUtils;
+import org.apache.ode.utils.stl.CollectionsX;
+import org.apache.ode.utils.stl.UnaryFunctionEx;
+import org.hibernate.Criteria;
+import org.hibernate.FetchMode;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.criterion.Expression;
+import org.hibernate.criterion.Projections;
+
+import javax.xml.namespace.QName;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.sql.Timestamp;
+import java.util.*;
+
+/**
+ * Hibernate-based {@link BpelDAOConnection} implementation.
+ */
+public class BpelDAOConnectionImpl implements BpelDAOConnection, FilteredInstanceDeletable {
+
+ private static final Log __log = LogFactory.getLog(BpelDAOConnectionImpl.class);
+ protected SessionManager _sm;
+
+ public BpelDAOConnectionImpl(SessionManager sm) {
+ _sm = sm;
+
+ }
+
+ public void close() {
+
+ }
+
+ public boolean isClosed() {
+ return _sm.isClosed();
+ }
+
+ protected Session getSession() {
+ return _sm.getSession();
+ }
+
+ public MessageExchangeDAO createMessageExchange(String mexId, char dir) {
+ HMessageExchange mex = new HMessageExchange();
+ mex.setMexId(mexId);
+ mex.setDirection(dir);
+ getSession().save(mex);
+ return new MessageExchangeDaoImpl(_sm, mex);
+ }
+
+ public MessageExchangeDAO getMessageExchange(String mexId) {
+ try {
+ org.hibernate.Query query = getSession().createQuery("from HMessageExchange x where x.mexId = ?");
+ query.setString(0, mexId);
+ HMessageExchange mex = (HMessageExchange) query.uniqueResult();
+ return mex == null ? null : new MessageExchangeDaoImpl(_sm, mex);
+ } catch (HibernateException e) {
+ __log.error("DbError", e);
+ throw e;
+ }
+ }
+
+ public void releaseMessageExchange(String mexid) {
+ MessageExchangeDAO mexDao = getMessageExchange(mexid);
+ if (mexDao != null) {
+ mexDao.release(true);
+ }
+ }
+
+ public ResourceRouteDAO getResourceRoute(String url, String method) {
+ try {
+ Criteria criteria = getSession().createCriteria(HResourceRoute.class);
+ criteria.add(Expression.eq("url", url));
+ criteria.add(Expression.eq("method", method));
+ HResourceRoute hrr = (HResourceRoute) criteria.uniqueResult();
+ return hrr == null ? null : new ResourceRouteDaoImpl(_sm, hrr);
+ } catch (HibernateException e) {
+ __log.error("DbError", e);
+ throw e;
+ }
+ }
+
+ public void deleteResourceRoute(String url, String method) {
+ getSession().createQuery("delete from HResourceRoute r where r.url = :url and r.method = :method").setString("url", url).setString("method", method).executeUpdate();
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<ResourceRouteDAO> getAllResourceRoutes() {
+ List<HResourceRoute> hrr = getSession().createCriteria(HResourceRoute.class).list();
+ ArrayList<ResourceRouteDAO> rr = new ArrayList<ResourceRouteDAO>(hrr.size());
+ for (HResourceRoute hroute : hrr) {
+ rr.add(new ResourceRouteDaoImpl(_sm, hroute));
+ }
+ return rr;
+ }
+
+ public ProcessDAO createProcess(QName pid, QName type, String guid, long version) {
+ HProcess process = new HProcess();
+ process.setProcessId(pid.toString());
+ process.setTypeName(type.getLocalPart());
+ process.setTypeNamespace(type.getNamespaceURI());
+ process.setDeployDate(new Date());
+ process.setGuid(guid);
+ process.setVersion(version);
+ getSession().save(process);
+ return new ProcessDaoImpl(_sm, process);
+ }
+
+ public ProcessDAO createTransientProcess(Serializable id) {
+ HProcess process = new HProcess();
+ process.setId((Long) id);
+
+ return new ProcessDaoImpl(_sm, process);
+ }
+
+ public ProcessDAO getProcess(QName processId) {
+
+ try {
+ Criteria criteria = getSession().createCriteria(HProcess.class);
+ criteria.add(Expression.eq("processId", processId.toString()));
+ // For the moment we are expecting only one result.
+ HProcess hprocess = (HProcess) criteria.uniqueResult();
+ return hprocess == null ? null : new ProcessDaoImpl(_sm, hprocess);
+ } catch (HibernateException e) {
+ __log.error("DbError", e);
+ throw e;
+ }
+
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessDAO#getInstance(java.lang.Long)
+ */
+ public ProcessInstanceDAO getInstance(Long instanceId) {
+ return _getInstance(_sm, getSession(), instanceId);
+ }
+
+ public ScopeDAO getScope(Long siidl) {
+ return _getScope(_sm, getSession(), siidl);
+ }
+
+ public Collection<ProcessInstanceDAO> instanceQuery(InstanceFilter criteria) {
+ if (criteria.getLimit() == 0) {
+ return Collections.emptyList();
+ }
+ List<ProcessInstanceDAO> daos = new ArrayList<ProcessInstanceDAO>();
+
+ Iterator<HProcessInstance> iter = _instanceQuery(getSession(), false, criteria);
+ while (iter.hasNext()) {
+ daos.add(new ProcessInstanceDaoImpl(_sm, iter.next()));
+ }
+
+ return daos;
+ }
+
+ @SuppressWarnings("unchecked")
+ static Iterator<HProcessInstance> _instanceQuery(Session session, boolean countOnly, InstanceFilter filter) {
+ Criteria crit = session.createCriteria(HProcessInstance.class);
+ CriteriaBuilder cb = new CriteriaBuilder();
+ cb.buildCriteria(crit, filter);
+ return crit.list().iterator();
+ }
+
+ static ProcessInstanceDAO _getInstance(SessionManager sm, Session session, Long iid) {
+ HProcessInstance instance = (HProcessInstance) session.get(HProcessInstance.class, iid);
+ return instance != null ? new ProcessInstanceDaoImpl(sm, instance) : null;
+ }
+
+ static ScopeDAO _getScope(SessionManager sm, Session session, Long siid) {
+ HScope scope = (HScope) session.get(HScope.class, siid);
+ return scope != null ? new ScopeDaoImpl(sm, scope) : null;
+ }
+
+ public void insertBpelEvent(BpelEvent event, ProcessDAO process, ProcessInstanceDAO instance) {
+ _insertBpelEvent(_sm.getSession(), event, process, instance);
+ }
+
+ /**
+ * Helper method for inserting bpel events into the database.
+ *
+ * @param sess
+ * @param event
+ * @param process
+ * @param instance
+ */
+ static void _insertBpelEvent(Session sess, BpelEvent event, ProcessDAO process, ProcessInstanceDAO instance) {
+ HBpelEvent hevent = new HBpelEvent();
+ hevent.setTstamp(new Timestamp(System.currentTimeMillis()));
+ hevent.setType(BpelEvent.eventName(event));
+ hevent.setDetail(event.toString());
+ if (process != null) {
+ hevent.setProcess((HProcess) ((ProcessDaoImpl) process).getHibernateObj());
+ }
+ if (instance != null) {
+ hevent.setInstance((HProcessInstance) ((ProcessInstanceDaoImpl) instance).getHibernateObj());
+ }
+ if (event instanceof ScopeEvent) {
+ hevent.setScopeId(((ScopeEvent) event).getScopeId());
+ }
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(event);
+ oos.flush();
+ HLargeData ld = new HLargeData(bos.toByteArray());
+ hevent.setData(ld);
+ sess.save(ld);
+ } catch (Throwable ex) {
+ // this is really unexpected.
+ __log.fatal("InternalError: BpelEvent serialization failed.", ex);
+ }
+ sess.save(hevent);
+ }
+
+ @SuppressWarnings({"unchecked", "deprecation"})
+ public List<Date> bpelEventTimelineQuery(InstanceFilter ifilter, BpelEventFilter efilter) {
+ CriteriaBuilder cb = new CriteriaBuilder();
+ Criteria crit = getSession().createCriteria(HBpelEvent.class);
+ if (ifilter != null) {
+ cb.buildCriteria(crit, efilter);
+ }
+ if (ifilter != null) {
+ cb.buildCriteria(crit.createCriteria("instance"), ifilter);
+ }
+ crit.setFetchMode("tstamp", FetchMode.EAGER);
+ crit.setProjection(Projections.property("tstamp"));
+ return crit.list();
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<BpelEvent> bpelEventQuery(InstanceFilter ifilter, BpelEventFilter efilter) {
+ CriteriaBuilder cb = new CriteriaBuilder();
+ Criteria crit = getSession().createCriteria(HBpelEvent.class);
+ if (efilter != null) {
+ cb.buildCriteria(crit, efilter);
+ }
+ if (ifilter != null) {
+ cb.buildCriteria(crit.createCriteria("instance"), ifilter);
+ }
+ List<HBpelEvent> hevents = crit.list();
+ List<BpelEvent> ret = new ArrayList<BpelEvent>(hevents.size());
+ try {
+ CollectionsX.transformEx(ret, hevents, new UnaryFunctionEx<HBpelEvent, BpelEvent>() {
+
+ public BpelEvent apply(HBpelEvent x) throws Exception {
+ return (BpelEvent) SerializableUtils.toObject(x.getData().getBinary(), BpelEvent.class.getClassLoader());
+ }
+ });
+ } catch (Exception ex) {
+ __log.fatal("Internal error: unable to transform HBpelEvent", ex);
+ throw new RuntimeException(ex);
+ }
+ return ret;
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.BpelDAOConnection#instanceQuery(String)
+ */
+ @SuppressWarnings("unchecked")
+ public Collection<ProcessInstanceDAO> instanceQuery(String expression) {
+ Builder<String> builder = BuilderFactory.getInstance().createBuilder();
+ final org.apache.ode.ql.tree.nodes.Node rootNode = builder.build(expression);
+
+ HibernateInstancesQueryCompiler compiler = new HibernateInstancesQueryCompiler();
+
+ CommandEvaluator<List, Session> eval = compiler.compile((Query) rootNode);
+ List<HProcessInstance> instancesList = (List<HProcessInstance>) eval.evaluate(getSession());
+
+ Collection<ProcessInstanceDAO> result = new ArrayList<ProcessInstanceDAO>(instancesList.size());
+ for (HProcessInstance instance : instancesList) {
+ result.add(getInstance(instance.getId()));
+ }
+ return result;
+ }
+
+ public int deleteInstances(InstanceFilter criteria, Set<CLEANUP_CATEGORY> categories) {
+ if (criteria.getLimit() == 0) {
+ return 0;
+ }
+
+ List<HProcessInstance> instances = _instanceQueryForList(getSession(), false, criteria);
+ if (__log.isDebugEnabled()) {
+ __log.debug("Collected " + instances.size() + " instances to delete.");
+ }
+
+ if (!instances.isEmpty()) {
+ ProcessDaoImpl process = (ProcessDaoImpl) createTransientProcess(instances.get(0).getProcessId());
+ return process.deleteInstances(instances, categories);
+ }
+
+ return 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static List<HProcessInstance> _instanceQueryForList(Session session, boolean countOnly, InstanceFilter filter) {
+ CriteriaBuilder cb = new CriteriaBuilder();
+
+ return cb.buildHQLQuery(session, filter).list();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<Long, Collection<CorrelationSetDAO>> getCorrelationSets(Collection<ProcessInstanceDAO> instances) {
+ if (instances.size() == 0) {
+ return new HashMap<Long, Collection<CorrelationSetDAO>>();
+ }
+ Long[] iids = new Long[instances.size()];
+ int i = 0;
+ for (ProcessInstanceDAO dao : instances) {
+ iids[i] = dao.getInstanceId();
+ i++;
+ }
+ Collection<HCorrelationSet> csets = getSession().getNamedQuery(HCorrelationSet.SELECT_CORSETS_BY_INSTANCES).setParameterList("instances", iids).list();
+ Map<Long, Collection<CorrelationSetDAO>> map = new HashMap<Long, Collection<CorrelationSetDAO>>();
+ for (HCorrelationSet cset : csets) {
+ Long id = cset.getInstance().getId();
+ Collection<CorrelationSetDAO> existing = map.get(id);
+ if (existing == null) {
+ existing = new ArrayList<CorrelationSetDAO>();
+ map.put(id, existing);
+ }
+ existing.add(new CorrelationSetDaoImpl(_sm, cset));
+ }
+ return map;
+ }
+
+ public ProcessManagementDAO getProcessManagement() {
+ return new ProcessManagementDaoImpl(_sm);
+ }
+
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ContextValueDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ContextValueDaoImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ContextValueDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ContextValueDaoImpl.java Sun May 2 17:02:51 2010
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.hib.bpel;
+
+import org.apache.ode.dao.bpel.ContextValueDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HContextValue;
+
+/**
+ * Hibernate-based {@link ContextValueDAO} implementation.
+ */
+public class ContextValueDaoImpl extends HibernateDao implements ContextValueDAO {
+
+ private HContextValue _self;
+
+ public ContextValueDaoImpl(SessionManager sessionManager, HContextValue hobj) {
+ super(sessionManager, hobj);
+ entering("PartnerLinkDAOImpl.PartnerLinkDAOImpl");
+ _self = hobj;
+ }
+
+ public String getKey() {
+ return _self.getKey();
+ }
+
+ public String getNamespace() {
+ return _self.getNamespace();
+ }
+
+ public String getValue() {
+ return _self.getValue();
+ }
+
+ public void setKey(String key) {
+ _self.setKey(key);
+ }
+
+ public void setNamespace(String namespace) {
+ _self.setNamespace(namespace);
+ }
+
+ public void setValue(String value) {
+ _self.setValue(value);
+ }
+
+}