Hibernate SVN: r12937 - in core/trunk: testsuite/src/test/java/org/hibernate/test/component/basic and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2007-08-14 15:47:14 -0400 (Tue, 14 Aug 2007)
New Revision: 12937
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/OptionalComponent.java
Modified:
core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java
core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/ComponentTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/Employee.java
core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/User.hbm.xml
Log:
HHH-2542 : Merge non-null component in a child persisted with a null component and added test for optional components
Modified: core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java 2007-08-14 19:45:56 UTC (rev 12936)
+++ core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java 2007-08-14 19:47:14 UTC (rev 12937)
@@ -553,7 +553,7 @@
AbstractComponentType componentType = ( AbstractComponentType ) types[i];
Type[] subtypes = componentType.getSubtypes();
Object[] origComponentValues = original[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( original[i], session );
- Object[] targetComponentValues = componentType.getPropertyValues( target[i], session );
+ Object[] targetComponentValues = target[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( target[i], session );
replaceAssociations( origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection );
copied[i] = target[i];
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/ComponentTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/ComponentTest.java 2007-08-14 19:45:56 UTC (rev 12936)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/ComponentTest.java 2007-08-14 19:47:14 UTC (rev 12937)
@@ -1,4 +1,4 @@
-//$Id: ComponentTest.java 11349 2007-03-28 15:37:21Z steve.ebersole(a)jboss.com $
+//$Id: ComponentTest.java 11346 2007-03-26 17:24:58Z steve.ebersole(a)jboss.com $
package org.hibernate.test.component.basic;
import java.util.ArrayList;
@@ -9,6 +9,7 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Mappings;
@@ -34,6 +35,10 @@
return new String[] { "component/basic/User.hbm.xml" };
}
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( ComponentTest.class );
+ }
+
public void configure(Configuration cfg) {
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
@@ -62,10 +67,6 @@
f.setFormula( yearFunction.render( args, null ) );
}
}
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite(ComponentTest.class);
- }
public void testUpdateFalse() {
getSessions().getStatistics().clear();
@@ -190,5 +191,131 @@
s.close();
}
+ public void testMergeComponent() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Employee emp = new Employee();
+ emp.setHireDate( new Date() );
+ emp.setPerson( new Person() );
+ emp.getPerson().setName( "steve" );
+ emp.getPerson().setDob( new Date() );
+ s.persist( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ t.commit();
+ s.close();
+
+ assertNull(emp.getOptionalComponent());
+ emp.setOptionalComponent( new OptionalComponent() );
+ emp.getOptionalComponent().setValue1( "emp-value1" );
+ emp.getOptionalComponent().setValue2( "emp-value2" );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ t.commit();
+ s.close();
+
+ assertEquals("emp-value1", emp.getOptionalComponent().getValue1());
+ assertEquals("emp-value2", emp.getOptionalComponent().getValue2());
+ emp.getOptionalComponent().setValue1( null );
+ emp.getOptionalComponent().setValue2( null );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ Hibernate.initialize(emp.getDirectReports());
+ t.commit();
+ s.close();
+
+ assertNull(emp.getOptionalComponent());
+
+ Employee emp1 = new Employee();
+ emp1.setHireDate( new Date() );
+ emp1.setPerson( new Person() );
+ emp1.getPerson().setName( "bozo" );
+ emp1.getPerson().setDob( new Date() );
+ emp.getDirectReports().add( emp1 );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ Hibernate.initialize(emp.getDirectReports());
+ t.commit();
+ s.close();
+
+ assertEquals(1, emp.getDirectReports().size());
+ emp1 = (Employee)emp.getDirectReports().iterator().next();
+ assertNull( emp1.getOptionalComponent() );
+ emp1.setOptionalComponent( new OptionalComponent() );
+ emp1.getOptionalComponent().setValue1( "emp1-value1" );
+ emp1.getOptionalComponent().setValue2( "emp1-value2" );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ Hibernate.initialize(emp.getDirectReports());
+ t.commit();
+ s.close();
+
+ assertEquals(1, emp.getDirectReports().size());
+ emp1 = (Employee)emp.getDirectReports().iterator().next();
+ assertEquals( "emp1-value1", emp1.getOptionalComponent().getValue1());
+ assertEquals( "emp1-value2", emp1.getOptionalComponent().getValue2());
+ emp1.getOptionalComponent().setValue1( null );
+ emp1.getOptionalComponent().setValue2( null );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ Hibernate.initialize(emp.getDirectReports());
+ t.commit();
+ s.close();
+
+ assertEquals(1, emp.getDirectReports().size());
+ emp1 = (Employee)emp.getDirectReports().iterator().next();
+ assertNull(emp1.getOptionalComponent());
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.delete( emp );
+ t.commit();
+ s.close();
+ }
+
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/Employee.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/Employee.java 2007-08-14 19:45:56 UTC (rev 12936)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/Employee.java 2007-08-14 19:47:14 UTC (rev 12937)
@@ -1,6 +1,8 @@
package org.hibernate.test.component.basic;
import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
/**
* todo: describe Employee
@@ -11,6 +13,8 @@
private Long id;
private Person person;
private Date hireDate;
+ private OptionalComponent optionalComponent;
+ private Set directReports = new HashSet();
public Long getId() {
return id;
@@ -35,4 +39,20 @@
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
+
+ public OptionalComponent getOptionalComponent() {
+ return optionalComponent;
+ }
+
+ public void setOptionalComponent(OptionalComponent optionalComponent) {
+ this.optionalComponent = optionalComponent;
+ }
+
+ public Set getDirectReports() {
+ return directReports;
+ }
+
+ public void setDirectReports(Set directReports) {
+ this.directReports = directReports;
+ }
}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/OptionalComponent.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/OptionalComponent.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/OptionalComponent.java 2007-08-14 19:47:14 UTC (rev 12937)
@@ -0,0 +1,27 @@
+//$Id: $
+package org.hibernate.test.component.basic;
+
+/**
+ * @author Gail Badner
+ */
+
+public class OptionalComponent {
+ private String value1;
+ private String value2;
+
+ public String getValue1() {
+ return value1;
+ }
+
+ public void setValue1(String value1) {
+ this.value1 = value1;
+ }
+
+ public String getValue2() {
+ return value2;
+ }
+
+ public void setValue2(String value2) {
+ this.value2 = value2;
+ }
+}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/User.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/User.hbm.xml 2007-08-14 19:45:56 UTC (rev 12936)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/component/basic/User.hbm.xml 2007-08-14 19:47:14 UTC (rev 12937)
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
+<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@@ -8,7 +8,7 @@
-->
<hibernate-mapping package="org.hibernate.test.component.basic">
-
+
<class name="User" table="T_USER">
<id name="userName"/>
<timestamp name="lastModified"/>
@@ -19,9 +19,9 @@
<property name="address"/>
<property name="previousAddress" insert="false"/>
<property name="yob" formula="year(dob)"/>
- <property name="currentAddress"
- column="address"
- insert="false"
+ <property name="currentAddress"
+ column="address"
+ insert="false"
update="false"/>
</component>
</class>
@@ -35,8 +35,16 @@
<property name="name" update="false" not-null="true"/>
<property name="dob" update="false" not-null="true"/>
</component>
+ <component name="optionalComponent">
+ <property name="value1" not-null="false"/>
+ <property name="value2" not-null="false"/>
+ </component>
+ <set name="directReports" cascade="all-delete-orphan,merge" lazy="true">
+ <key column="PARENT_ID" />
+ <one-to-many class="Employee"/>
+ </set>
</class>
-
+
<query name="userNameIn"><![CDATA[from User where person.name in (:nameList) or userName in (:nameList)]]></query>
-
+
</hibernate-mapping>
17 years, 4 months
Hibernate SVN: r12936 - in core/branches/Branch_3_2: test/org/hibernate/test/component/basic and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2007-08-14 15:45:56 -0400 (Tue, 14 Aug 2007)
New Revision: 12936
Added:
core/branches/Branch_3_2/test/org/hibernate/test/component/basic/OptionalComponent.java
Modified:
core/branches/Branch_3_2/src/org/hibernate/type/TypeFactory.java
core/branches/Branch_3_2/test/org/hibernate/test/component/basic/ComponentTest.java
core/branches/Branch_3_2/test/org/hibernate/test/component/basic/Employee.java
core/branches/Branch_3_2/test/org/hibernate/test/component/basic/User.hbm.xml
Log:
HHH-2542 : Merge non-null component in a child persisted with a null component and added test for optional components
Modified: core/branches/Branch_3_2/src/org/hibernate/type/TypeFactory.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/type/TypeFactory.java 2007-08-14 17:19:22 UTC (rev 12935)
+++ core/branches/Branch_3_2/src/org/hibernate/type/TypeFactory.java 2007-08-14 19:45:56 UTC (rev 12936)
@@ -553,7 +553,7 @@
AbstractComponentType componentType = ( AbstractComponentType ) types[i];
Type[] subtypes = componentType.getSubtypes();
Object[] origComponentValues = original[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( original[i], session );
- Object[] targetComponentValues = componentType.getPropertyValues( target[i], session );
+ Object[] targetComponentValues = target[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( target[i], session );
replaceAssociations( origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection );
copied[i] = target[i];
}
Modified: core/branches/Branch_3_2/test/org/hibernate/test/component/basic/ComponentTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/component/basic/ComponentTest.java 2007-08-14 17:19:22 UTC (rev 12935)
+++ core/branches/Branch_3_2/test/org/hibernate/test/component/basic/ComponentTest.java 2007-08-14 19:45:56 UTC (rev 12936)
@@ -9,6 +9,7 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.Hibernate;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Mappings;
@@ -190,5 +191,131 @@
s.close();
}
+ public void testMergeComponent() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Employee emp = new Employee();
+ emp.setHireDate( new Date() );
+ emp.setPerson( new Person() );
+ emp.getPerson().setName( "steve" );
+ emp.getPerson().setDob( new Date() );
+ s.persist( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ t.commit();
+ s.close();
+
+ assertNull(emp.getOptionalComponent());
+ emp.setOptionalComponent( new OptionalComponent() );
+ emp.getOptionalComponent().setValue1( "emp-value1" );
+ emp.getOptionalComponent().setValue2( "emp-value2" );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ t.commit();
+ s.close();
+
+ assertEquals("emp-value1", emp.getOptionalComponent().getValue1());
+ assertEquals("emp-value2", emp.getOptionalComponent().getValue2());
+ emp.getOptionalComponent().setValue1( null );
+ emp.getOptionalComponent().setValue2( null );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ Hibernate.initialize(emp.getDirectReports());
+ t.commit();
+ s.close();
+
+ assertNull(emp.getOptionalComponent());
+
+ Employee emp1 = new Employee();
+ emp1.setHireDate( new Date() );
+ emp1.setPerson( new Person() );
+ emp1.getPerson().setName( "bozo" );
+ emp1.getPerson().setDob( new Date() );
+ emp.getDirectReports().add( emp1 );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ Hibernate.initialize(emp.getDirectReports());
+ t.commit();
+ s.close();
+
+ assertEquals(1, emp.getDirectReports().size());
+ emp1 = (Employee)emp.getDirectReports().iterator().next();
+ assertNull( emp1.getOptionalComponent() );
+ emp1.setOptionalComponent( new OptionalComponent() );
+ emp1.getOptionalComponent().setValue1( "emp1-value1" );
+ emp1.getOptionalComponent().setValue2( "emp1-value2" );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ Hibernate.initialize(emp.getDirectReports());
+ t.commit();
+ s.close();
+
+ assertEquals(1, emp.getDirectReports().size());
+ emp1 = (Employee)emp.getDirectReports().iterator().next();
+ assertEquals( "emp1-value1", emp1.getOptionalComponent().getValue1());
+ assertEquals( "emp1-value2", emp1.getOptionalComponent().getValue2());
+ emp1.getOptionalComponent().setValue1( null );
+ emp1.getOptionalComponent().setValue2( null );
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.merge( emp );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ emp = (Employee)s.get( Employee.class, emp.getId() );
+ Hibernate.initialize(emp.getDirectReports());
+ t.commit();
+ s.close();
+
+ assertEquals(1, emp.getDirectReports().size());
+ emp1 = (Employee)emp.getDirectReports().iterator().next();
+ assertNull(emp1.getOptionalComponent());
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.delete( emp );
+ t.commit();
+ s.close();
+ }
+
}
Modified: core/branches/Branch_3_2/test/org/hibernate/test/component/basic/Employee.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/component/basic/Employee.java 2007-08-14 17:19:22 UTC (rev 12935)
+++ core/branches/Branch_3_2/test/org/hibernate/test/component/basic/Employee.java 2007-08-14 19:45:56 UTC (rev 12936)
@@ -1,6 +1,8 @@
package org.hibernate.test.component.basic;
import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
/**
* todo: describe Employee
@@ -11,6 +13,8 @@
private Long id;
private Person person;
private Date hireDate;
+ private OptionalComponent optionalComponent;
+ private Set directReports = new HashSet();
public Long getId() {
return id;
@@ -35,4 +39,20 @@
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
+
+ public OptionalComponent getOptionalComponent() {
+ return optionalComponent;
+ }
+
+ public void setOptionalComponent(OptionalComponent optionalComponent) {
+ this.optionalComponent = optionalComponent;
+ }
+
+ public Set getDirectReports() {
+ return directReports;
+ }
+
+ public void setDirectReports(Set directReports) {
+ this.directReports = directReports;
+ }
}
Added: core/branches/Branch_3_2/test/org/hibernate/test/component/basic/OptionalComponent.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/component/basic/OptionalComponent.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/component/basic/OptionalComponent.java 2007-08-14 19:45:56 UTC (rev 12936)
@@ -0,0 +1,27 @@
+//$Id: $
+package org.hibernate.test.component.basic;
+
+/**
+ * @author Gail Badner
+ */
+
+public class OptionalComponent {
+ private String value1;
+ private String value2;
+
+ public String getValue1() {
+ return value1;
+ }
+
+ public void setValue1(String value1) {
+ this.value1 = value1;
+ }
+
+ public String getValue2() {
+ return value2;
+ }
+
+ public void setValue2(String value2) {
+ this.value2 = value2;
+ }
+}
Modified: core/branches/Branch_3_2/test/org/hibernate/test/component/basic/User.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/component/basic/User.hbm.xml 2007-08-14 17:19:22 UTC (rev 12935)
+++ core/branches/Branch_3_2/test/org/hibernate/test/component/basic/User.hbm.xml 2007-08-14 19:45:56 UTC (rev 12936)
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
+<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@@ -8,7 +8,7 @@
-->
<hibernate-mapping package="org.hibernate.test.component.basic">
-
+
<class name="User" table="T_USER">
<id name="userName"/>
<timestamp name="lastModified"/>
@@ -19,9 +19,9 @@
<property name="address"/>
<property name="previousAddress" insert="false"/>
<property name="yob" formula="year(dob)"/>
- <property name="currentAddress"
- column="address"
- insert="false"
+ <property name="currentAddress"
+ column="address"
+ insert="false"
update="false"/>
</component>
</class>
@@ -35,8 +35,16 @@
<property name="name" update="false" not-null="true"/>
<property name="dob" update="false" not-null="true"/>
</component>
+ <component name="optionalComponent">
+ <property name="value1" not-null="false"/>
+ <property name="value2" not-null="false"/>
+ </component>
+ <set name="directReports" cascade="all-delete-orphan,merge" lazy="true">
+ <key column="PARENT_ID" />
+ <one-to-many class="Employee"/>
+ </set>
</class>
-
+
<query name="userNameIn"><![CDATA[from User where person.name in (:nameList) or userName in (:nameList)]]></query>
-
+
</hibernate-mapping>
17 years, 4 months
Hibernate SVN: r12935 - in sandbox/trunk: jdbc-impl and 17 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-14 13:19:22 -0400 (Tue, 14 Aug 2007)
New Revision: 12935
Added:
sandbox/trunk/jdbc-impl/
sandbox/trunk/jdbc-impl/pom.xml
sandbox/trunk/jdbc-impl/src/
sandbox/trunk/jdbc-impl/src/main/
sandbox/trunk/jdbc-impl/src/main/java/
sandbox/trunk/jdbc-impl/src/main/java/org/
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ConnectionWrapper.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/LogicalConnection.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/StatementWrapper.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetWrapperImplementor.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/StatementWrapperImplementor.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java
sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/SQLStatementLogger.java
sandbox/trunk/jdbc-impl/src/test/
sandbox/trunk/jdbc-impl/src/test/java/
sandbox/trunk/jdbc-impl/src/test/java/org/
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/BasicConnectionTests.java
sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java
sandbox/trunk/jdbc-impl/src/test/resources/
sandbox/trunk/jdbc-impl/src/test/resources/log4j.properties
Log:
crude direct-impl approach
Property changes on: sandbox/trunk/jdbc-impl
___________________________________________________________________
Name: svn:ignore
+ target
test-output
local
*.ipr
*.iws
*.iml
.classpath
.project
.nbattrs
*.log
*.properties
.clover
Added: sandbox/trunk/jdbc-impl/pom.xml
===================================================================
--- sandbox/trunk/jdbc-impl/pom.xml (rev 0)
+++ sandbox/trunk/jdbc-impl/pom.xml 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,73 @@
+ <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/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core-parent</artifactId>
+ <version>1</version>
+ </parent>
+
+ <groupId>org.hibernate.sandbox</groupId>
+ <artifactId>jdbc-impl</artifactId>
+ <version>1</version>
+ <packaging>jar</packaging>
+
+ <name>JDBC Implementation (sandbox)</name>
+ <description>PoC of a impl/delegation-based approach to JDBC interaction</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>3.3.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.4.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.4.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.5</version>
+ <classifier>jdk15</classifier>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ConnectionWrapper.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ConnectionWrapper.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ConnectionWrapper.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.Connection;
+
+/**
+ * Extra contract for {@link java.sql.Connection} proxies, for clients to be able to
+ * obtain the wrapped connection.
+ *
+ * @author Steve Ebersole
+ */
+public interface ConnectionWrapper {
+ /**
+ * Obtain the wrapped connection being delegated to.
+ * <p/>
+ * NOTE : The scope of validity for the returned connection is
+ * undefined.
+ *
+ * @return The wrapped connection.
+ */
+ public Connection getWrappedConnection();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainer.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+/**
+ * JDBCContainer contract
+ *
+ * @author Steve Ebersole
+ */
+public interface JDBCContainer {
+ public void register(Statement statement);
+ public void release(Statement statement);
+
+ public void register(ResultSet resultSet);
+ public void release(ResultSet resultSet);
+
+ public boolean hasRegisteredResources();
+
+ public void close();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCContainerBuilder.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+/**
+ * Contract for building {@link JDBCContainer} instances.
+ * <p/>
+ * Used mainly to make explicit the contract that a
+ * {@link LogicalConnection} owns the lifecycle of the container.
+ *
+ * @author Steve Ebersole
+ */
+public interface JDBCContainerBuilder {
+ public JDBCContainer buildJdbcContainer();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/JDBCServices.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.jdbc.util.SQLStatementLogger;
+
+/**
+ * Contract for services around JDBC operations.
+ *
+ * @author Steve Ebersole
+ */
+public interface JDBCServices {
+ public ConnectionProvider getConnectionProvider();
+ public JDBCContainerBuilder getJdbcContainerBuilder();
+ public SQLStatementLogger getSqlStatementLogger();
+ public ExceptionHelper getExceptionHelper();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/LogicalConnection.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/LogicalConnection.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/LogicalConnection.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.Connection;
+
+/**
+ * LogicalConnection contract
+ *
+ * @author Steve Ebersole
+ */
+public interface LogicalConnection {
+ /**
+ * Is this LogicalConnection open? Another phraseology sometimes used is: "are we
+ * logically connected"?
+ *
+ * @return True if physically connected; false otherwise.
+ */
+ public boolean isOpen();
+
+ /**
+ * Is this LogicalConnection instance "physically" connected. Meaning
+ * do we currently internally have a cached connection.
+ *
+ * @return True if physically connected; false otherwise.
+ */
+ public boolean isPhysicallyConnected();
+
+ /**
+ * Retreives the connection currently "logically" managed by this LogicalConnectionImpl.
+ * <p/>
+ * Note, that we may need to obtain a connection to return here if a
+ * connection has either not yet been obtained (non-UserSuppliedConnectionProvider)
+ * or has previously been aggressively released.
+ *
+ * @return The current Connection.
+ */
+ public Connection getConnection();
+
+ /**
+ * Release the underlying connection and clean up any other resources associated
+ * with this logical connection.
+ * <p/>
+ * This leaves the logical connection in a "no longer useable" state.
+ *
+ * @return The physical connection which was being used.
+ */
+ public Connection close();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.ResultSet;
+
+/**
+ * Extra contract for {@link ResultSet} proxies, for clients to be able to
+ * obtain the wrapped resultset.
+ *
+ * @author Steve Ebersole
+ */
+public interface ResultSetWrapper {
+ /**
+ * Obtain the wrapped resultset to which this wrapper is delegating.
+ *
+ * @return The wrapped resultset.
+ */
+ public ResultSet getWrappedResultSet();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/StatementWrapper.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/StatementWrapper.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/StatementWrapper.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.Statement;
+
+/**
+ * Extra contract for {@link Statement} proxies, for clients to be able to
+ * obtain the wrapped statement.
+ *
+ * @author Steve Ebersole
+ */
+public interface StatementWrapper {
+ /**
+ * Obtain the wrapped statement to which this wrapper is delegating.
+ *
+ * @return The wrapped statement.
+ */
+ public Statement getWrappedStatement();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+
+/**
+ * AbstractStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractStatementDelegate implements Statement, StatementWrapperImplementor {
+ private static final Logger log = LoggerFactory.getLogger( AbstractStatementDelegate.class );
+
+ private boolean valid = true;
+ private ConnectionDelegate connectionDelegate;
+ private Statement statement;
+
+ private ResultSet currentResultSetDelegate;
+
+ public AbstractStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement) {
+ this.connectionDelegate = connectionDelegate;
+ this.statement = statement;
+ getJdbcContainer().register( this );
+ }
+
+ protected void errorIfInvalid() {
+ if ( !valid ) {
+ throw new HibernateException( "statement handle is invalid" );
+ }
+ }
+
+ /*package-protected*/ JDBCServices getJdbcServices() {
+ return connectionDelegate.getJdbcServices();
+ }
+
+ /*package-protected*/ JDBCContainer getJdbcContainer() {
+ return connectionDelegate.getJdbcContainer();
+ }
+
+ protected Statement getWrappedStatementWithoutChecks() {
+ return statement;
+ }
+
+ public Statement getWrappedStatement() {
+ errorIfInvalid();
+ return statement;
+ }
+
+ public void invalidate() {
+ connectionDelegate = null;
+ statement = null;
+ valid = false;
+ }
+
+
+ // special Statement methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public Connection getConnection() throws SQLException {
+ errorIfInvalid();
+ return connectionDelegate;
+ }
+
+ public void close() throws SQLException {
+ if ( valid ) {
+ getJdbcContainer().release( this );
+ }
+ }
+
+ // execution-related methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public ResultSet getGeneratedKeys() throws SQLException {
+ return new ResultSetDelegate( this, getWrappedStatement().getGeneratedKeys() );
+ }
+
+ public ResultSet getResultSet() throws SQLException {
+ currentResultSetDelegate = new ResultSetDelegate( this, getWrappedStatement().getResultSet() );
+ return currentResultSetDelegate;
+ }
+
+ public int getUpdateCount() throws SQLException {
+ return getWrappedStatement().getUpdateCount();
+ }
+
+ public boolean getMoreResults() throws SQLException {
+ return getMoreResults( Statement.CLOSE_CURRENT_RESULT );
+ }
+
+ public boolean getMoreResults(int current) throws SQLException {
+ if ( current == Statement.CLOSE_ALL_RESULTS ) {
+ log.warn( "getMoreResults call requested all previous results be closed, but thats not possible here" );
+ current = Statement.CLOSE_CURRENT_RESULT;
+ }
+ if ( current == Statement.CLOSE_CURRENT_RESULT && currentResultSetDelegate != null ) {
+ getJdbcContainer().release( currentResultSetDelegate );
+ }
+ currentResultSetDelegate = null;
+ return getWrappedStatement().getMoreResults( current );
+ }
+
+ public void cancel() throws SQLException {
+ getWrappedStatement().cancel();
+ }
+
+ public void clearBatch() throws SQLException {
+ getWrappedStatement().clearBatch();
+ }
+
+ public int[] executeBatch() throws SQLException {
+ return getWrappedStatement().executeBatch();
+ }
+
+
+ // general Statement methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public int getMaxFieldSize() throws SQLException {
+ return getWrappedStatement().getMaxFieldSize();
+ }
+
+ public void setMaxFieldSize(int max) throws SQLException {
+ getWrappedStatement().setMaxFieldSize( max );
+ }
+
+ public int getMaxRows() throws SQLException {
+ return getWrappedStatement().getMaxRows();
+ }
+
+ public void setMaxRows(int max) throws SQLException {
+ getWrappedStatement().setMaxRows( max );
+ }
+
+ public void setEscapeProcessing(boolean enable) throws SQLException {
+ getWrappedStatement().setEscapeProcessing( enable );
+ }
+
+ public int getQueryTimeout() throws SQLException {
+ return getWrappedStatement().getQueryTimeout();
+ }
+
+ public void setQueryTimeout(int seconds) throws SQLException {
+ getWrappedStatement().setQueryTimeout( seconds );
+ }
+
+ public void setCursorName(String name) throws SQLException {
+ getWrappedStatement().setCursorName( name );
+ }
+
+ public void setFetchDirection(int direction) throws SQLException {
+ getWrappedStatement().setFetchDirection( direction );
+ }
+
+ public int getFetchDirection() throws SQLException {
+ return getWrappedStatement().getFetchDirection();
+ }
+
+ public void setFetchSize(int rows) throws SQLException {
+ getWrappedStatement().setFetchSize( rows );
+ }
+
+ public int getFetchSize() throws SQLException {
+ return getWrappedStatement().getFetchSize();
+ }
+
+ public int getResultSetConcurrency() throws SQLException {
+ return getWrappedStatement().getResultSetConcurrency();
+ }
+
+ public int getResultSetType() throws SQLException {
+ return getWrappedStatement().getResultSetType();
+ }
+
+ public int getResultSetHoldability() throws SQLException {
+ return getWrappedStatement().getResultSetHoldability();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return getWrappedStatement().getWarnings();
+ }
+
+ public void clearWarnings() throws SQLException {
+ getWrappedStatement().clearWarnings();
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.Statement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * BasicStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicStatementDelegate extends AbstractStatementDelegate {
+ public BasicStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement) {
+ super( connectionDelegate, statement );
+ }
+
+ public void addBatch(String sql) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ getWrappedStatement().addBatch( sql );
+ }
+
+ public boolean execute(String sql) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().execute( sql );
+ }
+
+ public ResultSet executeQuery(String sql) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return new ResultSetDelegate( this, getWrappedStatement().executeQuery( sql ) );
+ }
+
+ public int executeUpdate(String sql) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().executeUpdate( sql );
+ }
+
+ public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().executeUpdate( sql, autoGeneratedKeys );
+ }
+
+ public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().executeUpdate( sql, columnIndexes );
+ }
+
+ public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().executeUpdate( sql, columnNames );
+ }
+
+ public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().execute( sql, autoGeneratedKeys );
+ }
+
+ public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().execute( sql, columnIndexes );
+ }
+
+ public boolean execute(String sql, String[] columnNames) throws SQLException {
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ return getWrappedStatement().execute( sql, columnNames );
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/CallableStatementDelegate.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,376 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.CallableStatement;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.Ref;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Map;
+
+import org.hibernate.HibernateException;
+
+/**
+ * CallableStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class CallableStatementDelegate extends PreparedStatementDelegate implements CallableStatement {
+ public CallableStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement, String sql) {
+ super( connectionDelegate, statement, sql );
+ if ( ! ( statement instanceof CallableStatement ) ) {
+ throw new HibernateException( "iilegal argument: statement should be PreparedStatement" );
+ }
+ }
+
+ protected CallableStatement getCallableStatement() {
+ return ( CallableStatement ) super.getWrappedStatement();
+ }
+
+
+ // CallableStatement impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterIndex, sqlType );
+ }
+
+ public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterIndex, sqlType, scale );
+ }
+
+ public void registerOutParameter(int paramIndex, int sqlType, String typeName) throws SQLException {
+ getCallableStatement().registerOutParameter( paramIndex, sqlType, typeName );
+ }
+
+ public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterName, sqlType );
+ }
+
+ public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterName, sqlType, scale );
+ }
+
+ public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
+ getCallableStatement().registerOutParameter( parameterName, sqlType, typeName );
+ }
+
+
+ public boolean wasNull() throws SQLException {
+ return getCallableStatement().wasNull();
+ }
+
+ public void setNull(String parameterName, int sqlType) throws SQLException {
+ getCallableStatement().setNull( parameterName, sqlType );
+ }
+
+ public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
+ getCallableStatement().setNull( parameterName, sqlType, typeName );
+ }
+
+ public Object getObject(int parameterIndex) throws SQLException {
+ return getCallableStatement().getObject( parameterIndex );
+ }
+
+ public Object getObject(int i, Map<String, Class<?>> map) throws SQLException {
+ return getCallableStatement().getObject( i, map );
+ }
+
+ public Object getObject(String parameterName) throws SQLException {
+ return getCallableStatement().getObject( parameterName );
+ }
+
+ public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
+ return getCallableStatement().getObject( parameterName, map );
+ }
+
+ public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
+ getCallableStatement().setObject( parameterName, x, targetSqlType, scale );
+ }
+
+ public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
+ getCallableStatement().setObject( parameterName, x, targetSqlType );
+ }
+
+ public void setObject(String parameterName, Object x) throws SQLException {
+ getCallableStatement().setObject( parameterName, x );
+ }
+
+ public String getString(int parameterIndex) throws SQLException {
+ return getCallableStatement().getString( parameterIndex );
+ }
+
+ public String getString(String parameterName) throws SQLException {
+ return getCallableStatement().getString( parameterName );
+ }
+
+ public void setString(String parameterName, String x) throws SQLException {
+ getCallableStatement().setString( parameterName, x );
+ }
+
+ public boolean getBoolean(int parameterIndex) throws SQLException {
+ return getCallableStatement().getBoolean( parameterIndex );
+ }
+
+ public boolean getBoolean(String parameterName) throws SQLException {
+ return getCallableStatement().getBoolean( parameterName );
+ }
+
+ public void setBoolean(String parameterName, boolean x) throws SQLException {
+ getCallableStatement().setBoolean( parameterName, x );
+ }
+
+ public byte getByte(int parameterIndex) throws SQLException {
+ return getCallableStatement().getByte( parameterIndex );
+ }
+
+ public byte getByte(String parameterName) throws SQLException {
+ return getCallableStatement().getByte( parameterName );
+ }
+
+ public void setByte(String parameterName, byte x) throws SQLException {
+ getCallableStatement().setByte( parameterName, x );
+ }
+
+ public short getShort(int parameterIndex) throws SQLException {
+ return getCallableStatement().getShort( parameterIndex );
+ }
+
+ public short getShort(String parameterName) throws SQLException {
+ return getCallableStatement().getShort( parameterName );
+ }
+
+ public void setShort(String parameterName, short x) throws SQLException {
+ getCallableStatement().setShort( parameterName, x );
+ }
+
+ public int getInt(int parameterIndex) throws SQLException {
+ return getCallableStatement().getInt( parameterIndex );
+ }
+
+ public int getInt(String parameterName) throws SQLException {
+ return getCallableStatement().getInt( parameterName );
+ }
+
+ public void setInt(String parameterName, int x) throws SQLException {
+ getCallableStatement().setInt( parameterName, x );
+ }
+
+ public long getLong(int parameterIndex) throws SQLException {
+ return getCallableStatement().getLong( parameterIndex );
+ }
+
+ public long getLong(String parameterName) throws SQLException {
+ return getCallableStatement().getLong( parameterName );
+ }
+
+ public void setLong(String parameterName, long x) throws SQLException {
+ getCallableStatement().setLong( parameterName, x );
+ }
+
+ public float getFloat(int parameterIndex) throws SQLException {
+ return getCallableStatement().getFloat( parameterIndex );
+ }
+
+ public float getFloat(String parameterName) throws SQLException {
+ return getCallableStatement().getFloat( parameterName );
+ }
+
+ public void setFloat(String parameterName, float x) throws SQLException {
+ getCallableStatement().setFloat( parameterName, x );
+ }
+
+ public double getDouble(int parameterIndex) throws SQLException {
+ return getCallableStatement().getDouble( parameterIndex );
+ }
+
+ public double getDouble(String parameterName) throws SQLException {
+ return getCallableStatement().getDouble( parameterName );
+ }
+
+ public void setDouble(String parameterName, double x) throws SQLException {
+ getCallableStatement().setDouble( parameterName, x );
+ }
+
+ public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
+ return getCallableStatement().getBigDecimal( parameterIndex );
+ }
+
+ @Deprecated
+ public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
+ return getCallableStatement().getBigDecimal( parameterIndex, scale );
+ }
+
+ public BigDecimal getBigDecimal(String parameterName) throws SQLException {
+ return getCallableStatement().getBigDecimal( parameterName );
+ }
+
+ public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
+ getCallableStatement().setBigDecimal( parameterName, x );
+ }
+
+ public byte[] getBytes(int parameterIndex) throws SQLException {
+ return getCallableStatement().getBytes( parameterIndex );
+ }
+
+ public byte[] getBytes(String parameterName) throws SQLException {
+ return getCallableStatement().getBytes( parameterName );
+ }
+
+ public void setBytes(String parameterName, byte[] x) throws SQLException {
+ getCallableStatement().setBytes( parameterName, x );
+ }
+
+ public Date getDate(int parameterIndex) throws SQLException {
+ return getCallableStatement().getDate( parameterIndex );
+ }
+
+ public Date getDate(String parameterName) throws SQLException {
+ return getCallableStatement().getDate( parameterName );
+ }
+
+ public Date getDate(String parameterName, Calendar cal) throws SQLException {
+ return getCallableStatement().getDate( parameterName, cal );
+ }
+
+ public void setDate(String parameterName, Date x) throws SQLException {
+ getCallableStatement().setDate( parameterName, x );
+ }
+
+ public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
+ getCallableStatement().setDate( parameterName, x, cal );
+ }
+
+ public Time getTime(int parameterIndex) throws SQLException {
+ return getCallableStatement().getTime( parameterIndex );
+ }
+
+ public Timestamp getTimestamp(int parameterIndex) throws SQLException {
+ return getCallableStatement().getTimestamp( parameterIndex );
+ }
+
+ public Ref getRef(int i) throws SQLException {
+ return getCallableStatement().getRef( i );
+ }
+
+ public Ref getRef(String parameterName) throws SQLException {
+ return getCallableStatement().getRef( parameterName );
+ }
+
+ public Blob getBlob(int i) throws SQLException {
+ return getCallableStatement().getBlob( i );
+ }
+
+ public Blob getBlob(String parameterName) throws SQLException {
+ return getCallableStatement().getBlob( parameterName );
+ }
+
+ public Clob getClob(int i) throws SQLException {
+ return getCallableStatement().getClob( i );
+ }
+
+ public Clob getClob(String parameterName) throws SQLException {
+ return getCallableStatement().getClob( parameterName );
+ }
+
+ public Array getArray(int i) throws SQLException {
+ return getCallableStatement().getArray( i );
+ }
+
+ public Array getArray(String parameterName) throws SQLException {
+ return getCallableStatement().getArray( parameterName );
+ }
+
+ public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
+ return getCallableStatement().getDate( parameterIndex, cal );
+ }
+
+ public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
+ return getCallableStatement().getTime( parameterIndex, cal );
+ }
+
+ public Time getTime(String parameterName) throws SQLException {
+ return getCallableStatement().getTime( parameterName );
+ }
+
+ public Time getTime(String parameterName, Calendar cal) throws SQLException {
+ return getCallableStatement().getTime( parameterName, cal );
+ }
+
+ public void setTime(String parameterName, Time x) throws SQLException {
+ getCallableStatement().setTime( parameterName, x );
+ }
+
+ public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
+ getCallableStatement().setTime( parameterName, x, cal );
+ }
+
+ public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
+ return getCallableStatement().getTimestamp( parameterIndex, cal );
+ }
+
+ public Timestamp getTimestamp(String parameterName) throws SQLException {
+ return getCallableStatement().getTimestamp( parameterName );
+ }
+
+ public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
+ return getCallableStatement().getTimestamp( parameterName, cal );
+ }
+
+ public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
+ getCallableStatement().setTimestamp( parameterName, x );
+ }
+
+ public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
+ getCallableStatement().setTimestamp( parameterName, x, cal );
+ }
+
+ public URL getURL(int parameterIndex) throws SQLException {
+ return getCallableStatement().getURL( parameterIndex );
+ }
+
+ public URL getURL(String parameterName) throws SQLException {
+ return getCallableStatement().getURL( parameterName );
+ }
+
+ public void setURL(String parameterName, URL val) throws SQLException {
+ getCallableStatement().setURL( parameterName, val );
+ }
+
+ public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
+ getCallableStatement().setAsciiStream( parameterName, x, length );
+ }
+
+ public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
+ getCallableStatement().setBinaryStream( parameterName, x, length );
+ }
+
+ public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
+ getCallableStatement().setCharacterStream( parameterName, reader, length );
+ }
+
+
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,333 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.ConnectionWrapper;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+import org.hibernate.HibernateException;
+
+/**
+ * Connection implementation which delegates to the current connection as defined
+ * by its logical connection.
+ *
+ * @author Steve Ebersole
+ */
+public class ConnectionDelegate implements Connection, ConnectionWrapper, ConnectionObserver {
+ private static final Logger log = LoggerFactory.getLogger( ConnectionDelegate.class );
+
+ private boolean valid = true;
+ private LogicalConnectionImplementor logicalConnection;
+
+ /**
+ * Builds a connection delegate with the given logical connection.
+ *
+ * @param logicalConnection The logical connection handling this
+ * connection delegate's access to physical connections.
+ */
+ public ConnectionDelegate(LogicalConnectionImplementor logicalConnection) {
+ this.logicalConnection = logicalConnection;
+ logicalConnection.addObserver( this );
+ }
+
+ /*package-protected*/ JDBCServices getJdbcServices() {
+ return logicalConnection.getJdbcServices();
+ }
+
+ /*package-protected*/ JDBCContainer getJdbcContainer() {
+ return logicalConnection.getJdbcContainer();
+ }
+
+ public Connection getWrappedConnection() {
+ if ( !valid ) {
+ throw new HibernateException( "connection handle is invalid" );
+ }
+ return logicalConnection.getConnection();
+ }
+
+ protected Connection getWrappedConnectionWithoutChecks() {
+ return logicalConnection.getConnection();
+ }
+
+ public void physicalConnectionObtained() {
+ }
+
+ public void physicalConnectionReleased() {
+ }
+
+ public void logicalConnectionClosed() {
+ log.info( "*** logical connection closed ***" );
+ invalidateDelegate();
+ }
+
+ private void invalidateDelegate() {
+ log.trace( "Invalidating connection delegate" );
+ logicalConnection = null;
+ valid = false;
+ }
+
+
+ // statement-creation methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public Statement createStatement() {
+ try {
+ Statement statement = getWrappedConnection().createStatement();
+ return new BasicStatementDelegate( this, statement );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to create basic statement" );
+ }
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency) {
+ try {
+ Statement statement = getWrappedConnection().createStatement( resultSetType, resultSetConcurrency );
+ return new BasicStatementDelegate( this, statement );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to create basic statement" );
+ }
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) {
+ try {
+ Statement statement = getWrappedConnection()
+ .createStatement( resultSetType, resultSetConcurrency, resultSetHoldability );
+ return new BasicStatementDelegate( this, statement );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to create basic statement" );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql) {
+ try {
+ PreparedStatement statement = getWrappedConnection().prepareStatement( sql );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) {
+ try {
+ PreparedStatement statement = getWrappedConnection()
+ .prepareStatement( sql, resultSetType, resultSetConcurrency );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(
+ String sql,
+ int resultSetType,
+ int resultSetConcurrency,
+ int resultSetHoldability) {
+ try {
+ PreparedStatement statement = getWrappedConnection()
+ .prepareStatement( sql, resultSetType, resultSetConcurrency, resultSetHoldability );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) {
+ try {
+ PreparedStatement statement = getWrappedConnection().prepareStatement( sql, autoGeneratedKeys );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes) {
+ try {
+ PreparedStatement statement = getWrappedConnection().prepareStatement( sql, columnIndexes );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public PreparedStatement prepareStatement(String sql, String[] columnNames) {
+ try {
+ PreparedStatement statement = getWrappedConnection().prepareStatement( sql, columnNames );
+ return new PreparedStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare statement", sql );
+ }
+ }
+
+ public CallableStatement prepareCall(String sql) {
+ try {
+ CallableStatement statement = getWrappedConnection().prepareCall( sql );
+ return new CallableStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare call", sql );
+ }
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) {
+ try {
+ CallableStatement statement = getWrappedConnection()
+ .prepareCall( sql, resultSetType, resultSetConcurrency );
+ return new CallableStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare call", sql );
+ }
+ }
+
+ public CallableStatement prepareCall(
+ String sql,
+ int resultSetType,
+ int resultSetConcurrency,
+ int resultSetHoldability) {
+ try {
+ CallableStatement statement = getWrappedConnection()
+ .prepareCall( sql, resultSetType, resultSetConcurrency, resultSetHoldability );
+ return new CallableStatementDelegate( this, statement, sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to prepare call", sql );
+ }
+ }
+
+
+ // other Connection methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public void close() {
+ if ( valid ) {
+ invalidateDelegate();
+ }
+ }
+
+ public boolean isClosed() {
+ return !valid;
+ }
+
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ getWrappedConnection().setAutoCommit( autoCommit );
+ }
+
+ public boolean getAutoCommit() throws SQLException {
+ return getWrappedConnection().getAutoCommit();
+ }
+
+ public void commit() throws SQLException {
+ getWrappedConnection().commit();
+ }
+
+ public void rollback() throws SQLException {
+ getWrappedConnection().rollback();
+ }
+
+ public DatabaseMetaData getMetaData() throws SQLException {
+ return getWrappedConnection().getMetaData();
+ }
+
+ public String nativeSQL(String sql) throws SQLException {
+ return getWrappedConnection().nativeSQL( sql );
+ }
+
+ public void setReadOnly(boolean readOnly) throws SQLException {
+ getWrappedConnection().setReadOnly( readOnly );
+ }
+
+ public boolean isReadOnly() throws SQLException {
+ return getWrappedConnection().isReadOnly();
+ }
+
+ public void setCatalog(String catalog) throws SQLException {
+ getWrappedConnection().setCatalog( catalog );
+ }
+
+ public String getCatalog() throws SQLException {
+ return getWrappedConnection().getCatalog();
+ }
+
+ public void setTransactionIsolation(int level) throws SQLException {
+ getWrappedConnection().setTransactionIsolation( level );
+ }
+
+ public int getTransactionIsolation() throws SQLException {
+ return getWrappedConnection().getTransactionIsolation();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return getWrappedConnection().getWarnings();
+ }
+
+ public void clearWarnings() throws SQLException {
+ getWrappedConnection().clearWarnings();
+ }
+
+ public Map<String, Class<?>> getTypeMap() throws SQLException {
+ return getWrappedConnection().getTypeMap();
+ }
+
+ public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+ getWrappedConnection().setTypeMap( map );
+ }
+
+ public void setHoldability(int holdability) throws SQLException {
+ getWrappedConnection().setHoldability( holdability );
+ }
+
+ public int getHoldability() throws SQLException {
+ return getWrappedConnection().getHoldability();
+ }
+
+ public Savepoint setSavepoint() throws SQLException {
+ return getWrappedConnection().setSavepoint();
+ }
+
+ public Savepoint setSavepoint(String name) throws SQLException {
+ return getWrappedConnection().setSavepoint( name );
+ }
+
+ public void rollback(Savepoint savepoint) throws SQLException {
+ getWrappedConnection().rollback( savepoint );
+ }
+
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ getWrappedConnection().releaseSavepoint( savepoint );
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.jdbc.impl.BasicJDBCContainer;
+import org.hibernate.jdbc.util.ExceptionHelper;
+
+/**
+ * DelegateJDBCContainer implementation
+ *
+ * @author Steve Ebersole
+ */
+public class DelegateJDBCContainer extends BasicJDBCContainer {
+ private static final Logger log = LoggerFactory.getLogger( DelegateJDBCContainer.class );
+
+ public DelegateJDBCContainer(ExceptionHelper exceptionHelper) {
+ super( exceptionHelper );
+ }
+
+ protected void close(Statement statement) {
+ if ( statement instanceof StatementWrapperImplementor ) {
+ StatementWrapperImplementor wrapper = ( StatementWrapperImplementor ) statement;
+ super.close( wrapper.getWrappedStatement() );
+ wrapper.invalidate();
+ }
+ else {
+ super.close( statement );
+ }
+ }
+
+ protected void close(ResultSet resultSet) {
+ if ( resultSet instanceof ResultSetWrapperImplementor ) {
+ ResultSetWrapperImplementor wrapper = ( ResultSetWrapperImplementor ) resultSet;
+ super.close( wrapper.getWrappedResultSet() );
+ wrapper.invalidate();
+ }
+ else {
+ super.close( resultSet );
+ }
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Ref;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Array;
+import java.sql.ResultSetMetaData;
+import java.sql.ParameterMetaData;
+import java.math.BigDecimal;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Calendar;
+import java.net.URL;
+
+import org.hibernate.HibernateException;
+
+/**
+ * PreparedStatementDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class PreparedStatementDelegate extends AbstractStatementDelegate implements PreparedStatement {
+ private String sql;
+
+ public PreparedStatementDelegate(ConnectionDelegate connectionDelegate, Statement statement, String sql) {
+ super( connectionDelegate, statement );
+ if ( ! ( statement instanceof PreparedStatement ) ) {
+ throw new HibernateException( "iilegal argument: statement should be PreparedStatement" );
+ }
+ this.sql = sql;
+ getJdbcServices().getSqlStatementLogger().logStatement( sql );
+ }
+
+ private PreparedStatement getPreparedStatement() {
+ return ( PreparedStatement ) super.getWrappedStatement();
+ }
+
+
+ // PreparedStatement impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public void addBatch() throws SQLException {
+ getPreparedStatement().addBatch();
+ }
+
+ public boolean execute() throws SQLException {
+ return getPreparedStatement().execute();
+ }
+
+ public ResultSet executeQuery() throws SQLException {
+ return new ResultSetDelegate( this, getPreparedStatement().executeQuery() );
+ }
+
+ public int executeUpdate() throws SQLException {
+ return getPreparedStatement().executeUpdate();
+ }
+
+ public ResultSetMetaData getMetaData() throws SQLException {
+ return getPreparedStatement().getMetaData();
+ }
+
+ public ParameterMetaData getParameterMetaData() throws SQLException {
+ return getPreparedStatement().getParameterMetaData();
+ }
+
+ public void clearParameters() throws SQLException {
+ getPreparedStatement().clearParameters();
+ }
+
+ public void setNull(int parameterIndex, int sqlType) throws SQLException {
+ getPreparedStatement().setNull( parameterIndex, sqlType );
+ }
+
+ public void setBoolean(int parameterIndex, boolean x) throws SQLException {
+ getPreparedStatement().setBoolean( parameterIndex, x );
+ }
+
+ public void setByte(int parameterIndex, byte x) throws SQLException {
+ getPreparedStatement().setByte( parameterIndex, x );
+ }
+
+ public void setShort(int parameterIndex, short x) throws SQLException {
+ getPreparedStatement().setShort( parameterIndex, x );
+ }
+
+ public void setInt(int parameterIndex, int x) throws SQLException {
+ getPreparedStatement().setInt( parameterIndex, x );
+ }
+
+ public void setLong(int parameterIndex, long x) throws SQLException {
+ getPreparedStatement().setLong( parameterIndex, x );
+ }
+
+ public void setFloat(int parameterIndex, float x) throws SQLException {
+ getPreparedStatement().setFloat( parameterIndex, x );
+ }
+
+ public void setDouble(int parameterIndex, double x) throws SQLException {
+ getPreparedStatement().setDouble( parameterIndex, x );
+ }
+
+ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
+ getPreparedStatement().setBigDecimal( parameterIndex, x );
+ }
+
+ public void setString(int parameterIndex, String x) throws SQLException {
+ getPreparedStatement().setString( parameterIndex, x );
+ }
+
+ public void setBytes(int parameterIndex, byte[] x) throws SQLException {
+ getPreparedStatement().setBytes( parameterIndex, x );
+ }
+
+ public void setDate(int parameterIndex, Date x) throws SQLException {
+ getPreparedStatement().setDate( parameterIndex, x );
+ }
+
+ public void setTime(int parameterIndex, Time x) throws SQLException {
+ getPreparedStatement().setTime( parameterIndex, x );
+ }
+
+ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
+ getPreparedStatement().setTimestamp( parameterIndex, x );
+ }
+
+ public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
+ getPreparedStatement().setAsciiStream( parameterIndex, x, length );
+ }
+
+ @Deprecated
+ public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
+ getPreparedStatement().setUnicodeStream( parameterIndex, x, length );
+ }
+
+ public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
+ getPreparedStatement().setBinaryStream( parameterIndex, x, length );
+ }
+
+ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
+ getPreparedStatement().setObject( parameterIndex, x, targetSqlType, scale );
+ }
+
+ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
+ getPreparedStatement().setObject( parameterIndex, x, targetSqlType );
+ }
+
+ public void setObject(int parameterIndex, Object x) throws SQLException {
+ getPreparedStatement().setObject( parameterIndex, x );
+ }
+
+ public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
+ getPreparedStatement().setCharacterStream( parameterIndex, reader, length );
+ }
+
+ public void setRef(int parameterIndex, Ref x) throws SQLException {
+ getPreparedStatement().setRef( parameterIndex, x );
+ }
+
+ public void setBlob(int parameterIndex, Blob x) throws SQLException {
+ getPreparedStatement().setBlob( parameterIndex, x );
+ }
+
+ public void setClob(int parameterIndex, Clob x) throws SQLException {
+ getPreparedStatement().setClob( parameterIndex, x );
+ }
+
+ public void setArray(int parameterIndex, Array x) throws SQLException {
+ getPreparedStatement().setArray( parameterIndex, x );
+ }
+
+ public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
+ getPreparedStatement().setDate( parameterIndex, x, cal );
+ }
+
+ public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
+ getPreparedStatement().setTime( parameterIndex, x, cal );
+ }
+
+ public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
+ getPreparedStatement().setTimestamp( parameterIndex, x, cal );
+ }
+
+ public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
+ getPreparedStatement().setNull( parameterIndex, sqlType, typeName );
+ }
+
+ public void setURL(int parameterIndex, URL x) throws SQLException {
+ getPreparedStatement().setURL( parameterIndex, x );
+ }
+
+
+ // Statement methods not really valid on PreparedStatements ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public boolean execute(String sql) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public ResultSet executeQuery(String sql) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public int executeUpdate(String sql) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public boolean execute(String sql, String[] columnNames) throws SQLException {
+ throw new HibernateException( "This form of execute not allowed here" );
+ }
+
+ public void addBatch(String sql) throws SQLException {
+ throw new HibernateException( "This form of addBatch not allowed here" );
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetDelegate.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,653 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.SQLWarning;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import java.sql.Ref;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Array;
+import java.math.BigDecimal;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Map;
+import java.util.Calendar;
+import java.net.URL;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+
+/**
+ * ResultSetDelegate implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ResultSetDelegate implements ResultSet, ResultSetWrapperImplementor {
+ private boolean valid = true;
+ private AbstractStatementDelegate statementDelegate;
+ private ResultSet wrappedResultSet;
+
+ public ResultSetDelegate(AbstractStatementDelegate statementDelegate, ResultSet wrappedResultSet) {
+ this.statementDelegate = statementDelegate;
+ this.wrappedResultSet = wrappedResultSet;
+ }
+
+ /*package-protected*/ JDBCServices getJdbcServices() {
+ return statementDelegate.getJdbcServices();
+ }
+
+ /*package-protected*/ JDBCContainer getJdbcContainer() {
+ return statementDelegate.getJdbcContainer();
+ }
+
+ public ResultSet getWrappedResultSetWithoutChecks() {
+ return wrappedResultSet;
+ }
+
+ public ResultSet getWrappedResultSet() {
+ if ( !valid ) {
+ throw new HibernateException( "resultset handle is invalid" );
+ }
+ return wrappedResultSet;
+ }
+
+ public void invalidate() {
+ statementDelegate = null;
+ wrappedResultSet = null;
+ valid = false;
+ }
+
+
+ // special ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public Statement getStatement() throws SQLException {
+ return statementDelegate;
+ }
+
+ public void close() throws SQLException {
+ if ( valid ) {
+ getJdbcContainer().release( this );
+ }
+ }
+
+
+ // Navigational ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public boolean next() throws SQLException {
+ return getWrappedResultSet().next();
+ }
+
+ public boolean isBeforeFirst() throws SQLException {
+ return getWrappedResultSet().isBeforeFirst();
+ }
+
+ public boolean isAfterLast() throws SQLException {
+ return getWrappedResultSet().isAfterLast();
+ }
+
+ public boolean isFirst() throws SQLException {
+ return getWrappedResultSet().isFirst();
+ }
+
+ public boolean isLast() throws SQLException {
+ return getWrappedResultSet().isLast();
+ }
+
+ public void beforeFirst() throws SQLException {
+ getWrappedResultSet().beforeFirst();
+ }
+
+ public void afterLast() throws SQLException {
+ getWrappedResultSet().afterLast();
+ }
+
+ public boolean first() throws SQLException {
+ return getWrappedResultSet().first();
+ }
+
+ public boolean last() throws SQLException {
+ return getWrappedResultSet().last();
+ }
+
+ public int getRow() throws SQLException {
+ return getWrappedResultSet().getRow();
+ }
+
+ public boolean absolute(int row) throws SQLException {
+ return getWrappedResultSet().absolute( row );
+ }
+
+ public boolean relative(int rows) throws SQLException {
+ return getWrappedResultSet().relative( rows );
+ }
+
+ public boolean previous() throws SQLException {
+ return getWrappedResultSet().previous();
+ }
+
+
+ // informational ResultSet methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public String getCursorName() throws SQLException {
+ return getWrappedResultSet().getCursorName();
+ }
+
+ public ResultSetMetaData getMetaData() throws SQLException {
+ return getWrappedResultSet().getMetaData();
+ }
+
+ public void setFetchDirection(int direction) throws SQLException {
+ getWrappedResultSet().setFetchDirection( direction );
+ }
+
+ public int getFetchDirection() throws SQLException {
+ return getWrappedResultSet().getFetchDirection();
+ }
+
+ public void setFetchSize(int rows) throws SQLException {
+ getWrappedResultSet().setFetchSize( rows );
+ }
+
+ public int getFetchSize() throws SQLException {
+ return getWrappedResultSet().getFetchSize();
+ }
+
+ public int getType() throws SQLException {
+ return getWrappedResultSet().getType();
+ }
+
+ public int getConcurrency() throws SQLException {
+ return getWrappedResultSet().getConcurrency();
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ return getWrappedResultSet().getWarnings();
+ }
+
+ public void clearWarnings() throws SQLException {
+ getWrappedResultSet().clearWarnings();
+ }
+
+
+ // value accessors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public boolean wasNull() throws SQLException {
+ return getWrappedResultSet().wasNull();
+ }
+
+ public String getString(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getString( columnIndex );
+ }
+
+ public boolean getBoolean(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getBoolean( columnIndex );
+ }
+
+ public byte getByte(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getByte( columnIndex );
+ }
+
+ public short getShort(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getShort( columnIndex );
+ }
+
+ public int getInt(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getInt( columnIndex );
+ }
+
+ public long getLong(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getLong( columnIndex );
+ }
+
+ public float getFloat(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getFloat( columnIndex );
+ }
+
+ public double getDouble(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getDouble( columnIndex );
+ }
+
+ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
+ return getWrappedResultSet().getBigDecimal( columnIndex, scale );
+ }
+
+ public byte[] getBytes(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getBytes( columnIndex );
+ }
+
+ public Date getDate(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getDate( columnIndex );
+ }
+
+ public Time getTime(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getTime( columnIndex );
+ }
+
+ public Timestamp getTimestamp(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getTimestamp( columnIndex );
+ }
+
+ public InputStream getAsciiStream(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getAsciiStream( columnIndex );
+ }
+
+ public InputStream getUnicodeStream(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getUnicodeStream( columnIndex );
+ }
+
+ public InputStream getBinaryStream(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getBinaryStream( columnIndex );
+ }
+
+ public String getString(String columnName) throws SQLException {
+ return getWrappedResultSet().getString( columnName );
+ }
+
+ public boolean getBoolean(String columnName) throws SQLException {
+ return getWrappedResultSet().getBoolean( columnName );
+ }
+
+ public byte getByte(String columnName) throws SQLException {
+ return getWrappedResultSet().getByte( columnName );
+ }
+
+ public short getShort(String columnName) throws SQLException {
+ return getWrappedResultSet().getShort( columnName );
+ }
+
+ public int getInt(String columnName) throws SQLException {
+ return getWrappedResultSet().getInt( columnName );
+ }
+
+ public long getLong(String columnName) throws SQLException {
+ return getWrappedResultSet().getLong( columnName );
+ }
+
+ public float getFloat(String columnName) throws SQLException {
+ return getWrappedResultSet().getFloat( columnName );
+ }
+
+ public double getDouble(String columnName) throws SQLException {
+ return getWrappedResultSet().getDouble( columnName );
+ }
+
+ public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException {
+ return getWrappedResultSet().getBigDecimal( columnName, scale );
+ }
+
+ public byte[] getBytes(String columnName) throws SQLException {
+ return getWrappedResultSet().getBytes( columnName );
+ }
+
+ public Date getDate(String columnName) throws SQLException {
+ return getWrappedResultSet().getDate( columnName );
+ }
+
+ public Time getTime(String columnName) throws SQLException {
+ return getWrappedResultSet().getTime( columnName );
+ }
+
+ public Timestamp getTimestamp(String columnName) throws SQLException {
+ return getWrappedResultSet().getTimestamp( columnName );
+ }
+
+ public InputStream getAsciiStream(String columnName) throws SQLException {
+ return getWrappedResultSet().getAsciiStream( columnName );
+ }
+
+ public InputStream getUnicodeStream(String columnName) throws SQLException {
+ return getWrappedResultSet().getUnicodeStream( columnName );
+ }
+
+ public InputStream getBinaryStream(String columnName) throws SQLException {
+ return getWrappedResultSet().getBinaryStream( columnName );
+ }
+
+ public Object getObject(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getObject( columnIndex );
+ }
+
+ public Object getObject(String columnName) throws SQLException {
+ return getWrappedResultSet().getObject( columnName );
+ }
+
+ public int findColumn(String columnName) throws SQLException {
+ return getWrappedResultSet().findColumn( columnName );
+ }
+
+ public Reader getCharacterStream(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getCharacterStream( columnIndex );
+ }
+
+ public Reader getCharacterStream(String columnName) throws SQLException {
+ return getWrappedResultSet().getCharacterStream( columnName );
+ }
+
+ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getBigDecimal( columnIndex );
+ }
+
+ public BigDecimal getBigDecimal(String columnName) throws SQLException {
+ return getWrappedResultSet().getBigDecimal( columnName );
+ }
+
+ public Object getObject(int i, Map<String, Class<?>> map) throws SQLException {
+ return getWrappedResultSet().getObject( i, map );
+ }
+
+ public Ref getRef(int i) throws SQLException {
+ return getWrappedResultSet().getRef( i );
+ }
+
+ public Blob getBlob(int i) throws SQLException {
+ return getWrappedResultSet().getBlob( i );
+ }
+
+ public Clob getClob(int i) throws SQLException {
+ return getWrappedResultSet().getClob( i );
+ }
+
+ public Array getArray(int i) throws SQLException {
+ return getWrappedResultSet().getArray( i );
+ }
+
+ public Object getObject(String colName, Map<String, Class<?>> map) throws SQLException {
+ return getWrappedResultSet().getObject( colName, map );
+ }
+
+ public Ref getRef(String colName) throws SQLException {
+ return getWrappedResultSet().getRef( colName );
+ }
+
+ public Blob getBlob(String colName) throws SQLException {
+ return getWrappedResultSet().getBlob( colName );
+ }
+
+ public Clob getClob(String colName) throws SQLException {
+ return getWrappedResultSet().getClob( colName );
+ }
+
+ public Array getArray(String colName) throws SQLException {
+ return getWrappedResultSet().getArray( colName );
+ }
+
+ public Date getDate(int columnIndex, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getDate( columnIndex, cal );
+ }
+
+ public Date getDate(String columnName, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getDate( columnName, cal );
+ }
+
+ public Time getTime(int columnIndex, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getTime( columnIndex, cal );
+ }
+
+ public Time getTime(String columnName, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getTime( columnName, cal );
+ }
+
+ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getTimestamp( columnIndex, cal );
+ }
+
+ public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException {
+ return getWrappedResultSet().getTimestamp( columnName, cal );
+ }
+
+ public URL getURL(int columnIndex) throws SQLException {
+ return getWrappedResultSet().getURL( columnIndex );
+ }
+
+ public URL getURL(String columnName) throws SQLException {
+ return getWrappedResultSet().getURL( columnName );
+ }
+
+
+ // ResultSet mutability ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public boolean rowUpdated() throws SQLException {
+ return getWrappedResultSet().rowUpdated();
+ }
+
+ public boolean rowInserted() throws SQLException {
+ return getWrappedResultSet().rowInserted();
+ }
+
+ public boolean rowDeleted() throws SQLException {
+ return getWrappedResultSet().rowDeleted();
+ }
+
+ public void updateNull(int columnIndex) throws SQLException {
+ getWrappedResultSet().updateNull( columnIndex );
+ }
+
+ public void updateBoolean(int columnIndex, boolean x) throws SQLException {
+ getWrappedResultSet().updateBoolean( columnIndex, x );
+ }
+
+ public void updateByte(int columnIndex, byte x) throws SQLException {
+ getWrappedResultSet().updateByte( columnIndex, x );
+ }
+
+ public void updateShort(int columnIndex, short x) throws SQLException {
+ getWrappedResultSet().updateShort( columnIndex, x );
+ }
+
+ public void updateInt(int columnIndex, int x) throws SQLException {
+ getWrappedResultSet().updateInt( columnIndex, x );
+ }
+
+ public void updateLong(int columnIndex, long x) throws SQLException {
+ getWrappedResultSet().updateLong( columnIndex, x );
+ }
+
+ public void updateFloat(int columnIndex, float x) throws SQLException {
+ getWrappedResultSet().updateFloat( columnIndex, x );
+ }
+
+ public void updateDouble(int columnIndex, double x) throws SQLException {
+ getWrappedResultSet().updateDouble( columnIndex, x );
+ }
+
+ public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
+ getWrappedResultSet().updateBigDecimal( columnIndex, x );
+ }
+
+ public void updateString(int columnIndex, String x) throws SQLException {
+ getWrappedResultSet().updateString( columnIndex, x );
+ }
+
+ public void updateBytes(int columnIndex, byte[] x) throws SQLException {
+ getWrappedResultSet().updateBytes( columnIndex, x );
+ }
+
+ public void updateDate(int columnIndex, Date x) throws SQLException {
+ getWrappedResultSet().updateDate( columnIndex, x );
+ }
+
+ public void updateTime(int columnIndex, Time x) throws SQLException {
+ getWrappedResultSet().updateTime( columnIndex, x );
+ }
+
+ public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
+ getWrappedResultSet().updateTimestamp( columnIndex, x );
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
+ getWrappedResultSet().updateAsciiStream( columnIndex, x, length );
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
+ getWrappedResultSet().updateBinaryStream( columnIndex, x, length );
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
+ getWrappedResultSet().updateCharacterStream( columnIndex, x, length );
+ }
+
+ public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
+ getWrappedResultSet().updateObject( columnIndex, x, scale );
+ }
+
+ public void updateObject(int columnIndex, Object x) throws SQLException {
+ getWrappedResultSet().updateObject( columnIndex, x );
+ }
+
+ public void updateNull(String columnName) throws SQLException {
+ getWrappedResultSet().updateNull( columnName );
+ }
+
+ public void updateBoolean(String columnName, boolean x) throws SQLException {
+ getWrappedResultSet().updateBoolean( columnName, x );
+ }
+
+ public void updateByte(String columnName, byte x) throws SQLException {
+ getWrappedResultSet().updateByte( columnName, x );
+ }
+
+ public void updateShort(String columnName, short x) throws SQLException {
+ getWrappedResultSet().updateShort( columnName, x );
+ }
+
+ public void updateInt(String columnName, int x) throws SQLException {
+ getWrappedResultSet().updateInt( columnName, x );
+ }
+
+ public void updateLong(String columnName, long x) throws SQLException {
+ getWrappedResultSet().updateLong( columnName, x );
+ }
+
+ public void updateFloat(String columnName, float x) throws SQLException {
+ getWrappedResultSet().updateFloat( columnName, x );
+ }
+
+ public void updateDouble(String columnName, double x) throws SQLException {
+ getWrappedResultSet().updateDouble( columnName, x );
+ }
+
+ public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException {
+ getWrappedResultSet().updateBigDecimal( columnName, x );
+ }
+
+ public void updateString(String columnName, String x) throws SQLException {
+ getWrappedResultSet().updateString( columnName, x );
+ }
+
+ public void updateBytes(String columnName, byte[] x) throws SQLException {
+ getWrappedResultSet().updateBytes( columnName, x );
+ }
+
+ public void updateDate(String columnName, Date x) throws SQLException {
+ getWrappedResultSet().updateDate( columnName, x );
+ }
+
+ public void updateTime(String columnName, Time x) throws SQLException {
+ getWrappedResultSet().updateTime( columnName, x );
+ }
+
+ public void updateTimestamp(String columnName, Timestamp x) throws SQLException {
+ getWrappedResultSet().updateTimestamp( columnName, x );
+ }
+
+ public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException {
+ getWrappedResultSet().updateAsciiStream( columnName, x, length );
+ }
+
+ public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException {
+ getWrappedResultSet().updateBinaryStream( columnName, x, length );
+ }
+
+ public void updateCharacterStream(String columnName, Reader reader, int length) throws SQLException {
+ getWrappedResultSet().updateCharacterStream( columnName, reader, length );
+ }
+
+ public void updateObject(String columnName, Object x, int scale) throws SQLException {
+ getWrappedResultSet().updateObject( columnName, x, scale );
+ }
+
+ public void updateObject(String columnName, Object x) throws SQLException {
+ getWrappedResultSet().updateObject( columnName, x );
+ }
+
+ public void insertRow() throws SQLException {
+ getWrappedResultSet().insertRow();
+ }
+
+ public void updateRow() throws SQLException {
+ getWrappedResultSet().updateRow();
+ }
+
+ public void deleteRow() throws SQLException {
+ getWrappedResultSet().deleteRow();
+ }
+
+ public void refreshRow() throws SQLException {
+ getWrappedResultSet().refreshRow();
+ }
+
+ public void cancelRowUpdates() throws SQLException {
+ getWrappedResultSet().cancelRowUpdates();
+ }
+
+ public void moveToInsertRow() throws SQLException {
+ getWrappedResultSet().moveToInsertRow();
+ }
+
+ public void moveToCurrentRow() throws SQLException {
+ getWrappedResultSet().moveToCurrentRow();
+ }
+
+ public void updateRef(int columnIndex, Ref x) throws SQLException {
+ getWrappedResultSet().updateRef( columnIndex, x );
+ }
+
+ public void updateRef(String columnName, Ref x) throws SQLException {
+ getWrappedResultSet().updateRef( columnName, x );
+ }
+
+ public void updateBlob(int columnIndex, Blob x) throws SQLException {
+ getWrappedResultSet().updateBlob( columnIndex, x );
+ }
+
+ public void updateBlob(String columnName, Blob x) throws SQLException {
+ getWrappedResultSet().updateBlob( columnName, x );
+ }
+
+ public void updateClob(int columnIndex, Clob x) throws SQLException {
+ getWrappedResultSet().updateClob( columnIndex, x );
+ }
+
+ public void updateClob(String columnName, Clob x) throws SQLException {
+ getWrappedResultSet().updateClob( columnName, x );
+ }
+
+ public void updateArray(int columnIndex, Array x) throws SQLException {
+ getWrappedResultSet().updateArray( columnIndex, x );
+ }
+
+ public void updateArray(String columnName, Array x) throws SQLException {
+ getWrappedResultSet().updateArray( columnName, x );
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetWrapperImplementor.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/ResultSetWrapperImplementor.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import org.hibernate.jdbc.ResultSetWrapper;
+
+/**
+ * Extra, internal contract for implementations of ResultSetWrapper for allowing
+ * invalidation of the wrapper.
+ *
+ * @author Steve Ebersole
+ */
+public interface ResultSetWrapperImplementor extends ResultSetWrapper {
+ /**
+ * Make the wrapper invalid for further usage.
+ */
+ public void invalidate();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/StatementWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/StatementWrapperImplementor.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/delegation/StatementWrapperImplementor.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import org.hibernate.jdbc.StatementWrapper;
+
+/**
+ * Extra, internal contract for implementations of StatementWrapper for allowing
+ * invalidation of the wrapper.
+ *
+ * @author Steve Ebersole
+ */
+public interface StatementWrapperImplementor extends StatementWrapper {
+ /**
+ * Make the wrapper invalid for further usage.
+ */
+ public void invalidate();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.jdbc.JDBCContainer;
+
+/**
+ * BasicJDBCContainer implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicJDBCContainer implements JDBCContainer {
+ private static final Logger log = LoggerFactory.getLogger( BasicJDBCContainer.class );
+
+ private final ExceptionHelper exceptionHelper;
+ protected final HashMap xref = new HashMap();
+
+ public BasicJDBCContainer(ExceptionHelper exceptionHelper) {
+ this.exceptionHelper = exceptionHelper;
+ }
+
+ public void register(Statement statement) {
+ log.trace( "registering statement [" + statement + "]" );
+ if ( xref.containsKey( statement ) ) {
+ throw new HibernateException( "statement already registered with JDBCContainer" );
+ }
+ xref.put( statement, null );
+ }
+
+ public void release(Statement statement) {
+ log.trace( "releasing statement [" + statement + "]" );
+ Set resultSets = ( Set ) xref.get( statement );
+ if ( resultSets != null ) {
+ Iterator itr = resultSets.iterator();
+ while ( itr.hasNext() ) {
+ final ResultSet resultSet = ( ResultSet ) itr.next();
+ close( resultSet );
+ }
+ resultSets.clear();
+ }
+ xref.remove( statement );
+ close( statement );
+ }
+
+ public void register(ResultSet resultSet) {
+ log.trace( "registering result set [" + resultSet + "]" );
+ Statement statement;
+ try {
+ statement = resultSet.getStatement();
+ }
+ catch ( SQLException e ) {
+ throw exceptionHelper.convert( e, "unable to access statement from resultset" );
+ }
+ if ( log.isWarnEnabled() && !xref.containsKey( statement ) ) {
+ log.warn( "resultset's statement was not yet registered" );
+ }
+ Set resultSets = ( Set ) xref.get( statement );
+ if ( resultSets == null ) {
+ resultSets = new HashSet();
+ xref.put( statement, resultSets );
+ }
+ resultSets.add( resultSet );
+ }
+
+ public void release(ResultSet resultSet) {
+ log.trace( "releasing result set [" + resultSet + "]" );
+ Statement statement;
+ try {
+ statement = resultSet.getStatement();
+ }
+ catch ( SQLException e ) {
+ throw exceptionHelper.convert( e, "unable to access statement from resultset" );
+ }
+ if ( log.isWarnEnabled() && !xref.containsKey( statement ) ) {
+ log.warn( "resultset's statement was not registered" );
+ }
+ Set resultSets = ( Set ) xref.get( statement );
+ if ( resultSets != null ) {
+ resultSets.remove( resultSet );
+ }
+ close( resultSet );
+ }
+
+ public boolean hasRegisteredResources() {
+ return !xref.isEmpty();
+ }
+
+ public void close() {
+ log.trace( "closing JDBC container [" + this + "]" );
+ Iterator statementIterator = xref.keySet().iterator();
+ while ( statementIterator.hasNext() ) {
+ final Statement statement = ( Statement ) statementIterator.next();
+ final Set resultSets = ( Set ) xref.get( statement );
+ if ( resultSets != null ) {
+ Iterator resultSetIterator = resultSets.iterator();
+ while ( resultSetIterator.hasNext() ) {
+ final ResultSet resultSet = ( ResultSet ) resultSetIterator.next();
+ close( resultSet );
+ }
+ resultSets.clear();
+ }
+ close( statement );
+ }
+ xref.clear();
+ }
+
+ protected void close(Statement statement) {
+ log.trace( "closing prepared statement [" + statement + "]" );
+ try {
+ // if we are unable to "clan" the prepared statement,
+ // we do not close it
+ try {
+ if ( statement.getMaxRows() != 0 ) {
+ statement.setMaxRows( 0 );
+ }
+ if ( statement.getQueryTimeout() != 0 ) {
+ statement.setQueryTimeout( 0 );
+ }
+ }
+ catch( SQLException sqle ) {
+ // there was a problem "cleaning" the prepared statement
+ log.debug( "Exception clearing maxRows/queryTimeout [" + sqle.getMessage() + "]" );
+ return; // EARLY EXIT!!!
+ }
+ statement.close();
+ }
+ catch( SQLException sqle ) {
+ log.debug( "Unable to release statement [" + sqle.getMessage() + "]" );
+ }
+ }
+
+ protected void close(ResultSet resultSet) {
+ log.trace( "closing result set [" + resultSet + "]" );
+ try {
+ resultSet.close();
+ }
+ catch( SQLException e ) {
+ log.debug( "Unable to release result set [" + e.getMessage() + "]" );
+ }
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+/**
+ * Observer contract
+ *
+ * @author Steve Ebersole
+ */
+public interface ConnectionObserver {
+ public void physicalConnectionObtained();
+ public void physicalConnectionReleased();
+ public void logicalConnectionClosed();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.HibernateException;
+import org.hibernate.JDBCException;
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.JDBCServices;
+
+/**
+ * LogicalConnectionImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public class LogicalConnectionImpl implements LogicalConnectionImplementor {
+ private static final Logger log = LoggerFactory.getLogger( LogicalConnectionImpl.class );
+
+ private transient Connection physicalConnection;
+ private final ConnectionReleaseMode connectionReleaseMode;
+ private final JDBCServices jdbcServices;
+ private final JDBCContainer jdbcContainer;
+ private final List observers = new ArrayList();
+
+ private final boolean isUserSuppliedConnection;
+ private boolean isClosed;
+
+ public LogicalConnectionImpl(
+ Connection userSuppliedConnection,
+ ConnectionReleaseMode connectionReleaseMode,
+ JDBCServices jdbcServices) {
+ this.physicalConnection = userSuppliedConnection;
+ this.connectionReleaseMode = connectionReleaseMode;
+ this.jdbcServices = jdbcServices;
+ this.jdbcContainer = jdbcServices.getJdbcContainerBuilder().buildJdbcContainer();
+
+ this.isUserSuppliedConnection = ( userSuppliedConnection != null );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public JDBCServices getJdbcServices() {
+ return jdbcServices;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ConnectionReleaseMode getConnectionReleaseMode() {
+ return connectionReleaseMode;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public JDBCContainer getJdbcContainer() {
+ return jdbcContainer;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addObserver(ConnectionObserver observer) {
+ observers.add( observer );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isOpen() {
+ return !isClosed;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isPhysicallyConnected() {
+ return physicalConnection != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Connection getConnection() throws HibernateException {
+ if ( isClosed ) {
+ throw new HibernateException( "Logical connection is closed" );
+ }
+ if ( physicalConnection == null ) {
+ if ( isUserSuppliedConnection ) {
+ // should never happen
+ throw new HibernateException( "User-supplied connection was null" );
+ }
+ obtainConnection();
+ }
+ return physicalConnection;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Connection close() {
+ log.trace( "closing logical connection" );
+ Connection c = physicalConnection;
+ if ( !isUserSuppliedConnection && physicalConnection != null ) {
+ releaseConnection();
+ }
+ // not matter what
+ physicalConnection = null;
+ isClosed = true;
+ jdbcContainer.close();
+ for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
+ ( ( ConnectionObserver ) itr.next() ).logicalConnectionClosed();
+ }
+ log.trace( "logical connection closed" );
+ return c;
+ }
+
+// /**
+// * Is the connection considered "auto-commit"?
+// *
+// * @return True if we either do not have a connection, or the connection
+// * really is in auto-commit mode.
+// *
+// * @throws SQLException Can be thrown by the Connection.isAutoCommit() check.
+// */
+// public boolean isAutoCommit() throws SQLException {
+// return physicalConnection == null || physicalConnection.getAutoCommit();
+// }
+
+ /**
+ * Force aggresive release of the underlying connection.
+ */
+ public void aggressiveRelease() {
+ if ( isUserSuppliedConnection ) {
+ log.debug( "cannot aggresively release user-supplied connection; skipping" );
+ }
+ else if ( ! getJdbcServices().getConnectionProvider().supportsAggressiveRelease() ) {
+ log.debug( "connection provider reports to not support aggreswsive release; skipping" );
+ }
+ else {
+ log.debug( "aggressively releasing JDBC connection" );
+ if ( physicalConnection != null ) {
+ releaseConnection();
+ }
+ }
+ }
+
+
+ /**
+ * Obtains a physical connection from the
+ * Pysically opens a JDBC Connection.
+ *
+ * @throws JDBCException Indicates problem opening a connection
+ */
+ private void obtainConnection() throws JDBCException {
+ log.debug( "obtaining JDBC connection" );
+ try {
+ physicalConnection = getJdbcServices().getConnectionProvider().getConnection();
+ for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
+ ( ( ConnectionObserver ) itr.next() ).physicalConnectionObtained();
+ }
+ log.debug( "obtained JDBC connection" );
+ }
+ catch (SQLException sqle) {
+ throw getJdbcServices().getExceptionHelper().convert( sqle, "Could not open connection" );
+ }
+ }
+
+ /**
+ * Releases the physical JDBC connection back to the provider.
+ *
+ * @throws JDBCException Indicates problem releasing the connection
+ */
+ private void releaseConnection() throws JDBCException {
+ log.debug( "releasing JDBC connection" );
+ try {
+ if ( !physicalConnection.isClosed() ) {
+ getJdbcServices().getExceptionHelper().logAndClearWarnings( physicalConnection );
+ }
+ getJdbcServices().getConnectionProvider().closeConnection( physicalConnection );
+ physicalConnection = null;
+ for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
+ ( ( ConnectionObserver ) itr.next() ).physicalConnectionReleased();
+ }
+ log.debug( "released JDBC connection" );
+ }
+ catch (SQLException sqle) {
+ throw getJdbcServices().getExceptionHelper().convert( sqle, "Could not close connection" );
+ }
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.ConnectionObserver;
+import org.hibernate.jdbc.LogicalConnection;
+
+/**
+ * LogicalConnectionImplementor implementation
+ *
+ * @author Steve Ebersole
+ */
+public interface LogicalConnectionImplementor extends LogicalConnection {
+ public JDBCServices getJdbcServices();
+
+ public ConnectionReleaseMode getConnectionReleaseMode();
+
+ public JDBCContainer getJdbcContainer();
+
+ public void addObserver(ConnectionObserver observer);
+
+ public void aggressiveRelease();
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/ExceptionHelper.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.util;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.JDBCException;
+import org.hibernate.exception.SQLExceptionConverter;
+import org.hibernate.util.StringHelper;
+
+/**
+ * ExceptionHelper implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ExceptionHelper {
+ public static final String DEFAULT_EXCEPTION_MSG = "SQL Exception";
+ public static final String DEFAULT_WARNING_MSG = "SQL Warning";
+
+ private static final Logger log = LoggerFactory.getLogger( ExceptionHelper.class );
+
+ private SQLExceptionConverter sqlExceptionConverter;
+
+ public ExceptionHelper(SQLExceptionConverter sqlExceptionConverter) {
+ this.sqlExceptionConverter = sqlExceptionConverter;
+ }
+
+ public SQLExceptionConverter getSqlExceptionConverter() {
+ return sqlExceptionConverter;
+ }
+
+ public void setSqlExceptionConverter(SQLExceptionConverter sqlExceptionConverter) {
+ this.sqlExceptionConverter = sqlExceptionConverter;
+ }
+
+ public JDBCException convert(SQLException sqle, String message) {
+ return convert( sqle, message, "n/a" );
+ }
+
+ public JDBCException convert(SQLException sqle, String message, String sql) {
+ logExceptions( sqle, message + " [" + sql + "]" );
+ return sqlExceptionConverter.convert( sqle, message, sql );
+ }
+
+ public void logAndClearWarnings(Connection connection) {
+ if ( log.isWarnEnabled() ) {
+ try {
+ logWarnings( connection.getWarnings() );
+ }
+ catch ( SQLException sqle ) {
+ //workaround for WebLogic
+ log.debug( "could not log warnings", sqle );
+ }
+ }
+ try {
+ //Sybase fail if we don't do that, sigh...
+ connection.clearWarnings();
+ }
+ catch ( SQLException sqle ) {
+ log.debug( "could not clear warnings", sqle );
+ }
+
+ }
+
+ public void logWarnings(SQLWarning warning) {
+ logWarnings( warning, null );
+ }
+
+ public void logWarnings(SQLWarning warning, String message) {
+ if ( log.isWarnEnabled() ) {
+ if ( log.isDebugEnabled() && warning != null ) {
+ message = StringHelper.isNotEmpty( message ) ? message : DEFAULT_WARNING_MSG;
+ log.debug( message, warning );
+ }
+ while ( warning != null ) {
+ StringBuffer buf = new StringBuffer( 30 )
+ .append( "SQL Warning: " )
+ .append( warning.getErrorCode() )
+ .append( ", SQLState: " )
+ .append( warning.getSQLState() );
+ log.warn( buf.toString() );
+ log.warn( warning.getMessage() );
+ warning = warning.getNextWarning();
+ }
+ }
+ }
+
+ public void logExceptions(SQLException ex) {
+ logExceptions( ex, null );
+ }
+
+ public void logExceptions(SQLException ex, String message) {
+ if ( log.isErrorEnabled() ) {
+ if ( log.isDebugEnabled() ) {
+ message = StringHelper.isNotEmpty( message ) ? message : DEFAULT_EXCEPTION_MSG;
+ log.debug( message, ex );
+ }
+ while ( ex != null ) {
+ StringBuffer buf = new StringBuffer( 30 )
+ .append( "SQL Error: " )
+ .append( ex.getErrorCode() )
+ .append( ", SQLState: " )
+ .append( ex.getSQLState() );
+ log.warn( buf.toString() );
+ log.error( ex.getMessage() );
+ ex = ex.getNextException();
+ }
+ }
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/SQLStatementLogger.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/SQLStatementLogger.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/main/java/org/hibernate/jdbc/util/SQLStatementLogger.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Centralize logging for SQL statements.
+ *
+ * @author Steve Ebersole
+ */
+public class SQLStatementLogger {
+ private static final Logger log = LoggerFactory.getLogger( SQLStatementLogger.class );
+
+ private boolean logToStdout;
+
+ /**
+ * Constructs a new SQLStatementLogger instance.
+ */
+ public SQLStatementLogger() {
+ this( false );
+ }
+
+ /**
+ * Constructs a new SQLStatementLogger instance.
+ *
+ * @param logToStdout Should we log to STDOUT in addition to our internal logger.
+ */
+ public SQLStatementLogger(boolean logToStdout) {
+ this.logToStdout = logToStdout;
+ }
+
+ /**
+ * Setter for property 'logToStdout'.
+ *
+ * @param logToStdout Value to set for property 'logToStdout'.
+ */
+ public void setLogToStdout(boolean logToStdout) {
+ this.logToStdout = logToStdout;
+ }
+
+ /**
+ * Log a SQL statement string.
+ *
+ * @param statement The SQL statement.
+ */
+ public void logStatement(String statement) {
+ log.debug( statement );
+ if ( logToStdout ) {
+ System.out.println( "Hibernate: " + statement );
+ }
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/ConnectionProviderBuilder.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.util.Properties;
+
+import org.hibernate.cfg.Environment;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.connection.DriverManagerConnectionProvider;
+
+/**
+ * ConnectionProviderBuilder implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ConnectionProviderBuilder {
+ public static ConnectionProvider buildConnectionProvider() {
+ Properties props = new Properties( null );
+ props.put( Environment.DRIVER, "org.hsqldb.jdbcDriver" );
+ props.put( Environment.URL, "jdbc:hsqldb:mem:target/test/db/hsqldb/hibernate" );
+ props.put( Environment.USER, "sa" );
+ DriverManagerConnectionProvider connectionProvider = new DriverManagerConnectionProvider();
+ connectionProvider.configure( props );
+ return connectionProvider;
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/BasicDelegationTests.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ConnectionReleaseMode;
+import org.hibernate.JDBCException;
+import org.hibernate.jdbc.impl.LogicalConnectionImpl;
+
+/**
+ * BasicDelegationTests implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicDelegationTests {
+
+ private TestingServiceImpl services = new TestingServiceImpl();
+
+ @BeforeClass
+ protected void create() {
+ services.prepare();
+ }
+
+ @AfterClass
+ protected void destroy() {
+ services.release();
+ }
+
+ @Test
+ public void testBasicJdbcUsage() throws JDBCException {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ ConnectionDelegate connection = new ConnectionDelegate( logicalConnection );
+
+ try {
+ try {
+ connection.prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
+ }
+ catch ( JDBCException ok ) {
+ // expected outcome
+ }
+
+ Statement stmnt = connection.createStatement();
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ logicalConnection.getJdbcContainer().close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+
+ PreparedStatement ps = connection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.execute();
+
+ ps = connection.prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ ps.executeQuery();
+
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.delegation;
+
+import java.sql.SQLException;
+
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainerBuilder;
+import org.hibernate.jdbc.ConnectionProviderBuilder;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.util.SQLStatementLogger;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.exception.SQLStateConverter;
+import org.hibernate.exception.ViolatedConstraintNameExtracter;
+
+/**
+ * TestingServiceImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public class TestingServiceImpl implements JDBCServices {
+ private ConnectionProvider connectionProvider;
+ private SQLStatementLogger sqlStatementLogger;
+ private JDBCContainerBuilder jdbcContainerBuilder;
+ private ExceptionHelper exceptionHelper;
+
+ public void prepare() {
+ connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
+ sqlStatementLogger = new SQLStatementLogger( true );
+ exceptionHelper = new ExceptionHelper(
+ new SQLStateConverter(
+ new ViolatedConstraintNameExtracter() {
+ public String extractConstraintName(SQLException e) {
+ return null;
+ }
+ }
+ )
+ );
+ jdbcContainerBuilder = new JDBCContainerBuilder() {
+ public JDBCContainer buildJdbcContainer() {
+ return new DelegateJDBCContainer( exceptionHelper );
+ }
+ };
+ }
+
+ public void release() {
+ connectionProvider.close();
+ }
+
+ public ConnectionProvider getConnectionProvider() {
+ return connectionProvider;
+ }
+
+ public JDBCContainerBuilder getJdbcContainerBuilder() {
+ return jdbcContainerBuilder;
+ }
+
+ public SQLStatementLogger getSqlStatementLogger() {
+ return sqlStatementLogger;
+ }
+
+ public ExceptionHelper getExceptionHelper() {
+ return exceptionHelper;
+ }
+}
\ No newline at end of file
Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/BasicConnectionTests.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/BasicConnectionTests.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/BasicConnectionTests.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ConnectionReleaseMode;
+
+/**
+ * BasicConnectionTests implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicConnectionTests {
+ private static final Logger log = LoggerFactory.getLogger( BasicConnectionTests.class );
+
+ private TestingServiceImpl services = new TestingServiceImpl();
+
+ @BeforeClass
+ protected void create() {
+ services.prepare();
+ }
+
+ @AfterClass
+ protected void destroy() {
+ services.release();
+ }
+
+ @Test
+ public void testBasicJdbcUsage() throws SQLException {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ try {
+ try {
+ logicalConnection.getConnection().prepareStatement( "select count(*) from NON_EXISTENT" ).executeQuery();
+ }
+ catch ( SQLException e ) {
+ // expected outcome
+ }
+
+ Statement stmnt = logicalConnection.getConnection().createStatement();
+ logicalConnection.getJdbcContainer().register( stmnt );
+ stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
+ stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ logicalConnection.getJdbcContainer().close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+
+
+ PreparedStatement ps = logicalConnection.getConnection().prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
+ logicalConnection.getJdbcContainer().register( ps );
+ ps.setLong( 1, 1 );
+ ps.setString( 2, "name" );
+ ps.executeUpdate();
+
+ ps = logicalConnection.getConnection().prepareStatement( "select * from SANDBOX_JDBC_TST" );
+ logicalConnection.getJdbcContainer().register( ps );
+ ResultSet rs = ps.executeQuery();
+ logicalConnection.getJdbcContainer().register( rs );
+
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+ finally {
+ logicalConnection.close();
+ }
+
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+import java.sql.SQLException;
+
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainerBuilder;
+import org.hibernate.jdbc.ConnectionProviderBuilder;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.util.SQLStatementLogger;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.exception.SQLStateConverter;
+import org.hibernate.exception.ViolatedConstraintNameExtracter;
+
+/**
+ * TestingServiceImpl implementation
+ *
+ * @author Steve Ebersole
+ */
+public class TestingServiceImpl implements JDBCServices {
+ private ConnectionProvider connectionProvider;
+ private SQLStatementLogger sqlStatementLogger;
+ private JDBCContainerBuilder jdbcContainerBuilder;
+ private ExceptionHelper exceptionHelper;
+
+ public void prepare() {
+ connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
+ sqlStatementLogger = new SQLStatementLogger( true );
+ exceptionHelper = new ExceptionHelper(
+ new SQLStateConverter(
+ new ViolatedConstraintNameExtracter() {
+ public String extractConstraintName(SQLException e) {
+ return null;
+ }
+ }
+ )
+ );
+ jdbcContainerBuilder = new JDBCContainerBuilder() {
+ public JDBCContainer buildJdbcContainer() {
+ return new BasicJDBCContainer( exceptionHelper );
+ }
+ };
+ }
+
+ public void release() {
+ connectionProvider.close();
+ }
+
+ public ConnectionProvider getConnectionProvider() {
+ return connectionProvider;
+ }
+
+ public JDBCContainerBuilder getJdbcContainerBuilder() {
+ return jdbcContainerBuilder;
+ }
+
+ public SQLStatementLogger getSqlStatementLogger() {
+ return sqlStatementLogger;
+ }
+
+ public ExceptionHelper getExceptionHelper() {
+ return exceptionHelper;
+ }
+}
Added: sandbox/trunk/jdbc-impl/src/test/resources/log4j.properties
===================================================================
--- sandbox/trunk/jdbc-impl/src/test/resources/log4j.properties (rev 0)
+++ sandbox/trunk/jdbc-impl/src/test/resources/log4j.properties 2007-08-14 17:19:22 UTC (rev 12935)
@@ -0,0 +1,23 @@
+################################################################################
+# Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved. #
+# #
+# 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, v. 2.1. This program is distributed in the #
+# hope that it will be useful, but WITHOUT A 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, v.2.1 along with this #
+# distribution; if not, write to the Free Software Foundation, Inc., #
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
+# #
+# Red Hat Author(s): Steve Ebersole #
+################################################################################
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+
+log4j.rootLogger=info, stdout
+
+log4j.logger.org.hibernate=trace
\ No newline at end of file
17 years, 4 months
Hibernate SVN: r12934 - in sandbox/trunk/jdbc-proxy/src: main/java/org/hibernate/jdbc/impl and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-14 13:15:42 -0400 (Tue, 14 Aug 2007)
New Revision: 12934
Added:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/StatementWrapper.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetWrapperImplementor.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/StatementWrapperImplementor.java
Removed:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/Observer.java
Modified:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/JDBCContainer.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxy.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxy.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/PreparedStatementProxy.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxy.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java
Log:
applied some lessons learned from the direct impl approach
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/JDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/JDBCContainer.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/JDBCContainer.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -32,5 +32,6 @@
public boolean hasRegisteredResources();
+ public void releaseResources();
public void close();
}
Deleted: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/Observer.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/Observer.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/Observer.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1. This program is distributed in the
- * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
- * distribution; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Red Hat Author(s): Steve Ebersole
- */
-package org.hibernate.jdbc;
-
-/**
- * Observer contract
- *
- * @author Steve Ebersole
- */
-public interface Observer {
- public void physicalConnectionObtained();
- public void physicalConnectionReleased();
- public void logicalConnectionClosed();
-}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/ResultSetWrapper.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.ResultSet;
+
+/**
+ * Extra contract for {@link ResultSet} proxies, for clients to be able to
+ * obtain the wrapped resultset.
+ *
+ * @author Steve Ebersole
+ */
+public interface ResultSetWrapper {
+ /**
+ * Obtain the wrapped resultset to which this wrapper is delegating.
+ *
+ * @return The wrapped resultset.
+ */
+ public ResultSet getWrappedResultSet();
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/StatementWrapper.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/StatementWrapper.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/StatementWrapper.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc;
+
+import java.sql.Statement;
+
+/**
+ * Extra contract for {@link Statement} proxies, for clients to be able to
+ * obtain the wrapped statement.
+ *
+ * @author Steve Ebersole
+ */
+public interface StatementWrapper {
+ /**
+ * Obtain the wrapped statement to which this wrapper is delegating.
+ *
+ * @return The wrapped statement.
+ */
+ public Statement getWrappedStatement();
+}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -15,15 +15,19 @@
*/
package org.hibernate.jdbc.impl;
+import java.sql.ResultSet;
import java.sql.Statement;
-import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
import java.util.HashSet;
-import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.util.ExceptionHelper;
import org.hibernate.jdbc.JDBCContainer;
/**
@@ -34,55 +38,111 @@
public class BasicJDBCContainer implements JDBCContainer {
private static final Logger log = LoggerFactory.getLogger( BasicJDBCContainer.class );
- protected final HashSet registeredStatements = new HashSet();
- protected final HashSet registeredResultSets = new HashSet();
+ private final ExceptionHelper exceptionHelper;
+ protected final HashMap xref = new HashMap();
- public final void register(Statement statement) {
- log.trace( "registering prepared statement [" + statement + "]" );
- registeredStatements.add( statement );
+ public BasicJDBCContainer(ExceptionHelper exceptionHelper) {
+ this.exceptionHelper = exceptionHelper;
}
- public final void release(Statement statement) {
- log.trace( "releasing prepared statement [" + statement + "]" );
- registeredStatements.remove( statement );
+ public void register(Statement statement) {
+ log.trace( "registering statement [" + statement + "]" );
+ if ( xref.containsKey( statement ) ) {
+ throw new HibernateException( "statement already registered with JDBCContainer" );
+ }
+ xref.put( statement, null );
+ }
+
+ public void release(Statement statement) {
+ log.trace( "releasing statement [" + statement + "]" );
+ Set resultSets = ( Set ) xref.get( statement );
+ if ( resultSets != null ) {
+ Iterator itr = resultSets.iterator();
+ while ( itr.hasNext() ) {
+ final ResultSet resultSet = ( ResultSet ) itr.next();
+ close( resultSet );
+ }
+ resultSets.clear();
+ }
+ xref.remove( statement );
close( statement );
}
- public final void register(ResultSet resultSet) {
+ public void register(ResultSet resultSet) {
log.trace( "registering result set [" + resultSet + "]" );
- registeredResultSets.add( resultSet );
+ Statement statement;
+ try {
+ statement = resultSet.getStatement();
+ }
+ catch ( SQLException e ) {
+ throw exceptionHelper.convert( e, "unable to access statement from resultset" );
+ }
+ if ( log.isWarnEnabled() && !xref.containsKey( statement ) ) {
+ log.warn( "resultset's statement was not yet registered" );
+ }
+ Set resultSets = ( Set ) xref.get( statement );
+ if ( resultSets == null ) {
+ resultSets = new HashSet();
+ xref.put( statement, resultSets );
+ }
+ resultSets.add( resultSet );
}
- public final void release(ResultSet resultSet) {
- log.trace( "releasing result set [" + resultSet + "]" );
- registeredResultSets.remove( resultSet );
+ public void release(ResultSet resultSet) {
+ log.trace( "releasing result set [{}]", resultSet );
+ Statement statement;
+ try {
+ statement = resultSet.getStatement();
+ }
+ catch ( SQLException e ) {
+ throw exceptionHelper.convert( e, "unable to access statement from resultset" );
+ }
+ if ( log.isWarnEnabled() && !xref.containsKey( statement ) ) {
+ log.warn( "resultset's statement was not registered" );
+ }
+ Set resultSets = ( Set ) xref.get( statement );
+ if ( resultSets != null ) {
+ resultSets.remove( resultSet );
+ }
close( resultSet );
}
public boolean hasRegisteredResources() {
- return ! ( registeredStatements.isEmpty() && registeredResultSets.isEmpty() );
+ return !xref.isEmpty();
}
- public void close() {
- log.trace( "closing JDBC container [" + this + "]" );
- Iterator iter;
- iter = registeredResultSets.iterator();
- while ( iter.hasNext() ) {
- close( ( ResultSet ) iter.next() );
- }
- registeredResultSets.clear();
+ public void releaseResources() {
+ log.trace( "releasing JDBC container resources [{}]", this );
+ cleanup();
+ }
- iter = registeredStatements.iterator();
- while ( iter.hasNext() ) {
- close( ( Statement ) iter.next() );
+ private void cleanup() {
+ Iterator statementIterator = xref.keySet().iterator();
+ while ( statementIterator.hasNext() ) {
+ final Statement statement = ( Statement ) statementIterator.next();
+ final Set resultSets = ( Set ) xref.get( statement );
+ if ( resultSets != null ) {
+ Iterator resultSetIterator = resultSets.iterator();
+ while ( resultSetIterator.hasNext() ) {
+ final ResultSet resultSet = ( ResultSet ) resultSetIterator.next();
+ close( resultSet );
+ }
+ resultSets.clear();
+ }
+ close( statement );
}
- registeredStatements.clear();
+ xref.clear();
}
+ public void close() {
+ log.trace( "closing JDBC container [{}]", this );
+ cleanup();
+ }
+
protected void close(Statement statement) {
- log.trace( "closing prepared statement [" + statement + "]" );
+ log.trace( "closing prepared statement [{}]", statement );
try {
- // if we are unable to "clan" the prepared statement,
+ // if we are unable to "clean" the prepared statement,
// we do not close it
try {
if ( statement.getMaxRows() != 0 ) {
@@ -94,23 +154,23 @@
}
catch( SQLException sqle ) {
// there was a problem "cleaning" the prepared statement
- log.debug( "Exception clearing maxRows/queryTimeout [" + sqle.getMessage() + "]" );
+ log.debug( "Exception clearing maxRows/queryTimeout [{}]", sqle.getMessage() );
return; // EARLY EXIT!!!
}
statement.close();
}
catch( SQLException sqle ) {
- log.debug( "Unable to release statement [" + sqle.getMessage() + "]" );
+ log.debug( "Unable to release statement [{}]", sqle.getMessage() );
}
}
protected void close(ResultSet resultSet) {
- log.trace( "closing result set [" + resultSet + "]" );
+ log.trace( "closing result set [{}]", resultSet );
try {
resultSet.close();
}
catch( SQLException e ) {
- log.debug( "Unable to release result set [" + e.getMessage() + "]" );
+ log.debug( "Unable to release result set [{}]", e.getMessage() );
}
}
}
Copied: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java (from rev 12911, sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/Observer.java)
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/ConnectionObserver.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.impl;
+
+/**
+ * ConnectionObserver contract
+ *
+ * @author Steve Ebersole
+ */
+public interface ConnectionObserver {
+ public void physicalConnectionObtained();
+ public void physicalConnectionReleased();
+ public void logicalConnectionClosed();
+}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImpl.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -29,7 +29,6 @@
import org.hibernate.JDBCException;
import org.hibernate.jdbc.JDBCServices;
import org.hibernate.jdbc.JDBCContainer;
-import org.hibernate.jdbc.Observer;
/**
* LogicalConnectionImpl implementation
@@ -84,28 +83,13 @@
/**
* {@inheritDoc}
*/
- public void addObserver(Observer observer) {
+ public void addObserver(ConnectionObserver observer) {
observers.add( observer );
}
/**
* {@inheritDoc}
*/
- public void afterStatement() {
- // todo : implement...
- }
-
- /**
- * {@inheritDoc}
- */
- public void afterTransaction() {
- // todo : implement...
- }
-
-
- /**
- * {@inheritDoc}
- */
public boolean isOpen() {
return !isClosed;
}
@@ -141,14 +125,14 @@
log.trace( "closing logical connection" );
Connection c = physicalConnection;
if ( !isUserSuppliedConnection && physicalConnection != null ) {
+ jdbcContainer.close();
releaseConnection();
}
// not matter what
physicalConnection = null;
isClosed = true;
- jdbcContainer.close();
for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
- ( ( Observer ) itr.next() ).logicalConnectionClosed();
+ ( ( ConnectionObserver ) itr.next() ).logicalConnectionClosed();
}
log.trace( "logical connection closed" );
return c;
@@ -165,20 +149,26 @@
// public boolean isAutoCommit() throws SQLException {
// return physicalConnection == null || physicalConnection.getAutoCommit();
// }
-//
-// /**
-// * Force aggresive release of the underlying connection.
-// */
-// public void aggressiveRelease() {
-// if ( !isUserSuppliedConnection ) {
-// log.debug( "aggressively releasing JDBC connection" );
-// if ( physicalConnection != null ) {
-// releaseConnection();
-// }
-// }
-// }
+ /**
+ * Force aggresive release of the underlying connection.
+ */
+ public void aggressiveRelease() {
+ if ( isUserSuppliedConnection ) {
+ log.debug( "cannot aggresively release user-supplied connection; skipping" );
+ }
+ else if ( ! getJdbcServices().getConnectionProvider().supportsAggressiveRelease() ) {
+ log.debug( "connection provider reports to not support aggreswsive release; skipping" );
+ }
+ else {
+ log.debug( "aggressively releasing JDBC connection" );
+ if ( physicalConnection != null ) {
+ releaseConnection();
+ }
+ }
+ }
+
/**
* Pysically opens a JDBC Connection.
*
@@ -189,7 +179,7 @@
try {
physicalConnection = getJdbcServices().getConnectionProvider().getConnection();
for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
- ( ( Observer ) itr.next() ).physicalConnectionObtained();
+ ( ( ConnectionObserver ) itr.next() ).physicalConnectionObtained();
}
log.debug( "obtained JDBC connection" );
}
@@ -209,11 +199,11 @@
if ( !physicalConnection.isClosed() ) {
getJdbcServices().getExceptionHelper().logAndClearWarnings( physicalConnection );
}
- getJdbcServices().getConnectionProvider().closeConnection( physicalConnection );
- physicalConnection = null;
for ( Iterator itr = observers.iterator(); itr.hasNext(); ) {
- ( ( Observer ) itr.next() ).physicalConnectionReleased();
+ ( ( ConnectionObserver ) itr.next() ).physicalConnectionReleased();
}
+ getJdbcServices().getConnectionProvider().closeConnection( physicalConnection );
+ physicalConnection = null;
log.debug( "released JDBC connection" );
}
catch (SQLException sqle) {
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/LogicalConnectionImplementor.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -19,7 +19,6 @@
import org.hibernate.jdbc.JDBCContainer;
import org.hibernate.jdbc.JDBCServices;
import org.hibernate.jdbc.LogicalConnection;
-import org.hibernate.jdbc.Observer;
/**
* The "internal" contract for LogicalConnection
@@ -34,9 +33,7 @@
public JDBCContainer getJdbcContainer();
- public void addObserver(Observer observer);
+ public void addObserver(ConnectionObserver observer);
- public void afterStatement();
-
- public void afterTransaction();
+ public void aggressiveRelease();
}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxy.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxy.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxy.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -18,15 +18,9 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.sql.CallableStatement;
-import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,24 +35,22 @@
* @author Steve Ebersole
*/
public abstract class AbstractStatementProxy implements InvocationHandler {
- public static final Class[] PROXY_INTERFACES = new Class[] { Statement.class };
- public static final Class[] PS_PROXY_INTERFACES = new Class[] { PreparedStatement.class };
- public static final Class[] CS_PROXY_INTERFACES = new Class[] { CallableStatement.class };
private static final Logger log = LoggerFactory.getLogger( AbstractStatementProxy.class );
private boolean valid = true;
private Statement statement;
private ConnectionProxy connectionProxy;
- private Set resultSetProxies;
protected AbstractStatementProxy(Statement statement, ConnectionProxy connectionProxy) {
this.statement = statement;
this.connectionProxy = connectionProxy;
- getJdbcContainer().register( statement );
}
protected Statement getStatement() {
+ if ( !valid ) {
+ throw new HibernateException( "statment proxy is no longer valid" );
+ }
return statement;
}
@@ -66,10 +58,6 @@
return connectionProxy;
}
- protected Set getResultSetProxies() {
- return resultSetProxies;
- }
-
protected JDBCServices getJdbcServices() {
return getConnectionProxy().getJdbcServices();
}
@@ -78,19 +66,12 @@
return getConnectionProxy().getJdbcContainer();
}
- protected Set getOrCreateResultSetProxies() {
- if ( resultSetProxies == null ) {
- resultSetProxies = new HashSet();
- }
- return resultSetProxies;
- }
-
public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
log.trace( "Handling invocation of statement method [{}]", methodName );
- if ( !valid ) {
- throw new HibernateException( "connection handle is invalid" );
+ if ( "toString".equals( methodName ) ) {
+ return this.toString();
}
if ( "close".equals( methodName ) ) {
@@ -98,6 +79,19 @@
return null;
}
+ if ( "invalidate".equals( methodName ) ) {
+ invalidateHandle();
+ return null;
+ }
+
+ if ( "getWrappedStatement".equals( methodName ) ) {
+ return getStatement();
+ }
+
+ if ( !valid ) {
+ throw new HibernateException( "connection handle is no longer valid" );
+ }
+
beginningInvocationHandling( method, args );
try {
@@ -106,13 +100,8 @@
Object result = method.invoke( statement, args );
if ( exposingResultSet ) {
- ResultSetProxy handler = new ResultSetProxy( ( ResultSet ) result, this );
- result = Proxy.newProxyInstance(
- getClass().getClassLoader(),
- ResultSetProxy.PROXY_INTERFACES,
- handler
- );
- getOrCreateResultSetProxies().add( result );
+ result = ProxyBuilder.buildResultSet( ( ResultSet ) result, this );
+ getJdbcContainer().register( ( ResultSet ) result );
}
return result;
@@ -132,26 +121,14 @@
}
private void explicitClose(Statement proxy) {
- if ( resultSetProxies != null ) {
- Iterator itr = resultSetProxies.iterator();
- while ( itr.hasNext() ) {
- final ResultSet resultSetProxy = ( ResultSet ) itr.next();
- try {
- resultSetProxy.close();
- }
- catch ( SQLException e ) {
- // should never ever happen...
- log.warn( "unhandled SQLException escaped proxy handling!", e );
- // but the underlying resources should still get cleaned up when the logical connection closes...
- }
- itr.remove();
- }
+ if ( valid ) {
+ getJdbcContainer().release( proxy );
}
- connectionProxy.getJdbcContainer().release( statement );
- connectionProxy.proxiedStatementExplicitlyClosed( proxy );
- statement = null;
+ }
+
+ private void invalidateHandle() {
connectionProxy = null;
- resultSetProxies = null;
+ statement = null;
valid = false;
}
@@ -159,8 +136,4 @@
return ResultSet.class.isAssignableFrom( method.getReturnType() )
&& !method.getName().equals( "getGeneratedKeys" );
}
-
- /*package-protected*/ void proxiedResultSetExplicitlyClosed(ResultSet proxy) {
- resultSetProxies.remove( proxy );
- }
}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxy.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxy.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxy.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -18,23 +18,19 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
+import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
-import org.hibernate.jdbc.ConnectionWrapper;
import org.hibernate.jdbc.JDBCContainer;
import org.hibernate.jdbc.JDBCServices;
-import org.hibernate.jdbc.Observer;
+import org.hibernate.jdbc.impl.ConnectionObserver;
import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
/**
@@ -42,14 +38,12 @@
*
* @author Steve Ebersole
*/
-public class ConnectionProxy implements InvocationHandler, Observer {
- public static final Class[] PROXY_INTERFACES = new Class[] { Connection.class, ConnectionWrapper.class };
+public class ConnectionProxy implements InvocationHandler, ConnectionObserver {
private static final Logger log = LoggerFactory.getLogger( ConnectionProxy.class );
private boolean valid = true;
private LogicalConnectionImplementor logicalConnection;
- private HashSet statementProxies;
public ConnectionProxy(LogicalConnectionImplementor logicalConnection) {
this.logicalConnection = logicalConnection;
@@ -58,8 +52,17 @@
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
- log.trace( "Handling invocation of Connection method [{}]", methodName );
+ log.trace( "Handling invocation of connection method [{}]", methodName );
+ if ( "close".equals( methodName ) ) {
+ explicitClose();
+ return null;
+ }
+
+ if ( "toString".equals( methodName ) ) {
+ return this.toString();
+ }
+
if ( !valid ) {
throw new HibernateException( "connection handle is invalid" );
}
@@ -68,11 +71,6 @@
return extractPhysicalConnection();
}
- if ( "close".equals( methodName ) ) {
- explicitClose();
- return null;
- }
-
try {
boolean creatingBasicStatement = "createStatement".equals( methodName );
boolean creatingPreparedStatement = "prepareStatement".equals( methodName );
@@ -81,27 +79,16 @@
Object result = method.invoke( extractPhysicalConnection(), args );
if ( creatingBasicStatement || creatingPreparedStatement || creatingCallableStatement ) {
- AbstractStatementProxy proxyHandler;
- Class[] interfaces;
if ( creatingPreparedStatement ) {
- proxyHandler = new PreparedStatementProxy( ( String ) args[0], ( PreparedStatement ) result, this );
- interfaces = AbstractStatementProxy.PS_PROXY_INTERFACES;
+ result = ProxyBuilder.buildPreparedStatement( ( String ) args[0], ( PreparedStatement ) result, this );
}
else if ( creatingCallableStatement ) {
- proxyHandler = new PreparedStatementProxy( ( String ) args[0], ( PreparedStatement ) result, this );
- interfaces = AbstractStatementProxy.CS_PROXY_INTERFACES;
+ result = ProxyBuilder.buildCallableStatement( ( String ) args[0], ( CallableStatement ) result, this );
}
else {
- proxyHandler = new StatementProxy( ( Statement ) result, this );
- interfaces = AbstractStatementProxy.PROXY_INTERFACES;
+ result = ProxyBuilder.buildStatement( ( Statement ) result, this );
}
-
- result = Proxy.newProxyInstance(
- getClass().getClassLoader(), // use our classloader
- interfaces,
- proxyHandler
- );
- getOrCreateStatementProxies().add( result );
+ getJdbcContainer().register( ( Statement ) result );
}
return result;
@@ -109,7 +96,7 @@
catch( InvocationTargetException e ) {
Throwable realException = e.getTargetException();
if ( SQLException.class.isInstance( realException ) ) {
- throw logicalConnection.getJdbcServices().getExceptionHelper().convert( ( SQLException ) realException, "???", "???" );
+ throw logicalConnection.getJdbcServices().getExceptionHelper().convert( ( SQLException ) realException, realException.getMessage(), "???" );
}
else {
throw realException;
@@ -117,49 +104,22 @@
}
}
- private Set getOrCreateStatementProxies() {
- if ( statementProxies == null ) {
- statementProxies = new HashSet();
- }
- return statementProxies;
- }
-
private void explicitClose() {
- if ( statementProxies != null ) {
- Iterator itr = statementProxies.iterator();
- while ( itr.hasNext() ) {
- final Statement proxy = ( Statement ) itr.next();
- try {
- proxy.close();
- }
- catch ( SQLException e ) {
- // should never ever happen...
- log.warn( "unhandled SQLException escaped proxy handling!", e );
- // but the underlying resources should still get cleaned up when the logical connection closes...
- }
- }
+ if ( valid ) {
+ invalidateHandle();
}
- invalidateHandle();
}
private void invalidateHandle() {
log.trace( "Invalidating connection handle" );
logicalConnection = null;
valid = false;
- if ( statementProxies != null ) {
- statementProxies.clear();
- statementProxies = null;
- }
}
private Connection extractPhysicalConnection() {
return logicalConnection.getConnection();
}
- /*package-protected*/ void proxiedStatementExplicitlyClosed(Statement proxy) {
- statementProxies.remove( proxy );
- }
-
/*package-protected*/ JDBCServices getJdbcServices() {
return logicalConnection.getJdbcServices();
}
@@ -168,7 +128,7 @@
return logicalConnection.getJdbcContainer();
}
- // JDBC Observer impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // JDBC ConnectionObserver impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void physicalConnectionObtained() {
}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/PreparedStatementProxy.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/PreparedStatementProxy.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/PreparedStatementProxy.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -16,6 +16,7 @@
package org.hibernate.jdbc.proxy;
import java.sql.Statement;
+import java.lang.reflect.Method;
/**
* PreparedStatementProxy implementation
@@ -30,4 +31,31 @@
connectionProxy.getJdbcServices().getSqlStatementLogger().logStatement( sql );
this.sql = sql;
}
+
+ protected void beginningInvocationHandling(Method method, Object[] args) {
+ if ( isExecution( method ) ) {
+ logExecution();
+ }
+ else {
+ journalPossibleParameterBind( method, args );
+ }
+ }
+
+ private void journalPossibleParameterBind(Method method, Object[] args) {
+ String methodName = method.getName();
+ // todo : is this enough???
+ if ( methodName.startsWith( "set" ) && args != null && args.length >= 2 ) {
+ journalParameterBind( method, args );
+ }
+ }
+
+ private void journalParameterBind(Method method, Object[] args) {
+ }
+
+ private boolean isExecution(Method method) {
+ return false;
+ }
+
+ private void logExecution() {
+ }
}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.proxy;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+import java.sql.CallableStatement;
+import java.sql.ResultSet;
+import java.lang.reflect.Proxy;
+
+import org.hibernate.jdbc.ConnectionWrapper;
+import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
+
+/**
+ * ProxyBuilder implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ProxyBuilder {
+
+ // static for now simply to alleviate question about where to keep it...
+
+ public static final Class[] CONNECTION_PROXY_INTERFACES = new Class[] { Connection.class, ConnectionWrapper.class };
+
+ public static final Class[] STMNT_PROXY_INTERFACES = new Class[] { Statement.class, StatementWrapperImplementor.class };
+ public static final Class[] PREPARED_STMNT_PROXY_INTERFACES = new Class[] { PreparedStatement.class, StatementWrapperImplementor.class };
+ public static final Class[] CALLABLE_STMNT_PROXY_INTERFACES = new Class[] { CallableStatement.class, StatementWrapperImplementor.class };
+
+ public static final Class[] RESULTSET_PROXY_INTERFACES = new Class[] { ResultSet.class, ResultSetWrapperImplementor.class };
+
+ public static Connection buildConnection(LogicalConnectionImplementor logicalConnection) {
+ ConnectionProxy proxyHandler = new ConnectionProxy( logicalConnection );
+ return ( Connection ) Proxy.newProxyInstance(
+ ConnectionWrapper.class.getClassLoader(),
+ CONNECTION_PROXY_INTERFACES,
+ proxyHandler
+ );
+ }
+
+ public static Statement buildStatement(Statement statement, ConnectionProxy connectionProxy) {
+ StatementProxy proxyHandler = new StatementProxy( statement, connectionProxy );
+ return ( Statement ) Proxy.newProxyInstance(
+ StatementWrapperImplementor.class.getClassLoader(),
+ STMNT_PROXY_INTERFACES,
+ proxyHandler
+ );
+ }
+
+ public static PreparedStatement buildPreparedStatement(String sql, PreparedStatement statement, ConnectionProxy connectionProxy) {
+ PreparedStatementProxy proxyHandler = new PreparedStatementProxy( sql, statement, connectionProxy );
+ return ( PreparedStatement ) Proxy.newProxyInstance(
+ StatementWrapperImplementor.class.getClassLoader(),
+ PREPARED_STMNT_PROXY_INTERFACES,
+ proxyHandler
+ );
+ }
+
+ public static CallableStatement buildCallableStatement(String sql, CallableStatement statement, ConnectionProxy connectionProxy) {
+ PreparedStatementProxy proxyHandler = new PreparedStatementProxy( sql, statement, connectionProxy );
+ return ( CallableStatement ) Proxy.newProxyInstance(
+ StatementWrapperImplementor.class.getClassLoader(),
+ CALLABLE_STMNT_PROXY_INTERFACES,
+ proxyHandler
+ );
+ }
+
+ public static ResultSet buildResultSet(ResultSet resultSet, AbstractStatementProxy statementProxy) {
+ ResultSetProxy proxyHandler = new ResultSetProxy( resultSet, statementProxy );
+ return ( ResultSet ) Proxy.newProxyInstance(
+ ResultSetWrapperImplementor.class.getClassLoader(),
+ RESULTSET_PROXY_INTERFACES,
+ proxyHandler
+ );
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.proxy;
+
+import java.sql.Statement;
+import java.sql.ResultSet;
+
+import org.hibernate.jdbc.impl.BasicJDBCContainer;
+import org.hibernate.jdbc.util.ExceptionHelper;
+
+/**
+ * ProxyJDBCContainer implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ProxyJDBCContainer extends BasicJDBCContainer {
+ public ProxyJDBCContainer(ExceptionHelper exceptionHelper) {
+ super( exceptionHelper );
+ }
+
+ protected void close(Statement statement) {
+ if ( statement instanceof StatementWrapperImplementor ) {
+ StatementWrapperImplementor wrapper = ( StatementWrapperImplementor ) statement;
+ super.close( wrapper.getWrappedStatement() );
+ wrapper.invalidate();
+ }
+ else {
+ super.close( statement );
+ }
+ }
+
+ protected void close(ResultSet resultSet) {
+ if ( resultSet instanceof ResultSetWrapperImplementor ) {
+ ResultSetWrapperImplementor wrapper = ( ResultSetWrapperImplementor ) resultSet;
+ super.close( wrapper.getWrappedResultSet() );
+ wrapper.invalidate();
+ }
+ else {
+ super.close( resultSet );
+ }
+ }
+}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxy.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxy.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxy.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -25,6 +25,8 @@
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCServices;
+import org.hibernate.jdbc.JDBCContainer;
/**
* ResultSetProxy implementation
@@ -32,7 +34,6 @@
* @author Steve Ebersole
*/
public class ResultSetProxy implements InvocationHandler {
- public static final Class[] PROXY_INTERFACES = new Class[] { ResultSet.class };
private static final Logger log = LoggerFactory.getLogger( ResultSetProxy.class );
@@ -46,12 +47,35 @@
associatedStatementProxy.getJdbcContainer().register( physicalResultSet );
}
+ protected ResultSet getResultSet() {
+ errorIfInvalid();
+ return physicalResultSet;
+ }
+
+ protected void errorIfInvalid() {
+ if ( !valid ) {
+ throw new HibernateException( "resultset handle is no longer valid" );
+ }
+ }
+
+ protected AbstractStatementProxy getStatementProxy() {
+ return associatedStatementProxy;
+ }
+
+ protected JDBCServices getJdbcServices() {
+ return getStatementProxy().getJdbcServices();
+ }
+
+ protected JDBCContainer getJdbcContainer() {
+ return getStatementProxy().getJdbcContainer();
+ }
+
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
log.trace( "Handling invocation of resultset method [{}]", methodName );
- if ( !valid ) {
- throw new HibernateException( "connection handle is invalid" );
+ if ( "toString".equals( methodName ) ) {
+ return this.toString();
}
if ( "close".equals( methodName ) ) {
@@ -59,13 +83,24 @@
return null;
}
+ if ( "invalidate".equals( methodName ) ) {
+ invalidateHandle();
+ return null;
+ }
+
+ if ( "getWrappedStatement".equals( methodName ) ) {
+ return getResultSet();
+ }
+
+ errorIfInvalid();
+
try {
return method.invoke( physicalResultSet, args );
}
catch ( InvocationTargetException e ) {
Throwable realException = e.getTargetException();
if ( SQLException.class.isInstance( realException ) ) {
- throw associatedStatementProxy.getJdbcServices().getExceptionHelper().convert( ( SQLException ) realException, "???", "???" );
+ throw getJdbcServices().getExceptionHelper().convert( ( SQLException ) realException, "???" );
}
else {
throw realException;
@@ -74,10 +109,14 @@
}
private void explicitClose(ResultSet proxy) {
- associatedStatementProxy.getJdbcContainer().release( physicalResultSet );
- associatedStatementProxy.proxiedResultSetExplicitlyClosed( proxy );
+ if ( valid ) {
+ associatedStatementProxy.getJdbcContainer().release( proxy );
+ }
+ }
+
+ private void invalidateHandle() {
+ associatedStatementProxy = null;
physicalResultSet = null;
- associatedStatementProxy = null;
valid = false;
}
}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetWrapperImplementor.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetWrapperImplementor.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.proxy;
+
+import org.hibernate.jdbc.ResultSetWrapper;
+
+/**
+ * Extra, internal contract for implementations of ResultSetWrapper for allowing
+ * invalidation of the wrapper.
+ *
+ * @author Steve Ebersole
+ */
+public interface ResultSetWrapperImplementor extends ResultSetWrapper {
+ /**
+ * Make the wrapper invalid for further usage.
+ */
+ public void invalidate();
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/StatementWrapperImplementor.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/StatementWrapperImplementor.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/StatementWrapperImplementor.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.jdbc.proxy;
+
+import org.hibernate.jdbc.StatementWrapper;
+
+/**
+ * Extra, internal contract for implementations of StatementWrapper for allowing
+ * invalidation of the wrapper.
+ *
+ * @author Steve Ebersole
+ */
+public interface StatementWrapperImplementor extends StatementWrapper {
+ /**
+ * Make the wrapper invalid for further usage.
+ */
+ public void invalidate();
+}
Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -41,11 +41,6 @@
public void prepare() {
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
sqlStatementLogger = new SQLStatementLogger( true );
- jdbcContainerBuilder = new JDBCContainerBuilder() {
- public JDBCContainer buildJdbcContainer() {
- return new BasicJDBCContainer();
- }
- };
exceptionHelper = new ExceptionHelper(
new SQLStateConverter(
new ViolatedConstraintNameExtracter() {
@@ -55,6 +50,11 @@
}
)
);
+ jdbcContainerBuilder = new JDBCContainerBuilder() {
+ public JDBCContainer buildJdbcContainer() {
+ return new BasicJDBCContainer( exceptionHelper );
+ }
+ };
}
public void release() {
Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -35,7 +35,6 @@
import org.hibernate.JDBCException;
import org.hibernate.jdbc.ConnectionWrapper;
import org.hibernate.jdbc.impl.LogicalConnectionImpl;
-import org.hibernate.jdbc.impl.TestingServiceImpl;
/**
* BasicConnectionProxyTest implementation
@@ -45,7 +44,7 @@
public class BasicConnectionProxyTest {
private static final Logger log = LoggerFactory.getLogger( BasicConnectionProxyTest.class );
- private org.hibernate.jdbc.impl.TestingServiceImpl services = new TestingServiceImpl();
+ private TestingServiceImpl services = new TestingServiceImpl();
@BeforeClass
protected void create() {
@@ -79,7 +78,7 @@
stmnt.execute( "drop table SANDBOX_JDBC_TST if exists" );
stmnt.execute( "create table SANDBOX_JDBC_TST ( ID integer, NAME varchar(100) )" );
assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
- logicalConnection.getJdbcContainer().close();
+ logicalConnection.getJdbcContainer().releaseResources();
assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
PreparedStatement ps = proxiedConnection.prepareStatement( "insert into SANDBOX_JDBC_TST( ID, NAME ) values ( ?, ? )" );
Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java 2007-08-14 14:27:03 UTC (rev 12933)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java 2007-08-14 17:15:42 UTC (rev 12934)
@@ -21,7 +21,6 @@
import org.hibernate.jdbc.JDBCContainerBuilder;
import org.hibernate.jdbc.ConnectionProviderBuilder;
import org.hibernate.jdbc.JDBCContainer;
-import org.hibernate.jdbc.impl.BasicJDBCContainer;
import org.hibernate.jdbc.util.SQLStatementLogger;
import org.hibernate.jdbc.util.ExceptionHelper;
import org.hibernate.connection.ConnectionProvider;
@@ -42,12 +41,6 @@
public void prepare() {
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
sqlStatementLogger = new SQLStatementLogger( true );
- jdbcContainerBuilder = new JDBCContainerBuilder() {
- public JDBCContainer buildJdbcContainer() {
- // todo : need to over ride this to handle statement/resultset proxies properly
- return new BasicJDBCContainer();
- }
- };
exceptionHelper = new ExceptionHelper(
new SQLStateConverter(
new ViolatedConstraintNameExtracter() {
@@ -57,6 +50,11 @@
}
)
);
+ jdbcContainerBuilder = new JDBCContainerBuilder() {
+ public JDBCContainer buildJdbcContainer() {
+ return new ProxyJDBCContainer( exceptionHelper );
+ }
+ };
}
public void release() {
17 years, 4 months
Hibernate SVN: r12933 - core/trunk/documentation/manual/en-US/src/main/docbook/modules.
by hibernate-commits@lists.jboss.org
Author: d.plentz
Date: 2007-08-14 10:27:03 -0400 (Tue, 14 Aug 2007)
New Revision: 12933
Modified:
core/trunk/documentation/manual/en-US/src/main/docbook/modules/configuration.xml
Log:
[HHH-2519] Schema dropping not documented with hibernate.hbm2ddl.auto=create
Modified: core/trunk/documentation/manual/en-US/src/main/docbook/modules/configuration.xml
===================================================================
--- core/trunk/documentation/manual/en-US/src/main/docbook/modules/configuration.xml 2007-08-14 13:49:08 UTC (rev 12932)
+++ core/trunk/documentation/manual/en-US/src/main/docbook/modules/configuration.xml 2007-08-14 14:27:03 UTC (rev 12933)
@@ -989,9 +989,15 @@
<entry>
Automatically validate or export schema DDL to the database
when the <literal>SessionFactory</literal> is created. With
- <literal>create-drop</literal>, the database schema will be
- dropped when the <literal>SessionFactory</literal> is closed
- explicitly.
+ <literal>create</literal>, the database schema will be dropped
+ and re-created when the <literal>SessionFactory</literal> is
+ created. <literal>create-drop</literal> implies
+ <literal>create</literal>, and will additionally cause the
+ schema be dropped when the <literal>SessionFactory</literal>
+ is closed explicitly. With <literal>update</literal>, the
+ schema will not be dropped, but is updated. <literal>validate</literal>
+ will check the database for required tables/columns and throw an
+ Exception if something is missing.
<para>
<emphasis role="strong">eg.</emphasis>
<literal>validate</literal> | <literal>update</literal> |
17 years, 4 months
Hibernate SVN: r12932 - core/trunk/core/src/main/java/org/hibernate/transaction.
by hibernate-commits@lists.jboss.org
Author: d.plentz
Date: 2007-08-14 09:49:08 -0400 (Tue, 14 Aug 2007)
New Revision: 12932
Added:
core/trunk/core/src/main/java/org/hibernate/transaction/BTMTransactionManagerLookup.java
Log:
[HHH-2778] TransactionManagerLookup implementation for Bitronix Transaction Manager
Added: core/trunk/core/src/main/java/org/hibernate/transaction/BTMTransactionManagerLookup.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/transaction/BTMTransactionManagerLookup.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/transaction/BTMTransactionManagerLookup.java 2007-08-14 13:49:08 UTC (rev 12932)
@@ -0,0 +1,34 @@
+package org.hibernate.transaction;
+
+import java.util.Properties;
+
+import javax.transaction.TransactionManager;
+
+import org.hibernate.HibernateException;
+
+/**
+ * TransactionManager lookup strategy for BTM
+ * @author Ludovic Orban
+ */
+public class BTMTransactionManagerLookup implements TransactionManagerLookup {
+
+ /**
+ * @see org.hibernate.transaction.TransactionManagerLookup#getTransactionManager(Properties)
+ */
+ public TransactionManager getTransactionManager(Properties props) throws HibernateException {
+ try {
+ Class clazz = Class.forName("bitronix.tm.TransactionManagerServices");
+ return (TransactionManager) clazz.getMethod("getTransactionManager", null).invoke(null, null);
+ }
+ catch (Exception e) {
+ throw new HibernateException( "Could not obtain BTM transaction manager instance", e );
+ }
+ }
+
+ /**
+ * @see org.hibernate.transaction.TransactionManagerLookup#getUserTransactionName()
+ */
+ public String getUserTransactionName() {
+ return "java:comp/UserTransaction";
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/core/src/main/java/org/hibernate/transaction/BTMTransactionManagerLookup.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
17 years, 4 months
Hibernate SVN: r12931 - core/trunk/core/src/main/java/org/hibernate/type.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-13 18:38:26 -0400 (Mon, 13 Aug 2007)
New Revision: 12931
Modified:
core/trunk/core/src/main/java/org/hibernate/type/OrderedMapType.java
core/trunk/core/src/main/java/org/hibernate/type/OrderedSetType.java
Log:
HHH-2749 : direct use of LinkedHashSet/LinkedHashMap
Modified: core/trunk/core/src/main/java/org/hibernate/type/OrderedMapType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/OrderedMapType.java 2007-08-13 22:17:29 UTC (rev 12930)
+++ core/trunk/core/src/main/java/org/hibernate/type/OrderedMapType.java 2007-08-13 22:38:26 UTC (rev 12931)
@@ -24,7 +24,9 @@
* {@inheritDoc}
*/
public Object instantiate(int anticipatedSize) {
- return new LinkedHashMap( anticipatedSize );
+ return anticipatedSize > 0
+ ? new LinkedHashMap( anticipatedSize )
+ : new LinkedHashMap();
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/OrderedSetType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/OrderedSetType.java 2007-08-13 22:17:29 UTC (rev 12930)
+++ core/trunk/core/src/main/java/org/hibernate/type/OrderedSetType.java 2007-08-13 22:38:26 UTC (rev 12931)
@@ -24,7 +24,9 @@
* {@inheritDoc}
*/
public Object instantiate(int anticipatedSize) {
- return new LinkedHashSet( anticipatedSize );
+ return anticipatedSize > 0
+ ? new LinkedHashSet( anticipatedSize )
+ : new LinkedHashSet();
}
}
17 years, 4 months
Hibernate SVN: r12930 - core/trunk/testsuite.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-13 18:17:29 -0400 (Mon, 13 Aug 2007)
New Revision: 12930
Modified:
core/trunk/testsuite/pom.xml
Log:
oops... removed testng dep, as i was just playing with it locally
Modified: core/trunk/testsuite/pom.xml
===================================================================
--- core/trunk/testsuite/pom.xml 2007-08-13 22:16:21 UTC (rev 12929)
+++ core/trunk/testsuite/pom.xml 2007-08-13 22:17:29 UTC (rev 12930)
@@ -96,13 +96,15 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
- </dependency>
+ </dependency>
+<!--
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.5</version>
<classifier>jdk15</classifier>
- </dependency>
+ </dependency>
+-->
</dependencies>
<build>
17 years, 4 months
Hibernate SVN: r12929 - core/trunk/testsuite/src/test/java/org/hibernate/test/readonly.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-13 18:16:21 -0400 (Mon, 13 Aug 2007)
New Revision: 12929
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/TextHolder.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/TextHolder.java
Log:
added additional test
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/TextHolder.hbm.xml (from rev 12891, core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/DataPoint.hbm.xml)
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/TextHolder.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/TextHolder.hbm.xml 2007-08-13 22:16:21 UTC (rev 12929)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ ~ Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ ~
+ ~ 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, v. 2.1. This program is distributed in the
+ ~ hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ ~ distribution; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ~
+ ~ Red Hat Author(s): Steve Ebersole
+ -->
+<hibernate-mapping package="org.hibernate.test.readonly">
+
+ <class name="TextHolder" >
+ <id name="id">
+ <generator class="increment"/>
+ </id>
+ <property name="theText" column="TXT" type="text"/>
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/TextHolder.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/TextHolder.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/TextHolder.java 2007-08-13 22:16:21 UTC (rev 12929)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.test.readonly;
+
+/**
+ * TextHolder implementation
+ *
+ * @author Steve Ebersole
+ */
+public class TextHolder {
+ private Long id;
+ private String theText;
+
+ public TextHolder() {
+ }
+
+ public TextHolder(String theText) {
+ this.theText = theText;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTheText() {
+ return theText;
+ }
+
+ public void setTheText(String theText) {
+ this.theText = theText;
+ }
+}
17 years, 4 months
Hibernate SVN: r12928 - core/trunk/testsuite/src/test/java/org/hibernate/test/readonly.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-13 18:15:53 -0400 (Mon, 13 Aug 2007)
New Revision: 12928
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyTest.java
Log:
added additional test
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyTest.java 2007-08-13 20:04:46 UTC (rev 12927)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyTest.java 2007-08-13 22:15:53 UTC (rev 12928)
@@ -28,7 +28,7 @@
}
public String[] getMappings() {
- return new String[] { "readonly/DataPoint.hbm.xml" };
+ return new String[] { "readonly/DataPoint.hbm.xml", "readonly/TextHolder.hbm.xml" };
}
public void configure(Configuration cfg) {
@@ -117,5 +117,36 @@
}
+ public void testReadOnlyOnTextType() {
+ final String origText = "some huge text string";
+ final String newText = "some even bigger text string";
+
+ Session s = openSession();
+ s.beginTransaction();
+ s.setCacheMode( CacheMode.IGNORE );
+ TextHolder holder = new TextHolder( origText );
+ s.save( holder );
+ Long id = holder.getId();
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ s.setCacheMode( CacheMode.IGNORE );
+ holder = ( TextHolder ) s.get( TextHolder.class, id );
+ s.setReadOnly( holder, true );
+ holder.setTheText( newText );
+ s.flush();
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ holder = ( TextHolder ) s.get( TextHolder.class, id );
+ assertEquals( "change written to database", origText, holder.getTheText() );
+ s.delete( holder );
+ s.getTransaction().commit();
+ s.close();
+ }
}
17 years, 4 months