Hibernate SVN: r13957 - in core/trunk: testsuite/src/test/java/org/hibernate/test/reattachment and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2007-08-28 20:50:12 -0400 (Tue, 28 Aug 2007)
New Revision: 13957
Modified:
core/trunk/core/src/main/java/org/hibernate/impl/IteratorImpl.java
core/trunk/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java
Log:
HHH-2728 : session.clear() while retrieving objects via an iterator
Modified: core/trunk/core/src/main/java/org/hibernate/impl/IteratorImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/IteratorImpl.java 2007-08-29 00:47:06 UTC (rev 13956)
+++ core/trunk/core/src/main/java/org/hibernate/impl/IteratorImpl.java 2007-08-29 00:50:12 UTC (rev 13957)
@@ -1,4 +1,4 @@
-//$Id: IteratorImpl.java 9944 2006-05-24 21:14:56Z steve.ebersole(a)jboss.com $
+//$Id: IteratorImpl.java 11651 2007-06-07 18:22:50Z steve.ebersole(a)jboss.com $
package org.hibernate.impl;
import java.sql.PreparedStatement;
@@ -34,7 +34,6 @@
private boolean hasNext;
private final String[][] names;
private PreparedStatement ps;
- private Object nextResult;
private HolderInstantiator holderInstantiator;
public IteratorImpl(
@@ -55,14 +54,18 @@
single = types.length==1;
- postNext();
+ // rs.isBeforeFirst() will return false if rs contains no rows
+ hasNext = this.rs.isBeforeFirst();
+ if ( !hasNext ) {
+ log.debug("ResultSet contains no rows");
+ close();
+ }
}
public void close() throws JDBCException {
if (ps!=null) {
try {
log.debug("closing iterator");
- nextResult = null;
session.getBatcher().closeQueryStatement(ps, rs);
ps = null;
rs = null;
@@ -88,44 +91,42 @@
}
}
- private void postNext() throws HibernateException, SQLException {
- this.hasNext = rs.next();
+ private void postNext() throws SQLException {
+ this.hasNext = !rs.isLast();
if (!hasNext) {
log.debug("exhausted results");
close();
}
- else {
+ }
+
+ public boolean hasNext() {
+ return hasNext;
+ }
+
+ public Object next() throws HibernateException {
+ if ( !hasNext ) throw new NoSuchElementException("No more results");
+ try {
log.debug("retrieving next results");
+ rs.next();
boolean isHolder = holderInstantiator.isRequired();
if ( single && !isHolder ) {
- nextResult = types[0].nullSafeGet( rs, names[0], session, null );
+ currentResult = types[0].nullSafeGet( rs, names[0], session, null );
}
else {
- Object[] nextResults = new Object[types.length];
+ Object[] currentResults = new Object[types.length];
for (int i=0; i<types.length; i++) {
- nextResults[i] = types[i].nullSafeGet( rs, names[i], session, null );
+ currentResults[i] = types[i].nullSafeGet( rs, names[i], session, null );
}
if (isHolder) {
- nextResult = holderInstantiator.instantiate(nextResults);
+ currentResult = holderInstantiator.instantiate(currentResults);
}
else {
- nextResult = nextResults;
+ currentResult = currentResults;
}
}
- }
- }
-
- public boolean hasNext() {
- return hasNext;
- }
-
- public Object next() {
- if ( !hasNext ) throw new NoSuchElementException("No more results");
- try {
- currentResult = nextResult;
postNext();
log.debug("returning current results");
return currentResult;
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java 2007-08-29 00:47:06 UTC (rev 13956)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java 2007-08-29 00:50:12 UTC (rev 13957)
@@ -1,5 +1,9 @@
package org.hibernate.test.reattachment;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.HashSet;
+
import junit.framework.Test;
import org.hibernate.junit.functional.FunctionalTestCase;
@@ -73,4 +77,151 @@
s.getTransaction().commit();
s.close();
}
+
+ public void testIterateWithClearTopOfLoop() {
+ Session s = openSession();
+ s.beginTransaction();
+ Set parents = new HashSet();
+ for (int i=0; i<5; i++) {
+ Parent p = new Parent( String.valueOf( i ) );
+ Child child = new Child( "child" + i );
+ child.setParent( p );
+ p.getChildren().add( child );
+ s.save( p );
+ parents.add(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ int i = 0;
+ for ( Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
+ i++;
+ if (i % 2 == 0) {
+ s.flush();
+ s.clear();
+ }
+ Parent p = (Parent) it.next();
+ assertEquals( 1, p.getChildren().size() );
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it=parents.iterator(); it.hasNext(); ) {
+ s.delete(it.next());
+ }
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testIterateWithClearBottomOfLoop() {
+ Session s = openSession();
+ s.beginTransaction();
+ Set parents = new HashSet();
+ for (int i=0; i<5; i++) {
+ Parent p = new Parent( String.valueOf( i ) );
+ Child child = new Child( "child" + i );
+ child.setParent( p );
+ p.getChildren().add( child );
+ s.save( p );
+ parents.add(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ int i = 0;
+ for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
+ Parent p = (Parent) it.next();
+ assertEquals( 1, p.getChildren().size() );
+ i++;
+ if (i % 2 == 0) {
+ s.flush();
+ s.clear();
+ }
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it=parents.iterator(); it.hasNext(); ) {
+ s.delete(it.next());
+ }
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testIterateWithEvictTopOfLoop() {
+ Session s = openSession();
+ s.beginTransaction();
+ Set parents = new HashSet();
+ for (int i=0; i<5; i++) {
+ Parent p = new Parent( String.valueOf( i + 100 ) );
+ Child child = new Child( "child" + i );
+ child.setParent( p );
+ p.getChildren().add( child );
+ s.save( p );
+ parents.add(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ Parent p = null;
+ for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
+ if ( p != null) { s.evict(p); }
+ p = (Parent) it.next();
+ assertEquals( 1, p.getChildren().size() );
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it=parents.iterator(); it.hasNext(); ) {
+ s.delete(it.next());
+ }
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testIterateWithEvictBottomOfLoop() {
+ Session s = openSession();
+ s.beginTransaction();
+ Set parents = new HashSet();
+ for (int i=0; i<5; i++) {
+ Parent p = new Parent( String.valueOf( i + 100 ) );
+ Child child = new Child( "child" + i );
+ child.setParent( p );
+ p.getChildren().add( child );
+ s.save( p );
+ parents.add(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
+ Parent p = (Parent) it.next();
+ assertEquals( 1, p.getChildren().size() );
+ s.evict(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it=parents.iterator(); it.hasNext(); ) {
+ s.delete(it.next());
+ }
+ s.getTransaction().commit();
+ s.close();
+ }
}
16 years, 6 months
Hibernate SVN: r13956 - in core/branches/Branch_3_2: test/org/hibernate/test/reattachment and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2007-08-28 20:47:06 -0400 (Tue, 28 Aug 2007)
New Revision: 13956
Modified:
core/branches/Branch_3_2/src/org/hibernate/impl/IteratorImpl.java
core/branches/Branch_3_2/test/org/hibernate/test/reattachment/ProxyReattachmentTest.java
Log:
HHH-2728 : session.clear() while retrieving objects via an iterator
Modified: core/branches/Branch_3_2/src/org/hibernate/impl/IteratorImpl.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/impl/IteratorImpl.java 2007-08-28 19:35:50 UTC (rev 13955)
+++ core/branches/Branch_3_2/src/org/hibernate/impl/IteratorImpl.java 2007-08-29 00:47:06 UTC (rev 13956)
@@ -34,7 +34,6 @@
private boolean hasNext;
private final String[][] names;
private PreparedStatement ps;
- private Object nextResult;
private HolderInstantiator holderInstantiator;
public IteratorImpl(
@@ -55,14 +54,18 @@
single = types.length==1;
- postNext();
+ // rs.isBeforeFirst() will return false if rs contains no rows
+ hasNext = this.rs.isBeforeFirst();
+ if ( !hasNext ) {
+ log.debug("ResultSet contains no rows");
+ close();
+ }
}
public void close() throws JDBCException {
if (ps!=null) {
try {
log.debug("closing iterator");
- nextResult = null;
session.getBatcher().closeQueryStatement(ps, rs);
ps = null;
rs = null;
@@ -88,44 +91,42 @@
}
}
- private void postNext() throws HibernateException, SQLException {
- this.hasNext = rs.next();
+ private void postNext() throws SQLException {
+ this.hasNext = !rs.isLast();
if (!hasNext) {
log.debug("exhausted results");
close();
}
- else {
+ }
+
+ public boolean hasNext() {
+ return hasNext;
+ }
+
+ public Object next() throws HibernateException {
+ if ( !hasNext ) throw new NoSuchElementException("No more results");
+ try {
log.debug("retrieving next results");
+ rs.next();
boolean isHolder = holderInstantiator.isRequired();
if ( single && !isHolder ) {
- nextResult = types[0].nullSafeGet( rs, names[0], session, null );
+ currentResult = types[0].nullSafeGet( rs, names[0], session, null );
}
else {
- Object[] nextResults = new Object[types.length];
+ Object[] currentResults = new Object[types.length];
for (int i=0; i<types.length; i++) {
- nextResults[i] = types[i].nullSafeGet( rs, names[i], session, null );
+ currentResults[i] = types[i].nullSafeGet( rs, names[i], session, null );
}
if (isHolder) {
- nextResult = holderInstantiator.instantiate(nextResults);
+ currentResult = holderInstantiator.instantiate(currentResults);
}
else {
- nextResult = nextResults;
+ currentResult = currentResults;
}
}
- }
- }
-
- public boolean hasNext() {
- return hasNext;
- }
-
- public Object next() {
- if ( !hasNext ) throw new NoSuchElementException("No more results");
- try {
- currentResult = nextResult;
postNext();
log.debug("returning current results");
return currentResult;
Modified: core/branches/Branch_3_2/test/org/hibernate/test/reattachment/ProxyReattachmentTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/reattachment/ProxyReattachmentTest.java 2007-08-28 19:35:50 UTC (rev 13955)
+++ core/branches/Branch_3_2/test/org/hibernate/test/reattachment/ProxyReattachmentTest.java 2007-08-29 00:47:06 UTC (rev 13956)
@@ -1,5 +1,9 @@
package org.hibernate.test.reattachment;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.HashSet;
+
import junit.framework.Test;
import org.hibernate.junit.functional.FunctionalTestCase;
@@ -73,4 +77,151 @@
s.getTransaction().commit();
s.close();
}
+
+ public void testIterateWithClearTopOfLoop() {
+ Session s = openSession();
+ s.beginTransaction();
+ Set parents = new HashSet();
+ for (int i=0; i<5; i++) {
+ Parent p = new Parent( String.valueOf( i ) );
+ Child child = new Child( "child" + i );
+ child.setParent( p );
+ p.getChildren().add( child );
+ s.save( p );
+ parents.add(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ int i = 0;
+ for ( Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
+ i++;
+ if (i % 2 == 0) {
+ s.flush();
+ s.clear();
+ }
+ Parent p = (Parent) it.next();
+ assertEquals( 1, p.getChildren().size() );
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it=parents.iterator(); it.hasNext(); ) {
+ s.delete(it.next());
+ }
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testIterateWithClearBottomOfLoop() {
+ Session s = openSession();
+ s.beginTransaction();
+ Set parents = new HashSet();
+ for (int i=0; i<5; i++) {
+ Parent p = new Parent( String.valueOf( i ) );
+ Child child = new Child( "child" + i );
+ child.setParent( p );
+ p.getChildren().add( child );
+ s.save( p );
+ parents.add(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ int i = 0;
+ for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
+ Parent p = (Parent) it.next();
+ assertEquals( 1, p.getChildren().size() );
+ i++;
+ if (i % 2 == 0) {
+ s.flush();
+ s.clear();
+ }
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it=parents.iterator(); it.hasNext(); ) {
+ s.delete(it.next());
+ }
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testIterateWithEvictTopOfLoop() {
+ Session s = openSession();
+ s.beginTransaction();
+ Set parents = new HashSet();
+ for (int i=0; i<5; i++) {
+ Parent p = new Parent( String.valueOf( i + 100 ) );
+ Child child = new Child( "child" + i );
+ child.setParent( p );
+ p.getChildren().add( child );
+ s.save( p );
+ parents.add(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ Parent p = null;
+ for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
+ if ( p != null) { s.evict(p); }
+ p = (Parent) it.next();
+ assertEquals( 1, p.getChildren().size() );
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it=parents.iterator(); it.hasNext(); ) {
+ s.delete(it.next());
+ }
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testIterateWithEvictBottomOfLoop() {
+ Session s = openSession();
+ s.beginTransaction();
+ Set parents = new HashSet();
+ for (int i=0; i<5; i++) {
+ Parent p = new Parent( String.valueOf( i + 100 ) );
+ Child child = new Child( "child" + i );
+ child.setParent( p );
+ p.getChildren().add( child );
+ s.save( p );
+ parents.add(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
+ Parent p = (Parent) it.next();
+ assertEquals( 1, p.getChildren().size() );
+ s.evict(p);
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ for (Iterator it=parents.iterator(); it.hasNext(); ) {
+ s.delete(it.next());
+ }
+ s.getTransaction().commit();
+ s.close();
+ }
}
16 years, 6 months
Hibernate SVN: r13955 - in search/trunk/doc/reference/en: modules and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2007-08-28 15:35:50 -0400 (Tue, 28 Aug 2007)
New Revision: 13955
Modified:
search/trunk/doc/reference/en/master.xml
search/trunk/doc/reference/en/modules/getting-started.xml
Log:
HSEARCH-98 Minor changes and more explicit code examples.
Modified: search/trunk/doc/reference/en/master.xml
===================================================================
--- search/trunk/doc/reference/en/master.xml 2007-08-28 15:39:14 UTC (rev 13954)
+++ search/trunk/doc/reference/en/master.xml 2007-08-28 19:35:50 UTC (rev 13955)
@@ -39,8 +39,8 @@
dealing with object domain models. Amongst other things indexes have to be kept up to date and
mismatches between index structure and domain model as well as query mismatches
have to be avoided. <sbr/>
- Hibernate Search indexes your domain model thanks to a few annotations,
- takes care of database/index synchronization and brings you back
+ Hibernate Search indexes your domain model with the help of a few annotations,
+ takes care of database/index synchronization and brings back
regular managed objects from free text queries. To achieve this Hibernate Search
is combining the power of <ulink url="http://www.hibernate.org">Hibernate</ulink> and
<ulink url="http://lucene.apache.org">Apache Lucene</ulink>.
Modified: search/trunk/doc/reference/en/modules/getting-started.xml
===================================================================
--- search/trunk/doc/reference/en/modules/getting-started.xml 2007-08-28 15:39:14 UTC (rev 13954)
+++ search/trunk/doc/reference/en/modules/getting-started.xml 2007-08-28 19:35:50 UTC (rev 13955)
@@ -69,17 +69,18 @@
If you are using Hibernate via JPA you can also add the properties to <literal>persistence.xml</literal>.
The good news is that for standard use most properties offer a sensible default.
</para>
- <para>
- In this tutorial we will start off <classname>FSDirectoryProvider</classname> which will give us
- the ability to physically inspect the Lucene indexes (eg via
- <ulink url="http://www.getopt.org/luke/">Luke</ulink>) created by
- Hibernate Search. Once you have a working configuration you can start experimenting with
- other directory providers (see <xref linkend="search-configuration-directory"/>).
+ <para>
+ Apache Lucene has a notion of <literal>Directory</literal> to store the index files. Hibernate Search handles
+ the initialization and configuration of a Lucene <literal>Directory</literal> instance via a <literal>DirectoryProvider</literal>.
+ In this tutorial we will use a subclass of <literal>DirectoryProvider</literal> called
+ <classname>FSDirectoryProvider</classname>. This will give us the ability to physically inspect the Lucene
+ indexes created by Hibernate Search (eg via <ulink url="http://www.getopt.org/luke/">Luke</ulink>).
+ Once you have a working configuration you can start experimenting with other directory providers (see <xref linkend="search-configuration-directory"/>).
</para>
<para>
- Lets assume that your application contains the Hibernate managed class <classname>example.Book</classname>.
- You now want to add free text search capabilities to your application
- in order to search the bodies and summaries of the books contained in your database.
+ Lets assume that your application contains the Hibernate managed class <classname>example.Book</classname> and
+ you now want to add free text search capabilities to your application
+ in order to search body and summary of the books contained in your database.
</para>
<programlisting>
package exmaple.Book
@@ -105,7 +106,7 @@
<para>
First you have to tell Hibernate Search which <classname>DirectoryProvider</classname> to use.
This can be achieved by setting the <literal>hibernate.search.default.directory_provider</literal> property.
- You also want to specify the default root directory for all indexes via <literal>hibernate.search.default.indexBase</literal>.
+ You also have to specify the default root directory for all indexes via <literal>hibernate.search.default.indexBase</literal>.
</para>
<programlisting>
@@ -122,7 +123,7 @@
Next you have to add three annotations to the <classname>Book</classname> class. The
first annotation <literal>@Indexed</literal> marks <classname>Book</classname>
as indexable. By design Hibernate Search needs to store an untokenized id in the index to ensure
- index unicity for a given entity. <literal>@DocumentId</literal> marks the property to use.
+ index unicity for a given entity. <literal>@DocumentId</literal> marks the property to use for this purpose.
Last but not least you have to index the fields you want to make searchable. In our example
these fields are <literal>body</literal> and <literal>summary</literal>. Both properties get
annotated with <literal>@Field</literal>. The property <literal>index=Index.TOKENIZED</literal> will
@@ -132,7 +133,7 @@
<para>
These settings are sufficient for an initial test. For more details on entity mapping refer
to <xref linkend="search-mapping-entity"/>. In case you want to store and retrieve
- the indexed data refer to projections in <xref linkend="projections" />
+ the indexed data in order to avoid database roundtrips refer to projections in <xref linkend="projections" />
</para>
<programlisting>
@@ -177,7 +178,7 @@
<programlisting>
FullTextSession fullTextSession = Search.createFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
-... // retrieving the all books from the database using HQL
+List books = session.createQuery("from Book as book").list();
for (Book book : books) {
fullTextSession.index(book);
}
@@ -189,7 +190,7 @@
<programlisting>
EntityManager em = entityManagerFactory.createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.createFullTextEntityManager(em);
-... // retrieving the all books from the database using JPA-QL
+List books = em.createQuery("select book from Book as book").getResultList();
for (Book book : books) {
fullTextEntityManager.index(book);
}
@@ -204,16 +205,14 @@
<title>Searching</title>
<para>
Now it is time to execute a first search. The following code will prepare a query against
- the fields <literal>summary</literal> and <literal>body</literal> , execute it and return
+ the fields <literal>summary</literal> and <literal>body</literal>, execute it and return
a list of <classname>Book</classname>s:
</para>
<para>
Example using Hibernate Session:
</para>
<programlisting>
-// the use of HibernateUtil is only an example of how to get hold of the current session!
-Session session = HibernateUtil.getCurrentSession();
-FullTextSession fullTextSession = Search.createFullTextSession();
+FullTextSession fullTextSession = Search.createFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
@@ -247,12 +246,22 @@
Assume that one of your indexed book entities contains the text "Java rocks" and you want to get
hits for all of the following queries: "rock", "rocks", "rocked" and "rocking". In Lucene this
can be achieved by choosing an analyzer class which applies word stemming during the indexing process.
- Hibernate Search exposes this Lucene functionality and allows to specify the analyzer class via the
- property <literal>hibernate.search.analyzer</literal> in the configuration file or via an annotation
- on entity or field level (see <xref linkend="analyzer"/>).
+ Hibernate Search offers several ways to configure the analyzer to use (see <xref linkend="analyzer"/>):
- The following example uses an annotation on the entity level to apply a English language analyzer
- which would help you to achieve your goal:
+ <itemizedlist>
+ <listitem>Setting the <literal>hibernate.search.analyzer</literal> property in the configuration file.
+ The specified class will then be the default analyzer.
+ </listitem>
+ <listitem>Setting the <literal>Analyzer</literal> annotation on entity level.
+ </listitem>
+ <listitem>Setting the <literal>Analyzer</literal> annotation on field level.
+ </listitem>
+ </itemizedlist>
+
+ The following example uses the entity level annotation to apply a English language analyzer
+ which would help you to achieve your goal. The class <classname>EnglishAnalyzer</classname>
+ is a custom class using the Snowball English Stemmer from the
+ <ulink url="http://lucene.apache.org/java/docs/lucene-sandbox/">Lucene Sandbox</ulink>.
<programlisting>
package example.Book
...
@@ -303,7 +312,7 @@
The above paragraphs hopefully helped you getting started with Hibernate Search. You
should by now have a simple file system based index and be able to search and retrieve a list of
managed objects via Hibernate Search. The next step is to get more familiar with the
- overall architecture and explore the basic features in more detail.
+ overall architecture ((<xref linkend="search-architecture"/>)) and explore the basic features in more detail.
</para>
<para>
Two topics which where only briefly touched in this tutorial were analyzer configuration
@@ -311,7 +320,7 @@
features required for more fain grained indexing.
</para>
<para>
- More advanced topics cover topics like clustering (<xref linkend="jms-backend"/>) and large indexes
+ More advanced topics cover clustering (<xref linkend="jms-backend"/>) and large indexes
handling (<xref linkend="search-configuration-directory-sharding"/>).
</para>
</section>
16 years, 6 months
Hibernate SVN: r13954 - in search/trunk/src: test/org/hibernate/search/test and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-08-28 11:39:14 -0400 (Tue, 28 Aug 2007)
New Revision: 13954
Added:
search/trunk/src/java/org/hibernate/search/backend/PurgeAllLuceneWork.java
search/trunk/src/test/org/hibernate/search/test/PurgeTest.java
Log:
HSEARCH-69 purge and purge all
Added: search/trunk/src/java/org/hibernate/search/backend/PurgeAllLuceneWork.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/PurgeAllLuceneWork.java (rev 0)
+++ search/trunk/src/java/org/hibernate/search/backend/PurgeAllLuceneWork.java 2007-08-28 15:39:14 UTC (rev 13954)
@@ -0,0 +1,14 @@
+package org.hibernate.search.backend;
+
+import java.io.Serializable;
+
+/**
+ * A unit of work used to purge an entire index.
+ *
+ * @author John Griffin
+ */
+public class PurgeAllLuceneWork extends LuceneWork {
+ public PurgeAllLuceneWork(Class entity) {
+ super( null, null, entity, null );
+ }
+}
Added: search/trunk/src/test/org/hibernate/search/test/PurgeTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/PurgeTest.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/PurgeTest.java 2007-08-28 15:39:14 UTC (rev 13954)
@@ -0,0 +1,110 @@
+package org.hibernate.search.test;
+
+import java.util.List;
+
+import org.apache.lucene.analysis.StopAnalyzer;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.hibernate.Transaction;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.test.query.AlternateBook;
+import org.hibernate.search.test.query.Author;
+import org.hibernate.search.test.query.Book;
+import org.hibernate.search.test.query.Clock;
+import org.hibernate.search.test.query.Employee;
+
+/**
+ * Test the PURGE and PURGE_ALL functionality.
+ *
+ * @author John Griffin
+ */
+public class PurgeTest extends SearchTestCase {
+
+ public void testPurge() throws Exception {
+ FullTextSession s = Search.createFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ org.hibernate.search.test.query.Clock clock = new Clock( 1, "Seiko" );
+ s.save( clock );
+ clock = new Clock( 2, "Festina" );
+ s.save( clock );
+ Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
+ s.save( book );
+ book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
+ s.save( book );
+ tx.commit();
+ s.clear();
+
+ tx = s.beginTransaction();
+ QueryParser parser = new QueryParser( "brand", new StopAnalyzer() );
+
+ Query query = parser.parse( "brand:Seiko" );
+ org.hibernate.Query hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
+ List results = hibQuery.list();
+ assertEquals("incorrect test record", 1, results.size());
+ assertEquals("incorrect test record", 1, ((Clock)results.get( 0 )).getId().intValue());
+
+ s.purge( Clock.class, ((Clock)results.get( 0 )).getId());
+
+ tx.commit();
+
+ tx = s.beginTransaction();
+
+ query = parser.parse( "brand:Festina or brand:Seiko" );
+ hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
+ results = hibQuery.list();
+ assertEquals("incorrect test record count", 1, results.size());
+ assertEquals("incorrect test record", 2, ((Clock)results.get( 0 )).getId().intValue());
+
+ for (Object element : s.createQuery( "from java.lang.Object" ).list()) s.delete( element );
+ tx.commit();
+ s.close();
+ }
+
+ public void testPurgeAll() throws Exception {
+ FullTextSession s = Search.createFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ org.hibernate.search.test.query.Clock clock = new Clock( 1, "Seiko" );
+ s.save( clock );
+ clock = new Clock( 2, "Festina" );
+ s.save( clock );
+ clock = new Clock( 3, "Longine" );
+ s.save( clock );
+ clock = new Clock( 4, "Rolex" );
+ s.save( clock );
+ Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
+ s.save( book );
+ book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
+ s.save( book );
+ tx.commit();
+ s.clear();
+
+ tx = s.beginTransaction();
+ QueryParser parser = new QueryParser( "brand", new StopAnalyzer() );
+ tx = s.beginTransaction();
+ s.purge( Clock.class);
+
+ tx.commit();
+
+ tx = s.beginTransaction();
+
+ Query query = parser.parse( "brand:Festina or brand:Seiko" );
+ org.hibernate.Query hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
+ List results = hibQuery.list();
+ assertEquals("incorrect test record count", 0, results.size());
+
+ for (Object element : s.createQuery( "from java.lang.Object" ).list()) s.delete( element );
+ tx.commit();
+ s.close();
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ Book.class,
+ AlternateBook.class,
+ Clock.class,
+ Author.class,
+ Employee.class
+ };
+ }
+}
16 years, 6 months
Hibernate SVN: r13953 - in search/trunk/src/java/org/hibernate/search: backend and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-08-28 11:38:29 -0400 (Tue, 28 Aug 2007)
New Revision: 13953
Modified:
search/trunk/src/java/org/hibernate/search/FullTextSession.java
search/trunk/src/java/org/hibernate/search/backend/QueueingProcessor.java
search/trunk/src/java/org/hibernate/search/backend/Work.java
search/trunk/src/java/org/hibernate/search/backend/WorkType.java
search/trunk/src/java/org/hibernate/search/backend/Worker.java
search/trunk/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
search/trunk/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
search/trunk/src/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessor.java
search/trunk/src/java/org/hibernate/search/backend/impl/lucene/LuceneWorker.java
search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
search/trunk/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
search/trunk/src/java/org/hibernate/search/store/IdHashShardingStrategy.java
search/trunk/src/java/org/hibernate/search/store/IndexShardingStrategy.java
Log:
HSEARCH-69 purge and purge all
Modified: search/trunk/src/java/org/hibernate/search/FullTextSession.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/FullTextSession.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/FullTextSession.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -1,6 +1,8 @@
//$Id$
package org.hibernate.search;
+import java.io.Serializable;
+
import org.hibernate.classic.Session;
/**
@@ -26,4 +28,19 @@
* return the SearchFactory
*/
SearchFactory getSearchFactory();
+
+ /**
+ * Remove a particular entity from a particular class of an index.
+ *
+ * @param entityType
+ * @param id
+ */
+ public void purge(Class entityType, Serializable id);
+
+ /**
+ * Remove all entities from a particular class of an index.
+ *
+ * @param entityType
+ */
+ public void purge(Class entityType);
}
Modified: search/trunk/src/java/org/hibernate/search/backend/QueueingProcessor.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/QueueingProcessor.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/backend/QueueingProcessor.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -20,7 +20,7 @@
* Add a work
* TODO move that womewhere else, it does not really fit here
*/
- void add(Object entity, Serializable id, WorkType workType, WorkQueue workQueue);
+ void add(Work work, WorkQueue workQueue);
/**
* prepare resources for a later performWorks call
Modified: search/trunk/src/java/org/hibernate/search/backend/Work.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/Work.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/backend/Work.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -12,6 +12,7 @@
*/
public class Work {
private Object entity;
+ private Class entityClass;
private Serializable id;
private XMember idGetter;
private WorkType type;
@@ -23,12 +24,21 @@
this.type = type;
}
+ public Work(Class entityType, Serializable id, WorkType type) {
+ this.entityClass = entityType;
+ this.id = id;
+ this.type = type;
+ }
public Work(Object entity, XMember idGetter, WorkType type) {
this.entity = entity;
this.idGetter = idGetter;
this.type = type;
}
+
+ public Class getEntityClass() {
+ return entityClass;
+ }
public Object getEntity() {
return entity;
Modified: search/trunk/src/java/org/hibernate/search/backend/WorkType.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/WorkType.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/backend/WorkType.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -7,11 +7,22 @@
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
+ * @author John Griffin
*/
public enum WorkType {
ADD,
UPDATE,
DELETE,
+ /**
+ * Used to remove a specific instance
+ * of a class from an index.
+ */
+ PURGE,
+ /**
+ * Used to remove all instances of a
+ * class from an index.
+ */
+ PURGE_ALL,
/**
* This type is used for batch indexing.
Modified: search/trunk/src/java/org/hibernate/search/backend/Worker.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/Worker.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/backend/Worker.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -12,7 +12,7 @@
* @author Emmanuel Bernard
*/
public interface Worker {
- void performWork(Object entity, Serializable id, WorkType workType, EventSource session);
+ void performWork(Work work, EventSource session);
void initialize(Properties props, SearchFactoryImplementor searchFactoryImplementor);
}
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -96,9 +96,8 @@
searchFactoryImplementor.setBackendQueueProcessorFactory( backendQueueProcessorFactory );
}
- public void add(Object entity, Serializable id, WorkType workType, WorkQueue workQueue) {
+ public void add(Work work, WorkQueue workQueue) {
//don't check for builder it's done in prepareWork
- Work work = new Work(entity, id, workType);
workQueue.add( work );
if ( batchSize > 0 && workQueue.size() >= batchSize ) {
WorkQueue subQueue = workQueue.splitQueue();
@@ -115,10 +114,12 @@
for ( int i = 0 ; i < initialSize ; i++ ) {
Work work = queue.get( i );
queue.set( i, null ); // help GC and avoid 2 loaded queues in memory
- Class entityClass = Hibernate.getClass( work.getEntity() );
+ Class entityClass = work.getEntityClass() != null ?
+ work.getEntityClass() :
+ Hibernate.getClass( work.getEntity() );
DocumentBuilder<Object> builder = searchFactoryImplementor.getDocumentBuilders().get( entityClass );
if ( builder == null ) return; //or exception?
- builder.addWorkToQueue(work.getEntity(), work.getId(), work.getType(), luceneQueue, searchFactoryImplementor );
+ builder.addWorkToQueue(entityClass, work.getEntity(), work.getId(), work.getType(), luceneQueue, searchFactoryImplementor );
}
workQueue.setSealedQueue( luceneQueue );
}
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/PostTransactionWorkQueueSynchronization.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -32,8 +32,8 @@
this.queuePerTransaction = queuePerTransaction;
}
- public void add(Object entity, Serializable id, WorkType workType) {
- queueingProcessor.add( entity, id, workType, queue );
+ public void add(Work work) {
+ queueingProcessor.add( work, queue );
}
public boolean isConsumed() {
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/TransactionalWorker.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -8,6 +8,7 @@
import org.hibernate.search.backend.QueueingProcessor;
import org.hibernate.search.backend.WorkType;
import org.hibernate.search.backend.WorkQueue;
+import org.hibernate.search.backend.Work;
import org.hibernate.search.backend.impl.BatchedQueueingProcessor;
import org.hibernate.search.util.WeakIdentityHashMap;
import org.hibernate.search.engine.SearchFactoryImplementor;
@@ -28,7 +29,7 @@
protected WeakIdentityHashMap synchronizationPerTransaction = new WeakIdentityHashMap();
private QueueingProcessor queueingProcessor;
- public void performWork(Object entity, Serializable id, WorkType workType, EventSource session) {
+ public void performWork(Work work, EventSource session) {
if ( session.isTransactionInProgress() ) {
Transaction transaction = session.getTransaction();
PostTransactionWorkQueueSynchronization txSync = (PostTransactionWorkQueueSynchronization)
@@ -38,11 +39,11 @@
transaction.registerSynchronization( txSync );
synchronizationPerTransaction.put(transaction, txSync);
}
- txSync.add( entity, id, workType );
+ txSync.add( work );
}
else {
WorkQueue queue = new WorkQueue(2); //one work can be split
- queueingProcessor.add( entity, id, workType, queue );
+ queueingProcessor.add( work, queue );
queueingProcessor.prepareWorks( queue );
queueingProcessor.performWorks( queue );
}
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessor.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessor.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/lucene/LuceneBackendQueueProcessor.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -13,6 +13,7 @@
import org.hibernate.search.backend.Workspace;
import org.hibernate.search.backend.OptimizeLuceneWork;
import org.hibernate.search.backend.DeleteLuceneWork;
+import org.hibernate.search.backend.PurgeAllLuceneWork;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.store.DirectoryProvider;
@@ -24,6 +25,7 @@
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
+ * @author John Griffin
*/
public class LuceneBackendQueueProcessor implements Runnable {
@@ -51,7 +53,17 @@
DocumentBuilder documentBuilder = searchFactoryImplementor.getDocumentBuilders().get( work.getEntityClass() );
IndexShardingStrategy shardingStrategy = documentBuilder.getDirectoryProviderSelectionStrategy();
- if ( AddLuceneWork.class.isAssignableFrom( work.getClass() ) ) {
+ if ( PurgeAllLuceneWork.class.isAssignableFrom( work.getClass() ) ) {
+ DirectoryProvider[] providers = shardingStrategy.getDirectoryProvidersForDeletion(
+ work.getEntityClass(),
+ work.getId(),
+ work.getIdInString()
+ );
+ for (DirectoryProvider provider : providers) {
+ queueWithFlatDPs.add( new LuceneWorker.WorkWithPayload( work, provider ) );
+ }
+ }
+ else if ( AddLuceneWork.class.isAssignableFrom( work.getClass() ) ) {
DirectoryProvider provider = shardingStrategy.getDirectoryProviderForAddition(
work.getEntityClass(),
work.getId(),
Modified: search/trunk/src/java/org/hibernate/search/backend/impl/lucene/LuceneWorker.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/backend/impl/lucene/LuceneWorker.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/backend/impl/lucene/LuceneWorker.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -18,6 +18,7 @@
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.OptimizeLuceneWork;
import org.hibernate.search.backend.Workspace;
+import org.hibernate.search.backend.PurgeAllLuceneWork;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.store.DirectoryProvider;
@@ -26,6 +27,7 @@
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
+ * @author John Griffin
*/
public class LuceneWorker {
private Workspace workspace;
@@ -45,6 +47,8 @@
}
else if ( OptimizeLuceneWork.class.isAssignableFrom( workClass ) ) {
performWork( (OptimizeLuceneWork) luceneWork.getWork(), luceneWork.getProvider() );
+ }else if ( PurgeAllLuceneWork.class.isAssignableFrom( workClass ) ) {
+ performWork( (PurgeAllLuceneWork) luceneWork.getWork(), luceneWork.getProvider() );
}
else {
throw new AssertionFailure( "Unknown work type: " + workClass );
@@ -129,6 +133,20 @@
}
}
+ public void performWork(PurgeAllLuceneWork work, DirectoryProvider provider) {
+ Class entity = work.getEntityClass();
+ if ( log.isTraceEnabled() )
+ log.trace( "purgeAll Lucene index: " + entity );
+ IndexReader reader = workspace.getIndexReader( provider, entity );
+ try {
+ Term term = new Term( DocumentBuilder.CLASS_FIELDNAME, entity.getName() );
+ reader.deleteDocuments( term );
+ }
+ catch (Exception e) {
+ throw new SearchException( "Unable to purge all from Lucene index: " + entity, e );
+ }
+ }
+
public static class WorkWithPayload {
private LuceneWork work;
private DirectoryProvider provider;
Modified: search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -40,6 +40,7 @@
import org.hibernate.search.backend.DeleteLuceneWork;
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.WorkType;
+import org.hibernate.search.backend.PurgeAllLuceneWork;
import org.hibernate.search.bridge.BridgeFactory;
import org.hibernate.search.bridge.FieldBridge;
import org.hibernate.search.bridge.TwoWayFieldBridge;
@@ -396,14 +397,18 @@
return value;
}
- public void addWorkToQueue(T entity, Serializable id, WorkType workType, List<LuceneWork> queue, SearchFactoryImplementor searchFactoryImplementor) {
- Class entityClass = Hibernate.getClass( entity );
+ //TODO could we use T instead of EntityClass?
+ public void addWorkToQueue(Class entityClass, T entity, Serializable id, WorkType workType, List<LuceneWork> queue, SearchFactoryImplementor searchFactoryImplementor) {
//TODO with the caller loop we are in a n^2: optimize it using a HashMap for work recognition
for (LuceneWork luceneWork : queue) {
- //whatever the actual work, we should ignore
+ //any work on the same entity should be ignored
if ( luceneWork.getEntityClass() == entityClass
- && luceneWork.getId().equals( id ) ) {//find a way to use Type.equals(x,y)
- return;
+ ) {
+ Serializable currentId = luceneWork.getId();
+ if ( currentId != null && currentId.equals( id ) ) { //find a way to use Type.equals(x,y)
+ return;
+ }
+ //TODO do something to avoid multiple PURGE ALL and OPTIMIZE
}
}
@@ -414,9 +419,12 @@
queue.add( new AddLuceneWork( id, idInString, entityClass, doc ) );
searchForContainers = true;
}
- else if ( workType == WorkType.DELETE ) {
+ else if ( workType == WorkType.DELETE || workType == WorkType.PURGE ) {
queue.add( new DeleteLuceneWork( id, idInString, entityClass ) );
}
+ else if ( workType == WorkType.PURGE_ALL ) {
+ queue.add( new PurgeAllLuceneWork( entityClass ) );
+ }
else if ( workType == WorkType.UPDATE ) {
Document doc = getDocument( entity, id );
/**
@@ -499,7 +507,7 @@
private void processContainedInValue(Object value, List<LuceneWork> queue, Class valueClass,
DocumentBuilder builder, SearchFactoryImplementor searchFactoryImplementor) {
Serializable id = (Serializable) builder.getMemberValue( value, builder.idGetter );
- builder.addWorkToQueue( value, id, WorkType.UPDATE, queue, searchFactoryImplementor );
+ builder.addWorkToQueue( valueClass, value, id, WorkType.UPDATE, queue, searchFactoryImplementor );
}
public Document getDocument(T instance, Serializable id) {
Modified: search/trunk/src/java/org/hibernate/search/event/FullTextIndexEventListener.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/event/FullTextIndexEventListener.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -15,6 +15,7 @@
import org.hibernate.event.PostUpdateEvent;
import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.search.backend.WorkType;
+import org.hibernate.search.backend.Work;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.impl.SearchFactoryImpl;
@@ -77,6 +78,7 @@
}
private void processWork(Object entity, Serializable id, WorkType workType, AbstractEvent event) {
- searchFactoryImplementor.getWorker().performWork( entity, id, workType, event.getSession() );
+ Work work = new Work(entity, id, workType);
+ searchFactoryImplementor.getWorker().performWork( work, event.getSession() );
}
}
Modified: search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -44,6 +44,7 @@
import org.hibernate.search.FullTextQuery;
import org.hibernate.search.SearchFactory;
import org.hibernate.search.backend.WorkType;
+import org.hibernate.search.backend.Work;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.query.FullTextQueryImpl;
@@ -55,6 +56,7 @@
* Lucene full text search aware session.
*
* @author Emmanuel Bernard
+ * @author John Griffin
*/
public class FullTextSessionImpl implements FullTextSession, SessionImplementor {
private final Session session;
@@ -70,8 +72,8 @@
/**
* Execute a Lucene query and retrieve managed objects of type entities (or their indexed subclasses)
- * If entities is empty, include all indexed entities
- *
+ * If entities is empty, include all indexed entities
+ *
* @param entities must be immutable for the lifetime of the query object
*/
public FullTextQuery createFullTextQuery(org.apache.lucene.search.Query luceneQuery, Class... entities) {
@@ -79,6 +81,45 @@
}
/**
+ * Remove all entities from a particular class of an index.
+ *
+ * @param entityType
+ */
+ public void purge(Class entityType) {
+ purge( entityType, null );
+ }
+
+ /**
+ * Remove a particular entity from a particular class of an index.
+ *
+ * @param entityType
+ * @param id
+ */
+ public void purge(Class entityType, Serializable id) {
+ if ( entityType == null ) return;
+ SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
+ // not strictly necessary but a small optimization plus let's make sure the
+ // client didn't mess something up.
+ Map<Class, DocumentBuilder<Object>> builders = searchFactoryImplementor.getDocumentBuilders();
+ DocumentBuilder<Object> builder = builders.get( entityType );
+
+ if ( builder == null ) {
+ throw new IllegalArgumentException( entityType.getName() + " is not a mapped entity (don't forget to add @Indexed)" );
+ }
+ else {
+ WorkType type;
+ if ( id == null ) {
+ type = WorkType.PURGE_ALL;
+ }
+ else {
+ type = WorkType.PURGE;
+ }
+ Work work = new Work(entityType, id, type);
+ searchFactoryImplementor.getWorker().performWork( work, eventSource );
+ }
+ }
+
+ /**
* (re)index an entity.
* Non indexable entities are ignored
* The entity must be associated with the session
@@ -94,7 +135,8 @@
DocumentBuilder<Object> builder = searchFactoryImplementor.getDocumentBuilders().get( clazz );
if ( builder != null ) {
Serializable id = session.getIdentifier( entity );
- searchFactoryImplementor.getWorker().performWork( entity, id, WorkType.INDEX, eventSource );
+ Work work = new Work(entity, id, WorkType.INDEX);
+ searchFactoryImplementor.getWorker().performWork( work, eventSource );
}
//TODO
//need to add elements in a queue kept at the Session level
Modified: search/trunk/src/java/org/hibernate/search/store/IdHashShardingStrategy.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/store/IdHashShardingStrategy.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/store/IdHashShardingStrategy.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -26,6 +26,7 @@
}
public DirectoryProvider[] getDirectoryProvidersForDeletion(Class entity, Serializable id, String idInString) {
+ if ( idInString == null ) return providers;
return new DirectoryProvider[] { providers[ hashKey(idInString) ] };
}
Modified: search/trunk/src/java/org/hibernate/search/store/IndexShardingStrategy.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/store/IndexShardingStrategy.java 2007-08-27 21:48:51 UTC (rev 13952)
+++ search/trunk/src/java/org/hibernate/search/store/IndexShardingStrategy.java 2007-08-28 15:38:29 UTC (rev 13953)
@@ -29,6 +29,7 @@
DirectoryProvider getDirectoryProviderForAddition(Class entity, Serializable id, String idInString, Document document);
/**
* return the DirectoryProvider(s) where the given entity is stored and where the deletion operation needs to be applied
+ * id and idInString can be null. If null, all the directory providers containing entity types should be returned
*/
DirectoryProvider[] getDirectoryProvidersForDeletion(Class entity, Serializable id, String idInString);
}
16 years, 6 months
Hibernate SVN: r13952 - core/trunk/core/src/main/java/org/hibernate/engine/loading.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2007-08-27 17:48:51 -0400 (Mon, 27 Aug 2007)
New Revision: 13952
Modified:
core/trunk/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java
Log:
HHH-2563 : Reversed log messages in LoadContexts.locateLoadingCollectionEntry(CollectionKey key)
Modified: core/trunk/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java 2007-08-27 21:47:57 UTC (rev 13951)
+++ core/trunk/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java 2007-08-27 21:48:51 UTC (rev 13952)
@@ -268,10 +268,10 @@
LoadingCollectionEntry rtn = ( LoadingCollectionEntry ) xrefLoadingCollectionEntries.get( key );
if ( log.isTraceEnabled() ) {
if ( rtn == null ) {
- log.trace( "collection [" + key + "] located in load context" );
+ log.trace( "collection [" + key + "] not located in load context" );
}
else {
- log.trace( "collection [" + key + "] not located in load context" );
+ log.trace( "collection [" + key + "] located in load context" );
}
}
return rtn;
16 years, 6 months
Hibernate SVN: r13951 - core/branches/Branch_3_2/src/org/hibernate/engine/loading.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2007-08-27 17:47:57 -0400 (Mon, 27 Aug 2007)
New Revision: 13951
Modified:
core/branches/Branch_3_2/src/org/hibernate/engine/loading/LoadContexts.java
Log:
HHH-2563 : Reversed log messages in LoadContexts.locateLoadingCollectionEntry(CollectionKey key)
Modified: core/branches/Branch_3_2/src/org/hibernate/engine/loading/LoadContexts.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/engine/loading/LoadContexts.java 2007-08-27 21:09:58 UTC (rev 13950)
+++ core/branches/Branch_3_2/src/org/hibernate/engine/loading/LoadContexts.java 2007-08-27 21:47:57 UTC (rev 13951)
@@ -271,10 +271,10 @@
LoadingCollectionEntry rtn = ( LoadingCollectionEntry ) xrefLoadingCollectionEntries.get( key );
if ( log.isTraceEnabled() ) {
if ( rtn == null ) {
- log.trace( "collection [" + key + "] located in load context" );
+ log.trace( "collection [" + key + "] not located in load context" );
}
else {
- log.trace( "collection [" + key + "] not located in load context" );
+ log.trace( "collection [" + key + "] located in load context" );
}
}
return rtn;
16 years, 6 months
Hibernate SVN: r13950 - search/trunk/doc/reference/en/modules.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2007-08-27 17:09:58 -0400 (Mon, 27 Aug 2007)
New Revision: 13950
Modified:
search/trunk/doc/reference/en/modules/architecture.xml
search/trunk/doc/reference/en/modules/getting-started.xml
search/trunk/doc/reference/en/modules/mapping.xml
Log:
HSEARCH-98 More getting started and some other minor typo fixes.
Modified: search/trunk/doc/reference/en/modules/architecture.xml
===================================================================
--- search/trunk/doc/reference/en/modules/architecture.xml 2007-08-24 13:24:03 UTC (rev 13949)
+++ search/trunk/doc/reference/en/modules/architecture.xml 2007-08-27 21:09:58 UTC (rev 13950)
@@ -21,7 +21,7 @@
configure directory providers to adjust the directory target
(see <xref linkend="search-configuration-directory"/>).</para>
- <para>Hibernate Search can also use a Lucene index to search an entity and
+ <para>Next to the index updates Hibernate Search can also use the Lucene index to search an entity and
return a list of managed entities saving you the tedious object to
Lucene document mapping. The same persistence
context is shared between Hibernate and Hibernate Search; as a matter of
@@ -36,12 +36,12 @@
<para>Outside an transaction, the index update operation is executed
right after the actual database operation. This scope is really a no
- scoping, and no batching is performed.</para>
+ scoping setup and no batching is performed.</para>
<para>It is however recommended, for both your database and Hibernate
Search, to execute your operation in a transaction be it JDBC or
JTA. When in a transaction, the index update operation is scheduled for
- the transaction commit (and discarded in case of transaction rollback).
+ the transaction commit and discarded in case of transaction rollback.
The batching scope is the transaction. There are two immediate
benefits:</para>
@@ -162,8 +162,8 @@
<para>This is the safe mode where the back end work is executed in
concert with the transaction commit. Under highly concurrent
- environment, this can lead to throughput limitation (due to the Apache
- Lucene lock mechanism). It can increase the system response time too if
+ environment, this can lead to throughput limitations (due to the Apache
+ Lucene lock mechanism) and it can increase the system response time if
the backend is significantly slower than the transactional process and
if a lot of IO operations are involved.</para>
</section>
@@ -178,7 +178,7 @@
small overhead is introduced to deal with thread management.</para>
<para>It is recommended to use synchronous execution first and evaluate
- asynchronous if performance problems occur and after having set up a
+ asynchronous execution if performance problems occur and after having set up a
proper benchmark (ie not a lonely cowboy hitting the system in a
completely unrealistic way).</para>
</section>
@@ -198,7 +198,7 @@
<para>With this strategy, Hibernate Search will share the same
IndexReader, for a given Lucene index, across multiple queries and
threads provided that the IndexReader is still up-to-date. If the
- IndexReader is not up-to-date, an new one is opened and provided.
+ IndexReader is not up-to-date, a new one is opened and provided.
Generally speaking, this strategy provides much better performances than
the <literal>not-shared</literal> strategy. It is especially true if the
number of updates is much lower than the reads. This strategy is the
@@ -209,7 +209,7 @@
<title>Not-shared</title>
<para>Every time a query is executed, a Lucene IndexReader is opened.
- This strategy is not the most efficient: opening and warming up an
+ This strategy is not the most efficient since opening and warming up an
IndexReader can be a relatively expensive operation.</para>
</section>
Modified: search/trunk/doc/reference/en/modules/getting-started.xml
===================================================================
--- search/trunk/doc/reference/en/modules/getting-started.xml 2007-08-24 13:24:03 UTC (rev 13949)
+++ search/trunk/doc/reference/en/modules/getting-started.xml 2007-08-27 21:09:58 UTC (rev 13950)
@@ -4,7 +4,7 @@
<title>Getting started</title>
<para>
- The following chapter will guide you through the minimal steps
+ The following chapter will guide you through the initial steps
required to integrate Hibernate Search into an existing
Hibernate enabled application. In case you are a Hibernate new timer
we recommend you start <ulink url="http://hibernate.org/152.html">here</ulink>.
@@ -29,7 +29,7 @@
<entry>Hibernate Search</entry>
<entry>
<literal>hibernate-search.jar</literal> and all the dependencies from
- the <literal>lib</literal> directory of the distribution.
+ the <literal>lib</literal> directory of the Hibernate Search distribution.
</entry>
</row>
<row>
@@ -53,7 +53,7 @@
</tgroup>
</table>
<para>
- You can download these dependencies from the Hibernate
+ You can download all dependencies from the Hibernate
<ulink url="http://www.hibernate.org/6.html">download site</ulink>. You can also verify the
dependency versions against the <ulink url="http://www.hibernate.org/6.html#A3">
Hibernate Compatibility Matrix</ulink>.
@@ -64,13 +64,17 @@
<title>Configuration</title>
<para>
Once you have downloaded and added all required dependencies to your application you have
- to add a few properties to your hibernate configuration file (hibernate.properties, hibernate.cfg.xml or persistence.xml). The good news is that for standard use
- most properties offer a sensible default.
- We recommend to start with a <classname>FSDirectoryProvider</classname>.
- This has the advantage that you can physically inspect (eg via
- <ulink url="http://www.getopt.org/luke/">Luke</ulink>) the Lucene indeces created by
+ to add a few properties to your hibernate configuration file. If you are using Hibernate directly this can
+ be done in <literal>hibernate.properties</literal> or <literal>hibernate.cfg.xml</literal>.
+ If you are using Hibernate via JPA you can also add the properties to <literal>persistence.xml</literal>.
+ The good news is that for standard use most properties offer a sensible default.
+ </para>
+ <para>
+ In this tutorial we will start off <classname>FSDirectoryProvider</classname> which will give us
+ the ability to physically inspect the Lucene indexes (eg via
+ <ulink url="http://www.getopt.org/luke/">Luke</ulink>) created by
Hibernate Search. Once you have a working configuration you can start experimenting with
- other <xref linkend="search-configuration-directory"/>s.
+ other directory providers (see <xref linkend="search-configuration-directory"/>).
</para>
<para>
Lets assume that your application contains the Hibernate managed class <classname>example.Book</classname>.
@@ -100,7 +104,7 @@
<para>
First you have to tell Hibernate Search which <classname>DirectoryProvider</classname> to use.
- This can be achieved by setting the <literal>hibernate.search.default.directory_provider</literal>.
+ This can be achieved by setting the <literal>hibernate.search.default.directory_provider</literal> property.
You also want to specify the default root directory for all indexes via <literal>hibernate.search.default.indexBase</literal>.
</para>
@@ -118,8 +122,7 @@
Next you have to add three annotations to the <classname>Book</classname> class. The
first annotation <literal>@Indexed</literal> marks <classname>Book</classname>
as indexable. By design Hibernate Search needs to store an untokenized id in the index to ensure
- index unicity for a given entity. <literal>@DocumentId</literal> marks the property to use
- as id.
+ index unicity for a given entity. <literal>@DocumentId</literal> marks the property to use.
Last but not least you have to index the fields you want to make searchable. In our example
these fields are <literal>body</literal> and <literal>summary</literal>. Both properties get
annotated with <literal>@Field</literal>. The property <literal>index=Index.TOKENIZED</literal> will
@@ -165,24 +168,38 @@
<title>Indexing</title>
<para>
Once you have added the above properties and annotations it is time to trigger an
- initial batch index of your books. You can achieve this by adding the following lines
+ initial batch index of your books. You can achieve this by adding one of the following code examples
to your code (see also <xref linkend="search-batchindex"/>):
</para>
+ <para>
+ Example using Hibernate Session:
+ </para>
<programlisting>
FullTextSession fullTextSession = Search.createFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
+... // retrieving the all books from the database using HQL
for (Book book : books) {
fullTextSession.index(book);
}
tx.commit(); //index are written at commit time
</programlisting>
<para>
+ Example using JPA:
+ </para>
+ <programlisting>
+EntityManager em = entityManagerFactory.createEntityManager();
+FullTextEntityManager fullTextEntityManager = Search.createFullTextEntityManager(em);
+... // retrieving the all books from the database using JPA-QL
+for (Book book : books) {
+ fullTextEntityManager.index(book);
+}
+ </programlisting>
+ <para>
After executing the above code there should be a Lucene index under
<literal>/var/lucene/indexes/example.Book</literal>. Go ahead an inspect this index. It will
help you to understand how Hibernate Search works.
</para>
</section>
-
<section>
<title>Searching</title>
<para>
@@ -190,11 +207,10 @@
the fields <literal>summary</literal> and <literal>body</literal> , execute it and return
a list of <classname>Book</classname>s:
</para>
-
+ <para>
+ Example using Hibernate Session:
+ </para>
<programlisting>
-// JPA users have to use <classname>EntityManager</classname> and <classname>FullTextEntityManager</classname>
-// instead of <classname>Session</classname> and <classname>FullTextSession</classname> in order create a query - see <xref linkend="search-query"/>
-
// the use of HibernateUtil is only an example of how to get hold of the current session!
Session session = HibernateUtil.getCurrentSession();
FullTextSession fullTextSession = Search.createFullTextSession();
@@ -203,23 +219,100 @@
MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{"summary", "body"},
new StandardAnalyzer());
-Query query = parser.parse( "Java" );
+Query query = parser.parse( "Java rocks!" );
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery( query, Book.class );
List result = hibQuery.list();
tx.commit();
session.close();
- </programlisting>
+ </programlisting>
+ <para>
+ Example using JPA:
+ </para>
+ <programlisting>
+EntityManager em = entityManagerFactory.createEntityManager();
+
+FullTextEntityManager fullTextEntityManager =
+ org.hibernate.hibernate.search.jpa.Search.createFullTextEntityManager(em);
+MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{"summary", "body"},
+ new StandardAnalyzer());
+Query query = parser.parse( "Java rocks!" );
+org.hibernate.Query hibQuery = fullTextEntityManager.createFullTextQuery( query, Book.class );
+List result = hibQuery.list();
+ </programlisting>
</section>
<section>
+ <title>Analyzer</title>
+ Assume that one of your indexed book entities contains the text "Java rocks" and you want to get
+ hits for all of the following queries: "rock", "rocks", "rocked" and "rocking". In Lucene this
+ can be achieved by choosing an analyzer class which applies word stemming during the indexing process.
+ Hibernate Search exposes this Lucene functionality and allows to specify the analyzer class via the
+ property <literal>hibernate.search.analyzer</literal> in the configuration file or via an annotation
+ on entity or field level (see <xref linkend="analyzer"/>).
+
+ The following example uses an annotation on the entity level to apply a English language analyzer
+ which would help you to achieve your goal:
+ <programlisting>
+package example.Book
+...
+@Entity
+@Indexed
+<emphasis role="bold">@Analyzer(impl = example.EnglishAnalyzer.class)</emphasis>
+public class Book {
+
+ @Id
+ @DocumentId
+ private Integer id;
+
+ @Field(index=Index.TOKENIZED, store=Store.NO)
+ private String body;
+
+ @Field(index=Index.TOKENIZED, store=Store.NO)
+ private String summary;
+ private Set<Author> authors = new HashSet<Author>();
+ private Author mainAuthor;
+ private Date publicationDate;
+
+ public Book() {
+ }
+
+ // standard getters/setters follow here
+...
+}
+
+public class EnglishAnalyzer extends Analyzer {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public TokenStream tokenStream(String fieldName, Reader reader) {
+ TokenStream result = new StandardTokenizer(reader);
+ result = new StandardFilter(result);
+ result = new LowerCaseFilter(result);
+ result = new SnowballFilter(result, name);
+ return result;
+ }
+}
+ </programlisting>
+ </section>
+
+ <section>
<title>What's next</title>
<para>
- The above paragraphs hopefully helped you to get started with Hibernate Search. You
- should have a simple file system based index and be able to search and retrieve a list of
- your indexed objects via Hibernate Search. The next step is to get more familiar with the
- overall architecture and explore more advanced topics like <xref linkend="jms-backend"/> and
- <xref linkend="search-configuration-directory-sharding"/>.
+ The above paragraphs hopefully helped you getting started with Hibernate Search. You
+ should by now have a simple file system based index and be able to search and retrieve a list of
+ managed objects via Hibernate Search. The next step is to get more familiar with the
+ overall architecture and explore the basic features in more detail.
</para>
+ <para>
+ Two topics which where only briefly touched in this tutorial were analyzer configuration
+ (<xref linkend="analyzer"/>) and field bridges (<xref linkend="search-mapping-bridge"/>), both important
+ features required for more fain grained indexing.
+ </para>
+ <para>
+ More advanced topics cover topics like clustering (<xref linkend="jms-backend"/>) and large indexes
+ handling (<xref linkend="search-configuration-directory-sharding"/>).
+ </para>
</section>
</chapter>
\ No newline at end of file
Modified: search/trunk/doc/reference/en/modules/mapping.xml
===================================================================
--- search/trunk/doc/reference/en/modules/mapping.xml 2007-08-24 13:24:03 UTC (rev 13949)
+++ search/trunk/doc/reference/en/modules/mapping.xml 2007-08-27 21:09:58 UTC (rev 13950)
@@ -400,8 +400,8 @@
</citetitle> from Otis Gospodnetic and Erik Hatcher.</para>
</section>
- <section>
- <title>Analyser</title>
+ <section id="analyzer">
+ <title>Analyzer</title>
<para>The default analyzer class used to index the elements is
configurable through the <literal>hibernate.search.analyzer</literal>
16 years, 6 months
Hibernate SVN: r13949 - core/trunk/testsuite/src/test/java/org/hibernate/test/ops.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-24 09:24:03 -0400 (Fri, 24 Aug 2007)
New Revision: 13949
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/ops/GetLoadTest.java
Log:
new test
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/ops/GetLoadTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/ops/GetLoadTest.java 2007-08-22 15:36:17 UTC (rev 13948)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/ops/GetLoadTest.java 2007-08-24 13:24:03 UTC (rev 13949)
@@ -2,7 +2,6 @@
package org.hibernate.test.ops;
import junit.framework.Test;
-import junit.framework.TestSuite;
import org.hibernate.Hibernate;
import org.hibernate.Session;
@@ -83,6 +82,26 @@
assertFetchCount(0);
}
+ public void testGetAfterDelete() {
+ clearCounts();
+
+ Session s = openSession();
+ s.beginTransaction();
+ Employer emp = new Employer();
+ s.persist( emp );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( emp );
+ emp = ( Employer ) s.get( Employee.class, emp.getId() );
+ s.getTransaction().commit();
+ s.close();
+
+ assertNull( "get did not return null after delete", emp );
+ }
+
private void clearCounts() {
getSessions().getStatistics().clear();
}
16 years, 7 months
Hibernate SVN: r13948 - in sandbox/trunk/jdbc-proxy/src: main/java/org/hibernate/jdbc/impl and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-08-22 11:36:17 -0400 (Wed, 22 Aug 2007)
New Revision: 13948
Added:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainerBuilder.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractProxyHandler.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractResultSetProxyHandler.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/DatabaseMetaDataProxyHandler.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitResultSetProxyHandler.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitStatementProxyHandler.java
Removed:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java
Modified:
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxyHandler.java
sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxyHandler.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/ResultSetProxyHandler.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java
sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.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
sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java
sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java
Log:
refactoring
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/AbstractStatementDelegate.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -52,6 +52,10 @@
getJdbcContainer().register( this );
}
+ protected String getSql() {
+ return null;
+ }
+
protected void errorIfInvalid() {
if ( !valid ) {
throw new HibernateException( "statement handle is invalid" );
@@ -99,7 +103,7 @@
return connectionDelegate;
}
- public void close() throws SQLException {
+ public void close() {
if ( valid ) {
LogicalConnectionImplementor lc = connectionDelegate.getLogicalConnection();
getJdbcContainer().release( this );
@@ -109,24 +113,39 @@
// execution-related methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public ResultSet getGeneratedKeys() throws SQLException {
- return new ResultSetDelegate( this, getWrappedStatement().getGeneratedKeys() );
+ public ResultSet getGeneratedKeys() {
+ try {
+ return new ResultSetDelegate( this, getWrappedStatement().getGeneratedKeys() );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get generated keys", getSql() );
+ }
}
- public ResultSet getResultSet() throws SQLException {
- currentResultSetDelegate = new ResultSetDelegate( this, getWrappedStatement().getResultSet() );
- return currentResultSetDelegate;
+ public ResultSet getResultSet() {
+ try {
+ currentResultSetDelegate = new ResultSetDelegate( this, getWrappedStatement().getResultSet() );
+ return currentResultSetDelegate;
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set", getSql() );
+ }
}
- public int getUpdateCount() throws SQLException {
- return getWrappedStatement().getUpdateCount();
+ public int getUpdateCount() {
+ try {
+ return getWrappedStatement().getUpdateCount();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get update count", getSql() );
+ }
}
- public boolean getMoreResults() throws SQLException {
+ public boolean getMoreResults() {
return getMoreResults( Statement.CLOSE_CURRENT_RESULT );
}
- public boolean getMoreResults(int current) throws SQLException {
+ public boolean getMoreResults(int current) {
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;
@@ -135,89 +154,195 @@
getJdbcContainer().release( currentResultSetDelegate );
}
currentResultSetDelegate = null;
- return getWrappedStatement().getMoreResults( current );
+
+ try {
+ return getWrappedStatement().getMoreResults( current );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to getMoreResults", getSql() );
+ }
}
- public void cancel() throws SQLException {
- getWrappedStatement().cancel();
+ public void cancel() {
+ try {
+ getWrappedStatement().cancel();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to cancel", getSql() );
+ }
}
- public void clearBatch() throws SQLException {
- getWrappedStatement().clearBatch();
+ public void clearBatch() {
+ try {
+ getWrappedStatement().clearBatch();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to clear batch", getSql() );
+ }
}
- public int[] executeBatch() throws SQLException {
- return getWrappedStatement().executeBatch();
+ public int[] executeBatch() {
+ try {
+ return getWrappedStatement().executeBatch();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute batch", getSql() );
+ }
}
// general Statement methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public int getMaxFieldSize() throws SQLException {
- return getWrappedStatement().getMaxFieldSize();
+ public int getMaxFieldSize() {
+ try {
+ return getWrappedStatement().getMaxFieldSize();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get max field size", getSql() );
+ }
}
- public void setMaxFieldSize(int max) throws SQLException {
- getWrappedStatement().setMaxFieldSize( max );
+ public void setMaxFieldSize(int max) {
+ try {
+ getWrappedStatement().setMaxFieldSize( max );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set max field size", getSql() );
+ }
}
- public int getMaxRows() throws SQLException {
- return getWrappedStatement().getMaxRows();
+ public int getMaxRows() {
+ try {
+ return getWrappedStatement().getMaxRows();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get max rows", getSql() );
+ }
}
- public void setMaxRows(int max) throws SQLException {
- getWrappedStatement().setMaxRows( max );
+ public void setMaxRows(int max) {
+ try {
+ getWrappedStatement().setMaxRows( max );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set max rows", getSql() );
+ }
}
- public void setEscapeProcessing(boolean enable) throws SQLException {
- getWrappedStatement().setEscapeProcessing( enable );
+ public void setEscapeProcessing(boolean enable) {
+ try {
+ getWrappedStatement().setEscapeProcessing( enable );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set escape processing", getSql() );
+ }
}
- public int getQueryTimeout() throws SQLException {
- return getWrappedStatement().getQueryTimeout();
+ public int getQueryTimeout() {
+ try {
+ return getWrappedStatement().getQueryTimeout();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get query timeout", getSql() );
+ }
}
- public void setQueryTimeout(int seconds) throws SQLException {
- getWrappedStatement().setQueryTimeout( seconds );
+ public void setQueryTimeout(int seconds) {
+ try {
+ getWrappedStatement().setQueryTimeout( seconds );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set query timeout", getSql() );
+ }
}
- public void setCursorName(String name) throws SQLException {
- getWrappedStatement().setCursorName( name );
+ public void setCursorName(String name) {
+ try {
+ getWrappedStatement().setCursorName( name );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set cursor name", getSql() );
+ }
}
- public void setFetchDirection(int direction) throws SQLException {
- getWrappedStatement().setFetchDirection( direction );
+ public int getFetchDirection() {
+ try {
+ return getWrappedStatement().getFetchDirection();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get fetch direction", getSql() );
+ }
}
- public int getFetchDirection() throws SQLException {
- return getWrappedStatement().getFetchDirection();
+ public void setFetchDirection(int direction) {
+ try {
+ getWrappedStatement().setFetchDirection( direction );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set fetch direction", getSql() );
+ }
}
- public void setFetchSize(int rows) throws SQLException {
- getWrappedStatement().setFetchSize( rows );
+ public int getFetchSize() {
+ try {
+ return getWrappedStatement().getFetchSize();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get fetch size", getSql() );
+ }
}
- public int getFetchSize() throws SQLException {
- return getWrappedStatement().getFetchSize();
+ public void setFetchSize(int rows) {
+ try {
+ getWrappedStatement().setFetchSize( rows );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set fetch size", getSql() );
+ }
}
- public int getResultSetConcurrency() throws SQLException {
- return getWrappedStatement().getResultSetConcurrency();
+ public int getResultSetConcurrency() {
+ try {
+ return getWrappedStatement().getResultSetConcurrency();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set concurrency", getSql() );
+ }
}
- public int getResultSetType() throws SQLException {
- return getWrappedStatement().getResultSetType();
+ public int getResultSetType() {
+ try {
+ return getWrappedStatement().getResultSetType();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set type", getSql() );
+ }
}
- public int getResultSetHoldability() throws SQLException {
- return getWrappedStatement().getResultSetHoldability();
+ public int getResultSetHoldability() {
+ try {
+ return getWrappedStatement().getResultSetHoldability();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set holdability", getSql() );
+ }
}
- public SQLWarning getWarnings() throws SQLException {
- return getWrappedStatement().getWarnings();
+ public SQLWarning getWarnings() {
+ try {
+ return getWrappedStatement().getWarnings();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get warnings", getSql() );
+ }
}
- public void clearWarnings() throws SQLException {
- getWrappedStatement().clearWarnings();
+ public void clearWarnings() {
+ try {
+ getWrappedStatement().clearWarnings();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to clear warnings", getSql() );
+ }
}
}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/BasicStatementDelegate.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -29,53 +29,103 @@
super( connectionDelegate, statement );
}
- public void addBatch(String sql) throws SQLException {
+ public void addBatch(String sql) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- getWrappedStatement().addBatch( sql );
+ try {
+ getWrappedStatement().addBatch( sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to add batch", sql );
+ }
}
- public boolean execute(String sql) throws SQLException {
+ public boolean execute(String sql) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- return getWrappedStatement().execute( sql );
+ try {
+ return getWrappedStatement().execute( sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+ }
}
- public ResultSet executeQuery(String sql) throws SQLException {
+ public ResultSet executeQuery(String sql) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- return new ResultSetDelegate( this, getWrappedStatement().executeQuery( sql ) );
+ try {
+ return new ResultSetDelegate( this, getWrappedStatement().executeQuery( sql ) );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute query", sql );
+ }
}
- public int executeUpdate(String sql) throws SQLException {
+ public int executeUpdate(String sql) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- return getWrappedStatement().executeUpdate( sql );
+ try {
+ return getWrappedStatement().executeUpdate( sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+ }
}
- public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+ public int executeUpdate(String sql, int autoGeneratedKeys) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- return getWrappedStatement().executeUpdate( sql, autoGeneratedKeys );
+ try {
+ return getWrappedStatement().executeUpdate( sql, autoGeneratedKeys );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+ }
}
- public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+ public int executeUpdate(String sql, int[] columnIndexes) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- return getWrappedStatement().executeUpdate( sql, columnIndexes );
+ try {
+ return getWrappedStatement().executeUpdate( sql, columnIndexes );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+ }
}
- public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+ public int executeUpdate(String sql, String[] columnNames) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- return getWrappedStatement().executeUpdate( sql, columnNames );
+ try {
+ return getWrappedStatement().executeUpdate( sql, columnNames );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+ }
}
- public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+ public boolean execute(String sql, int autoGeneratedKeys) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- return getWrappedStatement().execute( sql, autoGeneratedKeys );
+ try {
+ return getWrappedStatement().execute( sql, autoGeneratedKeys );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+ }
}
- public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+ public boolean execute(String sql, int[] columnIndexes) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- return getWrappedStatement().execute( sql, columnIndexes );
+ try {
+ return getWrappedStatement().execute( sql, columnIndexes );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+ }
}
- public boolean execute(String sql, String[] columnNames) throws SQLException {
+ public boolean execute(String sql, String[] columnNames) {
getJdbcServices().getSqlStatementLogger().logStatement( sql );
- return getWrappedStatement().execute( sql, columnNames );
+ try {
+ return getWrappedStatement().execute( sql, columnNames );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+ }
}
}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/ConnectionDelegate.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -293,91 +293,202 @@
return !valid;
}
- public void setAutoCommit(boolean autoCommit) throws SQLException {
- getWrappedConnection().setAutoCommit( autoCommit );
+ public void setAutoCommit(boolean autoCommit) {
+ try {
+ getWrappedConnection().setAutoCommit( autoCommit );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set auto-commit" );
+ }
}
- public boolean getAutoCommit() throws SQLException {
- return getWrappedConnection().getAutoCommit();
+ public boolean getAutoCommit() {
+ try {
+ return getWrappedConnection().getAutoCommit();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get auto-commit" );
+ }
}
- public void commit() throws SQLException {
- getWrappedConnection().commit();
+ public void commit() {
+ try {
+ getWrappedConnection().commit();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to commit" );
+ }
}
- public void rollback() throws SQLException {
- getWrappedConnection().rollback();
+ public void rollback() {
+ try {
+ getWrappedConnection().rollback();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to rollback" );
+ }
}
- public DatabaseMetaData getMetaData() throws SQLException {
- return getWrappedConnection().getMetaData();
+ public DatabaseMetaData getMetaData() {
+ // todo : wrap...
+ try {
+ return getWrappedConnection().getMetaData();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get metadata" );
+ }
}
- public String nativeSQL(String sql) throws SQLException {
- return getWrappedConnection().nativeSQL( sql );
+ public String nativeSQL(String sql) {
+ try {
+ return getWrappedConnection().nativeSQL( sql );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to native-ize sql" );
+ }
}
- public void setReadOnly(boolean readOnly) throws SQLException {
- getWrappedConnection().setReadOnly( readOnly );
+ public void setReadOnly(boolean readOnly) {
+ try {
+ getWrappedConnection().setReadOnly( readOnly );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set readonly-ness" );
+ }
}
- public boolean isReadOnly() throws SQLException {
- return getWrappedConnection().isReadOnly();
+ public boolean isReadOnly() {
+ try {
+ return getWrappedConnection().isReadOnly();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to query readonly-ness" );
+ }
}
- public void setCatalog(String catalog) throws SQLException {
- getWrappedConnection().setCatalog( catalog );
+ public void setCatalog(String catalog) {
+ try {
+ getWrappedConnection().setCatalog( catalog );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set catalog" );
+ }
}
- public String getCatalog() throws SQLException {
- return getWrappedConnection().getCatalog();
+ public String getCatalog() {
+ try {
+ return getWrappedConnection().getCatalog();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set auto-commit" );
+ }
}
- public void setTransactionIsolation(int level) throws SQLException {
- getWrappedConnection().setTransactionIsolation( level );
+ public void setTransactionIsolation(int level) {
+ try {
+ getWrappedConnection().setTransactionIsolation( level );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set isolation" );
+ }
}
- public int getTransactionIsolation() throws SQLException {
- return getWrappedConnection().getTransactionIsolation();
+ public int getTransactionIsolation() {
+ try {
+ return getWrappedConnection().getTransactionIsolation();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get isolation" );
+ }
}
- public SQLWarning getWarnings() throws SQLException {
- return getWrappedConnection().getWarnings();
+ public SQLWarning getWarnings() {
+ try {
+ return getWrappedConnection().getWarnings();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get wranings" );
+ }
}
- public void clearWarnings() throws SQLException {
- getWrappedConnection().clearWarnings();
+ public void clearWarnings() {
+ try {
+ getWrappedConnection().clearWarnings();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to clear warnings" );
+ }
}
- public Map<String, Class<?>> getTypeMap() throws SQLException {
- return getWrappedConnection().getTypeMap();
+ public Map<String, Class<?>> getTypeMap() {
+ try {
+ return getWrappedConnection().getTypeMap();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get type-map" );
+ }
}
- public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
- getWrappedConnection().setTypeMap( map );
+ public void setTypeMap(Map<String, Class<?>> map) {
+ try {
+ getWrappedConnection().setTypeMap( map );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set type-map" );
+ }
}
- public void setHoldability(int holdability) throws SQLException {
- getWrappedConnection().setHoldability( holdability );
+ public void setHoldability(int holdability) {
+ try {
+ getWrappedConnection().setHoldability( holdability );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set holdability" );
+ }
}
- public int getHoldability() throws SQLException {
- return getWrappedConnection().getHoldability();
+ public int getHoldability() {
+ try {
+ return getWrappedConnection().getHoldability();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get holdability" );
+ }
}
- public Savepoint setSavepoint() throws SQLException {
- return getWrappedConnection().setSavepoint();
+ public Savepoint setSavepoint() {
+ try {
+ return getWrappedConnection().setSavepoint();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set savepoint" );
+ }
}
- public Savepoint setSavepoint(String name) throws SQLException {
- return getWrappedConnection().setSavepoint( name );
+ public Savepoint setSavepoint(String name) {
+ try {
+ return getWrappedConnection().setSavepoint( name );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to set savepoint" );
+ }
}
- public void rollback(Savepoint savepoint) throws SQLException {
- getWrappedConnection().rollback( savepoint );
+ public void rollback(Savepoint savepoint) {
+ try {
+ getWrappedConnection().rollback( savepoint );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to rollback savepoint" );
+ }
}
- public void releaseSavepoint(Savepoint savepoint) throws SQLException {
- getWrappedConnection().releaseSavepoint( savepoint );
+ public void releaseSavepoint(Savepoint savepoint) {
+ try {
+ getWrappedConnection().releaseSavepoint( savepoint );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to release savepoint" );
+ }
}
}
Deleted: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/DelegateJDBCContainer.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -1,62 +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.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.impl.StatementWrapperImplementor;
-import org.hibernate.jdbc.impl.ResultSetWrapperImplementor;
-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 );
- }
- }
-}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/delegation/PreparedStatementDelegate.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -53,6 +53,10 @@
getJdbcServices().getSqlStatementLogger().logStatement( sql );
}
+ protected String getSql() {
+ return sql;
+ }
+
private PreparedStatement getPreparedStatement() {
return ( PreparedStatement ) super.getWrappedStatement();
}
@@ -60,153 +64,338 @@
// PreparedStatement impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public void addBatch() throws SQLException {
- getPreparedStatement().addBatch();
+ public void addBatch() {
+ try {
+ getPreparedStatement().addBatch();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to addBatch", sql );
+ }
}
- public boolean execute() throws SQLException {
- return getPreparedStatement().execute();
+ public boolean execute() {
+ try {
+ return getPreparedStatement().execute();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute", sql );
+ }
}
- public ResultSet executeQuery() throws SQLException {
- return new ResultSetDelegate( this, getPreparedStatement().executeQuery() );
+ public ResultSet executeQuery() {
+ try {
+ return new ResultSetDelegate( this, getPreparedStatement().executeQuery() );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute query", sql );
+ }
}
- public int executeUpdate() throws SQLException {
- return getPreparedStatement().executeUpdate();
+ public int executeUpdate() {
+ try {
+ return getPreparedStatement().executeUpdate();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to execute update", sql );
+ }
}
- public ResultSetMetaData getMetaData() throws SQLException {
- return getPreparedStatement().getMetaData();
+ public ResultSetMetaData getMetaData() {
+ try {
+ return getPreparedStatement().getMetaData();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get result set metadata", sql );
+ }
}
- public ParameterMetaData getParameterMetaData() throws SQLException {
- return getPreparedStatement().getParameterMetaData();
+ public ParameterMetaData getParameterMetaData() {
+ try {
+ return getPreparedStatement().getParameterMetaData();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to get parameter metadata", sql );
+ }
}
- public void clearParameters() throws SQLException {
- getPreparedStatement().clearParameters();
+ public void clearParameters() {
+ try {
+ getPreparedStatement().clearParameters();
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to clear parameters", sql );
+ }
}
- public void setNull(int parameterIndex, int sqlType) throws SQLException {
- getPreparedStatement().setNull( parameterIndex, sqlType );
+ public void setNull(int parameterIndex, int sqlType) {
+ try {
+ getPreparedStatement().setNull( parameterIndex, sqlType );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setNull", sql );
+ }
}
- public void setBoolean(int parameterIndex, boolean x) throws SQLException {
- getPreparedStatement().setBoolean( parameterIndex, x );
+ public void setNull(int parameterIndex, int sqlType, String typeName) {
+ try {
+ getPreparedStatement().setNull( parameterIndex, sqlType, typeName );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setNull", sql );
+ }
}
- public void setByte(int parameterIndex, byte x) throws SQLException {
- getPreparedStatement().setByte( parameterIndex, x );
+ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) {
+ try {
+ getPreparedStatement().setObject( parameterIndex, x, targetSqlType, scale );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setObject", sql );
+ }
}
- public void setShort(int parameterIndex, short x) throws SQLException {
- getPreparedStatement().setShort( parameterIndex, x );
+ public void setObject(int parameterIndex, Object x, int targetSqlType) {
+ try {
+ getPreparedStatement().setObject( parameterIndex, x, targetSqlType );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setObject", sql );
+ }
}
- public void setInt(int parameterIndex, int x) throws SQLException {
- getPreparedStatement().setInt( parameterIndex, x );
+ public void setObject(int parameterIndex, Object x) {
+ try {
+ getPreparedStatement().setObject( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setObject", sql );
+ }
}
- public void setLong(int parameterIndex, long x) throws SQLException {
- getPreparedStatement().setLong( parameterIndex, x );
+ public void setBoolean(int parameterIndex, boolean x) {
+ try {
+ getPreparedStatement().setBoolean( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBoolean", sql );
+ }
}
- public void setFloat(int parameterIndex, float x) throws SQLException {
- getPreparedStatement().setFloat( parameterIndex, x );
+ public void setByte(int parameterIndex, byte x) {
+ try {
+ getPreparedStatement().setByte( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setByte", sql );
+ }
}
- public void setDouble(int parameterIndex, double x) throws SQLException {
- getPreparedStatement().setDouble( parameterIndex, x );
+ public void setShort(int parameterIndex, short x) {
+ try {
+ getPreparedStatement().setShort( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setShort", sql );
+ }
}
- public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
- getPreparedStatement().setBigDecimal( parameterIndex, x );
+ public void setInt(int parameterIndex, int x) {
+ try {
+ getPreparedStatement().setInt( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setInt", sql );
+ }
}
- public void setString(int parameterIndex, String x) throws SQLException {
- getPreparedStatement().setString( parameterIndex, x );
+ public void setLong(int parameterIndex, long x) {
+ try {
+ getPreparedStatement().setLong( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setLong", sql );
+ }
}
- public void setBytes(int parameterIndex, byte[] x) throws SQLException {
- getPreparedStatement().setBytes( parameterIndex, x );
+ public void setFloat(int parameterIndex, float x) {
+ try {
+ getPreparedStatement().setFloat( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setFloat", sql );
+ }
}
- public void setDate(int parameterIndex, Date x) throws SQLException {
- getPreparedStatement().setDate( parameterIndex, x );
+ public void setDouble(int parameterIndex, double x) {
+ try {
+ getPreparedStatement().setDouble( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setDouble", sql );
+ }
}
- public void setTime(int parameterIndex, Time x) throws SQLException {
- getPreparedStatement().setTime( parameterIndex, x );
+ public void setBigDecimal(int parameterIndex, BigDecimal x) {
+ try {
+ getPreparedStatement().setBigDecimal( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBigDecimal", sql );
+ }
}
- public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
- getPreparedStatement().setTimestamp( parameterIndex, x );
+ public void setString(int parameterIndex, String x) {
+ try {
+ getPreparedStatement().setString( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setString", sql );
+ }
}
- public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
- getPreparedStatement().setAsciiStream( parameterIndex, x, length );
+ public void setBytes(int parameterIndex, byte[] x) {
+ try {
+ getPreparedStatement().setBytes( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBytes", sql );
+ }
}
- @Deprecated
- public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
- getPreparedStatement().setUnicodeStream( parameterIndex, x, length );
+ public void setDate(int parameterIndex, Date x) {
+ try {
+ getPreparedStatement().setDate( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setDate", sql );
+ }
}
- public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
- getPreparedStatement().setBinaryStream( parameterIndex, x, length );
+ public void setTime(int parameterIndex, Time x) {
+ try {
+ getPreparedStatement().setTime( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setTime", sql );
+ }
}
- public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
- getPreparedStatement().setObject( parameterIndex, x, targetSqlType, scale );
+ public void setTimestamp(int parameterIndex, Timestamp x) {
+ try {
+ getPreparedStatement().setTimestamp( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setTimestamp", sql );
+ }
}
- public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
- getPreparedStatement().setObject( parameterIndex, x, targetSqlType );
+ public void setAsciiStream(int parameterIndex, InputStream x, int length) {
+ try {
+ getPreparedStatement().setAsciiStream( parameterIndex, x, length );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setAsciiStream", sql );
+ }
}
- public void setObject(int parameterIndex, Object x) throws SQLException {
- getPreparedStatement().setObject( parameterIndex, x );
+ @Deprecated
+ public void setUnicodeStream(int parameterIndex, InputStream x, int length) {
+ try {
+ getPreparedStatement().setUnicodeStream( parameterIndex, x, length );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setUnicodeStream", sql );
+ }
}
- public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
- getPreparedStatement().setCharacterStream( parameterIndex, reader, length );
+ public void setBinaryStream(int parameterIndex, InputStream x, int length) {
+ try {
+ getPreparedStatement().setBinaryStream( parameterIndex, x, length );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBinaryStream", sql );
+ }
}
- public void setRef(int parameterIndex, Ref x) throws SQLException {
- getPreparedStatement().setRef( parameterIndex, x );
+ public void setCharacterStream(int parameterIndex, Reader reader, int length) {
+ try {
+ getPreparedStatement().setCharacterStream( parameterIndex, reader, length );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setCharacterStream", sql );
+ }
}
- public void setBlob(int parameterIndex, Blob x) throws SQLException {
- getPreparedStatement().setBlob( parameterIndex, x );
+ public void setRef(int parameterIndex, Ref x) {
+ try {
+ getPreparedStatement().setRef( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setRef", sql );
+ }
}
- public void setClob(int parameterIndex, Clob x) throws SQLException {
- getPreparedStatement().setClob( parameterIndex, x );
+ public void setBlob(int parameterIndex, Blob x) {
+ try {
+ getPreparedStatement().setBlob( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setBlob", sql );
+ }
}
- public void setArray(int parameterIndex, Array x) throws SQLException {
- getPreparedStatement().setArray( parameterIndex, x );
+ public void setClob(int parameterIndex, Clob x) {
+ try {
+ getPreparedStatement().setClob( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setClob", sql );
+ }
}
- public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
- getPreparedStatement().setDate( parameterIndex, x, cal );
+ public void setArray(int parameterIndex, Array x) {
+ try {
+ getPreparedStatement().setArray( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setArray", sql );
+ }
}
- public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
- getPreparedStatement().setTime( parameterIndex, x, cal );
+ public void setDate(int parameterIndex, Date x, Calendar cal) {
+ try {
+ getPreparedStatement().setDate( parameterIndex, x, cal );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setDate", sql );
+ }
}
- public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
- getPreparedStatement().setTimestamp( parameterIndex, x, cal );
+ public void setTime(int parameterIndex, Time x, Calendar cal) {
+ try {
+ getPreparedStatement().setTime( parameterIndex, x, cal );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setTime", sql );
+ }
}
- public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
- getPreparedStatement().setNull( parameterIndex, sqlType, typeName );
+ public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) {
+ try {
+ getPreparedStatement().setTimestamp( parameterIndex, x, cal );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setTimestamp", sql );
+ }
}
- public void setURL(int parameterIndex, URL x) throws SQLException {
- getPreparedStatement().setURL( parameterIndex, x );
+ public void setURL(int parameterIndex, URL x) {
+ try {
+ getPreparedStatement().setURL( parameterIndex, x );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, "unable to setURL", sql );
+ }
}
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-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainer.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -103,6 +103,9 @@
Set resultSets = ( Set ) xref.get( statement );
if ( resultSets != null ) {
resultSets.remove( resultSet );
+ if ( resultSets.isEmpty() ) {
+ xref.remove( statement );
+ }
}
close( resultSet );
}
@@ -141,6 +144,14 @@
protected void close(Statement statement) {
log.trace( "closing prepared statement [{}]", statement );
+
+ if ( statement instanceof StatementWrapperImplementor ) {
+ StatementWrapperImplementor wrapper = ( StatementWrapperImplementor ) statement;
+ close( wrapper.getWrappedStatement() );
+ wrapper.invalidate();
+ return;
+ }
+
try {
// if we are unable to "clean" the prepared statement,
// we do not close it
@@ -166,6 +177,13 @@
protected void close(ResultSet resultSet) {
log.trace( "closing result set [{}]", resultSet );
+
+ if ( resultSet instanceof ResultSetWrapperImplementor ) {
+ ResultSetWrapperImplementor wrapper = ( ResultSetWrapperImplementor ) resultSet;
+ close( wrapper.getWrappedResultSet() );
+ wrapper.invalidate();
+ }
+
try {
resultSet.close();
}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainerBuilder.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainerBuilder.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/impl/BasicJDBCContainerBuilder.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,37 @@
+/*
+ * 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.jdbc.JDBCContainerBuilder;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.util.ExceptionHelper;
+
+/**
+ * BasicJDBCContainerBuilder implementation
+ *
+ * @author Steve Ebersole
+ */
+public class BasicJDBCContainerBuilder implements JDBCContainerBuilder {
+ private final ExceptionHelper exceptionHelper;
+
+ public BasicJDBCContainerBuilder(ExceptionHelper exceptionHelper) {
+ this.exceptionHelper = exceptionHelper;
+ }
+
+ public JDBCContainer buildJdbcContainer() {
+ return new BasicJDBCContainer( exceptionHelper );
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractProxyHandler.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractProxyHandler.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,77 @@
+/*
+ * 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.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.hibernate.HibernateException;
+
+/**
+ * Basic support for
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractProxyHandler implements InvocationHandler {
+ private boolean valid = true;
+ private final int hashCode;
+
+ public AbstractProxyHandler(int hashCode) {
+ this.hashCode = hashCode;
+ }
+
+ protected abstract Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable;
+
+ public String toString() {
+ return super.toString() + "[valid=" + valid + "]";
+ }
+
+ public final int hashCode() {
+ return hashCode;
+ }
+
+ protected final boolean isValid() {
+ return valid;
+ }
+
+ protected final void invalidate() {
+ valid = false;
+ }
+
+ protected final void errorIfInvalid() {
+ if ( !isValid() ) {
+ throw new HibernateException( "proxy handle is no longer valid" );
+ }
+ }
+
+ public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ String methodName = method.getName();
+
+ // basic Object methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ if ( "toString".equals( methodName ) ) {
+ return this.toString();
+ }
+ if ( "hashCode".equals( methodName ) ) {
+ return this.hashCode();
+ }
+ if ( "equals".equals( methodName ) ) {
+ return this.equals( args[0] );
+ }
+
+ return continueInvocation( proxy, method, args );
+ }
+
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractResultSetProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractResultSetProxyHandler.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractResultSetProxyHandler.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,110 @@
+/*
+ * 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.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.JDBCServices;
+
+/**
+ * AbstractResultSetProxyHandler implementation
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractResultSetProxyHandler extends AbstractProxyHandler {
+ private static final Logger log = LoggerFactory.getLogger( AbstractResultSetProxyHandler.class );
+
+ private ResultSet resultSet;
+
+ public AbstractResultSetProxyHandler(ResultSet resultSet) {
+ super( resultSet.hashCode() );
+ this.resultSet = resultSet;
+ }
+
+ protected abstract JDBCServices getJdbcServices();
+
+ protected abstract JDBCContainer getJdbcContainer();
+
+ protected abstract Statement getExposeableStatement();
+
+ protected final ResultSet getResultSet() {
+ errorIfInvalid();
+ return resultSet;
+ }
+
+ protected final ResultSet getResultSetWithoutChecks() {
+ return resultSet;
+ }
+
+ protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
+ String methodName = method.getName();
+ log.trace( "Handling invocation of resultset method [{}]", methodName );
+
+ // other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ if ( "close".equals( methodName ) ) {
+ explicitClose( ( ResultSet ) proxy );
+ return null;
+ }
+ if ( "invalidate".equals( methodName ) ) {
+ invalidateHandle();
+ return null;
+ }
+
+ errorIfInvalid();
+
+ if ( "getWrappedResultSet".equals( methodName ) ) {
+ return getResultSetWithoutChecks();
+ }
+
+ if ( "getStatement".equals( methodName ) ) {
+ return getExposeableStatement();
+ }
+
+ try {
+ return method.invoke( resultSet, args );
+ }
+ catch ( InvocationTargetException e ) {
+ Throwable realException = e.getTargetException();
+ if ( SQLException.class.isInstance( realException ) ) {
+ throw getJdbcServices().getExceptionHelper()
+ .convert( ( SQLException ) realException, realException.getMessage() );
+ }
+ else {
+ throw realException;
+ }
+ }
+ }
+
+ private void explicitClose(ResultSet proxy) {
+ if ( isValid() ) {
+ getJdbcContainer().release( proxy );
+ }
+ }
+
+ protected void invalidateHandle() {
+ resultSet = null;
+ invalidate();
+ }
+}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxyHandler.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/AbstractStatementProxyHandler.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,7 +15,6 @@
*/
package org.hibernate.jdbc.proxy;
-import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
@@ -26,7 +25,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.hibernate.HibernateException;
import org.hibernate.jdbc.JDBCContainer;
import org.hibernate.jdbc.JDBCServices;
import org.hibernate.jdbc.impl.LogicalConnectionImplementor;
@@ -36,31 +34,23 @@
*
* @author Steve Ebersole
*/
-public abstract class AbstractStatementProxyHandler implements InvocationHandler {
+public abstract class AbstractStatementProxyHandler extends AbstractProxyHandler {
private static final Logger log = LoggerFactory.getLogger( AbstractStatementProxyHandler.class );
private ConnectionProxyHandler connectionProxyHandler;
private Connection connectionProxy;
private Statement statement;
- private boolean valid = true;
- private final int hashCode;
protected AbstractStatementProxyHandler(
Statement statement,
ConnectionProxyHandler connectionProxyHandler,
Connection connectionProxy) {
+ super( statement.hashCode() );
this.statement = statement;
this.connectionProxyHandler = connectionProxyHandler;
this.connectionProxy = connectionProxy;
- this.hashCode = statement.hashCode();
}
- private void errorIfInvalid() {
- if ( !valid ) {
- throw new HibernateException( "statment proxy is no longer valid" );
- }
- }
-
protected ConnectionProxyHandler getConnectionProxy() {
errorIfInvalid();
return connectionProxyHandler;
@@ -83,21 +73,10 @@
return statement;
}
- public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
log.trace( "Handling invocation of statement method [{}]", methodName );
- // basic Object methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if ( "toString".equals( methodName ) ) {
- return this.toString();
- }
- if ( "equals".equals( methodName ) ) {
- return this.equals( args[0] );
- }
- if ( "hashCode".equals( methodName ) ) {
- return this.hashCode();
- }
-
// other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if ( "close".equals( methodName ) ) {
explicitClose( ( Statement ) proxy );
@@ -121,15 +100,8 @@
beginningInvocationHandling( method, args );
try {
- boolean exposingResultSet = doesMethodExposeResultSet( method );
-
Object result = method.invoke( statement, args );
-
- if ( exposingResultSet ) {
- result = ProxyBuilder.buildResultSet( ( ResultSet ) result, this, ( Statement ) proxy );
- getJdbcContainer().register( ( ResultSet ) result );
- }
-
+ result = wrapIfNecessary( result, proxy, method );
return result;
}
catch ( InvocationTargetException e ) {
@@ -144,11 +116,27 @@
}
}
+ private Object wrapIfNecessary(Object result, Object proxy, Method method) {
+ if ( !( ResultSet.class.isAssignableFrom( method.getReturnType() ) ) ) {
+ return result;
+ }
+
+ final ResultSet wrapper;
+ if ( "getGeneratedKeys".equals( method.getName() ) ) {
+ wrapper = ProxyBuilder.buildImplicitResultSet( ( ResultSet ) result, connectionProxyHandler, connectionProxy );
+ }
+ else {
+ wrapper = ProxyBuilder.buildResultSet( ( ResultSet ) result, this, ( Statement ) proxy );
+ }
+ getJdbcContainer().register( wrapper );
+ return wrapper;
+ }
+
protected void beginningInvocationHandling(Method method, Object[] args) {
}
private void explicitClose(Statement proxy) {
- if ( valid ) {
+ if ( isValid() ) {
LogicalConnectionImplementor lc = getConnectionProxy().getLogicalConnection();
getJdbcContainer().release( proxy );
lc.afterStatementExecution();
@@ -158,20 +146,6 @@
private void invalidateHandle() {
connectionProxyHandler = null;
statement = null;
- valid = false;
+ invalidate();
}
-
- protected boolean doesMethodExposeResultSet(Method method) {
- // todo : we still need to handle getGeneratedKeys, since the resultset there would expose the statement
- return ResultSet.class.isAssignableFrom( method.getReturnType() )
- && !method.getName().equals( "getGeneratedKeys" );
- }
-
- public String toString() {
- return super.toString() + "[valid=" + valid + "]";
- }
-
- public int hashCode() {
- return hashCode;
- }
}
Modified: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxyHandler.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ConnectionProxyHandler.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -20,6 +20,7 @@
import java.lang.reflect.Method;
import java.sql.CallableStatement;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
@@ -27,7 +28,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.hibernate.HibernateException;
import org.hibernate.jdbc.JDBCContainer;
import org.hibernate.jdbc.JDBCServices;
import org.hibernate.jdbc.impl.ConnectionObserver;
@@ -38,17 +38,15 @@
*
* @author Steve Ebersole
*/
-public class ConnectionProxyHandler implements InvocationHandler, ConnectionObserver {
+public class ConnectionProxyHandler extends AbstractProxyHandler implements InvocationHandler, ConnectionObserver {
private static final Logger log = LoggerFactory.getLogger( ConnectionProxyHandler.class );
private LogicalConnectionImplementor logicalConnection;
- private boolean valid = true;
- private final int hashCode;
public ConnectionProxyHandler(LogicalConnectionImplementor logicalConnection) {
+ super( logicalConnection.hashCode() );
this.logicalConnection = logicalConnection;
this.logicalConnection.addObserver( this );
- this.hashCode = this.logicalConnection.hashCode();
}
/**
@@ -61,12 +59,6 @@
return logicalConnection;
}
- private void errorIfInvalid() {
- if ( !valid ) {
- throw new HibernateException( "connection handle is invalid" );
- }
- }
-
/**
* Get reference to physical connection.
* <p/>
@@ -100,24 +92,10 @@
return logicalConnection.getJdbcContainer();
}
- /**
- * {@inheritDoc}
- */
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
log.trace( "Handling invocation of connection method [{}]", methodName );
- // basic Object methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if ( "toString".equals( methodName ) ) {
- return this.toString();
- }
- if ( "equals".equals( methodName ) ) {
- return this.equals( args[0] );
- }
- if ( "hashCode".equals( methodName ) ) {
- return this.hashCode();
- }
-
// other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if ( "close".equals( methodName ) ) {
explicitClose();
@@ -132,34 +110,8 @@
try {
Object result = method.invoke( extractPhysicalConnection(), args );
+ result = wrapIfNecessary( result, proxy, method, args );
- if ( "createStatement".equals( methodName ) ) {
- result = ProxyBuilder.buildStatement(
- ( Statement ) result,
- this,
- ( Connection ) proxy
- );
- getJdbcContainer().register( ( Statement ) result );
- }
- else if ( "prepareStatement".equals( methodName ) ) {
- result = ProxyBuilder.buildPreparedStatement(
- ( String ) args[0],
- ( PreparedStatement ) result,
- this,
- ( Connection ) proxy
- );
- getJdbcContainer().register( ( Statement ) result );
- }
- else if ( "prepareCall".equals( methodName ) ) {
- result = ProxyBuilder.buildCallableStatement(
- ( String ) args[0],
- ( CallableStatement ) result,
- this,
- ( Connection ) proxy
- );
- getJdbcContainer().register( ( Statement ) result );
- }
-
return result;
}
catch( InvocationTargetException e ) {
@@ -174,8 +126,43 @@
}
}
+ private Object wrapIfNecessary(Object result, Object proxy, Method method, Object[] args) {
+ String methodName = method.getName();
+ Object wrapped = result;
+ if ( "createStatement".equals( methodName ) ) {
+ wrapped = ProxyBuilder.buildStatement(
+ ( Statement ) result,
+ this,
+ ( Connection ) proxy
+ );
+ getJdbcContainer().register( ( Statement ) wrapped );
+ }
+ else if ( "prepareStatement".equals( methodName ) ) {
+ wrapped = ProxyBuilder.buildPreparedStatement(
+ ( String ) args[0],
+ ( PreparedStatement ) result,
+ this,
+ ( Connection ) proxy
+ );
+ getJdbcContainer().register( ( Statement ) wrapped );
+ }
+ else if ( "prepareCall".equals( methodName ) ) {
+ wrapped = ProxyBuilder.buildCallableStatement(
+ ( String ) args[0],
+ ( CallableStatement ) result,
+ this,
+ ( Connection ) proxy
+ );
+ getJdbcContainer().register( ( Statement ) wrapped );
+ }
+ else if ( "getMetaData".equals( methodName ) ) {
+ wrapped = ProxyBuilder.buildDatabaseMetaData( ( DatabaseMetaData ) result, this, ( Connection ) proxy );
+ }
+ return wrapped;
+ }
+
private void explicitClose() {
- if ( valid ) {
+ if ( isValid() ) {
invalidateHandle();
}
}
@@ -183,7 +170,7 @@
private void invalidateHandle() {
log.trace( "Invalidating connection handle" );
logicalConnection = null;
- valid = false;
+ invalidate();
}
/**
@@ -206,12 +193,4 @@
log.info( "*** logical connection closed ***" );
invalidateHandle();
}
-
- public String toString() {
- return super.toString() + "[valid=" + valid + "]";
- }
-
- public int hashCode() {
- return hashCode;
- }
}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/DatabaseMetaDataProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/DatabaseMetaDataProxyHandler.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/DatabaseMetaDataProxyHandler.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,75 @@
+/*
+ * 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.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * The InvocationHandler for intercepting messages to {@link DatabaseMetaData} proxies.
+ * <p/>
+ * Mainly we need to intercept the methods defined on {@link DatabaseMetaData} which expose
+ * {@link java.sql.ResultSet} instances, which in turn expose {@link java.sql.Statement}
+ * instances, which in turn...
+ *
+ * @author Steve Ebersole
+ */
+public class DatabaseMetaDataProxyHandler extends AbstractProxyHandler {
+ private ConnectionProxyHandler connectionProxyHandler;
+ private Connection connectionProxy;
+ private DatabaseMetaData databaseMetaData;
+
+ public DatabaseMetaDataProxyHandler(DatabaseMetaData databaseMetaData, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy) {
+ super( databaseMetaData.hashCode() );
+ this.connectionProxyHandler = connectionProxyHandler;
+ this.connectionProxy = connectionProxy;
+ this.databaseMetaData = databaseMetaData;
+ }
+
+ protected Object continueInvocation(Object proxy, Method method, Object[] args) throws Throwable {
+ try {
+ boolean exposingResultSet = doesMethodExposeResultSet( method );
+
+ Object result = method.invoke( databaseMetaData, args );
+
+ if ( exposingResultSet ) {
+ result = ProxyBuilder.buildImplicitResultSet( ( ResultSet ) result, connectionProxyHandler, connectionProxy );
+ connectionProxyHandler.getJdbcContainer().register( ( ResultSet ) result );
+ }
+
+ return result;
+ }
+ catch ( InvocationTargetException e ) {
+ Throwable realException = e.getTargetException();
+ if ( SQLException.class.isInstance( realException ) ) {
+ throw connectionProxyHandler.getJdbcServices().getExceptionHelper()
+ .convert( ( SQLException ) realException, realException.getMessage() );
+ }
+ else {
+ throw realException;
+ }
+ }
+ }
+
+ protected boolean doesMethodExposeResultSet(Method method) {
+ return ResultSet.class.isAssignableFrom( method.getReturnType() );
+ }
+
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitResultSetProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitResultSetProxyHandler.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitResultSetProxyHandler.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -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.proxy;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.SQLException;
+
+import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.JDBCServices;
+
+/**
+ * ImplicitResultSetProxyHandler implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ImplicitResultSetProxyHandler extends AbstractResultSetProxyHandler {
+ private ConnectionProxyHandler connectionProxyHandler;
+ private Connection connectionProxy;
+ private Statement sourceStatement;
+
+ public ImplicitResultSetProxyHandler(ResultSet resultSet, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy) {
+ super( resultSet );
+ this.connectionProxyHandler = connectionProxyHandler;
+ this.connectionProxy = connectionProxy;
+ }
+
+ protected JDBCServices getJdbcServices() {
+ return connectionProxyHandler.getJdbcServices();
+ }
+
+ protected JDBCContainer getJdbcContainer() {
+ return connectionProxyHandler.getJdbcContainer();
+ }
+
+ protected Statement getExposeableStatement() {
+ if ( sourceStatement == null ) {
+ try {
+ Statement stmnt = getResultSet().getStatement();
+ sourceStatement = ProxyBuilder.buildImplicitStatement( stmnt, connectionProxyHandler, connectionProxy );
+ }
+ catch ( SQLException e ) {
+ throw getJdbcServices().getExceptionHelper().convert( e, e.getMessage() );
+ }
+ }
+ return sourceStatement;
+ }
+
+ protected void invalidateHandle() {
+ sourceStatement = null;
+ super.invalidateHandle();
+ }
+}
Added: sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitStatementProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitStatementProxyHandler.java (rev 0)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ImplicitStatementProxyHandler.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -0,0 +1,40 @@
+/*
+ * 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.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.Statement;
+
+import org.hibernate.HibernateException;
+
+/**
+ * ImplicitStatementProxyHandler implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ImplicitStatementProxyHandler extends AbstractStatementProxyHandler {
+ protected ImplicitStatementProxyHandler(Statement statement, ConnectionProxyHandler connectionProxyHandler, Connection connectionProxy) {
+ super( statement, connectionProxyHandler, connectionProxy );
+ }
+
+ protected void beginningInvocationHandling(Method method, Object[] args) {
+ // disallow executions...
+ if ( method.getName().startsWith( "execute" ) ) {
+ throw new HibernateException( "execution not allowed on implicit statement object" );
+ }
+ }
+}
Modified: 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 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyBuilder.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -18,6 +18,7 @@
import java.lang.reflect.Proxy;
import java.sql.CallableStatement;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
@@ -57,6 +58,7 @@
ResultSetWrapperImplementor.class
};
+ public static final Class[] METADATA_PROXY_INTERFACES = new Class[] { DatabaseMetaData.class };
public static Connection buildConnection(LogicalConnectionImplementor logicalConnection) {
ConnectionProxyHandler proxyHandler = new ConnectionProxyHandler( logicalConnection );
@@ -130,4 +132,40 @@
proxyHandler
);
}
+
+ public static DatabaseMetaData buildDatabaseMetaData(
+ DatabaseMetaData metaData,
+ ConnectionProxyHandler connectionProxyHandler,
+ Connection connectionProxy) {
+ DatabaseMetaDataProxyHandler handler = new DatabaseMetaDataProxyHandler( metaData, connectionProxyHandler, connectionProxy );
+ return ( DatabaseMetaData ) Proxy.newProxyInstance(
+ DatabaseMetaDataProxyHandler.class.getClassLoader(),
+ METADATA_PROXY_INTERFACES,
+ handler
+ );
+ }
+
+ public static ResultSet buildImplicitResultSet(
+ ResultSet resultSet,
+ ConnectionProxyHandler connectionProxyHandler,
+ Connection connectionProxy) {
+ ImplicitResultSetProxyHandler proxyHandler = new ImplicitResultSetProxyHandler( resultSet, connectionProxyHandler, connectionProxy );
+ return ( ResultSet ) Proxy.newProxyInstance(
+ ResultSetWrapperImplementor.class.getClassLoader(),
+ RESULTSET_PROXY_INTERFACES,
+ proxyHandler
+ );
+ }
+
+ public static Statement buildImplicitStatement(
+ Statement statement,
+ ConnectionProxyHandler connectionProxyHandler,
+ Connection connectionProxy) {
+ ImplicitStatementProxyHandler handler = new ImplicitStatementProxyHandler( statement, connectionProxyHandler, connectionProxy );
+ return ( Statement ) Proxy.newProxyInstance(
+ StatementWrapperImplementor.class.getClassLoader(),
+ STMNT_PROXY_INTERFACES,
+ handler
+ );
+ }
}
Deleted: 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 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ProxyJDBCContainer.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -1,57 +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.proxy;
-
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-import org.hibernate.jdbc.impl.BasicJDBCContainer;
-import org.hibernate.jdbc.impl.ResultSetWrapperImplementor;
-import org.hibernate.jdbc.impl.StatementWrapperImplementor;
-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/ResultSetProxyHandler.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxyHandler.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/main/java/org/hibernate/jdbc/proxy/ResultSetProxyHandler.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,17 +15,9 @@
*/
package org.hibernate.jdbc.proxy;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.sql.ResultSet;
-import java.sql.SQLException;
import java.sql.Statement;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.hibernate.HibernateException;
import org.hibernate.jdbc.JDBCContainer;
import org.hibernate.jdbc.JDBCServices;
@@ -34,44 +26,27 @@
*
* @author Steve Ebersole
*/
-public class ResultSetProxyHandler implements InvocationHandler {
- private static final Logger log = LoggerFactory.getLogger( ResultSetProxyHandler.class );
-
+public class ResultSetProxyHandler extends AbstractResultSetProxyHandler {
private AbstractStatementProxyHandler statementProxyHandler;
private Statement statementProxy;
- private ResultSet resultSet;
- private boolean valid = true;
- private final int hashCode;
public ResultSetProxyHandler(
ResultSet resultSet,
AbstractStatementProxyHandler statementProxyHandler,
Statement statementProxy) {
- this.resultSet = resultSet;
+ super( resultSet );
this.statementProxyHandler = statementProxyHandler;
this.statementProxy = statementProxy;
- this.hashCode = resultSet.hashCode();
}
- protected ResultSet getResultSet() {
- errorIfInvalid();
- return resultSet;
- }
-
- protected ResultSet getResultSetWithoutChecks() {
- return resultSet;
- }
-
- protected void errorIfInvalid() {
- if ( !valid ) {
- throw new HibernateException( "resultset handle is no longer valid" );
- }
- }
-
protected AbstractStatementProxyHandler getStatementProxy() {
return statementProxyHandler;
}
+ protected Statement getExposeableStatement() {
+ return statementProxy;
+ }
+
protected JDBCServices getJdbcServices() {
return getStatementProxy().getJdbcServices();
}
@@ -80,73 +55,8 @@
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 );
-
- // basic Object methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if ( "toString".equals( methodName ) ) {
- return this.toString();
- }
- if ( "equals".equals( methodName ) ) {
- return this.equals( args[0] );
- }
- if ( "hashCode".equals( methodName ) ) {
- return this.hashCode();
- }
-
- // other methods allowed while invalid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if ( "close".equals( methodName ) ) {
- explicitClose( ( ResultSet ) proxy );
- return null;
- }
- if ( "invalidate".equals( methodName ) ) {
- invalidateHandle();
- return null;
- }
-
- errorIfInvalid();
-
- if ( "getWrappedResultSet".equals( methodName ) ) {
- return getResultSetWithoutChecks();
- }
-
- if ( "getStatement".equals( methodName ) ) {
- return statementProxy;
- }
-
- try {
- return method.invoke( resultSet, args );
- }
- catch ( InvocationTargetException e ) {
- Throwable realException = e.getTargetException();
- if ( SQLException.class.isInstance( realException ) ) {
- throw getJdbcServices().getExceptionHelper()
- .convert( ( SQLException ) realException, realException.getMessage() );
- }
- else {
- throw realException;
- }
- }
- }
-
- private void explicitClose(ResultSet proxy) {
- if ( valid ) {
- statementProxyHandler.getJdbcContainer().release( proxy );
- }
- }
-
- private void invalidateHandle() {
+ protected void invalidateHandle() {
statementProxyHandler = null;
- resultSet = null;
- valid = false;
+ super.invalidateHandle();
}
-
- public String toString() {
- return super.toString() + "[valid=" + valid + "]";
- }
-
- public int hashCode() {
- return hashCode;
- }
}
Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/batch/TestingServiceImpl.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,17 +15,11 @@
*/
package org.hibernate.jdbc.batch;
-import java.sql.SQLException;
-
-import org.hibernate.cfg.Settings;
import org.hibernate.connection.ConnectionProvider;
-import org.hibernate.exception.SQLStateConverter;
-import org.hibernate.exception.ViolatedConstraintNameExtracter;
import org.hibernate.jdbc.ConnectionProviderBuilder;
-import org.hibernate.jdbc.JDBCContainer;
import org.hibernate.jdbc.JDBCContainerBuilder;
import org.hibernate.jdbc.JDBCServices;
-import org.hibernate.jdbc.proxy.ProxyJDBCContainer;
+import org.hibernate.jdbc.impl.BasicJDBCContainerBuilder;
import org.hibernate.jdbc.util.ExceptionHelper;
import org.hibernate.jdbc.util.SQLStatementLogger;
@@ -43,20 +37,8 @@
public void prepare(boolean allowAggressiveRelease) {
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
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 ProxyJDBCContainer( exceptionHelper );
- }
- };
+ exceptionHelper = new ExceptionHelper();
+ jdbcContainerBuilder = new BasicJDBCContainerBuilder( exceptionHelper );
}
public void release() {
Modified: sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/delegation/TestingServiceImpl.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -18,7 +18,7 @@
import org.hibernate.jdbc.JDBCServices;
import org.hibernate.jdbc.JDBCContainerBuilder;
import org.hibernate.jdbc.ConnectionProviderBuilder;
-import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.BasicJDBCContainerBuilder;
import org.hibernate.jdbc.util.SQLStatementLogger;
import org.hibernate.jdbc.util.ExceptionHelper;
import org.hibernate.connection.ConnectionProvider;
@@ -38,11 +38,7 @@
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
sqlStatementLogger = new SQLStatementLogger( true );
exceptionHelper = new ExceptionHelper();
- jdbcContainerBuilder = new JDBCContainerBuilder() {
- public JDBCContainer buildJdbcContainer() {
- return new DelegateJDBCContainer( exceptionHelper );
- }
- };
+ jdbcContainerBuilder = new BasicJDBCContainerBuilder( exceptionHelper );
}
public void release() {
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-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/impl/TestingServiceImpl.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -20,12 +20,9 @@
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
@@ -41,20 +38,8 @@
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 );
- }
- };
+ exceptionHelper = new ExceptionHelper();
+ jdbcContainerBuilder = new BasicJDBCContainerBuilder( 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-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/BasicConnectionProxyTest.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,24 +15,24 @@
*/
package org.hibernate.jdbc.proxy;
-import java.lang.reflect.Proxy;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.sql.PreparedStatement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.assertFalse;
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.ConnectionWrapper;
import org.hibernate.jdbc.impl.LogicalConnectionImpl;
/**
@@ -56,6 +56,30 @@
}
@Test
+ public void testDatabaseMetaDataHandling() throws Throwable {
+ LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
+ Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
+ try {
+ DatabaseMetaData metaData = proxiedConnection.getMetaData();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ ResultSet rs1 = metaData.getCatalogs();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ rs1.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ metaData.getCatalogs();
+ metaData.getSchemas();
+ assertTrue( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+ catch ( SQLException sqle ) {
+ fail( "incorrect exception type : sqlexception" );
+ }
+ finally {
+ logicalConnection.close();
+ assertFalse( logicalConnection.getJdbcContainer().hasRegisteredResources() );
+ }
+ }
+
+ @Test
public void testExceptionHandling() {
LogicalConnectionImpl logicalConnection = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
Connection proxiedConnection = ProxyBuilder.buildConnection( logicalConnection );
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-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/java/org/hibernate/jdbc/proxy/TestingServiceImpl.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -20,12 +20,10 @@
import org.hibernate.jdbc.JDBCServices;
import org.hibernate.jdbc.JDBCContainerBuilder;
import org.hibernate.jdbc.ConnectionProviderBuilder;
-import org.hibernate.jdbc.JDBCContainer;
+import org.hibernate.jdbc.impl.BasicJDBCContainerBuilder;
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
@@ -41,20 +39,8 @@
public void prepare(boolean allowAggressiveRelease) {
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
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 ProxyJDBCContainer( exceptionHelper );
- }
- };
+ exceptionHelper = new ExceptionHelper();
+ jdbcContainerBuilder = new BasicJDBCContainerBuilder( exceptionHelper );
}
public void release() {
Modified: sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -129,9 +129,6 @@
System.gc();
System.gc();
- Connection c;
- LogicalConnectionImpl lc;
-
// prime ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for ( int a = 0, Z = datums.length; a < Z; a++ ) {
Modified: sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java 2007-08-22 05:14:13 UTC (rev 13947)
+++ sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/TestingServiceImpl.java 2007-08-22 15:36:17 UTC (rev 13948)
@@ -15,14 +15,10 @@
*/
package org.hibernate.jdbc;
-import java.sql.SQLException;
-
-import org.hibernate.jdbc.proxy.ProxyJDBCContainer;
-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;
+import org.hibernate.jdbc.impl.BasicJDBCContainerBuilder;
+import org.hibernate.jdbc.util.ExceptionHelper;
+import org.hibernate.jdbc.util.SQLStatementLogger;
/**
* TestingServiceImpl implementation
@@ -38,20 +34,8 @@
public void prepare(boolean allowAggressiveRelease) {
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider( allowAggressiveRelease );
sqlStatementLogger = new SQLStatementLogger( false );
- exceptionHelper = new ExceptionHelper(
- new SQLStateConverter(
- new ViolatedConstraintNameExtracter() {
- public String extractConstraintName(SQLException e) {
- return null;
- }
- }
- )
- );
- jdbcContainerBuilder = new JDBCContainerBuilder() {
- public JDBCContainer buildJdbcContainer() {
- return new ProxyJDBCContainer( exceptionHelper );
- }
- };
+ exceptionHelper = new ExceptionHelper();
+ jdbcContainerBuilder = new BasicJDBCContainerBuilder( exceptionHelper );
}
public void release() {
16 years, 7 months