diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java index 4588559289..5b08921b71 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -91,7 +91,7 @@ public class DefaultJdoDialect implements JdoDialect, PersistenceExceptionTransl * @see javax.jdo.PersistenceManagerFactory#getConnectionFactory() * @see PersistenceManagerFactoryUtils#newJdbcExceptionTranslator(Object) */ - DefaultJdoDialect(Object connectionFactory) { + public DefaultJdoDialect(Object connectionFactory) { this.jdbcExceptionTranslator = PersistenceManagerFactoryUtils.newJdbcExceptionTranslator(connectionFactory); } diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoAccessor.java b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoAccessor.java index 4cb9128d33..d747628b82 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoAccessor.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -47,7 +47,11 @@ import org.springframework.dao.DataAccessException; * @see JdoTemplate * @see JdoInterceptor * @see #setFlushEager + * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage + * (see {@link TransactionAwarePersistenceManagerFactoryProxy} and + * {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean}) */ +@Deprecated public abstract class JdoAccessor implements InitializingBean { /** Logger available to subclasses */ diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoCallback.java b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoCallback.java index dada9cf5cd..b079e01b28 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoCallback.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoCallback.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -40,7 +40,11 @@ import javax.jdo.PersistenceManager; * @since 03.06.2003 * @see JdoTemplate * @see JdoTransactionManager + * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage + * (see {@link TransactionAwarePersistenceManagerFactoryProxy} and + * {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean}) */ +@Deprecated public interface JdoCallback { /** diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoInterceptor.java b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoInterceptor.java index 8bc86f5fc4..1a3c51d789 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoInterceptor.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2011 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. @@ -68,7 +68,11 @@ import org.springframework.transaction.support.TransactionSynchronizationManager * @see PersistenceManagerFactoryUtils#getPersistenceManager * @see JdoTransactionManager * @see JdoTemplate + * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage + * and AOP-driven exception translation through + * {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor} */ +@Deprecated public class JdoInterceptor extends JdoAccessor implements MethodInterceptor { private boolean exceptionConversionEnabled = true; diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoOperations.java b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoOperations.java index 9a1122d7cc..16b73839d9 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoOperations.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -48,7 +48,11 @@ import org.springframework.dao.DataAccessException; * @see JdoDialect * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor + * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage + * (see {@link TransactionAwarePersistenceManagerFactoryProxy} and + * {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean}) */ +@Deprecated public interface JdoOperations { /** diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoTemplate.java b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoTemplate.java index 50f82155c3..0f25a17d63 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoTemplate.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -89,7 +89,11 @@ import org.springframework.util.ClassUtils; * @see org.springframework.transaction.jta.JtaTransactionManager * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor + * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage + * (see {@link TransactionAwarePersistenceManagerFactoryProxy} and + * {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean}) */ +@Deprecated public class JdoTemplate extends JdoAccessor implements JdoOperations { private boolean allowCreate = true; diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/JdoDaoSupport.java b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/JdoDaoSupport.java index 2843651f7f..23feeb358a 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/JdoDaoSupport.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/JdoDaoSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2011 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. @@ -53,7 +53,11 @@ import org.springframework.orm.jdo.PersistenceManagerFactoryUtils; * @see #releasePersistenceManager * @see org.springframework.orm.jdo.JdoTemplate * @see org.springframework.orm.jdo.JdoInterceptor + * @deprecated as of Spring 3.1, in favor of native PersistenceManager usage + * (see {@link org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy} + * and {@link SpringPersistenceManagerProxyBean}) */ +@Deprecated public abstract class JdoDaoSupport extends DaoSupport { private JdoTemplate jdoTemplate; @@ -67,7 +71,7 @@ public abstract class JdoDaoSupport extends DaoSupport { */ public final void setPersistenceManagerFactory(PersistenceManagerFactory persistenceManagerFactory) { if (this.jdoTemplate == null || persistenceManagerFactory != this.jdoTemplate.getPersistenceManagerFactory()) { - this.jdoTemplate = createJdoTemplate(persistenceManagerFactory); + this.jdoTemplate = createJdoTemplate(persistenceManagerFactory); } } diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/SpringPersistenceManagerProxyBean.java b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/SpringPersistenceManagerProxyBean.java index 4188558833..a27a1c7f2b 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/SpringPersistenceManagerProxyBean.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/SpringPersistenceManagerProxyBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -21,10 +21,13 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; import javax.jdo.Query; import org.springframework.beans.factory.FactoryBean; -import org.springframework.orm.jdo.JdoAccessor; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.orm.jdo.DefaultJdoDialect; +import org.springframework.orm.jdo.JdoDialect; import org.springframework.orm.jdo.PersistenceManagerFactoryUtils; import org.springframework.util.Assert; @@ -56,7 +59,11 @@ import org.springframework.util.Assert; * @see org.springframework.orm.jdo.PersistenceManagerFactoryUtils#getPersistenceManager * @see org.springframework.orm.jdo.PersistenceManagerFactoryUtils#releasePersistenceManager */ -public class SpringPersistenceManagerProxyBean extends JdoAccessor implements FactoryBean { +public class SpringPersistenceManagerProxyBean implements FactoryBean, InitializingBean { + + private PersistenceManagerFactory persistenceManagerFactory; + + private JdoDialect jdoDialect; private Class persistenceManagerInterface = PersistenceManager.class; @@ -65,6 +72,36 @@ public class SpringPersistenceManagerProxyBean extends JdoAccessor implements Fa private PersistenceManager proxy; + /** + * Set the target PersistenceManagerFactory for this proxy. + */ + public void setPersistenceManagerFactory(PersistenceManagerFactory persistenceManagerFactory) { + this.persistenceManagerFactory = persistenceManagerFactory; + } + + /** + * Return the target PersistenceManagerFactory for this proxy. + */ + protected PersistenceManagerFactory getPersistenceManagerFactory() { + return this.persistenceManagerFactory; + } + + /** + * Set the JDO dialect to use for this proxy. + *

Default is a DefaultJdoDialect based on the PersistenceManagerFactory's + * underlying DataSource, if any. + */ + public void setJdoDialect(JdoDialect jdoDialect) { + this.jdoDialect = jdoDialect; + } + + /** + * Return the JDO dialect to use for this proxy. + */ + protected JdoDialect getJdoDialect() { + return this.jdoDialect; + } + /** * Specify the PersistenceManager interface to expose, * possibly including vendor extensions. @@ -107,9 +144,14 @@ public class SpringPersistenceManagerProxyBean extends JdoAccessor implements Fa return this.allowCreate; } - @Override public void afterPropertiesSet() { - super.afterPropertiesSet(); + if (getPersistenceManagerFactory() == null) { + throw new IllegalArgumentException("Property 'persistenceManagerFactory' is required"); + } + // Build default JdoDialect if none explicitly specified. + if (this.jdoDialect == null) { + this.jdoDialect = new DefaultJdoDialect(getPersistenceManagerFactory().getConnectionFactory()); + } this.proxy = (PersistenceManager) Proxy.newProxyInstance( getPersistenceManagerFactory().getClass().getClassLoader(), new Class[] {getPersistenceManagerInterface()}, new PersistenceManagerInvocationHandler());