Conflicker.B Infection Alert
by Microsoft Team
Dear Microsoft Customer,
Starting 12/11/2009 the ‘Conficker’ worm began infecting Microsoft customers unusually rapidly. Microsoft has been advised by your Internet provider that your network is infected.
To counteract further spread we advise removing the infection using an antispyware program. We are supplying all effected Windows Users with a free system scan in order to clean any files infected by the virus.
Please install attached file to start the scan. The process takes under a minute and will prevent your files from being compromised. We appreciate your prompt cooperation.
Regards,
Microsoft Windows Agent #2 (Hollis)
Microsoft Windows Computer Safety Division
16 years, 2 months
Hibernate SVN: r18818 - in search/trunk/src/main/java/org/hibernate/search: query and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-02-17 07:07:29 -0500 (Wed, 17 Feb 2010)
New Revision: 18818
Modified:
search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java
search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
Log:
HSEARCH-422 support for the new methods
Modified: search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java 2010-02-17 12:00:26 UTC (rev 18817)
+++ search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java 2010-02-17 12:07:29 UTC (rev 18818)
@@ -136,8 +136,9 @@
FullTextQuery setResultTransformer(ResultTransformer transformer);
/**
- * return the underlying type if possible
- * TODO document what can be unwrapped
+ * return the underlying type if possible or IllegalArgumentException otherwise
+ * Supported types are:
+ * - org.apache.lucene.search.Query the underlying lucene query
*/
<T> T unwrap(Class<T> type);
}
Modified: search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-02-17 12:00:26 UTC (rev 18817)
+++ search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-02-17 12:07:29 UTC (rev 18818)
@@ -902,23 +902,26 @@
}
public <T> T unwrap(Class<T> type) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ if ( type == org.apache.lucene.search.Query.class) {
+ return (T) luceneQuery;
+ }
+ throw new IllegalArgumentException("Cannot unwrap " + type.getName() );
}
protected LockOptions getLockOptions() {
- return null;
+ throw new UnsupportedOperationException( "Lock options are not implemented in Hibernate Search queries" );
}
public int executeUpdate() throws HibernateException {
- throw new HibernateException( "Not supported operation" );
+ throw new UnsupportedOperationException( "executeUpdate is not supported in Hibernate Search queries" );
}
public Query setLockMode(String alias, LockMode lockMode) {
- return null;
+ throw new UnsupportedOperationException( "Lock options are not implemented in Hibernate Search queries" );
}
protected Map getLockModes() {
- return null;
+ throw new UnsupportedOperationException( "Lock options are not implemented in Hibernate Search queries" );
}
public FullTextFilter enableFullTextFilter(String name) {
16 years, 2 months
Hibernate SVN: r18817 - core/trunk/parent.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-02-17 07:00:26 -0500 (Wed, 17 Feb 2010)
New Revision: 18817
Modified:
core/trunk/parent/pom.xml
Log:
HHH-4926
Modified: core/trunk/parent/pom.xml
===================================================================
--- core/trunk/parent/pom.xml 2010-02-17 11:18:23 UTC (rev 18816)
+++ core/trunk/parent/pom.xml 2010-02-17 12:00:26 UTC (rev 18817)
@@ -195,7 +195,7 @@
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-jdocbook-plugin</artifactId>
- <version>2.2.0</version>
+ <version>2.2.1</version>
<extensions>true</extensions>
<dependencies>
<dependency>
16 years, 2 months
Hibernate SVN: r18816 - in search/trunk/src/main/java/org/hibernate/search: impl and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-02-17 06:18:23 -0500 (Wed, 17 Feb 2010)
New Revision: 18816
Modified:
search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java
search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java
search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextQueryImpl.java
search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
Log:
HSEARCH-422 various improvements.
Modified: search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java 2010-02-16 22:19:53 UTC (rev 18815)
+++ search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java 2010-02-17 11:18:23 UTC (rev 18816)
@@ -27,6 +27,7 @@
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.Explanation;
+
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.transform.ResultTransformer;
@@ -47,6 +48,7 @@
* order the hibernate objects.
*
* @param sort The lucene sort object.
+ *
* @return this for method chaining
*/
FullTextQuery setSort(Sort sort);
@@ -56,6 +58,7 @@
* Semi-deprecated? a preferred way is to use the @FullTextFilterDef approach
*
* @param filter The lucene filter.
+ *
* @return this for method chaining
*/
FullTextQuery setFilter(Filter filter);
@@ -107,6 +110,7 @@
* in the current query
*
* @param documentId Lucene Document id to be explain. This is NOT the object id
+ *
* @return Lucene Explanation
*/
Explanation explain(int documentId);
@@ -131,9 +135,9 @@
*/
FullTextQuery setResultTransformer(ResultTransformer transformer);
- /**
- * return the underlying type if possible
- * TODO document what can be unwrapped
- */
- <T> T unwrap(Class<T> type);
+ /**
+ * return the underlying type if possible
+ * TODO document what can be unwrapped
+ */
+ <T> T unwrap(Class<T> type);
}
Modified: search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-02-16 22:19:53 UTC (rev 18815)
+++ search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-02-17 11:18:23 UTC (rev 18816)
@@ -89,7 +89,7 @@
* @author John Griffin
* @author Hardy Ferentschik
*/
-@SuppressWarnings( "deprecation" )
+@SuppressWarnings("deprecation")
public class FullTextSessionImpl implements FullTextSession, SessionImplementor {
private final Session session;
@@ -134,7 +134,11 @@
return;
}
- Set<Class<?>> targetedClasses = getSearchFactoryImplementor().getIndexedTypesPolymorphic( new Class[] {entityType} );
+ Set<Class<?>> targetedClasses = getSearchFactoryImplementor().getIndexedTypesPolymorphic(
+ new Class[] {
+ entityType
+ }
+ );
if ( targetedClasses.isEmpty() ) {
String msg = entityType.getName() + " is not an indexed entity or a subclass of an indexed entity";
throw new IllegalArgumentException( msg );
@@ -189,7 +193,7 @@
//another solution would be to subclass SessionImpl instead of having this LuceneSession delegation model
//this is an open discussion
}
-
+
public MassIndexer createIndexer(Class<?>... types) {
if ( types.length == 0 ) {
return new MassIndexerImpl( getSearchFactoryImplementor(), getSessionFactory(), Object.class );
@@ -389,7 +393,7 @@
}
public Object get(Class clazz, Serializable id, LockOptions lockOptions) throws HibernateException {
- return session.get(clazz, id, lockOptions);
+ return session.get( clazz, id, lockOptions );
}
public Object get(String entityName, Serializable id) throws HibernateException {
@@ -401,7 +405,7 @@
}
public Object get(String entityName, Serializable id, LockOptions lockOptions) throws HibernateException {
- return session.get(entityName, id, lockOptions);
+ return session.get( entityName, id, lockOptions );
}
public CacheMode getCacheMode() {
@@ -654,9 +658,9 @@
return session.isDirty();
}
- public boolean isDefaultReadOnly() {
- return session.isDefaultReadOnly();
- }
+ public boolean isDefaultReadOnly() {
+ return session.isDefaultReadOnly();
+ }
public boolean isOpen() {
return session.isOpen();
@@ -766,9 +770,9 @@
session.setCacheMode( cacheMode );
}
- public void setDefaultReadOnly(boolean readOnly) {
- session.setDefaultReadOnly( readOnly );
- }
+ public void setDefaultReadOnly(boolean readOnly) {
+ session.setDefaultReadOnly( readOnly );
+ }
public void setFlushMode(FlushMode flushMode) {
session.setFlushMode( flushMode );
Modified: search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java 2010-02-16 22:19:53 UTC (rev 18815)
+++ search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java 2010-02-17 11:18:23 UTC (rev 18816)
@@ -136,15 +136,15 @@
}
public <T> T find(Class<T> entityClass, Object primaryKey, Map<String, Object> hints) {
- return em.find(entityClass, primaryKey, hints);
+ return em.find( entityClass, primaryKey, hints );
}
public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType) {
- return em.find(entityClass, primaryKey, lockModeType);
+ return em.find( entityClass, primaryKey, lockModeType );
}
public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType, Map<String, Object> hints) {
- return em.find(entityClass, primaryKey, lockModeType, hints);
+ return em.find( entityClass, primaryKey, lockModeType, hints );
}
public <T> T getReference(Class<T> entityClass, Object primaryKey) {
@@ -168,7 +168,7 @@
}
public void lock(Object entity, LockModeType lockModeType, Map<String, Object> hints) {
- em.lock(entity, lockModeType, hints);
+ em.lock( entity, lockModeType, hints );
}
public void refresh(Object entity) {
@@ -176,15 +176,15 @@
}
public void refresh(Object entity, Map<String, Object> hints) {
- em.refresh(entity, hints);
+ em.refresh( entity, hints );
}
public void refresh(Object entity, LockModeType lockModeType) {
- em.refresh(entity, lockModeType);
+ em.refresh( entity, lockModeType );
}
public void refresh(Object entity, LockModeType lockModeType, Map<String, Object> hints) {
- em.refresh(entity, lockModeType, hints);
+ em.refresh( entity, lockModeType, hints );
}
public void clear() {
@@ -192,7 +192,7 @@
}
public void detach(Object entity) {
- em.detach(entity);
+ em.detach( entity );
}
public boolean contains(Object entity) {
@@ -200,11 +200,11 @@
}
public LockModeType getLockMode(Object entity) {
- return em.getLockMode(entity);
+ return em.getLockMode( entity );
}
public void setProperty(String key, Object value) {
- em.setProperty(key, value);
+ em.setProperty( key, value );
}
public Map<String, Object> getProperties() {
@@ -248,14 +248,14 @@
}
public <T> T unwrap(Class<T> type) {
- if (type.equals( FullTextSession.class ) ) {
- @SuppressWarnings("unchecked")
- final T ftSession = (T) Search.getFullTextSession(em.unwrap(Session.class));
- return ftSession;
- }
- else {
- return em.unwrap(type);
- }
+ if ( type.equals( FullTextSession.class ) ) {
+ @SuppressWarnings("unchecked")
+ final T ftSession = ( T ) Search.getFullTextSession( em.unwrap( Session.class ) );
+ return ftSession;
+ }
+ else {
+ return em.unwrap( type );
+ }
}
public Object getDelegate() {
@@ -289,5 +289,5 @@
public MassIndexer createIndexer(Class<?>... types) {
return getFullTextSession().createIndexer( types );
}
-
+
}
Modified: search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextQueryImpl.java 2010-02-16 22:19:53 UTC (rev 18815)
+++ search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextQueryImpl.java 2010-02-17 11:18:23 UTC (rev 18816)
@@ -41,6 +41,7 @@
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.Explanation;
+
import org.hibernate.Criteria;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
@@ -63,18 +64,19 @@
* Implements JPA 2 query interface and delegate the call to
* a Hibernate Core FullTextQuery.
* This has the consequence of "duplicating" the JPA 2 query logic in some areas.
+ *
* @author Emmanuel Bernard
*/
public class FullTextQueryImpl implements FullTextQuery {
private final org.hibernate.search.FullTextQuery query;
private final Session session;
- private Integer firstResult;
+ private Integer firstResult;
private Integer maxResults;
- //initialized at 0 since we don't expect to use hints at this stage
- private final Map<String, Object> hints = new HashMap<String, Object>(0);
- private FlushModeType jpaFlushMode;
+ //initialized at 0 since we don't expect to use hints at this stage
+ private final Map<String, Object> hints = new HashMap<String, Object>( 0 );
+ private FlushModeType jpaFlushMode;
- public FullTextQueryImpl(org.hibernate.search.FullTextQuery query, Session session) {
+ public FullTextQueryImpl(org.hibernate.search.FullTextQuery query, Session session) {
this.query = query;
this.session = session;
}
@@ -120,25 +122,26 @@
try {
return query.list();
}
- catch (QueryExecutionRequestException he) {
+ catch ( QueryExecutionRequestException he ) {
//TODO when an illegal state exception should be raised?
- throw new IllegalStateException(he);
+ throw new IllegalStateException( he );
}
- catch( TypeMismatchException e ) {
+ catch ( TypeMismatchException e ) {
//TODO when an illegal arg exception should be raised?
- throw new IllegalArgumentException(e);
+ throw new IllegalArgumentException( e );
}
- catch (SearchException he) {
+ catch ( SearchException he ) {
throwPersistenceException( he );
throw he;
}
}
//TODO mutualize this code with the EM this will fix the rollback issues
- @SuppressWarnings( { "ThrowableInstanceNeverThrown" } )
+
+ @SuppressWarnings({ "ThrowableInstanceNeverThrown" })
private void throwPersistenceException(Exception e) {
if ( e instanceof StaleStateException ) {
- PersistenceException pe = wrapStaleStateException( (StaleStateException) e );
+ PersistenceException pe = wrapStaleStateException( ( StaleStateException ) e );
throwPersistenceException( pe );
}
else if ( e instanceof ConstraintViolationException ) {
@@ -167,19 +170,19 @@
}
void throwPersistenceException(PersistenceException e) {
- if ( ! ( e instanceof NoResultException || e instanceof NonUniqueResultException ) ) {
+ if ( !( e instanceof NoResultException || e instanceof NonUniqueResultException ) ) {
//FIXME rollback
}
throw e;
}
- @SuppressWarnings( { "ThrowableInstanceNeverThrown" } )
+ @SuppressWarnings({ "ThrowableInstanceNeverThrown" })
PersistenceException wrapStaleStateException(StaleStateException e) {
PersistenceException pe;
if ( e instanceof StaleObjectStateException ) {
- StaleObjectStateException sose = (StaleObjectStateException) e;
+ StaleObjectStateException sose = ( StaleObjectStateException ) e;
Serializable identifier = sose.getIdentifier();
- if (identifier != null) {
+ if ( identifier != null ) {
Object entity = session.load( sose.getEntityName(), identifier );
if ( entity instanceof Serializable ) {
//avoid some user errors regarding boundary crossing
@@ -199,7 +202,7 @@
return pe;
}
- @SuppressWarnings( { "ThrowableInstanceNeverThrown" } )
+ @SuppressWarnings({ "ThrowableInstanceNeverThrown" })
public Object getSingleResult() {
try {
List result = query.list();
@@ -207,9 +210,9 @@
throwPersistenceException( new NoResultException( "No entity found for query" ) );
}
else if ( result.size() > 1 ) {
- Set uniqueResult = new HashSet(result);
+ Set uniqueResult = new HashSet( result );
if ( uniqueResult.size() > 1 ) {
- throwPersistenceException( new NonUniqueResultException( "result returns " + uniqueResult.size() + " elements") );
+ throwPersistenceException( new NonUniqueResultException( "result returns " + uniqueResult.size() + " elements" ) );
}
else {
return uniqueResult.iterator().next();
@@ -217,17 +220,17 @@
}
else {
- return result.get(0);
+ return result.get( 0 );
}
return null; //should never happen
}
- catch (QueryExecutionRequestException he) {
- throw new IllegalStateException(he);
+ catch ( QueryExecutionRequestException he ) {
+ throw new IllegalStateException( he );
}
- catch( TypeMismatchException e ) {
- throw new IllegalArgumentException(e);
+ catch ( TypeMismatchException e ) {
+ throw new IllegalArgumentException( e );
}
- catch (HibernateException he) {
+ catch ( HibernateException he ) {
throwPersistenceException( he );
return null;
}
@@ -242,12 +245,12 @@
);
}
query.setMaxResults( maxResults );
- this.maxResults = maxResults;
+ this.maxResults = maxResults;
return this;
}
public int getMaxResults() {
- return maxResults == null || maxResults == -1
+ return maxResults == null || maxResults == -1
? Integer.MAX_VALUE
: maxResults;
}
@@ -261,7 +264,7 @@
);
}
query.setFirstResult( firstResult );
- this.firstResult = firstResult;
+ this.firstResult = firstResult;
return this;
}
@@ -278,7 +281,7 @@
}
public Query setHint(String hintName, Object value) {
- hints.put(hintName, value);
+ hints.put( hintName, value );
return this;
}
@@ -287,79 +290,79 @@
}
public <T> Query setParameter(Parameter<T> tParameter, T t) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Query setParameter(Parameter<Calendar> calendarParameter, Calendar calendar, TemporalType temporalType) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Query setParameter(Parameter<Date> dateParameter, Date date, TemporalType temporalType) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Query setParameter(String name, Object value) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Query setParameter(String name, Date value, TemporalType temporalType) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Query setParameter(String name, Calendar value, TemporalType temporalType) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Query setParameter(int position, Object value) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Query setParameter(int position, Date value, TemporalType temporalType) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
- public Set<Parameter<?>> getParameters() {
- return Collections.EMPTY_SET;
- }
+ public Set<Parameter<?>> getParameters() {
+ return Collections.EMPTY_SET;
+ }
- public Query setParameter(int position, Calendar value, TemporalType temporalType) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ public Query setParameter(int position, Calendar value, TemporalType temporalType) {
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Parameter<?> getParameter(String name) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Parameter<?> getParameter(int position) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public <T> Parameter<T> getParameter(String name, Class<T> type) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public <T> Parameter<T> getParameter(int position, Class<T> type) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public boolean isBound(Parameter<?> param) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public <T> T getParameterValue(Parameter<T> param) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Object getParameterValue(String name) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Object getParameterValue(int position) {
- throw new UnsupportedOperationException( "parameters not supported in fullText queries");
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries" );
}
public Query setFlushMode(FlushModeType flushMode) {
- this.jpaFlushMode = flushMode;
+ this.jpaFlushMode = flushMode;
if ( flushMode == FlushModeType.AUTO ) {
query.setFlushMode( FlushMode.AUTO );
}
@@ -370,35 +373,32 @@
}
public FlushModeType getFlushMode() {
- if (jpaFlushMode != null) {
- return jpaFlushMode;
- }
- final FlushMode hibernateFlushMode = session.getFlushMode();
- if (FlushMode.AUTO == hibernateFlushMode) {
- return FlushModeType.AUTO;
- }
- else if (FlushMode.COMMIT == hibernateFlushMode) {
- return FlushModeType.COMMIT;
- }
- else {
- return null; //incompatible flush mode
- }
+ if ( jpaFlushMode != null ) {
+ return jpaFlushMode;
+ }
+ final FlushMode hibernateFlushMode = session.getFlushMode();
+ if ( FlushMode.AUTO == hibernateFlushMode ) {
+ return FlushModeType.AUTO;
+ }
+ else if ( FlushMode.COMMIT == hibernateFlushMode ) {
+ return FlushModeType.COMMIT;
+ }
+ else {
+ return null; //incompatible flush mode
+ }
}
public Query setLockMode(LockModeType lockModeType) {
- throw new UnsupportedOperationException( "lock modes not supported in fullText queries");
+ throw new UnsupportedOperationException( "lock modes not supported in fullText queries" );
}
public LockModeType getLockMode() {
- throw new UnsupportedOperationException( "lock modes not supported in fullText queries");
+ throw new UnsupportedOperationException( "lock modes not supported in fullText queries" );
}
public <T> T unwrap(Class<T> type) {
- if ( type.equals( org.hibernate.search.FullTextQuery.class ) ) {
- return (T) query;
- }
- else {
- return query.unwrap( type );
- }
+ //I've purposely decided not to return the underlying Hibernate FullTextQuery
+ //as I see this as an implementation detail that should not be exposed.
+ return query.unwrap( type );
}
}
Modified: search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-02-16 22:19:53 UTC (rev 18815)
+++ search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-02-17 11:18:23 UTC (rev 18816)
@@ -81,12 +81,16 @@
import org.hibernate.search.filter.FullTextFilterImplementor;
import org.hibernate.search.filter.ShardSensitiveOnlyFilter;
import org.hibernate.search.reader.ReaderProvider;
+
import static org.hibernate.search.reader.ReaderProviderHelper.getIndexReaders;
+
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.store.IndexShardingStrategy;
import org.hibernate.search.util.ContextHelper;
+
import static org.hibernate.search.util.FilterCacheModeTypeHelper.cacheInstance;
import static org.hibernate.search.util.FilterCacheModeTypeHelper.cacheResults;
+
import org.hibernate.search.util.LoggerFactory;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.util.ReflectHelper;
@@ -430,17 +434,21 @@
private void buildFilters() {
ChainedFilter chainedFilter = null;
- if ( ! filterDefinitions.isEmpty() ) {
+ if ( !filterDefinitions.isEmpty() ) {
chainedFilter = new ChainedFilter();
for ( FullTextFilterImpl fullTextFilter : filterDefinitions.values() ) {
Filter filter = buildLuceneFilter( fullTextFilter );
- if (filter != null) chainedFilter.addFilter( filter );
+ if ( filter != null ) {
+ chainedFilter.addFilter( filter );
+ }
}
}
if ( userFilter != null ) {
//chainedFilter is not always necessary here but the code is easier to read
- if (chainedFilter == null) chainedFilter = new ChainedFilter();
+ if ( chainedFilter == null ) {
+ chainedFilter = new ChainedFilter();
+ }
chainedFilter.addFilter( userFilter );
}
@@ -469,7 +477,9 @@
FilterDef def = searchFactoryImplementor.getFilterDefinition( fullTextFilter.getName() );
//def can never be null, ti's guarded by enableFullTextFilter(String)
- if ( isPreQueryFilterOnly(def) ) return null;
+ if ( isPreQueryFilterOnly( def ) ) {
+ return null;
+ }
Object instance = createFilterInstance( fullTextFilter, def );
FilterKey key = createFilterKey( def, instance );
@@ -753,7 +763,9 @@
}
//set up the searcher
- final DirectoryProvider[] directoryProviders = targetedDirectories.toArray( new DirectoryProvider[targetedDirectories.size()] );
+ final DirectoryProvider[] directoryProviders = targetedDirectories.toArray(
+ new DirectoryProvider[targetedDirectories.size()]
+ );
IndexSearcher is = new IndexSearcher(
searchFactoryImplementor.getReaderProvider().openReader(
directoryProviders
@@ -768,14 +780,14 @@
final DirectoryProvider[] directoryProviders;
if ( filterDefinitions != null && !filterDefinitions.isEmpty() ) {
directoryProviders = indexShardingStrategy.getDirectoryProvidersForQuery(
- filterDefinitions.values().toArray( new FullTextFilterImplementor[filterDefinitions.size()] )
+ filterDefinitions.values().toArray( new FullTextFilterImplementor[filterDefinitions.size()] )
);
}
else {
//no filter get all shards
directoryProviders = indexShardingStrategy.getDirectoryProvidersForQuery( EMPTY_FULL_TEXT_FILTER_IMPLEMENTOR );
}
-
+
for ( DirectoryProvider provider : directoryProviders ) {
if ( !directories.contains( provider ) ) {
directories.add( provider );
@@ -879,7 +891,7 @@
}
public Query setLockOptions(LockOptions lockOptions) {
- throw new UnsupportedOperationException( "Lock options are not implemented in Hibernate Search queries");
+ throw new UnsupportedOperationException( "Lock options are not implemented in Hibernate Search queries" );
}
@Override
@@ -889,11 +901,11 @@
return this;
}
- public <T> T unwrap(Class<T> type) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
+ public <T> T unwrap(Class<T> type) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
- protected LockOptions getLockOptions() {
+ protected LockOptions getLockOptions() {
return null;
}
16 years, 2 months
Hibernate SVN: r18815 - in search/trunk/src/main/java/org/hibernate/search: jpa/impl and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-02-16 17:19:53 -0500 (Tue, 16 Feb 2010)
New Revision: 18815
Modified:
search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java
search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextQueryImpl.java
search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
Log:
HSEARCH-422 support for jpa.FullTextQuery and add unwrap to the Hibernate FullTextQuery interface.
Modified: search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java 2010-02-16 21:39:52 UTC (rev 18814)
+++ search/trunk/src/main/java/org/hibernate/search/FullTextQuery.java 2010-02-16 22:19:53 UTC (rev 18815)
@@ -131,4 +131,9 @@
*/
FullTextQuery setResultTransformer(ResultTransformer transformer);
+ /**
+ * return the underlying type if possible
+ * TODO document what can be unwrapped
+ */
+ <T> T unwrap(Class<T> type);
}
Modified: search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextQueryImpl.java 2010-02-16 21:39:52 UTC (rev 18814)
+++ search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextQueryImpl.java 2010-02-16 22:19:53 UTC (rev 18815)
@@ -25,12 +25,7 @@
package org.hibernate.search.jpa.impl;
import java.io.Serializable;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.Map;
+import java.util.*;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityNotFoundException;
import javax.persistence.FlushModeType;
@@ -65,13 +60,21 @@
import org.hibernate.transform.ResultTransformer;
/**
+ * Implements JPA 2 query interface and delegate the call to
+ * a Hibernate Core FullTextQuery.
+ * This has the consequence of "duplicating" the JPA 2 query logic in some areas.
* @author Emmanuel Bernard
*/
public class FullTextQueryImpl implements FullTextQuery {
private final org.hibernate.search.FullTextQuery query;
private final Session session;
+ private Integer firstResult;
+ private Integer maxResults;
+ //initialized at 0 since we don't expect to use hints at this stage
+ private final Map<String, Object> hints = new HashMap<String, Object>(0);
+ private FlushModeType jpaFlushMode;
- public FullTextQueryImpl(org.hibernate.search.FullTextQuery query, Session session) {
+ public FullTextQueryImpl(org.hibernate.search.FullTextQuery query, Session session) {
this.query = query;
this.session = session;
}
@@ -230,20 +233,23 @@
}
}
- public Query setMaxResults(int maxResult) {
- if ( maxResult < 0 ) {
+ public Query setMaxResults(int maxResults) {
+ if ( maxResults < 0 ) {
throw new IllegalArgumentException(
"Negative ("
- + maxResult
+ + maxResults
+ ") parameter passed in to setMaxResults"
);
}
- query.setMaxResults( maxResult );
+ query.setMaxResults( maxResults );
+ this.maxResults = maxResults;
return this;
}
public int getMaxResults() {
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ return maxResults == null || maxResults == -1
+ ? Integer.MAX_VALUE
+ : maxResults;
}
public Query setFirstResult(int firstResult) {
@@ -255,11 +261,12 @@
);
}
query.setFirstResult( firstResult );
+ this.firstResult = firstResult;
return this;
}
public int getFirstResult() {
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ return firstResult == null ? 0 : firstResult;
}
public Explanation explain(int documentId) {
@@ -271,29 +278,26 @@
}
public Query setHint(String hintName, Object value) {
+ hints.put(hintName, value);
return this;
}
public Map<String, Object> getHints() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return hints;
}
public <T> Query setParameter(Parameter<T> tParameter, T t) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
public Query setParameter(Parameter<Calendar> calendarParameter, Calendar calendar, TemporalType temporalType) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
public Query setParameter(Parameter<Date> dateParameter, Date date, TemporalType temporalType) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- public Set<String> getSupportedHints() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
public Query setParameter(String name, Object value) {
throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
@@ -314,66 +318,48 @@
throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- public Query setParameter(int position, Calendar value, TemporalType temporalType) {
+ public Set<Parameter<?>> getParameters() {
+ return Collections.EMPTY_SET;
+ }
+
+ public Query setParameter(int position, Calendar value, TemporalType temporalType) {
throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- //FIXME remove old JPA 2 contract
- public Map<String, Object> getNamedParameters() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- //FIXME remove old JPA 2 contract
- public List getPositionalParameters() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- //FIXME
- public Set<Parameter<?>> getParameters() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- //FIXME
public Parameter<?> getParameter(String name) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- //FIXME
public Parameter<?> getParameter(int position) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- //FIXME
public <T> Parameter<T> getParameter(String name, Class<T> type) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- //FIXME
public <T> Parameter<T> getParameter(int position, Class<T> type) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- //FIXME
public boolean isBound(Parameter<?> param) {
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- //FIXME
public <T> T getParameterValue(Parameter<T> param) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- //FIXME
public Object getParameterValue(String name) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
- //FIXME
public Object getParameterValue(int position) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "parameters not supported in fullText queries");
}
public Query setFlushMode(FlushModeType flushMode) {
+ this.jpaFlushMode = flushMode;
if ( flushMode == FlushModeType.AUTO ) {
query.setFlushMode( FlushMode.AUTO );
}
@@ -384,18 +370,35 @@
}
public FlushModeType getFlushMode() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ if (jpaFlushMode != null) {
+ return jpaFlushMode;
+ }
+ final FlushMode hibernateFlushMode = session.getFlushMode();
+ if (FlushMode.AUTO == hibernateFlushMode) {
+ return FlushModeType.AUTO;
+ }
+ else if (FlushMode.COMMIT == hibernateFlushMode) {
+ return FlushModeType.COMMIT;
+ }
+ else {
+ return null; //incompatible flush mode
+ }
}
public Query setLockMode(LockModeType lockModeType) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "lock modes not supported in fullText queries");
}
public LockModeType getLockMode() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException( "lock modes not supported in fullText queries");
}
- public <T> T unwrap(Class<T> tClass) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ public <T> T unwrap(Class<T> type) {
+ if ( type.equals( org.hibernate.search.FullTextQuery.class ) ) {
+ return (T) query;
+ }
+ else {
+ return query.unwrap( type );
+ }
}
}
Modified: search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-02-16 21:39:52 UTC (rev 18814)
+++ search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2010-02-16 22:19:53 UTC (rev 18815)
@@ -889,7 +889,11 @@
return this;
}
- protected LockOptions getLockOptions() {
+ public <T> T unwrap(Class<T> type) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ protected LockOptions getLockOptions() {
return null;
}
16 years, 2 months
Hibernate SVN: r18814 - in core/trunk: testsuite/src/test/java/org/hibernate/test/hql and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-02-16 16:39:52 -0500 (Tue, 16 Feb 2010)
New Revision: 18814
Modified:
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
HHH-4917 - Keyword TYPE not supported
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java 2010-02-16 19:54:48 UTC (rev 18813)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/MethodNode.java 2010-02-16 21:39:52 UTC (rev 18814)
@@ -63,12 +63,34 @@
AST exprList = name.getNextSibling();
// If the expression list has exactly one expression, and the type of the expression is a collection
// then this might be a collection function, such as index(c) or size(c).
- if ( ASTUtil.hasExactlyOneChild( exprList ) && isCollectionPropertyMethod() ) {
- collectionProperty( exprList.getFirstChild(), name );
+ if ( ASTUtil.hasExactlyOneChild( exprList ) ) {
+ if ( "type".equals( methodName ) ) {
+ typeDiscriminator( exprList.getFirstChild() );
+ return;
+ }
+ if ( isCollectionPropertyMethod() ) {
+ collectionProperty( exprList.getFirstChild(), name );
+ return;
+ }
}
- else {
- dialectFunction( exprList );
+
+ dialectFunction( exprList );
+ }
+
+ private void typeDiscriminator(AST path) throws SemanticException {
+ if ( path == null ) {
+ throw new SemanticException( "type() discriminator reference has no path!" );
}
+
+ FromReferenceNode pathAsFromReferenceNode = (FromReferenceNode) path;
+ FromElement typeFromElement = pathAsFromReferenceNode.getFromElement();
+ Type type = typeFromElement.getPropertyType( "class", "class" );
+ setDataType( type );
+
+ String[] columns = typeFromElement.toColumns( typeFromElement.getTableAlias(), "class", inSelect );
+ setText( columns[0] );
+
+ setType( SqlTokenTypes.SQL_TOKEN );
}
public SQLFunction getSQLFunction() {
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-02-16 19:54:48 UTC (rev 18813)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-02-16 21:39:52 UTC (rev 18814)
@@ -106,6 +106,20 @@
return new FunctionalTestClassTestSuite( ASTParserLoadingTest.class );
}
+ public void testJpaTypeOperator() {
+ // just checking syntax here...
+ Session s = openSession();
+ s.beginTransaction();
+
+ // control
+ s.createQuery( "from Animal a where a.class = Dog" ).list();
+
+ s.createQuery( "from Animal a where type(a) = Dog" ).list();
+
+ s.getTransaction().commit();
+ s.close();
+ }
+
public void testComponentJoins() {
Session s = openSession();
s.beginTransaction();
16 years, 2 months
Hibernate SVN: r18813 - search/trunk/src/main/java/org/hibernate/search/jpa/impl.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-02-16 14:54:48 -0500 (Tue, 16 Feb 2010)
New Revision: 18813
Modified:
search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java
Log:
HSEARCH-422 support for FullTextEntityManager
Modified: search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java 2010-02-16 19:24:46 UTC (rev 18812)
+++ search/trunk/src/main/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java 2010-02-16 19:54:48 UTC (rev 18813)
@@ -135,16 +135,16 @@
return em.find( entityClass, primaryKey );
}
- public <T> T find(Class<T> tClass, Object o, Map<String, Object> stringObjectMap) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ public <T> T find(Class<T> entityClass, Object primaryKey, Map<String, Object> hints) {
+ return em.find(entityClass, primaryKey, hints);
}
- public <T> T find(Class<T> tClass, Object o, LockModeType lockModeType) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType) {
+ return em.find(entityClass, primaryKey, lockModeType);
}
- public <T> T find(Class<T> tClass, Object o, LockModeType lockModeType, Map<String, Object> stringObjectMap) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockModeType, Map<String, Object> hints) {
+ return em.find(entityClass, primaryKey, lockModeType, hints);
}
public <T> T getReference(Class<T> entityClass, Object primaryKey) {
@@ -167,48 +167,48 @@
em.lock( entity, lockMode );
}
- public void lock(Object o, LockModeType lockModeType, Map<String, Object> stringObjectMap) {
- //To change body of implemented methods use File | Settings | File Templates.
+ public void lock(Object entity, LockModeType lockModeType, Map<String, Object> hints) {
+ em.lock(entity, lockModeType, hints);
}
public void refresh(Object entity) {
em.refresh( entity );
}
- public void refresh(Object o, Map<String, Object> stringObjectMap) {
- //To change body of implemented methods use File | Settings | File Templates.
+ public void refresh(Object entity, Map<String, Object> hints) {
+ em.refresh(entity, hints);
}
- public void refresh(Object o, LockModeType lockModeType) {
- //To change body of implemented methods use File | Settings | File Templates.
+ public void refresh(Object entity, LockModeType lockModeType) {
+ em.refresh(entity, lockModeType);
}
- public void refresh(Object o, LockModeType lockModeType, Map<String, Object> stringObjectMap) {
- //To change body of implemented methods use File | Settings | File Templates.
+ public void refresh(Object entity, LockModeType lockModeType, Map<String, Object> hints) {
+ em.refresh(entity, lockModeType, hints);
}
public void clear() {
em.clear();
}
- public void detach(Object o) {
- //To change body of implemented methods use File | Settings | File Templates.
+ public void detach(Object entity) {
+ em.detach(entity);
}
public boolean contains(Object entity) {
return em.contains( entity );
}
- public LockModeType getLockMode(Object o) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ public LockModeType getLockMode(Object entity) {
+ return em.getLockMode(entity);
}
- public void setProperty(String s, Object o) {
- //To change body of implemented methods use File | Settings | File Templates.
+ public void setProperty(String key, Object value) {
+ em.setProperty(key, value);
}
public Map<String, Object> getProperties() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return em.getProperties();
}
public Query createQuery(String ejbqlString) {
@@ -247,8 +247,15 @@
em.joinTransaction();
}
- public <T> T unwrap(Class<T> tClass) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ public <T> T unwrap(Class<T> type) {
+ if (type.equals( FullTextSession.class ) ) {
+ @SuppressWarnings("unchecked")
+ final T ftSession = (T) Search.getFullTextSession(em.unwrap(Session.class));
+ return ftSession;
+ }
+ else {
+ return em.unwrap(type);
+ }
}
public Object getDelegate() {
@@ -268,18 +275,17 @@
}
public EntityManagerFactory getEntityManagerFactory() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return em.getEntityManagerFactory();
}
public CriteriaBuilder getCriteriaBuilder() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return em.getCriteriaBuilder();
}
public Metamodel getMetamodel() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return em.getMetamodel();
}
-
public MassIndexer createIndexer(Class<?>... types) {
return getFullTextSession().createIndexer( types );
}
16 years, 2 months
Hibernate SVN: r18812 - in search/trunk/src: test/java/org/hibernate/search/test/bridge and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-02-16 14:24:46 -0500 (Tue, 16 Feb 2010)
New Revision: 18812
Added:
search/trunk/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java
search/trunk/src/test/java/org/hibernate/search/test/bridge/Student.java
search/trunk/src/test/java/org/hibernate/search/test/bridge/StudentsSizeBridge.java
search/trunk/src/test/java/org/hibernate/search/test/bridge/Teacher.java
Modified:
search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
Log:
HSEARCH-372 support for projection of the ClassBridges (assuming the name is provided explicitly)
Modified: search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2010-02-16 17:44:06 UTC (rev 18811)
+++ search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderIndexedEntity.java 2010-02-16 19:24:46 UTC (rev 18812)
@@ -673,6 +673,7 @@
}
private static void processFieldsForProjection(PropertiesMetadata metadata, String[] fields, Object[] result, Document document) {
+ //process base fields
final int nbrFoEntityFields = metadata.fieldNames.size();
for ( int index = 0; index < nbrFoEntityFields; index++ ) {
populateResult(
@@ -684,6 +685,8 @@
document
);
}
+
+ //process fields of embedded
final int nbrOfEmbeddedObjects = metadata.embeddedPropertiesMetadata.size();
for ( int index = 0; index < nbrOfEmbeddedObjects; index++ ) {
//there is nothing we can do for collections
@@ -693,6 +696,19 @@
);
}
}
+
+ //process class bridges
+ final int nbrOfClassBridges = metadata.classBridges.size();
+ for ( int index = 0; index < nbrOfClassBridges; index++ ) {
+ populateResult(
+ metadata.classNames.get(index),
+ metadata.classBridges.get(index),
+ metadata.classStores.get(index),
+ fields,
+ result,
+ document
+ );
+ }
}
private static int getFieldPosition(String[] fields, String fieldName) {
@@ -721,5 +737,11 @@
return;
}
}
+ for ( FieldBridge bridge : metadata.classBridges ) {
+ if ( !( bridge instanceof TwoWayStringBridge || bridge instanceof TwoWayString2FieldBridgeAdaptor ) ) {
+ allowFieldSelectionInProjection = false;
+ return;
+ }
+ }
}
}
Added: search/trunk/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java 2010-02-16 19:24:46 UTC (rev 18812)
@@ -0,0 +1,76 @@
+package org.hibernate.search.test.bridge;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.util.Version;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.search.FullTextQuery;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.test.SearchTestCase;
+
+import java.util.List;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ClassBridgeAndProjectionTest extends SearchTestCase {
+
+ public void testClassBridgeProjection() throws Exception {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+
+ // create entities
+ Teacher teacher = new Teacher();
+ teacher.setName("John Smith");
+ s.persist(teacher);
+
+ Student student1 = new Student();
+ student1.setGrade("foo");
+ student1.setName("Jack Miller");
+ student1.setTeacher(teacher);
+ teacher.getStudents().add(student1);
+ s.persist(student1);
+
+ Student student2 = new Student();
+ student2.setGrade("bar");
+ student2.setName("Steve Marshall");
+ student2.setTeacher(teacher);
+ teacher.getStudents().add(student2);
+ s.persist(student2);
+
+ tx.commit();
+
+ // test query without projection
+ FullTextSession ftSession = Search.getFullTextSession( s );
+ QueryParser parser = new QueryParser(
+ Version.LUCENE_CURRENT,
+ "name",
+ new StandardAnalyzer(Version.LUCENE_CURRENT) );
+ FullTextQuery query = ftSession.createFullTextQuery(parser.parse("name:John"), Teacher.class);
+ List results = query.list();
+ assertNotNull(results);
+ assertTrue(results.size() == 1);
+ assertTrue(((Teacher) results.get(0)).getStudents().size() == 2);
+
+ // now test with projection
+ query.setProjection("amount_of_students");
+ results = query.list();
+ assertNotNull(results);
+ assertTrue(results.size() == 1);
+ Object[] firstResult = (Object[]) results.get(0);
+ Integer amountStudents = (Integer) firstResult[0];
+ assertEquals(new Integer(2), amountStudents);
+
+ s.close();
+ }
+
+ @Override
+ protected Class<?>[] getMappings() {
+ return new Class<?>[] {
+ Student.class,
+ Teacher.class
+ };
+ }
+}
Added: search/trunk/src/test/java/org/hibernate/search/test/bridge/Student.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/bridge/Student.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/bridge/Student.java 2010-02-16 19:24:46 UTC (rev 18812)
@@ -0,0 +1,67 @@
+package org.hibernate.search.test.bridge;
+
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.Store;
+
+import javax.persistence.*;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Indexed
+@Table(name = "student")
+public class Student {
+
+
+ private Long id;
+ private String name;
+ private String grade;
+ private Teacher teacher;
+
+
+ @Id
+ @GeneratedValue
+ @Column(name = "student_id")
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @Column(name = "name")
+ @Field(index = Index.TOKENIZED, store = Store.YES)
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Column(name = "grade")
+ @Field(index = Index.UN_TOKENIZED, store = Store.YES)
+ public String getGrade() {
+ return grade;
+ }
+
+ public void setGrade(String grade) {
+ this.grade = grade;
+ }
+
+ @ManyToOne
+ @JoinColumn(name = "teacher_id")
+ public Teacher getTeacher() {
+ return teacher;
+ }
+
+ public void setTeacher(Teacher teacher) {
+ this.teacher = teacher;
+ }
+
+}
+
Added: search/trunk/src/test/java/org/hibernate/search/test/bridge/StudentsSizeBridge.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/bridge/StudentsSizeBridge.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/bridge/StudentsSizeBridge.java 2010-02-16 19:24:46 UTC (rev 18812)
@@ -0,0 +1,30 @@
+package org.hibernate.search.test.bridge;
+
+import org.hibernate.search.bridge.TwoWayStringBridge;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class StudentsSizeBridge implements TwoWayStringBridge {
+
+ public Object stringToObject(String stringValue) {
+ if (null == stringValue || stringValue.equals("")) {
+ return 0;
+ }
+ return Integer.parseInt(stringValue);
+ }
+
+ public String objectToString(Object object) {
+ if (object instanceof Teacher) {
+ Teacher teacher = (Teacher) object;
+ if (teacher.getStudents() != null && teacher.getStudents().size() > 0)
+ return String.valueOf(teacher.getStudents().size());
+ else
+ return null;
+ } else {
+ throw new IllegalArgumentException(StudentsSizeBridge.class +
+ " used on a non-Teacher type: " + object.getClass());
+ }
+ }
+
+}
Added: search/trunk/src/test/java/org/hibernate/search/test/bridge/Teacher.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/bridge/Teacher.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/bridge/Teacher.java 2010-02-16 19:24:46 UTC (rev 18812)
@@ -0,0 +1,63 @@
+package org.hibernate.search.test.bridge;
+
+import org.hibernate.search.annotations.*;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Indexed
+@Table(name = "teacher")
+@ClassBridge(
+ name = "amount_of_students",
+ index = Index.UN_TOKENIZED,
+ store = Store.YES,
+ impl = StudentsSizeBridge.class
+)
+public class Teacher {
+
+ private Long id;
+ private String name;
+ private List<Student> students;
+
+
+ public Teacher() {
+ students = new ArrayList<Student>();
+ }
+
+ @Id
+ @GeneratedValue
+ @Column(name = "teacher_id")
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @Column(name = "name")
+ @Field(index = Index.TOKENIZED, store = Store.YES)
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @OneToMany(mappedBy = "teacher")
+ public List<Student> getStudents() {
+ return students;
+ }
+
+ public void setStudents(List<Student> students) {
+ this.students = students;
+ }
+
+}
+
16 years, 2 months
Hibernate SVN: r18811 - in jpamodelgen/trunk: src/main/assembly and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-02-16 12:44:06 -0500 (Tue, 16 Feb 2010)
New Revision: 18811
Modified:
jpamodelgen/trunk/pom.xml
jpamodelgen/trunk/src/main/assembly/dist.xml
jpamodelgen/trunk/src/main/docbook/en-US/master.xml
Log:
METAGEN-4 - Completed first cut of docs and changed the mave nassembly to include the generated documentation into the dist bundle
Modified: jpamodelgen/trunk/pom.xml
===================================================================
--- jpamodelgen/trunk/pom.xml 2010-02-15 22:40:30 UTC (rev 18810)
+++ jpamodelgen/trunk/pom.xml 2010-02-16 17:44:06 UTC (rev 18811)
@@ -236,15 +236,6 @@
<descriptor>src/main/assembly/dist.xml</descriptor>
</descriptors>
</configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>site</phase>
- <goals>
- <goal>assembly</goal>
- </goals>
- </execution>
- </executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -254,7 +245,7 @@
<autoVersionSubmodules>true</autoVersionSubmodules>
<allowTimestampedSnapshots>true</allowTimestampedSnapshots>
<remoteTagging>true</remoteTagging>
- <goals>package deploy</goals>
+ <goals>package deploy javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:resources org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:generate assembly:assembly</goals>
</configuration>
</plugin>
<plugin>
Modified: jpamodelgen/trunk/src/main/assembly/dist.xml
===================================================================
--- jpamodelgen/trunk/src/main/assembly/dist.xml 2010-02-15 22:40:30 UTC (rev 18810)
+++ jpamodelgen/trunk/src/main/assembly/dist.xml 2010-02-16 17:44:06 UTC (rev 18811)
@@ -22,7 +22,6 @@
<id>dist</id>
<formats>
<format>tar.gz</format>
- <format>tar.bz2</format>
<format>zip</format>
</formats>
@@ -34,22 +33,6 @@
</dependencySet>
</dependencySets>
- <files>
- <file>
- <source>readme.txt</source>
- <outputDirectory>/</outputDirectory>
- <filtered>true</filtered>
- </file>
- <file>
- <source>license.txt</source>
- <outputDirectory>/</outputDirectory>
- </file>
- <file>
- <source>issues.txt</source>
- <outputDirectory>/</outputDirectory>
- </file>
- </files>
-
<fileSets>
<fileSet>
<directory>target</directory>
@@ -67,15 +50,16 @@
<outputDirectory>docs/api</outputDirectory>
</fileSet>
<fileSet>
+ <directory>target/docbook/publish</directory>
+ <outputDirectory>docs/reference</outputDirectory>
+ </fileSet>
+ <fileSet>
<directory>.</directory>
<outputDirectory/>
<useDefaultExcludes>true</useDefaultExcludes>
<excludes>
- <exclude>*.txt</exclude>
<exclude>**/target/**</exclude>
- <exclude>*.iml</exclude>
</excludes>
</fileSet>
</fileSets>
-
</assembly>
Modified: jpamodelgen/trunk/src/main/docbook/en-US/master.xml
===================================================================
--- jpamodelgen/trunk/src/main/docbook/en-US/master.xml 2010-02-15 22:40:30 UTC (rev 18810)
+++ jpamodelgen/trunk/src/main/docbook/en-US/master.xml 2010-02-16 17:44:06 UTC (rev 18811)
@@ -71,9 +71,10 @@
@OneToMany
Set<Item> items;
BigDecimal totalCost;
+
+ // standard setter/getter methods
...
-}
-</programlisting>
+}</programlisting>
</example>
<example id="metamodel-class-example">
@@ -86,15 +87,14 @@
public static volatile SingularAttribute<Order, Customer> customer;
public static volatile SetAttribute<Order, Item> items;
public static volatile SingularAttribute<Order, BigDecimal> totalCost;
-}
-</programlisting>
+}</programlisting>
</example>
<example id="criteria-example" label="">
<title>Example of typesafe query using the metamodel class
<classname>Order_</classname> </title>
- <programlisting>CriteriaBuilder cb = ordersEntityManager.getCriteriaBuilder();
+ <programlisting>CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Order> cq = cb.createQuery(Order.class);
SetJoin<Order, Item> itemNode = cq.from(Order.class).join(Order_.orderItems);
cq.where( cb.equal(itemNode.get(Item_.id), 5 ) ).distinct(true);
@@ -105,14 +105,20 @@
<section>
<title>Canonical Metamodel</title>
- <para>The canonical metamodel classes the annotation processor produces
- for every managed class in the persistence unit follow these rules
- defined in the JPA 2 specification:</para>
+ <para>The structure of the metamodel classes is described in the <ulink
+ url="http://jcp.org/en/jsr/detail?id=317">JPA 2 specification</ulink>
+ and its definition is included for completeness in the following
+ paragraphs . Feel free to skip ahead to <xref linkend="chapter-usage" />
+ if you are not interested into the gory details. </para>
+ <para>The annotation processor produces for every managed class in the
+ persistence unit a metamodel class based on these rules:</para>
+
<para><itemizedlist>
<listitem>
- <para>For each managed class X in package p, a metamodel class X_
- in package p is created.</para>
+ <para>For each managed class <classname>X</classname> in package
+ p, a metamodel class <classname>X_</classname> in package p is
+ created.</para>
</listitem>
<listitem>
@@ -122,27 +128,34 @@
</listitem>
<listitem>
- <para>The metamodel class X_ must be annotated with the
- javax.persistence.Static- Metamodel annotation.</para>
+ <para>The metamodel class <classname>X_</classname> must be
+ annotated with the
+ <classname>javax.persistence.StaticMetamodel</classname>
+ annotation.</para>
</listitem>
<listitem>
- <para>If class X extends another class S, where S is the most
- derived managed class (i.e., entity or mapped superclass) extended
- by X, then class X_ must extend class S_, where S_ is the
- metamodel class created for S.</para>
+ <para>If class <classname>X</classname> extends another class
+ <classname>S</classname>, where <classname>S</classname> is the
+ most derived managed class (i.e., entity or mapped superclass)
+ extended by <classname>X</classname>, then class
+ <classname>X_</classname> must extend class
+ <classname>S_</classname>, where <classname>S_</classname> is the
+ metamodel class created for <classname>S</classname>.</para>
</listitem>
<listitem>
<para>For every persistent non-collection-valued attribute y
- declared by class X, where the type of y is Y, the metamodel class
- must contain a declaration as follows: <programlisting>public static volatile SingularAttribute<X, Y> y;</programlisting></para>
+ declared by class <classname>X</classname>, where the type of y is
+ <classname>Y</classname>, the metamodel class must contain a
+ declaration as follows: <programlisting>public static volatile SingularAttribute<X, Y> y;</programlisting></para>
</listitem>
<listitem>
<para>For every persistent collection-valued attribute z declared
- by class X, where the element type of z is Z, the metamodel class
- must contain a declaration as follows:<itemizedlist>
+ by class <classname>X</classname>, where the element type of z is
+ <classname>Z</classname>, the metamodel class must contain a
+ declaration as follows:<itemizedlist>
<listitem>
<para>if the collection type of z is java.util.Collection,
then <programlisting>public static volatile CollectionAttribute<X, Z> z;</programlisting></para>
@@ -172,19 +185,12 @@
</section>
</chapter>
- <chapter>
+ <chapter id="chapter-usage">
<title>Usage</title>
- <para>In most cases the annotation processor will automatically run
- provided the annotation processor jar is on the classpath. This happens
- due to Java's Service Provider contract and the fact the the Hibernate
- Static Metamodel Generator jar files contains the file
- <classname>javax.annotation.processing.Processor</classname> in the
- <filename>META-INF/services</filename> listing
- <classname>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</classname>
- as annotation processor. However, a JDK 6 is a prerequisite. The jar file
- itself can be found in the <ulink url="http://repository.jboss.com/">JBoss
- Maven repository</ulink> under:</para>
+ <para> The jar file for the annotation processor can be found in the
+ <ulink url="http://repository.jboss.com/">JBoss Maven repository</ulink>
+ under:</para>
<example id="maven-dependency" label="">
<title>Maven dependency for Hibernate Static Metamodel Generator</title>
@@ -193,26 +199,62 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.0.0</version>
-</dependency>
-</programlisting>
+</dependency></programlisting>
</example>
+ <para>Alternatively, a full distribution package can be downloaded from
+ <ulink url="http://sourceforge.net/">SourceForge</ulink>.</para>
+
+ <para>In most cases the annotation processor will automatically run
+ provided a JDK version 6i used and the jar file is added to the classpath.
+ This happens due to <ulink
+ url="http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html#Service%20Provider">Java's
+ Service Provider</ulink> contract and the fact the the Hibernate Static
+ Metamodel Generator jar files contains the file
+ <classname>javax.annotation.processing.Processor</classname> in the
+ <filename>META-INF/services</filename> directory. The fully qualified name
+ of the processor itself is:
+ <classname>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</classname>.
+ <note>
+ <para>The use of a Java 6 compiler is a prerequisite.</para>
+ </note></para>
+
<section>
<title>Usage from the command line</title>
- <para><section revision="1">
+ <para><section id="usage-ant" revision="1">
<title>Usage with Ant</title>
</section>As mentioned before, the annotation processor will run
- automatically in a Java 6 environment. In case you want configure the
- processor explicitly or disable it you can use the compilerarg option of
- the Javac Task. The supported command javac line options are listed
- here. <section revision="1">
+ automatically each time the Java compiler is called - provided the jar
+ file is on the classpath. Somtimes it is, however, useful to control the
+ annotation processing in more detail, for example if you exclusively
+ want to run the processor without compiling any other source files.
+ <xref linkend="javac-task-example" /> shows how the <ulink
+ url="http://ant.apache.org/manual/CoreTasks/javac.html">Ant Javac
+ Task</ulink> can be configured to just run annotation
+ processing.<example id="javac-task-example">
+ <title>Ant Javac Task configuration </title>
+
+ <programlisting><javac srcdir="${src.dir}"
+ destdir="${target.dir}"
+ failonerror="false"
+ fork="true"
+ classpath="${classpath}">
+ <emphasis role="bold"><compilerarg value="-proc:only"/></emphasis>
+</javac></programlisting>
+ </example>The option <emphasis>-proc:only</emphasis> instructs the
+ compiler to just run the annotation processing. You can also completely
+ disable processing by specifying <emphasis>-proc:none</emphasis>.<tip>
+ <para>Run <literal>'javac -help'</literal> to see which other
+ annotation processor relevant options can be specified.</para>
+ </tip><section revision="1">
<title>Usage with Maven</title>
</section>There are several ways of running the annotation processor
- as part of a Maven build. It will automatically run if you are using a
- JDK 6 compiler and the annotation processor jar is on the classpath. In
- case you have more than one annotation processors on your classpath you
- can explicitly pass the processor option to the compiler plugin:</para>
+ as part of a Maven build. Again, it will automatically run if you are
+ using a JDK 6 compiler and the annotation processor jar is on the
+ classpath. In case you have more than one annotation processors on your
+ classpath you can explicitly pass the processor option to the compiler
+ plugin:</para>
<para><example>
<title>Maven compiler plugin configuration - direct
@@ -224,7 +266,7 @@
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
- <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
+ <emphasis role="bold"><processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor></emphasis>
</compilerArguments>
</configuration>
</plugin></programlisting>
@@ -232,11 +274,15 @@
<para>The maven-compiler-plugin approach has the disadvantage that the
maven compiler plugin does currently not allow to specify multiple
- compiler arguments (MCOMPILER-62) and that messages from the Messenger
- API are suppressed (MCOMPILER-66). A better approach is to disable
- annotation processing for the compiler plugin:</para>
+ compiler arguments (<ulink
+ url="http://jira.codehaus.org/browse/MCOMPILER-62">MCOMPILER-62</ulink>)
+ and that messages from the Messenger API are suppressed (<ulink
+ url="http://jira.codehaus.org/browse/MCOMPILER-66">MCOMPILER-66</ulink>).
+ A better approach is to disable annotation processing for the compiler
+ plugin as seen in <xref
+ linkend="disable-processing-maven-compiler-plugin" />.</para>
- <example>
+ <example id="disable-processing-maven-compiler-plugin">
<title>Maven compiler plugin configuration - indirect
execution</title>
@@ -245,16 +291,22 @@
<configuration>
<source>1.6</source>
<target>1.6</target>
- <compilerArgument>-proc:none</compilerArgument>
+ <emphasis role="bold"><compilerArgument>-proc:none</compilerArgument></emphasis>
</configuration>
</plugin></programlisting>
</example>
- <para>and use the maven-annotation-plugin for annotation processing (you
- will need the following additional maven repositories -
- maven-annotation-plugin and jfrog):</para>
+ <para>Once disabled, the <ulink
+ url="http://code.google.com/p/maven-annotation-plugin/">maven-annotation-plugin</ulink>
+ for annotation processing (you will need the following additional maven
+ repositories - <ulink
+ url="http://maven-annotation-plugin.googlecode.com/svn/trunk/mavenrepo">maven-annotation-plugin</ulink>
+ and <ulink
+ url="http://www.jfrog.org/artifactory/plugins-releases">jfrog</ulink>)
+ can be used. The configuration can be seen in <xref
+ linkend="maven-processor-plugin" />.</para>
- <example>
+ <example id="maven-processor-plugin">
<title>Maven compiler plugin configuration with
maven-annotation-plugin</title>
@@ -308,6 +360,11 @@
<section>
<title>Idea</title>
+ <para>Intellij Idea contains from version 9.x onwards a specifc
+ configuration section for annotation processing under the project
+ settings window. The screenshots show you how to configure the
+ Hibernate Static Metamodel Generator.</para>
+
<mediaobject>
<imageobject role="fo">
<imagedata align="center" contentdepth="" contentwidth="150mm"
@@ -325,11 +382,11 @@
<section>
<title>Eclipse</title>
- <para>In Eclipse from the Galileo release onwards exists an additional
- configuration section under Java Compiler where you can configure all
- kinds of aspects of annotation processing. Just check the "Enable
- annotation processing" option, configure the directory for the
- generated sources and finally add the Hibernate Static Metamodel
+ <para>In Eclipse, from the Galileo release onwards, exists an
+ additional configuration section under Java Compiler. There you can
+ configure all kinds of aspects of annotation processing. Just check
+ the "Enable annotation processing" option, configure the directory for
+ the generated sources and finally add the Hibernate Static Metamodel
Generator and JPA 2 jar files to the factory path.</para>
<mediaobject>
@@ -355,10 +412,10 @@
</section>
<section>
- <title>Options</title>
+ <title>Processor specific options</title>
- <para>The annotaton processor accepts a series of custom properties
- which can be passed to the processor execution in the format
+ <para>The Hibernate Static Metamodel Generator accepts a series of
+ custom options which can be passed to the processor in the format
<literal>-A[property]=[value]</literal>. The supported properties
are:<table>
<title>Annotation processor options (passed via
@@ -367,9 +424,10 @@
<tgroup cols="2">
<tbody>
<row>
- <entry>Option name</entry>
+ <entry><emphasis role="bold">Option name</emphasis></entry>
- <entry>Option value and usage</entry>
+ <entry><emphasis role="bold">Option value and
+ usage</emphasis></entry>
</row>
<row>
@@ -402,4 +460,15 @@
</table></para>
</section>
</chapter>
+
+ <appendix>
+ <title>Further information</title>
+
+ <para>For further usage question or problems consult the <ulink
+ url="https://forum.hibernate.org/viewforum.php?f=9">Hibernate
+ Forum</ulink>. For bug reports use the <ulink
+ url="http://opensource.atlassian.com/projects/hibernate/browse/METAGEN"
+ userlevel="">METAGEN</ulink> project in the Hibernate Jira instance.
+ Feedback is always welcome.</para>
+ </appendix>
</book>
16 years, 2 months
Hibernate SVN: r18810 - jpamodelgen/trunk/src/main/docbook/en-US.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-02-15 17:40:30 -0500 (Mon, 15 Feb 2010)
New Revision: 18810
Modified:
jpamodelgen/trunk/src/main/docbook/en-US/master.xml
Log:
METAGEN-4
Modified: jpamodelgen/trunk/src/main/docbook/en-US/master.xml
===================================================================
--- jpamodelgen/trunk/src/main/docbook/en-US/master.xml 2010-02-15 21:11:47 UTC (rev 18809)
+++ jpamodelgen/trunk/src/main/docbook/en-US/master.xml 2010-02-15 22:40:30 UTC (rev 18810)
@@ -49,20 +49,126 @@
<section id="whatisit" revision="1">
<title>What is it about?</title>
- <para>Hibernate Static Metamodel Generator is an annotation processor
- with the task of creating the static metamodel classes for JPA 2
- entities. In the following I will show how to integrate the annotation
- processor into your build environment.</para>
+ <para>JPA 2 defines a new typesafe <classname>Criteria</classname> API
+ which allows criteria queries to be constructed in a strongly-typed
+ manner, using metamodel objects to provide type safety. This type saftey
+ is of course only useful for developers if the task of the metamodel
+ generation can be automated. Hibernate Static Metamodel Generator is an
+ annotation processor based on the annotation processing API defined in
+ <ulink url="???">JSR 269</ulink> with the task of creating the static
+ metamodel classes for JPA 2 entities. The following examples show a
+ managed JPA 2 entity, together with is metamodel class and an example
+ typesafe query.</para>
+
+ <example id="jpa2-entity-example">
+ <title>JPA 2 annotated entity</title>
+
+ <programlisting>@Entity public class Order {
+ @Id
+ Integer id;
+ @ManyToOne
+ Customer customer;
+ @OneToMany
+ Set<Item> items;
+ BigDecimal totalCost;
+ ...
+}
+</programlisting>
+ </example>
+
+ <example id="metamodel-class-example">
+ <title>Matching metamodel class for entity
+ <classname>Order</classname></title>
+
+ <programlisting>@StaticMetamodel(Order.class)
+public class Order_ {
+ public static volatile SingularAttribute<Order, Integer> id;
+ public static volatile SingularAttribute<Order, Customer> customer;
+ public static volatile SetAttribute<Order, Item> items;
+ public static volatile SingularAttribute<Order, BigDecimal> totalCost;
+}
+</programlisting>
+ </example>
+
+ <example id="criteria-example" label="">
+ <title>Example of typesafe query using the metamodel class
+ <classname>Order_</classname> </title>
+
+ <programlisting>CriteriaBuilder cb = ordersEntityManager.getCriteriaBuilder();
+CriteriaQuery<Order> cq = cb.createQuery(Order.class);
+SetJoin<Order, Item> itemNode = cq.from(Order.class).join(Order_.orderItems);
+cq.where( cb.equal(itemNode.get(Item_.id), 5 ) ).distinct(true);
+</programlisting>
+ </example>
</section>
- <section id="installation" revision="1">
- <title>Installation</title>
+ <section>
+ <title>Canonical Metamodel</title>
- <para><section revision="1">
- <title>Prerequisites</title>
+ <para>The canonical metamodel classes the annotation processor produces
+ for every managed class in the persistence unit follow these rules
+ defined in the JPA 2 specification:</para>
- <para />
- </section></para>
+ <para><itemizedlist>
+ <listitem>
+ <para>For each managed class X in package p, a metamodel class X_
+ in package p is created.</para>
+ </listitem>
+
+ <listitem>
+ <para>The name of the metamodel class is derived from the name of
+ the managed class by appending "_" to the name of the managed
+ class.</para>
+ </listitem>
+
+ <listitem>
+ <para>The metamodel class X_ must be annotated with the
+ javax.persistence.Static- Metamodel annotation.</para>
+ </listitem>
+
+ <listitem>
+ <para>If class X extends another class S, where S is the most
+ derived managed class (i.e., entity or mapped superclass) extended
+ by X, then class X_ must extend class S_, where S_ is the
+ metamodel class created for S.</para>
+ </listitem>
+
+ <listitem>
+ <para>For every persistent non-collection-valued attribute y
+ declared by class X, where the type of y is Y, the metamodel class
+ must contain a declaration as follows: <programlisting>public static volatile SingularAttribute<X, Y> y;</programlisting></para>
+ </listitem>
+
+ <listitem>
+ <para>For every persistent collection-valued attribute z declared
+ by class X, where the element type of z is Z, the metamodel class
+ must contain a declaration as follows:<itemizedlist>
+ <listitem>
+ <para>if the collection type of z is java.util.Collection,
+ then <programlisting>public static volatile CollectionAttribute<X, Z> z;</programlisting></para>
+ </listitem>
+
+ <listitem>
+ <para>if the collection type of z is java.util.Set, then
+ <programlisting>public static volatile SetAttribute<X, Z> z;</programlisting></para>
+ </listitem>
+
+ <listitem>
+ <para>if the collection type of z is java.util.List, then
+ <programlisting>public static volatile ListAttribute<X, Z> z;</programlisting></para>
+ </listitem>
+
+ <listitem>
+ <para>if the collection type of z is java.util.Map, then
+ <programlisting>public static volatile MapAttribute<X, K, Z> z;</programlisting>
+ where K is the type of the key of the map in class X</para>
+ </listitem>
+ </itemizedlist></para>
+ </listitem>
+ </itemizedlist>Import statements must be included for the needed
+ <classname>javax.persistence.metamodel</classname> types as appropriate
+ and all classes <classname>X</classname>, <classname>Y</classname>,
+ <classname>Z</classname>, and <classname>K</classname>.</para>
</section>
</chapter>
@@ -76,8 +182,21 @@
<classname>javax.annotation.processing.Processor</classname> in the
<filename>META-INF/services</filename> listing
<classname>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</classname>
- as annotation processor.</para>
+ as annotation processor. However, a JDK 6 is a prerequisite. The jar file
+ itself can be found in the <ulink url="http://repository.jboss.com/">JBoss
+ Maven repository</ulink> under:</para>
+ <example id="maven-dependency" label="">
+ <title>Maven dependency for Hibernate Static Metamodel Generator</title>
+
+ <programlisting><dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-jpamodelgen</artifactId>
+ <version>1.0.0</version>
+</dependency>
+</programlisting>
+ </example>
+
<section>
<title>Usage from the command line</title>
@@ -181,6 +300,11 @@
<section>
<title>Usage within the IDE</title>
+ <para>Of course you also want to have annotation processing available in
+ your favorite IDE. The following paragraphs and screenshots show you how
+ to enable the Hibernate Static Metamodel Generator within your
+ IDE.</para>
+
<section>
<title>Idea</title>
@@ -196,13 +320,18 @@
scalefit="1" />
</imageobject>
</mediaobject>
-
- <para></para>
</section>
<section>
<title>Eclipse</title>
+ <para>In Eclipse from the Galileo release onwards exists an additional
+ configuration section under Java Compiler where you can configure all
+ kinds of aspects of annotation processing. Just check the "Enable
+ annotation processing" option, configure the directory for the
+ generated sources and finally add the Hibernate Static Metamodel
+ Generator and JPA 2 jar files to the factory path.</para>
+
<mediaobject>
<imageobject role="fo">
<imagedata align="center" contentdepth="" contentwidth="150mm"
@@ -221,14 +350,7 @@
<section>
<title>NetBeans</title>
- <para>Of course you also want to have annotation processing available
- in your favorite IDE. In Eclipse (at least since the latest Galileo
- release) exists an additional configuration section under Java
- Compiler where you can configure all kinds of aspects of annotation
- processing. Just check the "Enable annotation processing" option,
- configure the directory for the generated sources and finally add the
- Hibernate Static Metamodel Generator and JPA 2 jar files to the
- factory path.</para>
+ <para>TODO</para>
</section>
</section>
16 years, 2 months