1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package net.wotonomy.access;
19
20 import net.wotonomy.foundation.NSArray;
21 import net.wotonomy.foundation.NSMutableArray;
22 import net.wotonomy.foundation.NSNotificationCenter;
23
24 /***
25 *
26 * @author ezamudio@nasoft.com
27 * @author $Author: cgruber $
28 * @version $Revision: 894 $
29 */
30
31 public abstract class EOAdaptorContext {
32
33 public static final String AdaptorContextBeginTransactionNotification = "AdaptorContextBeginTransaction";
34 public static final String AdaptorContextCommitTransactionNotification = "AdaptorContextCommitTransaction";
35 public static final String AdaptorContextRollbackTransactionNotification = "AdaptorContextRollbackTransaction";
36
37 protected EOAdaptor _adaptor;
38 protected NSMutableArray _channels = new NSMutableArray();
39 protected boolean _hasOpenTransaction;
40
41 public EOAdaptorContext(EOAdaptor adaptor) {
42 super();
43 _adaptor = adaptor;
44 }
45
46 public EOAdaptor adaptor() {
47 return _adaptor;
48 }
49
50 public abstract void beginTransaction();
51
52 public abstract void commitTransaction();
53
54 public abstract void rollbackTransaction();
55
56 public abstract EOAdaptorChannel createAdaptorChannel();
57
58 public abstract void handleDroppedConnection();
59
60 public NSArray channels() {
61 return new NSArray(_channels);
62 }
63
64 public boolean hasBusyChannels() {
65 for (int i = 0; i < _channels.count(); i++) {
66 EOAdaptorChannel chan = (EOAdaptorChannel)_channels.objectAtIndex(i);
67 if (chan.isFetchInProgress())
68 return true;
69 }
70 return false;
71 }
72
73 public boolean hasOpenChannels() {
74 for (int i = 0; i < _channels.count(); i++) {
75 EOAdaptorChannel chan = (EOAdaptorChannel)_channels.objectAtIndex(i);
76 if (chan.isOpen())
77 return true;
78 }
79 return false;
80 }
81
82 public boolean hasOpenTransaction() {
83 return _hasOpenTransaction;
84 }
85
86 public void transactionDidBegin() {
87 _hasOpenTransaction = true;
88 NSNotificationCenter.defaultCenter().postNotification(
89 AdaptorContextBeginTransactionNotification, this);
90 }
91
92 public void transactionDidCommit() {
93 _hasOpenTransaction = false;
94 NSNotificationCenter.defaultCenter().postNotification(
95 AdaptorContextCommitTransactionNotification, this);
96 }
97
98 public void transactionDidRollback() {
99 _hasOpenTransaction = false;
100 NSNotificationCenter.defaultCenter().postNotification(
101 AdaptorContextRollbackTransactionNotification, this);
102 }
103
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118