01: /*
02: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.romaframework.aspect.persistence.jdo;
17:
18: import java.util.Map;
19:
20: import javax.jdo.PersistenceManager;
21:
22: /**
23: * Class to handle persistence using JPOX tool and JDO 2 technology. Every method is atomic, since it uses a different JDO
24: * PersistenceManager for all. Assure to call commit() or rollback() methods when finished to avoid resource consumption. JDO 2.0:
25: * http://jcp.org/en/jsr/detail?id=243 <br/> JPOX: http://www.jpox.org
26: *
27: * @author Luca Garulli (luca.garulli@assetdata.it)
28: */
29: public class JDOAtomicPersistenceAspect extends
30: JDOBasePersistenceAspect {
31:
32: public JDOAtomicPersistenceAspect(OIDManager iOIDManager) {
33: super (iOIDManager);
34: }
35:
36: public JDOAtomicPersistenceAspect(JDOBasePersistenceAspect iSource) {
37: super (iSource);
38: }
39:
40: public JDOAtomicPersistenceAspect(Map<String, String> iConfiguration) {
41: super (iConfiguration);
42: }
43:
44: @Override
45: protected void init() {
46: strategy = STRATEGY_DETACHING;
47: }
48:
49: @Override
50: public PersistenceManager getPersistenceManager() {
51: PersistenceManager pm = JDOPersistenceHelper
52: .getPersistenceManager(factory);
53: pm.setDetachAllOnCommit(true);
54: return pm;
55: }
56:
57: @Override
58: protected void beginOperation(PersistenceManager iManager) {
59: iManager.currentTransaction().begin();
60: iManager.currentTransaction().setRetainValues(true);
61: }
62:
63: @Override
64: protected void endOperation(PersistenceManager iManager) {
65: iManager.currentTransaction().commit();
66: }
67:
68: @Override
69: protected void closeOperation(PersistenceManager iManager) {
70: JDOPersistenceHelper.closeManager(iManager);
71: }
72:
73: public void commit() {
74: }
75:
76: public void rollback() {
77: }
78:
79: public void close() {
80: }
81:
82: @Override
83: protected void finalize() throws Throwable {
84: shutdown();
85: }
86: }
|