Hibernate SVN: r18453 - search/trunk/src/test/java/org/hibernate/search/test/query/dsl.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-01-08 11:07:05 -0500 (Fri, 08 Jan 2010)
New Revision: 18453
Removed:
search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java
Log:
fixing the build: removed test involving a removed class QueryContext
Deleted: search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java 2010-01-08 11:56:10 UTC (rev 18452)
+++ search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java 2010-01-08 16:07:05 UTC (rev 18453)
@@ -1,29 +0,0 @@
-package org.hibernate.search.test.query.dsl;
-
-import org.hibernate.search.test.SearchTestCase;
-import org.hibernate.search.test.query.Person;
-
-/**
- * Test Class for {@link org.hibernate.search.query.dsl.QueryContext}
- *
- * @author Navin Surtani
- */
-
-
-public class QueryContextTest extends SearchTestCase {
-
- protected Class<?>[] getMappings() {
- Class[] clazz = new Class[1];
- clazz[0] = Person.class;
- return clazz;
- }
-
- public void testSameInstance(){
- QueryContext qc = new QueryContext();
-
- QueryContext qc2 = qc.search("findStuff");
-
- assert qc.equals(qc2);
- }
-
-}
14 years, 7 months
Hibernate SVN: r18452 - search/trunk/src/main/java/org/hibernate/search/query/dsl.
by hibernate-commits@lists.jboss.org
Author: navssurtani
Date: 2010-01-08 06:56:10 -0500 (Fri, 08 Jan 2010)
New Revision: 18452
Modified:
search/trunk/src/main/java/org/hibernate/search/query/dsl/BooleanContext.java
search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java
search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnSearch.java
Log:
Added in some comments and to-do's that I missed out.
Modified: search/trunk/src/main/java/org/hibernate/search/query/dsl/BooleanContext.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/BooleanContext.java 2010-01-08 11:46:29 UTC (rev 18451)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/BooleanContext.java 2010-01-08 11:56:10 UTC (rev 18452)
@@ -8,7 +8,7 @@
import java.util.List;
/**
- * // TODO: Document this
+ * Class that allows users to create BooleanQueries.
*
* @author Navin Surtani
*/
Modified: search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java 2010-01-08 11:46:29 UTC (rev 18451)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java 2010-01-08 11:56:10 UTC (rev 18452)
@@ -3,8 +3,10 @@
import org.apache.lucene.search.BooleanClause;
/**
- * // TODO: Document this
+ * Starting class that will allow users to build their queries using the DSL.
*
+ * //TODO: This needs to be tied into the SearchFactory somehow so that users can actually "access" it.
+ *
* @author Navin Surtani
*/
Modified: search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnSearch.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnSearch.java 2010-01-08 11:46:29 UTC (rev 18451)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnSearch.java 2010-01-08 11:56:10 UTC (rev 18452)
@@ -3,7 +3,9 @@
import org.apache.lucene.index.Term;
/**
- * // TODO: Document this
+ * Class that allows users to continue building their TermQueries.
+ * However, a TermQuery cannot be built from an instance of this class, as there is not enough information
+ * to do so.
*
* @author Navin Surtani
*/
14 years, 7 months
Hibernate SVN: r18451 - in search/trunk/src: test/java/org/hibernate/search/test/query/dsl and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: navssurtani
Date: 2010-01-08 06:46:29 -0500 (Fri, 08 Jan 2010)
New Revision: 18451
Added:
search/trunk/src/main/java/org/hibernate/search/query/dsl/AbstractTermQueryBuilder.java
search/trunk/src/main/java/org/hibernate/search/query/dsl/BooleanContext.java
search/trunk/src/main/java/org/hibernate/search/query/dsl/BuildableTermQueryBuilder.java
search/trunk/src/main/java/org/hibernate/search/query/dsl/NegatableBooleanContext.java
search/trunk/src/main/java/org/hibernate/search/query/dsl/TermQueryBuilderDataStore.java
search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnField.java
search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnSearch.java
Removed:
search/trunk/src/main/java/org/hibernate/search/query/dsl/QueryContext.java
Modified:
search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java
search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java
Log:
Added in TermQueries and BooleanQueries to DSL.
Added: search/trunk/src/main/java/org/hibernate/search/query/dsl/AbstractTermQueryBuilder.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/AbstractTermQueryBuilder.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/AbstractTermQueryBuilder.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -0,0 +1,14 @@
+package org.hibernate.search.query.dsl;
+
+/**
+ * Abstract class that can be used to store state and any information that all the various TermQueryBuilder
+ * types might need.
+ *
+ * @author Navin Surtani
+ */
+
+
+public abstract class AbstractTermQueryBuilder {
+
+ protected TermQueryBuilderDataStore dataStore;
+}
Added: search/trunk/src/main/java/org/hibernate/search/query/dsl/BooleanContext.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/BooleanContext.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/BooleanContext.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -0,0 +1,47 @@
+package org.hibernate.search.query.dsl;
+
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Query;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Navin Surtani
+ */
+
+//TODO do we want a QueryCreator interface with T extends Query and T createQuery() ?
+public class BooleanContext {
+ private BooleanClause.Occur occur;
+ // List has an allocation of 5 temporarily so that it's not created with an arbitrary one.
+ private final List<Query> clauses = new ArrayList<Query>(5);
+
+ public BooleanContext(BooleanClause.Occur occur) {
+ this.occur = occur;
+ }
+
+ public BooleanContext add(Query clause) {
+ clauses.add(clause);
+ return this;
+ }
+
+ public Query createQuery() {
+ BooleanQuery boolQuery = new BooleanQuery();
+ for(Query clause : clauses) {
+ boolQuery.add(clause, occur);
+ }
+ return boolQuery;
+ }
+
+ protected void setOccur(BooleanClause.Occur occur) {
+ this.occur = occur;
+ }
+
+ protected BooleanClause.Occur getOccur() {
+ return occur;
+ }
+
+}
Added: search/trunk/src/main/java/org/hibernate/search/query/dsl/BuildableTermQueryBuilder.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/BuildableTermQueryBuilder.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/BuildableTermQueryBuilder.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -0,0 +1,49 @@
+package org.hibernate.search.query.dsl;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+
+import java.util.List;
+
+/**
+ * Class that will allow the user to actually build his query.
+ *
+ * @author Navin Surtani
+ */
+
+
+public class BuildableTermQueryBuilder extends AbstractTermQueryBuilder {
+ public BuildableTermQueryBuilder(TermQueryBuilderDataStore dataStore) {
+ this.dataStore = dataStore;
+ }
+
+ public UnbuildableTermQueryBuilderOnSearch on(String field) {
+ return new UnbuildableTermQueryBuilderOnSearch(dataStore, field);
+ }
+
+ public Query build() {
+ // Start by getting the lists of fields and searches.
+ List<Term> terms = dataStore.getTerms();
+
+ //TODO:- This kind of sucks. How can we do this nicely?
+ // Create a TermQuery for the first term.
+ Query tq = new TermQuery(terms.get(0));
+
+ // Now create an array of TermQueries for me to do the combine later on.
+ // The array size will be 1 less than that of the list.
+ TermQuery[] termQueries = new TermQuery[terms.size() - 1];
+
+ // Loop through the rest of the list.
+ for (int i = 1; i<terms.size(); i++){
+ // The index of each newly created TermQuery in the array will always be 1 less than that of the list
+ // This is because the first term in the list has already been dealt with, so the first termQuery in the array
+ // will correspond to the second term from the list.
+
+ termQueries[i - 1] = new TermQuery(terms.get(i));
+ }
+
+ tq = tq.combine(termQueries);
+ return tq;
+ }
+}
Added: search/trunk/src/main/java/org/hibernate/search/query/dsl/NegatableBooleanContext.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/NegatableBooleanContext.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/NegatableBooleanContext.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -0,0 +1,48 @@
+package org.hibernate.search.query.dsl;
+
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.Query;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Navin Surtani
+ */
+
+
+public class NegatableBooleanContext {
+ private final BooleanContext delegate;
+
+ public NegatableBooleanContext(BooleanClause.Occur occur) {
+ this.delegate = new BooleanContext(occur);
+ }
+
+ public NegatableBooleanContext not() {
+ BooleanClause.Occur present = delegate.getOccur();
+ if ( present == null ) {
+ //assertion exception
+ }
+ else if (present == BooleanClause.Occur.SHOULD) {
+ //assertion exception
+ }
+ else if ( present == BooleanClause.Occur.MUST) {
+ delegate.setOccur(BooleanClause.Occur.MUST_NOT);
+ }
+ else if (present == BooleanClause.Occur.MUST_NOT) {
+ delegate.setOccur(BooleanClause.Occur.MUST);
+ }
+ else {
+ //asseriton failure
+ }
+ return this;
+ }
+
+ public NegatableBooleanContext add(Query clause) {
+ delegate.add(clause);
+ return this;
+ }
+
+ public Query createQuery() {
+ return delegate.createQuery();
+ }
+}
Deleted: search/trunk/src/main/java/org/hibernate/search/query/dsl/QueryContext.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/QueryContext.java 2010-01-08 10:41:10 UTC (rev 18450)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/QueryContext.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -1,52 +0,0 @@
-package org.hibernate.search.query.dsl;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Query;
-
-/**
- * Class that will be called by the {@link org.hibernate.search.query.dsl.SealedQueryBuilder} each time someone wants
- * to create a new query instance.
- *
- * @author Navin Surtani
- */
-
-
-public class QueryContext {
-
- private Analyzer analyzer;
- private String field;
- private String search;
-
- public QueryContext search(String mySearch){
- this.search = mySearch;
- return this;
- }
-
- public QueryContext onField(String onField){
- this.field = onField;
- return this;
- }
-
- public QueryContext withAnalyzer(Analyzer analyzer){
- this.analyzer = analyzer;
- return this;
- }
-
- public Query build() throws ParseException {
- QueryParser parser;
-
- if (analyzer != null){
- parser = new QueryParser(field, analyzer);
- }
- else{
- // Do we just use a StandardAnalyzer?
- parser = new QueryParser(field, new StandardAnalyzer());
- }
-
- return parser.parse(search);
- }
-
-}
Modified: search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java 2010-01-08 10:41:10 UTC (rev 18450)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/SealedQueryBuilder.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -1,5 +1,7 @@
package org.hibernate.search.query.dsl;
+import org.apache.lucene.search.BooleanClause;
+
/**
* // TODO: Document this
*
@@ -13,7 +15,15 @@
}
- public QueryContext getContext(){
- return new QueryContext();
+ public BooleanContext should() {
+ return new BooleanContext(BooleanClause.Occur.SHOULD);
}
+
+ public NegatableBooleanContext must(){
+ return new NegatableBooleanContext(BooleanClause.Occur.MUST);
+ }
+
+ public UnbuildableTermQueryBuilderOnField term(){
+ return new UnbuildableTermQueryBuilderOnField();
+ }
}
Added: search/trunk/src/main/java/org/hibernate/search/query/dsl/TermQueryBuilderDataStore.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/TermQueryBuilderDataStore.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/TermQueryBuilderDataStore.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -0,0 +1,31 @@
+package org.hibernate.search.query.dsl;
+
+import org.apache.lucene.index.Term;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class will just store the required terms.
+ *
+ * @author Navin Surtani
+ */
+
+
+public class TermQueryBuilderDataStore {
+
+ private List<Term> terms;
+
+ public TermQueryBuilderDataStore(){
+ terms = new ArrayList<Term>();
+ }
+
+ public List<Term> getTerms(){
+ return terms;
+ }
+
+ public void addTerm(Term term){
+ terms.add(term);
+ }
+
+}
Added: search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnField.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnField.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnField.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -0,0 +1,20 @@
+package org.hibernate.search.query.dsl;
+
+/**
+ * Class that exposes only the on(String field) method as this class will only be returned to a user when
+ * SealedQueryBuilder.term() is called.
+ *
+ * @author Navin Surtani
+ */
+
+
+public class UnbuildableTermQueryBuilderOnField extends AbstractTermQueryBuilder {
+
+ public UnbuildableTermQueryBuilderOnField(){
+ dataStore = new TermQueryBuilderDataStore();
+ }
+
+ public UnbuildableTermQueryBuilderOnSearch on(String field){
+ return new UnbuildableTermQueryBuilderOnSearch(dataStore, field);
+ }
+}
Added: search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnSearch.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnSearch.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/query/dsl/UnbuildableTermQueryBuilderOnSearch.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -0,0 +1,30 @@
+package org.hibernate.search.query.dsl;
+
+import org.apache.lucene.index.Term;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Navin Surtani
+ */
+
+
+public class UnbuildableTermQueryBuilderOnSearch extends AbstractTermQueryBuilder {
+
+ private String field;
+
+ public UnbuildableTermQueryBuilderOnSearch(TermQueryBuilderDataStore dataStore, String field) {
+ this.dataStore = dataStore;
+ this.field = field;
+ }
+
+ public BuildableTermQueryBuilder matches(String search) {
+ // Now that I've got enough information to create a term I can do so
+ Term term = new Term(field, search);
+ dataStore.addTerm(term);
+ // return the Buildable type.
+ return new BuildableTermQueryBuilder(dataStore);
+ }
+
+
+}
Modified: search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java 2010-01-08 10:41:10 UTC (rev 18450)
+++ search/trunk/src/test/java/org/hibernate/search/test/query/dsl/QueryContextTest.java 2010-01-08 11:46:29 UTC (rev 18451)
@@ -1,6 +1,5 @@
package org.hibernate.search.test.query.dsl;
-import org.hibernate.search.query.dsl.QueryContext;
import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.test.query.Person;
14 years, 7 months
Hibernate SVN: r18450 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/test/beanvalidation and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-08 05:41:10 -0500 (Fri, 08 Jan 2010)
New Revision: 18450
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java
Log:
HHH-4675 Bean Validation ConstraintViolationException should trigger a tx rollback
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-01-08 06:55:42 UTC (rev 18449)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-01-08 10:41:10 UTC (rev 18450)
@@ -56,6 +56,7 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
+import javax.validation.ConstraintViolationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -444,8 +445,8 @@
catch ( MappingException e ) {
throw new IllegalArgumentException( e.getMessage() );
}
- catch ( HibernateException he ) {
- throw convert( he );
+ catch ( RuntimeException e ) {
+ throw convert( e );
}
}
@@ -461,8 +462,8 @@
catch ( MappingException e ) {
throw new IllegalArgumentException( e.getMessage(), e );
}
- catch ( HibernateException he ) {
- throw convert( he );
+ catch ( RuntimeException e ) { //including HibernateException
+ throw convert( e );
}
}
@@ -474,8 +475,8 @@
catch ( MappingException e ) {
throw new IllegalArgumentException( e.getMessage(), e );
}
- catch ( HibernateException he ) {
- throw convert( he );
+ catch ( RuntimeException e ) { //including HibernateException
+ throw convert( e );
}
}
@@ -553,8 +554,8 @@
//adjustFlushMode();
getSession().flush();
}
- catch ( HibernateException he ) {
- throw convert( he );
+ catch ( RuntimeException e ) {
+ throw convert( e );
}
}
@@ -768,7 +769,7 @@
tx.setRollbackOnly();
}
else {
- //no explicit use of the tx. boudaries methods
+ //no explicit use of the tx. boundaries methods
if ( PersistenceUnitTransactionType.JTA == transactionType ) {
TransactionManager transactionManager =
( ( SessionFactoryImplementor ) getRawSession().getSessionFactory() ).getTransactionManager();
@@ -985,6 +986,7 @@
/**
* {@inheritDoc}
*/
+ //FIXME should we remove all calls to this method and use convert(RuntimeException) ?
public RuntimeException convert(HibernateException e) {
return convert(e, null);
}
@@ -992,6 +994,21 @@
/**
* {@inheritDoc}
*/
+ public RuntimeException convert(RuntimeException e) {
+ RuntimeException result = e;
+ if ( e instanceof HibernateException ) {
+ result = convert( (HibernateException) e );
+ }
+ else if (e instanceof ConstraintViolationException) {
+ markAsRollback();
+ }
+ //if any RT exception should mark the tx for rollback, convert the last else if into a else
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public RuntimeException convert(HibernateException e, LockOptions lockOptions) {
if ( e instanceof StaleStateException ) {
PersistenceException converted = wrapStaleStateException( ( StaleStateException ) e );
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2010-01-08 06:55:42 UTC (rev 18449)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2010-01-08 10:41:10 UTC (rev 18450)
@@ -579,7 +579,8 @@
PersistenceException pe = new PersistenceException(
"Unsupported unwrap target type [" + tClass.getName() + "]"
);
- getEntityManager().handlePersistenceException( pe );
+ //It's probably against the spec to not mark the tx for rollback but it will be easier for people
+ //getEntityManager().handlePersistenceException( pe );
throw pe;
}
}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java 2010-01-08 06:55:42 UTC (rev 18449)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java 2010-01-08 10:41:10 UTC (rev 18450)
@@ -25,6 +25,10 @@
catch ( ConstraintViolationException e ) {
assertEquals( 1, e.getConstraintViolations().size() );
}
+ assertTrue(
+ "A constraint violation exception should mark the transaction for rollback",
+ em.getTransaction().getRollbackOnly()
+ );
em.getTransaction().rollback();
em.close();
}
14 years, 7 months
Hibernate SVN: r18449 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/criteria and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-08 01:55:42 -0500 (Fri, 08 Jan 2010)
New Revision: 18449
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/UncorrelatedSubqueryTest.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
Log:
HHH-4767 - Bug in how Criteria Subquery selections are handled
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2010-01-08 06:10:24 UTC (rev 18448)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2010-01-08 06:55:42 UTC (rev 18449)
@@ -53,7 +53,6 @@
private final AbstractQuery<?> parent;
private final QueryStructure<T> queryStructure;
- private Expression<T> selection;
private Set<Join<?, ?>> correlatedJoins = new HashSet<Join<?,?>>();
private final FromImplementor.JoinScope joinScope = new FromImplementor.JoinScope() {
@@ -144,12 +143,11 @@
}
public Expression<T> getSelection() {
- return selection;
+ return (Expression<T>) queryStructure.getSelection();
}
public Subquery<T> select(Expression<T> expression) {
- queryStructure.setSelection( selection );
- this.selection = expression;
+ queryStructure.setSelection( expression );
return this;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2010-01-08 06:10:24 UTC (rev 18448)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2010-01-08 06:55:42 UTC (rev 18449)
@@ -187,7 +187,7 @@
}
- // SUBQUERIES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // SUB-QUERIES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public List<Subquery<?>> getSubqueries() {
return subqueries;
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/UncorrelatedSubqueryTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/UncorrelatedSubqueryTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/UncorrelatedSubqueryTest.java 2010-01-08 06:55:42 UTC (rev 18449)
@@ -0,0 +1,63 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.criteria.subquery;
+
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Join;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Subquery;
+
+import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
+import org.hibernate.ejb.metamodel.Customer;
+import org.hibernate.ejb.metamodel.Customer_;
+import org.hibernate.ejb.metamodel.Order;
+import org.hibernate.ejb.metamodel.Order_;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class UncorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
+ public void testEqualAll() {
+ CriteriaBuilder builder = factory.getCriteriaBuilder();
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+
+ CriteriaQuery<Customer> criteria = builder.createQuery( Customer.class );
+ Root<Customer> customerRoot = criteria.from( Customer.class );
+ Join<Customer, Order> orderJoin = customerRoot.join( Customer_.orders );
+ criteria.select( customerRoot );
+ Subquery<Double> subCriteria = criteria.subquery( Double.class );
+ Root<Order> subqueryOrderRoot = subCriteria.from( Order.class );
+ subCriteria.select( builder.min( subqueryOrderRoot.get( Order_.totalPrice ) ) );
+ criteria.where( builder.equal( orderJoin.get( "totalPrice" ), builder.all( subCriteria ) ) );
+ em.createQuery( criteria ).getResultList();
+
+ em.getTransaction().commit();
+ em.close();
+ }
+}
14 years, 7 months
Hibernate SVN: r18448 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/criteria/basic and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-08 01:10:24 -0500 (Fri, 08 Jan 2010)
New Revision: 18448
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/AggregationResultTest.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Product.java
Log:
HHH-4766 - Properly support criteria notion of SUM aggregation return types
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java 2010-01-08 03:51:47 UTC (rev 18447)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/AggregationFunction.java 2010-01-08 06:10:24 UTC (rev 18448)
@@ -131,10 +131,14 @@
@SuppressWarnings({ "unchecked" })
public SUM(CriteriaBuilderImpl criteriaBuilder, Expression<N> expression) {
super( criteriaBuilder, (Class<N>)expression.getJavaType(), NAME , expression);
+ // force the use of a ValueHandler
+ resetJavaType( expression.getJavaType() );
}
public SUM(CriteriaBuilderImpl criteriaBuilder, Expression<? extends Number> expression, Class<N> returnType) {
super( criteriaBuilder, returnType, NAME , expression);
+ // force the use of a ValueHandler
+ resetJavaType( returnType );
}
}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/AggregationResultTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/AggregationResultTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/AggregationResultTest.java 2010-01-08 06:10:24 UTC (rev 18448)
@@ -0,0 +1,174 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.criteria.basic;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
+
+import junit.framework.AssertionFailedError;
+
+import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
+import org.hibernate.ejb.metamodel.Product;
+import org.hibernate.ejb.metamodel.Product_;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class AggregationResultTest extends AbstractMetamodelSpecificTest {
+ private CriteriaBuilder builder;
+
+ @Override
+ public void setUp() {
+ super.setUp();
+ builder = factory.getCriteriaBuilder();
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Product product = new Product();
+ product.setId( "product1" );
+ product.setPrice( 1.23d );
+ product.setQuantity( 1000 );
+ product.setPartNumber( Integer.MAX_VALUE + 1 );
+ product.setRating( 1.999f );
+ product.setSomeBigInteger( BigInteger.valueOf( 987654321 ) );
+ product.setSomeBigDecimal( BigDecimal.valueOf( 987654.321 ) );
+ em.persist( product );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ @Override
+ public void tearDown() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.createQuery( "delete Product" ).executeUpdate();
+ em.getTransaction().commit();
+ em.close();
+ super.tearDown();
+ }
+
+ /**
+ * Sum of Longs should return a Long
+ */
+ public void testSumOfLongs() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Long> criteria = builder.createQuery( Long.class );
+ Root<Product> productRoot = criteria.from( Product.class );
+ criteria.select( builder.sum( productRoot.get( Product_.partNumber ) ) );
+ Object sumResult = em.createQuery( criteria ).getSingleResult();
+ assertReturnType( Long.class, sumResult );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ /**
+ * Sum of Integers should return an Integer; note that this is distinctly different than JPAQL
+ */
+ public void testSumOfIntegers() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Integer> criteria = builder.createQuery( Integer.class );
+ Root<Product> productRoot = criteria.from( Product.class );
+ criteria.select( builder.sum( productRoot.get( Product_.quantity ) ) );
+ Object sumResult = em.createQuery( criteria ).getSingleResult();
+ assertReturnType( Integer.class, sumResult );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ /**
+ * Sum of Doubles should return a Double
+ */
+ public void testSumOfDoubles() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Double> criteria = builder.createQuery( Double.class );
+ Root<Product> productRoot = criteria.from( Product.class );
+ criteria.select( builder.sum( productRoot.get( Product_.price ) ) );
+ Object sumResult = em.createQuery( criteria ).getSingleResult();
+ assertReturnType( Double.class, sumResult );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ /**
+ * Sum of Floats should return a Float; note that this is distinctly different than JPAQL
+ */
+ public void testSumOfFloats() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Float> criteria = builder.createQuery( Float.class );
+ Root<Product> productRoot = criteria.from( Product.class );
+ criteria.select( builder.sum( productRoot.get( Product_.rating ) ) );
+ Object sumResult = em.createQuery( criteria ).getSingleResult();
+ assertReturnType( Float.class, sumResult );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ /**
+ * Sum of BigInteger should return a BigInteger
+ */
+ public void testSumOfBigIntegers() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<BigInteger> criteria = builder.createQuery( BigInteger.class );
+ Root<Product> productRoot = criteria.from( Product.class );
+ criteria.select( builder.sum( productRoot.get( Product_.someBigInteger ) ) );
+ Object sumResult = em.createQuery( criteria ).getSingleResult();
+ assertReturnType( BigInteger.class, sumResult );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ /**
+ * Sum of BigDecimal should return a BigDecimal
+ */
+ public void testSumOfBigDecimals() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<BigDecimal> criteria = builder.createQuery( BigDecimal.class );
+ Root<Product> productRoot = criteria.from( Product.class );
+ criteria.select( builder.sum( productRoot.get( Product_.someBigDecimal ) ) );
+ Object sumResult = em.createQuery( criteria ).getSingleResult();
+ assertReturnType( BigDecimal.class, sumResult );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void assertReturnType(Class expectedType, Object value) {
+ if ( value != null && ! expectedType.isInstance( value ) ) {
+ throw new AssertionFailedError(
+ "Result value was not of expected type: expected [" + expectedType.getName()
+ + "] but found [" + value.getClass().getName() + "]"
+ );
+ }
+ }
+}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Product.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Product.java 2010-01-08 03:51:47 UTC (rev 18447)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Product.java 2010-01-08 06:10:24 UTC (rev 18448)
@@ -23,6 +23,8 @@
*/
package org.hibernate.ejb.metamodel;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
@@ -53,8 +55,11 @@
private String id;
private String name;
private double price;
+ private float rating;
private int quantity;
private long partNumber;
+ private BigInteger someBigInteger;
+ private BigDecimal someBigDecimal;
private String wareHouse;
private ShelfLife shelfLife;
@@ -115,6 +120,30 @@
this.partNumber = v;
}
+ public float getRating() {
+ return rating;
+ }
+
+ public void setRating(float rating) {
+ this.rating = rating;
+ }
+
+ public BigInteger getSomeBigInteger() {
+ return someBigInteger;
+ }
+
+ public void setSomeBigInteger(BigInteger someBigInteger) {
+ this.someBigInteger = someBigInteger;
+ }
+
+ public BigDecimal getSomeBigDecimal() {
+ return someBigDecimal;
+ }
+
+ public void setSomeBigDecimal(BigDecimal someBigDecimal) {
+ this.someBigDecimal = someBigDecimal;
+ }
+
@Column(name = "WHOUSE", nullable = true, table = "PRODUCT_DETAILS")
public String getWareHouse() {
return wareHouse;
14 years, 7 months
Hibernate SVN: r18447 - core/trunk/entitymanager.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-07 22:51:47 -0500 (Thu, 07 Jan 2010)
New Revision: 18447
Modified:
core/trunk/entitymanager/build.xml
Log:
HHH-4763 Moved the directory creation into a different target
Modified: core/trunk/entitymanager/build.xml
===================================================================
--- core/trunk/entitymanager/build.xml 2010-01-08 03:40:18 UTC (rev 18446)
+++ core/trunk/entitymanager/build.xml 2010-01-08 03:51:47 UTC (rev 18447)
@@ -6,8 +6,8 @@
<project name="HibernateEntityManager" basedir=".">
<target name="generate-metamodel" depends="uptodate.check" unless="metamodel.build.notRequired">
-
<echo>Processing JPA annotations for metamodel generation</echo>
+ <mkdir dir="${target.dir}"/>
<javac srcdir="${src.dir}"
destdir="${target.dir}"
failonerror="false"
@@ -21,7 +21,6 @@
</target>
<target name="uptodate.check">
- <mkdir dir="${target.dir}"/>
<uptodate property="metamodel.build.notRequired" targetfile="${target.dir}/.staleflag">
<srcfiles dir="${src.dir}" includes="**/*.java"/>
</uptodate>
14 years, 7 months
Hibernate SVN: r18446 - core/trunk/entitymanager.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-07 22:40:18 -0500 (Thu, 07 Jan 2010)
New Revision: 18446
Modified:
core/trunk/entitymanager/build.xml
core/trunk/entitymanager/pom.xml
Log:
HHH-4763 Moved the metamodel task into build.xml and modified the antrun configuration to allow to run 'mvn antrun:run'. Also combined all antrun calls into one plugin configuration
Modified: core/trunk/entitymanager/build.xml
===================================================================
--- core/trunk/entitymanager/build.xml 2010-01-07 20:49:36 UTC (rev 18445)
+++ core/trunk/entitymanager/build.xml 2010-01-08 03:40:18 UTC (rev 18446)
@@ -4,98 +4,120 @@
-->
<project name="HibernateEntityManager" basedir=".">
-
- <target name="packjar">
- <property name="extension" value="jar"/>
- <property name="packagename" value="${jarname}"/>
- <property name="headerdirectory" value="."/>
- <mkdir dir="${package.dir}"/>
- <mkdir dir="${package.tmp.dir}/${headerdirectory}"/>
- <copy todir="${package.tmp.dir}/${headerdirectory}">
- <fileset dir="${classes.dir}">
- <include name="**/test/pack/${packagename}/**.*"/>
- </fileset>
- </copy>
- <jar destfile="${package.dir}/${jarname}.${extension}">
- <fileset dir="${package.tmp.dir}">
- <include name="**/*.*"/>
- </fileset>
- <fileset dir="${testresources.dir}/${jarname}">
- <include name="**/*.*"/>
- </fileset>
- </jar>
- <delete dir="${package.tmp.dir}"/>
- </target>
-
- <target name="packexploded">
- <property name="extension" value="jar"/>
- <mkdir dir="${package.dir}/${jarname}.${extension}"/>
- <copy todir="${package.dir}/${jarname}.${extension}">
- <fileset dir="${classes.dir}">
- <include name="**/test/pack/${jarname}/**.*"/>
- </fileset>
- <fileset dir="${testresources.dir}/${jarname}">
- <include name="**/*.*"/>
- </fileset>
- </copy>
- </target>
-
- <target name="package" description="Prepare all needed jars and pars">
- <antcall target="packjar" inheritall="true">
- <param name="extension" value="par"/>
- <param name="jarname" value="defaultpar"/>
- </antcall>
+
+ <target name="generate-metamodel" depends="uptodate.check" unless="metamodel.build.notRequired">
+
+ <echo>Processing JPA annotations for metamodel generation</echo>
+ <javac srcdir="${src.dir}"
+ destdir="${target.dir}"
+ failonerror="false"
+ fork="true"
+ executable="${jdk16_home}/bin/javac"
+ target="1.5"
+ classpath="${classpath}">
+ <compilerarg value="-proc:only"/>
+ </javac>
+ <touch file="${target.dir}/.staleflag"/>
+ </target>
+
+ <target name="uptodate.check">
+ <mkdir dir="${target.dir}"/>
+ <uptodate property="metamodel.build.notRequired" targetfile="${target.dir}/.staleflag">
+ <srcfiles dir="${src.dir}" includes="**/*.java"/>
+ </uptodate>
+ </target>
+
+ <target name="packjar">
+ <property name="extension" value="jar"/>
+ <property name="packagename" value="${jarname}"/>
+ <property name="headerdirectory" value="."/>
+ <mkdir dir="${package.dir}"/>
+ <mkdir dir="${package.tmp.dir}/${headerdirectory}"/>
+ <copy todir="${package.tmp.dir}/${headerdirectory}">
+ <fileset dir="${classes.dir}">
+ <include name="**/test/pack/${packagename}/**.*"/>
+ </fileset>
+ </copy>
+ <jar destfile="${package.dir}/${jarname}.${extension}">
+ <fileset dir="${package.tmp.dir}">
+ <include name="**/*.*"/>
+ </fileset>
+ <fileset dir="${testresources.dir}/${jarname}">
+ <include name="**/*.*"/>
+ </fileset>
+ </jar>
+ <delete dir="${package.tmp.dir}"/>
+ </target>
+
+ <target name="packexploded">
+ <property name="extension" value="jar"/>
+ <mkdir dir="${package.dir}/${jarname}.${extension}"/>
+ <copy todir="${package.dir}/${jarname}.${extension}">
+ <fileset dir="${classes.dir}">
+ <include name="**/test/pack/${jarname}/**.*"/>
+ </fileset>
+ <fileset dir="${testresources.dir}/${jarname}">
+ <include name="**/*.*"/>
+ </fileset>
+ </copy>
+ </target>
+
+ <target name="package" description="Prepare all needed jars and pars">
<antcall target="packjar" inheritall="true">
- <param name="extension" value="par"/>
- <param name="jarname" value="defaultpar_1_0"/>
- </antcall>
- <antcall target="packjar" inheritall="true">
- <param name="extension" value="par"/>
- <param name="jarname" value="space par"/>
- <param name="packagename" value="spacepar"/>
- </antcall>
- <antcall target="packjar" inheritall="true">
- <param name="extension" value="par"/>
- <param name="jarname" value="explicitpar"/>
- </antcall>
- <antcall target="packjar" inheritall="true">
- <param name="extension" value="par"/>
- <param name="jarname" value="excludehbmpar"/>
- </antcall>
- <antcall target="packjar" inheritall="true">
- <param name="extension" value="jar"/>
- <param name="jarname" value="externaljar"/>
- </antcall>
- <antcall target="packjar" inheritall="true">
- <param name="extension" value="par"/>
- <param name="jarname" value="cfgxmlpar"/>
- </antcall>
- <antcall target="packjar" inheritall="true">
- <param name="extension" value="jar"/>
- <param name="jarname" value="overridenpar"/>
- </antcall>
-
- <!-- nested jar -->
- <jar destfile="${package.dir}/nestedjar.ear">
- <fileset dir="${package.dir}">
- <include name="defaultpar.par"/>
- </fileset>
- </jar>
- <copy todir="${package.dir}/nesteddir.ear">
- <fileset dir="${package.dir}">
- <include name="defaultpar.par"/>
- </fileset>
- </copy>
-
- <antcall target="packjar" inheritall="true">
- <param name="extension" value="war"/>
- <param name="jarname" value="war"/>
- <param name="headerdirectory" value="WEB-INF/classes"/>
- </antcall>
-
- <antcall target="packexploded" inheritall="true">
- <param name="extension" value="par"/>
- <param name="jarname" value="explodedpar"/>
- </antcall>
- </target>
+ <param name="extension" value="par"/>
+ <param name="jarname" value="defaultpar"/>
+ </antcall>
+ <antcall target="packjar" inheritall="true">
+ <param name="extension" value="par"/>
+ <param name="jarname" value="defaultpar_1_0"/>
+ </antcall>
+ <antcall target="packjar" inheritall="true">
+ <param name="extension" value="par"/>
+ <param name="jarname" value="space par"/>
+ <param name="packagename" value="spacepar"/>
+ </antcall>
+ <antcall target="packjar" inheritall="true">
+ <param name="extension" value="par"/>
+ <param name="jarname" value="explicitpar"/>
+ </antcall>
+ <antcall target="packjar" inheritall="true">
+ <param name="extension" value="par"/>
+ <param name="jarname" value="excludehbmpar"/>
+ </antcall>
+ <antcall target="packjar" inheritall="true">
+ <param name="extension" value="jar"/>
+ <param name="jarname" value="externaljar"/>
+ </antcall>
+ <antcall target="packjar" inheritall="true">
+ <param name="extension" value="par"/>
+ <param name="jarname" value="cfgxmlpar"/>
+ </antcall>
+ <antcall target="packjar" inheritall="true">
+ <param name="extension" value="jar"/>
+ <param name="jarname" value="overridenpar"/>
+ </antcall>
+
+ <!-- nested jar -->
+ <jar destfile="${package.dir}/nestedjar.ear">
+ <fileset dir="${package.dir}">
+ <include name="defaultpar.par"/>
+ </fileset>
+ </jar>
+ <copy todir="${package.dir}/nesteddir.ear">
+ <fileset dir="${package.dir}">
+ <include name="defaultpar.par"/>
+ </fileset>
+ </copy>
+
+ <antcall target="packjar" inheritall="true">
+ <param name="extension" value="war"/>
+ <param name="jarname" value="war"/>
+ <param name="headerdirectory" value="WEB-INF/classes"/>
+ </antcall>
+
+ <antcall target="packexploded" inheritall="true">
+ <param name="extension" value="par"/>
+ <param name="jarname" value="explodedpar"/>
+ </antcall>
+ </target>
</project>
Modified: core/trunk/entitymanager/pom.xml
===================================================================
--- core/trunk/entitymanager/pom.xml 2010-01-07 20:49:36 UTC (rev 18445)
+++ core/trunk/entitymanager/pom.xml 2010-01-08 03:40:18 UTC (rev 18446)
@@ -1,4 +1,6 @@
-<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">
+<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>
@@ -94,35 +96,50 @@
<testResource>
<filtering>true</filtering>
<directory>src/test/bundles</directory>
- <targetPath>../bundles</targetPath>
- </testResource>
+ <targetPath>../bundles</targetPath>
+ </testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
+ <!-- Define one configuration outside executions and without a phase in order to allow 'mvn antrun:run' -->
+ <configuration>
+ <tasks>
+ <property name="target.dir" value="${project.build.directory}/generated-src/jpamodelgen"/>
+ <property name="src.dir" value="${project.build.testSourceDirectory}"/>
+ <property name="jdk16_home" value="${jdk16_home}"/>
+ <property name="classpath" refid="maven.test.classpath"/>
+ <ant antfile="${basedir}/build.xml">
+ <target name="generate-metamodel"/>
+ </ant>
+ </tasks>
+ </configuration>
<executions>
<execution>
<id>process_annotations</id>
- <phase>process-test-resources</phase>
+ <phase>process-test-sources</phase>
<configuration>
+ <!-- No additional configuration needed. Unbound configuration gets inherited. (Feels wrong, but that's how it is) -->
+ <testSourceRoot>${project.build.directory}/generated-src/jpamodelgen</testSourceRoot>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>package-tests</id>
+ <phase>process-test-classes</phase>
+ <configuration>
<tasks>
- <echo>processing JPA annotations</echo>
- <property name="target.dir" value="${project.build.directory}/generated-src/jpamodelgen"/>
- <mkdir dir="${target.dir}"/>
- <javac srcdir="${project.build.testSourceDirectory}"
- destdir="${target.dir}"
- failonerror="false"
- fork="true"
- executable="${jdk16_home}/bin/javac"
- target="1.5">
- <compilerarg value="-proc:only"/>
- <classpath>
- <path refid="maven.test.classpath"/>
- </classpath>
- </javac>
+ <property name="package.dir" value="${basedir}/target/test-packages"/>
+ <property name="package.tmp.dir" value="${basedir}/target/tmp"/>
+ <property name="classes.dir" value="${project.build.directory}/test-classes"/>
+ <property name="testresources.dir" value="${basedir}/target/bundles"/>
+ <ant antfile="${basedir}/build.xml">
+ <target name="package"/>
+ </ant>
</tasks>
- <testSourceRoot>${project.build.directory}/generated-src/jpamodelgen</testSourceRoot>
</configuration>
<goals>
<goal>run</goal>
@@ -130,29 +147,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <id>package-tests</id>
- <phase>process-test-classes</phase>
- <configuration>
- <tasks>
- <property name="package.dir" value="${basedir}/target/test-packages" />
- <property name="package.tmp.dir" value="${basedir}/target/tmp" />
- <property name="classes.dir" value="${project.build.directory}/test-classes" />
- <property name="testresources.dir" value="${basedir}/target/bundles" />
- <ant antfile="${basedir}/build.xml">
- <target name="package" />
- </ant>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@@ -173,32 +167,43 @@
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <forkMode>pertest</forkMode>
- <additionalClasspathElements>
- <additionalClasspathElement>${basedir}/target/test-packages/cfgxmlpar.par</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/defaultpar.par</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/defaultpar_1_0.par</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/excludehbmpar.par</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/explicitpar.par</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/explodedpar.par</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/externaljar.jar</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/nesteddir.ear</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/nestedjar.ear</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/overridenpar.jar</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/space par.par</additionalClasspathElement>
- <additionalClasspathElement>${basedir}/target/test-packages/war.war</additionalClasspathElement>
- </additionalClasspathElements>
- </configuration>
- </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>pertest</forkMode>
+ <additionalClasspathElements>
+ <additionalClasspathElement>${basedir}/target/test-packages/cfgxmlpar.par
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/defaultpar.par
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/defaultpar_1_0.par
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/excludehbmpar.par
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/explicitpar.par
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/explodedpar.par
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/externaljar.jar
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/nesteddir.ear
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/nestedjar.ear
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/overridenpar.jar
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/space par.par
+ </additionalClasspathElement>
+ <additionalClasspathElement>${basedir}/target/test-packages/war.war</additionalClasspathElement>
+ </additionalClasspathElements>
+ </configuration>
+ </plugin>
</plugins>
</build>
<profiles>
- <profile>
+ <profile>
<id>doc</id>
<build>
<plugins>
@@ -261,6 +266,6 @@
</plugins>
</build>
</profile>
- </profiles>
+ </profiles>
</project>
14 years, 7 months
Hibernate SVN: r18445 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria: expression and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-07 15:49:36 -0500 (Thu, 07 Jan 2010)
New Revision: 18445
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractNode.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractFromImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractPathImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/CollectionAttributeJoin.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/ListAttributeJoin.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/MapAttributeJoin.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/RootImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/SetAttributeJoin.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/SingularAttributeJoin.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java
Log:
HHH-4758 - Rename org.hibernate.ejb.criteria.AbstractNode#queryBuilder to #criteriaBuilder
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractNode.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractNode.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/AbstractNode.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -43,7 +43,7 @@
*
* @return The underlying {@link CriteriaBuilderImpl} instance.
*/
- protected CriteriaBuilderImpl queryBuilder() {
+ protected CriteriaBuilderImpl criteriaBuilder() {
return criteriaBuilder;
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -124,10 +124,10 @@
final Selection<? extends T> selection;
if ( Tuple.class.isAssignableFrom( getResultType() ) ) {
- selection = ( Selection<? extends T> ) queryBuilder().tuple( selections );
+ selection = ( Selection<? extends T> ) criteriaBuilder().tuple( selections );
}
else if ( getResultType().isArray() ) {
- selection = ( Selection<? extends T> ) queryBuilder().array(
+ selection = ( Selection<? extends T> ) criteriaBuilder().array(
( Class<? extends Object[]> ) getResultType(),
selections
);
@@ -144,12 +144,12 @@
break;
}
default: {
- selection = ( Selection<? extends T> ) queryBuilder().array( selections );
+ selection = ( Selection<? extends T> ) criteriaBuilder().array( selections );
}
}
}
else {
- selection = queryBuilder().construct( getResultType(), selections );
+ selection = criteriaBuilder().construct( getResultType(), selections );
}
applySelection( selection );
return this;
@@ -193,7 +193,7 @@
* {@inheritDoc}
*/
public CriteriaQuery<T> where(Expression<Boolean> expression) {
- queryStructure.setRestriction( queryBuilder().wrap( expression ) );
+ queryStructure.setRestriction( criteriaBuilder().wrap( expression ) );
return this;
}
@@ -202,7 +202,7 @@
*/
public CriteriaQuery<T> where(Predicate... predicates) {
// TODO : assuming this should be a conjuntion, but the spec does not say specifically...
- queryStructure.setRestriction( queryBuilder().and( predicates ) );
+ queryStructure.setRestriction( criteriaBuilder().and( predicates ) );
return this;
}
@@ -240,7 +240,7 @@
* {@inheritDoc}
*/
public CriteriaQuery<T> having(Expression<Boolean> expression) {
- queryStructure.setHaving( queryBuilder().wrap( expression ) );
+ queryStructure.setHaving( criteriaBuilder().wrap( expression ) );
return this;
}
@@ -248,7 +248,7 @@
* {@inheritDoc}
*/
public CriteriaQuery<T> having(Predicate... predicates) {
- queryStructure.setHaving( queryBuilder().and( predicates ) );
+ queryStructure.setHaving( criteriaBuilder().and( predicates ) );
return this;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -167,7 +167,7 @@
* {@inheritDoc}
*/
public Subquery<T> where(Expression<Boolean> expression) {
- queryStructure.setRestriction( queryBuilder().wrap( expression ) );
+ queryStructure.setRestriction( criteriaBuilder().wrap( expression ) );
return this;
}
@@ -176,7 +176,7 @@
*/
public Subquery<T> where(Predicate... predicates) {
// TODO : assuming this should be a conjuntion, but the spec does not say specifically...
- queryStructure.setRestriction( queryBuilder().and( predicates ) );
+ queryStructure.setRestriction( criteriaBuilder().and( predicates ) );
return this;
}
@@ -218,7 +218,7 @@
* {@inheritDoc}
*/
public Subquery<T> having(Expression<Boolean> expression) {
- queryStructure.setHaving( queryBuilder().wrap( expression ) );
+ queryStructure.setHaving( criteriaBuilder().wrap( expression ) );
return this;
}
@@ -226,7 +226,7 @@
* {@inheritDoc}
*/
public Subquery<T> having(Predicate... predicates) {
- queryStructure.setHaving( queryBuilder().and( predicates ) );
+ queryStructure.setHaving( criteriaBuilder().and( predicates ) );
return this;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -60,7 +60,7 @@
}
public Coalesce<T> value(T value) {
- return value( new LiteralExpression<T>( queryBuilder(), value ) );
+ return value( new LiteralExpression<T>( criteriaBuilder(), value ) );
}
@SuppressWarnings({ "unchecked" })
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -53,49 +53,49 @@
public <X> Expression<X> as(Class<X> type) {
return type.equals( getJavaType() )
? (Expression<X>) this
- : new CastFunction<X, T>( queryBuilder(), type, this );
+ : new CastFunction<X, T>( criteriaBuilder(), type, this );
}
/**
* {@inheritDoc}
*/
public Predicate isNull() {
- return queryBuilder().isNull( this );
+ return criteriaBuilder().isNull( this );
}
/**
* {@inheritDoc}
*/
public Predicate isNotNull() {
- return queryBuilder().isNotNull( this );
+ return criteriaBuilder().isNotNull( this );
}
/**
* {@inheritDoc}
*/
public Predicate in(Object... values) {
- return queryBuilder().in( this, values );
+ return criteriaBuilder().in( this, values );
}
/**
* {@inheritDoc}
*/
public Predicate in(Expression<?>... values) {
- return queryBuilder().in( this, values );
+ return criteriaBuilder().in( this, values );
}
/**
* {@inheritDoc}
*/
public Predicate in(Collection<?> values) {
- return queryBuilder().in( this, values );
+ return criteriaBuilder().in( this, values );
}
/**
* {@inheritDoc}
*/
public Predicate in(Expression<Collection<?>> values) {
- return queryBuilder().in( this, values );
+ return criteriaBuilder().in( this, values );
}
/**
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -86,7 +86,7 @@
final Class<R> type = result != null
? (Class<R>) result.getClass()
: getJavaType();
- return new LiteralExpression<R>( queryBuilder(), type, result );
+ return new LiteralExpression<R>( criteriaBuilder(), type, result );
}
public Case<R> when(Expression<Boolean> condition, Expression<? extends R> result) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -94,7 +94,7 @@
final Class<R> type = result != null
? (Class<R>) result.getClass()
: getJavaType();
- return new LiteralExpression<R>( queryBuilder(), type, result );
+ return new LiteralExpression<R>( criteriaBuilder(), type, result );
}
public SimpleCase<C, R> when(C condition, Expression<? extends R> result) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractFromImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractFromImpl.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractFromImpl.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -236,7 +236,7 @@
final Class<Y> attributeType = attribute.getBindableJavaType();
return new SingularAttributeJoin<X,Y>(
- queryBuilder(),
+ criteriaBuilder(),
attributeType,
this,
attribute,
@@ -272,7 +272,7 @@
final Class<Y> attributeType = collection.getBindableJavaType();
return new CollectionAttributeJoin<X, Y>(
- queryBuilder(),
+ criteriaBuilder(),
attributeType,
this,
collection,
@@ -308,7 +308,7 @@
// TODO : runtime check that the attribute in fact belongs to this From's model/bindable
final Class<Y> attributeType = set.getBindableJavaType();
- return new SetAttributeJoin<X,Y>( queryBuilder(), attributeType, this, set, jt );
+ return new SetAttributeJoin<X,Y>( criteriaBuilder(), attributeType, this, set, jt );
}
/**
@@ -339,7 +339,7 @@
// TODO : runtime check that the attribute in fact belongs to this From's model/bindable
final Class<Y> attributeType = list.getBindableJavaType();
- return new ListAttributeJoin<X,Y>( queryBuilder(), attributeType, this, list, jt );
+ return new ListAttributeJoin<X,Y>( criteriaBuilder(), attributeType, this, list, jt );
}
/**
@@ -370,7 +370,7 @@
// TODO : runtime check that the attribute in fact belongs to this From's model/bindable
final Class<V> attributeType = map.getBindableJavaType();
- return new MapAttributeJoin<X, K, V>( queryBuilder(), attributeType, this, map, jt );
+ return new MapAttributeJoin<X, K, V>( criteriaBuilder(), attributeType, this, map, jt );
}
/**
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractPathImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractPathImpl.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractPathImpl.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -69,7 +69,7 @@
PathSource pathSource) {
super( criteriaBuilder, javaType );
this.pathSource = pathSource;
- this.typeExpression = new PathTypeExpression( queryBuilder(), getJavaType() );
+ this.typeExpression = new PathTypeExpression( criteriaBuilder(), getJavaType() );
}
public PathSource getPathSource() {
@@ -137,7 +137,7 @@
SingularAttributePath<Y> path = (SingularAttributePath<Y>) resolveCachedAttributePath( attribute.getName() );
if ( path == null ) {
- path = new SingularAttributePath<Y>( queryBuilder(), attribute.getJavaType(), this, attribute );
+ path = new SingularAttributePath<Y>( criteriaBuilder(), attribute.getJavaType(), this, attribute );
registerAttributePath( attribute.getName(), path );
}
return path;
@@ -154,7 +154,7 @@
PluralAttributePath<C> path = (PluralAttributePath<C>) resolveCachedAttributePath( attribute.getName() );
if ( path == null ) {
- path = new PluralAttributePath<C>( queryBuilder(), this, attribute );
+ path = new PluralAttributePath<C>( criteriaBuilder(), this, attribute );
registerAttributePath( attribute.getName(), path );
}
return path;
@@ -171,7 +171,7 @@
PluralAttributePath path = (PluralAttributePath) resolveCachedAttributePath( attribute.getName() );
if ( path == null ) {
- path = new PluralAttributePath( queryBuilder(), this, attribute );
+ path = new PluralAttributePath( criteriaBuilder(), this, attribute );
registerAttributePath( attribute.getName(), path );
}
return path;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/CollectionAttributeJoin.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/CollectionAttributeJoin.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/CollectionAttributeJoin.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -70,7 +70,7 @@
@Override
protected FromImplementor<O, E> createCorrelationDelegate() {
return new CollectionAttributeJoin<O,E>(
- queryBuilder(),
+ criteriaBuilder(),
getJavaType(),
(PathImplementor<O>) getParentPath(),
getAttribute(),
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/ListAttributeJoin.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/ListAttributeJoin.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/ListAttributeJoin.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -60,7 +60,7 @@
* {@inheritDoc}
*/
public Expression<Integer> index() {
- return new ListIndexExpression( queryBuilder(), this, getAttribute() );
+ return new ListIndexExpression( criteriaBuilder(), this, getAttribute() );
}
@Override
@@ -81,7 +81,7 @@
@Override
protected FromImplementor<O, E> createCorrelationDelegate() {
return new ListAttributeJoin<O,E>(
- queryBuilder(),
+ criteriaBuilder(),
getJavaType(),
(PathImplementor<O>) getParentPath(),
getAttribute(),
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/MapAttributeJoin.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/MapAttributeJoin.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/MapAttributeJoin.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -75,7 +75,7 @@
@Override
protected FromImplementor<O, V> createCorrelationDelegate() {
return new MapAttributeJoin<O,K,V>(
- queryBuilder(),
+ criteriaBuilder(),
getJavaType(),
(PathImplementor<O>) getParentPath(),
getAttribute(),
@@ -96,7 +96,7 @@
*/
@SuppressWarnings({ "unchecked" })
public Expression<Map.Entry<K, V>> entry() {
- return new MapEntryExpression( queryBuilder(), Map.Entry.class, this, getAttribute() );
+ return new MapEntryExpression( criteriaBuilder(), Map.Entry.class, this, getAttribute() );
}
/**
@@ -105,13 +105,13 @@
@SuppressWarnings({ "unchecked" })
public Path<K> key() {
final MapKeyHelpers.MapKeySource<K,V> mapKeySource = new MapKeyHelpers.MapKeySource<K,V>(
- queryBuilder(),
+ criteriaBuilder(),
getAttribute().getJavaType(),
this,
getAttribute()
);
- final MapKeyHelpers.MapKeyAttribute mapKeyAttribute = new MapKeyHelpers.MapKeyAttribute( queryBuilder(), getAttribute() );
- return new MapKeyHelpers.MapKeyPath( queryBuilder(), mapKeySource, mapKeyAttribute );
+ final MapKeyHelpers.MapKeyAttribute mapKeyAttribute = new MapKeyHelpers.MapKeyAttribute( criteriaBuilder(), getAttribute() );
+ return new MapKeyHelpers.MapKeyPath( criteriaBuilder(), mapKeySource, mapKeyAttribute );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/RootImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/RootImpl.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/RootImpl.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -57,7 +57,7 @@
@Override
protected FromImplementor<X, X> createCorrelationDelegate() {
- return new RootImpl<X>( queryBuilder(), getEntityType() );
+ return new RootImpl<X>( criteriaBuilder(), getEntityType() );
}
@Override
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/SetAttributeJoin.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/SetAttributeJoin.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/SetAttributeJoin.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -72,7 +72,7 @@
@Override
protected FromImplementor<O, E> createCorrelationDelegate() {
return new SetAttributeJoin<O,E>(
- queryBuilder(),
+ criteriaBuilder(),
getJavaType(),
(PathImplementor<O>) getParentPath(),
getAttribute(),
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/SingularAttributeJoin.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/SingularAttributeJoin.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/SingularAttributeJoin.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -69,7 +69,7 @@
@Override
protected FromImplementor<Z, X> createCorrelationDelegate() {
return new SingularAttributeJoin<Z,X>(
- queryBuilder(),
+ criteriaBuilder(),
getJavaType(),
getPathSource(),
getAttribute(),
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java 2010-01-07 20:41:54 UTC (rev 18444)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java 2010-01-07 20:49:36 UTC (rev 18445)
@@ -143,7 +143,7 @@
}
public InPredicate<T> value(T value) {
- return value( new LiteralExpression<T>( queryBuilder(), value ) );
+ return value( new LiteralExpression<T>( criteriaBuilder(), value ) );
}
public InPredicate<T> value(Expression<? extends T> value) {
14 years, 8 months
Hibernate SVN: r18444 - in core/trunk/entitymanager/src: main/java/org/hibernate/ejb/criteria and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-07 15:41:54 -0500 (Thu, 07 Jan 2010)
New Revision: 18444
Removed:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/Customer.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/TupleCriteriaTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Customer.java
Log:
HHH-4724 - query.multiselect() on a CriteriaQuery<Tuple> returns List<Object[]> instead of List<Tuple>
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-01-07 20:34:59 UTC (rev 18443)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-01-07 20:41:54 UTC (rev 18444)
@@ -41,12 +41,15 @@
import javax.persistence.PessimisticLockException;
import javax.persistence.Query;
import javax.persistence.TransactionRequiredException;
+import javax.persistence.Tuple;
+import javax.persistence.TupleElement;
import javax.persistence.TypedQuery;
import javax.persistence.PessimisticLockScope;
import javax.persistence.LockTimeoutException;
import javax.persistence.QueryTimeoutException;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Selection;
import javax.persistence.metamodel.Metamodel;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.transaction.Status;
@@ -60,6 +63,7 @@
import org.hibernate.*;
import org.hibernate.cfg.Environment;
import org.hibernate.ejb.criteria.ValueHandlerFactory;
+import org.hibernate.ejb.criteria.expression.CompoundSelectionImpl;
import org.hibernate.ejb.transaction.JoinableCMTTransaction;
import org.hibernate.ejb.util.ConfigurationHelper;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
@@ -68,6 +72,7 @@
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.transaction.TransactionFactory;
import org.hibernate.transform.BasicTransformerAdapter;
+import org.hibernate.transform.ResultTransformer;
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.JTAHelper;
@@ -145,15 +150,24 @@
public <T> TypedQuery<T> createQuery(
String jpaqlString,
Class<T> resultClass,
+ Selection selection,
Options options) {
try {
org.hibernate.Query hqlQuery = getSession().createQuery( jpaqlString );
- if ( options.getValueHandlers() != null ) {
- hqlQuery.setResultTransformer( new ValueConversionResultTransformer( options.getValueHandlers() ) );
- }
- else {
+
+ if ( options.getValueHandlers() == null ) {
options.getResultMetadataValidator().validate( hqlQuery.getReturnTypes() );
}
+
+ // determine if we need a result transformer
+ List tupleElements = Tuple.class.equals( resultClass )
+ ? ( (CompoundSelectionImpl<Tuple>) selection ).getCompoundSelectionItems()
+ : null;
+ if ( options.getValueHandlers() != null || tupleElements != null ) {
+ hqlQuery.setResultTransformer(
+ new CriteriaQueryTransformer( options.getValueHandlers(), tupleElements )
+ );
+ }
return new QueryImpl<T>( hqlQuery, this, options.getNamedParameterExplicitTypes() );
}
catch ( HibernateException he ) {
@@ -161,24 +175,109 @@
}
}
- private static class ValueConversionResultTransformer extends BasicTransformerAdapter {
- private List<ValueHandlerFactory.ValueHandler> valueHandlers;
+ private static class CriteriaQueryTransformer extends BasicTransformerAdapter {
+ private final List<ValueHandlerFactory.ValueHandler> valueHandlers;
+ private final List tupleElements;
- private ValueConversionResultTransformer(List<ValueHandlerFactory.ValueHandler> valueHandlers) {
+ private CriteriaQueryTransformer(List<ValueHandlerFactory.ValueHandler> valueHandlers, List tupleElements) {
+ // todo : should these 2 sizes match *always*?
this.valueHandlers = valueHandlers;
+ this.tupleElements = tupleElements;
}
@Override
public Object transformTuple(Object[] tuple, String[] aliases) {
- Object[] result = new Object[ tuple.length ];
- for ( int i = 0; i < tuple.length; i++ ) {
- ValueHandlerFactory.ValueHandler valueHandler = valueHandlers.get( i );
- result[i] = valueHandler == null
- ? tuple[i]
- : valueHandler.convert( tuple[i] );
+ final Object[] valueHandlerResult;
+ if ( valueHandlers == null ) {
+ valueHandlerResult = tuple;
}
- return result.length == 1 ? result[0] : result;
+ else {
+ valueHandlerResult = new Object[ tuple.length ];
+ for ( int i = 0; i < tuple.length; i++ ) {
+ ValueHandlerFactory.ValueHandler valueHandler = valueHandlers.get( i );
+ valueHandlerResult[i] = valueHandler == null
+ ? tuple[i]
+ : valueHandler.convert( tuple[i] );
+ }
+ }
+
+ return tupleElements == null
+ ? valueHandlerResult.length == 1 ? valueHandlerResult[0] : valueHandlerResult
+ : new TupleImpl( tuple );
+
}
+
+ private class TupleImpl implements Tuple {
+ private final Object[] tuples;
+
+ private TupleImpl(Object[] tuples) {
+ if ( tuples.length != tupleElements.size() ) {
+ throw new IllegalArgumentException(
+ "Size mismatch between tuple result [" + tuples.length
+ + "] and expected tuple elements [" + tupleElements.size() + "]"
+ );
+ }
+ this.tuples = tuples;
+ }
+
+ public <X> X get(TupleElement<X> tupleElement) {
+ int index = tupleElements.indexOf( tupleElement );
+ if ( index < 0 ) {
+ throw new IllegalArgumentException( "Requested tuple element did not correspond to element in the result tuple" );
+ }
+ // index should be "in range" by nature of size check in ctor
+ return (X) tuples[index];
+ }
+
+ public Object get(String alias) {
+ int index = -1;
+ if ( alias != null ) {
+ alias = alias.trim();
+ if ( alias.length() > 0 ) {
+ int i = 0;
+ for ( TupleElement selection : (List<TupleElement>) tupleElements ) {
+ if ( alias.equals( selection.getAlias() ) ) {
+ index = i;
+ break;
+ }
+ i++;
+ }
+ }
+ }
+ if ( index < 0 ) {
+ throw new IllegalArgumentException(
+ "Given alias [" + alias + "] did not correspond to an element in the result tuple"
+ );
+ }
+ // index should be "in range" by nature of size check in ctor
+ return tuples[index];
+ }
+
+ public <X> X get(String alias, Class<X> type) {
+ return (X) get( alias );
+ }
+
+ public Object get(int i) {
+ if ( i >= tuples.length ) {
+ throw new IllegalArgumentException(
+ "Given index [" + i + "] was outside the range of result tuple size [" + tuples.length + "] "
+ );
+ }
+ return tuples[i];
+ }
+
+ public <X> X get(int i, Class<X> type) {
+ return (X) get( i );
+ }
+
+ public Object[] toArray() {
+ return tuples;
+ }
+
+ public List<TupleElement<?>> getElements() {
+ return (List<TupleElement<?>>) tupleElements;
+ }
+ }
}
private CriteriaQueryCompiler criteriaQueryCompiler;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java 2010-01-07 20:34:59 UTC (rev 18443)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java 2010-01-07 20:41:54 UTC (rev 18444)
@@ -26,6 +26,7 @@
import javax.persistence.PersistenceException;
import javax.persistence.LockModeType;
import javax.persistence.TypedQuery;
+import javax.persistence.criteria.Selection;
import org.hibernate.HibernateException;
import org.hibernate.StaleStateException;
@@ -141,9 +142,10 @@
*
* @param jpaqlString The criteria query rendered as a JPA QL string
* @param resultClass The result type (the type expected in the result list)
+ * @param selection The selection(s)
* @param options The options to use to build the query.
* @param <T> The query type
* @return The typed query
*/
- public <T> TypedQuery<T> createQuery(String jpaqlString, Class<T> resultClass, Options options);
+ public <T> TypedQuery<T> createQuery(String jpaqlString, Class<T> resultClass, Selection selection, Options options);
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java 2010-01-07 20:34:59 UTC (rev 18443)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java 2010-01-07 20:41:54 UTC (rev 18444)
@@ -154,6 +154,7 @@
TypedQuery<T> jpaqlQuery = entityManager.createQuery(
renderedCriteriaQuery.getQueryString(),
criteriaQuery.getResultType(),
+ criteriaQuery.getSelection(),
new HibernateEntityManagerImplementor.Options() {
public List<ValueHandlerFactory.ValueHandler> getValueHandlers() {
return renderedCriteriaQuery.getValueHandlers();
Deleted: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/Customer.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/Customer.java 2010-01-07 20:34:59 UTC (rev 18443)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/Customer.java 2010-01-07 20:41:54 UTC (rev 18444)
@@ -1,43 +0,0 @@
-package org.hibernate.ejb.criteria.tuple;
-
-import javax.persistence.Table;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.GeneratedValue;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-@Table(name="tup_cust")
-public class Customer {
- private Long id;
- private String name;
- private Integer age;
-
- @Id
- @GeneratedValue
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Integer getAge() {
- return age;
- }
-
- public void setAge(Integer age) {
- this.age = age;
- }
-}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/TupleCriteriaTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/TupleCriteriaTest.java 2010-01-07 20:34:59 UTC (rev 18443)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/TupleCriteriaTest.java 2010-01-07 20:41:54 UTC (rev 18444)
@@ -3,72 +3,92 @@
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Tuple;
-import javax.persistence.TupleElement;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
-import org.hibernate.ejb.test.TestCase;
+import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
+import org.hibernate.ejb.metamodel.Customer;
+import org.hibernate.ejb.metamodel.Customer_;
/**
* @author Emmanuel Bernard
*/
-public class TupleCriteriaTest extends TestCase {
+public class TupleCriteriaTest extends AbstractMetamodelSpecificTest {
public void testArray() {
EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
Customer c1 = new Customer();
+ c1.setId( "c1" );
c1.setAge( 18 );
c1.setName( "Bob" );
- em.getTransaction().begin();
em.persist( c1 );
- em.flush();
+ em.getTransaction().commit();
+ em.close();
+ em = factory.createEntityManager();
+ em.getTransaction().begin();
final CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> q = cb.createQuery(Object[].class);
Root<Customer> c = q.from(Customer.class);
q.select( cb.array( c.get(Customer_.name), c.get(Customer_.age) ) );
List<Object[]> result = em.createQuery(q).getResultList();
-
assertEquals( 1, result.size() );
assertEquals( c1.getName(), result.get( 0 )[0] );
assertEquals( c1.getAge(), result.get( 0 )[1] );
+ em.getTransaction().commit();
+ em.close();
- em.getTransaction().rollback();
+ em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.createQuery( "delete Customer" ).executeUpdate();
+ em.getTransaction().commit();
em.close();
}
public void testTuple() {
EntityManager em = factory.createEntityManager();
+
+ em.getTransaction().begin();
Customer c1 = new Customer();
+ c1.setId( "c1" );
c1.setAge( 18 );
c1.setName( "Bob" );
- em.getTransaction().begin();
em.persist( c1 );
- em.flush();
+ em.getTransaction().commit();
+ em.close();
- final CriteriaBuilder cb = em.getCriteriaBuilder();
+ em = factory.createEntityManager();
+ em.getTransaction().begin();
+ final CriteriaBuilder builder = em.getCriteriaBuilder();
+ CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
+ Root<Customer> customerRoot = criteria.from( Customer.class );
+ Path<String> namePath = customerRoot.get( Customer_.name );
+ Path<Integer> agePath = customerRoot.get( Customer_.age );
+ agePath.alias( "age" );
+ criteria.multiselect( namePath, agePath );
+ List<Tuple> results = em.createQuery( criteria ).getResultList();
+ assertEquals( 1, results.size() );
+ Object resultElement = results.get( 0 );
+ assertTrue( "Check result 'row' as Tuple", Tuple.class.isInstance( resultElement ) );
+ Tuple resultElementTuple = (Tuple) resultElement;
+ Object[] tupleArray = resultElementTuple.toArray();
+ assertEquals( 2, tupleArray.length );
+ assertEquals( tupleArray[0], resultElementTuple.get( 0 ) );
+ assertEquals( resultElementTuple.get( namePath ), resultElementTuple.get( 0 ) );
+ assertEquals( tupleArray[1], resultElementTuple.get( 1 ) );
+ assertEquals( resultElementTuple.get( agePath ), resultElementTuple.get( 1 ) );
+ assertEquals( resultElementTuple.get( agePath ), resultElementTuple.get( "age" ) );
+ em.getTransaction().commit();
+ em.close();
- CriteriaQuery<Tuple> q = cb.createTupleQuery();
- Root<Customer> c = q.from(Customer.class);
- Path<String> tname = c.get(Customer_.name);
- q.multiselect( tname, c.get(Customer_.age).alias("age") );
- List<Tuple> result = em.createQuery(q).getResultList();
-
- assertEquals( 1, result.size() );
- //FIXME uncomment when HHH-4724 is fixed
-// assertEquals( c1.getName(), result.get(0).get(tname) );
-// assertEquals( c1.getAge(), result.get(0).get("age") );
-
-
- em.getTransaction().rollback();
+ em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.createQuery( "delete Customer" ).executeUpdate();
+ em.getTransaction().commit();
em.close();
}
- public Class[] getAnnotatedClasses() {
- return new Class[] {
- Customer.class
- };
- }
}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Customer.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Customer.java 2010-01-07 20:34:59 UTC (rev 18443)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Customer.java 2010-01-07 20:41:54 UTC (rev 18444)
@@ -45,6 +45,7 @@
public class Customer implements java.io.Serializable {
private String id;
private String name;
+ private Integer age;
private Address home;
private Address work;
private Country country;
@@ -96,6 +97,15 @@
this.name = v;
}
+ @Column(name = "AGE")
+ public Integer getAge() {
+ return age;
+ }
+
+ public void setAge(Integer age) {
+ this.age = age;
+ }
+
@Embedded
public Country getCountry() {
return country;
14 years, 8 months