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-06-06 02:10:49
|
Author: ste...@jb...
Date: 2006-06-03 15:28:50 -0400 (Sat, 03 Jun 2006)
New Revision: 9984
Modified:
trunk/Hibernate3/test/org/hibernate/test/TestCase.java
Log:
use Hashtable cache (by default) for tests
Modified: trunk/Hibernate3/test/org/hibernate/test/TestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/TestCase.java 2006-06-02 20:14:17 UTC (rev 9983)
+++ trunk/Hibernate3/test/org/hibernate/test/TestCase.java 2006-06-03 19:28:50 UTC (rev 9984)
@@ -76,6 +76,8 @@
addMappings( files, cfg2 );
+ cfg.setProperty( Environment.CACHE_PROVIDER, "org.hibernate.cache.HashtableCacheProvider" );
+
configure(cfg);
if ( getCacheConcurrencyStrategy()!=null ) {
|
|
From: <hib...@li...> - 2006-06-05 23:50:46
|
Author: tho...@jb...
Date: 2006-06-03 16:48:08 -0400 (Sat, 03 Jun 2006)
New Revision: 9985
Modified:
trunk/HibernateExt/tools/lib/testlibs/README.TXT
trunk/HibernateExt/tools/lib/testlibs/ejb3-persistence.jar
trunk/HibernateExt/tools/lib/testlibs/hibernate-annotations.jar
trunk/HibernateExt/tools/lib/testlibs/hibernate3.jar
trunk/HibernateExt/tools/lib/testlibs/jboss-ejb3x.jar
trunk/HibernateExt/tools/lib/testlibs/jboss-seam.jar
trunk/HibernateExt/tools/lib/testlibs/myfaces-api.jar
trunk/HibernateExt/tools/src/templates/seam/editorbean.java.ftl
trunk/HibernateExt/tools/src/templates/seam/finderbean.java.ftl
trunk/HibernateExt/tools/src/templates/seam/selector.java.ftl
Log:
* Fixed Seam templates
* Updates testlibs with libs from jboss-4.0.4.GA
Modified: trunk/HibernateExt/tools/lib/testlibs/README.TXT
===================================================================
--- trunk/HibernateExt/tools/lib/testlibs/README.TXT 2006-06-03 19:28:50 UTC (rev 9984)
+++ trunk/HibernateExt/tools/lib/testlibs/README.TXT 2006-06-03 20:48:08 UTC (rev 9985)
@@ -2,3 +2,5 @@
Some of these libraries are only here for the purpose of verifying that the
generated code can compile.
+
+Jar files from JBoss 4.0.4.GA and jboss-seam-1.0.0.CR3
\ No newline at end of file
Modified: trunk/HibernateExt/tools/lib/testlibs/ejb3-persistence.jar
===================================================================
(Binary files differ)
Modified: trunk/HibernateExt/tools/lib/testlibs/hibernate-annotations.jar
===================================================================
(Binary files differ)
Modified: trunk/HibernateExt/tools/lib/testlibs/hibernate3.jar
===================================================================
(Binary files differ)
Modified: trunk/HibernateExt/tools/lib/testlibs/jboss-ejb3x.jar
===================================================================
(Binary files differ)
Modified: trunk/HibernateExt/tools/lib/testlibs/jboss-seam.jar
===================================================================
(Binary files differ)
Modified: trunk/HibernateExt/tools/lib/testlibs/myfaces-api.jar
===================================================================
(Binary files differ)
Modified: trunk/HibernateExt/tools/src/templates/seam/editorbean.java.ftl
===================================================================
--- trunk/HibernateExt/tools/src/templates/seam/editorbean.java.ftl 2006-06-03 19:28:50 UTC (rev 9984)
+++ trunk/HibernateExt/tools/src/templates/seam/editorbean.java.ftl 2006-06-03 20:48:08 UTC (rev 9985)
@@ -5,7 +5,7 @@
<#assign entityEditor = pojo.shortName.toLowerCase() + "Editor"><#assign entityFinder = pojo.shortName.toLowerCase() + "Finder"><#assign entityList = pojo.shortName.toLowerCase() + "List"><#assign entity = pojo.shortName.toLowerCase()><#assign entityClass = pojo.importType(pojo.qualifiedDeclarationName)>
@${pojo.importType("org.jboss.seam.annotations.Name")}("${entityEditor}")
@${pojo.importType("javax.ejb.Stateful")}
-@${pojo.importType("javax.ejb.Interceptors")}(${pojo.importType("org.jboss.seam.ejb.SeamInterceptor")}.class)
+@${pojo.importType("javax.interceptor.Interceptors")}(${pojo.importType("org.jboss.seam.ejb.SeamInterceptor")}.class)
public class ${pojo.shortName}EditorBean implements ${pojo.shortName}Editor {
@${pojo.importType("org.jboss.seam.annotations.In")}(create=true)
@@ -38,8 +38,8 @@
@${pojo.importType("org.jboss.seam.annotations.In")}(required=false)
private transient ${pojo.shortName}Finder ${entityFinder};
- @${pojo.importType("org.jboss.seam.annotations.In")}
- private transient ${pojo.importType("java.util.ResourceBundle")} resourceBundle;
+ @${pojo.importType("org.jboss.seam.annotations.In")}(create=true)
+ private transient ${pojo.importType("java.util.Map")} messages;
@${pojo.importType("org.jboss.seam.annotations.Begin")}(join=true)
@${pojo.importType("org.jboss.seam.annotations.IfInvalid")}(outcome=${pojo.importType("org.jboss.seam.annotations.Outcome")}.REDISPLAY)
@@ -48,8 +48,8 @@
{
${pojo.importType("javax.faces.context.FacesContext")}.getCurrentInstance().addMessage(null,
new ${pojo.importType("javax.faces.application.FacesMessage")}(
- resourceBundle.getString("${pojo.shortName}_${pojo.identifierProperty.name}") + " " +
- resourceBundle.getString("AlreadyExists")
+ messages.get("${pojo.shortName}_${pojo.identifierProperty.name}") + " " +
+ messages.get("AlreadyExists")
)
);
return null;
Modified: trunk/HibernateExt/tools/src/templates/seam/finderbean.java.ftl
===================================================================
--- trunk/HibernateExt/tools/src/templates/seam/finderbean.java.ftl 2006-06-03 19:28:50 UTC (rev 9984)
+++ trunk/HibernateExt/tools/src/templates/seam/finderbean.java.ftl 2006-06-03 20:48:08 UTC (rev 9985)
@@ -6,7 +6,7 @@
@${pojo.importType("org.jboss.seam.annotations.Name")}("${entityFinder}")
@${pojo.importType("javax.ejb.Stateful")}
@${pojo.importType("org.jboss.seam.annotations.Scope")}(${pojo.importType("org.jboss.seam.ScopeType")}.SESSION)
-@${pojo.importType("javax.ejb.Interceptors")}(${pojo.importType("org.jboss.seam.ejb.SeamInterceptor")}.class)
+@${pojo.importType("javax.interceptor.Interceptors")}(${pojo.importType("org.jboss.seam.ejb.SeamInterceptor")}.class)
public class ${pojo.shortName}FinderBean implements ${pojo.shortName}Finder {
private ${entityClass} example = new ${entityClass}();
Modified: trunk/HibernateExt/tools/src/templates/seam/selector.java.ftl
===================================================================
--- trunk/HibernateExt/tools/src/templates/seam/selector.java.ftl 2006-06-03 19:28:50 UTC (rev 9984)
+++ trunk/HibernateExt/tools/src/templates/seam/selector.java.ftl 2006-06-03 20:48:08 UTC (rev 9985)
@@ -17,7 +17,7 @@
<#assign entityEditor = pojo.shortName.toLowerCase() + "Editor"><#assign entitySelector = pojo.shortName.toLowerCase() + "Selector"><#assign entityFinder = pojo.shortName.toLowerCase() + "Finder"> @${pojo.importType("javax.ejb.Stateless")}
@${pojo.importType("org.jboss.seam.annotations.Name")}("${entitySelector}")
- @${pojo.importType("javax.ejb.Interceptors")}(${pojo.importType("org.jboss.seam.ejb.SeamInterceptor")}.class)
+ @${pojo.importType("javax.interceptor.Interceptors")}(${pojo.importType("org.jboss.seam.ejb.SeamInterceptor")}.class)
public static class Default${pojo.shortName}Selector implements ${pojo.shortName}Selector {
@${pojo.importType("org.jboss.seam.annotations.In")}
@@ -63,7 +63,7 @@
@${pojo.importType("org.jboss.seam.annotations.Name")}("${childSelector}")
@${pojo.importType("org.jboss.annotation.ejb.LocalBinding")}(jndiBinding="${childPojo.qualifiedDeclarationName}${pojo.shortName}Selector")
@${pojo.importType("org.jboss.seam.annotations.JndiName")}("${childPojo.qualifiedDeclarationName}${pojo.shortName}Selector")
- @${pojo.importType("javax.ejb.Interceptors")}(${pojo.importType("org.jboss.seam.ejb.SeamInterceptor")}.class)
+ @${pojo.importType("javax.interceptor.Interceptors")}(${pojo.importType("org.jboss.seam.ejb.SeamInterceptor")}.class)
public static class ${childPojo.shortName}${pojo.shortName}Selector implements ${pojo.shortName}Selector {
@${pojo.importType("org.jboss.seam.annotations.In")}
|
|
From: <hib...@li...> - 2006-06-05 22:05:11
|
Author: max...@jb...
Date: 2006-06-05 17:42:05 -0400 (Mon, 05 Jun 2006)
New Revision: 9986
Modified:
trunk/HibernateExt/tools/src/templates/hbm/bag.hbm.ftl
Log:
better bag
Modified: trunk/HibernateExt/tools/src/templates/hbm/bag.hbm.ftl
===================================================================
--- trunk/HibernateExt/tools/src/templates/hbm/bag.hbm.ftl 2006-06-03 20:48:08 UTC (rev 9985)
+++ trunk/HibernateExt/tools/src/templates/hbm/bag.hbm.ftl 2006-06-05 21:42:05 UTC (rev 9986)
@@ -2,10 +2,24 @@
name="${property.name}"
inverse="${property.value.inverse?string}"
>
- <key>
- <#foreach column in property.value.key.columnIterator>
- <#include "column.hbm.ftl">
- </#foreach>
+ <key>
+ <#foreach column in property.value.key.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
</key>
- <element type="string" column="dummy"/>
+<#if c2h.isOneToMany(property)>
+ <one-to-many
+ class="${property.getValue().getElement().getAssociatedClass().getClassName()}"
+<#if !property.getValue().getElement().getAssociatedClass().getClassName().equals(property.getValue().getElement().getReferencedEntityName())>
+ entity-name="${property.getValue().getElement().getReferencedEntityName()}"
+</#if>
+ />
+<#elseif c2h.isManyToMany(property)>
+ <many-to-many
+ entity-name="${property.getValue().getElement().referencedEntityName}"> <#-- lookup needed classname -->
+<#foreach column in property.getValue().getElement().columnIterator>
+ <#include "column.hbm.ftl">
+</#foreach>
+ </many-to-many>
+</#if>
</bag>
\ No newline at end of file
|
|
From: <hib...@li...> - 2006-06-02 20:14:34
|
Author: ste...@jb...
Date: 2006-06-02 16:14:17 -0400 (Fri, 02 Jun 2006)
New Revision: 9983
Modified:
trunk/Hibernate3/src/org/hibernate/impl/SessionFactoryImpl.java
Log:
minor
Modified: trunk/Hibernate3/src/org/hibernate/impl/SessionFactoryImpl.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/impl/SessionFactoryImpl.java 2006-06-02 19:47:51 UTC (rev 9982)
+++ trunk/Hibernate3/src/org/hibernate/impl/SessionFactoryImpl.java 2006-06-02 20:14:17 UTC (rev 9983)
@@ -1032,10 +1032,26 @@
// this reference within the same JVM, so simply writing out the
// uuid is enough
oos.writeUTF( uuid );
+ oos.writeBoolean( name != null );
+ if ( name != null ) {
+ oos.writeUTF( name );
+ }
}
+ /**
+ * Custom deserialization hook used during Session deserialization.
+ *
+ * @param ois The stream from which to "read" the factory
+ * @throws IOException
+ */
static SessionFactoryImpl deserialize(ObjectInputStream ois) throws IOException, ClassNotFoundException {
String uuid = ois.readUTF();
+ boolean isNamed = ois.readBoolean();
+ if ( isNamed ) {
+ // todo : potentially use name for lookups on deserialization;
+ // needed for clustered failover of a session (i.e. stateful session bean)
+ String name = ois.readUTF();
+ }
Object result = SessionFactoryObjectFactory.getInstance( uuid );
if ( result == null ) {
throw new InvalidObjectException( "could not locate session factory by uuid [" + uuid + "] during session deserialization" );
|
|
From: <hib...@li...> - 2006-06-02 19:47:54
|
Author: epbernard
Date: 2006-06-02 15:47:51 -0400 (Fri, 02 Jun 2006)
New Revision: 9982
Added:
trunk/Hibernate3/src/org/hibernate/hql/QueryExecutionRequestException.java
Modified:
trunk/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java
Log:
EJB-191 specialize exception when expected query operation does not match the called API
Added: trunk/Hibernate3/src/org/hibernate/hql/QueryExecutionRequestException.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/hql/QueryExecutionRequestException.java 2006-06-02 19:16:45 UTC (rev 9981)
+++ trunk/Hibernate3/src/org/hibernate/hql/QueryExecutionRequestException.java 2006-06-02 19:47:51 UTC (rev 9982)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.hql;
+
+import org.hibernate.QueryException;
+
+/**
+ * Expecting to execute an illegal operation regarding the query type
+ *
+ * @author Emmanuel Bernard
+ */
+public class QueryExecutionRequestException extends QueryException {
+
+ public QueryExecutionRequestException(String message, String queryString) {
+ super( message, queryString );
+ }
+}
Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java 2006-06-02 19:16:45 UTC (rev 9981)
+++ trunk/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java 2006-06-02 19:47:51 UTC (rev 9982)
@@ -1,6 +1,13 @@
// $Id$
package org.hibernate.hql.ast;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import antlr.ANTLRException;
import antlr.RecognitionException;
import antlr.TokenStreamException;
@@ -11,13 +18,14 @@
import org.hibernate.MappingException;
import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
-import org.hibernate.hql.ParameterTranslations;
import org.hibernate.engine.QueryParameters;
+import org.hibernate.engine.RowSelection;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.engine.RowSelection;
import org.hibernate.event.EventSource;
import org.hibernate.hql.FilterTranslator;
+import org.hibernate.hql.QueryExecutionRequestException;
+import org.hibernate.hql.ParameterTranslations;
import org.hibernate.hql.antlr.HqlSqlTokenTypes;
import org.hibernate.hql.antlr.HqlTokenTypes;
import org.hibernate.hql.antlr.SqlTokenTypes;
@@ -33,16 +41,9 @@
import org.hibernate.loader.hql.QueryLoader;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.type.Type;
+import org.hibernate.util.IdentitySet;
import org.hibernate.util.StringHelper;
-import org.hibernate.util.IdentitySet;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.ArrayList;
-
/**
* A QueryTranslator that uses an AST based parser.
* <br>User: josh
@@ -264,13 +265,13 @@
private void errorIfDML() throws HibernateException {
if ( sqlAst.needsExecutor() ) {
- throw new HibernateException( "Not supported for DML operations" );
+ throw new QueryExecutionRequestException( "Not supported for DML operations", hql );
}
}
private void errorIfSelect() throws HibernateException {
if ( !sqlAst.needsExecutor() ) {
- throw new HibernateException( "Not supported for select queries" );
+ throw new QueryExecutionRequestException( "Not supported for select queries", hql );
}
}
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java 2006-06-02 19:16:45 UTC (rev 9981)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java 2006-06-02 19:47:51 UTC (rev 9982)
@@ -15,8 +15,10 @@
import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
+import org.hibernate.QueryParameterException;
import org.hibernate.SQLQuery;
-import org.hibernate.QueryParameterException;
+import org.hibernate.TypeMismatchException;
+import org.hibernate.hql.QueryExecutionRequestException;
/**
* @author <a href="mailto:ga...@hi...">Gavin King</a>
@@ -43,28 +45,32 @@
}
return query.executeUpdate();
}
+ catch (QueryExecutionRequestException he) {
+ throw new IllegalStateException(he);
+ }
+ catch( TypeMismatchException e ) {
+ throw new IllegalArgumentException(e);
+ }
catch (HibernateException he) {
em.throwPersistenceException( he );
return 0;
}
- catch( ClassCastException cce ) {
- //TODO fix that when the TypeMismatchException is used by the core
- throw new IllegalArgumentException(cce);
- }
}
public List getResultList() {
try {
return query.list();
}
+ catch (QueryExecutionRequestException he) {
+ throw new IllegalStateException(he);
+ }
+ catch( TypeMismatchException e ) {
+ throw new IllegalArgumentException(e);
+ }
catch (HibernateException he) {
em.throwPersistenceException( he );
return null;
}
- catch( ClassCastException cce ) {
- //TODO fix that when the TypeMismatchException is used by the core
- throw new IllegalArgumentException(cce);
- }
}
public Object getSingleResult() {
@@ -77,14 +83,16 @@
return result;
}
+ catch (QueryExecutionRequestException he) {
+ throw new IllegalStateException(he);
+ }
+ catch( TypeMismatchException e ) {
+ throw new IllegalArgumentException(e);
+ }
catch (HibernateException he) {
em.throwPersistenceException( he );
return null;
}
- catch( ClassCastException cce ) {
- //TODO fix that when the TypeMismatchException is used by the core
- throw new IllegalArgumentException(cce);
- }
}
public Query setMaxResults(int maxResult) {
|
|
From: <hib...@li...> - 2006-06-02 19:17:03
|
Author: ste...@jb...
Date: 2006-06-02 15:16:45 -0400 (Fri, 02 Jun 2006)
New Revision: 9981
Modified:
trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
Log:
TCK : query param type mismatch
Modified: trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2006-06-02 19:14:50 UTC (rev 9980)
+++ trunk/Hibernate3/src/org/hibernate/loader/hql/QueryLoader.java 2006-06-02 19:16:45 UTC (rev 9981)
@@ -13,6 +13,7 @@
import org.hibernate.LockMode;
import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
+import org.hibernate.TypeMismatchException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.SessionFactoryImplementor;
@@ -75,15 +76,15 @@
private QueryableCollection[] collectionPersisters;
private int selectLength;
-
+
private ResultTransformer selectNewTransformer;
private String[] queryReturnAliases;
private LockMode[] defaultLockModes;
-
+
/**
* Creates a new Loader implementation.
*
@@ -110,10 +111,10 @@
queryReturnTypes = selectClause.getQueryReturnTypes();
selectNewTransformer = HolderInstantiator.createSelectNewTransformer(
- selectClause.getConstructor(),
- selectClause.isMap(),
+ selectClause.getConstructor(),
+ selectClause.isMap(),
selectClause.isList());
- queryReturnAliases = selectClause.getQueryReturnAliases();
+ queryReturnAliases = selectClause.getQueryReturnAliases();
List collectionFromElements = selectClause.getCollectionFromElements();
if ( collectionFromElements != null && collectionFromElements.size()!=0 ) {
@@ -327,7 +328,7 @@
private boolean hasSelectNew() {
return selectNewTransformer!=null;
}
-
+
protected Object getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session)
throws SQLException, HibernateException {
@@ -365,7 +366,7 @@
Object result = holderInstantiator.instantiate(row);
results.set( i, result );
}
-
+
if(!hasSelectNew() && resultTransformer!=null) {
return resultTransformer.transformList(results);
} else {
@@ -387,7 +388,7 @@
* @throws HibernateException
*/
public List list(SessionImplementor session, QueryParameters queryParameters)
- throws HibernateException {
+ throws HibernateException {
checkQuery( queryParameters );
return list( session, queryParameters, queryTranslator.getQuerySpaces(), queryReturnTypes );
}
@@ -397,7 +398,7 @@
throw new QueryException("ResultTransformer is not allowed for 'select new' queries.");
}
}
-
+
/**
* Return the query results as an iterator
*/
@@ -512,7 +513,16 @@
" [" + location + "]"
);
}
- typedval.getType().nullSafeSet( ps, typedval.getValue(), location, session );
+ try {
+ typedval.getType().nullSafeSet( ps, typedval.getValue(), location, session );
+ }
+ catch( ClassCastException cce ) {
+ throw new TypeMismatchException(
+ "named parameter [" + name + "] not of expected type; expected = " +
+ typedval.getValue().getClass().getName() + "; but was =" +
+ typedval.getType().getReturnedClass()
+ );
+ }
}
result += locs.length;
}
|
|
From: <hib...@li...> - 2006-06-02 19:15:10
|
Author: ste...@jb...
Date: 2006-06-02 15:14:50 -0400 (Fri, 02 Jun 2006)
New Revision: 9980
Modified:
trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
TCK : query param type mismatch
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-06-02 18:07:08 UTC (rev 9979)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-06-02 19:14:50 UTC (rev 9980)
@@ -22,6 +22,7 @@
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.TypeMismatchException;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.DB2Dialect;
@@ -84,6 +85,24 @@
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
+ public void testParameterTypeMismatchFails() {
+ Session s = openSession();
+ s.beginTransaction();
+
+ Query query = s.createQuery( "from Animal a where a.description = :nonstring" )
+ .setParameter( "nonstring", new Integer(1) );
+ try {
+ query.list();
+ fail( "query execution should have failed" );
+ }
+ catch( TypeMismatchException tme ) {
+ // expected behavior
+ }
+
+ s.getTransaction().commit();
+ s.close();
+ }
+
public void testMultipleBagFetchesFail() {
Session s = openSession();
s.beginTransaction();
|
|
From: <hib...@li...> - 2006-06-02 18:07:14
|
Author: epbernard
Date: 2006-06-02 14:07:08 -0400 (Fri, 02 Jun 2006)
New Revision: 9979
Added:
trunk/Hibernate3/src/org/hibernate/QueryParameterException.java
Modified:
trunk/Hibernate3/src/org/hibernate/engine/query/ParameterMetadata.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java
Log:
EJB-190 catch QueryParameterException and raise an IAE
Added: trunk/Hibernate3/src/org/hibernate/QueryParameterException.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/QueryParameterException.java 2006-06-02 16:28:06 UTC (rev 9978)
+++ trunk/Hibernate3/src/org/hibernate/QueryParameterException.java 2006-06-02 18:07:08 UTC (rev 9979)
@@ -0,0 +1,26 @@
+//$Id: $
+package org.hibernate;
+
+/**
+ * Parameter invalid or not found in the query
+ *
+ * @author Emmanuel Bernard
+ */
+public class QueryParameterException extends QueryException {
+
+ public QueryParameterException(Exception e) {
+ super( e );
+ }
+
+ public QueryParameterException(String message) {
+ super( message );
+ }
+
+ public QueryParameterException(String message, Throwable e) {
+ super( message, e );
+ }
+
+ public QueryParameterException(String message, String queryString) {
+ super( message, queryString );
+ }
+}
Modified: trunk/Hibernate3/src/org/hibernate/engine/query/ParameterMetadata.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/query/ParameterMetadata.java 2006-06-02 16:28:06 UTC (rev 9978)
+++ trunk/Hibernate3/src/org/hibernate/engine/query/ParameterMetadata.java 2006-06-02 18:07:08 UTC (rev 9979)
@@ -1,13 +1,13 @@
package org.hibernate.engine.query;
-import org.hibernate.type.Type;
-import org.hibernate.HibernateException;
-
import java.io.Serializable;
+import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import java.util.HashMap;
+import org.hibernate.QueryParameterException;
+import org.hibernate.type.Type;
+
/**
* Encapsulates metadata about parameters encountered within a query.
*
@@ -72,7 +72,7 @@
public NamedParameterDescriptor getNamedParameterDescriptor(String name) {
NamedParameterDescriptor meta = ( NamedParameterDescriptor ) namedDescriptorMap.get( name );
if ( meta == null ) {
- throw new HibernateException( "could not locate named parameter [" + name + "]" );
+ throw new QueryParameterException( "could not locate named parameter [" + name + "]" );
}
return meta;
}
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java 2006-06-02 16:28:06 UTC (rev 9978)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java 2006-06-02 18:07:08 UTC (rev 9979)
@@ -16,6 +16,7 @@
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
+import org.hibernate.QueryParameterException;
/**
* @author <a href="mailto:ga...@hi...">Gavin King</a>
@@ -46,6 +47,10 @@
em.throwPersistenceException( he );
return 0;
}
+ catch( ClassCastException cce ) {
+ //TODO fix that when the TypeMismatchException is used by the core
+ throw new IllegalArgumentException(cce);
+ }
}
public List getResultList() {
@@ -56,6 +61,10 @@
em.throwPersistenceException( he );
return null;
}
+ catch( ClassCastException cce ) {
+ //TODO fix that when the TypeMismatchException is used by the core
+ throw new IllegalArgumentException(cce);
+ }
}
public Object getSingleResult() {
@@ -72,6 +81,10 @@
em.throwPersistenceException( he );
return null;
}
+ catch( ClassCastException cce ) {
+ //TODO fix that when the TypeMismatchException is used by the core
+ throw new IllegalArgumentException(cce);
+ }
}
public Query setMaxResults(int maxResult) {
@@ -145,6 +158,9 @@
}
return this;
}
+ catch (QueryParameterException e) {
+ throw new IllegalArgumentException( e );
+ }
catch (HibernateException he) {
em.throwPersistenceException( he );
return null;
@@ -164,6 +180,9 @@
}
return this;
}
+ catch (QueryParameterException e) {
+ throw new IllegalArgumentException( e );
+ }
catch (HibernateException he) {
em.throwPersistenceException( he );
return null;
@@ -183,6 +202,9 @@
}
return this;
}
+ catch (QueryParameterException e) {
+ throw new IllegalArgumentException( e );
+ }
catch (HibernateException he) {
em.throwPersistenceException( he );
return null;
@@ -199,6 +221,9 @@
}
return this;
}
+ catch (QueryParameterException e) {
+ throw new IllegalArgumentException( e );
+ }
catch (HibernateException he) {
em.throwPersistenceException( he );
return null;
@@ -228,6 +253,9 @@
}
return this;
}
+ catch (QueryParameterException e) {
+ throw new IllegalArgumentException( e );
+ }
catch (HibernateException he) {
em.throwPersistenceException( he );
return null;
@@ -253,6 +281,9 @@
}
return this;
}
+ catch (QueryParameterException e) {
+ throw new IllegalArgumentException( e );
+ }
catch (HibernateException he) {
em.throwPersistenceException( he );
return null;
|
|
From: <hib...@li...> - 2006-06-02 16:24:06
|
Author: epbernard
Date: 2006-06-02 12:24:00 -0400 (Fri, 02 Jun 2006)
New Revision: 9977
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java
Log:
useless log
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-06-02 16:12:13 UTC (rev 9976)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-06-02 16:24:00 UTC (rev 9977)
@@ -26,6 +26,7 @@
import javax.persistence.Embedded;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
+import javax.persistence.EntityListeners;
import javax.persistence.EntityResult;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
@@ -54,6 +55,13 @@
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
+import javax.persistence.PostLoad;
+import javax.persistence.PostPersist;
+import javax.persistence.PostRemove;
+import javax.persistence.PostUpdate;
+import javax.persistence.PrePersist;
+import javax.persistence.PreRemove;
+import javax.persistence.PreUpdate;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.PrimaryKeyJoinColumns;
import javax.persistence.QueryHint;
@@ -69,14 +77,6 @@
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
-import javax.persistence.EntityListeners;
-import javax.persistence.PrePersist;
-import javax.persistence.PreRemove;
-import javax.persistence.PreUpdate;
-import javax.persistence.PostRemove;
-import javax.persistence.PostPersist;
-import javax.persistence.PostUpdate;
-import javax.persistence.PostLoad;
import org.dom4j.Attribute;
import org.dom4j.Element;
@@ -84,14 +84,12 @@
import org.hibernate.annotationfactory.AnnotationDescriptor;
import org.hibernate.annotationfactory.AnnotationFactory;
import org.hibernate.annotations.AccessType;
-import org.hibernate.annotations.Columns;
import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.annotations.Columns;
import org.hibernate.reflection.Filter;
import org.hibernate.reflection.java.xml.XMLContext;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* Encapsulates the overriding of Java annotations from an EJB 3.0 descriptor.
@@ -1698,8 +1696,6 @@
}
}
- private static Log log = LogFactory.getLog( EJB3OverridenAnnotationReader.class );
-
private MappedSuperclass getMappedSuperclass(Element tree, XMLContext.Default defaults) {
if ( tree == null ) {
return defaults.canUseJavaAnnotations() ? super.getAnnotation( MappedSuperclass.class ) : null;
|
|
From: <hib...@li...> - 2006-06-02 16:12:20
|
Author: epbernard
Date: 2006-06-02 12:12:13 -0400 (Fri, 02 Jun 2006)
New Revision: 9976
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java
Log:
ANN-359 wring ann type sied when building annoation descriptor
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-05-31 22:03:16 UTC (rev 9975)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-06-02 16:12:13 UTC (rev 9976)
@@ -90,6 +90,8 @@
import org.hibernate.reflection.java.xml.XMLContext;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Encapsulates the overriding of Java annotations from an EJB 3.0 descriptor.
@@ -1696,13 +1698,15 @@
}
}
+ private static Log log = LogFactory.getLog( EJB3OverridenAnnotationReader.class );
+
private MappedSuperclass getMappedSuperclass(Element tree, XMLContext.Default defaults) {
if ( tree == null ) {
return defaults.canUseJavaAnnotations() ? super.getAnnotation( MappedSuperclass.class ) : null;
}
else {
if ( "mapped-superclass".equals( tree.getName() ) ) {
- AnnotationDescriptor entity = new AnnotationDescriptor( Entity.class );
+ AnnotationDescriptor entity = new AnnotationDescriptor( MappedSuperclass.class );
return AnnotationFactory.create( entity );
}
else {
|
|
From: <hib...@li...> - 2006-05-31 22:03:35
|
Author: ste...@jb...
Date: 2006-05-31 18:03:16 -0400 (Wed, 31 May 2006)
New Revision: 9975
Modified:
trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
Log:
added hook for HEM to affect deletion of detached entity
Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-05-31 18:01:41 UTC (rev 9974)
+++ trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-05-31 22:03:16 UTC (rev 9975)
@@ -65,11 +65,15 @@
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;
}
+ else {
+ performDetachedEntityDeletionCheck( event );
+ }
id = persister.getIdentifier( entity, source.getEntityMode() );
@@ -128,6 +132,11 @@
}
}
+ protected void performDetachedEntityDeletionCheck(DeleteEvent event) {
+ // ok in normal Hibernate usage to delete a detached entity; JPA however
+ // forbids it, thus this is a hook for HEM to affect this behavior
+ }
+
/**
* We encountered a delete request on a transient instance.
* <p/>
|
|
From: <hib...@li...> - 2006-05-31 18:02:02
|
Author: epbernard
Date: 2006-05-31 14:01:41 -0400 (Wed, 31 May 2006)
New Revision: 9974
Modified:
trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
Log:
HHH-1800 / EJB-189 raise exception when the id is not of the expected type
Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java 2006-05-31 17:00:12 UTC (rev 9973)
+++ trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java 2006-05-31 18:01:41 UTC (rev 9974)
@@ -75,7 +75,7 @@
Class idClass = persister.getIdentifierType().getReturnedClass();
if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
throw new TypeMismatchException(
- "Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId()
+ "Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId().getClass()
);
}
|
|
From: <hib...@li...> - 2006-05-31 17:00:38
|
Author: ste...@jb...
Date: 2006-05-31 13:00:12 -0400 (Wed, 31 May 2006)
New Revision: 9973
Modified:
trunk/Hibernate3/doc/reference/en/modules/basic_mapping.xml
Log:
documented DTDEntityResolver capabilities
Modified: trunk/Hibernate3/doc/reference/en/modules/basic_mapping.xml
===================================================================
--- trunk/Hibernate3/doc/reference/en/modules/basic_mapping.xml 2006-05-31 16:59:05 UTC (rev 9972)
+++ trunk/Hibernate3/doc/reference/en/modules/basic_mapping.xml 2006-05-31 17:00:12 UTC (rev 9973)
@@ -96,7 +96,7 @@
- <sect2 id="mapping-declaration-doctype" revision="2">
+ <sect2 id="mapping-declaration-doctype" revision="3">
<title>Doctype</title>
<para>
@@ -107,6 +107,58 @@
Internet connection, check your DTD declaration against the contents of your
claspath.
</para>
+
+ <sect3 id="mapping-declaration-entity-resolution">
+ <title>EntityResolver</title>
+ <para>
+ As mentioned previously, Hibernate will first attempt to resolve DTDs in its classpath. The
+ manner in which it does this is by registering a custom <literal>org.xml.sax.EntityResolver</literal>
+ implementation with the SAXReader it uses to read in the xml files. This custom
+ <literal>EntityResolver</literal> recognizes two different systemId namespaces.
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ a <literal>hibernate namespace</literal> is recognized whenever the
+ resolver encounteres a systemId starting with
+ <literal>http://hibernate.sourceforge.net/</literal>; the resolver
+ attempts to resolve these entities via the classlaoder which loaded
+ the Hibernate classes.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ a <literal>user namespace</literal> is recognized whenever the
+ resolver encounteres a systemId using a <literal>classpath://</literal>
+ URL protocol; the resolver will attempt to resolve these entities
+ via (1) the current thread context classloader and (2) the
+ classloader which loaded the Hibernate classes.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <para>
+ An example of utilizing user namespacing:
+ </para>
+ <programlisting><![CDATA[<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" [
+ <!ENTITY types SYSTEM "classpath://your/domain/types.xml">
+]>
+
+<hibernate-mapping package="your.domain">
+ <class name="MyEntity">
+ <id name="id" type="my-custom-id-type">
+ ...
+ </id>
+ <class>
+ &types;
+</hibernate-mapping>]]></programlisting>
+ <para>
+ Where <literal>types.xml</literal> is a resource in the <literal>your.domain</literal>
+ package and contains a custom <xref linkend="mapping-types-custom">typedef</xref>.
+ </para>
+ </sect3>
</sect2>
<sect2 id="mapping-declaration-mapping" revision="3">
|
|
From: <hib...@li...> - 2006-05-31 16:59:31
|
Author: ste...@jb...
Date: 2006-05-31 12:59:05 -0400 (Wed, 31 May 2006)
New Revision: 9972
Modified:
trunk/Hibernate3/src/org/hibernate/util/ConfigHelper.java
Log:
recognition of classpath:// entity references
Modified: trunk/Hibernate3/src/org/hibernate/util/ConfigHelper.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/util/ConfigHelper.java 2006-05-31 16:58:26 UTC (rev 9971)
+++ trunk/Hibernate3/src/org/hibernate/util/ConfigHelper.java 2006-05-31 16:59:05 UTC (rev 9972)
@@ -129,10 +129,10 @@
private ConfigHelper() {}
public static InputStream getResourceAsStream(String resource) {
- String stripped = resource.startsWith("/") ?
+ String stripped = resource.startsWith("/") ?
resource.substring(1) : resource;
-
- InputStream stream = null;
+
+ InputStream stream = null;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader!=null) {
stream = classLoader.getResourceAsStream( stripped );
@@ -148,4 +148,34 @@
}
return stream;
}
+
+
+ public static InputStream getUserResourceAsStream(String resource) {
+ boolean hasLeadingSlash = resource.startsWith( "/" );
+ String stripped = hasLeadingSlash ? resource.substring(1) : resource;
+
+ InputStream stream = null;
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if ( classLoader != null ) {
+ stream = classLoader.getResourceAsStream( resource );
+ if ( stream == null && hasLeadingSlash ) {
+ stream = classLoader.getResourceAsStream( stripped );
+ }
+ }
+
+ if ( stream == null ) {
+ stream = Environment.class.getClassLoader().getResourceAsStream( resource );
+ }
+ if ( stream == null && hasLeadingSlash ) {
+ stream = Environment.class.getClassLoader().getResourceAsStream( stripped );
+ }
+
+ if ( stream == null ) {
+ throw new HibernateException( resource + " not found" );
+ }
+
+ return stream;
+ }
+
}
|
|
From: <hib...@li...> - 2006-05-31 16:58:52
|
Author: ste...@jb...
Date: 2006-05-31 12:58:26 -0400 (Wed, 31 May 2006)
New Revision: 9971
Modified:
trunk/Hibernate3/src/org/hibernate/util/DTDEntityResolver.java
Log:
recognition of classpath:// entity references
Modified: trunk/Hibernate3/src/org/hibernate/util/DTDEntityResolver.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/util/DTDEntityResolver.java 2006-05-31 16:37:03 UTC (rev 9970)
+++ trunk/Hibernate3/src/org/hibernate/util/DTDEntityResolver.java 2006-05-31 16:58:26 UTC (rev 9971)
@@ -10,12 +10,28 @@
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
+/**
+ * An {@link EntityResolver} implementation which attempts to resolve
+ * various systemId URLs to local classpath lookups<ol>
+ * <li>Any systemId URL beginning with <tt>http://hibernate.sourceforge.net/</tt> is
+ * searched for as a classpath resource in the classloader which loaded the
+ * Hibernate classes.</li>
+ * <li>Any systemId URL using <tt>classpath</tt> as the scheme (i.e. starting
+ * with <tt>classpath://</tt> is searched for as a classpath resource using first
+ * the current thread context classloader and then the classloader which loaded
+ * the Hibernate classes.
+ * </ol>
+ * <p/>
+ * Any entity references which cannot be resolved in relation to the above
+ * rules result in returning null, which should force the SAX reader to
+ * handle the entity reference in its default manner.
+ */
public class DTDEntityResolver implements EntityResolver, Serializable {
private static final Log log = LogFactory.getLog( DTDEntityResolver.class );
private static final String HIBERNATE_NAMESPACE = "http://hibernate.sourceforge.net/";
- private static final String LOCAL_NAMESPACE = "file://";
+ private static final String USER_NAMESPACE = "classpath://";
public InputSource resolveEntity(String publicId, String systemId) {
if ( systemId != null ) {
@@ -38,9 +54,9 @@
return source;
}
}
- else if ( systemId.startsWith( LOCAL_NAMESPACE ) ) {
+ else if ( systemId.startsWith( USER_NAMESPACE ) ) {
log.debug( "recognized local namespace; attempting to resolve on classpath" );
- String path = systemId.substring( LOCAL_NAMESPACE.length() );
+ String path = systemId.substring( USER_NAMESPACE.length() );
InputStream stream = resolveInLocalNamespace( path );
if ( stream == null ) {
log.debug( "unable to locate [" + systemId + "] on classpath" );
@@ -63,12 +79,11 @@
}
protected InputStream resolveInLocalNamespace(String path) {
- // attempt to find local stuff on the context classloader first...
- InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream( path );
- if ( stream == null ) {
- // next try our classloader
- stream = getClass().getClassLoader().getResourceAsStream( path );
+ try {
+ return ConfigHelper.getUserResourceAsStream( path );
}
- return stream;
+ catch( Throwable t ) {
+ return null;
+ }
}
}
|
|
From: <hib...@li...> - 2006-05-31 16:37:09
|
Author: epbernard
Date: 2006-05-31 12:37:03 -0400 (Wed, 31 May 2006)
New Revision: 9970
Added:
trunk/Hibernate3/src/org/hibernate/TypeMismatchException.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competitor.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Race.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/RemoveTest.java
Modified:
trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
Log:
HHH-1800 / EJB-189 raise exception when the id is not of the expected type
Added: trunk/Hibernate3/src/org/hibernate/TypeMismatchException.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/TypeMismatchException.java 2006-05-31 15:31:49 UTC (rev 9969)
+++ trunk/Hibernate3/src/org/hibernate/TypeMismatchException.java 2006-05-31 16:37:03 UTC (rev 9970)
@@ -0,0 +1,21 @@
+//$Id: $
+package org.hibernate;
+
+/**
+ * Used when a user provided type does not match the expected one
+ *
+ * @author Emmanuel Bernard
+ */
+public class TypeMismatchException extends HibernateException {
+ public TypeMismatchException(Throwable root) {
+ super( root );
+ }
+
+ public TypeMismatchException(String s) {
+ super( s );
+ }
+
+ public TypeMismatchException(String string, Throwable root) {
+ super( string, root );
+ }
+}
Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java 2006-05-31 15:31:49 UTC (rev 9969)
+++ trunk/Hibernate3/src/org/hibernate/event/def/DefaultLoadEventListener.java 2006-05-31 16:37:03 UTC (rev 9970)
@@ -9,8 +9,8 @@
import org.hibernate.LockMode;
import org.hibernate.NonUniqueObjectException;
import org.hibernate.ObjectDeletedException;
-import org.hibernate.ObjectNotFoundException;
import org.hibernate.PersistentObjectException;
+import org.hibernate.TypeMismatchException;
import org.hibernate.cache.CacheConcurrencyStrategy;
import org.hibernate.cache.CacheKey;
import org.hibernate.cache.entry.CacheEntry;
@@ -71,7 +71,14 @@
event.getEntityClassName()
);
}
-
+
+ Class idClass = persister.getIdentifierType().getReturnedClass();
+ if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
+ throw new TypeMismatchException(
+ "Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId()
+ );
+ }
+
EntityKey keyToLoad = new EntityKey( event.getEntityId(), persister, source.getEntityMode() );
try {
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-05-31 15:31:49 UTC (rev 9969)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-05-31 16:37:03 UTC (rev 9970)
@@ -40,6 +40,7 @@
import org.hibernate.StaleStateException;
import org.hibernate.Transaction;
import org.hibernate.UnresolvableObjectException;
+import org.hibernate.TypeMismatchException;
import org.hibernate.ejb.transaction.JoinableCMTTransaction;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
@@ -139,6 +140,9 @@
catch (MappingException e) {
throw new IllegalArgumentException( e.getMessage(), e );
}
+ catch (TypeMismatchException e ) {
+ throw new IllegalArgumentException( e.getMessage(), e );
+ }
catch (ClassCastException e) {
throw new IllegalArgumentException( e.getMessage(), e );
}
@@ -165,6 +169,9 @@
catch (MappingException e) {
throw new IllegalArgumentException( e.getMessage(), e );
}
+ catch (TypeMismatchException e ) {
+ throw new IllegalArgumentException( e.getMessage(), e );
+ }
catch (ClassCastException e) {
throw new IllegalArgumentException( e.getMessage(), e );
}
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competitor.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competitor.java 2006-05-31 15:31:49 UTC (rev 9969)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Competitor.java 2006-05-31 16:37:03 UTC (rev 9970)
@@ -0,0 +1,22 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Competitor {
+ @Id @GeneratedValue public Integer id;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+}
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java 2006-05-31 15:31:49 UTC (rev 9969)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java 2006-05-31 16:37:03 UTC (rev 9970)
@@ -0,0 +1,35 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.test.TestCase;
+
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GetReferenceTest extends TestCase {
+
+ public void testWrongIdType() throws Exception {
+ EntityManager em = factory.createEntityManager();
+ try {
+ Competitor c = em.getReference( Competitor.class, new String("30") );
+ fail("Expected IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e) {
+ //success
+ }
+ catch ( Exception e ) {
+ fail("Wrong exception: " + e );
+ }
+ em.close();
+ }
+
+ public Class[] getAnnotatedClasses() {
+ return new Class[] {
+ Competitor.class,
+ Race.class
+ };
+ }
+}
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2006-05-31 15:31:49 UTC (rev 9969)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2006-05-31 16:37:03 UTC (rev 9970)
@@ -0,0 +1,63 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.test.TestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class MergeTest extends TestCase {
+ public void testMergeWithIndexColumn() {
+ Race race = new Race();
+ race.competitors.add( new Competitor() );
+ race.competitors.add( new Competitor() );
+ race.competitors.add( new Competitor() );
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.persist( race );
+ em.flush();
+ em.clear();
+ race.competitors.add( new Competitor() );
+ race.competitors.remove( 2 );
+ race = em.merge( race );
+ em.flush();
+ em.clear();
+ race = em.find( Race.class, race.id );
+ assertEquals( 3, race.competitors.size() );
+ em.getTransaction().rollback();
+ em.close();
+ }
+
+ public void testRemoveAndMerge() {
+ Race race = new Race();
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.persist( race );
+ em.flush();
+ em.clear();
+ race = em.find(Race.class, race.id );
+ em.remove(race);
+ try {
+ race = em.merge( race );
+ em.flush();
+ fail("Should raise an IllegalArgumentException");
+ }
+ catch (IllegalArgumentException e) {
+ //all good
+ }
+ catch (Exception e) {
+ fail("Should raise an IllegalArgumentException");
+ }
+ em.getTransaction().rollback();
+ em.close();
+ }
+
+ public Class[] getAnnotatedClasses() {
+ return new Class[] {
+ Race.class,
+ Competitor.class
+ };
+ }
+}
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Race.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Race.java 2006-05-31 15:31:49 UTC (rev 9969)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Race.java 2006-05-31 16:37:03 UTC (rev 9970)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import java.util.List;
+import java.util.ArrayList;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.CascadeType;
+import javax.persistence.FetchType;
+
+import org.hibernate.annotations.IndexColumn;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Race {
+ @Id @GeneratedValue public Integer id;
+ @IndexColumn( name="index" ) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
+ public List<Competitor> competitors = new ArrayList<Competitor>();
+}
Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/RemoveTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/RemoveTest.java 2006-05-31 15:31:49 UTC (rev 9969)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/RemoveTest.java 2006-05-31 16:37:03 UTC (rev 9970)
@@ -0,0 +1,33 @@
+//$Id: $
+package org.hibernate.ejb.test.emops;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.test.TestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class RemoveTest extends TestCase {
+ public void testMergeWithIndexColumn() {
+ Race race = new Race();
+ race.competitors.add( new Competitor() );
+ race.competitors.add( new Competitor() );
+ race.competitors.add( new Competitor() );
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.persist( race );
+ em.flush();
+ em.remove( race );
+ em.flush();
+ em.getTransaction().rollback();
+ em.close();
+ }
+
+ public Class[] getAnnotatedClasses() {
+ return new Class[] {
+ Race.class,
+ Competitor.class
+ };
+ }
+}
|
|
From: <hib...@li...> - 2006-05-31 15:31:59
|
Author: epbernard
Date: 2006-05-31 11:31:49 -0400 (Wed, 31 May 2006)
New Revision: 9969
Modified:
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/TransactionImpl.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
Log:
ANN-356 Clear the PC on Rollback on RESOURCE_LOCAL Transactions
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/TransactionImpl.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/TransactionImpl.java 2006-05-31 14:28:07 UTC (rev 9968)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/TransactionImpl.java 2006-05-31 15:31:49 UTC (rev 9969)
@@ -80,9 +80,17 @@
throw new PersistenceException( "unexpected error when rollbacking", e );
}
finally {
+ try {
+ if (entityManager != null) {
+ Session session = ( (HibernateEntityManager) entityManager ).getSession();
+ if ( session != null && session.isOpen() ) session.clear();
+ }
+ }
+ catch (Throwable t) {
+ //we don't really care here since it's only for safety purpose
+ }
rollbackOnly = false;
}
- //if ( entityManager.isOpen() ) entityManager.adjustFlushMode();
}
public void setRollbackOnly() {
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2006-05-31 14:28:07 UTC (rev 9968)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2006-05-31 15:31:49 UTC (rev 9969)
@@ -202,9 +202,27 @@
catch (RollbackException e) {
//success
}
+ finally {
+ em.close();
+ }
}
+ public void testRollbackClearPC() throws Exception {
+ Book book = new Book();
+ book.name = "Stolen keys";
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.persist( book );
+ em.getTransaction().commit();
+ em.getTransaction().begin();
+ book.name = "Recovered keys";
+ em.merge( book );
+ em.getTransaction().rollback();
+ assertEquals( "Stolen keys", em.find( Book.class, book.id ).name );
+ em.close();
+ }
+
public Class[] getAnnotatedClasses() {
return new Class[]{
Book.class
|
|
From: <hib...@li...> - 2006-05-31 14:28:30
|
Author: ste...@jb...
Date: 2006-05-31 10:28:07 -0400 (Wed, 31 May 2006)
New Revision: 9968
Modified:
trunk/Hibernate3/doc/reference/en/modules/performance.xml
Log:
changed docs regarding L2 cache (EhCache no longer default)
Modified: trunk/Hibernate3/doc/reference/en/modules/performance.xml
===================================================================
--- trunk/Hibernate3/doc/reference/en/modules/performance.xml 2006-05-31 08:22:57 UTC (rev 9967)
+++ trunk/Hibernate3/doc/reference/en/modules/performance.xml 2006-05-31 14:28:07 UTC (rev 9968)
@@ -635,11 +635,14 @@
(though they may be configured to regularly expire cached data).
</para>
- <para>
- By default, Hibernate uses EHCache for JVM-level caching. (JCS support is now deprecated and will
- be removed in a future version of Hibernate.) You may choose a different implementation by
+ <para revision="1">
+ You have the option to tell Hibernate which caching implementation to use by
specifying the name of a class that implements <literal>org.hibernate.cache.CacheProvider</literal>
- using the property <literal>hibernate.cache.provider_class</literal>.
+ using the property <literal>hibernate.cache.provider_class</literal>. Hibernate
+ comes bundled with a number of built-in integrations with open-source cache providers
+ (listed below); additionally, you could implement your own and plug it in as
+ outlined above. Note that versions prior to 3.2 defaulted to use EhCache as the
+ default cache provider; that is no longer the case as of 3.2.
</para>
<table frame="topbot" id="cacheproviders" revision="1">
|
|
From: <hib...@li...> - 2006-05-31 08:23:00
|
Author: epbernard
Date: 2006-05-31 04:22:57 -0400 (Wed, 31 May 2006)
New Revision: 9967
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java
Log:
ANN-355 adjust XML access type discovery rules
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-05-31 08:13:43 UTC (rev 9966)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-05-31 08:22:57 UTC (rev 9967)
@@ -557,6 +557,7 @@
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");
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-05-31 08:13:43 UTC (rev 9966)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-05-31 08:22:57 UTC (rev 9967)
@@ -815,9 +815,10 @@
private void getEmbeddedId(List<Annotation> annotationList, XMLContext.Default defaults) {
for ( Element element : elementsForProperty ) {
if ( "embedded-id".equals( element.getName() ) ) {
- boolean properAccessOnMetadataComplete = computeProperAccessOnMetadataComplete( defaults );
- boolean properOverridingOnMetadataNonComplete = computeProperOverridingOnMetadataComplete( defaults );
- if ( properAccessOnMetadataComplete || properOverridingOnMetadataNonComplete ) {
+ //boolean properAccessOnMetadataComplete = computeProperAccessOnMetadataComplete( defaults );
+ //boolean properOverridingOnMetadataNonComplete = computeProperOverridingOnMetadataNonComplete( defaults );
+ //if ( properAccessOnMetadataComplete || properOverridingOnMetadataNonComplete ) {
+ if ( isProcessingId( defaults ) ) {
Annotation annotation = getAttributeOverrides( element, defaults );
if ( annotation != null ) annotationList.add( annotation );
annotation = getAssociationOverrides( element, defaults );
@@ -825,21 +826,21 @@
AnnotationDescriptor ad = new AnnotationDescriptor( EmbeddedId.class );
annotationList.add( AnnotationFactory.create( ad ) );
}
- else {
- if ( defaults.canUseJavaAnnotations() ) {
- if ( ! properOverridingOnMetadataNonComplete ) {
- //check that id exists on the other attribute
- //TODO Id too?
- if ( mirroredAttribute == null || ! mirroredAttribute.isAnnotationPresent(
- EmbeddedId.class
- ) ) {
- throw new AnnotationException(
- "Cannot override an property with <embedded-id> not having an @EmbeddedId already"
- );
- }
- }
- }
- }
+// else {
+// if ( defaults.canUseJavaAnnotations() ) {
+// if ( ! properOverridingOnMetadataNonComplete ) {
+// //check that id exists on the other attribute
+// //TODO Id too?
+// if ( mirroredAttribute == null || ! mirroredAttribute.isAnnotationPresent(
+// EmbeddedId.class
+// ) ) {
+// throw new AnnotationException(
+// "Cannot override an property with <embedded-id> not having an @EmbeddedId already"
+// );
+// }
+// }
+// }
+// }
}
}
if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) {
@@ -894,9 +895,10 @@
private void getId(List<Annotation> annotationList, XMLContext.Default defaults) {
for ( Element element : elementsForProperty ) {
if ( "id".equals( element.getName() ) ) {
- boolean properAccessOnMetadataComplete = computeProperAccessOnMetadataComplete( defaults );
- boolean properOverridingOnMetadataNonComplete = computeProperOverridingOnMetadataComplete( defaults );
- if ( properAccessOnMetadataComplete || properOverridingOnMetadataNonComplete ) {
+ //boolean properAccessOnMetadataComplete = computeProperAccessOnMetadataComplete( defaults );
+ //boolean properOverridingOnMetadataNonComplete = computeProperOverridingOnMetadataNonComplete( defaults );
+ boolean processId = isProcessingId( defaults );
+ if ( processId ) {
Annotation annotation = buildColumns( element );
if ( annotation != null ) annotationList.add( annotation );
annotation = buildGeneratedValue( element );
@@ -910,19 +912,19 @@
AnnotationDescriptor id = new AnnotationDescriptor( Id.class );
annotationList.add( AnnotationFactory.create( id ) );
}
- else {
- if ( defaults.canUseJavaAnnotations() ) {
- if ( ! properOverridingOnMetadataNonComplete ) {
- //check that id exists on the other attribute
- //TODO EmbeddedId too?
- if ( mirroredAttribute == null || ! mirroredAttribute.isAnnotationPresent( Id.class ) ) {
- throw new AnnotationException(
- "Cannot override an property with <id> it does not have an @Id already"
- );
- }
- }
- }
- }
+// else {
+// if ( defaults.canUseJavaAnnotations() ) {
+// if ( ! properOverridingOnMetadataNonComplete ) {
+// //check that id exists on the other attribute
+// //TODO EmbeddedId too?
+// if ( mirroredAttribute == null || ! mirroredAttribute.isAnnotationPresent( Id.class ) ) {
+// throw new AnnotationException(
+// "Cannot override a property with <id> it does not have an @Id already"
+// );
+// }
+// }
+// }
+// }
}
}
if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) {
@@ -953,7 +955,23 @@
}
}
- private boolean computeProperOverridingOnMetadataComplete(XMLContext.Default defaults) {
+ private boolean isProcessingId(XMLContext.Default defaults) {
+ boolean isExplicit = defaults.getAccess() != null;
+ boolean correctAccess =
+ ( PropertyType.PROPERTY.equals( propertyType ) && "property".equalsIgnoreCase( defaults.getAccess() ) )
+ || ( PropertyType.FIELD.equals( propertyType ) && "field".equalsIgnoreCase( defaults.getAccess() ) );
+ boolean hasId = defaults.canUseJavaAnnotations()
+ && ( super.isAnnotationPresent( Id.class ) || super.isAnnotationPresent( EmbeddedId.class ) );
+ //if ( properAccessOnMetadataComplete || properOverridingOnMetadataNonComplete ) {
+ boolean mirrorAttributeIsId = defaults.canUseJavaAnnotations() &&
+ ( mirroredAttribute.isAnnotationPresent(Id.class)
+ || mirroredAttribute.isAnnotationPresent( EmbeddedId.class ) );
+ boolean propertyIsDefault = PropertyType.PROPERTY.equals( propertyType )
+ && ! mirrorAttributeIsId;
+ return correctAccess || ( ! isExplicit && hasId ) || ( ! isExplicit && propertyIsDefault );
+ }
+
+ private boolean computeProperOverridingOnMetadataNonComplete(XMLContext.Default defaults) {
return defaults.canUseJavaAnnotations()
&& super.isAnnotationPresent( Id.class );
}
|
|
From: <hib...@li...> - 2006-05-31 08:13:47
|
Author: epbernard Date: 2006-05-31 04:13:43 -0400 (Wed, 31 May 2006) New Revision: 9966 Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java Log: NoCache is the default in hibernate core, remove the overriding Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-30 18:00:28 UTC (rev 9965) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-05-31 08:13:43 UTC (rev 9966) @@ -837,7 +837,6 @@ //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" ); |
|
From: <hib...@li...> - 2006-05-30 18:01:05
|
Author: ste...@jb...
Date: 2006-05-30 14:00:28 -0400 (Tue, 30 May 2006)
New Revision: 9965
Modified:
trunk/Hibernate3/src/org/hibernate/cache/OptimisticTreeCache.java
trunk/Hibernate3/src/org/hibernate/cache/TreeCache.java
Log:
HHH-1796 : TreeCache based providers and Fqn
Modified: trunk/Hibernate3/src/org/hibernate/cache/OptimisticTreeCache.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cache/OptimisticTreeCache.java 2006-05-30 15:40:54 UTC (rev 9964)
+++ trunk/Hibernate3/src/org/hibernate/cache/OptimisticTreeCache.java 2006-05-30 18:00:28 UTC (rev 9965)
@@ -33,14 +33,14 @@
private org.jboss.cache.TreeCache cache;
private final String regionName;
- private final String userRegionName;
+ private final Fqn regionFqn;
private OptimisticCacheSource source;
public OptimisticTreeCache(org.jboss.cache.TreeCache cache, String regionName)
throws CacheException {
this.cache = cache;
- userRegionName = regionName;
- this.regionName = regionName.replace('.', '/');
+ this.regionName = regionName;
+ this.regionFqn = Fqn.fromString( regionName.replace( '.', '/' ) );
}
@@ -69,7 +69,7 @@
);
}
}
- cache.put( new Fqn( new Object[] { regionName, key } ), ITEM, value, option );
+ cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
}
catch (Exception e) {
throw new CacheException(e);
@@ -80,7 +80,7 @@
try {
Option option = new Option();
option.setFailSilently( true );
- cache.remove( new Fqn( new Object[] { regionName, key } ), "ITEM", option );
+ cache.remove( new Fqn( regionFqn, key ), "ITEM", option );
if ( source != null ) {
if ( source.isVersioned() ) {
option.setDataVersion(
@@ -92,7 +92,7 @@
);
}
}
- cache.put( new Fqn( new Object[] { regionName, key } ), ITEM, value, option );
+ cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
}
catch (Exception e) {
throw new CacheException(e);
@@ -106,7 +106,7 @@
try {
Option option = new Option();
option.setFailSilently( true );
- return cache.get( new Fqn( new Object[] { regionName, key } ), ITEM, option );
+ return cache.get( new Fqn( regionFqn, key ), ITEM, option );
}
catch (Exception e) {
throw new CacheException(e);
@@ -115,7 +115,7 @@
public Object read(Object key) throws CacheException {
try {
- return cache.get( new Fqn( new Object[] { regionName, key } ), ITEM );
+ return cache.get( new Fqn( regionFqn, key ), ITEM );
}
catch (Exception e) {
throw new CacheException(e);
@@ -124,7 +124,7 @@
public void update(Object key, Object value) throws CacheException {
try {
- cache.put( new Fqn( new Object[] { regionName, key } ), ITEM, value );
+ cache.put( new Fqn( regionFqn, key ), ITEM, value );
}
catch (Exception e) {
throw new CacheException(e);
@@ -136,7 +136,7 @@
// do the put outside the scope of the JTA txn
Option option = new Option();
option.setFailSilently( true );
- cache.put( new Fqn( new Object[] { regionName, key } ), ITEM, value, option );
+ cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
}
catch (TimeoutException te) {
//ignore!
@@ -149,7 +149,7 @@
public void remove(Object key) throws CacheException {
try {
- cache.remove( new Fqn( new Object[] { regionName, key } ) );
+ cache.remove( new Fqn( regionFqn, key ) );
}
catch (Exception e) {
throw new CacheException(e);
@@ -158,7 +158,7 @@
public void clear() throws CacheException {
try {
- cache.remove( new Fqn(regionName) );
+ cache.remove( regionFqn );
}
catch (Exception e) {
throw new CacheException(e);
@@ -169,7 +169,7 @@
try {
Option option = new Option();
option.setCacheModeLocal( true );
- cache.remove( new Fqn( regionName ), option );
+ cache.remove( regionFqn, option );
}
catch( Exception e ) {
throw new CacheException( e );
@@ -177,11 +177,11 @@
}
public void lock(Object key) throws CacheException {
- throw new UnsupportedOperationException("TreeCache is a fully transactional cache" + regionName);
+ throw new UnsupportedOperationException( "TreeCache is a fully transactional cache" + regionName );
}
public void unlock(Object key) throws CacheException {
- throw new UnsupportedOperationException("TreeCache is a fully transactional cache: " + regionName);
+ throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
}
public long nextTimestamp() {
@@ -193,7 +193,7 @@
}
public String getRegionName() {
- return userRegionName;
+ return regionName;
}
public long getSizeInMemory() {
@@ -202,7 +202,7 @@
public long getElementCountInMemory() {
try {
- Set children = cache.getChildrenNames( new Fqn(regionName) );
+ Set children = cache.getChildrenNames( regionFqn );
return children == null ? 0 : children.size();
}
catch (Exception e) {
@@ -217,14 +217,14 @@
public Map toMap() {
try {
Map result = new HashMap();
- Set childrenNames = cache.getChildrenNames( new Fqn(regionName) );
+ Set childrenNames = cache.getChildrenNames( regionFqn );
if (childrenNames != null) {
Iterator iter = childrenNames.iterator();
while ( iter.hasNext() ) {
Object key = iter.next();
result.put(
key,
- cache.get( new Fqn( new Object[] { regionName, key } ), ITEM )
+ cache.get( new Fqn( regionFqn, key ), ITEM )
);
}
}
@@ -236,7 +236,7 @@
}
public String toString() {
- return "OptimisticTreeCache(" + userRegionName + ')';
+ return "OptimisticTreeCache(" + regionName + ')';
}
public static class DataVersionAdapter implements DataVersion {
Modified: trunk/Hibernate3/src/org/hibernate/cache/TreeCache.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cache/TreeCache.java 2006-05-30 15:40:54 UTC (rev 9964)
+++ trunk/Hibernate3/src/org/hibernate/cache/TreeCache.java 2006-05-30 18:00:28 UTC (rev 9965)
@@ -28,14 +28,14 @@
private org.jboss.cache.TreeCache cache;
private final String regionName;
- private final String userRegionName;
+ private final Fqn regionFqn;
private final TransactionManager transactionManager;
public TreeCache(org.jboss.cache.TreeCache cache, String regionName, TransactionManager transactionManager)
throws CacheException {
this.cache = cache;
- userRegionName = regionName;
- this.regionName = regionName.replace('.', '/');
+ this.regionName = regionName;
+ this.regionFqn = Fqn.fromString( regionName.replace( '.', '/' ) );
this.transactionManager = transactionManager;
}
@@ -51,7 +51,7 @@
public Object read(Object key) throws CacheException {
try {
- return cache.get( new Fqn( new Object[] { regionName, key } ), ITEM );
+ return cache.get( new Fqn( regionFqn, key ), ITEM );
}
catch (Exception e) {
throw new CacheException(e);
@@ -60,7 +60,7 @@
public void update(Object key, Object value) throws CacheException {
try {
- cache.put( new Fqn( new Object[] { regionName, key } ), ITEM, value );
+ cache.put( new Fqn( regionFqn, key ), ITEM, value );
}
catch (Exception e) {
throw new CacheException(e);
@@ -71,7 +71,7 @@
Transaction tx = suspend();
try {
//do the failfast put outside the scope of the JTA txn
- cache.putFailFast( new Fqn( new Object[] { regionName, key } ), ITEM, value, 0 );
+ cache.putFailFast( new Fqn( regionFqn, key ), ITEM, value, 0 );
}
catch (TimeoutException te) {
//ignore!
@@ -109,7 +109,7 @@
public void remove(Object key) throws CacheException {
try {
- cache.remove( new Fqn( new Object[] { regionName, key } ) );
+ cache.remove( new Fqn( regionFqn, key ) );
}
catch (Exception e) {
throw new CacheException(e);
@@ -118,7 +118,7 @@
public void clear() throws CacheException {
try {
- cache.remove( new Fqn(regionName) );
+ cache.remove( regionFqn );
}
catch (Exception e) {
throw new CacheException(e);
@@ -132,7 +132,7 @@
// exactly what is needed when we destroy() here; destroy() is used
// as part of the process of shutting down a SessionFactory; thus
// these removals should not be propogated
- cache.evict( new Fqn( regionName ) );
+ cache.evict( regionFqn );
}
catch( Exception e ) {
throw new CacheException( e );
@@ -140,11 +140,11 @@
}
public void lock(Object key) throws CacheException {
- throw new UnsupportedOperationException("TreeCache is a fully transactional cache" + regionName);
+ throw new UnsupportedOperationException( "TreeCache is a fully transactional cache" + regionName );
}
public void unlock(Object key) throws CacheException {
- throw new UnsupportedOperationException("TreeCache is a fully transactional cache: " + regionName);
+ throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
}
public long nextTimestamp() {
@@ -156,7 +156,7 @@
}
public String getRegionName() {
- return userRegionName;
+ return regionName;
}
public long getSizeInMemory() {
@@ -165,7 +165,7 @@
public long getElementCountInMemory() {
try {
- Set children = cache.getChildrenNames( new Fqn(regionName) );
+ Set children = cache.getChildrenNames( regionFqn );
return children == null ? 0 : children.size();
}
catch (Exception e) {
@@ -180,14 +180,14 @@
public Map toMap() {
try {
Map result = new HashMap();
- Set childrenNames = cache.getChildrenNames( new Fqn(regionName) );
+ Set childrenNames = cache.getChildrenNames( regionFqn );
if (childrenNames != null) {
Iterator iter = childrenNames.iterator();
while ( iter.hasNext() ) {
Object key = iter.next();
result.put(
key,
- cache.get( new Fqn( new Object[] { regionName, key } ), ITEM )
+ cache.get( new Fqn( regionFqn, key ), ITEM )
);
}
}
@@ -199,7 +199,7 @@
}
public String toString() {
- return "TreeCache(" + userRegionName + ')';
+ return "TreeCache(" + regionName + ')';
}
}
|
|
From: <hib...@li...> - 2006-05-30 15:41:04
|
Author: epbernard
Date: 2006-05-30 11:40:54 -0400 (Tue, 30 May 2006)
New Revision: 9964
Modified:
trunk/Hibernate3/src/org/hibernate/action/EntityUpdateAction.java
trunk/Hibernate3/src/org/hibernate/cache/EhCacheProvider.java
trunk/Hibernate3/src/org/hibernate/event/PostUpdateEvent.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/EJB3PostUpdateEventListener.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/TestCase.java
Log:
EJB-188 add event source to the post update event and check the status
minor fixes to ehcache
Modified: trunk/Hibernate3/src/org/hibernate/action/EntityUpdateAction.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/action/EntityUpdateAction.java 2006-05-30 14:15:54 UTC (rev 9963)
+++ trunk/Hibernate3/src/org/hibernate/action/EntityUpdateAction.java 2006-05-30 15:40:54 UTC (rev 9964)
@@ -18,6 +18,7 @@
import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.event.PreUpdateEvent;
import org.hibernate.event.PreUpdateEventListener;
+import org.hibernate.event.EventSource;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.TypeFactory;
@@ -175,7 +176,8 @@
getId(),
state,
previousState,
- getPersister()
+ getPersister(),
+ (EventSource) getSession()
);
for ( int i = 0; i < postListeners.length; i++ ) {
postListeners[i].onPostUpdate(postEvent);
@@ -192,7 +194,8 @@
getId(),
state,
previousState,
- getPersister()
+ getPersister(),
+ (EventSource) getSession()
);
for ( int i = 0; i < postListeners.length; i++ ) {
postListeners[i].onPostUpdate(postEvent);
Modified: trunk/Hibernate3/src/org/hibernate/cache/EhCacheProvider.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cache/EhCacheProvider.java 2006-05-30 14:15:54 UTC (rev 9963)
+++ trunk/Hibernate3/src/org/hibernate/cache/EhCacheProvider.java 2006-05-30 15:40:54 UTC (rev 9964)
@@ -128,11 +128,12 @@
}
} catch (net.sf.ehcache.CacheException e) {
//yukky! Don't you have subclasses for that!
+ //TODO race conditions can happen here
if (e.getMessage().startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " +
"CacheManager using the diskStorePath")) {
throw new CacheException("Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() " +
- " between repeated calls to buildSessionFactory. Consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider. Error from " +
- " ehcache was: " + e.getMessage());
+ " between repeated calls to buildSessionFactory. Consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider."
+ , e );
} else {
throw e;
}
Modified: trunk/Hibernate3/src/org/hibernate/event/PostUpdateEvent.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/PostUpdateEvent.java 2006-05-30 14:15:54 UTC (rev 9963)
+++ trunk/Hibernate3/src/org/hibernate/event/PostUpdateEvent.java 2006-05-30 15:40:54 UTC (rev 9964)
@@ -10,7 +10,7 @@
*
* @author Gavin King
*/
-public class PostUpdateEvent {
+public class PostUpdateEvent extends AbstractEvent {
private Object entity;
private EntityPersister persister;
private Object[] state;
@@ -22,8 +22,10 @@
Serializable id,
Object[] state,
Object[] oldState,
- EntityPersister persister
+ EntityPersister persister,
+ EventSource source
) {
+ super(source);
this.entity = entity;
this.id = id;
this.state = state;
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/EJB3PostUpdateEventListener.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/EJB3PostUpdateEventListener.java 2006-05-30 14:15:54 UTC (rev 9963)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/EJB3PostUpdateEventListener.java 2006-05-30 15:40:54 UTC (rev 9964)
@@ -8,6 +8,8 @@
import org.hibernate.event.PostUpdateEvent;
import org.hibernate.event.PostUpdateEventListener;
+import org.hibernate.engine.EntityEntry;
+import org.hibernate.engine.Status;
/**
* @author <a href="mailto:kab...@jb...">Kabir Khan</a>
@@ -32,6 +34,10 @@
public void onPostUpdate(PostUpdateEvent event) {
Object entity = event.getEntity();
- callbackHandler.postUpdate( entity );
+ EntityEntry entry = (EntityEntry) event.getSession().getPersistenceContext().getEntityEntries().get( entity );
+ //mimic the preUpdate filter
+ if ( Status.DELETED != entry.getStatus() ) {
+ callbackHandler.postUpdate( entity );
+ }
}
}
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/TestCase.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/TestCase.java 2006-05-30 14:15:54 UTC (rev 9963)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/TestCase.java 2006-05-30 15:40:54 UTC (rev 9964)
@@ -38,6 +38,10 @@
public abstract Class[] getAnnotatedClasses();
+ public String[] getEjb3DD() {
+ return new String[] {};
+ }
+
public Map<Class, String> getCachedClasses() {
return new HashMap<Class, String>();
}
@@ -88,6 +92,13 @@
entry.getValue()
);
}
+ if ( getEjb3DD().length > 0 ) {
+ ArrayList<String> dds = new ArrayList<String>();
+ for ( String dd : getEjb3DD() ) {
+ dds.add( dd );
+ }
+ config.put( HibernatePersistence.XML_FILE_NAMES, dds );
+ }
return config;
}
}
|
|
From: <hib...@li...> - 2006-05-30 14:16:13
|
Author: ste...@jb...
Date: 2006-05-30 10:15:54 -0400 (Tue, 30 May 2006)
New Revision: 9963
Modified:
trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
Log:
HHH-1791: incorrect handling of generated="insert" and update="false" combo
Modified: trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-05-30 13:56:00 UTC (rev 9962)
+++ trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-05-30 14:15:54 UTC (rev 9963)
@@ -1209,28 +1209,44 @@
Attribute generatedNode = node.attribute( "generated" );
String generationName = generatedNode == null ? null : generatedNode.getValue();
PropertyGeneration generation = PropertyGeneration.parse( generationName );
- // values marked as "generated=always" or "generated=insert" cannot also be marked
- // insertable and/or updateable.
- // insertable and updateable are the defaults, so if the user did not specify
- // just override; otherwise, throw an exception
+ property.setGeneration( generation );
+
if ( generation == PropertyGeneration.ALWAYS || generation == PropertyGeneration.INSERT ) {
- if ( insertNode != null && property.isInsertable() ) {
- throw new MappingException(
- "cannot specify both insert=\"true\" and generated=\"" + generation.getName() +
- "\" for property: " +
- propName
+ // generated properties can *never* be insertable...
+ if ( property.isInsertable() ) {
+ if ( insertNode == null ) {
+ // insertable simply because that is the user did not specify
+ // anything; just override it
+ property.setInsertable( false );
+ }
+ else {
+ // the user specifically supplied insert="true",
+ // which constitutes an illegal combo
+ throw new MappingException(
+ "cannot specify both insert=\"true\" and generated=\"" + generation.getName() +
+ "\" for property: " +
+ propName
);
- }
- if ( updateNode != null && property.isUpdateable() && generation == PropertyGeneration.ALWAYS ) {
- throw new MappingException(
- "cannot specify both update=\"true\" and generated=\"" + generation.getName() +
- "\" for property: " +
- propName
+ }
+ }
+
+ // properties generated on update can never be updateable...
+ if ( property.isUpdateable() && generation == PropertyGeneration.ALWAYS ) {
+ if ( updateNode == null ) {
+ // updateable only because the user did not specify
+ // anything; just override it
+ property.setUpdateable( false );
+ }
+ else {
+ // the user specifically supplied update="true",
+ // which constitutes an illegal combo
+ throw new MappingException(
+ "cannot specify both update=\"true\" and generated=\"" + generation.getName() +
+ "\" for property: " +
+ propName
);
- }
- property.setInsertable( false );
- property.setUpdateable( generation != PropertyGeneration.ALWAYS );
- property.setGeneration( generation );
+ }
+ }
}
boolean isLazyable = "property".equals( node.getName() ) ||
|
|
From: <hib...@li...> - 2006-05-30 13:56:05
|
Author: max...@jb... Date: 2006-05-30 09:56:00 -0400 (Tue, 30 May 2006) New Revision: 9962 Modified: trunk/HibernateExt/tools/readme.txt Log: remove obsolete version statement that people apparently look at ;) Modified: trunk/HibernateExt/tools/readme.txt =================================================================== --- trunk/HibernateExt/tools/readme.txt 2006-05-30 13:17:45 UTC (rev 9961) +++ trunk/HibernateExt/tools/readme.txt 2006-05-30 13:56:00 UTC (rev 9962) @@ -1,6 +1,5 @@ Hibernate Tools - Tools for Hibernate ===================================== -version 3.1.0alpha5, 21. August 2005 Instructions ------------ |
|
From: <hib...@li...> - 2006-05-30 13:17:52
|
Author: max...@jb...
Date: 2006-05-30 09:17:45 -0400 (Tue, 30 May 2006)
New Revision: 9961
Added:
trunk/Hibernate3/test/org/hibernate/test/pretty/SQLFormatterTest.java
Modified:
trunk/Hibernate3/src/org/hibernate/pretty/Formatter.java
Log:
HHH-1748 formatter breaks on single tick in e.g. a comment
+ Tests for the formatter
Modified: trunk/Hibernate3/src/org/hibernate/pretty/Formatter.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/pretty/Formatter.java 2006-05-30 13:17:40 UTC (rev 9960)
+++ trunk/Hibernate3/src/org/hibernate/pretty/Formatter.java 2006-05-30 13:17:45 UTC (rev 9961)
@@ -112,7 +112,7 @@
t = tokens.nextToken();
token += t;
}
- while ( !"'".equals(t) );
+ while ( !"'".equals(t) && tokens.hasMoreTokens() ); // cannot handle single quotes
}
else if ( "\"".equals(token) ) {
String t;
@@ -365,30 +365,6 @@
if ( args.length>0 ) System.out.println(
new Formatter( StringHelper.join(" ", args) ).format()
);
- System.out.println(
- new Formatter("insert into Address (city, state, zip, \"from\") values (?, ?, ?, 'insert value')").format()
- );
- System.out.println(
- new Formatter("delete from Address where id = ? and version = ?").format()
- );
- System.out.println(
- new Formatter("update Address set city = ?, state=?, zip=?, version = ? where id = ? and version = ?").format()
- );
- System.out.println(
- new Formatter("update Address set city = ?, state=?, zip=?, version = ? where id in (select aid from Person)").format()
- );
- System.out.println(
- new Formatter("select p.name, a.zipCode, count(*) from Person p left outer join Employee e on e.id = p.id and p.type = 'E' and (e.effective>? or e.effective<?) join Address a on a.pid = p.id where upper(p.name) like 'G%' and p.age > 100 and (p.sex = 'M' or p.sex = 'F') and coalesce( trim(a.street), a.city, (a.zip) ) is not null order by p.name asc, a.zipCode asc").format()
- );
- System.out.println(
- new Formatter("select ( (m.age - p.age) * 12 ), trim(upper(p.name)) from Person p, Person m where p.mother = m.id and ( p.age = (select max(p0.age) from Person p0 where (p0.mother=m.id)) and p.name like ? )").format()
- );
- System.out.println(
- new Formatter("select * from Address a join Person p on a.pid = p.id, Person m join Address b on b.pid = m.id where p.mother = m.id and p.name like ?").format()
- );
- System.out.println(
- new Formatter("select case when p.age > 50 then 'old' when p.age > 18 then 'adult' else 'child' end from Person p where ( case when p.age > 50 then 'old' when p.age > 18 then 'adult' else 'child' end ) like ?").format()
- );
}
}
Added: trunk/Hibernate3/test/org/hibernate/test/pretty/SQLFormatterTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/pretty/SQLFormatterTest.java 2006-05-30 13:17:40 UTC (rev 9960)
+++ trunk/Hibernate3/test/org/hibernate/test/pretty/SQLFormatterTest.java 2006-05-30 13:17:45 UTC (rev 9961)
@@ -0,0 +1,40 @@
+package org.hibernate.test.pretty;
+
+import java.util.StringTokenizer;
+
+import junit.framework.TestCase;
+
+import org.hibernate.pretty.Formatter;
+
+public class SQLFormatterTest extends TestCase {
+
+ public void testNoLoss() {
+ assertNoLoss("insert into Address (city, state, zip, \"from\") values (?, ?, ?, 'insert value')");
+ assertNoLoss("delete from Address where id = ? and version = ?");
+ assertNoLoss("update Address set city = ?, state=?, zip=?, version = ? where id = ? and version = ?");
+ assertNoLoss("update Address set city = ?, state=?, zip=?, version = ? where id in (select aid from Person)");
+ assertNoLoss("select p.name, a.zipCode, count(*) from Person p left outer join Employee e on e.id = p.id and p.type = 'E' and (e.effective>? or e.effective<?) join Address a on a.pid = p.id where upper(p.name) like 'G%' and p.age > 100 and (p.sex = 'M' or p.sex = 'F') and coalesce( trim(a.street), a.city, (a.zip) ) is not null order by p.name asc, a.zipCode asc");
+ assertNoLoss("select ( (m.age - p.age) * 12 ), trim(upper(p.name)) from Person p, Person m where p.mother = m.id and ( p.age = (select max(p0.age) from Person p0 where (p0.mother=m.id)) and p.name like ? )");
+ assertNoLoss("select * from Address a join Person p on a.pid = p.id, Person m join Address b on b.pid = m.id where p.mother = m.id and p.name like ?");
+ assertNoLoss("select case when p.age > 50 then 'old' when p.age > 18 then 'adult' else 'child' end from Person p where ( case when p.age > 50 then 'old' when p.age > 18 then 'adult' else 'child' end ) like ?");
+ assertNoLoss("/* Here we' go! */ select case when p.age > 50 then 'old' when p.age > 18 then 'adult' else 'child' end from Person p where ( case when p.age > 50 then 'old' when p.age > 18 then 'adult' else 'child' end ) like ?");
+ }
+
+ private void assertNoLoss(String query) {
+ String formattedQuery = new Formatter(query).format();
+ StringTokenizer formatted = new StringTokenizer(formattedQuery," \t\n\r\f()");
+ StringTokenizer plain = new StringTokenizer(query," \t\n\r\f()");
+
+ System.out.println("Original: " + query);
+ System.out.println("Formatted: " + formattedQuery);
+ while(formatted.hasMoreTokens() && plain.hasMoreTokens()) {
+ String plainToken = plain.nextToken();
+ String formattedToken = formatted.nextToken();
+ assertEquals("formatter did not return the same token",plainToken, formattedToken);
+ }
+ assertFalse(formatted.hasMoreTokens());
+ assertFalse(plain.hasMoreTokens());
+ }
+
+
+}
|