You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(22) |
Nov
(308) |
Dec
(131) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(369) |
Feb
(171) |
Mar
(236) |
Apr
(187) |
May
(218) |
Jun
(217) |
Jul
(127) |
Aug
(448) |
Sep
(270) |
Oct
(231) |
Nov
(422) |
Dec
(255) |
| 2004 |
Jan
(111) |
Feb
(73) |
Mar
(338) |
Apr
(351) |
May
(349) |
Jun
(495) |
Jul
(394) |
Aug
(1048) |
Sep
(499) |
Oct
(142) |
Nov
(269) |
Dec
(638) |
| 2005 |
Jan
(825) |
Feb
(1272) |
Mar
(593) |
Apr
(690) |
May
(950) |
Jun
(958) |
Jul
(767) |
Aug
(839) |
Sep
(525) |
Oct
(449) |
Nov
(585) |
Dec
(455) |
| 2006 |
Jan
(603) |
Feb
(656) |
Mar
(195) |
Apr
(114) |
May
(136) |
Jun
(100) |
Jul
(128) |
Aug
(68) |
Sep
(7) |
Oct
(1) |
Nov
(1) |
Dec
(8) |
| 2007 |
Jan
(4) |
Feb
(3) |
Mar
(8) |
Apr
(16) |
May
(5) |
Jun
(4) |
Jul
(6) |
Aug
(23) |
Sep
(15) |
Oct
(5) |
Nov
(7) |
Dec
(5) |
| 2008 |
Jan
(5) |
Feb
(1) |
Mar
(1) |
Apr
(5) |
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
(1) |
Jul
(1) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(2) |
| 2013 |
Jan
(1) |
Feb
|
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(2) |
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
| 2015 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2017 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <hib...@li...> - 2006-05-30 13:17:50
|
Author: max...@jb... Date: 2006-05-30 09:17:40 -0400 (Tue, 30 May 2006) New Revision: 9960 Added: trunk/Hibernate3/test/org/hibernate/test/pretty/ Log: HHH-1748 formatter breaks on single tick in e.g. a comment + Tests for the formatter |
|
From: <hib...@li...> - 2006-05-30 12:51:18
|
Author: ste...@jb...
Date: 2006-05-30 08:51:00 -0400 (Tue, 30 May 2006)
New Revision: 9959
Modified:
trunk/Hibernate3/src/org/hibernate/cfg/SettingsFactory.java
Log:
HHH-1795 : default CacheProvider to NoCacheProvider
Modified: trunk/Hibernate3/src/org/hibernate/cfg/SettingsFactory.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cfg/SettingsFactory.java 2006-05-29 14:22:22 UTC (rev 9958)
+++ trunk/Hibernate3/src/org/hibernate/cfg/SettingsFactory.java 2006-05-30 12:51:00 UTC (rev 9959)
@@ -45,6 +45,7 @@
public class SettingsFactory implements Serializable {
private static final Log log = LogFactory.getLog(SettingsFactory.class);
+ public static final String DEF_CACHE_PROVIDER = NoCacheProvider.class.getName();
protected SettingsFactory() throws HibernateException {}
@@ -293,7 +294,7 @@
}
- private BytecodeProvider buildBytecodeProvider(String providerName) {
+ protected BytecodeProvider buildBytecodeProvider(String providerName) {
if ( "javassist".equals( providerName ) ) {
return new org.hibernate.bytecode.javassist.BytecodeProviderImpl();
}
@@ -336,10 +337,10 @@
throw new HibernateException("could not instantiate QueryCacheFactory: " + queryCacheFactoryClassName, cnfe);
}
}
-
+
protected CacheProvider createCacheProvider(Properties properties) {
String cacheClassName = PropertiesHelper.getString(
- Environment.CACHE_PROVIDER, properties, "org.hibernate.cache.EhCacheProvider"
+ Environment.CACHE_PROVIDER, properties, DEF_CACHE_PROVIDER
);
log.info("Cache provider: " + cacheClassName);
try {
|
|
From: <hib...@li...> - 2006-05-29 14:22:33
|
Author: max...@jb...
Date: 2006-05-29 10:22:22 -0400 (Mon, 29 May 2006)
New Revision: 9958
Modified:
trunk/HibernateExt/tools/src/templates/doc/tables/table-list.ftl
Log:
removed wrong </font>
Modified: trunk/HibernateExt/tools/src/templates/doc/tables/table-list.ftl
===================================================================
--- trunk/HibernateExt/tools/src/templates/doc/tables/table-list.ftl 2006-05-29 14:21:56 UTC (rev 9957)
+++ trunk/HibernateExt/tools/src/templates/doc/tables/table-list.ftl 2006-05-29 14:22:22 UTC (rev 9958)
@@ -20,7 +20,7 @@
</FONT>
<BR>
<#foreach table in tableList>
- <A HREF='${docFileManager.getRef(docFile, docFileManager.getTableDocFile(table))}' TARGET="generalFrame">${table.name}</A></FONT>
+ <A HREF='${docFileManager.getRef(docFile, docFileManager.getTableDocFile(table))}' TARGET="generalFrame">${table.name}</A>
<BR>
</#foreach> </TD>
</TR>
|
|
From: <hib...@li...> - 2006-05-29 14:22:13
|
Author: max...@jb...
Date: 2006-05-29 10:21:56 -0400 (Mon, 29 May 2006)
New Revision: 9957
Modified:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Model.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.hbm.xml
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.java
Log:
fixed completion for joined components
e.g. "from Product p join p.otherOwners where p.|"
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java 2006-05-29 14:20:28 UTC (rev 9956)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java 2006-05-29 14:21:56 UTC (rev 9957)
@@ -9,6 +9,7 @@
import java.util.Set;
import java.util.Map.Entry;
+import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Component;
@@ -104,6 +105,8 @@
// No properties left
if (value instanceof Component) {
addPropertiesToList((Component) value, prefix, cursorPosition, hcc);
+ } else if (value instanceof Collection && ((Collection)value).getElement() instanceof Component) {
+ addPropertiesToList((Component) ((Collection)value).getElement(), prefix, cursorPosition, hcc);
} else {
addPropertiesToList(getPersistentClass( getReferencedEntityName( value ) ), prefix, cursorPosition, hcc);
}
@@ -280,8 +283,13 @@
if (attribute.equals(idName)) {
return cmd.getIdentifierProperty().getValue();
}
- Property property = cmd.getProperty( attribute );
- return property==null?null:property.getValue();
+ try {
+ Property property = cmd.getProperty( attribute );
+ return property==null?null:property.getValue();
+ } catch (HibernateException he) {
+ return null;
+ }
+
}
private Value getNextAttributeType(Component t, String attributeName) {
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Model.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Model.java 2006-05-29 14:20:28 UTC (rev 9956)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Model.java 2006-05-29 14:21:56 UTC (rev 9957)
@@ -38,6 +38,7 @@
addInputStream(Model.class.getResourceAsStream("Store.hbm.xml")).
addInputStream(Model.class.getResourceAsStream("ProductOwnerAddress.hbm.xml")).
addInputStream(Model.class.getResourceAsStream("StoreCity.hbm.xml"));
+ cfg.buildMappings();
return cfg;
}
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java 2006-05-29 14:20:28 UTC (rev 9956)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java 2006-05-29 14:21:56 UTC (rev 9957)
@@ -96,7 +96,7 @@
Collector hcc = new Collector();
cc.getMatchingProperties( "Product", "", hcc );
- doTestFields(hcc.getCompletionProposals(), new String[] {"id", "owner", "price", "stores", "version", "weight"});
+ doTestFields(hcc.getCompletionProposals(), new String[] {"id", "otherOwners", "owner", "price", "stores", "version", "weight" });
hcc.clear();
cc.getMatchingProperties( "Product", " ", hcc );
@@ -407,7 +407,17 @@
assertEquals(3, completionProposals.length);
-
+ c.clear();
+
+ query = "from Product as p join p.otherOwners o where o.";
+ caretPosition = getCaretPosition(query);
+ hqlEval.codeComplete(getCleanQuery(query), caretPosition, c);
+
+ completionProposals = c.getCompletionProposals();
+
+ assertEquals(3, completionProposals.length);
+
+
}
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.hbm.xml
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.hbm.xml 2006-05-29 14:20:28 UTC (rev 9956)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.hbm.xml 2006-05-29 14:21:56 UTC (rev 9957)
@@ -23,6 +23,15 @@
<property name="lastName"/>
<one-to-one name="address" class="ProductOwnerAddress"/>
</component>
+
+ <set name="otherOwners">
+ <key/>
+ <composite-element class="ProductOwner">
+ <property name="firstName"/>
+ <property name="lastName"/>
+ <many-to-one name="address" class="ProductOwnerAddress"/>
+ </composite-element>
+ </set>
</class>
</hibernate-mapping>
\ No newline at end of file
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.java 2006-05-29 14:20:28 UTC (rev 9956)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.java 2006-05-29 14:21:56 UTC (rev 9957)
@@ -37,6 +37,8 @@
private ProductOwner owner;
+ private Set otherOwners;
+
public Product() {
}
@@ -87,5 +89,12 @@
public ProductOwner getOwner() {
return owner;
}
+
+ public Set getOtherOwners() {
+ return otherOwners;
+ }
+ public void setOtherOwners(Set otherOwners) {
+ this.otherOwners = otherOwners;
+ }
}
|
|
From: <hib...@li...> - 2006-05-29 14:20:33
|
Author: max...@jb...
Date: 2006-05-29 10:20:28 -0400 (Mon, 29 May 2006)
New Revision: 9956
Modified:
trunk/HibernateExt/tools/doc/reference/en/modules/plugins.xml
trunk/HibernateExt/tools/doc/reference/en/modules/reverseengineering.xml
Log:
typos
Modified: trunk/HibernateExt/tools/doc/reference/en/modules/plugins.xml
===================================================================
--- trunk/HibernateExt/tools/doc/reference/en/modules/plugins.xml 2006-05-29 04:04:13 UTC (rev 9955)
+++ trunk/HibernateExt/tools/doc/reference/en/modules/plugins.xml 2006-05-29 14:20:28 UTC (rev 9956)
@@ -571,7 +571,7 @@
<para>The Hibernate Mapping file editor provides XML editing functionality
for the hbm.xml and cfg.xml files. The editor is based on the Eclipse WTP
- tools and extend its functionallity to provide hiberante specific code
+ tools and extend its functionallity to provide hibernate specific code
completion.</para>
<mediaobject>
Modified: trunk/HibernateExt/tools/doc/reference/en/modules/reverseengineering.xml
===================================================================
--- trunk/HibernateExt/tools/doc/reference/en/modules/reverseengineering.xml 2006-05-29 04:04:13 UTC (rev 9955)
+++ trunk/HibernateExt/tools/doc/reference/en/modules/reverseengineering.xml 2006-05-29 14:20:28 UTC (rev 9956)
@@ -605,7 +605,7 @@
<callout arearefs="foreignkey-schema">
<para>foreign-schema (Optional): Name of the foreign table's
- schema. (Only relevant if you want to explicitly define a
+ schema. (Only relevant if you want to explicitly define a
foreign key)</para>
</callout>
|
Author: epbernard
Date: 2006-05-29 00:04:13 -0400 (Mon, 29 May 2006)
New Revision: 9955
Added:
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/ExceptionListener.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/Rythm.java
Modified:
trunk/HibernateExt/ejb/lib/hibernate-annotations.jar
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/BeanCallback.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/ListenerCallback.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java
Log:
ANN-350 no schemalocator allowed in dd
EJB-187 RE passes as is from callback methods
Modified: trunk/HibernateExt/ejb/lib/hibernate-annotations.jar
===================================================================
(Binary files differ)
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-28 17:20:26 UTC (rev 9954)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-29 04:04:13 UTC (rev 9955)
@@ -367,6 +367,10 @@
SAXReader saxReader = xmlHelper.createSAXReader( "XML InputStream", errors, cfg.getEntityResolver() );
try {
saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
+ //saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
+ //set the default schema locators
+ saxReader.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation",
+ "http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd");
}
catch (SAXException e) {
saxReader.setValidation( false );
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/BeanCallback.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/BeanCallback.java 2006-05-28 17:20:26 UTC (rev 9954)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/BeanCallback.java 2006-05-29 04:04:13 UTC (rev 9955)
@@ -7,6 +7,7 @@
package org.hibernate.ejb.event;
import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
/**
* @author <a href="mailto:kab...@jb...">Kabir Khan</a>
@@ -21,6 +22,15 @@
try {
callbackMethod.invoke( bean, new Object[0] );
}
+ catch (InvocationTargetException e) {
+ //keep runtime exceptions as is
+ if ( e.getTargetException() instanceof RuntimeException ) {
+ throw (RuntimeException) e.getCause();
+ }
+ else {
+ throw new RuntimeException( e.getTargetException() );
+ }
+ }
catch (Exception e) {
throw new RuntimeException( e );
}
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/ListenerCallback.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/ListenerCallback.java 2006-05-28 17:20:26 UTC (rev 9954)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/ListenerCallback.java 2006-05-29 04:04:13 UTC (rev 9955)
@@ -10,6 +10,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
import org.hibernate.util.ReflectHelper;
@@ -29,6 +30,15 @@
try {
callbackMethod.invoke( listener, new Object[]{bean} );
}
+ catch (InvocationTargetException e) {
+ //keep runtime exceptions as is
+ if ( e.getTargetException() instanceof RuntimeException ) {
+ throw (RuntimeException) e.getCause();
+ }
+ else {
+ throw new RuntimeException( e.getTargetException() );
+ }
+ }
catch (Exception e) {
throw new RuntimeException( e );
}
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java 2006-05-28 17:20:26 UTC (rev 9954)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java 2006-05-29 04:04:13 UTC (rev 9955)
@@ -125,16 +125,39 @@
em.flush();
assertEquals( 1, tv.counter );
em.getTransaction().rollback();
+ em.close();
assertEquals( 5, tv.communication );
assertTrue( tv.isLast );
}
+ public void testException() throws Exception {
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ Rythm r = new Rythm();
+ try {
+ em.persist( r );
+ em.flush();
+ fail("should have raised an ArythmeticException:");
+ }
+ catch (ArithmeticException e) {
+ //success
+ }
+ catch( Exception e ) {
+ fail("should have raised an ArythmeticException:" + e.getClass() );
+ }
+
+ em.getTransaction().rollback();
+ em.close();
+
+ }
+
public Class[] getAnnotatedClasses() {
return new Class[]{
Cat.class,
Translation.class,
Television.class,
- RemoteControl.class
+ RemoteControl.class,
+ Rythm.class
};
}
}
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/ExceptionListener.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/ExceptionListener.java 2006-05-28 17:20:26 UTC (rev 9954)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/ExceptionListener.java 2006-05-29 04:04:13 UTC (rev 9955)
@@ -0,0 +1,14 @@
+//$Id: $
+package org.hibernate.ejb.test.callbacks;
+
+import javax.persistence.PrePersist;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ExceptionListener {
+ @PrePersist
+ public void raiseException(Object e) {
+ throw new ArithmeticException( "1/0 impossible" );
+ }
+}
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/Rythm.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/Rythm.java 2006-05-28 17:20:26 UTC (rev 9954)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/callbacks/Rythm.java 2006-05-29 04:04:13 UTC (rev 9955)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.ejb.test.callbacks;
+
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+import javax.persistence.EntityListeners;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@EntityListeners(ExceptionListener.class)
+public class Rythm {
+ @Id @GeneratedValue private Integer id;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+}
|
|
From: <hib...@li...> - 2006-05-28 17:20:37
|
Author: max...@jb...
Date: 2006-05-28 13:20:26 -0400 (Sun, 28 May 2006)
New Revision: 9954
Modified:
trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideBinder.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/XMLPrettyPrinter.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Article.hbm.xml
trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java
Log:
HBX-666 generics appended when using property-type
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideBinder.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideBinder.java 2006-05-28 17:18:19 UTC (rev 9953)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideBinder.java 2006-05-28 17:20:26 UTC (rev 9954)
@@ -314,6 +314,9 @@
}
}
+ String getMatchString(String input) {
+ return input.toUpperCase();
+ }
}
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java 2006-05-28 17:18:19 UTC (rev 9953)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java 2006-05-28 17:20:26 UTC (rev 9954)
@@ -166,7 +166,14 @@
public String getJavaTypeName(Property p, boolean useGenerics, ImportContext importContext) {
String overrideType = getMetaAsString( p, "property-type" );
if ( !StringHelper.isEmpty( overrideType ) ) {
- return importContext.importType(overrideType);
+ String importType = importContext.importType(overrideType);
+ if ( useGenerics && importType.indexOf( "<" )<0) {
+ if ( p.getValue() instanceof Collection ) {
+ String decl = getGenericCollectionDeclaration( (Collection) p.getValue(), true, importContext );
+ return importType + decl;
+ }
+ }
+ return importType;
}
else {
String rawType = getRawTypeName( p, useGenerics, true, importContext );
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/XMLPrettyPrinter.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/XMLPrettyPrinter.java 2006-05-28 17:18:19 UTC (rev 9953)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/XMLPrettyPrinter.java 2006-05-28 17:20:26 UTC (rev 9954)
@@ -130,11 +130,13 @@
if ( tidy.getParseErrors() > 0 ) {
if(silent) {
- log.info("Tidy was unable to process file " + inputFile + ", " + tidy.getParseErrors() + " errors found." );
+ log.warn("Tidy was unable to process file " + inputFile + ", " + tidy.getParseErrors() + " errors found." );
} else {
throw new ExporterException( "Tidy was unable to process file "
+ inputFile + ", " + tidy.getParseErrors() + " errors found." );
}
+ } else {
+ log.debug("XMLPrettyPrinting completed");
}
}
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Article.hbm.xml
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Article.hbm.xml 2006-05-28 17:18:19 UTC (rev 9953)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Article.hbm.xml 2006-05-28 17:20:26 UTC (rev 9954)
@@ -41,7 +41,7 @@
<bag name="bagarticles"
inverse="true"
cascade="save-update">
-
+ <meta attribute="property-type">java.util.List</meta>
<key column="authorId"/>
<one-to-many class="Article"/>
</bag>
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java 2006-05-28 17:18:19 UTC (rev 9953)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java 2006-05-28 17:20:26 UTC (rev 9954)
@@ -93,7 +93,7 @@
assertEquals("Map<String,Article>",cfg2java.getJavaTypeName(p, true, clazz));
assertEquals("new HashMap<String,Article>(0)", clazz.getFieldInitialization(p, true));
assertEquals("new HashMap(0)", clazz.getFieldInitialization(p, false));
-
+
p = classMapping.getProperty("aList");
assertEquals("lists should not have the index visible in the declaration", "List<Article>",cfg2java.getJavaTypeName(p, true, clazz));
@@ -104,6 +104,16 @@
p = classMapping.getProperty("content");
assertEquals("\"what can I say\"",clazz.getFieldInitialization(p, false));
+
+ p = classMapping.getProperty("bagarticles");
+
+ assertEquals("Should be a list via property-type", "java.util.List", cfg2java.getJavaTypeName( p, false ));
+ assertEquals("Should be a a generic'd list when generics=true", "java.util.List<org.hibernate.tool.hbm2x.Article>", cfg2java.getJavaTypeName( p, true ));
+ assertEquals("List<Article>",cfg2java.getJavaTypeName(p, true, clazz));
+ assertEquals("new ArrayList<Article>(0)", clazz.getFieldInitialization(p, true));
+ assertEquals("new ArrayList(0)", clazz.getFieldInitialization(p, false));
+
+
}
|
|
From: <hib...@li...> - 2006-05-28 17:18:25
|
Author: max...@jb...
Date: 2006-05-28 13:18:19 -0400 (Sun, 28 May 2006)
New Revision: 9953
Modified:
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java
Log:
component property completion test
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java 2006-05-28 15:28:12 UTC (rev 9952)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java 2006-05-28 17:18:19 UTC (rev 9953)
@@ -19,16 +19,11 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import junit.framework.TestCase;
import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Property;
/**
* @author leon
@@ -167,7 +162,7 @@
String f = fields[j];
HQLCompletionProposal proposal = proposals[j];
assertEquals("Invalid field name at " + j, f, proposal.getSimpleName());
- assertEquals("Invalid kind at " + j, proposal.getCompletionKind(), proposal.PROPERTY);
+ assertEquals("Invalid kind at " + j, proposal.getCompletionKind(), HQLCompletionProposal.PROPERTY);
}
}
@@ -388,6 +383,34 @@
}
+ public void testComponentPropertyNames() {
+ Collector c = new Collector();
+
+ IHQLCodeAssist hqlEval = new HQLCodeAssist(sf);
+
+ String query = "from Product as p where p.owner.|";
+ int caretPosition = getCaretPosition(query);
+ hqlEval.codeComplete(getCleanQuery(query), caretPosition, c);
+
+ HQLCompletionProposal[] completionProposals = c.getCompletionProposals();
+
+ assertEquals(3, completionProposals.length);
+ HQLCompletionProposal proposal = completionProposals[0];
+
+ c.clear();
+
+ query = "from Product as p where p.owner.address.";
+ caretPosition = getCaretPosition(query);
+ hqlEval.codeComplete(getCleanQuery(query), caretPosition, c);
+
+ completionProposals = c.getCompletionProposals();
+
+ assertEquals(3, completionProposals.length);
+
+
+ }
+
+
public void testInFromAfterEntityAlias() {
Collector c = new Collector();
|
|
From: <hib...@li...> - 2006-05-28 15:28:14
|
Author: epbernard
Date: 2006-05-28 11:28:12 -0400 (Sun, 28 May 2006)
New Revision: 9952
Modified:
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
Log:
EJB-98 em.remove() em.find() no longer fails
EJB-185 align exceptions to glassfish
EJB-186 change the default cache provider
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-05-28 15:20:06 UTC (rev 9951)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-05-28 15:28:12 UTC (rev 9952)
@@ -154,6 +154,10 @@
try {
return (A) getSession().get( entityClass, (Serializable) primaryKey );
}
+ catch (ObjectDeletedException e) {
+ //the spec is silent about people doing remove() find() on the same PC
+ return null;
+ }
catch (ObjectNotFoundException e) {
//should not happen on the entity itself with get
throw new IllegalArgumentException( e.getMessage(), e );
@@ -555,13 +559,13 @@
throwPersistenceException( new EntityExistsException( e ) );
}
else if ( e instanceof ObjectNotFoundException ) {
- throwPersistenceException( new EntityNotFoundException( e ) );
+ throwPersistenceException( new EntityNotFoundException( e.getMessage() ) );
}
else if ( e instanceof org.hibernate.NonUniqueResultException ) {
- throwPersistenceException( new NonUniqueResultException( e ) );
+ throwPersistenceException( new NonUniqueResultException( e.getMessage() ) );
}
else if ( e instanceof UnresolvableObjectException ) {
- throwPersistenceException( new EntityNotFoundException( e ) );
+ throwPersistenceException( new EntityNotFoundException( e.getMessage() ) );
}
else {
throwPersistenceException( new PersistenceException( e ) );
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-28 15:20:06 UTC (rev 9951)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-28 15:28:12 UTC (rev 9952)
@@ -39,9 +39,7 @@
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.MappingException;
-import org.hibernate.ObjectNotFoundException;
import org.hibernate.SessionFactory;
-import org.hibernate.reflection.java.xml.XMLContext;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
@@ -61,6 +59,7 @@
import org.hibernate.mapping.AuxiliaryDatabaseObject;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.proxy.EntityNotFoundDelegate;
+import org.hibernate.reflection.java.xml.XMLContext;
import org.hibernate.secure.JACCConfiguration;
import org.hibernate.transaction.JDBCTransactionFactory;
import org.hibernate.util.CollectionHelper;
@@ -94,9 +93,7 @@
cfg.setEntityNotFoundDelegate( new EntityNotFoundDelegate() {
public void handleEntityNotFound(String entityName, Serializable id) {
- //keep the original ONFE for the sake of consistency in the way we handle Hibernate exceptions
- Exception e = new ObjectNotFoundException( id, entityName );
- throw new EntityNotFoundException("Unable to find " + entityName + " with id " + id, e);
+ throw new EntityNotFoundException("Unable to find " + entityName + " with id " + id);
}
} );
listenerConfigurator = new EventListenerConfigurator( this );
@@ -836,6 +833,7 @@
//defaults different to Hibernate
preparedProperties.setProperty( Environment.RELEASE_CONNECTIONS, "auto" );
+ preparedProperties.setProperty( Environment.CACHE_PROVIDER, "org.hibernate.cache.NoCacheProvider" ); //use a string to avoid class loading
//settings that always apply to a compliant EJB3
preparedProperties.setProperty( Environment.AUTOCOMMIT, "true" );
preparedProperties.setProperty( Environment.USE_IDENTIFIER_ROLLBACK, "false" );
|
Author: epbernard
Date: 2006-05-28 11:20:06 -0400 (Sun, 28 May 2006)
New Revision: 9951
Added:
trunk/HibernateExt/metadata/src/java/org/hibernate/validator/resources/DefaultValidatorMessages_pt_BR.properties
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/fetch/FetchingTest.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/fetch/Person.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/xml/ejb3/orm.xml
Log:
ANN-350 support no grammar on EJB3 schema
ANN-351 add brazilian translation
more tests
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-05-28 14:47:10 UTC (rev 9950)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-05-28 15:20:06 UTC (rev 9951)
@@ -556,6 +556,9 @@
SAXReader saxReader = xmlHelper.createSAXReader( "XML InputStream", errors, getEntityResolver() );
try {
saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
+ //saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true );
+ saxReader.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation",
+ "http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd");
}
catch (SAXException e) {
saxReader.setValidation( false );
Added: trunk/HibernateExt/metadata/src/java/org/hibernate/validator/resources/DefaultValidatorMessages_pt_BR.properties
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/validator/resources/DefaultValidatorMessages_pt_BR.properties 2006-05-28 14:47:10 UTC (rev 9950)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/validator/resources/DefaultValidatorMessages_pt_BR.properties 2006-05-28 15:20:06 UTC (rev 9951)
@@ -0,0 +1,12 @@
+validator.assertFalse=asser falhou
+validator.assertTrue=asser falhou
+validator.future=deve ser uma data no futuro
+validator.length=tamanho deve estar entre {min} e {max}
+validator.max=deve ser menor ou igual a {value}
+validator.min=deve ser maior ou igual a {value}
+validator.notNull=npode ser nulo
+validator.past=deve ser uma data no passado
+validator.pattern=deve ser vda de acordo com a express"{regex}"
+validator.range=deve estar entre {min} e {max}
+validator.size=tamanho deve estar entre {min} e {max}
+validator.email=nm email vdo
\ No newline at end of file
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/fetch/FetchingTest.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/fetch/FetchingTest.java 2006-05-28 14:47:10 UTC (rev 9950)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/fetch/FetchingTest.java 2006-05-28 15:20:06 UTC (rev 9951)
@@ -32,6 +32,30 @@
s.close();
}
+ public void testExtraLazy() throws Exception {
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ Person p = new Person( "Gavin", "King", "JBoss Inc" );
+ Stay stay = new Stay( p, new Date(), new Date(), "A380", "Blah", "Blah" );
+ p.getOrderedStay().add( stay );
+ s.persist( p );
+ tx.commit();
+ s.clear();
+ tx = s.beginTransaction();
+ p = (Person) s.createQuery( "from Person p where p.firstName = :name" )
+ .setParameter( "name", "Gavin" ).uniqueResult();
+ assertFalse( Hibernate.isInitialized( p.getOrderedStay() ) );
+ assertEquals( 1, p.getOrderedStay().size() );
+ assertFalse( Hibernate.isInitialized( p.getOrderedStay() ) );
+ assertEquals( "A380", p.getOrderedStay().get(0).getVessel() );
+ assertFalse( Hibernate.isInitialized( p.getOrderedStay() ) );
+ s.delete( p );
+ tx.commit();
+ s.close();
+ }
+
public void testHibernateFetchingLazy() throws Exception {
Session s;
Transaction tx;
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/fetch/Person.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/fetch/Person.java 2006-05-28 14:47:10 UTC (rev 9950)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/fetch/Person.java 2006-05-28 15:20:06 UTC (rev 9951)
@@ -18,6 +18,7 @@
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
+import org.hibernate.annotations.IndexColumn;
/**
@@ -35,6 +36,7 @@
private Collection<Stay> stays;
private Collection<Stay> oldStays;
private Collection<Stay> veryOldStays;
+ private List<Stay> orderedStay = new ArrayList<Stay>();
// constructors
public Person() {
@@ -113,7 +115,19 @@
this.veryOldStays = veryOldStays;
}
+ @OneToMany(cascade=CascadeType.ALL)
+ @LazyCollection(LazyCollectionOption.EXTRA)
+ @Fetch(FetchMode.SUBSELECT)
+ @IndexColumn(name="orderedStayIndex")
+ public List<Stay> getOrderedStay() {
+ return orderedStay;
+ }
+ public void setOrderedStay(List<Stay> orderedStay) {
+ this.orderedStay = orderedStay;
+ }
+
+
// business logic
public void addStay(Date startDate, Date endDate, String vessel, String authoriser, String comments) {
Stay stay = new Stay( this, startDate, endDate, vessel, authoriser, comments );
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/xml/ejb3/orm.xml
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/xml/ejb3/orm.xml 2006-05-28 14:47:10 UTC (rev 9950)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/xml/ejb3/orm.xml 2006-05-28 15:20:06 UTC (rev 9951)
@@ -2,9 +2,9 @@
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
version="1.0"
>
+ <!-- no grammar specified should pass -->
<persistence-unit-metadata>
<persistence-unit-defaults>
<cascade-persist/>
|
|
From: <hib...@li...> - 2006-05-28 14:47:17
|
Author: max...@jb... Date: 2006-05-28 10:47:10 -0400 (Sun, 28 May 2006) New Revision: 9950 Modified: trunk/Hibernate3/etc/hibernate.properties Log: oops Modified: trunk/Hibernate3/etc/hibernate.properties =================================================================== --- trunk/Hibernate3/etc/hibernate.properties 2006-05-28 13:04:35 UTC (rev 9949) +++ trunk/Hibernate3/etc/hibernate.properties 2006-05-28 14:47:10 UTC (rev 9950) @@ -35,11 +35,11 @@ hibernate.connection.url jdbc:hsqldb:. ## H2 (www.h2database.com) -hibernate.dialect org.hibernate.dialect.H2Dialect -hibernate.connection.driver_class org.h2.Driver -hibernate.connection.username sa -hibernate.connection.password -hibernate.connection.url jdbc:h2:testdb/h2test +#hibernate.dialect org.hibernate.dialect.H2Dialect +#hibernate.connection.driver_class org.h2.Driver +#hibernate.connection.username sa +#hibernate.connection.password +#hibernate.connection.url jdbc:h2:testdb/h2test #hibernate.connection.url jdbc:h2:mem:imdb1 #hibernate.connection.url jdbc:h2:tcp://dbserv:8084/sample; #hibernate.connection.url jdbc:h2:ssl://secureserv:8085/sample; |
|
From: <hib...@li...> - 2006-05-28 13:04:42
|
Author: max...@jb... Date: 2006-05-28 09:04:35 -0400 (Sun, 28 May 2006) New Revision: 9949 Modified: trunk/Hibernate3/etc/hibernate.properties trunk/Hibernate3/src/org/hibernate/cfg/Environment.java Log: h2 hibernate.properties missing HHH-227 hibernate.properties and javadoc update Modified: trunk/Hibernate3/etc/hibernate.properties =================================================================== --- trunk/Hibernate3/etc/hibernate.properties 2006-05-28 11:30:18 UTC (rev 9948) +++ trunk/Hibernate3/etc/hibernate.properties 2006-05-28 13:04:35 UTC (rev 9949) @@ -34,6 +34,16 @@ #hibernate.connection.url jdbc:hsqldb:test hibernate.connection.url jdbc:hsqldb:. +## H2 (www.h2database.com) +hibernate.dialect org.hibernate.dialect.H2Dialect +hibernate.connection.driver_class org.h2.Driver +hibernate.connection.username sa +hibernate.connection.password +hibernate.connection.url jdbc:h2:testdb/h2test +#hibernate.connection.url jdbc:h2:mem:imdb1 +#hibernate.connection.url jdbc:h2:tcp://dbserv:8084/sample; +#hibernate.connection.url jdbc:h2:ssl://secureserv:8085/sample; +#hibernate.connection.url jdbc:h2:ssl://secureserv/testdb;cipher=AES ## MySQL @@ -54,6 +64,7 @@ #hibernate.connection.username ora #hibernate.connection.password ora #hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl +#hibernate.connection.url jdbc:oracle:thin:@localhost:1522:XE ## PostgreSQL @@ -68,8 +79,10 @@ ## DB2 #hibernate.dialect org.hibernate.dialect.DB2Dialect +#hibernate.connection.driver_class com.ibm.db2.jcc.DB2Driver #hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver -#hibernate.connection.url jdbc:db2:test +#hibernate.connection.url jdbc:db2://localhost:50000/somename +#hibernate.connection.url jdbc:db2:somename #hibernate.connection.username db2 #hibernate.connection.password db2 @@ -156,6 +169,10 @@ #hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver #hibernate.connection.url jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor +## The New Microsoft Driver +#hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver +#hibernate.connection.url jdbc:sqlserver://localhost + ## jTDS (since version 0.9) #hibernate.connection.driver_class net.sourceforge.jtds.jdbc.Driver #hibernate.connection.url jdbc:jtds:sqlserver://1E1/test @@ -357,9 +374,9 @@ #hibernate.use_identifer_rollback true -## enable CGLIB reflection optimizer (enabled by default) +## enable bytecode reflection optimizer (disabled by default) -#hibernate.cglib.use_reflection_optimizer false +#hibernate.bytecode.use_reflection_optimizer true Modified: trunk/Hibernate3/src/org/hibernate/cfg/Environment.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/cfg/Environment.java 2006-05-28 11:30:18 UTC (rev 9948) +++ trunk/Hibernate3/src/org/hibernate/cfg/Environment.java 2006-05-28 13:04:35 UTC (rev 9949) @@ -406,7 +406,7 @@ public static final String USE_IDENTIFIER_ROLLBACK = "hibernate.use_identifier_rollback"; /** - * Use CGLIB <tt>MetaClass</tt> to optimize property access + * Use bytecode libraries optimized property access */ public static final String USE_REFLECTION_OPTIMIZER = "hibernate.bytecode.use_reflection_optimizer"; |
|
From: <hib...@li...> - 2006-05-28 11:30:24
|
Author: max...@jb...
Date: 2006-05-28 07:30:18 -0400 (Sun, 28 May 2006)
New Revision: 9948
Added:
trunk/Hibernate3/src/org/hibernate/dialect/H2Dialect.java
Log:
HHH-1558 H2Dialect
Added: trunk/Hibernate3/src/org/hibernate/dialect/H2Dialect.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/dialect/H2Dialect.java 2006-05-28 11:28:13 UTC (rev 9947)
+++ trunk/Hibernate3/src/org/hibernate/dialect/H2Dialect.java 2006-05-28 11:30:18 UTC (rev 9948)
@@ -0,0 +1,278 @@
+package org.hibernate.dialect;
+
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.Hibernate;
+import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.function.NoArgSQLFunction;
+import org.hibernate.dialect.function.StandardSQLFunction;
+import org.hibernate.dialect.function.VarArgsSQLFunction;
+import org.hibernate.exception.TemplatedViolatedConstraintNameExtracter;
+import org.hibernate.exception.ViolatedConstraintNameExtracter;
+
+/**
+ * A dialect compatible with the H2 database.
+ *
+ * @author Thomas Mueller
+ *
+ */
+public class H2Dialect extends Dialect {
+
+ public H2Dialect() {
+ super();
+
+ registerColumnType(Types.BOOLEAN, "boolean");
+ registerColumnType(Types.BIGINT, "bigint");
+ registerColumnType(Types.BINARY, "binary");
+ registerColumnType(Types.BIT, "bit");
+ registerColumnType(Types.CHAR, "char($l)");
+ registerColumnType(Types.DATE, "date");
+ registerColumnType(Types.DECIMAL, "decimal($p,$s)");
+ registerColumnType(Types.DOUBLE, "double");
+ registerColumnType(Types.FLOAT, "float");
+ registerColumnType(Types.INTEGER, "integer");
+ registerColumnType(Types.LONGVARBINARY, "longvarbinary");
+ registerColumnType(Types.LONGVARCHAR, "longvarchar");
+ registerColumnType(Types.REAL, "real");
+ registerColumnType(Types.SMALLINT, "smallint");
+ registerColumnType(Types.TINYINT, "tinyint");
+ registerColumnType(Types.TIME, "time");
+ registerColumnType(Types.TIMESTAMP, "timestamp");
+ registerColumnType(Types.VARCHAR, "varchar($l)");
+ registerColumnType(Types.VARBINARY, "binary($l)");
+ registerColumnType(Types.NUMERIC, "numeric");
+ registerColumnType(Types.BLOB, "blob");
+ registerColumnType(Types.CLOB, "clob");
+
+ // select topic, syntax from information_schema.help
+ // where section like 'Function%' order by section, topic
+
+// registerFunction("abs", new StandardSQLFunction("abs"));
+ registerFunction("acos", new StandardSQLFunction("acos", Hibernate.DOUBLE));
+ registerFunction("asin", new StandardSQLFunction("asin", Hibernate.DOUBLE));
+ registerFunction("atan", new StandardSQLFunction("atan", Hibernate.DOUBLE));
+ registerFunction("atan2", new StandardSQLFunction("atan2", Hibernate.DOUBLE));
+ registerFunction("bitand", new StandardSQLFunction("bitand", Hibernate.INTEGER));
+ registerFunction("bitor", new StandardSQLFunction("bitor", Hibernate.INTEGER));
+ registerFunction("bitxor", new StandardSQLFunction("bitxor", Hibernate.INTEGER));
+ registerFunction("ceiling", new StandardSQLFunction("ceiling", Hibernate.DOUBLE));
+ registerFunction("cos", new StandardSQLFunction("cos", Hibernate.DOUBLE));
+ registerFunction("cot", new StandardSQLFunction("cot", Hibernate.DOUBLE));
+ registerFunction("degrees", new StandardSQLFunction("degrees", Hibernate.DOUBLE));
+ registerFunction("exp", new StandardSQLFunction("exp", Hibernate.DOUBLE));
+ registerFunction("floor", new StandardSQLFunction("floor", Hibernate.DOUBLE));
+ registerFunction("log", new StandardSQLFunction("log", Hibernate.DOUBLE));
+ registerFunction("log10", new StandardSQLFunction("log10", Hibernate.DOUBLE));
+// registerFunction("mod", new StandardSQLFunction("mod", Hibernate.INTEGER));
+ registerFunction("pi", new NoArgSQLFunction("pi", Hibernate.DOUBLE));
+ registerFunction("power", new StandardSQLFunction("power", Hibernate.DOUBLE));
+ registerFunction("radians", new StandardSQLFunction("radians", Hibernate.DOUBLE));
+ registerFunction("rand", new NoArgSQLFunction("rand", Hibernate.DOUBLE));
+ registerFunction("round", new StandardSQLFunction("round", Hibernate.DOUBLE));
+ registerFunction("roundmagic", new StandardSQLFunction("roundmagic", Hibernate.DOUBLE));
+ registerFunction("sign", new StandardSQLFunction("sign", Hibernate.INTEGER));
+ registerFunction("sin", new StandardSQLFunction("sin", Hibernate.DOUBLE));
+// registerFunction("sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE));
+ registerFunction("tan", new StandardSQLFunction("tan", Hibernate.DOUBLE));
+ registerFunction("truncate", new StandardSQLFunction("truncate", Hibernate.DOUBLE));
+
+ registerFunction("compress", new StandardSQLFunction("compress", Hibernate.BINARY));
+ registerFunction("expand", new StandardSQLFunction("compress", Hibernate.BINARY));
+ registerFunction("decrypt", new StandardSQLFunction("decrypt", Hibernate.BINARY));
+ registerFunction("encrypt", new StandardSQLFunction("encrypt", Hibernate.BINARY));
+ registerFunction("hash", new StandardSQLFunction("hash", Hibernate.BINARY));
+
+ registerFunction("ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER));
+// registerFunction("bit_length", new StandardSQLFunction("bit_length", Hibernate.INTEGER));
+ registerFunction("char", new StandardSQLFunction("char", Hibernate.CHARACTER));
+ registerFunction("concat", new VarArgsSQLFunction(Hibernate.STRING, "(", "||", ")"));
+ registerFunction("difference", new StandardSQLFunction("difference", Hibernate.INTEGER));
+ registerFunction("hextoraw", new StandardSQLFunction("hextoraw", Hibernate.STRING));
+ registerFunction("lower", new StandardSQLFunction("lower", Hibernate.STRING));
+ registerFunction("insert", new StandardSQLFunction("lower", Hibernate.STRING));
+ registerFunction("left", new StandardSQLFunction("left", Hibernate.STRING));
+// registerFunction("length", new StandardSQLFunction("length", Hibernate.INTEGER));
+// registerFunction("locate", new StandardSQLFunction("locate", Hibernate.INTEGER));
+// registerFunction("lower", new StandardSQLFunction("lower", Hibernate.STRING));
+ registerFunction("lcase", new StandardSQLFunction("lcase", Hibernate.STRING));
+ registerFunction("ltrim", new StandardSQLFunction("ltrim", Hibernate.STRING));
+ registerFunction("octet_length", new StandardSQLFunction("octet_length", Hibernate.INTEGER));
+ registerFunction("position", new StandardSQLFunction("position", Hibernate.INTEGER));
+ registerFunction("rawtohex", new StandardSQLFunction("rawtohex", Hibernate.STRING));
+ registerFunction("repeat", new StandardSQLFunction("repeat", Hibernate.STRING));
+ registerFunction("replace", new StandardSQLFunction("replace", Hibernate.STRING));
+ registerFunction("right", new StandardSQLFunction("right", Hibernate.STRING));
+ registerFunction("rtrim", new StandardSQLFunction("rtrim", Hibernate.STRING));
+ registerFunction("soundex", new StandardSQLFunction("soundex", Hibernate.STRING));
+ registerFunction("space", new StandardSQLFunction("space", Hibernate.STRING));
+ registerFunction("stringencode", new StandardSQLFunction("stringencode", Hibernate.STRING));
+ registerFunction("stringdecode", new StandardSQLFunction("stringdecode", Hibernate.STRING));
+// registerFunction("substring", new StandardSQLFunction("substring", Hibernate.STRING));
+// registerFunction("upper", new StandardSQLFunction("upper", Hibernate.STRING));
+ registerFunction("ucase", new StandardSQLFunction("ucase", Hibernate.STRING));
+
+ registerFunction("stringtoutf8", new StandardSQLFunction("stringtoutf8", Hibernate.BINARY));
+ registerFunction("utf8tostring", new StandardSQLFunction("utf8tostring", Hibernate.STRING));
+
+ registerFunction("current_date", new NoArgSQLFunction("current_date", Hibernate.DATE));
+ registerFunction("current_time", new NoArgSQLFunction("current_time", Hibernate.TIME));
+ registerFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP));
+ registerFunction("datediff", new NoArgSQLFunction("datediff", Hibernate.INTEGER));
+ registerFunction("dayname", new StandardSQLFunction("dayname", Hibernate.STRING));
+ registerFunction("dayofmonth", new StandardSQLFunction("dayofmonth", Hibernate.INTEGER));
+ registerFunction("dayofweek", new StandardSQLFunction("dayofweek", Hibernate.INTEGER));
+ registerFunction("dayofyear", new StandardSQLFunction("dayofyear", Hibernate.INTEGER));
+// registerFunction("hour", new StandardSQLFunction("hour", Hibernate.INTEGER));
+// registerFunction("minute", new StandardSQLFunction("minute", Hibernate.INTEGER));
+// registerFunction("month", new StandardSQLFunction("month", Hibernate.INTEGER));
+ registerFunction("monthname", new StandardSQLFunction("monthname", Hibernate.STRING));
+ registerFunction("quater", new StandardSQLFunction("quater", Hibernate.INTEGER));
+// registerFunction("second", new StandardSQLFunction("second", Hibernate.INTEGER));
+ registerFunction("week", new StandardSQLFunction("week", Hibernate.INTEGER));
+// registerFunction("year", new StandardSQLFunction("year", Hibernate.INTEGER));
+
+ registerFunction("curdate", new NoArgSQLFunction("curdate", Hibernate.DATE));
+ registerFunction("curtime", new NoArgSQLFunction("curtime", Hibernate.TIME));
+ registerFunction("curtimestamp", new NoArgSQLFunction("curtimestamp", Hibernate.TIME));
+ registerFunction("now", new NoArgSQLFunction("now", Hibernate.TIMESTAMP));
+
+ registerFunction("database", new NoArgSQLFunction("database", Hibernate.STRING));
+ registerFunction("user", new NoArgSQLFunction("user", Hibernate.STRING));
+
+ getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
+
+ }
+
+ public String getAddColumnString() {
+ return "add column";
+ }
+
+ public boolean supportsIdentityColumns() {
+ return true;
+ }
+
+ public String getIdentityColumnString() {
+ return "generated by default as identity"; // not null is implicit
+ }
+
+ public String getIdentitySelectString() {
+ return "call identity()";
+ }
+
+ public String getIdentityInsertString() {
+ return "null";
+ }
+
+ public String getForUpdateString() {
+ return " for update";
+ }
+
+ public boolean supportsUnique() {
+ return true;
+ }
+
+ public boolean supportsLimit() {
+ return true;
+ }
+
+ public String getLimitString(String sql, boolean hasOffset) {
+ return new StringBuffer(sql.length() + 20).
+ append(sql).
+ append(hasOffset ? " limit ? offset ?" : " limit ?").
+ toString();
+ }
+
+ public boolean bindLimitParametersInReverseOrder() {
+ return true;
+ }
+
+ public boolean bindLimitParametersFirst() {
+ return false;
+ }
+
+ public boolean supportsIfExistsAfterTableName() {
+ return true;
+ }
+
+ public String[] getCreateSequenceStrings(String sequenceName) {
+ return new String[] {
+ "create sequence " + sequenceName
+ };
+ }
+
+ public String[] getDropSequenceStrings(String sequenceName) {
+ return new String[] {
+ "drop sequence " + sequenceName
+ };
+ }
+
+ public String getSelectSequenceNextValString(String sequenceName) {
+ return "next value for " + sequenceName;
+ }
+
+ public String getSequenceNextValString(String sequenceName) {
+ return "call next value for " + sequenceName;
+ }
+
+ public String getQuerySequencesString() {
+ return "select name from information_schema.sequences";
+ }
+
+ public boolean supportsSequences() {
+ return true;
+ }
+
+ public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
+ return EXTRACTER;
+ }
+
+ private static ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter() {
+
+ /**
+ * Extract the name of the violated constraint from the given SQLException.
+ *
+ * @param sqle The exception that was the result of the constraint violation.
+ * @return The extracted constraint name.
+ */
+ public String extractConstraintName(SQLException sqle) {
+ String constraintName = null;
+ // 23000: Check constraint violation: {0}
+ // 23001: Unique index or primary key violation: {0}
+ if(sqle.getSQLState().startsWith("23")) {
+ String message = sqle.getMessage();
+ int idx = message.indexOf("violation: ");
+ if(idx > 0) {
+ constraintName = message.substring(idx + "violation: ".length());
+ }
+ }
+ return constraintName;
+ }
+
+ };
+
+ public boolean supportsTemporaryTables() {
+ return true;
+ }
+
+ public String getCreateTemporaryTableString() {
+ return "create temporary table if not exists";
+ }
+
+ public boolean supportsCurrentTimestampSelection() {
+ return true;
+ }
+
+ public boolean isCurrentTimestampSelectStringCallable() {
+ return false;
+ }
+
+ public String getCurrentTimestampSelectString() {
+ return "call current_timestamp()";
+ }
+
+ public boolean supportsUnionAll() {
+ return true;
+ }
+
+}
\ No newline at end of file
|
|
From: <hib...@li...> - 2006-05-28 11:28:18
|
Author: max...@jb...
Date: 2006-05-28 07:28:13 -0400 (Sun, 28 May 2006)
New Revision: 9947
Modified:
trunk/Hibernate3/src/org/hibernate/persister/collection/AbstractCollectionPersister.java
Log:
alias names bug.
Modified: trunk/Hibernate3/src/org/hibernate/persister/collection/AbstractCollectionPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/collection/AbstractCollectionPersister.java 2006-05-28 09:46:07 UTC (rev 9946)
+++ trunk/Hibernate3/src/org/hibernate/persister/collection/AbstractCollectionPersister.java 2006-05-28 11:28:13 UTC (rev 9947)
@@ -1526,7 +1526,7 @@
for (int i = 0; i < propertyNames.length; i++) {
String name = propertyNames[i];
collectionPropertyColumnAliases.put( aliasName + "." + name, columnAliases[i] );
- collectionPropertyColumnAliases.put( aliasName + "." + name, columnNames[i] );
+ collectionPropertyColumnNames.put( aliasName + "." + name, columnNames[i] );
}
}
|
|
From: <hib...@li...> - 2006-05-28 09:46:20
|
Author: max...@jb... Date: 2006-05-28 05:46:07 -0400 (Sun, 28 May 2006) New Revision: 9946 Modified: trunk/HibernateExt/tools/src/templates/doc/index.html Log: html typo Modified: trunk/HibernateExt/tools/src/templates/doc/index.html =================================================================== --- trunk/HibernateExt/tools/src/templates/doc/index.html 2006-05-24 21:43:29 UTC (rev 9945) +++ trunk/HibernateExt/tools/src/templates/doc/index.html 2006-05-28 09:46:07 UTC (rev 9946) @@ -13,7 +13,6 @@ <FRAMESET rows="50px,80%"> <FRAME src="header.html" name="headerFrame" title="Header"> <FRAME src="tables/index.html" name="mainFrame" title="Main"> - </FRAMESET> <NOFRAMES> <H2>Frame Alert</H2> This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web browser. |
|
From: <hib...@li...> - 2006-05-24 21:44:03
|
Author: ste...@jb...
Date: 2006-05-24 17:43:29 -0400 (Wed, 24 May 2006)
New Revision: 9945
Modified:
trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java
trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
Log:
HHH-1779 : minor
Modified: trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-05-24 21:14:56 UTC (rev 9944)
+++ trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-05-24 21:43:29 UTC (rev 9945)
@@ -46,9 +46,7 @@
if ( log.isTraceEnabled() ) {
log.trace("cascading to delete: " + entityName);
}
-// if ( ForeignKeys.isNotTransient(entityName, child, null, session) ) {
- session.delete( entityName, child, isCascadeDeleteEnabled, ( Set ) anything );
-// }
+ session.delete( entityName, child, isCascadeDeleteEnabled, ( Set ) anything );
}
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
// delete does cascade to uninitialized collections
Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-05-24 21:14:56 UTC (rev 9944)
+++ trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-05-24 21:43:29 UTC (rev 9945)
@@ -56,29 +56,27 @@
final PersistenceContext persistenceContext = source.getPersistenceContext();
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
- EntityEntry entityEntry = persistenceContext.getEntry(entity);
-
+ EntityEntry entityEntry = persistenceContext.getEntry( entity );
final EntityPersister persister;
final Serializable id;
final Object version;
+
if ( entityEntry == null ) {
- log.trace( "deleting a detached instance" );
+ log.trace( "entity was not persistent in delete processing" );
persister = source.getEntityPersister( event.getEntityName(), entity );
+ if ( ForeignKeys.isTransient( persister.getEntityName(), entity, null, source ) ) {
+ deleteTransientEntity( source, entity, event.isCascadeDeleteEnabled(), persister, transientEntities );
+ // EARLY EXIT!!!
+ return;
+ }
+
id = persister.getIdentifier( entity, source.getEntityMode() );
if ( id == null ) {
-// throw new TransientObjectException(
-// "the detached instance passed to delete() had a null identifier"
-// );
- if ( ForeignKeys.isNotTransient( persister.getEntityName(), entity, null, source ) ) {
- throw new TransientObjectException( "the detached instance passed to delete() had a null identifier" );
- }
- else {
- deleteTransientEntity( source, entity, event.isCascadeDeleteEnabled(), persister, transientEntities );
- // EARLY EXIT!!!
- return;
- }
+ throw new TransientObjectException(
+ "the detached instance passed to delete() had a null identifier"
+ );
}
EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
|
Author: ste...@jb...
Date: 2006-05-24 17:14:56 -0400 (Wed, 24 May 2006)
New Revision: 9944
Added:
trunk/Hibernate3/test/org/hibernate/test/deletetransient/
trunk/Hibernate3/test/org/hibernate/test/deletetransient/Address.java
trunk/Hibernate3/test/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
trunk/Hibernate3/test/org/hibernate/test/deletetransient/Person.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/deletetransient/Person.java
Modified:
trunk/Hibernate3/src/org/hibernate/engine/BatchFetchQueue.java
trunk/Hibernate3/src/org/hibernate/engine/Cascade.java
trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java
trunk/Hibernate3/src/org/hibernate/event/DeleteEventListener.java
trunk/Hibernate3/src/org/hibernate/event/EventSource.java
trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
trunk/Hibernate3/src/org/hibernate/impl/IteratorImpl.java
trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java
Log:
HHH-1779 : delete() on transient entity per jpa spec;
HHH-1617 : BatchFetchQueue L2 cache peeking
Modified: trunk/Hibernate3/src/org/hibernate/engine/BatchFetchQueue.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/BatchFetchQueue.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/src/org/hibernate/engine/BatchFetchQueue.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -8,6 +8,7 @@
import org.apache.commons.collections.SequencedHashMap;
import org.hibernate.EntityMode;
+import org.hibernate.cache.CacheKey;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
@@ -17,27 +18,27 @@
* Tracks entity and collection keys that are available for batch
* fetching, and the queries which were used to load entities, which
* can be re-used as a subquery for loading owned collections.
- *
+ *
* @author Gavin King
*/
public class BatchFetchQueue {
public static final Object MARKER = new MarkerObject("MARKER");
-
+
// A set of entity keys that we predict we might need to load soon
// TODO: this would be better as a SequencedReferenceSet, but no such beast exists!
private final Map batchLoadableEntityKeys = new SequencedHashMap(8); //actually, a Set
-
+
// The subqueries that were used to load the entity with the given key
private final Map subselectsByEntityKey = new HashMap(8); //new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
-
+
// The owning persistence context
private final PersistenceContext context;
-
+
public BatchFetchQueue(PersistenceContext context) {
this.context = context;
}
-
+
public void clear() {
batchLoadableEntityKeys.clear();
subselectsByEntityKey.clear();
@@ -54,26 +55,26 @@
public void clearSubselects() {
subselectsByEntityKey.clear();
}
-
+
/**
- * After evicting or deleting or loading an entity, we don't
+ * After evicting or deleting or loading an entity, we don't
* need to batch fetch it anymore, remove it from the queue
* if necessary
*/
public void removeBatchLoadableEntityKey(EntityKey key) {
if ( key.isBatchLoadable() ) batchLoadableEntityKeys.remove(key);
}
-
+
/**
- * After evicting or deleting an entity, we don't need to
- * know the query that was used to load it anymore (don't
+ * After evicting or deleting an entity, we don't need to
+ * know the query that was used to load it anymore (don't
* call this after loading the entity, since we might still
* need to load its collections)
*/
public void removeSubselect(EntityKey key) {
subselectsByEntityKey.remove(key);
}
-
+
/**
* If an EntityKey represents a batch loadable entity, add
* it to the queue.
@@ -83,18 +84,18 @@
}
/**
- * Get a batch of uninitialized collection keys for this role
- * @param collectionPersister the collection role
- * @param id a key that must be included
+ * Get a batch of uninitialized collection keys for a given role
+ *
+ * @param collectionPersister The persister for the collection role.
+ * @param id A key that must be included in the batch fetch
* @param batchSize the maximum number of keys to return
* @return an array of collection keys, of length batchSize (padded with nulls)
*/
public Serializable[] getCollectionBatch(
- final CollectionPersister collectionPersister,
- final Serializable id,
+ final CollectionPersister collectionPersister,
+ final Serializable id,
final int batchSize,
- final EntityMode entityMode
- ) {
+ final EntityMode entityMode) {
Serializable[] keys = new Serializable[batchSize];
keys[0] = id;
int i = 1;
@@ -107,37 +108,41 @@
Iterator iter = context.getCollectionEntries().entrySet().iterator(); //TODO: calling entrySet on an IdentityMap is SLOW!!
while ( iter.hasNext() ) {
Map.Entry me = (Map.Entry) iter.next();
-
+
CollectionEntry ce = (CollectionEntry) me.getValue();
PersistentCollection collection = (PersistentCollection) me.getKey();
if ( !collection.wasInitialized() && ce.getLoadedPersister() == collectionPersister ) {
-
- if ( checkForEnd && i == end ) return keys; //the first key found after the given key
-
+
+ if ( checkForEnd && i == end ) {
+ return keys; //the first key found after the given key
+ }
+
//if ( end == -1 && count > batchSize*10 ) return keys; //try out ten batches, max
-
- final boolean isEqual = collectionPersister.getKeyType().isEqual(
- id,
- ce.getLoadedKey(),
- entityMode,
- collectionPersister.getFactory()
- );
-
+
+ final boolean isEqual = collectionPersister.getKeyType().isEqual(
+ id,
+ ce.getLoadedKey(),
+ entityMode,
+ collectionPersister.getFactory()
+ );
+
if ( isEqual ) {
end = i;
//checkForEnd = false;
}
- else {
+ else if ( !isCached( ce.getLoadedKey(), collectionPersister, entityMode ) ) {
keys[i++] = ce.getLoadedKey();
//count++;
}
-
+
if ( i == batchSize ) {
i = 1; //end of array, start filling again from start
- if (end!=-1) checkForEnd = true;
+ if ( end != -1 ) {
+ checkForEnd = true;
+ }
}
}
-
+
}
return keys; //we ran out of keys to try
}
@@ -146,52 +151,79 @@
* Get a batch of unloaded identifiers for this class, using a slightly
* complex algorithm that tries to grab keys registered immediately after
* the given key.
- *
- * @param entityName The name of the persistent class
- * @param id an identifier that must be included
- * @param batchSize the maximum number of keys to return
- * @return an array of identifiers, of length batchSize (padded with nulls)
+ *
+ * @param persister The persister for the entities being loaded.
+ * @param id The identifier of the entity currently demanding load.
+ * @param batchSize The maximum number of keys to return
+ * @return an array of identifiers, of length batchSize (possibly padded with nulls)
*/
public Serializable[] getEntityBatch(
- final EntityPersister persister,
- final Serializable id,
- final int batchSize,
- final EntityMode entityMode
- ) {
+ final EntityPersister persister,
+ final Serializable id,
+ final int batchSize,
+ final EntityMode entityMode) {
Serializable[] ids = new Serializable[batchSize];
ids[0] = id; //first element of array is reserved for the actual instance we are loading!
int i = 1;
int end = -1;
boolean checkForEnd = false;
- //int count = 0;
+
Iterator iter = batchLoadableEntityKeys.keySet().iterator();
while ( iter.hasNext() ) {
-
EntityKey key = (EntityKey) iter.next();
if ( key.getEntityName().equals( persister.getEntityName() ) ) { //TODO: this needn't exclude subclasses...
-
- if ( checkForEnd && i == end ) return ids; //the first id found after the given id
-
- //if ( end == -1 && count > batchSize*10 ) return ids; //try out ten batches, max
-
+ if ( checkForEnd && i == end ) {
+ //the first id found after the given id
+ return ids;
+ }
if ( persister.getIdentifierType().isEqual( id, key.getIdentifier(), entityMode ) ) {
end = i;
- //checkForEnd = false;
}
else {
- ids[i++] = key.getIdentifier();
- //count++;
+ if ( !isCached( key, persister, entityMode ) ) {
+ ids[i++] = key.getIdentifier();
+ }
}
-
if ( i == batchSize ) {
i = 1; //end of array, start filling again from start
if (end!=-1) checkForEnd = true;
}
-
}
-
}
return ids; //we ran out of ids to try
}
+ private boolean isCached(
+ EntityKey entityKey,
+ EntityPersister persister,
+ EntityMode entityMode) {
+ if ( persister.hasCache() ) {
+ CacheKey key = new CacheKey(
+ entityKey.getIdentifier(),
+ persister.getIdentifierType(),
+ entityKey.getEntityName(),
+ entityMode,
+ context.getSession().getFactory()
+ );
+ return persister.getCache().getCache().get( key ) != null;
+ }
+ return false;
+ }
+
+ private boolean isCached(
+ Serializable collectionKey,
+ CollectionPersister persister,
+ EntityMode entityMode) {
+ if ( persister.hasCache() ) {
+ CacheKey cacheKey = new CacheKey(
+ collectionKey,
+ persister.getKeyType(),
+ persister.getRole(),
+ entityMode,
+ context.getSession().getFactory()
+ );
+ return persister.getCache().getCache().get( cacheKey ) != null;
+ }
+ return false;
+ }
}
Modified: trunk/Hibernate3/src/org/hibernate/engine/Cascade.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/Cascade.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/src/org/hibernate/engine/Cascade.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -348,7 +348,7 @@
if ( log.isTraceEnabled() ) {
log.trace("deleting orphaned entity instance: " + entityName);
}
- eventSource.delete(entityName, orphan, false);
+ eventSource.delete( entityName, orphan, false, null );
}
}
Modified: trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/src/org/hibernate/engine/CascadingAction.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -3,6 +3,7 @@
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -42,10 +43,12 @@
public static final CascadingAction DELETE = new CascadingAction() {
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled)
throws HibernateException {
- if ( log.isTraceEnabled() ) log.trace("cascading to delete: " + entityName);
- if ( ForeignKeys.isNotTransient(entityName, child, null, session) ) {
- session.delete(entityName, child, isCascadeDeleteEnabled);
+ if ( log.isTraceEnabled() ) {
+ log.trace("cascading to delete: " + entityName);
}
+// if ( ForeignKeys.isNotTransient(entityName, child, null, session) ) {
+ session.delete( entityName, child, isCascadeDeleteEnabled, ( Set ) anything );
+// }
}
public Iterator getCascadableChildrenIterator(EventSource session, CollectionType collectionType, Object collection) {
// delete does cascade to uninitialized collections
Modified: trunk/Hibernate3/src/org/hibernate/event/DeleteEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/DeleteEventListener.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/src/org/hibernate/event/DeleteEventListener.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -4,6 +4,7 @@
import org.hibernate.HibernateException;
import java.io.Serializable;
+import java.util.Set;
/**
* Defines the contract for handling of deletion events generated from a session.
@@ -18,4 +19,6 @@
* @throws HibernateException
*/
public void onDelete(DeleteEvent event) throws HibernateException;
+
+ public void onDelete(DeleteEvent event, Set transientEntities) throws HibernateException;
}
Modified: trunk/Hibernate3/src/org/hibernate/event/EventSource.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/EventSource.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/src/org/hibernate/event/EventSource.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -3,6 +3,7 @@
import java.io.Serializable;
import java.util.Map;
+import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.Session;
@@ -57,6 +58,6 @@
/**
* Cascade delete an entity instance
*/
- public void delete(String entityName, Object child, boolean isCascadeDeleteEnabled);
+ public void delete(String entityName, Object child, boolean isCascadeDeleteEnabled, Set transientEntities);
}
Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -2,6 +2,7 @@
package org.hibernate.event.def;
import java.io.Serializable;
+import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -9,6 +10,7 @@
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.TransientObjectException;
+import org.hibernate.util.IdentitySet;
import org.hibernate.action.EntityDeleteAction;
import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.Cascade;
@@ -44,10 +46,16 @@
* @throws HibernateException
*/
public void onDelete(DeleteEvent event) throws HibernateException {
+ onDelete( event, new IdentitySet() );
+ }
+
+ public void onDelete(DeleteEvent event, Set transientEntities) throws HibernateException {
+
final EventSource source = event.getSession();
final PersistenceContext persistenceContext = source.getPersistenceContext();
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
+
EntityEntry entityEntry = persistenceContext.getEntry(entity);
final EntityPersister persister;
@@ -60,9 +68,17 @@
id = persister.getIdentifier( entity, source.getEntityMode() );
if ( id == null ) {
- throw new TransientObjectException(
- "the detached instance passed to delete() had a null identifier"
- );
+// throw new TransientObjectException(
+// "the detached instance passed to delete() had a null identifier"
+// );
+ if ( ForeignKeys.isNotTransient( persister.getEntityName(), entity, null, source ) ) {
+ throw new TransientObjectException( "the detached instance passed to delete() had a null identifier" );
+ }
+ else {
+ deleteTransientEntity( source, entity, event.isCascadeDeleteEnabled(), persister, transientEntities );
+ // EARLY EXIT!!!
+ return;
+ }
}
EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
@@ -107,25 +123,53 @@
if ( invokeDeleteLifecycle( source, entity, persister ) ) return;
- deleteEntity( source, entity, entityEntry, event.isCascadeDeleteEnabled(), persister );
+ deleteEntity( source, entity, entityEntry, event.isCascadeDeleteEnabled(), persister, transientEntities );
if ( source.getFactory().getSettings().isIdentifierRollbackEnabled() ) {
persister.resetIdentifier( entity, id, version, source.getEntityMode() );
}
-
}
+ /**
+ * We encountered a delete request on a transient instance.
+ * <p/>
+ * This is a deviation from historical Hibernate (pre-3.2) behavior to
+ * align with the JPA spec, which states that transient entities can be
+ * passed to remove operation in which case cascades still need to be
+ * performed.
+ *
+ * @param session The session which is the source of the event
+ * @param entity The entity being delete processed
+ * @param cascadeDeleteEnabled
+ * @param persister The entity persister
+ */
+ protected void deleteTransientEntity(
+ EventSource session,
+ Object entity,
+ boolean cascadeDeleteEnabled,
+ EntityPersister persister,
+ Set transientEntities) {
+ log.info( "handling transient entity in delete processing" );
+ if ( transientEntities.contains( entity ) ) {
+ log.trace( "already handled transient entity; skipping" );
+ return;
+ }
+ transientEntities.add( entity );
+ cascadeBeforeDelete( session, persister, entity, null, transientEntities );
+ cascadeAfterDelete( session, persister, entity, transientEntities );
+ }
+
protected final void deleteEntity(
final EventSource session,
final Object entity,
final EntityEntry entityEntry,
final boolean isCascadeDeleteEnabled,
- final EntityPersister persister)
- throws HibernateException {
+ final EntityPersister persister,
+ final Set transientEntities) throws HibernateException {
if ( log.isTraceEnabled() ) {
log.trace(
- "deleting " +
+ "deleting " +
MessageHelper.infoString( persister, entityEntry.getId(), session.getFactory() )
);
}
@@ -143,13 +187,13 @@
else {
currentState = entityEntry.getLoadedState();
}
-
+
final Object[] deletedState = new Object[propTypes.length];
- TypeFactory.deepCopy(
- currentState,
- propTypes,
- persister.getPropertyUpdateability(),
- deletedState,
+ TypeFactory.deepCopy(
+ currentState,
+ propTypes,
+ persister.getPropertyUpdateability(),
+ deletedState,
session
);
entityEntry.setDeletedState(deletedState);
@@ -166,7 +210,7 @@
persistenceContext.setEntryStatus(entityEntry, Status.DELETED);
EntityKey key = new EntityKey( entityEntry.getId(), persister, session.getEntityMode() );
- cascadeBeforeDelete(session, persister, entity, entityEntry);
+ cascadeBeforeDelete( session, persister, entity, entityEntry, transientEntities );
new ForeignKeys.Nullifier(entity, true, false, session)
.nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );
@@ -175,19 +219,19 @@
// Ensures that containing deletions happen before sub-deletions
session.getActionQueue().addAction(
- new EntityDeleteAction(
- entityEntry.getId(),
- deletedState,
- version,
- entity,
- persister,
- isCascadeDeleteEnabled,
- session
+ new EntityDeleteAction(
+ entityEntry.getId(),
+ deletedState,
+ version,
+ entity,
+ persister,
+ isCascadeDeleteEnabled,
+ session
)
);
-
- cascadeAfterDelete(session, persister, entity);
-
+
+ cascadeAfterDelete( session, persister, entity, transientEntities );
+
// the entry will be removed after the flush, and will no longer
// override the stale snapshot
// This is now handled by removeEntity() in EntityDeleteAction
@@ -210,15 +254,16 @@
EventSource session,
EntityPersister persister,
Object entity,
- EntityEntry entityEntry) throws HibernateException {
+ EntityEntry entityEntry,
+ Set transientEntities) throws HibernateException {
CacheMode cacheMode = session.getCacheMode();
session.setCacheMode(CacheMode.GET);
session.getPersistenceContext().incrementCascadeLevel();
try {
// cascade-delete to collections BEFORE the collection owner is deleted
- new Cascade(CascadingAction.DELETE, Cascade.AFTER_INSERT_BEFORE_DELETE, session)
- .cascade(persister, entity);
+ new Cascade( CascadingAction.DELETE, Cascade.AFTER_INSERT_BEFORE_DELETE, session )
+ .cascade( persister, entity, transientEntities );
}
finally {
session.getPersistenceContext().decrementCascadeLevel();
@@ -229,15 +274,16 @@
protected void cascadeAfterDelete(
EventSource session,
EntityPersister persister,
- Object entity) throws HibernateException {
+ Object entity,
+ Set transientEntities) throws HibernateException {
CacheMode cacheMode = session.getCacheMode();
session.setCacheMode(CacheMode.GET);
session.getPersistenceContext().incrementCascadeLevel();
try {
// cascade-delete to many-to-one AFTER the parent was deleted
- new Cascade(CascadingAction.DELETE, Cascade.BEFORE_INSERT_AFTER_DELETE, session)
- .cascade(persister, entity);
+ new Cascade( CascadingAction.DELETE, Cascade.BEFORE_INSERT_AFTER_DELETE, session )
+ .cascade( persister, entity, transientEntities );
}
finally {
session.getPersistenceContext().decrementCascadeLevel();
Modified: trunk/Hibernate3/src/org/hibernate/impl/IteratorImpl.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/impl/IteratorImpl.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/src/org/hibernate/impl/IteratorImpl.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -144,7 +144,8 @@
session.delete(
( (EntityType) types[0] ).getAssociatedEntityName(),
currentResult,
- false
+ false,
+ null
);
}
Modified: trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -756,8 +756,8 @@
/**
* Delete a persistent object
*/
- public void delete(String entityName, Object object, boolean isCascadeDeleteEnabled) throws HibernateException {
- fireDelete( new DeleteEvent(entityName, object, isCascadeDeleteEnabled, this) );
+ public void delete(String entityName, Object object, boolean isCascadeDeleteEnabled, Set transientEntities) throws HibernateException {
+ fireDelete( new DeleteEvent( entityName, object, isCascadeDeleteEnabled, this ), transientEntities );
}
private void fireDelete(DeleteEvent event) {
@@ -769,7 +769,16 @@
}
}
+ private void fireDelete(DeleteEvent event, Set transientEntities) {
+ errorIfClosed();
+ checkTransactionSynchStatus();
+ DeleteEventListener[] deleteEventListener = listeners.getDeleteEventListeners();
+ for ( int i = 0; i < deleteEventListener.length; i++ ) {
+ deleteEventListener[i].onDelete( event, transientEntities );
+ }
+ }
+
// load()/get() operations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void load(Object object, Serializable id) throws HibernateException {
Added: trunk/Hibernate3/test/org/hibernate/test/deletetransient/Address.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/deletetransient/Address.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/test/org/hibernate/test/deletetransient/Address.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -0,0 +1,34 @@
+package org.hibernate.test.deletetransient;
+
+/**
+ * todo: describe Address
+ *
+ * @author Steve Ebersole
+ */
+public class Address {
+ private Long id;
+ private String info;
+
+ public Address() {
+ }
+
+ public Address(String info) {
+ this.info = info;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getInfo() {
+ return info;
+ }
+
+ public void setInfo(String info) {
+ this.info = info;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/test/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -0,0 +1,101 @@
+package org.hibernate.test.deletetransient;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
+/**
+ * todo: describe DeleteTransientEntityTest
+ *
+ * @author Steve Ebersole
+ */
+public class DeleteTransientEntityTest extends TestCase {
+ public DeleteTransientEntityTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "deletetransient/Person.hbm.xml" };
+ }
+
+ public void testTransientEntityDeletionNoCascades() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ s.delete( new Address() );
+ t.commit();
+ s.close();
+ }
+
+ public void testTransientEntityDeletionCascadingToTransientAssociation() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ p.getAddresses().add( new Address() );
+ s.delete( p );
+ t.commit();
+ s.close();
+ }
+
+ public void testTransientEntityDeleteCascadingToCircularity() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p1 = new Person();
+ Person p2 = new Person();
+ p1.getFriends().add( p2 );
+ p2.getFriends().add( p1 );
+ s.delete( p1 );
+ t.commit();
+ s.close();
+ }
+
+ public void testTransientEntityDeletionCascadingToDetachedAssociation() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ s.save( address );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Person p = new Person();
+ p.getAddresses().add( address );
+ s.delete( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Long count = ( Long ) s.createQuery( "select count(*) from Address" ).list().get( 0 );
+ assertEquals( "delete not cascaded properly across transient entity", 0, count.longValue() );
+ t.commit();
+ s.close();
+ }
+
+ public void testTransientEntityDeletionCascadingToPersistentAssociation() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ s.save( address );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ address = ( Address ) s.get( Address.class, address.getId() );
+ Person p = new Person();
+ p.getAddresses().add( address );
+ s.delete( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Long count = ( Long ) s.createQuery( "select count(*) from Address" ).list().get( 0 );
+ assertEquals( "delete not cascaded properly across transient entity", 0, count.longValue() );
+ t.commit();
+ s.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/deletetransient/Person.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/deletetransient/Person.hbm.xml 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/test/org/hibernate/test/deletetransient/Person.hbm.xml 2006-05-24 21:14:56 UTC (rev 9944)
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+-->
+
+<hibernate-mapping package="org.hibernate.test.deletetransient">
+
+ <class name="Person" table="T_PERSON">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string"/>
+ <set name="addresses" lazy="true" inverse="false" cascade="all">
+ <key column="PERSON_ID"/>
+ <one-to-many class="Address"/>
+ </set>
+ <bag name="friends" lazy="true" inverse="false" cascade="all" table="T_FRIENDS">
+ <key column="FRIEND_ID_1"/>
+ <many-to-many class="Person" column="FRIEND_ID_2"/>
+ </bag>
+ </class>
+
+ <class name="Address" table="T_ADDRESS">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="info" type="string"/>
+ </class>
+
+</hibernate-mapping>
Added: trunk/Hibernate3/test/org/hibernate/test/deletetransient/Person.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/deletetransient/Person.java 2006-05-24 13:34:55 UTC (rev 9943)
+++ trunk/Hibernate3/test/org/hibernate/test/deletetransient/Person.java 2006-05-24 21:14:56 UTC (rev 9944)
@@ -0,0 +1,57 @@
+package org.hibernate.test.deletetransient;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ * todo: describe Person
+ *
+ * @author Steve Ebersole
+ */
+public class Person {
+ private Long id;
+ private String name;
+ private Set addresses = new HashSet();
+ private Collection friends = new ArrayList();
+
+ public Person() {
+ }
+
+ public Person(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set getAddresses() {
+ return addresses;
+ }
+
+ public void setAddresses(Set addresses) {
+ this.addresses = addresses;
+ }
+
+ public Collection getFriends() {
+ return friends;
+ }
+
+ public void setFriends(Collection friends) {
+ this.friends = friends;
+ }
+}
|
|
From: <hib...@li...> - 2006-05-24 14:06:28
|
Author: epbernard
Date: 2006-05-24 09:34:55 -0400 (Wed, 24 May 2006)
New Revision: 9943
Modified:
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/JarVisitor.java
Log:
EJB-182 support Websphere jars
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/JarVisitor.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/JarVisitor.java 2006-05-23 21:53:37 UTC (rev 9942)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/JarVisitor.java 2006-05-24 13:34:55 UTC (rev 9943)
@@ -52,11 +52,13 @@
file = file.substring( 0, file.length() - entry.length() );
if ( file.endsWith( "!" ) ) file = file.substring( 0, file.length() - 1 );
try {
- if ( "jar".equals( url.getProtocol() ) ) {
+ String protocol = url.getProtocol();
+ if ( "jar".equals( protocol )
+ || "wsjar".equals( protocol ) ) { //Websphere has it's own way
jarUrl = new URL( file );
}
else {
- jarUrl = new URL( url.getProtocol(), url.getHost(), url.getPort(), file );
+ jarUrl = new URL( protocol, url.getHost(), url.getPort(), file );
}
}
catch (MalformedURLException e) {
|
|
From: <hib...@li...> - 2006-05-23 21:53:42
|
Author: epbernard
Date: 2006-05-23 17:53:37 -0400 (Tue, 23 May 2006)
New Revision: 9942
Added:
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/Owner.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/OwnerAddress.java
Modified:
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/OneToOneTest.java
Log:
test on foreign and one to one
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/OneToOneTest.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/OneToOneTest.java 2006-05-22 18:28:53 UTC (rev 9941)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/OneToOneTest.java 2006-05-23 21:53:37 UTC (rev 9942)
@@ -223,6 +223,24 @@
s.close();
}
+ public void testForeignGenerator() {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ Owner owner = new Owner();
+ OwnerAddress address = new OwnerAddress();
+ owner.setAddress( address );
+ address.setOwner( owner );
+ s.persist( owner );
+ s.flush();
+ s.clear();
+ owner = (Owner) s.get( Owner.class, owner.getId() );
+ assertNotNull( owner );
+ assertNotNull( owner.getAddress() );
+ assertEquals( owner.getId(), owner.getAddress().getId() );
+ tx.rollback();
+ s.close();
+ }
+
/**
* @see org.hibernate.test.annotations.TestCase#getMappings()
*/
@@ -241,7 +259,9 @@
Computer.class,
SerialNumber.class,
Body.class,
- Heart.class
+ Heart.class,
+ Owner.class,
+ OwnerAddress.class
};
}
Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/Owner.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/Owner.java 2006-05-22 18:28:53 UTC (rev 9941)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/Owner.java 2006-05-23 21:53:37 UTC (rev 9942)
@@ -0,0 +1,35 @@
+//$Id: $
+package org.hibernate.test.annotations.onetoone;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.OneToOne;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.CascadeType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Owner {
+ @Id @GeneratedValue private Integer id;
+
+ @OneToOne(cascade = CascadeType.ALL) @PrimaryKeyJoinColumn private OwnerAddress address;
+
+ public OwnerAddress getAddress() {
+ return address;
+ }
+
+ public void setAddress(OwnerAddress address) {
+ this.address = address;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+}
Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/OwnerAddress.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/OwnerAddress.java 2006-05-22 18:28:53 UTC (rev 9941)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/onetoone/OwnerAddress.java 2006-05-23 21:53:37 UTC (rev 9942)
@@ -0,0 +1,39 @@
+//$Id: $
+package org.hibernate.test.annotations.onetoone;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.OneToOne;
+
+import org.hibernate.annotations.GenericGenerator;
+import org.hibernate.annotations.Parameter;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class OwnerAddress {
+ @Id @GeneratedValue(generator = "fk")
+ @GenericGenerator(strategy = "foreign", name = "fk", parameters = @Parameter(name="property", value="owner"))
+ private Integer id;
+
+ @OneToOne(mappedBy="address", optional = false)
+ private Owner owner;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Owner getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Owner owner) {
+ this.owner = owner;
+ }
+}
|
|
From: <hib...@li...> - 2006-05-22 18:28:58
|
Author: epbernard
Date: 2006-05-22 14:28:53 -0400 (Mon, 22 May 2006)
New Revision: 9941
Modified:
trunk/Hibernate3/src/org/hibernate/cfg/ImprovedNamingStrategy.java
Log:
HHH-1773 typo
Modified: trunk/Hibernate3/src/org/hibernate/cfg/ImprovedNamingStrategy.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cfg/ImprovedNamingStrategy.java 2006-05-21 14:51:17 UTC (rev 9940)
+++ trunk/Hibernate3/src/org/hibernate/cfg/ImprovedNamingStrategy.java 2006-05-22 18:28:53 UTC (rev 9941)
@@ -81,7 +81,7 @@
String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName
) {
String header = propertyName != null ? StringHelper.unqualify( propertyName ) : propertyTableName;
- if (header == null) throw new AssertionFailure("NammingStrategy not properly filled");
+ if (header == null) throw new AssertionFailure("NamingStrategy not properly filled");
return columnName( header ); //+ "_" + referencedColumnName not used for backward compatibility
}
|
|
From: <hib...@li...> - 2006-05-21 14:51:22
|
Author: epbernard
Date: 2006-05-21 10:51:17 -0400 (Sun, 21 May 2006)
New Revision: 9940
Modified:
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
Log:
stupid fatal logs
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-19 15:04:02 UTC (rev 9939)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-21 14:51:17 UTC (rev 9940)
@@ -501,7 +501,6 @@
if ( result[1] ) {
filters[size - 1] = new JarVisitor.FileFilter( true ) {
public boolean accept(String javaElementName) {
- log.fatal( javaElementName + "O-:-O" + mappingFiles.contains( javaElementName ) );
return javaElementName.endsWith( "hbm.xml" )
|| javaElementName.endsWith( META_INF_ORM_XML )
|| mappingFiles.contains( javaElementName );
@@ -511,7 +510,6 @@
else {
filters[size - 1] = new JarVisitor.FileFilter( true ) {
public boolean accept(String javaElementName) {
- log.fatal( javaElementName + "O:O" + mappingFiles.contains( javaElementName ) );
return javaElementName.endsWith( META_INF_ORM_XML )
|| mappingFiles.contains( javaElementName );
}
|
|
From: <hib...@li...> - 2006-05-19 15:04:09
|
Author: max...@jb... Date: 2006-05-19 11:04:02 -0400 (Fri, 19 May 2006) New Revision: 9939 Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCompletionProposal.java Log: remove wrong comments Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCompletionProposal.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCompletionProposal.java 2006-05-19 14:44:38 UTC (rev 9938) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCompletionProposal.java 2006-05-19 15:04:02 UTC (rev 9939) @@ -16,38 +16,25 @@ protected static final int LAST_KIND = ALIAS_REF; /** - * Kind of completion request. + * kind of completion request. */ private int completionKind; /** - * Offset in original buffer where ICodeAssist.codeComplete() was - * requested. + * original cursorposition in the query */ private int completionLocation; /** - * Completion string; defaults to empty string. + * The actual completion. */ private String completion = ""; - /** - * Start position (inclusive) of source range in original buffer - * to be replaced by completion string; - * defaults to empty subrange at [0,0). - */ - private int replaceStart = 0; - - /** - * End position (exclusive) of source range in original buffer - * to be replaced by completion string; - * defaults to empty subrange at [0,0). - */ + private int replaceStart = 0; private int replaceEnd = 0; /** - * Relevance rating; positive; higher means better; - * defaults to minimum rating. + * Relevance rating */ private int relevance = 1; |
Author: max...@jb...
Date: 2006-05-19 10:44:38 -0400 (Fri, 19 May 2006)
New Revision: 9938
Added:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/AntlrSimpleHQLLexer.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/CompletionHelper.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/EntityNameReference.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLAnalyzer.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCodeAssist.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCompletionProposal.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/IHQLCodeAssist.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/IHQLCompletionRequestor.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/SimpleHQLLexer.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/SimpleLexerException.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/CompletionHelperTest.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/HQLCompletionProposalComparator.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/HqlAnalyzerTest.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Model.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ModelCompletionTest.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.hbm.xml
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Product.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ProductOwner.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ProductOwnerAddress.hbm.xml
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/ProductOwnerAddress.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Store.hbm.xml
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/Store.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/StoreCity.hbm.xml
trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/StoreCity.java
Log:
hql code completion api
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/AntlrSimpleHQLLexer.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/AntlrSimpleHQLLexer.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/AntlrSimpleHQLLexer.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,59 @@
+package org.hibernate.tool.ide.completion;
+
+import java.io.CharArrayReader;
+
+import org.hibernate.hql.antlr.HqlBaseLexer;
+
+import antlr.Token;
+import antlr.TokenStreamException;
+
+/**
+ * A lexer implemented on top of the Antlr grammer implemented in core.
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
+public class AntlrSimpleHQLLexer implements SimpleHQLLexer {
+
+ private HqlBaseLexer lexer;
+ private Token token;
+
+ public AntlrSimpleHQLLexer(char[] cs, int length) {
+ lexer = new HqlBaseLexer(new CharArrayReader(cs, 0, length)) {
+ public void newline() {
+ //super.newline();
+ }
+
+ public int getColumn() {
+ return super.getColumn()-1;
+ }
+
+
+ };
+ }
+
+ public int getTokenLength() {
+ if(token.getText()==null) {
+ return 0;
+ }
+ return token.getText().length();
+ }
+
+ public int getTokenOffset() {
+ return token.getColumn()-1;
+ }
+
+ public int nextTokenId() {
+ try {
+ token = lexer.nextToken();
+ if(token==null) {
+ System.out.println(token);
+ }
+ }
+ catch (TokenStreamException e) {
+ throw new SimpleLexerException(e);
+ }
+ return token.getType();
+ }
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/CompletionHelper.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/CompletionHelper.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/CompletionHelper.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,74 @@
+package org.hibernate.tool.ide.completion;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Helper class for completion.
+ * Package private, not to be used externally.
+ *
+ * @author leon, max...@jb...
+ */
+class CompletionHelper {
+
+ private CompletionHelper() {
+ }
+
+ public static String getCanonicalPath(List qts, String name) {
+ Map alias2Type = new HashMap();
+ for (Iterator iter = qts.iterator(); iter.hasNext();) {
+ EntityNameReference qt = (EntityNameReference) iter.next();
+ alias2Type.put(qt.getAlias(), qt.getEntityName());
+ }
+ if (qts.size() == 1) {
+ EntityNameReference visible = (EntityNameReference) qts.get(0);
+ String alias = visible.getAlias();
+ if (name.equals(alias)) {
+ return visible.getEntityName();
+ } else if (alias == null || alias.length() == 0 || alias.equals(visible.getEntityName())) {
+ return visible.getEntityName() + "/" + name;
+ }
+ }
+ return getCanonicalPath(new HashSet(), alias2Type, name);
+ }
+
+
+ private static String getCanonicalPath(Set resolved, Map alias2Type, String name) {
+ if (resolved.contains(name)) {
+ // To prevent a stack overflow
+ return name;
+ }
+ resolved.add(name);
+ String type = (String) alias2Type.get(name);
+ if (type != null) {
+ return name.equals(type) ? name : getCanonicalPath(resolved, alias2Type, type);
+ }
+ int idx = name.lastIndexOf('.');
+ if (idx == -1) {
+ return type != null ? type : name;
+ }
+ String baseName = name.substring(0, idx);
+ String prop = name.substring(idx + 1);
+ if (isAliasNown(alias2Type, baseName)) {
+ return getCanonicalPath(resolved, alias2Type, baseName) + "/" + prop;
+ } else {
+ return name;
+ }
+ }
+
+ private static boolean isAliasNown(Map alias2Type, String alias) {
+ if (alias2Type.containsKey(alias)) {
+ return true;
+ }
+ int idx = alias.lastIndexOf('.');
+ if (idx == -1) {
+ return false;
+ }
+ return isAliasNown(alias2Type, alias.substring(0, idx));
+ }
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/ConfigurationCompletion.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,341 @@
+package org.hibernate.tool.ide.completion;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.OneToMany;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.ToOne;
+import org.hibernate.mapping.Value;
+import org.hibernate.tool.hbm2x.Cfg2JavaTool;
+import org.hibernate.tool.hbm2x.pojo.EntityPOJOClass;
+
+/**
+ * Completion based on a Configuration.
+ * package protected for now - not meant to be used externally.
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
+class ConfigurationCompletion {
+
+ private final Configuration cfg;
+
+ public ConfigurationCompletion(Configuration cfg) {
+ this.cfg = cfg;
+
+ }
+
+ public void getMatchingImports(String prefix , IHQLCompletionRequestor collector) {
+ getMatchingImports( prefix, prefix.length() , collector );
+ }
+
+ public void getMatchingImports(String prefix, int cursorPosition, IHQLCompletionRequestor collector) {
+ Iterator iterator = cfg.getImports().entrySet().iterator();
+ while ( iterator.hasNext() ) {
+ Map.Entry entry = (Entry) iterator.next();
+ String entityImport = (String) entry.getKey();
+ String entityName = (String) entry.getValue();
+
+ if(entityImport.startsWith(prefix)) {
+ String remaining = entityImport.substring( prefix.length() );
+ HQLCompletionProposal proposal = new HQLCompletionProposal(
+ HQLCompletionProposal.ENTITY_NAME,
+ cursorPosition);
+ proposal.setCompletion( remaining );
+ proposal.setSimpleName( entityImport );
+ proposal.setReplaceStart( cursorPosition );
+ proposal.setReplaceEnd( cursorPosition+0 ); // we don't replace anything here
+
+ proposal.setShortEntityName( entityImport );
+ proposal.setEntityName( entityName );
+ collector.accept(proposal);
+
+ }
+ }
+ }
+
+ public void getMatchingKeywords(String prefix, int cursorPosition, IHQLCompletionRequestor collector) {
+ findMatchingWords( cursorPosition, prefix, HQLAnalyzer.getHQLKeywords(), HQLCompletionProposal.KEYWORD, collector);
+ }
+
+ public void getMatchingFunctions(String prefix, int cursorPosition, IHQLCompletionRequestor collector) {
+ findMatchingWords( cursorPosition, prefix, HQLAnalyzer.getHQLFunctionNames(), HQLCompletionProposal.FUNCTION, collector);
+ }
+
+ public void getMatchingProperties(String path, String prefix, IHQLCompletionRequestor hcc) {
+ getMatchingProperties( path, prefix, prefix.length(), hcc );
+ }
+
+ public void getMatchingProperties(String path, String prefix, int cursorPosition, IHQLCompletionRequestor hcc) {
+ int idx = path.indexOf('/');
+ if (idx == -1) { // root name
+ PersistentClass cmd = getPersistentClass(path);
+ if (cmd == null) {
+ return;
+ }
+ addPropertiesToList(cmd, prefix, cursorPosition, hcc);
+ } else {
+ String baseEntityName = path.substring(0, idx);
+ String propertyPath = path.substring(idx + 1);
+ Value value = getNextAttributeType(baseEntityName, propertyPath);
+ if (value == null) {
+ return;
+ }
+
+ // Go to the next property (get the y of x/y/z when root is x)
+ idx = propertyPath.indexOf('/');
+ if (idx == -1) {
+ path = "";
+ } else {
+ path = propertyPath.substring(idx + 1);
+ }
+ if (path.length() == 0) {
+ // No properties left
+ if (value instanceof Component) {
+ addPropertiesToList((Component) value, prefix, cursorPosition, hcc);
+ } else {
+ addPropertiesToList(getPersistentClass( getReferencedEntityName( value ) ), prefix, cursorPosition, hcc);
+ }
+ } else {
+ // Nested properties
+ if (value instanceof Component) {
+ // We need to find the first non-component type
+ while (value instanceof Component && path.length() > 0) {
+ value = getNextAttributeType((Component) value, path);
+ if (value != null) {
+ // Consume part of the canonical path
+ idx = path.indexOf('/');
+ if (idx != -1) {
+ path = path.substring(idx + 1);
+ } else {
+ path = "";
+ }
+ }
+ }
+ if (value instanceof Component) {
+ addPropertiesToList((Component) value, prefix, cursorPosition, hcc);
+ } else if (value != null) {
+ if (path.length() > 0) {
+ path = getReferencedEntityName( value ) + "/" + path;
+ } else {
+ path = getReferencedEntityName( value );
+ }
+ getMatchingProperties( path, prefix, cursorPosition, hcc );
+ }
+ } else {
+ // Just call the method recursively to add our new type
+ getMatchingProperties(getReferencedEntityName( value ) + "/" + path, prefix, cursorPosition, hcc);
+ }
+ }
+ }
+ }
+
+ private String getReferencedEntityName(Value value) {
+ if(value instanceof ToOne) {
+ return ((ToOne)value).getReferencedEntityName();
+ }
+ if ( value instanceof Collection ) {
+ Collection collection = ((Collection)value);
+ Value element = collection.getElement();
+ String elementType = getReferencedEntityName( element );
+ if(collection.isIndexed()) {
+ //TODO..list/map
+ /*IndexedCollection idxCol = (IndexedCollection) collection;
+ if(!idxCol.isList()) {
+ Value idxElement = idxCol.getIndex();
+ String indexType = getReferencedEntityName( value );
+ genericDecl = indexType + "," + elementType;
+ }*/
+ }
+ return elementType;
+ }
+
+ if(value instanceof OneToMany) {
+ return ((OneToMany)value).getReferencedEntityName();
+ }
+
+ return null;
+ }
+
+ private void addPropertiesToList(PersistentClass cmd, String prefix, int cursorPosition, IHQLCompletionRequestor hcc) {
+ if (cmd == null) {
+ return;
+ }
+ if (prefix == null) {
+ prefix = "";
+ }
+
+ EntityPOJOClass pc = new EntityPOJOClass(cmd, new Cfg2JavaTool()); // TODO: we should extract the needed functionallity from this hbm2java class.
+
+ Iterator allPropertiesIterator = pc.getAllPropertiesIterator();
+ while ( allPropertiesIterator.hasNext() ) {
+ Property property = (Property) allPropertiesIterator.next();
+ String candidate = property.getName();
+ if (prefix.length() == 0 || candidate.startsWith(prefix)) {
+ HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, HQLCompletionProposal.PROPERTY, candidate );
+ proposal.setEntityName( cmd.getEntityName() );
+ proposal.setPropertyName( candidate );
+ hcc.accept( proposal);
+ }
+ }
+ }
+
+ private HQLCompletionProposal createStartWithCompletionProposal(String prefix, int cursorPosition, int kind, String candidate) {
+ HQLCompletionProposal proposal = new HQLCompletionProposal(kind, cursorPosition);
+ proposal.setCompletion( candidate.substring( prefix.length() ) );
+ proposal.setSimpleName( candidate );
+ proposal.setReplaceEnd( cursorPosition );
+ proposal.setReplaceStart( cursorPosition );
+ return proposal;
+ }
+
+ /** returns PersistentClass for path. Can be null if path is an imported non-mapped class */
+ private PersistentClass getPersistentClass(String path) {
+ if(path==null) return null;
+ String entityName = (String) cfg.getImports().get( path );
+ if(entityName==null) {
+ return null;
+ } else {
+ return cfg.getClassMapping( entityName );
+ }
+ }
+
+ public String getCanonicalPath(List qts, String name) {
+ Map alias2Type = new HashMap();
+ for (Iterator iter = qts.iterator(); iter.hasNext();) {
+ EntityNameReference qt = (EntityNameReference) iter.next();
+ alias2Type.put(qt.getAlias(), qt.getEntityName());
+ }
+ if (qts.size() == 1) {
+ EntityNameReference visible = (EntityNameReference) qts.get(0);
+ String alias = visible.getAlias();
+ if (name.equals(alias)) {
+ return visible.getEntityName();
+ } else if (alias == null || alias.length() == 0 || alias.equals(visible.getEntityName())) {
+ return visible.getEntityName() + "/" + name;
+ }
+ }
+ return getCanonicalPath(new HashSet(), alias2Type, name);
+ }
+
+ private String getCanonicalPath(Set resolved, Map alias2Type, String name) {
+ if (resolved.contains(name)) {
+ // To prevent a stack overflow
+ return name;
+ }
+ resolved.add(name);
+ String type = (String) alias2Type.get(name);
+ if (type != null) {
+ return name.equals(type) ? name : getCanonicalPath(resolved, alias2Type, type);
+ }
+ int idx = name.lastIndexOf('.');
+ if (idx == -1) {
+ return type != null ? type : name;
+ }
+ String baseName = name.substring(0, idx);
+ String prop = name.substring(idx + 1);
+ if (isAliasKnown(alias2Type, baseName)) {
+ return getCanonicalPath(resolved, alias2Type, baseName) + "/" + prop;
+ } else {
+ return name;
+ }
+ }
+
+ private static boolean isAliasKnown(Map alias2Type, String alias) {
+ if (alias2Type.containsKey(alias)) {
+ return true;
+ }
+ int idx = alias.lastIndexOf('.');
+ if (idx == -1) {
+ return false;
+ }
+ return isAliasKnown(alias2Type, alias.substring(0, idx));
+ }
+
+ private Value getNextAttributeType(String type, String attributePath) {
+ PersistentClass cmd = getPersistentClass( type );
+ if (cmd == null) {
+ return null;
+ }
+ String attribute;
+ int idx = attributePath.indexOf('/');
+ if (idx == -1) {
+ attribute = attributePath;
+ } else {
+ attribute = attributePath.substring(0, idx);
+ }
+
+ String idName = cmd.getIdentifierProperty()==null?null:cmd.getIdentifierProperty().getName();
+ if (attribute.equals(idName)) {
+ return cmd.getIdentifierProperty().getValue();
+ }
+ Property property = cmd.getProperty( attribute );
+ return property==null?null:property.getValue();
+ }
+
+ private Value getNextAttributeType(Component t, String attributeName) {
+ int idx = attributeName.indexOf('/');
+ if (idx != -1) {
+ attributeName = attributeName.substring(0, idx);
+ }
+ Iterator names = t.getPropertyIterator();
+ int i = 0;
+ while ( names.hasNext() ) {
+ Property element = (Property) names.next();
+ String name = element.getName();
+ if (attributeName.equals(name)) {
+ return element.getValue();
+ }
+ i++;
+ }
+ return null;
+ }
+
+ void addPropertiesToList(Component t, String prefix, int cursorPosition, IHQLCompletionRequestor hcc) {
+ if (t == null) {
+ return;
+ }
+ Iterator props = t.getPropertyIterator();
+ int i = 0;
+ while ( props.hasNext() ) {
+ Property element = (Property) props.next();
+ String candidate = element.getName();
+ if (candidate.startsWith(prefix)) {
+ HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, HQLCompletionProposal.PROPERTY, candidate );
+ //proposal.setEntityName( cmd.getEntityName() ); ...we don't know here..TODO: pass in the "path"
+ proposal.setPropertyName( candidate );
+ hcc.accept( proposal);
+ }
+ i++;
+ }
+ }
+
+ private void findMatchingWords(int cursorPosition, String prefix, String[] words, int kind, IHQLCompletionRequestor hcc) {
+ int i = Arrays.binarySearch(words, prefix);
+ if(i<0) {
+ i = Math.abs(i+1);
+ }
+
+ for (int cnt = i; cnt < words.length; cnt++) {
+ String word = words[cnt];
+ if(word.startsWith(prefix)) {
+ HQLCompletionProposal proposal = createStartWithCompletionProposal( prefix, cursorPosition, kind, word );
+ hcc.accept( proposal);
+ } else {
+ break;
+ }
+ }
+ }
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/EntityNameReference.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/EntityNameReference.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/EntityNameReference.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,43 @@
+package org.hibernate.tool.ide.completion;
+
+/**
+ * Class that represents an alias to some entityname in a HQL statement. e.g. "Product as p" or "Product p"
+ *
+ * Should not be used by external clients.
+ *
+ * @author leon, Max Rydahl Andersen
+ */
+public class EntityNameReference {
+
+ private String alias;
+
+ private String entityName;
+
+ public EntityNameReference(String type, String alias) {
+ this.entityName = type;
+ this.alias = alias;
+ }
+
+ /**
+ *
+ * @return The alias, the "p" in "Product as p"
+ */
+ public String getAlias() {
+ return alias;
+ }
+
+ /**
+ *
+ * @return the entityname, the "Product" in "Product as b"
+ */
+ public String getEntityName() {
+ return entityName;
+ }
+
+ public String toString() {
+ return alias + ":" + entityName;
+ }
+
+
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLAnalyzer.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLAnalyzer.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLAnalyzer.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,388 @@
+package org.hibernate.tool.ide.completion;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.hibernate.hql.antlr.HqlSqlTokenTypes;
+
+/**
+ * The HQLAnalyzer can answer certain questions about a HQL String.
+ *
+ * @author leon, max...@jb...
+ */
+public class HQLAnalyzer {
+
+ /** Defines the HQL keywords. Based on hql.g antlr grammer in 2005 ;) */
+ private static String[] hqlKeywords = { "between", "class", "delete",
+ "desc", "distinct", "elements", "escape", "exists", "false",
+ "fetch", "from", "full", "group", "having", "in", "indices",
+ "inner", "insert", "into", "is", "join", "left", "like", "new",
+ "not", "null", "or", "order", "outer", "properties", "right",
+ "select", "set", "some", "true", "union", "update", "versioned",
+ "where", "and", "or", "as","on", "with",
+
+ // -- SQL tokens --
+ // These aren't part of HQL, but recognized by the lexer. Could be
+ // usefull for having SQL in the editor..but for now we keep them out
+ // "case", "end", "else", "then", "when",
+
+
+ // -- EJBQL tokens --
+ "both", "empty", "leading", "member", "object", "of", "trailing",
+ };
+
+
+ /**
+ * built-in function names. Various normal builtin functions in SQL/HQL.
+ * Maybe sShould try and do this dynamically based on dialect or
+ * sqlfunctionregistry
+ */
+ private static String[] builtInFunctions = {
+ // standard sql92 functions
+ "substring", "locate", "trim", "length", "bit_length", "coalesce",
+ "nullif", "abs", "mod", "sqrt",
+ "upper",
+ "lower",
+ "cast",
+ "extract",
+
+ // time functions mapped to ansi extract
+ "second", "minute", "hour", "day",
+ "month",
+ "year",
+
+ "str",
+
+ // misc functions - based on oracle dialect
+ "sign", "acos", "asin", "atan", "cos", "cosh", "exp", "ln", "sin",
+ "sinh", "stddev", "sqrt", "tan", "tanh", "variance",
+
+ "round", "trunc", "ceil", "floor",
+
+ "chr", "initcap", "lower", "ltrim", "rtrim", "soundex", "upper",
+ "ascii", "length", "to_char", "to_date",
+
+ "current_date", "current_time", "current_timestamp", "lastday",
+ "sysday", "systimestamp", "uid", "user",
+
+ "rowid", "rownum",
+
+ "concat", "instr", "instrb", "lpad", "replace", "rpad", "substr",
+ "substrb", "translate",
+
+ "substring", "locate", "bit_length", "coalesce",
+
+ "atan2", "log", "mod", "nvl", "nvl2", "power",
+
+ "add_months", "months_between", "next_day",
+
+ "max", "min", };
+
+ static {
+ // to allow binary search
+ Arrays.sort(builtInFunctions);
+ Arrays.sort(hqlKeywords);
+ }
+
+ protected SimpleHQLLexer getLexer(char chars[], int end) {
+ return new AntlrSimpleHQLLexer(chars,end);
+ }
+
+ protected SimpleHQLLexer getLexer(char chars[]) {
+ return new AntlrSimpleHQLLexer(chars,chars.length);
+ }
+
+ /**
+ * Returns true if the position is at a location where an entityname makes sense.
+ * e.g. "from Pr| where x"
+ * @param query
+ * @param cursorPosition
+ * @return
+ */
+ public boolean shouldShowEntityNames(String query, int cursorPosition) {
+ return shouldShowEntityNames( query.toCharArray(), cursorPosition );
+ }
+
+ public boolean shouldShowEntityNames(char chars[], int cursorPosition) {
+ SimpleHQLLexer lexer = getLexer( chars, cursorPosition );
+ int tokenId = -1;
+ boolean show = false;
+ while ((tokenId = lexer.nextTokenId()) != HqlSqlTokenTypes.EOF) {
+ if ((tokenId == HqlSqlTokenTypes.FROM ||
+ tokenId == HqlSqlTokenTypes.DELETE ||
+ tokenId == HqlSqlTokenTypes.UPDATE) &&
+ (lexer.getTokenOffset() + lexer.getTokenLength()) < cursorPosition) {
+ show = true;
+ } else if (tokenId != HqlSqlTokenTypes.DOT && tokenId != HqlSqlTokenTypes.AS && tokenId != HqlSqlTokenTypes.COMMA && tokenId != HqlSqlTokenTypes.IDENT && tokenId != HqlSqlTokenTypes.WS) {
+ show = false;
+ }
+ }
+ return show;
+ }
+
+ public List getVisibleSubQueries(char[] chars, int position) {
+ SubQueryList sqList = getSubQueries(chars, position);
+ List visible = new ArrayList();
+ for (Iterator iter = sqList.subQueries.iterator(); iter.hasNext();) {
+ SubQuery sq = (SubQuery) iter.next();
+ if (sqList.caretDepth >= sq.depth && (sq.startOffset <= position || sq.endOffset >= position)) {
+ visible.add(sq);
+ }
+ }
+ return visible;
+ }
+
+ public List getVisibleEntityNames(char[] chars, int position) {
+ List sqs = getVisibleSubQueries(chars, position);
+ List entityReferences = new ArrayList();
+ for (Iterator iter = sqs.iterator(); iter.hasNext();) {
+ SubQuery sq = (SubQuery) iter.next();
+ entityReferences.addAll(sq.getEntityNames());
+ }
+ return entityReferences;
+ }
+
+ protected SubQueryList getSubQueries(char[] query, int position) {
+ SimpleHQLLexer syntax = getLexer( query );
+ int numericId = -1;
+ List subQueries = new ArrayList();
+ int depth = 0;
+ int caretDepth = 0;
+ Map level2SubQuery = new HashMap();
+ SubQuery current = null;
+ while ((numericId = syntax.nextTokenId()) != HqlSqlTokenTypes.EOF) {
+ boolean tokenAdded = false;
+ if (numericId == HqlSqlTokenTypes.OPEN) {
+ depth++;
+ if (position > syntax.getTokenOffset()) {
+ caretDepth = depth;
+ }
+ } else if (numericId == HqlSqlTokenTypes.CLOSE) {
+ SubQuery currentDepthQuery = (SubQuery) level2SubQuery.get(new Integer(depth));
+ // We check if we have a query on the current depth.
+ // If yes, we'll have to close it
+ if (currentDepthQuery != null && currentDepthQuery.depth == depth) {
+ currentDepthQuery.endOffset = syntax.getTokenOffset();
+ currentDepthQuery.tokenIds.add(new Integer(numericId));
+ currentDepthQuery.tokenText.add(String.valueOf(query, syntax.getTokenOffset(), syntax.getTokenLength()));
+ subQueries.add(currentDepthQuery);
+ level2SubQuery.remove(new Integer(depth));
+ tokenAdded = true;
+ }
+ depth--;
+ if (position > syntax.getTokenOffset()) {
+ caretDepth = depth;
+ }
+ }
+ switch (numericId) {
+ case HqlSqlTokenTypes.FROM:
+ case HqlSqlTokenTypes.UPDATE:
+ case HqlSqlTokenTypes.DELETE:
+ case HqlSqlTokenTypes.SELECT:
+ if (!level2SubQuery.containsKey(new Integer(depth))) {
+ current = new SubQuery();
+ current.depth = depth;
+ current.startOffset = syntax.getTokenOffset();
+ level2SubQuery.put(new Integer(depth), current);
+ }
+ current.tokenIds.add(new Integer(numericId));
+ current.tokenText.add(String.valueOf(query, syntax.getTokenOffset(), syntax.getTokenLength()));
+ break;
+ default:
+ if (!tokenAdded) {
+ SubQuery sq = (SubQuery) level2SubQuery.get(new Integer(depth));
+ int i = depth;
+ while (sq == null && i >= 0) {
+ sq = (SubQuery) level2SubQuery.get(new Integer(i--));
+ }
+ if (sq != null) {
+ sq.tokenIds.add(new Integer(numericId));
+ sq.tokenText.add(String.valueOf(query, syntax.getTokenOffset(), syntax.getTokenLength()));
+ }
+ }
+ }
+ }
+ for (Iterator iter = level2SubQuery.values().iterator(); iter.hasNext();) {
+ SubQuery sq = (SubQuery) iter.next();
+ sq.endOffset = syntax.getTokenOffset() + syntax.getTokenLength();
+ subQueries.add(sq);
+ }
+ Collections.sort(subQueries);
+ SubQueryList sql = new SubQueryList();
+ sql.caretDepth = caretDepth;
+ sql.subQueries = subQueries;
+ return sql;
+ }
+
+
+ /** Returns reference name found from position and backwards in the array.
+ **/
+ public static String getEntityNamePrefix(char[] chars, int position) {
+ StringBuffer buff = new StringBuffer();
+ for (int i = position - 1; i >= 0; i--) {
+ char c = chars[i];
+ if (c == '.' || Character.isJavaIdentifierPart(c)) {
+ buff.insert(0, c);
+ } else {
+ break;
+ }
+ }
+ return buff.toString();
+ }
+
+ public static class SubQuery implements Comparable {
+
+ public int compareTo(Object s) {
+ return startOffset - ((SubQuery)s).startOffset;
+ }
+
+ private List tokenIds = new ArrayList();
+
+ private List tokenText = new ArrayList();
+
+ private int startOffset;
+
+ private int endOffset;
+
+ private int depth;
+
+ public int getTokenCount() {
+ return tokenIds.size();
+ }
+
+ public int getToken(int i) {
+ return ((Number)tokenIds.get(i)).intValue();
+ }
+
+ public String getTokenText(int i) {
+ return (String) tokenText.get(i);
+ }
+
+ public List getEntityNames() {
+ boolean afterFrom = false;
+ boolean afterJoin = false;
+ StringBuffer tableNames = new StringBuffer();
+ StringBuffer joins = new StringBuffer();
+ int i = 0;
+ boolean cont = true;
+ int lastToken = HqlSqlTokenTypes.EOF;
+ for (Iterator iter = tokenIds.iterator(); iter.hasNext();) {
+ Integer typeInteger = (Integer) iter.next();
+ int type = typeInteger.intValue();
+ if (!cont) {
+ break;
+ }
+ if (!afterFrom &&
+ (type == HqlSqlTokenTypes.FROM ||
+ type == HqlSqlTokenTypes.UPDATE ||
+ type == HqlSqlTokenTypes.DELETE)) {
+ afterFrom = true;
+ } else if (afterJoin) {
+ switch (type) {
+ case HqlSqlTokenTypes.ORDER:
+ case HqlSqlTokenTypes.WHERE:
+ case HqlSqlTokenTypes.GROUP:
+ case HqlSqlTokenTypes.HAVING:
+ cont = false;
+ break;
+ case HqlSqlTokenTypes.INNER:
+ case HqlSqlTokenTypes.OUTER:
+ case HqlSqlTokenTypes.LEFT:
+ case HqlSqlTokenTypes.RIGHT:
+ case HqlSqlTokenTypes.JOIN:
+ joins.append(",");
+ break;
+ case HqlSqlTokenTypes.COMMA:
+ joins.append(","); //TODO: we should detect this and create the list directly instead of relying on the tokenizer
+ break;
+ case HqlSqlTokenTypes.DOT:
+ joins.append(".");
+ break;
+ case HqlSqlTokenTypes.IDENT:
+ if(lastToken!=HqlSqlTokenTypes.DOT) {
+ joins.append(" ");
+ }
+ joins.append(tokenText.get(i));
+ break;
+ }
+ } else if (afterFrom) {
+ switch (type) {
+ case HqlSqlTokenTypes.ORDER:
+ case HqlSqlTokenTypes.WHERE:
+ case HqlSqlTokenTypes.GROUP:
+ case HqlSqlTokenTypes.HAVING:
+ case HqlSqlTokenTypes.SET:
+ cont = false;
+ break;
+ case HqlSqlTokenTypes.COMMA:
+ tableNames.append(","); //TODO: we should detect this and create the list directly instead of relying on the tokenizer
+ break;
+ case HqlSqlTokenTypes.DOT:
+ tableNames.append(".");
+ break;
+ case HqlSqlTokenTypes.IDENT:
+ if(lastToken!=HqlSqlTokenTypes.DOT) {
+ tableNames.append(" ");
+ }
+ tableNames.append(tokenText.get(i));
+ break;
+ case HqlSqlTokenTypes.JOIN:
+ tableNames.append(",");
+ afterJoin = true;
+ break;
+ default:
+ break;
+ }
+ }
+ i++;
+ lastToken = type;
+ }
+ List tables = new ArrayList();
+ addEntityReferences(tables, tableNames);
+ addEntityReferences(tables, joins);
+ return tables;
+ }
+
+ private void addEntityReferences(final List tables, final StringBuffer tableNames) {
+ StringTokenizer tableTokenizer = new StringTokenizer(tableNames.toString(), ",");
+ while (tableTokenizer.hasMoreTokens()) {
+ String table = tableTokenizer.nextToken().trim();
+ if (table.indexOf(' ') == -1 && table.length() > 0) {
+ tables.add(new EntityNameReference(table, table));
+ } else {
+ StringTokenizer aliasTokenizer = new StringTokenizer(table, " ");
+ if (aliasTokenizer.countTokens() >= 2) {
+ String type = aliasTokenizer.nextToken().trim();
+ String alias = aliasTokenizer.nextToken().trim();
+ if (type.length() > 0 && alias.length() > 0) {
+ tables.add(new EntityNameReference(type, alias));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ static class SubQueryList {
+
+ int caretDepth;
+
+ List subQueries;
+ }
+
+
+ static String[] getHQLKeywords() {
+ return hqlKeywords;
+ }
+
+ static String[] getHQLFunctionNames() {
+ return builtInFunctions;
+ }
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCodeAssist.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCodeAssist.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCodeAssist.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,103 @@
+package org.hibernate.tool.ide.completion;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.cfg.Configuration;
+
+public class HQLCodeAssist implements IHQLCodeAssist {
+
+ private Configuration configuration;
+ private ConfigurationCompletion completion;
+
+ public HQLCodeAssist(Configuration configuration) {
+ this.configuration = configuration;
+ completion = new ConfigurationCompletion(configuration);
+ }
+
+ public void codeComplete(String query, int position, IHQLCompletionRequestor collector) {
+
+ int prefixStart = findNearestWhiteSpace(query, position);
+ String prefix = query.substring( prefixStart, position );
+
+ boolean showEntityNames;
+ try {
+ showEntityNames = new HQLAnalyzer().shouldShowEntityNames( query, position );
+
+ if(showEntityNames) {
+ if(hasConfiguration()) {
+ completion.getMatchingImports( prefix, position, collector );
+ } else {
+ collector.completionFailure("Configuration not available nor open");
+ }
+ } else {
+ List visible = new HQLAnalyzer().getVisibleEntityNames( query.toCharArray(), position );
+ int dotIndex = prefix.lastIndexOf(".");
+ if (dotIndex == -1) {
+ // It's a simple path, not a dot separated one (find aliases that matches)
+ for (Iterator iter = visible.iterator(); iter.hasNext();) {
+ EntityNameReference qt = (EntityNameReference) iter.next();
+ String alias = qt.getAlias();
+ if (alias.startsWith(prefix)) {
+ HQLCompletionProposal completionProposal = new HQLCompletionProposal(HQLCompletionProposal.ALIAS_REF, position);
+ completionProposal.setCompletion( alias.substring( prefix.length() ) );
+ completionProposal.setReplaceStart( position );
+ completionProposal.setReplaceEnd( position+0 );
+ completionProposal.setSimpleName( alias );
+ completionProposal.setShortEntityName( qt.getEntityName() );
+ if(hasConfiguration()) {
+ String importedName = (String) getConfiguration().getImports().get( qt.getEntityName() );
+ completionProposal.setEntityName( importedName );
+ }
+ collector.accept( completionProposal );
+ }
+ }
+ } else {
+ if(hasConfiguration()) {
+ String path = CompletionHelper.getCanonicalPath(visible, prefix.substring(0, dotIndex));
+ String propertyPrefix = prefix.substring(dotIndex + 1);
+ completion.getMatchingProperties( path, propertyPrefix, position, collector );
+ } else {
+ collector.completionFailure("Configuration not available nor open");
+ }
+ }
+
+ completion.getMatchingFunctions( prefix, position, collector );
+ completion.getMatchingKeywords( prefix, position, collector );
+
+
+ }
+ } catch(SimpleLexerException sle) {
+ collector.completionFailure( "Syntax error: " + sle.getMessage() );
+ }
+
+ }
+
+ private boolean hasConfiguration() {
+ return configuration!=null;
+ }
+
+ private Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public int findNearestWhiteSpace( CharSequence doc, int start ) {
+ boolean loop = true;
+
+ int offset = 0;
+
+ int tmpOffset = start - 1;
+ while (loop && tmpOffset >= 0) {
+ char c = doc.charAt(tmpOffset);
+ if(Character.isWhitespace(c)) {
+ loop = false;
+ } else {
+ tmpOffset--;
+ }
+ }
+ offset = tmpOffset + 1;
+
+ return offset;
+ }
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCompletionProposal.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCompletionProposal.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/HQLCompletionProposal.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,193 @@
+package org.hibernate.tool.ide.completion;
+
+
+
+public class HQLCompletionProposal {
+
+ static final char[] NO_CHAR = new char[0];
+
+ public static final int ENTITY_NAME = 1;
+ public static final int PROPERTY = 2;
+ public static final int KEYWORD = 3;
+ public static final int FUNCTION = 4;
+ public static final int ALIAS_REF = 5; // ref to an alias name, e.g. "bar" in "from Bar as bar where b|"
+
+ protected static final int FIRST_KIND = ENTITY_NAME;
+ protected static final int LAST_KIND = ALIAS_REF;
+
+ /**
+ * Kind of completion request.
+ */
+ private int completionKind;
+
+ /**
+ * Offset in original buffer where ICodeAssist.codeComplete() was
+ * requested.
+ */
+ private int completionLocation;
+
+ /**
+ * Completion string; defaults to empty string.
+ */
+ private String completion = "";
+
+ /**
+ * Start position (inclusive) of source range in original buffer
+ * to be replaced by completion string;
+ * defaults to empty subrange at [0,0).
+ */
+ private int replaceStart = 0;
+
+ /**
+ * End position (exclusive) of source range in original buffer
+ * to be replaced by completion string;
+ * defaults to empty subrange at [0,0).
+ */
+ private int replaceEnd = 0;
+
+ /**
+ * Relevance rating; positive; higher means better;
+ * defaults to minimum rating.
+ */
+ private int relevance = 1;
+
+ /** The default name for the entityname, keyword, property etc. */
+ private String simpleName = "";
+
+ /** The full related entity name, the resolved shortEntityName. Can be null */
+ private String entityName = null;
+
+ /**
+ * A short entity name. e.g. the imported name.
+ * e.g. "Product" instead of "org.hibernate.model.Product"
+ * (note: a imported name can also be the long version)
+ **/
+ private String shortEntityName = null;
+
+ /**
+ * The propertyName, can be null.
+ */
+ private String propertyName = null;
+
+ public String getCompletion() {
+ return completion;
+ }
+
+ public void setCompletion(String completion) {
+ this.completion = completion;
+ }
+
+ public int getCompletionKind() {
+ return completionKind;
+ }
+
+ public void setCompletionKind(int completionKind) {
+ this.completionKind = completionKind;
+ }
+
+ public int getCompletionLocation() {
+ return completionLocation;
+ }
+
+ public void setCompletionLocation(int completionLocation) {
+ this.completionLocation = completionLocation;
+ }
+
+ public int getRelevance() {
+ return relevance;
+ }
+
+ public void setRelevance(int relevance) {
+ this.relevance = relevance;
+ }
+
+ public int getReplaceEnd() {
+ return replaceEnd;
+ }
+
+ public void setReplaceEnd(int replaceEnd) {
+ this.replaceEnd = replaceEnd;
+ }
+
+ public int getReplaceStart() {
+ return replaceStart;
+ }
+
+ public void setReplaceStart(int replaceStart) {
+ this.replaceStart = replaceStart;
+ }
+
+ public HQLCompletionProposal(int kind, int cursorPosition) {
+ this.completionKind = kind;
+ this.completionLocation = cursorPosition;
+ }
+
+ public String getSimpleName() {
+ return simpleName;
+ }
+
+ public void setSimpleName(String simpleName) {
+ this.simpleName = simpleName;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append('[');
+ switch(this.completionKind) {
+ case ENTITY_NAME :
+ buffer.append("ENTITY_NAME");
+ break;
+ case PROPERTY:
+ buffer.append("PROPERTY");
+ break;
+ case KEYWORD:
+ buffer.append("KEYWORD");
+ break;
+ default :
+ buffer.append("<Unknown type>");
+ break;
+
+ }
+ buffer.append("]{completion:"); //$NON-NLS-1$
+ if (this.completion != null) buffer.append(this.completion);
+ buffer.append(", simpleName:"); //$NON-NLS-1$
+ if (this.simpleName != null) buffer.append(this.simpleName);
+ buffer.append(", ["); //$NON-NLS-1$
+ buffer.append(this.replaceStart);
+ buffer.append(',');
+ buffer.append(this.replaceEnd);
+ buffer.append("], relevance="); //$NON-NLS-1$
+ buffer.append(this.relevance);
+ buffer.append('}');
+ return buffer.toString();
+ }
+
+ public String getEntityName() {
+ return entityName;
+ }
+
+ public void setEntityName(String entityName) {
+ this.entityName = entityName;
+ }
+
+ public String getShortEntityName() {
+ return shortEntityName;
+ }
+
+ public void setShortEntityName(String shortEntityName) {
+ this.shortEntityName = shortEntityName;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public void setPropertyName(String propertyName) {
+ this.propertyName = propertyName;
+ }
+
+
+
+
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/IHQLCodeAssist.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/IHQLCodeAssist.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/IHQLCodeAssist.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,19 @@
+package org.hibernate.tool.ide.completion;
+
+/**
+ * Interface for code assist on HQL strings.
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
+public interface IHQLCodeAssist {
+
+ /**
+ *
+ * @param query the query string (full or partial)
+ * @param position the cursor position inside the query string
+ * @param requestor requestor on which the codeassist will call methods with information about proposals.
+ */
+ void codeComplete(String query, int position, IHQLCompletionRequestor requestor);
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/IHQLCompletionRequestor.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/IHQLCompletionRequestor.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/IHQLCompletionRequestor.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,16 @@
+package org.hibernate.tool.ide.completion;
+
+
+/**
+ * The interface to implement to collect completion proposals.
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
+public interface IHQLCompletionRequestor {
+
+ boolean accept(HQLCompletionProposal proposal);
+
+ void completionFailure(String errorMessage);
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/SimpleHQLLexer.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/SimpleHQLLexer.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/SimpleHQLLexer.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,17 @@
+package org.hibernate.tool.ide.completion;
+
+/**
+ * Minimal lexer interface that allows HqlAnalyzer to work.
+ *
+ * @author Max Rydahl Andersen
+ */
+public interface SimpleHQLLexer {
+
+
+ int nextTokenId() throws SimpleLexerException;
+
+ int getTokenOffset();
+
+ int getTokenLength();
+
+}
Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/SimpleLexerException.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/SimpleLexerException.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/completion/SimpleLexerException.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,27 @@
+package org.hibernate.tool.ide.completion;
+
+/**
+ * Exception that can be thrown when the lexer encounters errors (such as syntax errors etc.)
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
+public class SimpleLexerException extends RuntimeException {
+
+ public SimpleLexerException() {
+ super();
+ }
+
+ public SimpleLexerException(String message, Throwable cause) {
+ super( message, cause );
+ }
+
+ public SimpleLexerException(String message) {
+ super( message );
+ }
+
+ public SimpleLexerException(Throwable cause) {
+ super( cause );
+ }
+
+}
Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/CompletionHelperTest.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/CompletionHelperTest.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/CompletionHelperTest.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,60 @@
+/*
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.hibernate.tool.ide.completion;
+
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ * @author leon
+ */
+public class CompletionHelperTest extends TestCase {
+
+ public CompletionHelperTest() {
+ }
+
+ public void testGetCanonicalPath() {
+ List qts = new ArrayList();
+ qts.add(new EntityNameReference("Article", "art"));
+ qts.add(new EntityNameReference("art.descriptions", "descr"));
+ qts.add(new EntityNameReference("descr.name", "n"));
+ assertEquals("Invalid path", "Article/descriptions/name/locale", CompletionHelper.getCanonicalPath(qts, "n.locale"));
+ assertEquals("Invalid path", "Article/descriptions", CompletionHelper.getCanonicalPath(qts, "descr"));
+ //
+ qts.clear();
+ qts.add(new EntityNameReference("com.company.Clazz", "clz"));
+ qts.add(new EntityNameReference("clz.attr", "a"));
+ assertEquals("Invalid path", "com.company.Clazz/attr", CompletionHelper.getCanonicalPath(qts, "a"));
+ //
+ qts.clear();
+ qts.add(new EntityNameReference("Agga", "a"));
+ assertEquals("Invalid path", "Agga", CompletionHelper.getCanonicalPath(qts, "a"));
+ }
+
+ public void testStackOverflowInGetCanonicalPath() {
+ List qts = new ArrayList();
+ qts.add(new EntityNameReference("Article", "art"));
+ qts.add(new EntityNameReference("art.stores", "store"));
+ qts.add(new EntityNameReference("store.articles", "art"));
+ // This should not result in a stack overflow
+ CompletionHelper.getCanonicalPath(qts, "art");
+ }
+
+
+}
Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/HQLCompletionProposalComparator.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/HQLCompletionProposalComparator.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/HQLCompletionProposalComparator.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,13 @@
+package org.hibernate.tool.ide.completion;
+
+import java.util.Comparator;
+
+public class HQLCompletionProposalComparator implements Comparator {
+
+ public int compare(Object o1, Object o2) {
+ HQLCompletionProposal p1 = (HQLCompletionProposal) o1;
+ HQLCompletionProposal p2 = (HQLCompletionProposal) o2;
+ return p1.getSimpleName().compareTo( p2.getSimpleName() );
+ }
+
+}
Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/HqlAnalyzerTest.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/HqlAnalyzerTest.java 2006-05-19 14:44:33 UTC (rev 9937)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/HqlAnalyzerTest.java 2006-05-19 14:44:38 UTC (rev 9938)
@@ -0,0 +1,260 @@
+/*
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.hibernate.tool.ide.completion;
+
+import java.util.Iterator;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ * @author leon
+ */
+public class HqlAnalyzerTest extends TestCase {
+
+ public HqlAnalyzerTest() {
+ }
+
+ public void testShouldShowTables() {
+ String query = "select | from";
+ doTestShouldShowTables(query, false);
+ query = "select art from | Article1, Article2";
+ doTestShouldShowTables(query, true);
+ query = "from Article1, | Article2";
+ doTestShouldShowTables(query, true);
+ query = "select a, b, c | from Article a";
+ doTestShouldShowTables(query, false);
+ query = "select a, b, c from Article a where a in (select | from";
+ doTestShouldShowTables(query, false);
+ query = "select a, b, c from Article a where a in (select a from |";
+ doTestShouldShowTables(query, true);
+ query = "select a, b, c from Article a where a in (select a from C c where c.id in (select t from | G";
+ doTestShouldShowTables(query, true);
+ query = "select a from|";
+ doTestShouldShowTables(query, false);
+ query = "\n\nfrom Article art where art.|";
+ doTestShouldShowTables(query, false);
+ query = "update |";
+ doTestShouldShowTables(query, true);
+ query = "delete |";
+ doTestShouldShowTables(query, true);
+ query = "select new map(item.id as id, item.description as d, bid.amount as a) from |Item item join item.bids bid\r\n" +
+ " where bid.amount > 100";
+ doTestShouldShowTables( query, true );
+
+ query = "select new map(item.id| as id, item.description as d, bid.amount as a) from |Item item join item.bids bid\r\n" +
+ " where bid.amount > 100";
+ doTestShouldShowTables( query, false );
+
+ query = "select new map(item.id as id, item.description as d, bid.amount as a) from Item item join item|.bids bid\r\n" +
+ " where bid.amount > 100";
+ doTestShouldShowTables( query, false );
+
+ query = "from org.|hibernate";
+ doTestShouldShowTables( query, true );
+
+ query = "from \n\r\r\n" +
+ "org.|hibernate";
+ doTestShouldShowTables( query, true );
+
+ query = "from \n\r\r\n" +
+ "org.hibernate \n\r where |";
+ doTestShouldShowTables( query, false );
+
+ query = "from \n\r\r\n" +
+ "org.hibernate \n\r | where ";
+ doTestShouldShowTables( query, true );
+
+ }
+
+ public void testTableNamePrefix() {
+ doTestPrefix("select a fromtable.substring(0, i0) Art|, Bart", "Art");
+ doTestPrefix("from |", "");
+ doTestPrefix("select a, b, c from Art,|", "");
+ doTestPrefix("select u from | Garga", "");
+ doTestPrefix("select t from A.B.C.D.|", "A.B.C.D.");
+ doTestPrefix("from Goro|boro, Zoroor", "Goro");
+ }
+
+ public void testSubQueries() {
+ doTestSubQueries("select a", 1);
+ doTestSubQueries("fr", 0);
+ doTestSubQueries("from Article a", 1);
+ doTestSubQueries("select a from A, B, C", 1);
+ doTestSubQueries("select a from T a where a.id in ( select c from C c)", 2);
+ doTestSubQueries("select c where c.id in (select D from D D)", 2);
+ doTestSubQueries("select d from D d where d.id in (select a.id from A a where a.id in (select b.id from B b", 3);
+ }
+
+ public void testVisibleSubQueries() {
+ doTestVisibleSubQueries("select | from A a join a.b b", 1);
+ doTestVisibleSubQueries("select | from A a join a.b b where b.id in (select c.id from C c)", 1);
+ doTestVisibleSubQueries("select a from A a join a.b b where b.id in (select c.id from | C c)", 2);
+ doTestVisibleSubQueries("select a from A a join a.b b where b.id in (select c.id from C c) and b.| > 2", 1);
+ doTestVisibleSubQueries("select a from A a where | a.id in (select b.id from B b where b.id in (select c.id", 1);
+ doTestVisibleSubQueries("select a from A a where a.id in (select | b.id from B b where b.id in (select c.id", 2);
+ doTestVisibleSubQueries("select a from A a where a.id in (select b.id from B b where b.id in (select c.id |", 3);
+ }
+
+ public void doTestVisibleSubQueries(String query, int size) {
+ char[] cs = query.replaceAll("\\|", "").toCharArray();
+ List visible = new HQLAnalyzer().getVisibleSubQueries(cs, query.indexOf("|"));
+ assertEquals("Invalid visible query size", size, visible.size());
+ }
+
+ private void doTestSubQueries(String query, int size) {
+ char[] cs = query.toCharArray();
+ List l = new HQLAnalyzer().getSubQueries(query.toCharArray(), 0).subQueries;
+ assertEquals("Incorrent subqueries count", size, l.size());
+ }
+
+ private void doTestPrefix(String query, String prefix) {
+ assertEquals(prefix, HQLAnalyzer.getEntityNamePrefix(query.toCharArray(), query.indexOf("|")));
+ }
+
+ private void doTestShouldShowTables(String query, boolean expectedValue) {
+ char[] ch = query.replaceAll("\\|", "").toCharArray();
+ if (expectedValue) {
+ assertTrue(new HQLAnalyzer().shouldShowEntityNames(ch, getCaretPosition(query)));
+ } else {
+ assertFalse(new HQLAnalyzer().shouldShowEntityNames(ch, getCaretPosition(query)...
[truncated message content] |
|
From: <hib...@li...> - 2006-05-19 14:44:39
|
Author: max...@jb... Date: 2006-05-19 10:44:33 -0400 (Fri, 19 May 2006) New Revision: 9937 Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ide/ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/ Log: hql code completion api |
|
From: <hib...@li...> - 2006-05-19 14:33:43
|
Author: max...@jb...
Date: 2006-05-19 10:33:37 -0400 (Fri, 19 May 2006)
New Revision: 9936
Modified:
trunk/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java
Log:
minor
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java 2006-05-19 07:18:08 UTC (rev 9935)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java 2006-05-19 14:33:37 UTC (rev 9936)
@@ -33,6 +33,10 @@
super(name, outputdir);
}
+ public NonReflectiveTestCase(String name) {
+ super(name);
+ }
+
protected boolean recreateSchema() {
return true;
}
@@ -97,7 +101,7 @@
* @return
*/
protected String getBaseForMappings() {
- return "org/hibernate/test/";
+ return "org/hibernate/tool/";
}
public String getCacheConcurrencyStrategy() {
|