Hibernate SVN: r11533 - in trunk/HibernateExt/search/src: java/org/hibernate/search/bridge/builtin and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-05-17 15:19:25 -0400 (Thu, 17 May 2007)
New Revision: 11533
Added:
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java
trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/builtin/BooleanBridge.java
trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/builtin/EnumBridge.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentBuilder.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentExtractor.java
trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Author.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java
Log:
HSEARCH-53 support for projection (ie load data from the index only)
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java 2007-05-16 23:48:00 UTC (rev 11532)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java 2007-05-17 19:19:25 UTC (rev 11533)
@@ -41,9 +41,22 @@
* Defines the Database Query used to load the Lucene results.
* Useful to load a given object graph by refining the fetch modes
*
- * No projection allowed, the root entity must be the only returned type
+ * No projection (criteria.setProjection() ) allowed, the root entity must be the only returned type
* No where restriction can be defined either.
*
*/
FullTextQuery setCriteriaQuery(Criteria criteria);
+
+ /**
+ * Defines the Lucene field names projected and returned in a query result
+ * Each field is converted back to it's object representation, an Object[] being returned for each "row"
+ * (similar to an HQL or a Criteria API projection).
+ *
+ * A projectable field must be stored in the Lucene index and use a {@link org.hibernate.search.bridge.TwoWayFieldBridge}
+ * Unless notified in their JavaDoc, all built-in bridges are two-way. All @DocumentId fields are projectable by design.
+ *
+ * If the projected field is not a projectable field, null is returned in the object[]
+ *
+ */
+ FullTextQuery setProjection(String... fields);
}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/builtin/BooleanBridge.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/builtin/BooleanBridge.java 2007-05-16 23:48:00 UTC (rev 11532)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/builtin/BooleanBridge.java 2007-05-17 19:19:25 UTC (rev 11533)
@@ -2,6 +2,7 @@
package org.hibernate.search.bridge.builtin;
import org.hibernate.search.bridge.TwoWayStringBridge;
+import org.hibernate.annotations.common.util.StringHelper;
/**
@@ -12,6 +13,7 @@
public class BooleanBridge implements TwoWayStringBridge {
public Boolean stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty(stringValue) ) return null;
return Boolean.valueOf( stringValue );
}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/builtin/EnumBridge.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/builtin/EnumBridge.java 2007-05-16 23:48:00 UTC (rev 11532)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/builtin/EnumBridge.java 2007-05-17 19:19:25 UTC (rev 11533)
@@ -2,6 +2,7 @@
package org.hibernate.search.bridge.builtin;
import org.hibernate.search.bridge.TwoWayStringBridge;
+import org.hibernate.annotations.common.util.StringHelper;
/**
@@ -21,6 +22,7 @@
}
public Enum<? extends Enum> stringToObject(String stringValue) {
+ if ( StringHelper.isEmpty( stringValue ) ) return null;
return Enum.valueOf( clazz, stringValue );
}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-05-16 23:48:00 UTC (rev 11532)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-05-17 19:19:25 UTC (rev 11533)
@@ -10,6 +10,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -533,6 +534,70 @@
return (Serializable) builder.getIdBridge().get( builder.getIdKeywordName(), document );
}
+ public static Object[] getDocumentFields(SearchFactory searchFactory, Class clazz, Document document, String[] fields) {
+ DocumentBuilder builder = searchFactory.getDocumentBuilders().get( clazz );
+ if ( builder == null ) throw new SearchException( "No Lucene configuration set up for: " + clazz.getName() );
+ final int fieldNbr = fields.length;
+ Object[] result = new Object[fieldNbr];
+
+ if ( builder.idKeywordName != null ) {
+ populateResult(builder.idKeywordName, builder.idBridge, Field.Store.YES, fields, result, document);
+ }
+
+ final PropertiesMetadata metadata = builder.rootPropertiesMetadata;
+ processFieldsForProjection( metadata, fields, result, document );
+ return result;
+ }
+
+ private static void processFieldsForProjection(PropertiesMetadata metadata, String[] fields, Object[] result, Document document) {
+ final int nbrFoEntityFields = metadata.fieldNames.size();
+ for (int index = 0 ; index < nbrFoEntityFields; index++ ) {
+ populateResult( metadata.fieldNames.get(index),
+ metadata.fieldBridges.get(index),
+ metadata.fieldStore.get(index),
+ fields,
+ result,
+ document
+ );
+ }
+ final int nbrOfEmbeddedObjects = metadata.embeddedPropertiesMetadata.size();
+ for (int index = 0 ; index < nbrOfEmbeddedObjects ; index++) {
+ //there is nothing we can do for collections
+ if ( metadata.embeddedContainers.get(index) == PropertiesMetadata.Container.OBJECT) {
+ processFieldsForProjection( metadata.embeddedPropertiesMetadata.get(index), fields, result, document );
+ }
+ }
+ }
+
+ private static void populateResult(String fieldName, FieldBridge fieldBridge, Field.Store store,
+ String[] fields, Object[] result, Document document) {
+ int matchingPosition = getFieldPosition( fields, fieldName );
+ if (matchingPosition != -1) {
+ //TODO make use of an isTwoWay() method
+ if ( store != Field.Store.NO && TwoWayFieldBridge.class.isAssignableFrom( fieldBridge.getClass() ) ) {
+ result[matchingPosition] = ( (TwoWayFieldBridge) fieldBridge ).get( fieldName, document );
+ if ( log.isTraceEnabled() ) {
+ log.trace( "Field " + fieldName + " projected as " + result[matchingPosition] );
+ }
+ }
+ else {
+ //FIXME else exception?
+ if ( log.isTraceEnabled() ) {
+ log.trace( "Field " + fieldName + " not projected: Store = " + store + " and isTwoWay = "
+ + TwoWayFieldBridge.class.isAssignableFrom( fieldBridge.getClass() ) );
+ }
+ }
+ }
+ }
+
+ private static int getFieldPosition(String[] fields, String fieldName) {
+ int fieldNbr = fields.length;
+ for (int index = 0 ; index < fieldNbr ; index++) {
+ if ( fieldName.equals( fields[index] ) ) return index;
+ }
+ return -1;
+ }
+
public void postInitialize(Set<Class> indexedClasses) {
//this method does not requires synchronization
Class plainClass = reflectionManager.toClass( beanClass );
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentExtractor.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentExtractor.java 2007-05-16 23:48:00 UTC (rev 11532)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentExtractor.java 2007-05-17 19:19:25 UTC (rev 11533)
@@ -10,14 +10,20 @@
*/
public class DocumentExtractor {
private SearchFactory searchFactory;
- public DocumentExtractor(SearchFactory searchFactory) {
+ private String[] projection;
+
+ public DocumentExtractor(SearchFactory searchFactory, String... projection) {
this.searchFactory = searchFactory;
+ this.projection = projection;
}
- public EntityInfo extract(Document document, String... fields) {
+ public EntityInfo extract(Document document) {
EntityInfo entityInfo = new EntityInfo();
entityInfo.clazz = DocumentBuilder.getDocumentClass( document );
entityInfo.id = DocumentBuilder.getDocumentId( searchFactory, entityInfo.clazz, document );
+ if (projection != null && projection.length > 0) {
+ entityInfo.projection = DocumentBuilder.getDocumentFields( searchFactory, entityInfo.clazz, document, projection );
+ }
//TODO read fields
return entityInfo;
}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-05-16 23:48:00 UTC (rev 11532)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-05-17 19:19:25 UTC (rev 11533)
@@ -45,6 +45,7 @@
import org.hibernate.search.engine.ObjectLoader;
import org.hibernate.search.engine.QueryLoader;
import org.hibernate.search.engine.EntityInfo;
+import org.hibernate.search.engine.ProjectionLoader;
import org.hibernate.search.util.ContextHelper;
/**
@@ -64,6 +65,7 @@
private Integer resultSize;
private Sort sort;
private Criteria criteria;
+ private String[] projection;
/**
* classes must be immutable
@@ -105,7 +107,7 @@
Session sess = (Session) this.session;
List<EntityInfo> entityInfos = new ArrayList<EntityInfo>( max - first + 1 );
- DocumentExtractor extractor = new DocumentExtractor( searchFactory );
+ DocumentExtractor extractor = new DocumentExtractor( searchFactory, projection );
for ( int index = first; index <= max; index++ ) {
Document document = hits.doc( index );
entityInfos.add( extractor.extract( document ) );
@@ -127,6 +129,11 @@
}
private Loader getLoader(Session session, SearchFactory searchFactory) {
+ if (projection != null) {
+ ProjectionLoader loader = new ProjectionLoader();
+ loader.init( session, searchFactory );
+ return loader;
+ }
if (criteria != null) {
if (classes.length > 1) throw new SearchException("Cannot mix criteria and multiple entity types");
if ( criteria instanceof CriteriaImpl ) {
@@ -175,7 +182,7 @@
hits = getHits( searcher );
int first = first();
int max = max( first, hits );
- DocumentExtractor extractor = new DocumentExtractor( searchFactory );
+ DocumentExtractor extractor = new DocumentExtractor( searchFactory, projection );
Loader loader = getLoader( (Session) this.session, searchFactory );
return new ScrollableResultsImpl( searcher, hits, first, max, extractor, loader);
}
@@ -208,7 +215,7 @@
int max = max( first, hits );
Session sess = (Session) this.session;
List<EntityInfo> infos = new ArrayList<EntityInfo>( max - first + 1 );
- DocumentExtractor extractor = new DocumentExtractor( searchFactory );
+ DocumentExtractor extractor = new DocumentExtractor( searchFactory, projection );
for ( int index = first; index <= max; index++ ) {
Document document = hits.doc( index );
infos.add( extractor.extract( document ) );
@@ -383,6 +390,16 @@
return this;
}
+ public FullTextQuery setProjection(String... fields) {
+ if ( fields == null || fields.length == 0) {
+ this.projection = null;
+ }
+ else {
+ this.projection = fields;
+ }
+ return this;
+ }
+
public FullTextQuery setFirstResult(int firstResult) {
this.firstResult = firstResult;
return this;
Modified: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Author.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Author.java 2007-05-16 23:48:00 UTC (rev 11532)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Author.java 2007-05-17 19:19:25 UTC (rev 11533)
@@ -5,6 +5,10 @@
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Store;
+import org.hibernate.search.annotations.Index;
+
/**
* @author Emmanuel Bernard
*/
@@ -21,6 +25,7 @@
this.id = id;
}
+ @Field(index = Index.TOKENIZED, store = Store.YES)
public String getName() {
return name;
}
Modified: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java 2007-05-16 23:48:00 UTC (rev 11532)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java 2007-05-17 19:19:25 UTC (rev 11533)
@@ -6,11 +6,16 @@
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Text;
import org.hibernate.search.annotations.Keyword;
import org.hibernate.search.annotations.Unstored;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Store;
+import org.hibernate.search.annotations.IndexedEmbedded;
/**
* @author Emmanuel Bernard
@@ -23,7 +28,18 @@
private String body;
private String summary;
private Set<Author> authors = new HashSet<Author>();
+ private Author mainAuthor;
+ @IndexedEmbedded
+ @ManyToOne
+ public Author getMainAuthor() {
+ return mainAuthor;
+ }
+
+ public void setMainAuthor(Author mainAuthor) {
+ this.mainAuthor = mainAuthor;
+ }
+
@ManyToMany
public Set<Author> getAuthors() {
return authors;
@@ -60,7 +76,7 @@
this.id = id;
}
- @Text
+ @Field(index = Index.TOKENIZED, store = Store.YES)
public String getSummary() {
return summary;
}
Added: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java (rev 0)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java 2007-05-17 19:19:25 UTC (rev 11533)
@@ -0,0 +1,74 @@
+//$Id: $
+package org.hibernate.search.test.query;
+
+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.SearchTestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ProjectionQueryTest extends SearchTestCase {
+
+ public void testProjection() throws Exception {
+ FullTextSession s = Search.createFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ 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 );
+ Author emmanuel = new Author();
+ emmanuel.setName( "Emmanuel" );
+ s.save( emmanuel );
+ book.setMainAuthor(emmanuel);
+ tx.commit();
+ s.clear();
+ tx = s.beginTransaction();
+ QueryParser parser = new QueryParser( "title", new StopAnalyzer() );
+
+ Query query = parser.parse( "summary:Festina" );
+ org.hibernate.search.FullTextQuery hibQuery = s.createFullTextQuery( query, Book.class );
+ hibQuery.setProjection( "id", "summary", "body", "mainAuthor.name");
+
+ List result = hibQuery.list();
+ assertNotNull( result );
+ assertEquals( "Query with no explicit criteria", 1, result.size() );
+ Object[] projection = (Object[]) result.get( 0 );
+ assertEquals( "id", 1, projection[0] );
+ assertEquals( "summary", "La chute de la petite reine a travers les yeux de Festina", projection[1] );
+ assertEquals( "body should be null (non projectable)", null, projection[2] );
+ assertEquals( "mainAuthor.name (embedded objects)", "Emmanuel", projection[3] );
+
+ hibQuery = s.createFullTextQuery( query, Book.class );
+ hibQuery.setProjection();
+ result = hibQuery.list();
+ assertNotNull( result );
+ assertEquals( 1, result.size() );
+ assertTrue( "Should not trigger projection", result.get(0) instanceof Book);
+
+ hibQuery = s.createFullTextQuery( query, Book.class );
+ hibQuery.setProjection(null);
+ result = hibQuery.list();
+ assertNotNull( result );
+ assertEquals( 1, result.size() );
+ assertTrue( "Should not trigger projection", result.get(0) instanceof Book);
+
+ //cleanup
+ for (Object element : s.createQuery( "from " + Book.class.getName() ).list()) s.delete( element );
+ for (Object element : s.createQuery( "from " + Author.class.getName() ).list()) s.delete( element );
+ tx.commit();
+ s.close();
+ }
+
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ Book.class,
+ Author.class
+ };
+ }
+}
16 years, 11 months
Hibernate SVN: r11532 - in trunk/HibernateExt/search/src: java/org/hibernate/search/engine and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-05-16 19:48:00 -0400 (Wed, 16 May 2007)
New Revision: 11532
Added:
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Author.java
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java
trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
Log:
HSEARCH-52 support injection of the criteria query used to load the objects
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java 2007-05-16 22:25:22 UTC (rev 11531)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java 2007-05-16 23:48:00 UTC (rev 11532)
@@ -3,6 +3,7 @@
import org.apache.lucene.search.Sort;
import org.hibernate.Query;
+import org.hibernate.Criteria;
/**
* The base interface for lucene powered searches.
@@ -35,4 +36,14 @@
* not in sync with the database at the time of query.
*/
int resultSize();
+
+ /**
+ * Defines the Database Query used to load the Lucene results.
+ * Useful to load a given object graph by refining the fetch modes
+ *
+ * No projection allowed, the root entity must be the only returned type
+ * No where restriction can be defined either.
+ *
+ */
+ FullTextQuery setCriteriaQuery(Criteria criteria);
}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java 2007-05-16 22:25:22 UTC (rev 11531)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java 2007-05-16 23:48:00 UTC (rev 11532)
@@ -26,6 +26,7 @@
private Session session;
private Class entityType;
private SearchFactory searchFactory;
+ private Criteria criteria;
public void init(Session session, SearchFactory searchFactory) {
this.session = session;
@@ -46,7 +47,7 @@
final int maxResults = entityInfos.length;
if ( maxResults == 0) return EMPTY_LIST;
if (entityType == null) throw new AssertionFailure("EntityType not defined");
- Criteria criteria = session.createCriteria( entityType );
+ if (criteria == null) criteria = session.createCriteria( entityType );
DocumentBuilder builder = searchFactory.getDocumentBuilders().get( entityType );
String idName = builder.getIdentifierName();
@@ -80,4 +81,8 @@
}
return result;
}
+
+ public void setCriteria(Criteria criteria) {
+ this.criteria = criteria;
+ }
}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-05-16 22:25:22 UTC (rev 11531)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-05-16 23:48:00 UTC (rev 11532)
@@ -29,11 +29,16 @@
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
+import org.hibernate.Criteria;
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.annotations.common.AssertionFailure;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.query.ParameterMetadata;
import org.hibernate.impl.AbstractQueryImpl;
+import org.hibernate.impl.CriteriaImpl;
import org.hibernate.search.SearchFactory;
import org.hibernate.search.FullTextQuery;
+import org.hibernate.search.SearchException;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.engine.DocumentExtractor;
import org.hibernate.search.engine.Loader;
@@ -58,19 +63,8 @@
private Integer maxResults;
private Integer resultSize;
private Sort sort;
- private static Loader noLoader = new Loader() {
- public void init(Session session, SearchFactory searchFactory) {
- }
+ private Criteria criteria;
- public Object load(EntityInfo entityInfo) {
- throw new UnsupportedOperationException( "noLoader should not be used" );
- }
-
- public List load(EntityInfo... entityInfos) {
- throw new UnsupportedOperationException( "noLoader should not be used" );
- }
- };
-
/**
* classes must be immutable
*/
@@ -133,12 +127,35 @@
}
private Loader getLoader(Session session, SearchFactory searchFactory) {
- if (classes.length == 1) {
+ if (criteria != null) {
+ if (classes.length > 1) throw new SearchException("Cannot mix criteria and multiple entity types");
+ if ( criteria instanceof CriteriaImpl ) {
+ String targetEntity = ( (CriteriaImpl) criteria).getEntityOrClassName();
+ if ( classes.length == 1 && !classes[0].getName().equals( targetEntity ) ) {
+ throw new SearchException("Criteria query entity should match query entity");
+ }
+ else {
+ try {
+ Class entityType = ReflectHelper.classForName( targetEntity );
+ classes = new Class[] { entityType };
+ }
+ catch (ClassNotFoundException e) {
+ throw new SearchException("Unable to load entity class from criteria: " + targetEntity, e);
+ }
+ }
+ }
QueryLoader loader = new QueryLoader();
loader.init( session, searchFactory );
loader.setEntityType( classes[0] );
+ loader.setCriteria(criteria);
return loader;
}
+ else if (classes.length == 1) {
+ QueryLoader loader = new QueryLoader();
+ loader.init( session, searchFactory );
+ loader.setEntityType( classes[0] );
+ return loader;
+ }
else {
final ObjectLoader objectLoader = new ObjectLoader();
objectLoader.init( session, searchFactory );
@@ -361,6 +378,11 @@
return this.resultSize;
}
+ public FullTextQuery setCriteriaQuery(Criteria criteria) {
+ this.criteria = criteria;
+ return this;
+ }
+
public FullTextQuery setFirstResult(int firstResult) {
this.firstResult = firstResult;
return this;
@@ -382,4 +404,17 @@
protected Map getLockModes() {
return null;
}
+
+ private static Loader noLoader = new Loader() {
+ public void init(Session session, SearchFactory searchFactory) {
+ }
+
+ public Object load(EntityInfo entityInfo) {
+ throw new UnsupportedOperationException( "noLoader should not be used" );
+ }
+
+ public List load(EntityInfo... entityInfos) {
+ throw new UnsupportedOperationException( "noLoader should not be used" );
+ }
+ };
}
Added: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Author.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Author.java (rev 0)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Author.java 2007-05-16 23:48:00 UTC (rev 11532)
@@ -0,0 +1,31 @@
+//$Id: $
+package org.hibernate.search.test.query;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Author {
+ @Id @GeneratedValue private Integer id;
+ private String name;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Modified: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java 2007-05-16 22:25:22 UTC (rev 11531)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/Book.java 2007-05-16 23:48:00 UTC (rev 11532)
@@ -1,8 +1,11 @@
//$Id: $
package org.hibernate.search.test.query;
+import java.util.Set;
+import java.util.HashSet;
import javax.persistence.Entity;
import javax.persistence.Id;
+import javax.persistence.ManyToMany;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Text;
@@ -19,7 +22,17 @@
private Integer id;
private String body;
private String summary;
+ private Set<Author> authors = new HashSet<Author>();
+ @ManyToMany
+ public Set<Author> getAuthors() {
+ return authors;
+ }
+
+ public void setAuthors(Set<Author> authors) {
+ this.authors = authors;
+ }
+
public Book() {
}
Modified: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java 2007-05-16 22:25:22 UTC (rev 11531)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java 2007-05-16 23:48:00 UTC (rev 11532)
@@ -94,7 +94,8 @@
return new Class[] {
Book.class,
AlternateBook.class,
- Clock.class
+ Clock.class,
+ Author.class
};
}
}
Modified: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2007-05-16 22:25:22 UTC (rev 11531)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2007-05-16 23:48:00 UTC (rev 11532)
@@ -11,6 +11,7 @@
import org.hibernate.Transaction;
import org.hibernate.Hibernate;
import org.hibernate.ScrollableResults;
+import org.hibernate.FetchMode;
import org.hibernate.stat.Statistics;
import org.apache.lucene.search.Query;
import org.apache.lucene.queryParser.QueryParser;
@@ -304,12 +305,52 @@
s.close();
}
+ public void testCriteria() throws Exception {
+ FullTextSession s = Search.createFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ 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 );
+ Author emmanuel = new Author();
+ emmanuel.setName("Emmanuel");
+ s.save( emmanuel );
+ book.getAuthors().add(emmanuel);
+ tx.commit();
+ s.clear();
+ tx = s.beginTransaction();
+ QueryParser parser = new QueryParser( "title", new StopAnalyzer() );
+ Query query = parser.parse( "summary:Festina" );
+ org.hibernate.Query hibQuery = s.createFullTextQuery( query, Book.class );
+ List result = hibQuery.list();
+ assertNotNull( result );
+ assertEquals( "Query with no explicit criteria", 1, result.size() );
+ book = (Book) result.get(0);
+ assertFalse( "Association should not be inintialized", Hibernate.isInitialized( book.getAuthors() ) );
+
+ result = s.createFullTextQuery( query ).setCriteriaQuery(
+ s.createCriteria( Book.class ).setFetchMode( "authors", FetchMode.JOIN ) ).list();
+ assertNotNull( result );
+ assertEquals( "Query with explicit criteria", 1, result.size() );
+ book = (Book) result.get(0);
+ assertTrue( "Association should be inintialized", Hibernate.isInitialized( book.getAuthors() ) );
+ assertEquals( 1, book.getAuthors().size() );
+
+ //cleanup
+ Author author = book.getAuthors().iterator().next();
+ book.getAuthors().remove( author );
+
+ 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
+ Clock.class,
+ Author.class
};
}
}
16 years, 11 months
Hibernate SVN: r11531 - in trunk/HibernateExt/search/src: java/org/hibernate/search/engine and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-05-16 18:25:22 -0400 (Wed, 16 May 2007)
New Revision: 11531
Added:
trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentExtractor.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/EntityInfo.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/Loader.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/ObjectLoader.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/ProjectionLoader.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java
Removed:
trunk/HibernateExt/search/src/java/org/hibernate/search/query/EntityInfo.java
trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQuery.java
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextSession.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentBuilder.java
trunk/HibernateExt/search/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
trunk/HibernateExt/search/src/java/org/hibernate/search/query/IteratorImpl.java
trunk/HibernateExt/search/src/java/org/hibernate/search/query/ScrollableResultsImpl.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
Log:
HSEARCH-51 Use where id in (...) rather than the load() then initialize approach
Copied: trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java (from rev 11519, trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQuery.java)
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java (rev 0)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextQuery.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -0,0 +1,38 @@
+//$Id: $
+package org.hibernate.search;
+
+import org.apache.lucene.search.Sort;
+import org.hibernate.Query;
+
+/**
+ * The base interface for lucene powered searches.
+ *
+ * @author Hardy Ferentschik
+ */
+//TODO return FullTextQuery rather than Query in useful chain methods
+public interface FullTextQuery extends Query {
+ //todo Determine what other lucene specific features to expose via this
+ // interface. Maybe we should give access to the underlying lucene hit
+ // objects?
+
+ /**
+ * Allows to let lucene sort the results. This is useful when you have
+ * additional sort requirements on top of the default lucene ranking.
+ * Without lucene sorting you would have to retrieve the full result set and
+ * order the hibernate objects.
+ *
+ * @param sort The lucene sort object.
+ * @return this for method chaining
+ */
+ FullTextQuery setSort(Sort sort);
+
+ /**
+ * Returns the number of hits for this search
+ *
+ * Caution:
+ * The number of results might be slightly different from
+ * <code>list().size()</code> because list() if the index is
+ * not in sync with the database at the time of query.
+ */
+ int resultSize();
+}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextSession.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextSession.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/FullTextSession.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -2,8 +2,7 @@
package org.hibernate.search;
import org.hibernate.classic.Session;
-import org.hibernate.Query;
-import org.hibernate.search.query.FullTextQuery;
+import org.hibernate.search.FullTextQuery;
/**
* Extends the Hibernate {@link Session} with Full text search and indexing capabilities
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentBuilder.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -19,12 +19,12 @@
import org.apache.lucene.index.Term;
import org.hibernate.Hibernate;
import org.hibernate.annotations.common.AssertionFailure;
-import org.hibernate.annotations.common.util.ReflectHelper;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XAnnotatedElement;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XMember;
import org.hibernate.annotations.common.reflection.XProperty;
+import org.hibernate.annotations.common.util.ReflectHelper;
import org.hibernate.search.SearchException;
import org.hibernate.search.SearchFactory;
import org.hibernate.search.annotations.Boost;
@@ -109,6 +109,10 @@
}
}
+ public String getIdentifierName() {
+ return idGetter.getName();
+ }
+
private void initializeMember(XProperty member, PropertiesMetadata propertiesMetadata, boolean isRoot,
String prefix, Set<XClass> processedClasses) {
Keyword keywordAnn = member.getAnnotation( Keyword.class );
Added: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentExtractor.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentExtractor.java (rev 0)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/DocumentExtractor.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.search.engine;
+
+import org.apache.lucene.document.Document;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.engine.EntityInfo;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class DocumentExtractor {
+ private SearchFactory searchFactory;
+ public DocumentExtractor(SearchFactory searchFactory) {
+ this.searchFactory = searchFactory;
+ }
+
+ public EntityInfo extract(Document document, String... fields) {
+ EntityInfo entityInfo = new EntityInfo();
+ entityInfo.clazz = DocumentBuilder.getDocumentClass( document );
+ entityInfo.id = DocumentBuilder.getDocumentId( searchFactory, entityInfo.clazz, document );
+ //TODO read fields
+ return entityInfo;
+ }
+}
Copied: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/EntityInfo.java (from rev 11296, trunk/HibernateExt/search/src/java/org/hibernate/search/query/EntityInfo.java)
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/EntityInfo.java (rev 0)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/EntityInfo.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -0,0 +1,15 @@
+//$Id: $
+package org.hibernate.search.engine;
+
+import java.io.Serializable;
+
+/**
+ *
+ * @author Emmanuel Bernard
+ */
+//Move to egine?
+public class EntityInfo {
+ public Class clazz;
+ public Serializable id;
+ public Object[] projection;
+}
Added: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/Loader.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/Loader.java (rev 0)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/Loader.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -0,0 +1,17 @@
+//$Id: $
+package org.hibernate.search.engine;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.engine.EntityInfo;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public interface Loader {
+ void init(Session session, SearchFactory searchFactory);
+ Object load(EntityInfo entityInfo);
+ List load(EntityInfo... entityInfos);
+}
Added: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/ObjectLoader.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/ObjectLoader.java (rev 0)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/ObjectLoader.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -0,0 +1,50 @@
+//$Id: $
+package org.hibernate.search.engine;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.Hibernate;
+import org.hibernate.ObjectNotFoundException;
+import org.hibernate.Session;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.engine.EntityInfo;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ObjectLoader implements Loader {
+ private static final Log log = LogFactory.getLog( ObjectLoader.class );
+ private Session session;
+
+ public void init(Session session, SearchFactory searchFactory) {
+ this.session = session;
+ }
+
+ public Object load(EntityInfo entityInfo) {
+ return session.get( entityInfo.clazz, entityInfo.id );
+ }
+
+ public List load(EntityInfo... entityInfos) {
+ //use load to benefit from the batch-size
+ //we don't face proxy casting issues since the exact class is extracted from the index
+ for (EntityInfo entityInfo : entityInfos) {
+ session.load( entityInfo.clazz, entityInfo.id );
+ }
+ List result = new ArrayList(entityInfos.length);
+ for (EntityInfo entityInfo : entityInfos) {
+ try {
+ Object entity = session.load( entityInfo.clazz, entityInfo.id );
+ Hibernate.initialize( entity );
+ result.add( entity );
+ }
+ catch (ObjectNotFoundException e) {
+ log.debug( "Object found in Search index but not in database: "
+ + e.getEntityName() + " wih id " + e.getIdentifier() );
+ }
+ }
+ return result;
+ }
+}
Added: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/ProjectionLoader.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/ProjectionLoader.java (rev 0)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/ProjectionLoader.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -0,0 +1,29 @@
+//$Id: $
+package org.hibernate.search.engine;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.engine.EntityInfo;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ProjectionLoader implements Loader {
+ public void init(Session session, SearchFactory searchFactory) {
+ }
+
+ public Object load(EntityInfo entityInfo) {
+ return entityInfo.projection;
+ }
+
+ public List load(EntityInfo... entityInfos) {
+ List results = new ArrayList(entityInfos.length);
+ for (EntityInfo entityInfo : entityInfos) {
+ results.add( entityInfo.projection );
+ }
+ return results;
+ }
+}
Added: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java (rev 0)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/engine/QueryLoader.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -0,0 +1,83 @@
+//$Id: $
+package org.hibernate.search.engine;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.Hibernate;
+import org.hibernate.annotations.common.AssertionFailure;
+import org.hibernate.criterion.Disjunction;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.engine.EntityInfo;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class QueryLoader implements Loader {
+ private static final Log log = LogFactory.getLog( QueryLoader.class );
+ private static final int MAX_IN_CLAUSE = 500;
+ private static final List EMPTY_LIST = new ArrayList(0);
+
+ private Session session;
+ private Class entityType;
+ private SearchFactory searchFactory;
+
+ public void init(Session session, SearchFactory searchFactory) {
+ this.session = session;
+ this.searchFactory = searchFactory;
+ }
+
+ public void setEntityType(Class entityType) {
+ this.entityType = entityType;
+ }
+
+
+
+ public Object load(EntityInfo entityInfo) {
+ return session.get( entityInfo.clazz, entityInfo.id );
+ }
+
+ public List load(EntityInfo... entityInfos) {
+ final int maxResults = entityInfos.length;
+ if ( maxResults == 0) return EMPTY_LIST;
+ if (entityType == null) throw new AssertionFailure("EntityType not defined");
+ Criteria criteria = session.createCriteria( entityType );
+
+ DocumentBuilder builder = searchFactory.getDocumentBuilders().get( entityType );
+ String idName = builder.getIdentifierName();
+ int loop = maxResults / MAX_IN_CLAUSE;
+ boolean exact = maxResults % MAX_IN_CLAUSE == 0;
+ if (!exact) loop++;
+ Disjunction disjunction = Restrictions.disjunction();
+ for (int index = 0 ; index < loop ; index++) {
+ int max = index*MAX_IN_CLAUSE + MAX_IN_CLAUSE <= maxResults ?
+ index*MAX_IN_CLAUSE + MAX_IN_CLAUSE :
+ maxResults;
+ List ids = new ArrayList(max - index*MAX_IN_CLAUSE);
+ for (int entityInfoIndex = index * MAX_IN_CLAUSE ; entityInfoIndex < max ; entityInfoIndex++) {
+ ids.add(entityInfos[entityInfoIndex].id);
+ }
+ disjunction.add( Restrictions.in( idName, ids ) );
+ }
+ criteria.add( disjunction );
+ criteria.setMaxResults( maxResults ); //is it faster
+ criteria.list(); //load all objects
+
+ //mandatory to keep the same ordering
+ List result = new ArrayList(entityInfos.length);
+ for (EntityInfo entityInfo : entityInfos) {
+ Object element = session.load( entityInfo.clazz, entityInfo.id );
+ if ( Hibernate.isInitialized( element ) ) {
+ //all existing elements should have been loaded by the query,
+ //the other ones are missing ones
+ result.add( element );
+ }
+ }
+ return result;
+ }
+}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -42,10 +42,10 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.SearchFactory;
+import org.hibernate.search.FullTextQuery;
import org.hibernate.search.backend.WorkType;
import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.query.FullTextQueryImpl;
-import org.hibernate.search.query.FullTextQuery;
import org.hibernate.search.util.ContextHelper;
import org.hibernate.stat.SessionStatistics;
import org.hibernate.type.Type;
Deleted: trunk/HibernateExt/search/src/java/org/hibernate/search/query/EntityInfo.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/query/EntityInfo.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/query/EntityInfo.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -1,12 +0,0 @@
-//$Id: $
-package org.hibernate.search.query;
-
-import java.io.Serializable;
-
-/**
- * @author Emmanuel Bernard
- */
-class EntityInfo {
- public Class clazz;
- public Serializable id;
-}
Deleted: trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQuery.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQuery.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQuery.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -1,36 +0,0 @@
-//$Id: $
-package org.hibernate.search.query;
-
-import org.apache.lucene.search.Sort;
-import org.hibernate.Query;
-
-/**
- * The base interface for lucene powered searches.
- *
- * @author Hardy Ferentschik
- */
-public interface FullTextQuery extends Query {
- //todo Determine what other lucene specific features to expose via this
- // interface. Maybe we should give access to the underlying lucene hit
- // objects?
-
- /**
- * Allows to let lucene sort the results. This is useful when you have
- * additional sort requirements on top of the default lucene ranking.
- * Without lucene sorting you would have to retrieve the full result set and
- * order the hibernate objects.
- *
- * @param sort The lucene sort object.
- */
- void setSort(Sort sort);
-
- /**
- * Returns the number of hits for this search
- *
- * Caution:
- * The number of results might be slightly different from
- * <code>list().size()</code> because list() if the index is
- * not in sync with the database at the time of query.
- */
- int resultSize();
-}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -2,7 +2,6 @@
package org.hibernate.search.query;
import java.io.IOException;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -21,26 +20,30 @@
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MultiSearcher;
import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.Sort;
import org.apache.lucene.store.Directory;
-import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
-import org.hibernate.ObjectNotFoundException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.query.ParameterMetadata;
import org.hibernate.impl.AbstractQueryImpl;
+import org.hibernate.search.SearchFactory;
+import org.hibernate.search.FullTextQuery;
import org.hibernate.search.engine.DocumentBuilder;
-import org.hibernate.search.SearchFactory;
+import org.hibernate.search.engine.DocumentExtractor;
+import org.hibernate.search.engine.Loader;
+import org.hibernate.search.engine.ObjectLoader;
+import org.hibernate.search.engine.QueryLoader;
+import org.hibernate.search.engine.EntityInfo;
import org.hibernate.search.util.ContextHelper;
/**
- * Implementation of {@link org.hibernate.search.query.FullTextQuery}
+ * Implementation of {@link org.hibernate.search.FullTextQuery}
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
@@ -55,7 +58,19 @@
private Integer maxResults;
private Integer resultSize;
private Sort sort;
+ private static Loader noLoader = new Loader() {
+ public void init(Session session, SearchFactory searchFactory) {
+ }
+ public Object load(EntityInfo entityInfo) {
+ throw new UnsupportedOperationException( "noLoader should not be used" );
+ }
+
+ public List load(EntityInfo... entityInfos) {
+ throw new UnsupportedOperationException( "noLoader should not be used" );
+ }
+ };
+
/**
* classes must be immutable
*/
@@ -68,8 +83,9 @@
}
- public void setSort(Sort sort) {
+ public FullTextQuery setSort(Sort sort) {
this.sort = sort;
+ return this;
}
/**
@@ -86,51 +102,68 @@
//find the directories
Searcher searcher = buildSearcher( searchFactory );
if ( searcher == null ) {
- return new IteratorImpl( new ArrayList<EntityInfo>(0), (Session) this.session);
+ return new IteratorImpl( new ArrayList<EntityInfo>(0), noLoader );
}
try {
Hits hits = getHits( searcher );
- setResultSize( hits );
int first = first();
int max = max( first, hits );
+ Session sess = (Session) this.session;
+
List<EntityInfo> entityInfos = new ArrayList<EntityInfo>( max - first + 1 );
+ DocumentExtractor extractor = new DocumentExtractor( searchFactory );
for ( int index = first; index <= max; index++ ) {
Document document = hits.doc( index );
- EntityInfo entityInfo = new EntityInfo();
- entityInfo.clazz = DocumentBuilder.getDocumentClass( document );
- entityInfo.id = DocumentBuilder.getDocumentId( searchFactory, entityInfo.clazz, document );
- entityInfos.add( entityInfo );
+ entityInfos.add( extractor.extract( document ) );
}
- return new IteratorImpl( entityInfos, (Session) this.session );
+ Loader loader = getLoader(sess, searchFactory);
+ return new IteratorImpl( entityInfos, loader );
}
catch (IOException e) {
throw new HibernateException( "Unable to query Lucene index", e );
}
finally {
- try {
- searcher.close();
- } catch (IOException e) {
- log.warn("Unable to properly close searcher during lucene query: " + getQueryString(), e);
- }
- }
+ try {
+ searcher.close();
+ }
+ catch (IOException e) {
+ log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
+ }
+ }
}
+ private Loader getLoader(Session session, SearchFactory searchFactory) {
+ if (classes.length == 1) {
+ QueryLoader loader = new QueryLoader();
+ loader.init( session, searchFactory );
+ loader.setEntityType( classes[0] );
+ return loader;
+ }
+ else {
+ final ObjectLoader objectLoader = new ObjectLoader();
+ objectLoader.init( session, searchFactory );
+ return objectLoader;
+ }
+ }
+
public ScrollableResults scroll() throws HibernateException {
//keep the searcher open until the resultset is closed
SearchFactory searchFactory = ContextHelper.getSearchFactoryBySFI( session );
-
+
//find the directories
Searcher searcher = buildSearcher( searchFactory );
//FIXME: handle null searcher
Hits hits;
try {
hits = getHits( searcher );
- setResultSize( hits );
int first = first();
int max = max( first, hits );
- return new ScrollableResultsImpl( searcher, hits, first, max, (Session) this.session, searchFactory );
+ DocumentExtractor extractor = new DocumentExtractor( searchFactory );
+ Loader loader = getLoader( (Session) this.session, searchFactory );
+ return new ScrollableResultsImpl( searcher, hits, first, max, extractor, loader);
}
catch (IOException e) {
+ //close only in case of exception
try {
if ( searcher != null ) searcher.close();
}
@@ -154,41 +187,23 @@
Hits hits;
try {
hits = getHits( searcher );
- setResultSize( hits );
int first = first();
int max = max( first, hits );
- List result = new ArrayList( max - first + 1 );
Session sess = (Session) this.session;
+ List<EntityInfo> infos = new ArrayList<EntityInfo>( max - first + 1 );
+ DocumentExtractor extractor = new DocumentExtractor( searchFactory );
for ( int index = first; index <= max; index++ ) {
Document document = hits.doc( index );
- Class clazz = DocumentBuilder.getDocumentClass( document );
- Serializable id = DocumentBuilder.getDocumentId( searchFactory, clazz, document );
- result.add( sess.load( clazz, id ) );
- //use load to benefit from the batch-size
- //we don't face proxy casting issues since the exact class is extracted from the index
+ infos.add( extractor.extract( document ) );
}
- //then initialize the objects
- List excludedObects = new ArrayList();
- for ( Object element : result ) {
- try {
- Hibernate.initialize( element );
- }
- catch (ObjectNotFoundException e) {
- log.debug( "Object found in Search index but not in database: "
- + e.getEntityName() + " wih id " + e.getIdentifier() );
- excludedObects.add( element );
- }
- }
- if ( excludedObects.size() > 0 ) {
- result.removeAll( excludedObects );
- }
- return result;
+ Loader loader = getLoader( sess, searchFactory );
+ return loader.load( infos.toArray( new EntityInfo[infos.size()]) );
}
catch (IOException e) {
throw new HibernateException( "Unable to query Lucene index", e );
}
finally {
- if ( searcher != null ) try {
+ try {
searcher.close();
}
catch (IOException e) {
@@ -213,6 +228,7 @@
else {
hits = searcher.search( query, sort );
}
+ setResultSize( hits );
return hits;
}
@@ -327,7 +343,6 @@
Hits hits;
try {
hits = getHits( searcher );
- setResultSize( hits );
}
catch (IOException e) {
throw new HibernateException( "Unable to query Lucene index", e );
@@ -346,12 +361,12 @@
return this.resultSize;
}
- public Query setFirstResult(int firstResult) {
+ public FullTextQuery setFirstResult(int firstResult) {
this.firstResult = firstResult;
return this;
}
- public Query setMaxResults(int maxResults) {
+ public FullTextQuery setMaxResults(int maxResults) {
this.maxResults = maxResults;
return this;
}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/query/IteratorImpl.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/query/IteratorImpl.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/query/IteratorImpl.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -5,7 +5,8 @@
import java.util.List;
import java.util.NoSuchElementException;
-import org.hibernate.Session;
+import org.hibernate.search.engine.Loader;
+import org.hibernate.search.engine.EntityInfo;
/**
* @author Emmanuel Bernard
@@ -14,16 +15,16 @@
public class IteratorImpl implements Iterator {
private final List<EntityInfo> entityInfos;
- private final Session session;
private int index = 0;
private final int size;
private Object next;
private int nextObjectIndex = -1;
+ private Loader loader;
- public IteratorImpl(List<EntityInfo> entityInfos, Session session) {
+ public IteratorImpl(List<EntityInfo> entityInfos, Loader loader) {
this.entityInfos = entityInfos;
- this.session = session;
this.size = entityInfos.size();
+ this.loader = loader;
}
//side effect is to set up next
@@ -37,7 +38,7 @@
next = null;
return false;
}
- next = session.get( entityInfos.get( index ).clazz, entityInfos.get( index ).id );
+ next = loader.load( entityInfos.get( index ) );
if ( next == null ) {
index++;
}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/query/ScrollableResultsImpl.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/query/ScrollableResultsImpl.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/query/ScrollableResultsImpl.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -9,16 +9,18 @@
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
+import java.util.Map;
import java.util.TimeZone;
+import java.util.HashMap;
import org.apache.lucene.document.Document;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.Searcher;
import org.hibernate.HibernateException;
import org.hibernate.ScrollableResults;
-import org.hibernate.Session;
-import org.hibernate.search.engine.DocumentBuilder;
-import org.hibernate.search.SearchFactory;
+import org.hibernate.search.engine.DocumentExtractor;
+import org.hibernate.search.engine.Loader;
+import org.hibernate.search.engine.EntityInfo;
import org.hibernate.type.Type;
/**
@@ -34,21 +36,23 @@
private final int first;
private final int max;
private int current;
- private final Session session;
private EntityInfo[] entityInfos;
- private final SearchFactory searchFactory;
+ private Loader loader;
+ private DocumentExtractor documentExtractor;
+ private Map<EntityInfo, Object[]> resultContext;
public ScrollableResultsImpl(
- Searcher searcher, Hits hits, int first, int max, Session session, SearchFactory searchFactory
+ Searcher searcher, Hits hits, int first, int max, DocumentExtractor extractor, Loader loader
) {
this.searcher = searcher;
this.hits = hits;
this.first = first;
this.max = max;
this.current = first;
- this.session = session;
- this.searchFactory = searchFactory;
- entityInfos = new EntityInfo[max - first + 1];
+ this.loader = loader;
+ this.documentExtractor = extractor;
+ this.entityInfos = new EntityInfo[max - first + 1];
+ this.resultContext = new HashMap<EntityInfo, Object[]>(max - first + 1);
}
public boolean next() throws HibernateException {
@@ -103,7 +107,6 @@
if ( current < first || current > max ) return null; //or exception?
EntityInfo info = entityInfos[current - first];
if ( info == null ) {
- info = new EntityInfo();
Document document = null;
try {
document = hits.doc( current );
@@ -111,14 +114,16 @@
catch (IOException e) {
throw new HibernateException( "Unable to read Lucene hits[" + current + "]", e );
}
- info.clazz = DocumentBuilder.getDocumentClass( document );
//FIXME should check that clazz match classes but this complexify a lot the firstResult/maxResult
- info.id = DocumentBuilder.getDocumentId( searchFactory, info.clazz, document );
+ info = documentExtractor.extract( document );
entityInfos[current - first] = info;
}
- return new Object[]{
- session.get( info.clazz, info.id )
- };
+ if ( !resultContext.containsKey( info ) ) {
+ Object loaded = loader.load( info );
+ if ( !loaded.getClass().isArray() ) loaded = new Object[] { loaded };
+ resultContext.put( info, (Object[]) loaded );
+ }
+ return resultContext.get( info );
}
public Object get(int i) throws HibernateException {
Modified: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQuerySortTest.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -14,7 +14,7 @@
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.Version;
-import org.hibernate.search.query.FullTextQuery;
+import org.hibernate.search.FullTextQuery;
import org.hibernate.search.test.SearchTestCase;
Modified: trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
===================================================================
--- trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2007-05-16 15:32:33 UTC (rev 11530)
+++ trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2007-05-16 22:25:22 UTC (rev 11531)
@@ -7,7 +7,7 @@
import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
-import org.hibernate.search.query.FullTextQuery;
+import org.hibernate.search.FullTextQuery;
import org.hibernate.Transaction;
import org.hibernate.Hibernate;
import org.hibernate.ScrollableResults;
@@ -51,6 +51,12 @@
assertEquals( "Query with explicit class filter", 2, result.size() );
query = parser.parse( "summary:Festina Or brand:Seiko" );
+ hibQuery = s.createFullTextQuery( query, Clock.class );
+ result = hibQuery.list();
+ assertNotNull( result );
+ assertEquals( "Query with one class filter", 1, result.size() );
+
+ query = parser.parse( "summary:Festina Or brand:Seiko" );
hibQuery = s.createFullTextQuery( query );
result = hibQuery.list();
assertNotNull( result );
16 years, 11 months
Hibernate SVN: r11529 - trunk/HibernateExt/search/src/java/org/hibernate/search/query.
by hibernate-commits@lists.jboss.org
Author: alesj
Date: 2007-05-15 19:06:34 -0400 (Tue, 15 May 2007)
New Revision: 11529
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
Log:
Non-functional null check + test commit.
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-05-15 23:03:21 UTC (rev 11528)
+++ trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-05-15 23:06:34 UTC (rev 11529)
@@ -107,15 +107,12 @@
throw new HibernateException( "Unable to query Lucene index", e );
}
finally {
- if ( searcher != null ) {
- try {
- searcher.close();
- }
- catch (IOException e) {
- log.warn( "Unable to properly close searcher during lucene query: " + getQueryString(), e );
- }
- }
- }
+ try {
+ searcher.close();
+ } catch (IOException e) {
+ log.warn("Unable to properly close searcher during lucene query: " + getQueryString(), e);
+ }
+ }
}
public ScrollableResults scroll() throws HibernateException {
16 years, 11 months
Hibernate SVN: r11527 - in trunk/Hibernate3: test/org/hibernate/test/jpa/lock and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-05-15 16:16:50 -0400 (Tue, 15 May 2007)
New Revision: 11527
Modified:
trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
trunk/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java
Log:
HHH-2613 support LockMode.FORCE on non-versioned entity
Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-05-15 20:15:58 UTC (rev 11526)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-05-15 20:16:50 UTC (rev 11527)
@@ -1314,7 +1314,7 @@
lockers.put( LockMode.READ, generateLocker( LockMode.READ ) );
lockers.put( LockMode.UPGRADE, generateLocker( LockMode.UPGRADE ) );
lockers.put( LockMode.UPGRADE_NOWAIT, generateLocker( LockMode.UPGRADE_NOWAIT ) );
- //lockers.put( LockMode.FORCE, generateLocker( LockMode.FORCE ) );
+ lockers.put( LockMode.FORCE, generateLocker( LockMode.FORCE ) );
}
protected LockingStrategy generateLocker(LockMode lockMode) {
Modified: trunk/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java 2007-05-15 20:15:58 UTC (rev 11526)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java 2007-05-15 20:16:50 UTC (rev 11527)
@@ -8,6 +8,7 @@
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.test.jpa.AbstractJPATest;
import org.hibernate.test.jpa.Item;
+import org.hibernate.test.jpa.MyEntity;
/**
* Tests specifically relating to section 3.3.5.3 [Lock Modes] of the
@@ -45,7 +46,7 @@
* is permissible.
* <p/>
* The persistence implementation is not required to support calling lock(entity, LockMode-Type.READ)
- * on a non-versioned object. When it cannot support such a lock call, it must throw the
+ * on a non-versioned object. When it cannot support such a lock call, it must throw the
* PersistenceException. When supported, whether for versioned or non-versioned objects, LockMode-Type.READ
* must always prevent the phenomena P1 and P2. Applications that call lock(entity, LockModeType.READ)
* on non-versioned objects will not be portable.
@@ -53,11 +54,11 @@
* Odd as it may sound, EJB3 LockModeType.READ actually maps to the Hibernate LockMode.UPGRADE
*/
public void testLockModeTypeRead() {
- if ( ! readCommittedIsolationMaintained( "ejb3 lock tests" ) ) {
+ if ( !readCommittedIsolationMaintained( "ejb3 lock tests" ) ) {
return;
}
- if(getDialect().doesReadCommittedCauseWritersToBlockReaders()) {
- reportSkip("deadlock", "jpa read locking");
+ if ( getDialect().doesReadCommittedCauseWritersToBlockReaders() ) {
+ reportSkip( "deadlock", "jpa read locking" );
return;
}
@@ -76,20 +77,20 @@
// perform the isolated update
s1 = getSessions().openSession();
t1 = s1.beginTransaction();
- item = ( Item ) s1.get( Item.class, itemId );
+ item = (Item) s1.get( Item.class, itemId );
s1.lock( item, LockMode.UPGRADE );
item.setName( "updated" );
s1.flush();
Session s2 = getSessions().openSession();
Transaction t2 = s2.beginTransaction();
- Item item2 = ( Item ) s2.get( Item.class, itemId );
+ Item item2 = (Item) s2.get( Item.class, itemId );
assertEquals( "isolation not maintained", initialName, item2.getName() );
t1.commit();
s1.close();
- item2 = ( Item ) s2.get( Item.class, itemId );
+ item2 = (Item) s2.get( Item.class, itemId );
assertEquals( "repeatable read not maintained", initialName, item2.getName() );
t2.commit();
s2.close();
@@ -124,11 +125,11 @@
* a new Hibernate LockMode was added to support this behavior: {@link org.hibernate.LockMode#FORCE}.
*/
public void testLockModeTypeWrite() {
- if ( ! readCommittedIsolationMaintained( "ejb3 lock tests" ) ) {
+ if ( !readCommittedIsolationMaintained( "ejb3 lock tests" ) ) {
return;
}
- if(getDialect().doesReadCommittedCauseWritersToBlockReaders()) {
- reportSkip("deadlock", "jpa write locking");
+ if ( getDialect().doesReadCommittedCauseWritersToBlockReaders() ) {
+ reportSkip( "deadlock", "jpa write locking" );
return;
}
final String initialName = "lock test";
@@ -138,6 +139,9 @@
Item item = new Item();
item.setName( initialName );
s1.save( item );
+ MyEntity myEntity = new MyEntity();
+ myEntity.setName( "Test" );
+ s1.save( myEntity );
t1.commit();
s1.close();
@@ -146,16 +150,20 @@
s1 = getSessions().openSession();
t1 = s1.beginTransaction();
- item = ( Item ) s1.get( Item.class, itemId );
+ item = (Item) s1.get( Item.class, itemId );
s1.lock( item, LockMode.FORCE );
assertEquals( "no forced version increment", initialVersion + 1, item.getVersion() );
+ myEntity = (MyEntity) s1.get( MyEntity.class, myEntity.getId() );
+ s1.lock( myEntity, LockMode.FORCE );
+ assertTrue( "LockMode.FORCE on a unversioned entity should degrade nicely to UPGRADE", true );
+
s1.lock( item, LockMode.FORCE );
assertEquals( "subsequent LockMode.FORCE did not no-op", initialVersion + 1, item.getVersion() );
Session s2 = getSessions().openSession();
Transaction t2 = s2.beginTransaction();
- Item item2 = ( Item ) s2.get( Item.class, itemId );
+ Item item2 = (Item) s2.get( Item.class, itemId );
assertEquals( "isolation not maintained", initialName, item2.getName() );
item.setName( "updated-1" );
@@ -171,7 +179,7 @@
t2.commit();
fail( "optimisitc lock should have failed" );
}
- catch( Throwable ignore ) {
+ catch (Throwable ignore) {
// expected behavior
t2.rollback();
}
@@ -182,6 +190,7 @@
s1 = getSessions().openSession();
t1 = s1.beginTransaction();
s1.delete( item );
+ s1.delete( myEntity );
t1.commit();
s1.close();
}
16 years, 11 months
Hibernate SVN: r11526 - in branches/Branch_3_2/Hibernate3: test/org/hibernate/test/jpa/lock and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-05-15 16:15:58 -0400 (Tue, 15 May 2007)
New Revision: 11526
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java
Log:
HHH-2613 support LockMode.FORCE on non-versioned entity
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-05-14 21:51:58 UTC (rev 11525)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2007-05-15 20:15:58 UTC (rev 11526)
@@ -1314,7 +1314,7 @@
lockers.put( LockMode.READ, generateLocker( LockMode.READ ) );
lockers.put( LockMode.UPGRADE, generateLocker( LockMode.UPGRADE ) );
lockers.put( LockMode.UPGRADE_NOWAIT, generateLocker( LockMode.UPGRADE_NOWAIT ) );
- //lockers.put( LockMode.FORCE, generateLocker( LockMode.FORCE ) );
+ lockers.put( LockMode.FORCE, generateLocker( LockMode.FORCE ) );
}
protected LockingStrategy generateLocker(LockMode lockMode) {
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java 2007-05-14 21:51:58 UTC (rev 11525)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/jpa/lock/JPALockTest.java 2007-05-15 20:15:58 UTC (rev 11526)
@@ -8,6 +8,7 @@
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.test.jpa.AbstractJPATest;
import org.hibernate.test.jpa.Item;
+import org.hibernate.test.jpa.MyEntity;
/**
* Tests specifically relating to section 3.3.5.3 [Lock Modes] of the
@@ -139,6 +140,9 @@
Item item = new Item();
item.setName( initialName );
s1.save( item );
+ MyEntity myEntity = new MyEntity();
+ myEntity.setName( "Test" );
+ s1.save( myEntity );
t1.commit();
s1.close();
@@ -151,6 +155,11 @@
s1.lock( item, LockMode.FORCE );
assertEquals( "no forced version increment", initialVersion + 1, item.getVersion() );
+ myEntity = (MyEntity) s1.get( MyEntity.class, myEntity.getId() );
+ s1.lock( myEntity, LockMode.FORCE );
+ assertTrue( "LockMode.FORCE on a unversioned entity should degrade nicely to UPGRADE", true );
+
+
s1.lock( item, LockMode.FORCE );
assertEquals( "subsequent LockMode.FORCE did not no-op", initialVersion + 1, item.getVersion() );
@@ -183,6 +192,7 @@
s1 = getSessions().openSession();
t1 = s1.beginTransaction();
s1.delete( item );
+ s1.delete( myEntity );
t1.commit();
s1.close();
}
16 years, 11 months
Hibernate SVN: r11525 - trunk/sandbox/maven-poc/Hibernate3/testsuite.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-14 17:51:58 -0400 (Mon, 14 May 2007)
New Revision: 11525
Modified:
trunk/sandbox/maven-poc/Hibernate3/testsuite/pom.xml
Log:
fixed testsuite deps to account for needed modules
Modified: trunk/sandbox/maven-poc/Hibernate3/testsuite/pom.xml
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/testsuite/pom.xml 2007-05-14 21:48:31 UTC (rev 11524)
+++ trunk/sandbox/maven-poc/Hibernate3/testsuite/pom.xml 2007-05-14 21:51:58 UTC (rev 11525)
@@ -14,7 +14,8 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-testsuite</artifactId>
<packaging>jar</packaging>
- <name>Hibernate Functional Testsuite</name>
+ <name>Hibernate Testsuite</name>
+ <description>The testsuite of Hibernate functionality</description>
<url>http://hibernate.org</url>
<dependencies>
@@ -26,6 +27,22 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-testing</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-ehcache</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-jbosscache</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-oscache</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-swarmcache</artifactId>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
16 years, 11 months
Hibernate SVN: r11524 - in trunk/sandbox/maven-poc/Hibernate3: cache-jbosscache2 and 7 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-14 17:48:31 -0400 (Mon, 14 May 2007)
New Revision: 11524
Added:
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/pom.xml
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TransactionManagerLookupAdaptor.java
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionAdapter.java
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionFactory.java
Log:
fix deps to account for jbosscache "transitive" deps...
Added: trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/pom.xml
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/pom.xml (rev 0)
+++ trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/pom.xml 2007-05-14 21:48:31 UTC (rev 11524)
@@ -0,0 +1,58 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core-project</artifactId>
+ <version>3.3.0.beta1</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-jbosscache2</artifactId>
+ <packaging>jar</packaging>
+ <name>Hibernate JBossCache2.x integration</name>
+ <description>Integration of Hibernate with JBossCache (based on JBossCache2.x APIs)</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-cache</artifactId>
+ <!-- does not work with idea plugin :(
+ <version>[2.0.0.BETA2,)</version>
+ -->
+ <version>2.0.0.BETA2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-idea-plugin</artifactId>
+ <configuration>
+ <jdkName>1.5</jdkName>
+ <jdkLevel>5.0</jdkLevel>
+ <!-- why this isnt the default I have no clue -->
+ <linkModules>true</linkModules>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TransactionManagerLookupAdaptor.java
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TransactionManagerLookupAdaptor.java (rev 0)
+++ trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TransactionManagerLookupAdaptor.java 2007-05-14 21:48:31 UTC (rev 11524)
@@ -0,0 +1,25 @@
+package org.hibernate.cache.impl.jbc;
+
+import java.util.Properties;
+import javax.transaction.TransactionManager;
+
+import org.hibernate.transaction.TransactionManagerLookup;
+
+/**
+ * An adapter between JBossCache's notion of a TM lookup and Hibernate's.
+ *
+ * @author Steve Ebersole
+ */
+public class TransactionManagerLookupAdaptor implements org.jboss.cache.transaction.TransactionManagerLookup {
+ private final TransactionManagerLookup tml;
+ private final Properties props;
+
+ TransactionManagerLookupAdaptor(TransactionManagerLookup tml, Properties props) {
+ this.tml = tml;
+ this.props = props;
+ }
+
+ public TransactionManager getTransactionManager() throws Exception {
+ return tml.getTransactionManager( props );
+ }
+}
Added: trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionAdapter.java
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionAdapter.java (rev 0)
+++ trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionAdapter.java 2007-05-14 21:48:31 UTC (rev 11524)
@@ -0,0 +1,105 @@
+package org.hibernate.cache.impl.jbc;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Node;
+import org.jboss.cache.config.Option;
+
+import org.hibernate.cache.Region;
+import org.hibernate.cache.CacheException;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class TreeCacheRegionAdapter implements Region {
+ private static final String ITEM = "item";
+
+ protected final Node jbcNode;
+ protected final String regionName;
+
+ public TreeCacheRegionAdapter(Cache jbcCache, String regionName) {
+ this.regionName = regionName;
+ Fqn fqn = Fqn.fromString( regionName.replace( '.', '/' ) );
+ this.jbcNode = jbcCache.getRoot().addChild( fqn );
+ }
+
+ public String getName() {
+ return regionName;
+ }
+
+ public void destroy() throws CacheException {
+ try {
+ // NOTE : this is being used from the process of shutting down a
+ // SessionFactory. Specific things to consider:
+ // (1) this clearing of the region should not propogate to
+ // other nodes on the cluster (if any); this is the
+ // cache-mode-local option bit...
+ // (2) really just trying a best effort to cleanup after
+ // ourselves; lock failures, etc are not critical here;
+ // this is the fail-silently option bit...
+ Option option = new Option();
+ option.setCacheModeLocal( true );
+ option.setFailSilently( true );
+ jbcNode.
+ jbcTreeCache.remove( regionFqn, option );
+ }
+ catch( Exception e ) {
+ throw new CacheException( e );
+ }
+ }
+
+ public long getSizeInMemory() {
+ // not supported
+ return -1;
+ }
+
+ public long getElementCountInMemory() {
+ try {
+ Set children = jbcTreeCache.getChildrenNames( regionFqn );
+ return children == null ? 0 : children.size();
+ }
+ catch ( Exception e ) {
+ throw new CacheException( e );
+ }
+ }
+
+ public long getElementCountOnDisk() {
+ return -1;
+ }
+
+ public Map toMap() {
+ try {
+ Map result = new HashMap();
+ Set childrenNames = jbcTreeCache.getChildrenNames( regionFqn );
+ if (childrenNames != null) {
+ Iterator iter = childrenNames.iterator();
+ while ( iter.hasNext() ) {
+ Object key = iter.next();
+ result.put(
+ key,
+ jbcTreeCache.get( new Fqn( regionFqn, key ), ITEM )
+ );
+ }
+ }
+ return result;
+ }
+ catch (Exception e) {
+ throw new CacheException(e);
+ }
+ }
+
+ public long nextTimestamp() {
+ return System.currentTimeMillis() / 100;
+ }
+
+ public int getTimeout() {
+ return 600; //60 seconds
+ }
+}
Added: trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionFactory.java
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionFactory.java (rev 0)
+++ trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionFactory.java 2007-05-14 21:48:31 UTC (rev 11524)
@@ -0,0 +1,226 @@
+package org.hibernate.cache.impl.jbc;
+
+import java.util.Properties;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+
+import org.hibernate.cache.RegionFactory;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.EntityRegion;
+import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.CollectionRegion;
+import org.hibernate.cache.QueryResultsRegion;
+import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+import org.hibernate.cache.access.AccessType;
+import org.hibernate.cfg.Settings;
+import org.hibernate.util.PropertiesHelper;
+
+/**
+ * A factory for building regions based on a JBossCache
+ * {@link org.jboss.cache.Node}. Here we are utilizing the
+ * same underlying {@link org.jboss.cache.Node} instance for each jbcTreeCache region.
+ *
+ * @author Steve Ebersole
+ */
+public class TreeCacheRegionFactory implements RegionFactory {
+ public static final String ENTITY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc.cfg.entity";
+ public static final String COLL_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc.cfg.collection";
+ public static final String TS_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc.cfg.ts";
+ public static final String QUERY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc.cfg.query";
+
+ public static final String DEF_ENTITY_RESOURCE = "entity-cache.xml";
+ public static final String DEF_COLL_RESOURCE = "collection-cache.xml";
+ public static final String DEF_TS_RESOURCE = "ts-cache.xml";
+ public static final String DEF_QUERY_RESOURCE = "query-cache.xml";
+
+ public static final String OPTIMISTIC_LOCKING_SCHEME = "OPTIMISTIC";
+
+ private static final Log log = LogFactory.getLog( TreeCacheRegionFactory.class );
+
+ private Cache jbcEntityCache;
+ private Cache jbcCollectionCache;
+ private Cache jbcTsCache;
+ private Cache jbcQueryCache;
+ private boolean useOptimisticLocking;
+
+ public void start(Settings settings, Properties properties) throws CacheException {
+ try {
+ TransactionManager tm = settings.getTransactionManagerLookup() == null
+ ? null
+ : settings.getTransactionManagerLookup().getTransactionManager( properties );
+ if ( settings.isSecondLevelCacheEnabled() ) {
+ jbcEntityCache = buildEntityRegionCacheInstance( properties );
+ jbcCollectionCache = buildCollectionRegionCacheInstance( properties );
+ if ( tm != null ) {
+ jbcEntityCache.getConfiguration().getRuntimeConfig().setTransactionManager( tm );
+ jbcCollectionCache.getConfiguration().getRuntimeConfig().setTransactionManager( tm );
+ }
+ }
+ if ( settings.isQueryCacheEnabled() ) {
+ jbcTsCache = buildTsRegionCacheInstance( properties );
+ jbcQueryCache = buildQueryRegionCacheInstance( properties );
+ }
+ }
+ catch( CacheException ce ) {
+ throw ce;
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "Unable to start region factory", t );
+ }
+// String resource = PropertiesHelper.getString( Environment.CACHE_PROVIDER_CONFIG, properties, DEFAULT_CONFIG );
+// log.debug( "Configuring basic TreeCache RegionFactory from resource [" + resource + "]" );
+// try {
+// jbcTreeCache = new TreeCache();
+// PropertyConfigurator config = new PropertyConfigurator();
+// config.configure( jbcTreeCache, resource );
+// TransactionManagerLookup transactionManagerLookup = settings.getTransactionManagerLookup();
+// if ( transactionManagerLookup != null ) {
+// jbcTreeCache.setTransactionManagerLookup(
+// new TransactionManagerLookupAdaptor( transactionManagerLookup, properties )
+// );
+// }
+// jbcTreeCache.start();
+// useOptimisticLocking = OPTIMISTIC_LOCKING_SCHEME.equalsIgnoreCase( jbcTreeCache.getNodeLockingScheme() );
+// }
+// catch ( Exception e ) {
+// throw new CacheException( e );
+// }
+ }
+
+ protected Cache buildEntityRegionCacheInstance(Properties properties) {
+ try {
+ String configResource = PropertiesHelper.getString( ENTITY_CACHE_RESOURCE_PROP, properties, DEF_ENTITY_RESOURCE );
+ return DefaultCacheFactory.getInstance().createCache( configResource );
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "unable to build entity region cache instance", t );
+ }
+ }
+
+ protected Cache buildCollectionRegionCacheInstance(Properties properties) {
+ try {
+ String configResource = PropertiesHelper.getString( COLL_CACHE_RESOURCE_PROP, properties, DEF_COLL_RESOURCE );
+ return DefaultCacheFactory.getInstance().createCache( configResource );
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "unable to build collection region cache instance", t );
+ }
+ }
+
+ protected Cache buildTsRegionCacheInstance(Properties properties) {
+ try {
+ String configResource = PropertiesHelper.getString( TS_CACHE_RESOURCE_PROP, properties, DEF_TS_RESOURCE );
+ return DefaultCacheFactory.getInstance().createCache( configResource );
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "unable to build timestamps region cache instance", t );
+ }
+ }
+
+ protected Cache buildQueryRegionCacheInstance(Properties properties) {
+ try {
+ String configResource = PropertiesHelper.getString( QUERY_CACHE_RESOURCE_PROP, properties, DEF_QUERY_RESOURCE );
+ return DefaultCacheFactory.getInstance().createCache( configResource );
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "unable to build query region cache instance", t );
+ }
+ }
+
+ public void stop() {
+ if ( jbcEntityCache != null ) {
+ try {
+ jbcEntityCache.stop();
+ }
+ catch( Throwable t ) {
+ log.info( "Unable to stop entity cache instance", t );
+ }
+ }
+ if ( jbcCollectionCache != null ) {
+ try {
+ jbcCollectionCache.stop();
+ }
+ catch( Throwable t ) {
+ log.info( "Unable to stop collection cache instance", t );
+ }
+ }
+ if ( jbcTsCache != null ) {
+ try {
+ jbcTsCache.stop();
+ }
+ catch( Throwable t ) {
+ log.info( "Unable to stop timestamp cache instance", t );
+ }
+ }
+ if ( jbcQueryCache != null ) {
+ try {
+ jbcQueryCache.stop();
+ }
+ catch( Throwable t ) {
+ log.info( "Unable to stop query cache instance", t );
+ }
+ }
+ }
+
+ public boolean isMinimalPutsEnabledByDefault() {
+ return true;
+ }
+
+ public long nextTimestamp() {
+ return System.currentTimeMillis() / 100;
+ }
+
+ public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) {
+ if ( useOptimisticLocking && !metadata.isVersioned() ) {
+ log.warn( "JBossCache configured to use optimistic locking, but entity to be cached is not versioned [" + regionName + "]" );
+ }
+ else if ( !useOptimisticLocking && metadata.isVersioned() ) {
+ log.info( "Caching versioned entity without optimisitic locking; consider optimistic locking if all cached entities are versioned" );
+ }
+ return new EntityRegionAdapter( regionName, metadata );
+ }
+
+ public CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata)
+ throws CacheException {
+ return null;
+ }
+
+ public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException {
+ return null;
+ }
+
+ public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException {
+ return null;
+ }
+
+ private class EntityRegionAdapter extends TreeCacheRegionAdapter implements EntityRegion {
+ private final CacheDataDescription metadata;
+
+ public EntityRegionAdapter(String regionName, CacheDataDescription metadata) {
+ super( TreeCacheRegionFactory.this.jbcTreeCache, regionName );
+ this.metadata = metadata;
+ }
+
+ public boolean isTransactionAware() {
+ return jbcTreeCache.getTransactionManager() != null;
+ }
+
+ public CacheDataDescription getCacheDataDescription() {
+ return metadata;
+ }
+
+ public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
+ if ( ! ( AccessType.READ_ONLY.equals( accessType ) || AccessType.TRANSACTIONAL.equals( accessType ) ) ) {
+ throw new CacheException( "TreeCacheRegionFactory only supports ( " + AccessType.READ_ONLY.getName() + " | " + AccessType.TRANSACTIONAL + " ) access strategies [" + accessType.getName() + "]" );
+ }
+ // todo : implement :)
+ return null;
+ }
+ }
+}
16 years, 11 months
Hibernate SVN: r11523 - trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-14 17:44:53 -0400 (Mon, 14 May 2007)
New Revision: 11523
Modified:
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache/pom.xml
Log:
fix deps to account for jbosscache "transitive" deps...
Modified: trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache/pom.xml
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache/pom.xml 2007-05-14 21:37:48 UTC (rev 11522)
+++ trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache/pom.xml 2007-05-14 21:44:53 UTC (rev 11523)
@@ -19,7 +19,7 @@
<dependencies>
<dependency>
- <groupId>org.hibernate</groupId>
+ <groupId>${groupId}</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
@@ -27,6 +27,37 @@
<artifactId>jboss-cache</artifactId>
<version>1.4.1.GA</version>
</dependency>
+ <!-- jboss-cache (the one from the jboss repo, anyway) does not properly define its dependencies -->
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-system</artifactId>
+ <version>4.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common</artifactId>
+ <version>4.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-minimal</artifactId>
+ <version>4.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-j2se</artifactId>
+ <version>200504122039</version>
+ </dependency>
+ <dependency>
+ <groupId>concurrent</groupId>
+ <artifactId>concurrent</artifactId>
+ <version>1.3.4</version>
+ </dependency>
+ <dependency>
+ <groupId>jgroups</groupId>
+ <artifactId>jgroups-all</artifactId>
+ <version>2.2.7</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
16 years, 11 months
Hibernate SVN: r11522 - trunk/sandbox/maven-poc/Hibernate3.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-05-14 17:37:48 -0400 (Mon, 14 May 2007)
New Revision: 11522
Modified:
trunk/sandbox/maven-poc/Hibernate3/pom.xml
Log:
cleanup based on suggestions from Cedirc Vidal
Modified: trunk/sandbox/maven-poc/Hibernate3/pom.xml
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/pom.xml 2007-05-14 16:07:48 UTC (rev 11521)
+++ trunk/sandbox/maven-poc/Hibernate3/pom.xml 2007-05-14 21:37:48 UTC (rev 11522)
@@ -90,9 +90,7 @@
<module>jmx</module>
<module>testing</module>
<module>documentation</module>
-<!--
<module>testsuite</module>
--->
<!-- Need to scope bytecode providers first
<module>bytecode-cglib</module>
<module>bytecode-javassist</module>
@@ -146,6 +144,16 @@
<artifactId>hibernate-testing</artifactId>
<version>${version}</version>
</dependency>
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>hibernate-testsuite</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>hibernate-manual</artifactId>
+ <version>${version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
@@ -163,23 +171,23 @@
<id>jboss-maven-repo</id>
<name>JBoss maintained repo</name>
<url>http://repository.jboss.com/maven2</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
</repository>
</repositories>
-<!--
- The jbc2.0-based module is not written yet, but it will require jdk5
<profiles>
<profile>
- <id>jdk5</id>
+ <id>jbosscache2-module</id>
<modules>
<module>cache-jbosscache2</module>
</modules>
<activation>
- <jdk>5</jdk>
+ <jdk>1.5</jdk>
</activation>
</profile>
</profiles>
--->
<build>
<plugins>
@@ -187,6 +195,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-idea-plugin</artifactId>
<configuration>
+ <jdkName>1.4</jdkName>
+ <jdkLevel>1.4</jdkLevel>
<!-- why this isnt the default I have no clue -->
<linkModules>true</linkModules>
</configuration>
@@ -194,14 +204,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.4</source>
- <target>1.4</target>
- </configuration>
+ <configuration>
+ <source>1.4</source>
+ <target>1.4</target>
+ </configuration>
</plugin>
</plugins>
</build>
+ <!-- Not really caring about reporting plugin versions; I think this is ok??? -->
<reporting>
<plugins>
<plugin>
@@ -209,30 +220,13 @@
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<links>
- <link>http://java.sun.com/j2se/1.4.2/docs/api</link>
+ <link>http://java.sun.com/j2se/1.4.2/docs/api/</link>
<link>http://java.sun.com/j2ee/1.4/docs/api/</link>
</links>
</configuration>
</plugin>
-<!--
- This one completely does not work for me...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-changes-plugin</artifactId>
- <reportSets>
- <reportSet>
- <reports>
- <report>jira-report</report>
- </reports>
- </reportSet>
- </reportSets>
- <configuration>
- <statusIds>Closed</statusIds>
- </configuration>
- </plugin>
--->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
<plugin>
@@ -244,9 +238,11 @@
<artifactId>taglist-maven-plugin</artifactId>
<configuration>
<tags>
+ <tag>@FIXME</tag>
<tag>@fixme</tag>
<tag>FIXME</tag>
<tag>fixme</tag>
+ <tag>@TODO</tag>
<tag>@todo</tag>
<tag>TODO</tag>
<tag>todo</tag>
@@ -261,7 +257,7 @@
<minimumTokens>100</minimumTokens>
<targetJdk>1.4</targetJdk>
</configuration>
- </plugin>
+ </plugin>
</plugins>
</reporting>
16 years, 11 months