Hibernate SVN: r16372 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-04-21 07:29:01 -0400 (Tue, 21 Apr 2009)
New Revision: 16372
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolation.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
Log:
BVAL-150 add ConstraintViolation#getRootBeanClass
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolation.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolation.java 2009-04-21 11:03:38 UTC (rev 16371)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolation.java 2009-04-21 11:29:01 UTC (rev 16372)
@@ -44,6 +44,11 @@
T getRootBean();
/**
+ * @return The class of the root bean being validated
+ */
+ Class<T> getRootBeanClass();
+
+ /**
* If a bean constraint, the bean instance the constraint is applied on
* If a property constraint, the bean instance hosting the property the
* constraint is applied on
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java 2009-04-21 11:03:38 UTC (rev 16371)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintViolationImpl.java 2009-04-21 11:29:01 UTC (rev 16372)
@@ -25,17 +25,18 @@
* @author Hardy Ferentschik
*/
public class ConstraintViolationImpl<T> implements ConstraintViolation<T> {
- private String interpolatedMessage;
- private T rootBean;
- private Object value;
- private String propertyPath;
- private Object leafBeanInstance;
+ private final String interpolatedMessage;
+ private final T rootBean;
+ private final Object value;
+ private final String propertyPath;
+ private final Object leafBeanInstance;
private final ConstraintDescriptor constraintDescriptor;
- private String rawMessage;
+ private final String rawMessage;
+ private final Class<T> rootBeanClass;
- public ConstraintViolationImpl(String messageTemplate, String interpolatedMessage, T rootBean,
- Object leafBeanInstance, Object value,
+ public ConstraintViolationImpl(String messageTemplate, String interpolatedMessage, Class<T> rootBeanClass,
+ T rootBean, Object leafBeanInstance, Object value,
String propertyPath, ConstraintDescriptor constraintDescriptor) {
this.rawMessage = messageTemplate;
this.interpolatedMessage = interpolatedMessage;
@@ -44,6 +45,7 @@
this.propertyPath = propertyPath;
this.leafBeanInstance = leafBeanInstance;
this.constraintDescriptor = constraintDescriptor;
+ this.rootBeanClass = rootBeanClass;
}
/**
@@ -64,6 +66,10 @@
return rootBean;
}
+ public Class<T> getRootBeanClass() {
+ return rootBeanClass;
+ }
+
public Object getLeafBean() {
return leafBeanInstance;
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-04-21 11:03:38 UTC (rev 16371)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-04-21 11:29:01 UTC (rev 16372)
@@ -283,6 +283,7 @@
return new ConstraintViolationImpl<T>(
messageTemplate,
interpolatedMessage,
+ null, //FIXME get the rootBeanClass
getRootBean(),
peekCurrentBean(),
value,
15 years, 7 months
Hibernate SVN: r16371 - in entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test: association and 11 other directories.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-04-21 07:03:38 -0400 (Tue, 21 Apr 2009)
New Revision: 16371
Modified:
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/EntityManagerTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/QueryTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/TestCase.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/association/AssociationTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/CascadeTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/FetchTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/FetchTest2.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/FlushTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/MergeTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/RefreshTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/RemoveTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/inheritance/InheritanceTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/lob/BlobTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/lock/LockTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/ops/FindTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/ops/MergeNewTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java
entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/xml/XmlTest.java
Log:
EJB-430 - Applied patch to avoid locking transactions when exceptions occurs in EM tests - Branch v3_3_2_GA_CP
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/EntityManagerTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/EntityManagerTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/EntityManagerTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -49,7 +49,7 @@
//
// Item item = new Item( "Mouse", "Micro$oft mouse" );
//
-// EntityManager em = factory.createEntityManager();
+// EntityManager em = getOrCreateEntityManager();
// em.getTransaction().begin();
// em.persist( item );
// assertTrue( em.contains( item ) );
@@ -95,7 +95,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -148,7 +148,7 @@
stats.clear();
stats.setStatisticsEnabled( true );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( res );
@@ -161,7 +161,7 @@
assertEquals( 1, stats.getSecondLevelCachePutCount() );
assertEquals( 0, stats.getSecondLevelCacheHitCount() );
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Item second = em.find( Item.class, item.getName() );
assertEquals( 1, second.getDistributors().size() );
@@ -169,7 +169,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
second = em.find( Item.class, item.getName() );
assertEquals( 1, second.getDistributors().size() );
@@ -184,7 +184,7 @@
}
public void testContains() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Integer nonManagedObject = new Integer( 4 );
try {
@@ -198,7 +198,7 @@
finally {
em.close();
}
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Item item = new Item();
item.setDescr( "Mine" );
@@ -214,7 +214,7 @@
}
public void testClear() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand( "Lacoste" );
@@ -229,7 +229,7 @@
}
public void testFlushMode() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.setFlushMode( FlushModeType.COMMIT );
assertEquals( FlushModeType.COMMIT, em.getFlushMode() );
( (HibernateEntityManager) em ).getSession().setFlushMode( FlushMode.ALWAYS );
@@ -238,7 +238,7 @@
}
public void testPersistNoneGenerator() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand( "Lacoste" );
@@ -255,7 +255,7 @@
}
public void testSerializableException() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Query query = em.createQuery( "SELECT p FETCH JOIN p.distributors FROM Item p" );
@@ -297,7 +297,7 @@
}
public void testIsOpen() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
assertTrue( em.isOpen() );
em.getTransaction().begin();
assertTrue( em.isOpen() );
@@ -308,7 +308,7 @@
//EJB-9
// public void testGet() throws Exception {
-// EntityManager em = factory.createEntityManager();
+// EntityManager em = getOrCreateEntityManager();
// em.getTransaction().begin();
// Item item = (Item) em.get(Item.class, "nonexistentone");
// try {
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -258,7 +258,7 @@
//
// Item item = new Item( "Mouse", "Micro$oft mouse" );
//
-// EntityManager em = factory.createEntityManager();
+// EntityManager em = getOrCreateEntityManager();
// em.getTransaction().begin();
// em.persist( item );
// assertTrue( em.contains( item ) );
@@ -307,7 +307,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -360,7 +360,7 @@
stats.clear();
stats.setStatisticsEnabled( true );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( res );
@@ -373,7 +373,7 @@
assertEquals( 1, stats.getSecondLevelCachePutCount() );
assertEquals( 0, stats.getSecondLevelCacheHitCount() );
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Item second = em.find( Item.class, item.getName() );
assertEquals( 1, second.getDistributors().size() );
@@ -381,7 +381,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
second = em.find( Item.class, item.getName() );
assertEquals( 1, second.getDistributors().size() );
@@ -398,7 +398,7 @@
}
public void testExternalJar() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Scooter s = new Scooter();
s.setModel( "Abadah" );
s.setSpeed( 85l );
@@ -406,7 +406,7 @@
em.persist( s );
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
s = em.find( Scooter.class, s.getModel() );
assertEquals( new Long( 85 ), s.getSpeed() );
@@ -416,7 +416,7 @@
}
public void testORMFileOnMainAndExplicitJars() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Seat seat = new Seat();
seat.setNumber( "3B" );
Airplane plane = new Airplane();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/QueryTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/QueryTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/QueryTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -17,7 +17,7 @@
public class QueryTest extends TestCase {
public void testPagedQuery() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Item item = new Item( "Mouse", "Micro$oft mouse" );
em.persist( item );
@@ -36,7 +36,7 @@
}
public void testAggregationReturnType() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Item item = new Item( "Mouse", "Micro$oft mouse" );
em.persist( item );
@@ -53,7 +53,7 @@
final Item item = new Item( "Mouse", "Micro$oft mouse" );
final Item item2 = new Item( "Computer", "D�ll computer" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
em.persist( item2 );
@@ -97,7 +97,7 @@
// auchan.setName("Auchan");
// item.addDistributor(auchan);
//
-// EntityManager em = factory.createEntityManager();
+// EntityManager em = getOrCreateEntityManager();
// em.getTransaction().begin();
// em.persist(fnac);
// em.persist(auchan);
@@ -125,7 +125,7 @@
final Item item = new Item( "Mouse", "Micro_oft mouse" );
final Item item2 = new Item( "Computer", "D�ll computer" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
em.persist( item2 );
@@ -148,7 +148,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -169,7 +169,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -188,7 +188,7 @@
}
public void testExplicitPositionalParameter() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand( "Lacoste" );
@@ -213,7 +213,7 @@
}
public void testNativeQuestionMarkParameter() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand( "Lacoste" );
@@ -235,7 +235,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -260,7 +260,7 @@
}
public void testDistinct() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.createQuery( "delete Item" ).executeUpdate();
em.createQuery( "delete Distributor" ).executeUpdate();
@@ -288,7 +288,7 @@
}
public void testIsNull() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Distributor d1 = new Distributor();
d1.setName( "Fnac" );
@@ -324,7 +324,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -349,7 +349,7 @@
public void testUnavailableNamedQuery() throws Exception {
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
try {
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/TestCase.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/TestCase.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/TestCase.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -7,9 +7,13 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+
+import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.ejb.HibernatePersistence;
@@ -20,6 +24,8 @@
*/
public abstract class TestCase extends junit.framework.TestCase {
protected EntityManagerFactory factory;
+ protected EntityManager em;
+ private static Log log = LogFactory.getLog( TestCase.class );
public TestCase() {
super();
@@ -36,7 +42,43 @@
public void tearDown() {
factory.close();
}
+
+ @Override
+ public void runTest() throws Throwable {
+ try {
+ em = getOrCreateEntityManager();
+ super.runTest();
+ if (em.getTransaction().isActive()) {
+ em.getTransaction().rollback();
+ fail("You left an open transaction! Fix your test case. For now, we are closing it for you.");
+ }
+ } catch (Throwable t) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
+ throw t;
+ } finally {
+ if (em.isOpen()) {
+ em.close();
+ log.warn("The test case didn't closed the Entity Manager. Make sure you close it always!");
+ }
+ }
+ }
+
+ protected EntityManager getOrCreateEntityManager() {
+ if (em == null || !em.isOpen())
+ em = factory.createEntityManager();
+ return em;
+ }
+ /** always reopen a new EM and clse the existing one */
+ protected EntityManager createEntityManager(Map properties) {
+ if (em != null && em.isOpen() ) {
+ em.close();
+ }
+ em = factory.createEntityManager(properties);
+ return em;
+ }
+
public abstract Class[] getAnnotatedClasses();
public String[] getEjb3DD() {
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/association/AssociationTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/association/AssociationTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/association/AssociationTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -10,7 +10,7 @@
*/
public class AssociationTest extends TestCase {
public void testBidirOneToOne() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
String id = "10";
Incident i = em.find( Incident.class, id );
@@ -30,7 +30,7 @@
}
public void testMergeAndBidirOneToOne() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Oven oven = new Oven();
Kitchen kitchen = new Kitchen();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -13,7 +13,7 @@
public class CallbackAndDirtyTest extends TestCase {
public void testDirtyButNotDirty() throws Exception {
- EntityManager manager = factory.createEntityManager();
+ EntityManager manager = getOrCreateEntityManager();
manager.getTransaction().begin();
Employee mark = new Employee();
mark.setName( "Mark" );
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -14,7 +14,7 @@
public class CallbacksTest extends TestCase {
public void testCallbackMethod() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
c.setName( "Kitty" );
c.setDateOfBirth( new Date( 90, 11, 15 ) );
@@ -36,7 +36,7 @@
}
public void testEntityListener() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
c.setName( "Kitty" );
c.setLength( 12 );
@@ -63,7 +63,7 @@
public void testPostPersist() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
em.getTransaction().begin();
c.setLength( 23 );
@@ -80,7 +80,7 @@
//Not a test since the spec did not make the proper change on listeners
public void listenerAnnotation() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Translation tl = new Translation();
em.getTransaction().begin();
tl.setInto( "France" );
@@ -102,7 +102,7 @@
}
public void testPrePersistOnCascade() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Television tv = new Television();
RemoteControl rc = new RemoteControl();
@@ -116,7 +116,7 @@
}
public void testCallBackListenersHierarchy() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Television tv = new Television();
em.persist( tv );
@@ -131,7 +131,7 @@
}
public void testException() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Rythm r = new Rythm();
try {
@@ -154,7 +154,7 @@
public void testIdNullSetByPrePersist() throws Exception {
Plant plant = new Plant();
plant.setName( "Origuna plantula gigantic" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( plant );
em.flush();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/CascadeTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/CascadeTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/CascadeTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -14,7 +14,7 @@
public void testCascade() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Teacher teacher = null;
@@ -33,7 +33,7 @@
em.getTransaction().commit();
System.out.println("***************************");
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Teacher foundTeacher = (Teacher) em.createQuery( "select t from Teacher as t" ).getSingleResult();
@@ -59,7 +59,7 @@
e1.setAuthor(e2);
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(e2);
@@ -67,7 +67,7 @@
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
e1 = em.find(Song.class, e1.getId());
e2 = null;
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -20,7 +20,7 @@
public void testDeleteOrphan() throws Exception {
EntityTransaction tx;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Troop disney = new Troop();
@@ -33,7 +33,7 @@
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Troop troop = em.find( Troop.class, disney.getId() );
@@ -45,14 +45,14 @@
troop.getSoldiers().remove( soldier );
troop = (Troop) unserialize( serialize( troop ) );
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
em.merge( troop );
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
soldier = em.find( Soldier.class, mickey.getId() );
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/FetchTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/FetchTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/FetchTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -17,7 +17,7 @@
public class FetchTest extends TestCase {
public void testCascadeAndFetchCollection() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop disney = new Troop();
disney.setName( "Disney" );
@@ -28,7 +28,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop troop = em.find( Troop.class, disney.getId() );
assertFalse( Hibernate.isInitialized( troop.getSoldiers() ) );
@@ -36,7 +36,7 @@
assertFalse( Hibernate.isInitialized( troop.getSoldiers() ) );
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
troop = em.find( Troop.class, disney.getId() );
em.remove( troop );
@@ -46,7 +46,7 @@
}
public void testCascadeAndFetchEntity() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop disney = new Troop();
disney.setName( "Disney" );
@@ -57,14 +57,14 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Soldier soldier = em.find( Soldier.class, mickey.getId() );
assertFalse( Hibernate.isInitialized( soldier.getTroop() ) );
em.getTransaction().commit();
assertFalse( Hibernate.isInitialized( soldier.getTroop() ) );
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop troop = em.find( Troop.class, disney.getId() );
em.remove( troop );
@@ -76,7 +76,7 @@
public void testTwoLevelDeepPersist() throws Exception {
EntityTransaction tx;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Conference jbwBarcelona = new Conference();
@@ -94,7 +94,7 @@
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
jbwBarcelona = em.find( Conference.class, jbwBarcelona.getId() );
@@ -112,7 +112,7 @@
public void testTwoLevelDeepPersistOnManyToOne() throws Exception {
EntityTransaction tx;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Grandson gs = new Grandson();
@@ -121,7 +121,7 @@
em.persist( gs );
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
gs = em.find( Grandson.class, gs.getId() );
@@ -134,7 +134,7 @@
}
public void testPerfCascadeAndFetchEntity() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
//init data
em.getTransaction().begin();
int loop = 50;
@@ -150,7 +150,7 @@
em.close();
//Warm up loop
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
for ( int i = 0; i < loop ; i++ ) {
//Soldier soldier = em.find( Soldier.class, new Integer(i) );
@@ -167,7 +167,7 @@
//do not evict
for ( int j = 0; j < 10 ; j++ ) {
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
for ( int i = 0; i < loop ; i++ ) {
Troop troop = em.find( Troop.class, new Integer( i ) );
@@ -182,7 +182,7 @@
em.close();
//evict
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
for ( int i = 0; i < loop ; i++ ) {
//Soldier soldier = em.find( Soldier.class, new Integer(i) );
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/FetchTest2.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/FetchTest2.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/cascade/FetchTest2.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -8,7 +8,7 @@
public void testProxyTransientStuff() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop2 disney = new Troop2();
@@ -24,7 +24,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Soldier2 soldier = em.find( Soldier2.class, mickey.getId() );
@@ -39,7 +39,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
//load troop wo a proxy
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/FlushTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/FlushTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/FlushTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -26,7 +26,7 @@
//Test for EJBTHREE-722
public void testFlushOnDetached() throws Exception {
- EntityManager manager = factory.createEntityManager( );
+ EntityManager manager = getOrCreateEntityManager( );
manager.getTransaction().begin();
Pet p1 = createCat("Toonses", 15.0, 9, manager);
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -12,7 +12,7 @@
public class GetReferenceTest extends TestCase {
public void testWrongIdType() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
try {
Competitor c = em.getReference( Competitor.class, new String("30") );
fail("Expected IllegalArgumentException");
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/MergeTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -16,7 +16,7 @@
race.competitors.add( new Competitor("Name") );
race.competitors.add( new Competitor() );
race.competitors.add( new Competitor() );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.flush();
@@ -40,7 +40,7 @@
competition.getCompetitors().add( new Competitor("Name") );
competition.getCompetitors().add( new Competitor() );
competition.getCompetitors().add( new Competitor() );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( competition );
em.flush();
@@ -64,7 +64,7 @@
competition.getCompetitors().add( new Competitor("Name") );
competition.getCompetitors().add( new Competitor() );
competition.getCompetitors().add( new Competitor() );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( competition );
em.flush();
@@ -86,7 +86,7 @@
public void testRemoveAndMerge() {
Race race = new Race();
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.flush();
@@ -111,7 +111,7 @@
public void testConcurrentMerge() {
Race race = new Race();
race.name = "Derby";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.flush();
@@ -120,7 +120,7 @@
race.name = "Magnicourt";
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Race race2 = em.find(Race.class, race.id );
race2.name = "Mans";
@@ -130,7 +130,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
race2 = em.find(Race.class, race.id );
assertEquals( "Last commit win in merge", "Magnicourt", race2.name );
@@ -141,7 +141,7 @@
}
public void testMergeUnidirectionalOneToMany() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Empire roman = new Empire();
em.persist( roman );
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/RefreshTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/RefreshTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/RefreshTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -11,7 +11,7 @@
public class RefreshTest extends TestCase {
public void testRefreshNonManaged() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Race race = new Race();
em.persist( race );
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/RemoveTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/RemoveTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/RemoveTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -16,7 +16,7 @@
race.competitors.add( new Competitor() );
race.competitors.add( new Competitor() );
race.competitors.add( new Competitor() );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.flush();
@@ -28,7 +28,7 @@
public void testRemoveAndFind() {
Race race = new Race();
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.remove( race );
@@ -40,26 +40,27 @@
public void testUpdatedAndRemove() {
Music music = new Music();
music.setName( "Classical" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( music );
em.getTransaction().commit();
em.clear();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
EntityManager em2 = factory.createEntityManager();
- em2.getTransaction().begin();
- //read music from 2nd EM
- music = em2.find( Music.class, music.getId() );
-
//change music
em.find( Music.class, music.getId() ).setName( "Rap" );
em.getTransaction().commit();
try {
+ em2.getTransaction().begin();
+
+ //read music from 2nd EM
+ music = em2.find( Music.class, music.getId() );
+
em2.remove( music ); //remove changed music
em2.flush();
fail("should have an optimistic lock exception");
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -13,7 +13,7 @@
public class CascadePersistTest extends TestCase {
public void testLazyCollectionsStayLazyOnPersist() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
//initialize
A a = new A();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -15,7 +15,7 @@
public class ExceptionTest extends TestCase {
public void testOptimisticLockingException() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
EntityManager em2 = factory.createEntityManager();
em.getTransaction().begin();
Music music = new Music();
@@ -50,7 +50,7 @@
}
public void testEntityNotFoundException() throws Exception {
- EntityManager em = factory.createEntityManager( );
+ EntityManager em = getOrCreateEntityManager( );
Music music = em.getReference( Music.class, new Integer(-1) );
try {
music.getName();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/inheritance/InheritanceTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/inheritance/InheritanceTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/inheritance/InheritanceTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -11,7 +11,7 @@
public class InheritanceTest extends TestCase {
public void testFind() throws Exception {
- EntityManager firstSession = factory.createEntityManager( );
+ EntityManager firstSession = getOrCreateEntityManager( );
Strawberry u = new Strawberry();
u.setSize( 12l );
firstSession.getTransaction().begin();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/lob/BlobTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/lob/BlobTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/lob/BlobTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -18,7 +18,7 @@
public class BlobTest extends TestCase {
public void testBlobSerialization() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Map image = new HashMap();
image.put( "meta", "metadata" );
@@ -31,7 +31,7 @@
em.persist( reader );
em.getTransaction().commit();
em.close(); //useless but y'a know
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
reader = em.find( ImageReader.class, reader.getId() );
ObjectInputStream ois = new ObjectInputStream( reader.getImage().getBinaryStream() );
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/lock/LockTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/lock/LockTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/lock/LockTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -14,7 +14,7 @@
public void testLockRead() throws Exception {
Lock lock = new Lock();
lock.setName( "name" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( lock );
em.getTransaction().commit();
@@ -35,7 +35,7 @@
public void testLockWrite() throws Exception {
Lock lock = new Lock();
lock.setName( "second" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( lock );
em.getTransaction().commit();
@@ -61,7 +61,7 @@
public void testLockWriteOnUnversioned() throws Exception {
UnversionedLock lock = new UnversionedLock();
lock.setName( "second" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( lock );
em.getTransaction().commit();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/ops/FindTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/ops/FindTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/ops/FindTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -14,7 +14,7 @@
Mammal mammal = new Mammal();
mammal.setMamalNbr( 2 );
mammal.setName( "Human" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( mammal );
em.flush();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/ops/MergeNewTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/ops/MergeNewTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/ops/MergeNewTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -14,7 +14,7 @@
Workload load = new Workload();
load.name = "Cleaning";
load.load = 10;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
load = em.merge( load );
assertNotNull( load.id );
@@ -28,20 +28,20 @@
Workload load = new Workload();
load.name = "Cleaning";
load.load = 10;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
load = em.merge( load );
em.flush();
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
load = em.find( Workload.class, load.id );
em.remove( load );
em.flush();
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
em.merge( load );
em.flush();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -21,7 +21,7 @@
public void testAlwaysTransactionalOperations() throws Exception {
Book book = new Book();
book.name = "Le petit prince";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( book );
em.getTransaction().commit();
@@ -47,7 +47,7 @@
// public void testTransactionalOperationsWhenTransactional() throws Exception {
// Book book = new Book();
// book.name = "Le petit prince";
-// EntityManager em = factory.createEntityManager( PersistenceContextType.TRANSACTION );
+// EntityManager em = getOrCreateEntityManager( PersistenceContextType.TRANSACTION );
// try {
// em.persist( book );
// fail("flush has to be inside a Tx");
@@ -75,7 +75,7 @@
public void testTransactionalOperationsWhenExtended() throws Exception {
Book book = new Book();
book.name = "Le petit prince";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Statistics stats = ( (HibernateEntityManagerFactory) factory ).getSessionFactory().getStatistics();
stats.clear();
stats.setStatisticsEnabled( true );
@@ -118,7 +118,7 @@
public void testMergeWhenExtended() throws Exception {
Book book = new Book();
book.name = "Le petit prince";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Statistics stats = ( (HibernateEntityManagerFactory) factory ).getSessionFactory().getStatistics();
em.getTransaction().begin();
@@ -159,7 +159,7 @@
}
public void testCloseAndTransaction() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Book book = new Book();
book.name = "Java for Dummies";
@@ -176,7 +176,7 @@
}
em.getTransaction().commit();
assertFalse( em.isOpen() );
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
book = em.find( Book.class, book.id );
assertEquals( "C# for Dummies", book.name );
@@ -186,14 +186,14 @@
}
public void testTransactionCommitDoesNotFlush() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Book book = new Book();
book.name = "Java for Dummies";
em.persist( book );
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
List result = em.createQuery("select book from Book book where book.name = :title").
setParameter( "title", book.name ).getResultList();
@@ -203,14 +203,14 @@
}
public void testTransactionAndContains() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Book book = new Book();
book.name = "Java for Dummies";
em.persist( book );
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
List result = em.createQuery("select book from Book book where book.name = :title").
setParameter( "title", book.name ).getResultList();
@@ -225,7 +225,7 @@
Book book = new Book();
book.name = "Stolen keys";
book.id = null; //new Integer( 50 );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
em.persist( book );
@@ -260,7 +260,7 @@
Book book = new Book();
book.name = "Stolen keys";
book.id = null; //new Integer( 50 );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( book );
em.flush();
@@ -287,7 +287,7 @@
public void testRollbackClearPC() throws Exception {
Book book = new Book();
book.name = "Stolen keys";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( book );
em.getTransaction().commit();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -11,7 +11,7 @@
public class XmlAttributeOverrideTest extends TestCase {
public void testAttributeOverriding() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Employee e = new Employee();
@@ -29,7 +29,7 @@
}
public void testDefaultEventListener() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CounterListener.reset();
Modified: entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/xml/XmlTest.java
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/xml/XmlTest.java 2009-04-21 09:57:14 UTC (rev 16370)
+++ entitymanager/branches/v3_3_2_GA_CP/src/test/org/hibernate/ejb/test/xml/XmlTest.java 2009-04-21 11:03:38 UTC (rev 16371)
@@ -10,7 +10,7 @@
*/
public class XmlTest extends TestCase {
public void testXmlMappingCorrectness() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.close();
}
15 years, 7 months
Hibernate SVN: r16370 - beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-04-21 05:57:14 -0400 (Tue, 21 Apr 2009)
New Revision: 16370
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/BootstrapState.java
Log:
BVAL-149 Provide access to the ValidationProviderResolver via BootstrapState
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/BootstrapState.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/BootstrapState.java 2009-04-21 09:55:35 UTC (rev 16369)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/BootstrapState.java 2009-04-21 09:57:14 UTC (rev 16370)
@@ -6,6 +6,7 @@
* Defines the state used to bootstrap the Configuration
*
* @author Emmanuel Bernard
+ * @author Sebastian Thomschke
*/
public interface BootstrapState {
/**
15 years, 7 months
Hibernate SVN: r16369 - beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-04-21 05:55:35 -0400 (Tue, 21 Apr 2009)
New Revision: 16369
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/BootstrapState.java
validator/trunk/hibernate-validator/pom.xml
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
Log:
BVAL-149 Provide access to the ValidationProviderResolver via BootstrapState
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-04-21 09:51:00 UTC (rev 16368)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-04-21 09:55:35 UTC (rev 16369)
@@ -199,13 +199,16 @@
"builder is mandatory. Use Validation.byDefaultProvider() to use the generic provider discovery mechanism"
);
}
+ GenericBootstrapImpl state = new GenericBootstrapImpl();
if ( resolver == null ) {
- resolver = new DefaultValidationProviderResolver();
+ resolver = state.getDefaultValidationProviderResolver();
}
+ else {
+ //stay null if no resolver is defined
+ state.providerResolver( resolver );
+ }
for ( ValidationProvider provider : resolver.getValidationProviders() ) {
if ( provider.isSuitable( configurationType ) ) {
- GenericBootstrapImpl state = new GenericBootstrapImpl();
- state.providerResolver( resolver );
return provider.createSpecializedConfiguration( state, configurationType );
}
}
@@ -217,6 +220,7 @@
private static class GenericBootstrapImpl implements GenericBootstrap, BootstrapState {
private ValidationProviderResolver resolver;
+ private ValidationProviderResolver defaultResolver;
public GenericBootstrap providerResolver(ValidationProviderResolver resolver) {
this.resolver = resolver;
@@ -227,9 +231,16 @@
return resolver;
}
+ public ValidationProviderResolver getDefaultValidationProviderResolver() {
+ if (defaultResolver == null) {
+ defaultResolver = new DefaultValidationProviderResolver();
+ }
+ return defaultResolver;
+ }
+
public Configuration<?> configure() {
ValidationProviderResolver resolver = this.resolver == null ?
- new DefaultValidationProviderResolver() :
+ getDefaultValidationProviderResolver() :
this.resolver;
if ( resolver.getValidationProviders().size() == 0 ) {
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/BootstrapState.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/BootstrapState.java 2009-04-21 09:51:00 UTC (rev 16368)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/spi/BootstrapState.java 2009-04-21 09:55:35 UTC (rev 16369)
@@ -9,10 +9,17 @@
*/
public interface BootstrapState {
/**
- * returns the user defined ValidationProviderResolver strategy instance or <code>null</code>
+ * User defined ValidationProviderResolver strategy instance or <code>null</code>
* if undefined.
*
* @return ValidationProviderResolver instance or null
*/
ValidationProviderResolver getValidationProviderResolver();
+
+ /**
+ * Specification default ValidationProviderResolver strategy instance
+ *
+ * @return default implementation of ValidationProviderResolver
+ */
+ ValidationProviderResolver getDefaultValidationProviderResolver();
}
Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml 2009-04-21 09:51:00 UTC (rev 16368)
+++ validator/trunk/hibernate-validator/pom.xml 2009-04-21 09:55:35 UTC (rev 16369)
@@ -24,7 +24,7 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
- <version>1.0.CR1</version>
+ <version>1.0.CR2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-04-21 09:51:00 UTC (rev 16368)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-04-21 09:55:35 UTC (rev 16369)
@@ -78,7 +78,7 @@
public ConfigurationImpl(BootstrapState state) {
if ( state.getValidationProviderResolver() == null ) {
- this.providerResolver = new DefaultValidationProviderResolver();
+ this.providerResolver = state.getDefaultValidationProviderResolver();
}
else {
this.providerResolver = state.getValidationProviderResolver();
15 years, 7 months
Hibernate SVN: r16368 - beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-04-21 05:51:00 -0400 (Tue, 21 Apr 2009)
New Revision: 16368
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java
Log:
BVAL-148 add @Constraint on built-in annotations
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertFalse.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be false.
@@ -36,6 +37,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface AssertFalse {
String message() default "{constraint.assertFalse}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/AssertTrue.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be true.
@@ -36,6 +37,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface AssertTrue {
String message() default "{constraint.assertTrue}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be a number whose value must be lower or
@@ -47,6 +48,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface DecimalMax {
String message() default "{constraint.decimalmax}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMin.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be a number whose value must be higher or
@@ -47,6 +48,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface DecimalMin {
String message() default "{constraint.decimalmin}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Digits.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be a number within accepted range
@@ -44,6 +45,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface Digits {
String message() default "{constraint.digits}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Future.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be a date in the future.
@@ -44,6 +45,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface Future {
String message() default "{constraint.future}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Max.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be a number whose value must be lower or
@@ -46,6 +47,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface Max {
String message() default "{constraint.max}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Min.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be a number whose value must be higher or
@@ -46,6 +47,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface Min {
String message() default "{constraint.min}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/NotNull.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must not be <code>null</code>.
@@ -34,6 +35,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface NotNull {
String message() default "{constraint.notNull}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Null.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be null.
@@ -34,6 +35,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface Null {
String message() default "{constraint.null}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Past.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
+import javax.validation.Constraint;
/**
* The annotated element must be a date in the past.
@@ -44,6 +45,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface Past {
String message() default "{constraint.past}";
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Pattern.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -7,6 +7,7 @@
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import javax.validation.Constraint;
/**
* The annotated String must match the following regular expression.
@@ -20,6 +21,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface Pattern {
/**
* regular expression to match
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java 2009-04-20 22:26:31 UTC (rev 16367)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/Size.java 2009-04-21 09:51:00 UTC (rev 16368)
@@ -24,6 +24,7 @@
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import javax.validation.Constraint;
/**
* The annotated element size must be between the specified boundaries (included).
@@ -42,6 +43,7 @@
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
+@Constraint(validatedBy = {})
public @interface Size {
String message() default "{constraint.size}";
Class<?>[] groups() default {};
15 years, 7 months
Hibernate SVN: r16367 - in core/branches/antlr3/src: main/java/org/hibernate/sql/ast/common and 7 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-04-20 18:26:31 -0400 (Mon, 20 Apr 2009)
New Revision: 16367
Added:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PropertyPathTerminus.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ResolutionContext.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategy.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathedPropertyReferenceSource.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/TreePrinter.java
Removed:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ASTAppender.java
Modified:
core/branches/antlr3/src/main/java/org/hibernate/loader/CollectionAliases.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateTree.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ASTPrinter.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/DisplayableNode.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/NodeTraverser.java
core/branches/antlr3/src/test/java/org/hibernate/sql/TemplateTest.java
Log:
tree package
Modified: core/branches/antlr3/src/main/java/org/hibernate/loader/CollectionAliases.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/loader/CollectionAliases.java 2009-04-20 21:58:44 UTC (rev 16366)
+++ core/branches/antlr3/src/main/java/org/hibernate/loader/CollectionAliases.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -25,46 +25,53 @@
package org.hibernate.loader;
/**
- * Type definition of CollectionAliases.
+ * Defines the column names/aliases we can use to read selected values correlating to various part of a collection from
+ * the result set. For example, {@link #getSuffixedKeyAliases()} identifies the column/alias which represent the
+ * values for the collection key (the values mapped using <key/> in the metadata).
*
* @author Steve Ebersole
*/
public interface CollectionAliases {
/**
- * Returns the suffixed result-set column-aliases for columns making
- * up the key for this collection (i.e., its FK to its owner).
+ * Retrieve the aliases to the collection key values (i.e., the <tt>FK</tt> to its owner).
*
- * @return The key result-set column aliases.
+ * @return The collection key result-set column aliases.
*/
public String[] getSuffixedKeyAliases();
/**
- * Returns the suffixed result-set column-aliases for the collumns
- * making up the collection's index (map or list).
+ * Retrieve the aliases to the "collection identifer", which is the PK of the entity which owns this collection.
+ * Can be different from {@link #getSuffixedKeyAliases()} in the case of <property-ref/>, though usually these
+ * will be the same values.
*
- * @return The index result-set column aliases.
+ * @return The collection identifier result-set column aliases.
*/
- public String[] getSuffixedIndexAliases();
+ public String getSuffixedIdentifierAlias();
/**
- * Returns the suffixed result-set column-aliases for the columns
- * making up the collection's elements.
+ * Retrieve the aliases to the collection index values (pertinent only for indexed collections like
+ * {@link java.util.Map} and {@link java.util.List}).
*
- * @return The element result-set column aliases.
+ * @return The collection index result-set column aliases.
*/
- public String[] getSuffixedElementAliases();
+ public String[] getSuffixedIndexAliases();
/**
- * Returns the suffixed result-set column-aliases for the column
- * defining the collection's identifier (if any).
+ * Retrieve the aliases to the values defining the collection values. The "values" of a collection of different
+ * depending on the type of elements defined in the metadata (is it a value colletion or an entity collection)<ul>
+ * <li><b><elements></b> - represents a colletion of values (e.g. Strings); the aliases here would represent
+ * the columns making up the element values</li>
+ * <li><b><one-to-many></b> - ???</li>
+ * <li><b><many-to-many></b> - the aliases here would represent the values from the association table which
+ * map to the related element entity's; normally this would be the same as the element entity's PK value but could
+ * be different in the case of a <property-ref/>.
*
- * @return The identifier result-set column aliases.
+ * @return The collection element result-set column aliases.
*/
- public String getSuffixedIdentifierAlias();
+ public String[] getSuffixedElementAliases();
/**
- * Returns the suffix used to unique the column aliases for this
- * particular alias set.
+ * Returns the suffix used to unique the column aliases for this particular alias set.
*
* @return The uniqued column alias suffix.
*/
Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateTree.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateTree.java 2009-04-20 21:58:44 UTC (rev 16366)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateTree.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -61,6 +61,10 @@
this( new HibernateToken( type, text ) );
}
+ public HibernateTree(int type) {
+ this( new HibernateToken( type ) );
+ }
+
public Tree dupNode() {
return new HibernateTree( this );
}
Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java 2009-04-20 21:58:44 UTC (rev 16366)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -30,11 +30,12 @@
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
-import org.hibernate.sql.ast.util.ASTPrinter;
+import org.hibernate.sql.ast.util.TreePrinter;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.tree.Tree;
/**
* A translator which coordinates translation of an <tt>order-by</tt> mapping.
@@ -61,7 +62,12 @@
OrderByParserLexer lexer = new OrderByParserLexer( new ANTLRStringStream( fragment ) );
OrderByFragmentParser parser = new OrderByFragmentParser( new CommonTokenStream( lexer ), context );
try {
- parser.orderByFragment();
+ Tree tree = ( Tree ) parser.orderByFragment().getTree();
+
+ if ( log.isTraceEnabled() ) {
+ TreePrinter printer = new TreePrinter( OrderByParserParser.class );
+ log.trace( printer.renderAsString( tree, "--- {order-by fragment} ---" ) );
+ }
}
catch ( HibernateException e ) {
throw e;
@@ -70,11 +76,6 @@
throw new HibernateException( "Unable to parse order-by fragment", t );
}
-// if ( log.isTraceEnabled() ) {
-// ASTPrinter printer = new ASTPrinter( OrderByParserParser.class );
-// log.trace( printer.showAsString( parser..getAST(), "--- {order-by fragment} ---" ) );
-// }
-//
// OrderByFragmentRenderer renderer = new OrderByFragmentRenderer();
// try {
// renderer.orderByFragment( parser.getAST() );
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -0,0 +1,46 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.phase.hql.resolve;
+
+import java.util.List;
+
+import org.antlr.runtime.tree.Tree;
+
+import org.hibernate.type.Type;
+
+/**
+ *
+ * @author Steve Ebersole
+ */
+public interface PersisterSpace {
+ public String getAlias();
+ public List<Tree> getTables();
+
+ public Type getPropertyType(String propertyName);
+}
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -0,0 +1,77 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.phase.hql.resolve;
+
+/**
+ * todo : javadocs
+ *
+ * @author Steve Ebersole
+ */
+public interface PersisterSpaceContext {
+ /**
+ * Does the given text represent an alias for a persister within this context?
+ *
+ * @param text The potential persister alias.
+ * @return True if given text is a persister alias; false otherwise.
+ */
+ public boolean isContainedAlias(String text);
+
+ /**
+ * Does the given text represent a property exposed from a persister in this context?
+ *
+ * @param text The potential property name.
+ * @return True if a persister in this context exposes such a property; false otherwise.
+ */
+ public boolean isContainedExposedProperty(String text);
+
+ /**
+ * Locate a {@link PersisterSpace} by alias.
+ *
+ * @param alias The alias by which to locate the persister space.
+ * @return The persister reference, or null.
+ */
+ public PersisterSpace locatePersisterSpaceByAlias(String alias);
+
+ /**
+ * Locate a {@link PersisterSpace} in this context defined by a persister which exposes the
+ * specified property.
+ *
+ * @param propertyName The name of the property.
+ * @return The persister space, or null.
+ */
+ public PersisterSpace locatePersisterSpaceExposingProperty(String propertyName);
+
+ /**
+ * Registers a persister space in this context.
+ *
+ * @param persisterSpace The persister reference to register.
+ */
+ public void registerPersisterSpace(PersisterSpace persisterSpace);
+}
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -0,0 +1,128 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.phase.hql.resolve;
+
+import org.hibernate.persister.MappedTableMetadata;
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.sql.ast.alias.TableAliasGenerator;
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
+import org.hibernate.sql.ast.tree.Table;
+
+/**
+ * Generate table expressions for persisters.
+ * <p/>
+ * NOTE : temporary, until such time as we are able to have the persisters themselves return these structures.
+ *
+ * @author Steve Ebersole
+ */
+public class PersisterTableExpressionGenerator {
+ public static Table generateTableExpression(
+ Queryable persister,
+ TableAliasGenerator.TableAliasRoot aliasRoot,
+ Table.EntityTableSpace tableSpace) {
+ MappedTableMetadata tableMetadata = persister.getMappedTableMetadata();
+
+ final String drivingTableName = tableMetadata.getDrivingTableName();
+ final String[] drivingTableJoinColumns = tableMetadata.getIdentifierColumnNames();
+ final String drivingTableAlias = aliasRoot.generate( 0 );
+ final Table drivingTable = generateTableReference( drivingTableName, drivingTableAlias, tableSpace );
+
+ int suffix = 0;
+
+ MappedTableMetadata.JoinedTable[] tables = tableMetadata.getJoinedTables();
+ for ( int i = 0; i < tables.length; i++ ) {
+ final String joinTableAlias = aliasRoot.generate( ++suffix );
+ final Table table = generateTableReference( tables[i].getName(), joinTableAlias, tableSpace );
+
+ final HibernateTree join = new HibernateTree( HQLParser.JOIN, "join" );
+ drivingTable.addChild( join );
+ if ( tables[i].useInnerJoin() ) {
+ join.addChild( new HibernateTree( HQLParser.INNER, "inner" ) );
+ }
+ else {
+ join.addChild( new HibernateTree( HQLParser.LEFT, "left outer" ) );
+ }
+ join.addChild( table );
+
+ final HibernateTree on = new HibernateTree( HQLParser.ON, "on" );
+ join.addChild( on );
+ final HibernateTree joinCondition = generateJoinCorrelation(
+ drivingTableAlias,
+ drivingTableJoinColumns,
+ joinTableAlias,
+ tables[i].getKeyColumns()
+ );
+ on.addChild( joinCondition );
+ }
+
+ return drivingTable;
+ }
+
+ private static Table generateTableReference(String tableName, String tableAlias, Table.TableSpace tableSpace) {
+ Table table = new Table( HQLParser.TABLE, tableSpace );
+ table.addChild( new HibernateTree( HQLParser.IDENTIFIER, tableName ) );
+ table.addChild( new HibernateTree( HQLParser.ALIAS_NAME, tableAlias ) );
+ return table;
+ }
+
+ public static HibernateTree generateJoinCorrelation(
+ String lhsAlias,
+ String[] lhsColumns,
+ String rhsAlias,
+ String[] rhsColumns) {
+ HibernateTree correlation = generateJoinCorrelation( lhsAlias, lhsColumns[0], rhsAlias, rhsColumns[0] );
+ if ( lhsColumns.length > 1 ) {
+ for ( int i = 1; i < lhsColumns.length; i++ ) {
+ HibernateTree previous = correlation;
+ correlation = new HibernateTree( HQLParser.AND, "and" );
+ correlation.addChild( previous );
+ correlation.addChild( generateJoinCorrelation( lhsAlias, lhsColumns[i], rhsAlias, rhsColumns[i] ) );
+ }
+ }
+ return correlation;
+ }
+
+ public static HibernateTree generateJoinCorrelation(String lhsAlias, String lhsColumn, String rhsAlias, String rhsColumn) {
+ HibernateTree lhs = new HibernateTree( HQLParser.COLUMN );
+ lhs.addChild( new HibernateTree( HQLParser.ALIAS_REF, lhsAlias ) );
+ lhs.addChild( new HibernateTree( HQLParser.IDENTIFIER, lhsColumn ) );
+
+ HibernateTree rhs = new HibernateTree( HQLParser.COLUMN );
+ rhs.addChild( new HibernateTree( HQLParser.ALIAS_REF, rhsAlias ) );
+ rhs.addChild( new HibernateTree( HQLParser.IDENTIFIER, rhsColumn ) );
+
+ HibernateTree correlation = new HibernateTree( HQLParser.EQUALS, "=" );
+ correlation.addChild( lhs );
+ correlation.addChild( rhs );
+
+ return correlation;
+ }
+}
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PropertyPathTerminus.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PropertyPathTerminus.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PropertyPathTerminus.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -0,0 +1,40 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.phase.hql.resolve;
+
+import org.hibernate.sql.ast.common.HibernateTree;
+
+/**
+ * Represents the terminal part of a property path.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class PropertyPathTerminus extends HibernateTree {
+}
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ResolutionContext.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ResolutionContext.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ResolutionContext.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -0,0 +1,103 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.phase.hql.resolve;
+
+import org.antlr.runtime.tree.TreeAdaptor;
+
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.sql.ast.alias.ImplicitAliasGenerator;
+import org.hibernate.sql.ast.util.TreePrinter;
+import org.hibernate.sql.ast.phase.hql.resolve.path.PathResolutionStrategy;
+
+/**
+ * todo : javadocs
+ *
+ * @author Steve Ebersole
+ */
+public interface ResolutionContext {
+
+ /**
+ * The session factory available for this context. Providing, for example, mapping information.
+ *
+ * @return The session factory.
+ */
+ public SessionFactoryImplementor getSessionFactoryImplementor();
+
+ public TreeAdaptor getTreeAdaptor();
+
+// /**
+// * The alias builder available in this context.
+// *
+// * @return The alias builder.
+// */
+// public ImplicitAliasGenerator getAliasBuilder();
+
+ /**
+ * The current {@link PersisterSpaceContext} for this context. The {@link PersisterSpaceContext}
+ * can change in relation to subqueries and such. See {@link PersisterSpaceContext} docs for more info.
+ *
+ * @return The current {@link PersisterSpaceContext} for this resolution context.
+ */
+ public PersisterSpaceContext getCurrentPersisterSpaceContext();
+
+// /**
+// * The builder of {@link PersisterReference} instances for this context.
+// *
+// * @return The {@link PersisterReference} builder.
+// */
+// public PersisterReferenceBuilder getPersisterReferenceBuilder();
+//
+// /**
+// * The builder of {@link Join} instances pertaining to property joins for this context.
+// *
+// * @return The property {@link Join} builder.
+// */
+// public PropertyJoinBuilder getPropertyJoinBuilder();
+
+ /**
+ * The tree printer available for this context.
+ *
+ * @return The tree printer.
+ */
+ public TreePrinter getTreePrinter();
+
+ /**
+ * Is this context currently processing a function?
+ *
+ * @return True or false.
+ */
+ public boolean isCurrentlyProcessingFunction();
+
+ public PathResolutionStrategy getCurrentPathResolutionStrategy();
+
+// public void registerAssociationFetch(Join join);
+//
+// public void registerPropertyFetch(PersisterReference persisterReference);
+}
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategy.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategy.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategy.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -0,0 +1,95 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.phase.hql.resolve.path;
+
+import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
+import org.hibernate.sql.ast.phase.hql.resolve.PropertyPathTerminus;
+import org.hibernate.sql.ast.common.HibernateTree;
+
+/**
+ * Applies a strategy pattern to the manner in which path expressions are normalized, allowing contextual pluggability
+ * of the implicit-join and index-access handling rules...
+ *
+ * @author Steve Ebersole
+ */
+public interface PathResolutionStrategy {
+ /**
+ * Handle the root of the pathed property reference.
+ *
+ * @param persisterReference The root of the path.
+ *
+ * @return The source representation of the path root.
+ */
+ public PathedPropertyReferenceSource handleRoot(PersisterSpace persisterReference);
+
+ /**
+ * Handle an intermeidary path part.
+ *
+ * @param source The source of the property reference.
+ * @param pathPart The current property path part.
+ *
+ * @return The new source for further property part handling.
+ */
+ public PathedPropertyReferenceSource handleIntermediatePathPart(PathedPropertyReferenceSource source, String pathPart);
+
+ /**
+ * Handle the terminal path part.
+ *
+ * @param source The source of the property reference.
+ * @param pathPart The current (and terminal/last) path part.
+ *
+ * @return The terminal property reference indicated by the overall path.
+ */
+ public PropertyPathTerminus handleTerminalPathPart(PathedPropertyReferenceSource source, String pathPart);
+
+ /**
+ * Handle an index access operation (a.b[selector] for example). In this particular case the index access
+ * is further dereferenced (it is intermediate).
+ *
+ * @param source The source of the property reference.
+ * @param pathPart The current property path part, here specifically naming the collection property
+ * @param selector The index selection expression
+ *
+ * @return The new source for further property part handling.
+ */
+ public PathedPropertyReferenceSource handleIntermediateIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector);
+
+ /**
+ * Handle an index access operation (a.b[selector] for example). In this particular case the index access
+ * is the terminus of the path expression.
+ *
+ * @param source The source of the property reference.
+ * @param pathPart The current property path part, here specifically naming the collection property
+ * @param selector The index selection expression
+ *
+ * @return The terminal property reference indicated by the overall path.
+ */
+ public PropertyPathTerminus handleTerminalIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector);
+}
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathedPropertyReferenceSource.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathedPropertyReferenceSource.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathedPropertyReferenceSource.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -0,0 +1,92 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.phase.hql.resolve.path;
+
+import org.antlr.runtime.tree.Tree;
+
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.phase.hql.resolve.PropertyPathTerminus;
+
+/**
+ * The contract for representing the non-terminal parts of a property path expression
+ * <p/>
+ * NOTE : extends AST so the grammar can more easily handle it, not because it will actually end up in the syntax
+ * tree (it will not).
+ *
+ * @author Steve Ebersole
+ */
+public interface PathedPropertyReferenceSource extends Tree {
+ /**
+ * Return the path which led to this source.
+ *
+ * @return The origination path.
+ */
+ public String getOriginationPath();
+
+ /**
+ * Handle an intermediate path part reference.
+ *
+ * @param name The name for the path part to handle.
+ *
+ * @return An appropriate source representation of said intermeidate path part.
+ */
+ public PathedPropertyReferenceSource handleIntermediatePathPart(String name);
+
+ /**
+ * Handle the terminal path reference.
+ *
+ * @param name The name of the terminal path part.
+ *
+ * @return The property reference terminus.
+ */
+ public PropertyPathTerminus handleTerminalPathPart(String name);
+
+ /**
+ * Handle an index access operation (a.b[selector] for example). In this particular case the index access
+ * is further dereferenced (it is intermediate).
+ *
+ * @param collectionPropertyName The name of the collection property to which the index operator applies
+ * @param selector The index selection expression
+ *
+ * @return An appropriate source representation of said intermeidate path part.
+ */
+ public PathedPropertyReferenceSource handleIntermediateIndexAccess(String collectionPropertyName, HibernateTree selector);
+
+ /**
+ * Handle an index access operation (a.b[selector] for example). In this particular case the index access
+ * is the terminus of the path expression.
+ *
+ * @param collectionPropertyName The name of the collection property to which the index operator applies
+ * @param selector The index selection expression
+ *
+ * @return The property reference terminus.
+ */
+ public PropertyPathTerminus handleTerminalIndexAccess(String collectionPropertyName, HibernateTree selector);
+}
Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java 2009-04-20 21:58:44 UTC (rev 16366)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -38,6 +38,7 @@
import org.hibernate.type.Type;
import org.hibernate.sql.ast.alias.ImplicitAliasGenerator;
import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.common.HibernateToken;
import org.hibernate.sql.ast.util.DisplayableNode;
import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
import org.hibernate.persister.entity.Queryable;
@@ -62,6 +63,10 @@
this( node.getToken(), tableSpace );
}
+ public Table(int tokenType, TableSpace tableSpace) {
+ this( new HibernateToken( tokenType ), tableSpace );
+ }
+
public TableSpace getTableSpace() {
return tableSpace;
}
Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ASTAppender.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ASTAppender.java 2009-04-20 21:58:44 UTC (rev 16366)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ASTAppender.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -1,68 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
- *
- * 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.sql.ast.util;
-
-import antlr.ASTFactory;
-import antlr.collections.AST;
-
-/**
- * Appends child nodes to a parent efficiently.
- *
- * @author Joshua Davis
- */
-public class ASTAppender {
- private AST parent;
- private AST last;
- private ASTFactory factory;
-
- public ASTAppender(ASTFactory factory, AST parent) {
- this( parent );
- this.factory = factory;
- }
-
- public ASTAppender(AST parent) {
- this.parent = parent;
- this.last = ASTUtil.getLastChild( parent );
- }
-
- public AST append(int type, String text, boolean appendIfEmpty) {
- if ( text != null && ( appendIfEmpty || text.length() > 0 ) ) {
- return append( factory.create( type, text ) );
- }
- else {
- return null;
- }
- }
-
- public AST append(AST child) {
- if ( last == null ) {
- parent.setFirstChild( child );
- }
- else {
- last.setNextSibling( child );
- }
- last = child;
- return last;
- }
-}
Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ASTPrinter.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ASTPrinter.java 2009-04-20 21:58:44 UTC (rev 16366)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/ASTPrinter.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -64,7 +64,7 @@
*
* @param tokenTypeConstants The token types to use during printing; typically the {vocabulary}TokenTypes.java
* interface generated by ANTLR.
- * @param showClassNames Should the class names of the {@link org.hibernate.sql.ast.common.Node} impls be displayed.
+ * @param showClassNames Should the class names of the {@link org.hibernate.sql.ast.common.HibernateToken} impls be displayed.
*/
public ASTPrinter(Class tokenTypeConstants, boolean showClassNames) {
this( ASTUtil.generateTokenNameCache( tokenTypeConstants ), showClassNames );
Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/DisplayableNode.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/DisplayableNode.java 2009-04-20 21:58:44 UTC (rev 16366)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/DisplayableNode.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -24,7 +24,7 @@
package org.hibernate.sql.ast.util;
/**
- * Contract for {@link org.hibernate.sql.ast.common.Node} implementations which wish to return customized display information
+ * Contract for {@link org.hibernate.sql.ast.common.HibernateToken} implementations which wish to return customized display information
* about themselves.
*
* @author Steve Ebersole
Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/NodeTraverser.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/NodeTraverser.java 2009-04-20 21:58:44 UTC (rev 16366)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/NodeTraverser.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -31,6 +31,9 @@
* @author Steve Ebersole
*/
public class NodeTraverser {
+
+ // todo : look at org.antlr.runtime.tree.TreeVisitor/TreeVsitorAction
+
public static interface VisitationStrategy {
public void visit(AST node);
}
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/TreePrinter.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/TreePrinter.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/TreePrinter.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -0,0 +1,233 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.hibernate.util.StringHelper;
+import org.antlr.runtime.tree.Tree;
+
+/**
+ * Utility for generating pretty "ASCII art" representations of syntax trees.
+ *
+ * @author Joshua Davis
+ * @author Steve Ebersole
+ */
+public class TreePrinter {
+ private final Map tokenTypeNameCache;
+ private final boolean showClassNames;
+
+ /**
+ * Constructs a printer.
+ * <p/>
+ * Delegates to {@link #TreePrinter(Class, boolean)} with {@link #isShowClassNames showClassNames} as <tt>false</tt>
+ *
+ * @param tokenTypeConstants The token types to use during printing; typically the {vocabulary}TokenTypes.java
+ * interface generated by ANTLR.
+ */
+ public TreePrinter(Class tokenTypeConstants) {
+ this( ASTUtil.generateTokenNameCache( tokenTypeConstants ), false );
+ }
+
+ public TreePrinter(boolean showClassNames) {
+ this( ( Map ) null, showClassNames );
+ }
+
+ /**
+ * Constructs a printer.
+ *
+ * @param tokenTypeConstants The token types to use during printing; typically the {vocabulary}TokenTypes.java
+ * interface generated by ANTLR.
+ * @param showClassNames Should the class names of the tree nodes impls be displayed.
+ */
+ public TreePrinter(Class tokenTypeConstants, boolean showClassNames) {
+ this( ASTUtil.generateTokenNameCache( tokenTypeConstants ), showClassNames );
+ }
+
+ private TreePrinter(Map tokenTypeNameCache, boolean showClassNames) {
+ this.tokenTypeNameCache = tokenTypeNameCache;
+ this.showClassNames = showClassNames;
+ }
+
+ /**
+ * Getter for property 'showClassNames'.
+ *
+ * @return Value for property 'showClassNames'.
+ */
+ public boolean isShowClassNames() {
+ return showClassNames;
+ }
+
+ /**
+ * Renders the tree into 'ASCII art' form and returns that string representation.
+ *
+ * @param tree The tree to display.
+ * @param header The header for the display.
+ *
+ * @return The'ASCII art' form, as a string.
+ */
+ public String renderAsString(Tree tree, String header) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream( baos );
+ ps.println( header );
+ render( tree, ps );
+ ps.flush();
+ return new String( baos.toByteArray() );
+ }
+
+ /**
+ * Prints the tree in 'ASCII art' form to the specified print stream.
+ *
+ * @param tree The tree to print.
+ * @param out The print stream to which the tree should be printed.
+ */
+ public void render(Tree tree, PrintStream out) {
+ render( tree, new PrintWriter( out ) );
+ }
+
+ /**
+ * Prints the tree in 'ASCII art' tree form to the specified print writer.
+ *
+ * @param tree The tree to print.
+ * @param pw The print writer to which the tree should be written.
+ */
+ public void render(Tree tree, PrintWriter pw) {
+ ArrayList parents = new ArrayList();
+ render( parents, pw, tree );
+ pw.flush();
+ }
+
+ /**
+ * Returns the token type name for the given token type.
+ *
+ * @param type The token type.
+ * @return String - The token type name from the token type constant class,
+ * or just the integer as a string if none exists.
+ */
+ public String getTokenTypeName(int type) {
+ final Integer typeInteger = new Integer( type );
+ String value = null;
+ if ( tokenTypeNameCache != null ) {
+ value = ( String ) tokenTypeNameCache.get( typeInteger );
+ }
+ if ( value == null ) {
+ value = typeInteger.toString();
+ }
+ return value;
+ }
+
+ private void render(ArrayList parents, PrintWriter pw, Tree tree) {
+ if ( tree == null ) {
+ pw.println( "tree is null!" );
+ return;
+ }
+
+ // Tree.getChildIndex() -> the tree's position within its parent's children...
+
+ for ( int i = 0; i < parents.size(); i++ ) {
+ final Tree parent = ( Tree ) parents.get( i );
+ if ( hasNextSibling( parent ) ) {
+ pw.print( " " );
+ }
+ else {
+ pw.print( " | " );
+ }
+ }
+
+ if ( hasNextSibling( tree ) ) {
+ pw.print( " \\-" );
+ }
+ else {
+ pw.print( " +-" );
+ }
+
+ writeNode( pw, tree );
+
+ ArrayList newParents = new ArrayList( parents );
+ newParents.add( tree );
+ for ( int i = 0; i < tree.getChildCount(); i++ ) {
+ render( newParents, pw, tree.getChild( i ) );
+ }
+ newParents.clear();
+ }
+
+ private boolean hasNextSibling(Tree tree) {
+ return tree.getParent() != null
+ && tree.getParent().getChildCount() <= tree.getChildIndex();
+ }
+
+ private void writeNode(PrintWriter pw, Tree tree) {
+ pw.println( nodeToString( tree ) );
+ }
+
+ private String nodeToString(Tree tree) {
+ if ( tree == null ) {
+ return "{node:null}";
+ }
+
+ StringBuffer buf = new StringBuffer();
+ buf.append( "[" ).append( getTokenTypeName( tree.getType() ) ).append( "] " );
+ if ( showClassNames ) {
+ buf.append( StringHelper.unqualify( tree.getClass().getName() ) ).append( ": " );
+ }
+
+ buf.append( "'" );
+ String text = tree.getText();
+ if ( text == null ) {
+ text = "{text:null}";
+ }
+ appendEscapedMultibyteChars(text, buf);
+ buf.append( "'" );
+
+ if ( tree instanceof DisplayableNode ) {
+ DisplayableNode displayableNode = ( DisplayableNode ) tree;
+ // Add a space before the display text.
+ buf.append( " " ).append( displayableNode.getDisplayText() );
+ }
+ return buf.toString();
+ }
+
+ public static void appendEscapedMultibyteChars(String text, StringBuffer buf) {
+ char[] chars = text.toCharArray();
+ for (int i = 0; i < chars.length; i++) {
+ char aChar = chars[i];
+ if (aChar > 256) {
+ buf.append("\\u");
+ buf.append(Integer.toHexString(aChar));
+ }
+ else
+ buf.append(aChar);
+ }
+ }
+
+ public static String escapeMultibyteChars(String text) {
+ StringBuffer buf = new StringBuffer();
+ appendEscapedMultibyteChars(text,buf);
+ return buf.toString();
+ }
+}
Modified: core/branches/antlr3/src/test/java/org/hibernate/sql/TemplateTest.java
===================================================================
--- core/branches/antlr3/src/test/java/org/hibernate/sql/TemplateTest.java 2009-04-20 21:58:44 UTC (rev 16366)
+++ core/branches/antlr3/src/test/java/org/hibernate/sql/TemplateTest.java 2009-04-20 22:26:31 UTC (rev 16367)
@@ -85,99 +85,104 @@
private static final SQLFunctionRegistry FUNCTION_REGISTRY = new SQLFunctionRegistry( DIALECT, Collections.EMPTY_MAP );
- public void testSQLReferences() {
- String fragment = "sql asc, sql desc";
- String template = doStandardRendering( fragment );
+ public void testParsing() {
+ String fragment = "sql asc, sql desc";
+ String template = doStandardRendering( fragment );
+ }
- assertEquals( Template.TEMPLATE + ".sql asc, " + Template.TEMPLATE + ".sql desc", template );
- }
+// public void testSQLReferences() {
+// String fragment = "sql asc, sql desc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( Template.TEMPLATE + ".sql asc, " + Template.TEMPLATE + ".sql desc", template );
+// }
+//
+// public void testQuotedSQLReferences() {
+// String fragment = "`sql` asc, `sql` desc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( Template.TEMPLATE + ".\"sql\" asc, " + Template.TEMPLATE + ".\"sql\" desc", template );
+// }
+//
+// public void testPropertyReference() {
+// String fragment = "property asc, property desc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( Template.TEMPLATE + ".prop asc, " + Template.TEMPLATE + ".prop desc", template );
+// }
+//
+// public void testFunctionReference() {
+// String fragment = "upper(sql) asc, lower(sql) desc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( "upper(" + Template.TEMPLATE + ".sql) asc, lower(" + Template.TEMPLATE + ".sql) desc", template );
+// }
+//
+// public void testQualifiedFunctionReference() {
+// String fragment = "qual.upper(property) asc, qual.lower(property) desc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( "qual.upper(" + Template.TEMPLATE + ".prop) asc, qual.lower(" + Template.TEMPLATE + ".prop) desc", template );
+// }
+//
+// public void testDoubleQualifiedFunctionReference() {
+// String fragment = "qual1.qual2.upper(property) asc, qual1.qual2.lower(property) desc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( "qual1.qual2.upper(" + Template.TEMPLATE + ".prop) asc, qual1.qual2.lower(" + Template.TEMPLATE + ".prop) desc", template );
+// }
+//
+// public void testFunctionWithPropertyReferenceAsParam() {
+// String fragment = "upper(property) asc, lower(property) desc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( "upper(" + Template.TEMPLATE + ".prop) asc, lower(" + Template.TEMPLATE + ".prop) desc", template );
+// }
+//
+// public void testNestedFunctionReferences() {
+// String fragment = "upper(lower(sql)) asc, lower(upper(sql)) desc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( "upper(lower(" + Template.TEMPLATE + ".sql)) asc, lower(upper(" + Template.TEMPLATE + ".sql)) desc", template );
+// }
+//
+// public void testComplexNestedFunctionReferences() {
+// String fragment = "mod(mod(sql,2),3) asc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( "mod(mod(" + Template.TEMPLATE + ".sql, 2), 3) asc", template );
+// }
+//
+// public void testCollation() {
+// String fragment = "`sql` COLLATE my_collation, `sql` COLLATE your_collation";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( Template.TEMPLATE + ".\"sql\" collate my_collation, " + Template.TEMPLATE + ".\"sql\" collate your_collation", template );
+// }
+//
+// public void testCollationAndOrdering() {
+// String fragment = "sql COLLATE my_collation, upper(prop) COLLATE your_collation asc, `sql` desc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( Template.TEMPLATE + ".sql collate my_collation, upper(" + Template.TEMPLATE + ".prop) collate your_collation asc, " + Template.TEMPLATE + ".\"sql\" desc", template );
+//
+// }
+//
+// public void testComponentReferences() {
+// String fragment = "component asc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( Template.TEMPLATE + ".comp_1 asc, " + Template.TEMPLATE + ".comp_2 asc", template );
+//
+// }
+//
+// public void testComponentDerefReferences() {
+// String fragment = "component.prop1 asc";
+// String template = doStandardRendering( fragment );
+//
+// assertEquals( Template.TEMPLATE + ".comp_1 asc", template );
+// }
- public void testQuotedSQLReferences() {
- String fragment = "`sql` asc, `sql` desc";
- String template = doStandardRendering( fragment );
-
- assertEquals( Template.TEMPLATE + ".\"sql\" asc, " + Template.TEMPLATE + ".\"sql\" desc", template );
- }
-
- public void testPropertyReference() {
- String fragment = "property asc, property desc";
- String template = doStandardRendering( fragment );
-
- assertEquals( Template.TEMPLATE + ".prop asc, " + Template.TEMPLATE + ".prop desc", template );
- }
-
- public void testFunctionReference() {
- String fragment = "upper(sql) asc, lower(sql) desc";
- String template = doStandardRendering( fragment );
-
- assertEquals( "upper(" + Template.TEMPLATE + ".sql) asc, lower(" + Template.TEMPLATE + ".sql) desc", template );
- }
-
- public void testQualifiedFunctionReference() {
- String fragment = "qual.upper(property) asc, qual.lower(property) desc";
- String template = doStandardRendering( fragment );
-
- assertEquals( "qual.upper(" + Template.TEMPLATE + ".prop) asc, qual.lower(" + Template.TEMPLATE + ".prop) desc", template );
- }
-
- public void testDoubleQualifiedFunctionReference() {
- String fragment = "qual1.qual2.upper(property) asc, qual1.qual2.lower(property) desc";
- String template = doStandardRendering( fragment );
-
- assertEquals( "qual1.qual2.upper(" + Template.TEMPLATE + ".prop) asc, qual1.qual2.lower(" + Template.TEMPLATE + ".prop) desc", template );
- }
-
- public void testFunctionWithPropertyReferenceAsParam() {
- String fragment = "upper(property) asc, lower(property) desc";
- String template = doStandardRendering( fragment );
-
- assertEquals( "upper(" + Template.TEMPLATE + ".prop) asc, lower(" + Template.TEMPLATE + ".prop) desc", template );
- }
-
- public void testNestedFunctionReferences() {
- String fragment = "upper(lower(sql)) asc, lower(upper(sql)) desc";
- String template = doStandardRendering( fragment );
-
- assertEquals( "upper(lower(" + Template.TEMPLATE + ".sql)) asc, lower(upper(" + Template.TEMPLATE + ".sql)) desc", template );
- }
-
- public void testComplexNestedFunctionReferences() {
- String fragment = "mod(mod(sql,2),3) asc";
- String template = doStandardRendering( fragment );
-
- assertEquals( "mod(mod(" + Template.TEMPLATE + ".sql, 2), 3) asc", template );
- }
-
- public void testCollation() {
- String fragment = "`sql` COLLATE my_collation, `sql` COLLATE your_collation";
- String template = doStandardRendering( fragment );
-
- assertEquals( Template.TEMPLATE + ".\"sql\" collate my_collation, " + Template.TEMPLATE + ".\"sql\" collate your_collation", template );
- }
-
- public void testCollationAndOrdering() {
- String fragment = "sql COLLATE my_collation, upper(prop) COLLATE your_collation asc, `sql` desc";
- String template = doStandardRendering( fragment );
-
- assertEquals( Template.TEMPLATE + ".sql collate my_collation, upper(" + Template.TEMPLATE + ".prop) collate your_collation asc, " + Template.TEMPLATE + ".\"sql\" desc", template );
-
- }
-
- public void testComponentReferences() {
- String fragment = "component asc";
- String template = doStandardRendering( fragment );
-
- assertEquals( Template.TEMPLATE + ".comp_1 asc, " + Template.TEMPLATE + ".comp_2 asc", template );
-
- }
-
- public void testComponentDerefReferences() {
- String fragment = "component.prop1 asc";
- String template = doStandardRendering( fragment );
-
- assertEquals( Template.TEMPLATE + ".comp_1 asc", template );
- }
-
public String doStandardRendering(String fragment) {
return Template.renderOrderByStringTemplate( fragment, MAPPER, null, DIALECT, FUNCTION_REGISTRY );
}
15 years, 7 months
Hibernate SVN: r16366 - in core/branches/antlr3/src/main/java/org/hibernate/sql/ast: tree and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-04-20 17:58:44 -0400 (Mon, 20 Apr 2009)
New Revision: 16366
Added:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/EntityNameTree.java
Removed:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/EntityNameTree.java
Log:
tree package
Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/EntityNameTree.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/EntityNameTree.java 2009-04-20 21:57:42 UTC (rev 16365)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/EntityNameTree.java 2009-04-20 21:58:44 UTC (rev 16366)
@@ -1,38 +0,0 @@
-package org.hibernate.sql.ast.phase.hql.parse;
-
-import java.util.List;
-
-import org.antlr.runtime.CommonToken;
-import org.antlr.runtime.Token;
-import org.antlr.runtime.tree.CommonTree;
-
-public class EntityNameTree extends CommonTree {
-
- private List entityNames = null;
- private String outputText = null;
-
- public EntityNameTree(EntityNameTree entityNameTree, String outputText) {
- this.token = entityNameTree.getToken();
- this.outputText = outputText;
- }
-
- public EntityNameTree(int tokenType, Token token, String tokenText,
- List entityNames) {
- Token newToken = createToken(token);
- newToken.setType(tokenType);
- newToken.setText(tokenText);
- this.token = newToken;
- this.entityNames = entityNames;
- }
-
- private Token createToken(Token fromToken) {
- return new CommonToken(fromToken);
- }
-
- public String toString() {
- if (outputText == null) {
- outputText = entityNames.get(0).toString();
- }
- return outputText;
- }
-}
\ No newline at end of file
Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/EntityNameTree.java (from rev 16362, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/EntityNameTree.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/EntityNameTree.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/EntityNameTree.java 2009-04-20 21:58:44 UTC (rev 16366)
@@ -0,0 +1,38 @@
+package org.hibernate.sql.ast.tree;
+
+import java.util.List;
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.antlr.runtime.tree.CommonTree;
+
+public class EntityNameTree extends CommonTree {
+
+ private List entityNames = null;
+ private String outputText = null;
+
+ public EntityNameTree(EntityNameTree entityNameTree, String outputText) {
+ this.token = entityNameTree.getToken();
+ this.outputText = outputText;
+ }
+
+ public EntityNameTree(int tokenType, Token token, String tokenText,
+ List entityNames) {
+ Token newToken = createToken(token);
+ newToken.setType(tokenType);
+ newToken.setText(tokenText);
+ this.token = newToken;
+ this.entityNames = entityNames;
+ }
+
+ private Token createToken(Token fromToken) {
+ return new CommonToken(fromToken);
+ }
+
+ public String toString() {
+ if (outputText == null) {
+ outputText = entityNames.get(0).toString();
+ }
+ return outputText;
+ }
+}
\ No newline at end of file
Property changes on: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/EntityNameTree.java
___________________________________________________________________
Name: svn:eol-style
+ native
15 years, 7 months
Hibernate SVN: r16365 - in core/branches/antlr3/src/main/java/org/hibernate/sql/ast: tree and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-04-20 17:57:42 -0400 (Mon, 20 Apr 2009)
New Revision: 16365
Added:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
Log:
tree package
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java 2009-04-20 21:57:42 UTC (rev 16365)
@@ -0,0 +1,285 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.tree;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+
+import org.antlr.runtime.Token;
+
+import org.hibernate.type.Type;
+import org.hibernate.sql.ast.alias.ImplicitAliasGenerator;
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.util.DisplayableNode;
+import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.persister.collection.QueryableCollection;
+import org.hibernate.util.StringHelper;
+
+/**
+ * todo : javadocs
+ *
+ * @author Steve Ebersole
+ */
+public class Table extends HibernateTree implements DisplayableNode {
+ private final TableSpace tableSpace;
+
+ public Table(Token token, TableSpace tableSpace) {
+ super( token );
+ this.tableSpace = tableSpace;
+ tableSpace.addTable( this );
+ }
+
+ public Table(HibernateTree node, TableSpace tableSpace) {
+ this( node.getToken(), tableSpace );
+ }
+
+ public TableSpace getTableSpace() {
+ return tableSpace;
+ }
+
+ public HibernateTree getTableName() {
+ return ( HibernateTree ) getChild( 0 );
+ }
+
+ public String getTableNameText() {
+ return getTableName().getText();
+ }
+
+ public HibernateTree getAlias() {
+ return ( HibernateTree ) getChild( 1 );
+ }
+
+ public String getAliasText() {
+ return getAlias().getText();
+ }
+
+ public String getText() {
+ return getTableNameText() + " (" + getAliasText() + ")";
+ }
+
+ public String getDisplayText() {
+ return "[source-alias=" + tableSpace.getSourceAlias() + "]";
+ }
+
+ public static interface TableSpace {
+ /**
+ * Used as a unique identification since each table space originates from a single source alias (persister reference).
+ *
+ * @return The source alias.
+ */
+ public String getSourceAlias();
+
+ /**
+ * Get the table reference that should act as the RHS for this table space whenever we join to into it.
+ *
+ * @return The RHS table for joining into this table space structure.
+ */
+ public Table getJoinIntoTable();
+
+ public String[] getJoinIntoColumns();
+
+ public void addTable(Table table);
+
+
+ /**
+ * Get the table reference that contains the columns to which the given property is mapped.
+ *
+ * @param propertyName The name of the property for which to locate the containing table.
+ *
+ * @return The containing table.
+ */
+ public Table getContainingTable(String propertyName);
+
+ public Type getPropertyType(String propertyName);
+
+ public String[] getPropertyColumnNames(String propertyName);
+
+ public List buildIdentifierColumnReferences();
+
+ public List buildCompleteColumnReferences();
+ }
+
+ public static abstract class AbstractTableSpace implements Table.TableSpace {
+ private final String sourceAlias;
+ private final String sqlAliasBaseRoot;
+ protected final LinkedHashSet<Table> tables = new LinkedHashSet<Table>();
+
+ private AbstractTableSpace(String sourceAlias, String persisterName) {
+ this.sourceAlias = sourceAlias;
+ this.sqlAliasBaseRoot = ImplicitAliasGenerator.isImplicitAlias( sourceAlias ) ? persisterName : sourceAlias;
+ }
+
+ public String getSourceAlias() {
+ return sourceAlias;
+ }
+
+ public String getSqlAliasBaseRoot() {
+ return sqlAliasBaseRoot;
+ }
+
+ public void addTable(Table table) {
+ tables.add( table );
+ }
+ }
+
+ public static class EntityTableSpace extends AbstractTableSpace {
+ private final Queryable entityPersister;
+ private final ArrayList tables;
+
+ public EntityTableSpace(Queryable entityPersister, String sourecAlias) {
+ super( sourecAlias, StringHelper.unqualifyEntityName( entityPersister.getEntityName() ) );
+ this.entityPersister = entityPersister;
+ int numberOfTables = entityPersister.getMappedTableMetadata().getJoinedTables().length + 1;
+ int listSize = numberOfTables + (int) ( numberOfTables * .75 ) + 1;
+ this.tables = new ArrayList( listSize );
+ }
+
+ public Queryable getEntityPersister() {
+ return entityPersister;
+ }
+
+ public void addTable(Table table) {
+ tables.add( table );
+ }
+
+ public Table getDrivingTable() {
+ return ( Table ) tables.get( 0 );
+ }
+
+ public Table getJoinIntoTable() {
+ return getDrivingTable();
+ }
+
+ public String[] getJoinIntoColumns() {
+ return entityPersister.getIdentifierColumnNames();
+ }
+
+ public Table getContainingTable(String propertyName) {
+ return ( Table ) tables.get( entityPersister.getSubclassPropertyTableNumber( propertyName ) );
+ }
+
+ public Type getPropertyType(String propertyName) {
+ return entityPersister.getPropertyType( propertyName );
+ }
+
+ public String[] getPropertyColumnNames(String propertyName) {
+ int index = entityPersister.getEntityMetamodel().getPropertyIndex( propertyName );
+ return entityPersister.getPropertyColumnNames( index );
+ }
+
+ public List buildIdentifierColumnReferences() {
+ String[] identifierColumnsNames = entityPersister.getIdentifierColumnNames();
+ ArrayList columnsReferences = new ArrayList( collectionSizeWithoutRehashing( identifierColumnsNames.length ) );
+ for ( int i = 0; i < identifierColumnsNames.length; i++ ) {
+ HibernateTree columnNode = new HibernateTree( HQLParser.COLUMN );
+ columnNode.addChild( new HibernateTree( HQLParser.ALIAS_REF, getDrivingTable().getAliasText() ) );
+ columnNode.addChild( new HibernateTree( HQLParser.IDENTIFIER, identifierColumnsNames[i] ) );
+ columnsReferences.add( columnNode );
+ }
+ return columnsReferences;
+ }
+
+ public List buildCompleteColumnReferences() {
+ // todo : implement
+ return null;
+ }
+ }
+
+ private static int collectionSizeWithoutRehashing(int elements) {
+ // usually collection load factors are .75
+ return collectionSizeWithoutRehashing( elements, .75 );
+ }
+
+ private static int collectionSizeWithoutRehashing(int elements, double factor) {
+ return elements + ( (int) ( elements * factor ) + 1 );
+ }
+
+ public static class CollectionTableSpace extends AbstractTableSpace {
+ private final QueryableCollection persister;
+ private final boolean areElementsEntities;
+
+ private Table collectionTable;
+ private EntityTableSpace entityElementTableSpace;
+
+ public CollectionTableSpace(QueryableCollection persister, String sourceAlias) {
+ super( sourceAlias, StringHelper.unqualify( persister.getRole() ) );
+ this.persister = persister;
+ this.areElementsEntities = persister.getElementType().isEntityType();
+ if ( areElementsEntities ) {
+ entityElementTableSpace = new EntityTableSpace( ( Queryable ) persister.getElementPersister(), sourceAlias );
+ }
+ }
+
+ public QueryableCollection getPersister() {
+ return persister;
+ }
+
+ public void setCollectionTable(Table collectionTable) {
+ this.collectionTable = collectionTable;
+ }
+
+ public EntityTableSpace getEntityElementTableSpace() {
+ return entityElementTableSpace;
+ }
+
+ public Table getJoinIntoTable() {
+ return collectionTable;
+ }
+
+ public String[] getJoinIntoColumns() {
+ return persister.getKeyColumnNames();
+ }
+
+ public Table getContainingTable(String propertyName) {
+ // todo : are we needing to handle "collection properties" (SIZE, etc) here still?
+ return getEntityElementTableSpace().getContainingTable( propertyName );
+ }
+
+ public Type getPropertyType(String propertyName) {
+ return getEntityElementTableSpace().getPropertyType( propertyName );
+ }
+
+ public String[] getPropertyColumnNames(String propertyName) {
+ return getEntityElementTableSpace().getPropertyColumnNames( propertyName );
+ }
+
+ public List buildIdentifierColumnReferences() {
+ // todo : implement
+ return null;
+ }
+
+ public List buildCompleteColumnReferences() {
+ // todo : implement
+ return null;
+ }
+ }
+}
15 years, 7 months
Hibernate SVN: r16364 - core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-04-20 17:34:30 -0400 (Mon, 20 Apr 2009)
New Revision: 16364
Added:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateToken.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateTree.java
Log:
token and tree types
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateToken.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateToken.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateToken.java 2009-04-20 21:34:30 UTC (rev 16364)
@@ -0,0 +1,70 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.common;
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.antlr.runtime.CharStream;
+
+/**
+ * Models the token-type/text portion of an Antlr tree for a specific node in said tree.
+ *
+ * @author Steve Ebersole
+ */
+public class HibernateToken extends CommonToken {
+ public HibernateToken(int type) {
+ super(type);
+ }
+
+ public HibernateToken(CharStream input, int type, int channel, int start,
+ int stop) {
+ super(input, type, channel, start, stop);
+ }
+
+ public HibernateToken(int type, String text) {
+ super(type, text);
+ }
+
+ /**
+ * Constructor that preserves the char offset
+ *
+ * @param oldToken
+ */
+ public HibernateToken(Token oldToken) {
+ super(oldToken);
+ if (null != oldToken
+ && (oldToken.getClass().equals(CommonToken.class) || oldToken
+ .getClass().equals(HibernateToken.class))) {
+ start = ((CommonToken) oldToken).getStartIndex();
+ stop = ((CommonToken) oldToken).getStopIndex();
+ }
+ }
+
+}
Added: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateTree.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateTree.java (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/common/HibernateTree.java 2009-04-20 21:34:30 UTC (rev 16364)
@@ -0,0 +1,103 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.sql.ast.common;
+
+import org.antlr.runtime.tree.CommonTree;
+import org.antlr.runtime.tree.Tree;
+import org.antlr.runtime.Token;
+
+/**
+ * todo : javadocs
+ *
+ * @author Steve Ebersole
+ */
+public class HibernateTree extends CommonTree {
+ /**
+ * start char offset
+ */
+ int startCharOffset = -1;
+
+ /**
+ * end char offset
+ */
+ int endCharOffset = -1;
+
+ public HibernateTree(HibernateTree node) {
+ super( node );
+ this.token = node.token;
+ }
+
+ public HibernateTree(Token token) {
+ super( token );
+ }
+
+ public HibernateTree(int type, String text) {
+ this( new HibernateToken( type, text ) );
+ }
+
+ public Tree dupNode() {
+ return new HibernateTree( this );
+ }
+
+ /**
+ * getter for start char offset
+ *
+ * @return start char offset
+ */
+ public int getStartCharOffset() {
+ return startCharOffset;
+ }
+
+ /**
+ * setter for start char offset
+ *
+ * @param startCharOffset start char offset
+ */
+ public void setStartCharOffset(int startCharOffset) {
+ this.startCharOffset = startCharOffset;
+ }
+
+ /**
+ * getter of end char offset
+ *
+ * @return end char offset
+ */
+ public int getEndCharOffset() {
+ return endCharOffset;
+ }
+
+ /**
+ * setter of end char offset
+ *
+ * @param endCharOffset end char offset
+ */
+ public void setEndCharOffset(int endCharOffset) {
+ this.endCharOffset = endCharOffset;
+ }
+}
15 years, 7 months
Hibernate SVN: r16363 - core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse.
by hibernate-commits@lists.jboss.org
Author: porcelli
Date: 2009-04-20 17:13:36 -0400 (Mon, 20 Apr 2009)
New Revision: 16363
Modified:
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQL.g
core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLTreeWalker.g
Log:
starting handling splitting and some new tokens for general SQL structure.
Modified: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQL.g
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQL.g 2009-04-20 15:42:05 UTC (rev 16362)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQL.g 2009-04-20 21:13:36 UTC (rev 16363)
@@ -5,6 +5,10 @@
}
tokens {
+//GENERIC SQL TOKENS
+ TABLE;
+ COLUMN;
+
//VIRTUAL TOKENS
ALIAS_NAME;
ALIAS_REF;
@@ -18,7 +22,6 @@
ENTITY_PERSISTER_REF;
FILTER;
GENERAL_FUNCTION_CALL;
- GENERIC_ELEMENT;
GROUPING_VALUE;
IN_LIST;
INSERTABILITY_SPEC;
@@ -31,6 +34,7 @@
NOT_BETWEEN;
NOT_IN;
NOT_LIKE;
+ PATH;
PERSISTER_JOIN;
PERSISTER_SPACE;
PROP_FETCH;
@@ -45,9 +49,11 @@
SELECT_LIST;
SIMPLE_CASE;
SORT_SPEC;
+ SUB_QUERY;
UNARY_MINUS;
UNARY_PLUS;
VECTOR_EXPR;
+ VERSIONED_VALUE;
//SOFT KEYWORDS
ABS;
@@ -182,6 +188,7 @@
import java.util.LinkedList;
import java.util.HashSet;
import java.util.Set;
+import java.util.Iterator;
}
@lexer::header {
@@ -237,11 +244,14 @@
}
@parser::members {
- Stack entitySplitStack = new Stack();
- ParserContext context = new ParserContextDefaultImpl();
-
+ private Stack enableParameterUsage = new Stack();
+ private ParserContext context = new ParserContextDefaultImpl();
private List errorMessages = new LinkedList();
+ public void setParserContext(ParserContext context){
+ this.context = context;
+ }
+
private boolean validateIdentifierKey(String text) {
return validateLT(1, text);
}
@@ -338,9 +348,83 @@
}
return implementors;
}
+
+ private Object generatePersisterSpacesTree(List persistenceSpaces) {
+ List persisterSpaceList = new ArrayList();
+ for (Iterator iterator = persistenceSpaces.iterator(); iterator
+ .hasNext();) {
+ Tree persistenceSpaceData = (Tree) iterator.next();
+ if (persistenceSpaceData.getType() == PERSISTER_JOIN || persistenceSpaceData.getType() == PROPERTY_JOIN){
+ adaptor.addChild(persisterSpaceList.get(persisterSpaceList.size() - 1), persistenceSpaceData);
+ } else {
+ Object persistenceSpaceTree = (Object)adaptor.nil();
+ persistenceSpaceTree = adaptor.becomeRoot((Object)adaptor.create(PERSISTER_SPACE, "PERSISTER_SPACE"), persistenceSpaceTree);
+ adaptor.addChild(persistenceSpaceTree, persistenceSpaceData);
+ persisterSpaceList.add(persistenceSpaceTree);
+ }
+ }
+ Tree resultTree = (Tree) adaptor.nil();
+ for (Iterator iterator = persisterSpaceList.iterator(); iterator
+ .hasNext();) {
+ Object persistenceElement = (Object) iterator.next();
+ adaptor.addChild(resultTree, persistenceElement);
+ }
+
+ return resultTree;
+ }
+
+ private Object generateUpdateStatementTree(Object updateKey, Object entityName,
+ Object aliasClause, Object setClause, Object whereClause) {
+ Object result = (Object)adaptor.nil();
+ EntityNameTree entityNameTree = (EntityNameTree) entityName;
+ for (int i = 0; i < entityNameTree.getEntityCount(); i++) {
+ Object root_1 = (Object)adaptor.nil();
+ root_1 = (Object)adaptor.becomeRoot(new CommonTree((CommonTree)updateKey), root_1);
+
+ adaptor.addChild(root_1, new EntityNameTree(entityNameTree, entityNameTree.getEntityName(i)));
+
+ if ( aliasClause != null ) {
+ adaptor.addChild(root_1, aliasClause);
+ }
+ adaptor.addChild(root_1, setClause);
+
+ if ( whereClause != null ) {
+ adaptor.addChild(root_1, whereClause);
+ }
+
+ adaptor.addChild(result, root_1);
+ }
+ return result;
+ }
+
+ private Object generateDeleteStatementTree(Object deleteKey, Object entityName,
+ Object aliasClause, Object whereClause) {
+ Object result = (Object)adaptor.nil();
+ EntityNameTree entityNameTree = (EntityNameTree) entityName;
+ for (int i = 0; i < entityNameTree.getEntityCount(); i++) {
+ Object root_1 = (Object)adaptor.nil();
+ root_1 = (Object)adaptor.becomeRoot(new CommonTree((CommonTree)deleteKey), root_1);
+
+ adaptor.addChild(root_1, new EntityNameTree(entityNameTree, entityNameTree.getEntityName(i)));
+
+ if ( aliasClause != null ) {
+ adaptor.addChild(root_1, aliasClause);
+ }
+
+ if ( whereClause != null ) {
+ adaptor.addChild(root_1, whereClause);
+ }
+
+ adaptor.addChild(result, root_1);
+ }
+ return result;
+ }
+
}
filterStatement[String collectionRole]
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+@after { enableParameterUsage.pop(); }
: selectClause? from_key? whereClause? ( groupByClause havingClause?)? orderByClause?
-> ^(QUERY ^(QUERY_SPEC["filter-query-spec"] FILTER[$collectionRole]
selectClause? from_key? whereClause? ( groupByClause havingClause?)? orderByClause?))
@@ -348,6 +432,8 @@
;
statement
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+@after { enableParameterUsage.pop(); }
: updateStatement
| deleteStatement
| insertStatement
@@ -355,14 +441,19 @@
;
updateStatement
-@init { if (state.backtracking == 0) entitySplitStack.push(Boolean.FALSE); }
-@after { entitySplitStack.pop(); }
- : udpate_key^
- versioned_key? from_key!? entityName aliasClause setClause whereClause?
+scope{
+ boolean generateVersionedField;
+}
+ : udpate_key
+ (versioned_key {$updateStatement::generateVersionedField = true;})?
+ from_key? entityName aliasClause setClause whereClause?
+ -> { generateUpdateStatementTree($udpate_key.tree, $entityName.tree, $aliasClause.tree, $setClause.tree, $whereClause.tree ) }
;
setClause
- : set_key^ assignment (COMMA! assignment)*
+ : set_key assignment (COMMA assignment)*
+ -> {$updateStatement::generateVersionedField}? ^(set_key assignment+ ^(EQUALS VERSIONED_VALUE STRING_LITERAL))
+ -> ^(set_key assignment+)
;
assignment
@@ -374,14 +465,11 @@
;
deleteStatement
-@init { if (state.backtracking == 0) entitySplitStack.push(Boolean.FALSE); }
-@after { entitySplitStack.pop(); }
- : delete_key^ from_key!? entityName aliasClause whereClause?
+ : delete_key from_key? entityName aliasClause whereClause?
+ -> { generateDeleteStatementTree($delete_key.tree, $entityName.tree, $aliasClause.tree, $whereClause.tree ) }
;
insertStatement
-@init { if (state.backtracking == 0) entitySplitStack.push(Boolean.FALSE); }
-@after { entitySplitStack.pop(); }
: insert_key^
intoClause selectStatement
;
@@ -407,8 +495,6 @@
//Think about the exception generation where Polimorfic queris are used inside a Mix of results (union, intersect and except)
queryExpression
-@init { if (state.backtracking == 0) entitySplitStack.push(Boolean.FALSE); }
-@after { entitySplitStack.pop(); }
: querySpec ( ( union_key^ | intersect_key^ | except_key^ ) all_key? querySpec )*
;
@@ -444,8 +530,10 @@
;
subQuery
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+@after { enableParameterUsage.pop(); }
: queryExpression
- -> ^(QUERY queryExpression)
+ -> ^(SUB_QUERY ^(QUERY queryExpression))
;
fromClause
@@ -454,9 +542,8 @@
;
persisterSpaces
- : persisterSpace ( COMMA persisterSpace )*
-//TODO: Should handle here if the persisterSpace first element is a join.. it it is.. should be inside the last one.
- -> ^(PERSISTER_SPACE persisterSpace)+
+ : ps+=persisterSpace ( COMMA ps+=persisterSpace )*
+ -> {generatePersisterSpacesTree($ps)}
;
persisterSpace
@@ -473,8 +560,7 @@
: nonCrossJoinType join_key fetch_key? path aliasClause
( on_key
{ isEntityReference = true;
- entityNames = extractEntityNames($path.text);
- if (entityNames.size() > 1 && entitySplitStack.peek().equals(Boolean.FALSE)) { entitySplitStack.pop(); entitySplitStack.push(Boolean.TRUE); } }
+ entityNames = extractEntityNames($path.text); }
logicalExpression
| propertyFetch? withClause?
)
@@ -549,7 +635,9 @@
;
selectExpression
-//TODO: PARAMETERS CAN'T BE USED -> This verification should be scoped
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.FALSE); }
+@after { enableParameterUsage.pop(); }
+//PARAMETERS CAN'T BE USED -> This verification should be scoped
: expression aliasClause
-> ^(SELECT_ITEM expression aliasClause?)
;
@@ -605,7 +693,9 @@
;
sortKey
-//TODO: PARAMETERS CAN'T BE USED -> This verification should be scoped
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.FALSE); }
+@after { enableParameterUsage.pop(); }
+//PARAMETERS CAN'T BE USED -> This verification should be scoped
: concatenation
;
@@ -650,8 +740,8 @@
( is_key (not_key {isNegated = true;})? (NULL {isNull = true;}|empty_key)
-> {isNull && isNegated}? ^(IS_NOT_NULL[$not_key.start, "is not null"] $equalityExpression)
-> {isNull && !isNegated}? ^(IS_NULL[$NULL, "is null"] $equalityExpression)
- -> {!isNull && isNegated}? ^(NOT ^(EXISTS ^(QUERY ^(QUERY_SPEC ^(SELECT_FROM ^(FROM $equalityExpression))))))
- -> ^(EXISTS ^(QUERY ^(QUERY_SPEC ^(SELECT_FROM ^(FROM $equalityExpression)))))
+ -> {!isNull && isNegated}? ^(NOT ^(EXISTS ^(SUB_QUERY ^(QUERY ^(QUERY_SPEC ^(SELECT_FROM ^(FROM $equalityExpression)))))))
+ -> ^(EXISTS ^(SUB_QUERY ^(QUERY ^(QUERY_SPEC ^(SELECT_FROM ^(FROM $equalityExpression))))))
| ( op=EQUALS | op=NOT_EQUAL ) relationalExpression
-> ^($op $equalityExpression relationalExpression)
)*
@@ -675,8 +765,8 @@
-> {isNegated}? ^(NOT_LIKE[$not_key.start, "not like"] $relationalExpression concatenation likeEscape?)
-> ^(like_key $relationalExpression concatenation likeEscape?)
| member_of_key path
- -> {isNegated}? ^(NOT_IN[$not_key.start, "not in"] $relationalExpression ^(IN_LIST ^(QUERY ^(QUERY_SPEC ^(SELECT_FROM ^(FROM ^(GENERIC_ELEMENT path)))))))
- -> ^(IN[$member_of_key.start, "in"] $relationalExpression ^(IN_LIST ^(QUERY ^(QUERY_SPEC ^(SELECT_FROM ^(FROM ^(GENERIC_ELEMENT path)))))))
+ -> {isNegated}? ^(NOT_IN[$not_key.start, "not in"] $relationalExpression ^(IN_LIST ^(SUB_QUERY ^(QUERY ^(QUERY_SPEC ^(SELECT_FROM ^(FROM ^(PATH path))))))))
+ -> ^(IN[$member_of_key.start, "in"] $relationalExpression ^(IN_LIST ^(SUB_QUERY ^(QUERY ^(QUERY_SPEC ^(SELECT_FROM ^(FROM ^(PATH path))))))))
)
)?
;
@@ -698,15 +788,15 @@
;
concatenation
- : additiveExpression (DOUBLE_PIPE^ additiveExpression)*
+ : additiveExpression (DOUBLE_PIPE^ {enableParameterUsage.push(Boolean.TRUE);} additiveExpression { enableParameterUsage.pop(); })*
;
additiveExpression
- : multiplyExpression ( ( PLUS^ | MINUS^ ) multiplyExpression )*
+ : multiplyExpression ( ( PLUS^ | MINUS^ ) {enableParameterUsage.push(Boolean.TRUE);} multiplyExpression { enableParameterUsage.pop(); })*
;
multiplyExpression
- : unaryExpression ( ( ASTERISK^ | SOLIDUS^ ) unaryExpression )*
+ : unaryExpression ( ( ASTERISK^ | SOLIDUS^ ) {enableParameterUsage.push(Boolean.TRUE);} unaryExpression { enableParameterUsage.pop(); })*
;
unaryExpression
@@ -722,6 +812,8 @@
;
caseExpression
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+@after { enableParameterUsage.pop(); }
: caseAbbreviation
| caseSpecification
;
@@ -769,6 +861,8 @@
;
standardFunction
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+@after { enableParameterUsage.pop(); }
: castFunction
| concatFunction
| substringFunction
@@ -920,7 +1014,8 @@
;
setFunction
-@init{boolean generateOmmitedElement = true;}
+@init { boolean generateOmmitedElement = true; if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+@after { enableParameterUsage.pop(); }
: ( sum_key^ | avg_key^ | max_key^ | min_key^ ) LEFT_PAREN! additiveExpression RIGHT_PAREN!
| count_key LEFT_PAREN ( ASTERISK {generateOmmitedElement = false;} | ( ( (distinct_key | all_key) {generateOmmitedElement = false;} )? countFunctionArguments ) ) RIGHT_PAREN
-> {generateOmmitedElement}? ^(count_key ASTERISK? ALL countFunctionArguments?)
@@ -941,6 +1036,8 @@
;
collectionFunction
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+@after { enableParameterUsage.pop(); }
: ( maxelement_key^ | maxindex_key^ | minelement_key^ | minindex_key^ ) LEFT_PAREN! propertyReference RIGHT_PAREN!
;
@@ -967,10 +1064,10 @@
-> {type == 2}? ^(INDICES ^(PROPERTY_REFERENCE identPrimary))
-> {type == 3}? ^(GENERAL_FUNCTION_CALL identPrimary)
-> {type == 4}? ^(JAVA_CONSTANT identPrimary) //-> here will have 2 strutctures element and the constant
- -> ^(GENERIC_ELEMENT identPrimary)
+ -> ^(PATH identPrimary)
| constant
- | parameterSpecification
- //TODO: validate using Scopes if it is enabled or not to use parameterSpecification.. if not generate an exception
+ | parameterSpecification { if (enableParameterUsage.peek().equals(Boolean.FALSE)) throw new RecognitionException( ); }
+ //validate using Scopes if it is enabled or not to use parameterSpecification.. if not generate an exception
| LEFT_PAREN! (expressionOrVector | subQuery) RIGHT_PAREN!
;
@@ -990,6 +1087,8 @@
;
vectorExpr
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+@after { enableParameterUsage.pop(); }
: COMMA! expression (COMMA! expression)*
;
@@ -1003,6 +1102,8 @@
;
exprList
+@init { if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+@after { enableParameterUsage.pop(); }
: expression? (COMMA! expression)*
;
@@ -1029,7 +1130,6 @@
entityName
@init { List entityNames = null; }
-@after { if (entityNames.size() > 1 && entitySplitStack.peek().equals(Boolean.FALSE)) { entitySplitStack.pop(); entitySplitStack.push(Boolean.TRUE); } }
: dotIdentifierPath
{ entityNames = extractEntityNames($dotIdentifierPath.text); }
//here the polimorfic entities should be resolved... to:
Modified: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLTreeWalker.g
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLTreeWalker.g 2009-04-20 15:42:05 UTC (rev 16362)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLTreeWalker.g 2009-04-20 21:13:36 UTC (rev 16363)
@@ -8,10 +8,6 @@
TokenLabelType=CommonToken;
}
-tokens {
- VERSIONED_VALUE;
-}
-
@header {
/*
* Hibernate, Relational Persistence for Idiomatic Java
@@ -43,8 +39,6 @@
* entirety.
*/
package org.hibernate.sql.ast.phase.hql.parse;
-
-import java.util.LinkedList;
}
filterStatement[String collectionRole]
@@ -55,7 +49,7 @@
statement
: updateStatementSet
| deleteStatementSet
- | insertStatement
+ | insertStatementSet
| queryStatementSet
;
@@ -64,15 +58,12 @@
;
updateStatement
-@init {boolean hasVersioned = false; Object versionedPropertyDaya = null;}
- : ^(UPDATE (VERSIONED {hasVersioned = true;})? entityName ^(SET assignment+) whereClause?)
- -> {hasVersioned}? ^(UPDATE entityName ^(SET assignment+
- ^(EQUALS ^(PROPERTY_REFERENCE IDENTIFIER["name"]) VERSIONED_VALUE)) whereClause?)
- -> ^(UPDATE entityName ^(SET assignment+) whereClause?)
+ : ^(UPDATE entityName ^(SET assignment+) whereClause?)
;
assignment
: ^(EQUALS propertyReference valueExpression)
+ | ^(EQUALS VERSIONED_VALUE STRING_LITERAL)
;
deleteStatementSet
@@ -83,6 +74,9 @@
: ^(DELETE entityName whereClause?)
;
+insertStatementSet
+ : insertStatement+
+ ;
insertStatement
: ^(INSERT intoClause queryStatementSet)
@@ -137,7 +131,7 @@
persisterSpaces
: ^(PERSISTER_SPACE persisterSpace)
- | ^(GENERIC_ELEMENT identPrimary)
+ | ^(PATH identPrimary)
;
persisterSpace
@@ -165,7 +159,6 @@
persisterSpaceRoot
: ^(ENTITY_PERSISTER_REF entityName PROP_FETCH?)
- //| joins // this is created based on legacy syntax... check if we can move this from here
;
selectClause
@@ -269,12 +262,12 @@
| constant
| parameter
| propertyReference
- | queryStatementSet
+ | ^(SUB_QUERY queryStatementSet)
| ALIAS_REF //ID COLUMN, full property column list
| ^(DOT_CLASS identPrimary) // crazy
| ^(GENERAL_FUNCTION_CALL identPrimary)
| ^(JAVA_CONSTANT identPrimary) //It will generate at SQL a parameter element (?) -> 'cos we do not need to care about char escaping
- | ^(GENERIC_ELEMENT identPrimary)
+ | ^(PATH identPrimary)
;
caseExpression
15 years, 7 months