1 | |
package org.apache.ojb.otm.kit; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import org.apache.ojb.broker.Identity; |
19 | |
import org.apache.ojb.otm.OTMKit; |
20 | |
import org.apache.ojb.otm.copy.*; |
21 | |
import org.apache.ojb.otm.lock.map.InMemoryLockMap; |
22 | |
import org.apache.ojb.otm.lock.map.LockMap; |
23 | |
import org.apache.ojb.otm.lock.wait.LockWaitStrategy; |
24 | |
import org.apache.ojb.otm.lock.wait.TimeoutStrategy; |
25 | |
import org.apache.ojb.otm.swizzle.CopySwizzling; |
26 | |
import org.apache.ojb.otm.swizzle.Swizzling; |
27 | |
import org.apache.ojb.otm.transaction.LocalTransactionFactory; |
28 | |
import org.apache.ojb.otm.transaction.TransactionFactory; |
29 | |
|
30 | |
import java.io.Serializable; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class SimpleKit extends OTMKit |
40 | |
{ |
41 | |
|
42 | |
private static SimpleKit _instance; |
43 | |
|
44 | |
protected TransactionFactory _txFactory; |
45 | |
protected Swizzling _swizzlingStrategy; |
46 | |
protected LockWaitStrategy _lockWaitStrategy; |
47 | |
protected LockMap _lockMap; |
48 | |
protected ObjectCopyStrategy _noOpCopyStrategy; |
49 | |
protected ObjectCopyStrategy _defaultCopyStrategy; |
50 | |
protected ObjectCopyStrategy _cloneableCopyStrategy; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
protected SimpleKit() |
56 | |
{ |
57 | |
super(); |
58 | |
_txFactory = new LocalTransactionFactory(); |
59 | |
_swizzlingStrategy = new CopySwizzling(); |
60 | |
_lockWaitStrategy = new TimeoutStrategy(); |
61 | |
_lockMap = new InMemoryLockMap(); |
62 | |
_noOpCopyStrategy = new NoOpObjectCopyStrategy(); |
63 | |
|
64 | |
|
65 | |
_defaultCopyStrategy = new MetadataObjectCopyStrategy(); |
66 | |
_cloneableCopyStrategy = new CloneableObjectCopyStrategy(); |
67 | |
} |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public static SimpleKit getInstance() |
73 | |
{ |
74 | |
if (_instance == null) |
75 | |
{ |
76 | |
_instance = new SimpleKit(); |
77 | |
} |
78 | |
return _instance; |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
protected TransactionFactory getTransactionFactory() |
89 | |
{ |
90 | |
return _txFactory; |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public Swizzling getSwizzlingStrategy() |
97 | |
{ |
98 | |
return _swizzlingStrategy; |
99 | |
} |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public LockWaitStrategy getLockWaitStrategy() |
106 | |
{ |
107 | |
return _lockWaitStrategy; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public LockMap getLockMap() |
114 | |
{ |
115 | |
return _lockMap; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public ObjectCopyStrategy getCopyStrategy(Identity oid) |
122 | |
{ |
123 | |
Class clazz = oid.getClass(); |
124 | |
|
125 | |
if (OjbCloneable.class.isAssignableFrom(clazz)) |
126 | |
{ |
127 | |
return _cloneableCopyStrategy; |
128 | |
} |
129 | |
else if (Serializable.class.isAssignableFrom(clazz)) |
130 | |
{ |
131 | |
return _defaultCopyStrategy; |
132 | |
} |
133 | |
else |
134 | |
{ |
135 | |
return _noOpCopyStrategy; |
136 | |
} |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
public boolean isImplicitLockingUsed() |
146 | |
{ |
147 | |
return true; |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public boolean isInsertVerified() |
155 | |
{ |
156 | |
return false; |
157 | |
} |
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
public boolean isEagerInsert(Object obj) |
163 | |
{ |
164 | |
return false; |
165 | |
} |
166 | |
} |