Author: hardy.ferentschik
Date: 2009-05-18 10:11:08 -0400 (Mon, 18 May 2009)
New Revision: 16588
Modified:
search/trunk/src/test/java/org/hibernate/search/test/session/MassIndexTest.java
search/trunk/src/test/java/org/hibernate/search/test/session/SessionTest.java
Log:
Resolved some test issues for PostgeSQL
Modified: search/trunk/src/test/java/org/hibernate/search/test/session/MassIndexTest.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/session/MassIndexTest.java 2009-05-18
13:21:37 UTC (rev 16587)
+++
search/trunk/src/test/java/org/hibernate/search/test/session/MassIndexTest.java 2009-05-18
14:11:08 UTC (rev 16588)
@@ -2,6 +2,7 @@
package org.hibernate.search.test.session;
import java.sql.Statement;
+import java.sql.SQLException;
import java.util.List;
import java.util.Iterator;
@@ -143,27 +144,27 @@
tx.commit();
s.close();
- s = openSession();
+ s = getSessionWithAutoCommit();
FullTextSession session = Search.getFullTextSession( s );
Query luceneQuery = new TermQuery( new Term( "categorie.nom",
"livre" ) );
List result = session.createFullTextQuery( luceneQuery, Entite.class ).list();
assertEquals( 1, result.size() );
s.close();
- s = openSession();
+ s = getSessionWithAutoCommit();
ent = (Entite) s.get( Entite.class, ent.getId() );
session = Search.getFullTextSession( s );
session.index( ent );
s.close();
- s = openSession();
+ s = getSessionWithAutoCommit();
session = Search.getFullTextSession( s );
luceneQuery = new TermQuery( new Term( "categorie.nom", "livre" )
);
result = session.createFullTextQuery( luceneQuery, Entite.class ).list();
assertEquals( "test lazy loading and indexing", 1, result.size() );
s.close();
- s = openSession();
+ s = getSessionWithAutoCommit();
Iterator it = s.createQuery( "from Entite where id = :id").setParameter(
"id", ent.getId() ).iterate();
session = Search.getFullTextSession( s );
while ( it.hasNext() ) {
@@ -172,19 +173,21 @@
}
s.close();
- s = openSession();
+ s = getSessionWithAutoCommit();
session = Search.getFullTextSession( s );
luceneQuery = new TermQuery( new Term( "categorie.nom", "livre" )
);
result = session.createFullTextQuery( luceneQuery, Entite.class ).list();
assertEquals( "test lazy loading and indexing", 1, result.size() );
- ent = (Entite) result.get( 0 );
- cat = ent.getCategorie();
- ent.setCategorie( null );
- session.delete( cat );
- session.delete( ent );
s.close();
}
+ private Session getSessionWithAutoCommit() throws SQLException {
+ Session s;
+ s = openSession();
+ s.connection().setAutoCommit( true );
+ return s;
+ }
+
protected void configure(org.hibernate.cfg.Configuration cfg) {
super.configure( cfg );
cfg.setProperty( "hibernate.search.worker.batch_size", "5" );
Modified: search/trunk/src/test/java/org/hibernate/search/test/session/SessionTest.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/session/SessionTest.java 2009-05-18
13:21:37 UTC (rev 16587)
+++
search/trunk/src/test/java/org/hibernate/search/test/session/SessionTest.java 2009-05-18
14:11:08 UTC (rev 16588)
@@ -2,14 +2,14 @@
package org.hibernate.search.test.session;
import java.lang.reflect.Proxy;
-import java.util.List;
-import org.hibernate.search.test.SearchTestCase;
-import org.hibernate.search.Search;
-import org.hibernate.search.FullTextSession;
+import org.hibernate.Criteria;
import org.hibernate.Session;
-import org.hibernate.Criteria;
+import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.DetachedCriteria;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.test.SearchTestCase;
/**
* @author Emmanuel Bernard
@@ -18,39 +18,39 @@
private static final Class[] SESS_PROXY_INTERFACES = new Class[] {
org.hibernate.classic.Session.class,
- org.hibernate.engine.SessionImplementor.class,
- org.hibernate.jdbc.JDBCContext.Context.class,
- org.hibernate.event.EventSource.class
+ org.hibernate.engine.SessionImplementor.class,
+ org.hibernate.jdbc.JDBCContext.Context.class,
+ org.hibernate.event.EventSource.class
};
public void testSessionWrapper() throws Exception {
- Session s = openSession( );
+ Session s = openSession();
DelegationWrapper wrapper = new DelegationWrapper( s );
- Session wrapped = (Session) Proxy.newProxyInstance(
+ Session wrapped = ( Session ) Proxy.newProxyInstance(
org.hibernate.classic.Session.class.getClassLoader(),
- SESS_PROXY_INTERFACES,
- wrapper
- );
+ SESS_PROXY_INTERFACES,
+ wrapper
+ );
try {
Search.getFullTextSession( wrapped );
}
- catch( ClassCastException e ) {
- e.printStackTrace( );
- fail(e.toString());
+ catch ( ClassCastException e ) {
+ e.printStackTrace();
+ fail( e.toString() );
}
wrapped.close();
}
public void testDetachedCriteria() throws Exception {
- FullTextSession s = Search.getFullTextSession( openSession( ) );
+ FullTextSession s = Search.getFullTextSession( openSession() );
DetachedCriteria dc = DetachedCriteria.forClass( Email.class );
try {
Criteria c = dc.getExecutableCriteria( s ).setMaxResults( 10 );
- List results = c.list();
+ c.list();
}
- catch( ClassCastException e ) {
- e.printStackTrace( );
- fail(e.toString());
+ catch ( ClassCastException e ) {
+ e.printStackTrace();
+ fail( e.toString() );
}
s.close();
}
@@ -61,4 +61,11 @@
Domain.class
};
}
+
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+ // for this test we explcitly set the auto commit mode since we are not explcitly
starting a transaction
+ // which could be a problem in some databases.
+ cfg.setProperty( "hibernate.connection.autocommit", "true" );
+ }
}