EL container integration; support for contextual objects; removal of deprecated Spring 2.0 functionality; Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-20 02:10:53 +00:00
parent 369821dd66
commit 347f34c68a
281 changed files with 6120 additions and 9903 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -331,12 +331,12 @@ public abstract class HibernateAccessor implements InitializingBean, BeanFactory
if (existingTransaction) {
FlushMode previousFlushMode = session.getFlushMode();
if (!previousFlushMode.lessThan(FlushMode.COMMIT)) {
session.setFlushMode(FlushMode.NEVER);
session.setFlushMode(FlushMode.MANUAL);
return previousFlushMode;
}
}
else {
session.setFlushMode(FlushMode.NEVER);
session.setFlushMode(FlushMode.MANUAL);
}
}
else if (getFlushMode() == FLUSH_EAGER) {

View File

@@ -17,7 +17,6 @@
package org.springframework.orm.hibernate3;
import java.sql.Connection;
import javax.sql.DataSource;
import org.hibernate.ConnectionReleaseMode;
@@ -111,7 +110,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
* support nested transactions! Hence, do not expect Hibernate access code to
* semantically participate in a nested transaction.</i>
*
* <p>Requires Hibernate 3.1 or later, as of Spring 2.5.
* <p>Requires Hibernate 3.2 or later, as of Spring 3.0.
*
* @author Juergen Hoeller
* @since 1.2
@@ -255,11 +254,6 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
* call <code>Connection.setReadOnly(true)</code> for read-only transactions
* anymore either. If this flag is turned off, no cleanup of a JDBC Connection
* is required after a transaction, since no Connection settings will get modified.
* <p>It is recommended to turn this flag off if running against Hibernate 3.1
* and a connection pool that does not reset connection settings (for example,
* Jakarta Commons DBCP). To keep this flag turned on, you can set the
* "hibernate.connection.release_mode" property to "on_close" instead,
* or consider using a smarter connection pool (for example, C3P0).
* @see java.sql.Connection#setTransactionIsolation
* @see java.sql.Connection#setReadOnly
*/
@@ -297,14 +291,14 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
/**
* Set whether to perform an early flush before proceeding with a commit.
* <p>Default is "false", performing an implicit flush as part of the
* actual commit step. Switch this to "true" in order to enforce an
* explicit flush before the before-commit synchronization phase, making
* flushed state visible to <code>beforeCommit</code> callbacks of registered
* <p>Default is "false", performing an implicit flush as part of the actual
* commit step. Switch this to "true" in order to enforce an explicit early
* flush right <i>before</i> the actual commit step.
* <p>An early flush happens before the before-commit synchronization phase,
* making flushed state visible to <code>beforeCommit</code> callbacks of registered
* {@link org.springframework.transaction.support.TransactionSynchronization}
* objects.
* <p>Such explicit flush behavior is also consistent with Spring-driven
* flushing in a JTA transaction environment, so may also be enforced for
* objects. Such explicit flush behavior is consistent with Spring-driven
* flushing in a JTA transaction environment, so may also get enforced for
* consistency with JTA transaction behavior.
* @see #prepareForCommit
*/
@@ -533,7 +527,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
if (definition.isReadOnly() && txObject.isNewSession()) {
// Just set to NEVER in case of a new Session for this transaction.
session.setFlushMode(FlushMode.NEVER);
session.setFlushMode(FlushMode.MANUAL);
}
if (!definition.isReadOnly() && !txObject.isNewSession()) {
@@ -550,7 +544,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
// Register transaction timeout.
int timeout = determineTimeout(definition);
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
// Use Hibernate's own transaction timeout mechanism on Hibernate 3.1
// Use Hibernate's own transaction timeout mechanism on Hibernate 3.1+
// Applies to all statements, also to inserts, updates and deletes!
hibTx = session.getTransaction();
hibTx.setTimeout(timeout);
@@ -633,7 +627,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
@Override
protected void prepareForCommit(DefaultTransactionStatus status) {
if (this.earlyFlushBeforeCommit) {
if (this.earlyFlushBeforeCommit && status.isNewTransaction()) {
HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction();
Session session = txObject.getSessionHolder().getSession();
if (!session.getFlushMode().lessThan(FlushMode.COMMIT)) {
@@ -645,7 +639,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
throw convertHibernateAccessException(ex);
}
finally {
session.setFlushMode(FlushMode.NEVER);
session.setFlushMode(FlushMode.MANUAL);
}
}
}

View File

@@ -26,7 +26,6 @@ import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import javax.sql.DataSource;
import javax.transaction.TransactionManager;
@@ -90,7 +89,7 @@ import org.springframework.util.StringUtils;
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewFilter} /
* {@link org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor}.
*
* <p><b>Requires Hibernate 3.1 or later.</b> Note that this factory will use
* <p><b>Requires Hibernate 3.2 or later.</b> Note that this factory will use
* "on_close" as default Hibernate connection release mode, unless in the
* case of a "jtaTransactionManager" specified, for the reason that
* this is appropriate for most Spring-based applications (in particular when
@@ -447,8 +446,6 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
* &lt;prop key="com.mycompany.Product"&gt;read-only,myRegion&lt;/prop&gt;
* &lt;/props&gt;
* &lt;/property&gt;</pre>
* Note that appending a cache region name (with a comma separator) is only
* supported on Hibernate 3.1, where this functionality is publically available.
* @param entityCacheStrategies properties that define entity cache strategies,
* with class names as keys and cache concurrency strategies as values
* @see org.hibernate.cfg.Configuration#setCacheConcurrencyStrategy(String, String)
@@ -469,8 +466,6 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
* &lt;prop key="com.mycompany.Product.categories"&gt;read-only,myRegion&lt;/prop&gt;
* &lt;/props&gt;
* &lt;/property&gt;</pre>
* Note that appending a cache region name (with a comma separator) is only
* supported on Hibernate 3.1, where this functionality is publically available.
* @param collectionCacheStrategies properties that define collection cache strategies,
* with collection roles as keys and cache concurrency strategies as values
* @see org.hibernate.cfg.Configuration#setCollectionCacheConcurrencyStrategy(String, String)
@@ -481,10 +476,8 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
/**
* Specify the Hibernate event listeners to register, with listener types
* as keys and listener objects as values.
* <p>Instead of a single listener object, you can also pass in a list
* or set of listeners objects as value. However, this is only supported
* on Hibernate 3.1.
* as keys and listener objects as values. Instead of a single listener object,
* you can also pass in a list or set of listeners objects as value.
* <p>See the Hibernate documentation for further details on listener types
* and associated listener interfaces.
* @param eventListeners Map with listener type Strings as keys and
@@ -549,7 +542,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
try {
if (isExposeTransactionAwareSessionFactory()) {
// Set Hibernate 3.1 CurrentSessionContext implementation,
// Set Hibernate 3.1+ CurrentSessionContext implementation,
// providing the Spring-managed Session as current Session.
// Can be overridden by a custom value for the corresponding Hibernate property.
config.setProperty(

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -100,7 +100,7 @@ public class OpenSessionInViewFilter extends OncePerRequestFilter {
private boolean singleSession = true;
private FlushMode flushMode = FlushMode.NEVER;
private FlushMode flushMode = FlushMode.MANUAL;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -217,36 +217,6 @@ public interface JdoOperations {
*/
Collection detachCopyAll(Collection entities);
/**
* Reattach the given detached instance (for example, a web form object) with
* the current JDO transaction, merging its changes into the current persistence
* instance that represents the corresponding entity.
* <p>Note that as of JDO 2.0 final, this operation is equivalent to a
* <code>makePersistent</code> call, with the latter method returning the
* persistence instance.
* @param detachedEntity the detached instance to attach
* @return the corresponding persistent instance
* @deprecated in favor of {@link #makePersistent(Object)}.
* To be removed in Spring 3.0.
*/
@Deprecated
Object attachCopy(Object detachedEntity);
/**
* Reattach the given detached instances (for example, web form objects) with
* the current JDO transaction, merging their changes into the current persistence
* instances that represent the corresponding entities.
* <p>Note that as of JDO 2.0 final, this operation is equivalent to a
* <code>makePersistentAll</code> call, with the latter method returning the
* persistence instance.
* @param detachedEntities the detached instances to reattach
* @return the corresponding persistent instances
* @deprecated in favor of {@link #makePersistentAll(java.util.Collection)}.
* To be removed in Spring 3.0.
*/
@Deprecated
Collection attachCopyAll(Collection detachedEntities);
/**
* Flush all transactional modifications to the database.
* <p>Only invoke this for selective eager flushing, for example when JDBC code

View File

@@ -377,24 +377,6 @@ public class JdoTemplate extends JdoAccessor implements JdoOperations {
}, true);
}
/**
* @deprecated in favor of {@link #makePersistent(Object)}.
* To be removed in Spring 3.0.
*/
@Deprecated
public Object attachCopy(Object detachedEntity) {
return makePersistent(detachedEntity);
}
/**
* @deprecated in favor of {@link #makePersistentAll(java.util.Collection)}.
* To be removed in Spring 3.0.
*/
@Deprecated
public Collection attachCopyAll(Collection detachedEntities) {
return makePersistentAll(detachedEntities);
}
public void flush() throws DataAccessException {
execute(new JdoCallback() {
public Object doInJdo(PersistenceManager pm) throws JDOException {

View File

@@ -21,12 +21,10 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
@@ -85,7 +83,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
private String persistenceUnitName;
private final Map jpaPropertyMap = new HashMap();
private final Map<Object, Object> jpaPropertyMap = new HashMap<Object, Object>();
private Class<? extends EntityManagerFactory> entityManagerFactoryInterface;
@@ -168,7 +166,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
* @see javax.persistence.Persistence#createEntityManagerFactory(String, java.util.Map)
* @see javax.persistence.spi.PersistenceProvider#createContainerEntityManagerFactory(javax.persistence.spi.PersistenceUnitInfo, java.util.Map)
*/
public void setJpaPropertyMap(Map jpaProperties) {
public void setJpaPropertyMap(Map<?, ?> jpaProperties) {
if (jpaProperties != null) {
this.jpaPropertyMap.putAll(jpaProperties);
}
@@ -262,10 +260,9 @@ public abstract class AbstractEntityManagerFactoryBean implements
if (this.persistenceProvider == null) {
this.persistenceProvider = this.jpaVendorAdapter.getPersistenceProvider();
}
Map vendorPropertyMap = this.jpaVendorAdapter.getJpaPropertyMap();
Map<?, ?> vendorPropertyMap = this.jpaVendorAdapter.getJpaPropertyMap();
if (vendorPropertyMap != null) {
for (Iterator it = vendorPropertyMap.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
for (Map.Entry entry : vendorPropertyMap.entrySet()) {
if (!this.jpaPropertyMap.containsKey(entry.getKey())) {
this.jpaPropertyMap.put(entry.getKey(), entry.getValue());
}
@@ -422,7 +419,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
else if (method.getName().equals("hashCode")) {
// Use hashCode of EntityManagerFactory proxy.
return new Integer(System.identityHashCode(proxy));
return System.identityHashCode(proxy);
}
else if (method.getDeclaringClass().isAssignableFrom(EntityManagerFactoryInfo.class)) {
return method.invoke(this.entityManagerFactoryInfo, args);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -102,7 +102,19 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
}
protected Session getSession(EntityManager em) {
return ((HibernateEntityManager) em).getSession();
if (em instanceof HibernateEntityManager) {
return ((HibernateEntityManager) em).getSession();
}
else {
Object delegate = em.getDelegate();
if (delegate instanceof Session) {
return (Session) delegate;
}
else {
throw new IllegalStateException(
"Cannot obtain native Hibernate Session from given JPA EntityManager: " + em.getClass());
}
}
}

View File

@@ -18,7 +18,6 @@ package org.springframework.orm.jpa.vendor;
import java.util.Map;
import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceProvider;
@@ -30,7 +29,7 @@ import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.InformixDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.SybaseDialect;
@@ -42,7 +41,7 @@ import org.springframework.orm.jpa.JpaDialect;
/**
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for
* Hibernate EntityManager. Developed and tested against Hibernate 3.2.
* Hibernate EntityManager. Developed and tested against Hibernate 3.2 and 3.3.
*
* <p>Exposes Hibernate's persistence provider and EntityManager extension interface,
* and supports {@link AbstractJpaVendorAdapter}'s common configuration settings.
@@ -106,7 +105,7 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter {
case HSQL: return HSQLDialect.class;
case INFORMIX: return InformixDialect.class;
case MYSQL: return MySQLDialect.class;
case ORACLE: return Oracle9Dialect.class; // deprecated since Hibernate 3.2.5 - to be updated in Spring 3.0
case ORACLE: return Oracle9iDialect.class;
case POSTGRESQL: return PostgreSQLDialect.class;
case SQL_SERVER: return SQLServerDialect.class;
case SYBASE: return SybaseDialect.class;