Skip to content

Commit ba2c8fc

Browse files
committed
deprecated JdoTemplate and co in favor of native PersistenceManager usage
1 parent feed594 commit ba2c8fc

File tree

8 files changed

+80
-14
lines changed

8 files changed

+80
-14
lines changed

org.springframework.orm/src/main/java/org/springframework/orm/jdo/DefaultJdoDialect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,7 +91,7 @@ public DefaultJdoDialect() {
9191
* @see javax.jdo.PersistenceManagerFactory#getConnectionFactory()
9292
* @see PersistenceManagerFactoryUtils#newJdbcExceptionTranslator(Object)
9393
*/
94-
DefaultJdoDialect(Object connectionFactory) {
94+
public DefaultJdoDialect(Object connectionFactory) {
9595
this.jdbcExceptionTranslator = PersistenceManagerFactoryUtils.newJdbcExceptionTranslator(connectionFactory);
9696
}
9797

org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoAccessor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,11 @@
4747
* @see JdoTemplate
4848
* @see JdoInterceptor
4949
* @see #setFlushEager
50+
* @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
51+
* (see {@link TransactionAwarePersistenceManagerFactoryProxy} and
52+
* {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean})
5053
*/
54+
@Deprecated
5155
public abstract class JdoAccessor implements InitializingBean {
5256

5357
/** Logger available to subclasses */

org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoCallback.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,11 @@
4040
* @since 03.06.2003
4141
* @see JdoTemplate
4242
* @see JdoTransactionManager
43+
* @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
44+
* (see {@link TransactionAwarePersistenceManagerFactoryProxy} and
45+
* {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean})
4346
*/
47+
@Deprecated
4448
public interface JdoCallback<T> {
4549

4650
/**

org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoInterceptor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,7 +68,11 @@
6868
* @see PersistenceManagerFactoryUtils#getPersistenceManager
6969
* @see JdoTransactionManager
7070
* @see JdoTemplate
71+
* @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
72+
* and AOP-driven exception translation through
73+
* {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor}
7174
*/
75+
@Deprecated
7276
public class JdoInterceptor extends JdoAccessor implements MethodInterceptor {
7377

7478
private boolean exceptionConversionEnabled = true;

org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoOperations.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,11 @@
4848
* @see JdoDialect
4949
* @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter
5050
* @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor
51+
* @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
52+
* (see {@link TransactionAwarePersistenceManagerFactoryProxy} and
53+
* {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean})
5154
*/
55+
@Deprecated
5256
public interface JdoOperations {
5357

5458
/**

org.springframework.orm/src/main/java/org/springframework/orm/jdo/JdoTemplate.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,7 +89,11 @@
8989
* @see org.springframework.transaction.jta.JtaTransactionManager
9090
* @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter
9191
* @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor
92+
* @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
93+
* (see {@link TransactionAwarePersistenceManagerFactoryProxy} and
94+
* {@link org.springframework.orm.jdo.support.SpringPersistenceManagerProxyBean})
9295
*/
96+
@Deprecated
9397
public class JdoTemplate extends JdoAccessor implements JdoOperations {
9498

9599
private boolean allowCreate = true;

org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/JdoDaoSupport.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,7 +53,11 @@
5353
* @see #releasePersistenceManager
5454
* @see org.springframework.orm.jdo.JdoTemplate
5555
* @see org.springframework.orm.jdo.JdoInterceptor
56+
* @deprecated as of Spring 3.1, in favor of native PersistenceManager usage
57+
* (see {@link org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy}
58+
* and {@link SpringPersistenceManagerProxyBean})
5659
*/
60+
@Deprecated
5761
public abstract class JdoDaoSupport extends DaoSupport {
5862

5963
private JdoTemplate jdoTemplate;
@@ -67,7 +71,7 @@ public abstract class JdoDaoSupport extends DaoSupport {
6771
*/
6872
public final void setPersistenceManagerFactory(PersistenceManagerFactory persistenceManagerFactory) {
6973
if (this.jdoTemplate == null || persistenceManagerFactory != this.jdoTemplate.getPersistenceManagerFactory()) {
70-
this.jdoTemplate = createJdoTemplate(persistenceManagerFactory);
74+
this.jdoTemplate = createJdoTemplate(persistenceManagerFactory);
7175
}
7276
}
7377

org.springframework.orm/src/main/java/org/springframework/orm/jdo/support/SpringPersistenceManagerProxyBean.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,10 +21,13 @@
2121
import java.lang.reflect.Method;
2222
import java.lang.reflect.Proxy;
2323
import javax.jdo.PersistenceManager;
24+
import javax.jdo.PersistenceManagerFactory;
2425
import javax.jdo.Query;
2526

2627
import org.springframework.beans.factory.FactoryBean;
27-
import org.springframework.orm.jdo.JdoAccessor;
28+
import org.springframework.beans.factory.InitializingBean;
29+
import org.springframework.orm.jdo.DefaultJdoDialect;
30+
import org.springframework.orm.jdo.JdoDialect;
2831
import org.springframework.orm.jdo.PersistenceManagerFactoryUtils;
2932
import org.springframework.util.Assert;
3033

@@ -56,7 +59,11 @@
5659
* @see org.springframework.orm.jdo.PersistenceManagerFactoryUtils#getPersistenceManager
5760
* @see org.springframework.orm.jdo.PersistenceManagerFactoryUtils#releasePersistenceManager
5861
*/
59-
public class SpringPersistenceManagerProxyBean extends JdoAccessor implements FactoryBean<PersistenceManager> {
62+
public class SpringPersistenceManagerProxyBean implements FactoryBean<PersistenceManager>, InitializingBean {
63+
64+
private PersistenceManagerFactory persistenceManagerFactory;
65+
66+
private JdoDialect jdoDialect;
6067

6168
private Class<? extends PersistenceManager> persistenceManagerInterface = PersistenceManager.class;
6269

@@ -65,6 +72,36 @@ public class SpringPersistenceManagerProxyBean extends JdoAccessor implements Fa
6572
private PersistenceManager proxy;
6673

6774

75+
/**
76+
* Set the target PersistenceManagerFactory for this proxy.
77+
*/
78+
public void setPersistenceManagerFactory(PersistenceManagerFactory persistenceManagerFactory) {
79+
this.persistenceManagerFactory = persistenceManagerFactory;
80+
}
81+
82+
/**
83+
* Return the target PersistenceManagerFactory for this proxy.
84+
*/
85+
protected PersistenceManagerFactory getPersistenceManagerFactory() {
86+
return this.persistenceManagerFactory;
87+
}
88+
89+
/**
90+
* Set the JDO dialect to use for this proxy.
91+
* <p>Default is a DefaultJdoDialect based on the PersistenceManagerFactory's
92+
* underlying DataSource, if any.
93+
*/
94+
public void setJdoDialect(JdoDialect jdoDialect) {
95+
this.jdoDialect = jdoDialect;
96+
}
97+
98+
/**
99+
* Return the JDO dialect to use for this proxy.
100+
*/
101+
protected JdoDialect getJdoDialect() {
102+
return this.jdoDialect;
103+
}
104+
68105
/**
69106
* Specify the PersistenceManager interface to expose,
70107
* possibly including vendor extensions.
@@ -107,9 +144,14 @@ protected boolean isAllowCreate() {
107144
return this.allowCreate;
108145
}
109146

110-
@Override
111147
public void afterPropertiesSet() {
112-
super.afterPropertiesSet();
148+
if (getPersistenceManagerFactory() == null) {
149+
throw new IllegalArgumentException("Property 'persistenceManagerFactory' is required");
150+
}
151+
// Build default JdoDialect if none explicitly specified.
152+
if (this.jdoDialect == null) {
153+
this.jdoDialect = new DefaultJdoDialect(getPersistenceManagerFactory().getConnectionFactory());
154+
}
113155
this.proxy = (PersistenceManager) Proxy.newProxyInstance(
114156
getPersistenceManagerFactory().getClass().getClassLoader(),
115157
new Class[] {getPersistenceManagerInterface()}, new PersistenceManagerInvocationHandler());

0 commit comments

Comments
 (0)