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 |
|
|
27 |
|
|
28 |
|
|
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 |
0 |
protected NSMutableArray _channels = new NSMutableArray(); |
39 |
|
protected boolean _hasOpenTransaction; |
40 |
|
|
41 |
|
public EOAdaptorContext(EOAdaptor adaptor) { |
42 |
0 |
super(); |
43 |
0 |
_adaptor = adaptor; |
44 |
0 |
} |
45 |
|
|
46 |
|
public EOAdaptor adaptor() { |
47 |
0 |
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 |
0 |
return new NSArray(_channels); |
62 |
|
} |
63 |
|
|
64 |
|
public boolean hasBusyChannels() { |
65 |
0 |
for (int i = 0; i < _channels.count(); i++) { |
66 |
0 |
EOAdaptorChannel chan = (EOAdaptorChannel)_channels.objectAtIndex(i); |
67 |
0 |
if (chan.isFetchInProgress()) |
68 |
0 |
return true; |
69 |
|
} |
70 |
0 |
return false; |
71 |
|
} |
72 |
|
|
73 |
|
public boolean hasOpenChannels() { |
74 |
0 |
for (int i = 0; i < _channels.count(); i++) { |
75 |
0 |
EOAdaptorChannel chan = (EOAdaptorChannel)_channels.objectAtIndex(i); |
76 |
0 |
if (chan.isOpen()) |
77 |
0 |
return true; |
78 |
|
} |
79 |
0 |
return false; |
80 |
|
} |
81 |
|
|
82 |
|
public boolean hasOpenTransaction() { |
83 |
0 |
return _hasOpenTransaction; |
84 |
|
} |
85 |
|
|
86 |
|
public void transactionDidBegin() { |
87 |
0 |
_hasOpenTransaction = true; |
88 |
0 |
NSNotificationCenter.defaultCenter().postNotification( |
89 |
0 |
AdaptorContextBeginTransactionNotification, this); |
90 |
0 |
} |
91 |
|
|
92 |
|
public void transactionDidCommit() { |
93 |
0 |
_hasOpenTransaction = false; |
94 |
0 |
NSNotificationCenter.defaultCenter().postNotification( |
95 |
0 |
AdaptorContextCommitTransactionNotification, this); |
96 |
0 |
} |
97 |
|
|
98 |
|
public void transactionDidRollback() { |
99 |
0 |
_hasOpenTransaction = false; |
100 |
0 |
NSNotificationCenter.defaultCenter().postNotification( |
101 |
0 |
AdaptorContextRollbackTransactionNotification, this); |
102 |
0 |
} |
103 |
|
|
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|