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 not atomic, since it uses the same 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 JDONoTxPersistenceAspect extends JDOBasePersistenceAspect {
30:
31: protected PersistenceManager contextManager;
32:
33: public JDONoTxPersistenceAspect(OIDManager iOIDManager) {
34: super (iOIDManager);
35: }
36:
37: public JDONoTxPersistenceAspect(JDOBasePersistenceAspect iSource) {
38: super (iSource);
39: }
40:
41: public JDONoTxPersistenceAspect(Map<String, String> iConfiguration) {
42: super (iConfiguration);
43: }
44:
45: @Override
46: protected void init() {
47: contextManager = JDOPersistenceHelper
48: .getPersistenceManager(factory);
49:
50: strategy = STRATEGY_STANDARD;
51: }
52:
53: @Override
54: public PersistenceManager getPersistenceManager() {
55: return contextManager;
56: }
57:
58: @Override
59: protected void beginOperation(PersistenceManager iManager) {
60: iManager.currentTransaction().begin();
61: iManager.currentTransaction().setRetainValues(true);
62: }
63:
64: @Override
65: protected void endOperation(PersistenceManager iManager) {
66: iManager.currentTransaction().commit();
67: }
68:
69: @Override
70: protected void closeOperation(PersistenceManager iManager) {
71: }
72:
73: public void commit() {
74: close();
75: }
76:
77: public void rollback() {
78: close();
79: }
80:
81: public void close() {
82: JDOPersistenceHelper.closeManager(contextManager);
83: }
84:
85: @Override
86: protected void finalize() throws Throwable {
87: JDOPersistenceHelper.closeManager(contextManager);
88: }
89: }
|