Revision 46315
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DefaultTransaction.java | ||
---|---|---|
37 | 37 |
import org.gvsig.fmap.dal.spi.DataTransactionServices; |
38 | 38 |
import org.gvsig.tools.dispose.Disposable; |
39 | 39 |
import org.gvsig.tools.dispose.DisposeUtils; |
40 |
import org.gvsig.tools.observer.BaseNotification; |
|
41 |
import org.gvsig.tools.observer.ObservableHelper; |
|
42 |
import org.gvsig.tools.observer.Observer; |
|
40 | 43 |
import org.slf4j.Logger; |
41 | 44 |
import org.slf4j.LoggerFactory; |
42 | 45 |
|
... | ... | |
55 | 58 |
private Map<String,DataStore> stores; |
56 | 59 |
private boolean inProgress; |
57 | 60 |
private List<Disposable> disposables; |
61 |
private ObservableHelper observableHelper; |
|
58 | 62 |
|
59 | 63 |
public DefaultTransaction() { |
60 | 64 |
this.code = UUID.randomUUID().toString().replace("-", ""); |
... | ... | |
63 | 67 |
this.disposables = new ArrayList<>(); |
64 | 68 |
this.inProgress = false; |
65 | 69 |
this.connections = new HashMap<>(); |
70 |
this.observableHelper = new ObservableHelper(); |
|
66 | 71 |
} |
67 | 72 |
|
68 | 73 |
@Override |
... | ... | |
75 | 80 |
if( this.inProgress ) { |
76 | 81 |
throw new IllegalStateException("Transaction already started."); |
77 | 82 |
} |
83 |
this.observableHelper.notifyObservers(this, new BaseNotification("BEGIN", null)); |
|
78 | 84 |
this.inProgress = true; |
79 | 85 |
} |
80 | 86 |
|
... | ... | |
92 | 98 |
} |
93 | 99 |
} |
94 | 100 |
} |
101 |
for (ConnectionService connection : this.connections.values()) { |
|
102 |
connection.finish(); |
|
103 |
} |
|
104 |
this.observableHelper.notifyObservers(this, new BaseNotification("COMMIT", null)); |
|
95 | 105 |
this.inProgress = false; |
96 | 106 |
} |
97 | 107 |
|
... | ... | |
109 | 119 |
} |
110 | 120 |
} |
111 | 121 |
} |
122 |
for (ConnectionService connection : this.connections.values()) { |
|
123 |
connection.abort(); |
|
124 |
} |
|
125 |
this.observableHelper.notifyObservers(this, new BaseNotification("ROLLBACK", null)); |
|
112 | 126 |
this.inProgress = false; |
113 | 127 |
} |
114 | 128 |
|
... | ... | |
285 | 299 |
if( resource instanceof SupportTransactions ) { |
286 | 300 |
((SupportTransactions) resource).setTransaction(null); |
287 | 301 |
} |
288 |
DisposeUtils.disposeQuietly(resource); |
|
289 |
|
|
302 |
DisposeUtils.disposeQuietly(resource); |
|
290 | 303 |
} |
304 |
for (ConnectionService connection : this.connections.values()) { |
|
305 |
connection.dispose(); |
|
306 |
} |
|
291 | 307 |
this.disposables = null; |
292 | 308 |
this.stores = null; |
293 | 309 |
} |
... | ... | |
319 | 335 |
public boolean existsConnection(String id) { |
320 | 336 |
return this.connections.containsKey(id); |
321 | 337 |
} |
338 |
|
|
339 |
@Override |
|
340 |
public void addObserver(Observer obsrvr) { |
|
341 |
this.observableHelper.addObserver(obsrvr); |
|
342 |
} |
|
343 |
|
|
344 |
@Override |
|
345 |
public void deleteObserver(Observer obsrvr) { |
|
346 |
this.observableHelper.deleteObserver(obsrvr); |
|
347 |
} |
|
348 |
|
|
349 |
@Override |
|
350 |
public void deleteObservers() { |
|
351 |
this.observableHelper.deleteObservers(); |
|
352 |
} |
|
322 | 353 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java | ||
---|---|---|
171 | 171 |
import org.gvsig.tools.exception.BaseException; |
172 | 172 |
import org.gvsig.tools.exception.NotYetImplemented; |
173 | 173 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
174 |
import org.gvsig.tools.observer.BaseNotification; |
|
174 | 175 |
import org.gvsig.tools.observer.Observable; |
175 | 176 |
import org.gvsig.tools.observer.Observer; |
176 | 177 |
import org.gvsig.tools.observer.impl.DelegateWeakReferencingObservable; |
... | ... | |
252 | 253 |
private String editingSessionCode; |
253 | 254 |
|
254 | 255 |
private CachedValue<Feature> sampleFeatureCache; |
256 |
|
|
257 |
private final Observer transactionObserver; |
|
255 | 258 |
|
256 | 259 |
private class StateInformation extends HashMap<Object, Object> { |
257 | 260 |
|
... | ... | |
303 | 306 |
public DefaultFeatureStore() { |
304 | 307 |
this.state = new StateInformation(); |
305 | 308 |
this.sampleFeatureCache = null; |
309 |
this.transactionObserver = new Observer() { |
|
310 |
@Override |
|
311 |
public void update(Observable o, Object o1) { |
|
312 |
if( o1 instanceof BaseNotification && ( |
|
313 |
((BaseNotification)o1).isOfType("ROLLBACK") || |
|
314 |
((BaseNotification)o1).isOfType("COMMIT") |
|
315 |
) ) { |
|
316 |
featureCount = null; |
|
317 |
} |
|
318 |
} |
|
319 |
}; |
|
306 | 320 |
} |
307 | 321 |
|
308 | 322 |
@Override |
... | ... | |
499 | 513 |
this.delegateObservable = null; |
500 | 514 |
} |
501 | 515 |
DisposeUtils.disposeQuietly(this.resourcesStorage); |
516 |
if( this.transaction!=null ) { |
|
517 |
this.transaction.deleteObserver(transactionObserver); |
|
518 |
this.transaction = null; |
|
519 |
} |
|
502 | 520 |
} |
503 | 521 |
|
504 | 522 |
@Override |
... | ... | |
3835 | 3853 |
|
3836 | 3854 |
@Override |
3837 | 3855 |
public void setTransaction(DataTransaction transaction) { |
3856 |
if( this.transaction!=null ) { |
|
3857 |
this.transaction.deleteObserver(transactionObserver); |
|
3858 |
} |
|
3838 | 3859 |
this.transaction = transaction; |
3839 | 3860 |
if (transaction instanceof DataTransactionServices) { |
3840 | 3861 |
this.provider.setTransaction((DataTransactionServices) transaction); |
3841 | 3862 |
} |
3863 |
if( transaction!=null ) { |
|
3864 |
transaction.addObserver(transactionObserver); |
|
3865 |
} |
|
3842 | 3866 |
} |
3843 | 3867 |
|
3844 | 3868 |
@Override |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/test/java/org/gvsig/fmap/dal/store/jdbc2/AbstractTestTransaction.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.jdbc2; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Objects; |
|
6 |
import junit.framework.TestCase; |
|
7 |
import static junit.framework.TestCase.assertEquals; |
|
8 |
import org.apache.commons.lang3.tuple.Pair; |
|
9 |
import org.apache.log4j.Level; |
|
10 |
import org.apache.log4j.LogManager; |
|
11 |
import org.gvsig.fmap.dal.DALLocator; |
|
12 |
import org.gvsig.fmap.dal.DataTransaction; |
|
13 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
|
14 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
15 |
import org.gvsig.fmap.dal.feature.Feature; |
|
16 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
17 |
import org.gvsig.fmap.dal.store.jdbc2.impl.ResulSetControlerBase; |
|
18 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
19 |
import org.slf4j.Logger; |
|
20 |
import org.slf4j.LoggerFactory; |
|
21 |
|
|
22 |
@SuppressWarnings("UseSpecificCatch") |
|
23 |
public abstract class AbstractTestTransaction extends TestCase { |
|
24 |
|
|
25 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractTestTransaction.class); |
|
26 |
|
|
27 |
protected AbstractTestUtils utils; |
|
28 |
|
|
29 |
public AbstractTestTransaction(String testName) { |
|
30 |
super(testName); |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
protected void setUp() throws Exception { |
|
35 |
super.setUp(); |
|
36 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
protected void tearDown() throws Exception { |
|
41 |
super.tearDown(); |
|
42 |
} |
|
43 |
|
|
44 |
public AbstractTestUtils utils() { |
|
45 |
if (this.utils == null) { |
|
46 |
this.utils = this.createUtils(); |
|
47 |
} |
|
48 |
return this.utils; |
|
49 |
} |
|
50 |
|
|
51 |
protected abstract AbstractTestUtils createUtils(); |
|
52 |
|
|
53 |
private List<Pair<org.apache.log4j.Logger,Level>> get_loggers(Object... classes) { |
|
54 |
List<Pair<org.apache.log4j.Logger,Level>> loggers = new ArrayList<>(); |
|
55 |
for (Object theClass : classes) { |
|
56 |
org.apache.log4j.Logger logger; |
|
57 |
if( theClass instanceof Class ) { |
|
58 |
logger = LogManager.getLogger((Class)theClass); |
|
59 |
} else { |
|
60 |
logger = LogManager.getLogger(Objects.toString(theClass, null)); |
|
61 |
} |
|
62 |
if( logger!=null ) { |
|
63 |
loggers.add(Pair.of(logger,logger.getLevel())); |
|
64 |
} |
|
65 |
} |
|
66 |
return loggers; |
|
67 |
} |
|
68 |
|
|
69 |
private void restore_level(List<Pair<org.apache.log4j.Logger,Level>> loggers) { |
|
70 |
for (Pair<org.apache.log4j.Logger, Level> logger : loggers) { |
|
71 |
logger.getLeft().setLevel(logger.getRight()); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
private void set_level(List<Pair<org.apache.log4j.Logger,Level>> loggers, Level level) { |
|
76 |
for (Pair<org.apache.log4j.Logger, Level> logger : loggers) { |
|
77 |
logger.getLeft().setLevel(level); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
protected void testTransaction1() throws Exception { |
|
82 |
DataTransaction transaction = null; |
|
83 |
Feature f = null; |
|
84 |
try { |
|
85 |
if (!utils().isTheDatabaseAvailable()) { |
|
86 |
return; |
|
87 |
} |
|
88 |
|
|
89 |
List<Pair<org.apache.log4j.Logger, Level>> loggers = get_loggers(JDBCUtils.class, ResulSetControlerBase.class, "org.gvsig.fmap.dal.store.h2.H2SpatialHelper"); |
|
90 |
set_level(loggers, Level.INFO); |
|
91 |
|
|
92 |
FeatureStore sourceStore = utils().openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/esp_poblaciones-nogeom.csv"); |
|
93 |
JDBCServerExplorer explorer1 = utils().openServerExplorer("testTransaction1"); |
|
94 |
JDBCServerExplorer explorer2 = utils().openServerExplorer("testTransaction2"); |
|
95 |
|
|
96 |
utils().info_jdbc(explorer1); |
|
97 |
|
|
98 |
// Importamos el CSV en la bbdd |
|
99 |
LOGGER.info("Creating table 'poblaciones' in h2 temporary database."); |
|
100 |
utils().drop_tables(explorer1, "poblaciones1", "poblaciones2", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
101 |
utils().create_table_from(explorer1, "poblaciones1", sourceStore); |
|
102 |
utils().create_table_from(explorer1, "poblaciones2", sourceStore); |
|
103 |
utils().insert_into_from(explorer1, "poblaciones1", sourceStore, FeatureStore.MODE_APPEND); |
|
104 |
utils().insert_into_from(explorer1, "poblaciones2", sourceStore, FeatureStore.MODE_APPEND); |
|
105 |
|
|
106 |
utils().drop_tables(explorer2, "poblaciones3", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
107 |
utils().create_table_from(explorer2, "poblaciones3", sourceStore); |
|
108 |
|
|
109 |
transaction = DALLocator.getDataManager().createTransaction(); |
|
110 |
transaction.begin(); |
|
111 |
|
|
112 |
transaction.add(explorer1); |
|
113 |
transaction.add(explorer2); |
|
114 |
|
|
115 |
FeatureStore dbstore1 = utils().openStore(explorer1, "poblaciones1"); |
|
116 |
transaction.add(dbstore1); |
|
117 |
FeatureStore dbstore2 = utils().openStore(explorer1, "poblaciones2"); |
|
118 |
transaction.add(dbstore2); |
|
119 |
FeatureStore dbstore3 = utils().openStore(explorer2, "poblaciones3"); |
|
120 |
transaction.add(dbstore3); |
|
121 |
|
|
122 |
dbstore1.edit(); |
|
123 |
dbstore2.edit(); |
|
124 |
dbstore3.edit(); |
|
125 |
|
|
126 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
127 |
EditableFeature ef = f.getEditable(); |
|
128 |
ef.set("POB_NOMBRE", "Ibarra-1"); |
|
129 |
dbstore1.update(ef); |
|
130 |
|
|
131 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
132 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
133 |
|
|
134 |
dbstore1.finishEditing(); |
|
135 |
|
|
136 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
137 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
138 |
|
|
139 |
transaction.rollback(); |
|
140 |
|
|
141 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
142 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
143 |
|
|
144 |
transaction.dispose(); |
|
145 |
|
|
146 |
|
|
147 |
} catch (Throwable th) { |
|
148 |
DataTransaction.rollbackQuietly(transaction); |
|
149 |
LOGGER.warn("", th); |
|
150 |
throw th; |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
protected void testTransaction2() throws Exception { |
|
155 |
try { |
|
156 |
if (!utils().isTheDatabaseAvailable()) { |
|
157 |
return; |
|
158 |
} |
|
159 |
|
|
160 |
List<Pair<org.apache.log4j.Logger, Level>> loggers = get_loggers(JDBCUtils.class, ResulSetControlerBase.class, "org.gvsig.fmap.dal.store.h2.H2SpatialHelper"); |
|
161 |
set_level(loggers, Level.INFO); |
|
162 |
|
|
163 |
FeatureStore sourceStore = utils().openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/esp_poblaciones-nogeom.csv"); |
|
164 |
JDBCServerExplorer explorer1 = utils().openServerExplorer("testTransaction1"); |
|
165 |
JDBCServerExplorer explorer2 = utils().openServerExplorer("testTransaction2"); |
|
166 |
|
|
167 |
utils().info_jdbc(explorer1); |
|
168 |
|
|
169 |
// Importamos el CSV en la bbdd |
|
170 |
LOGGER.info("Creating table 'poblaciones' in h2 temporary database."); |
|
171 |
utils().drop_tables(explorer1, "poblaciones1", "poblaciones2", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
172 |
utils().create_table_from(explorer1, "poblaciones1", sourceStore); |
|
173 |
utils().create_table_from(explorer1, "poblaciones2", sourceStore); |
|
174 |
utils().insert_into_from(explorer1, "poblaciones1", sourceStore, FeatureStore.MODE_APPEND); |
|
175 |
utils().insert_into_from(explorer1, "poblaciones2", sourceStore, FeatureStore.MODE_APPEND); |
|
176 |
|
|
177 |
utils().drop_tables(explorer2, "poblaciones3", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
178 |
utils().create_table_from(explorer2, "poblaciones3", sourceStore); |
|
179 |
|
|
180 |
DataTransaction transaction = DALLocator.getDataManager().createTransaction(); |
|
181 |
transaction.begin(); |
|
182 |
|
|
183 |
transaction.add(explorer1); |
|
184 |
transaction.add(explorer2); |
|
185 |
|
|
186 |
FeatureStore dbstore1 = utils().openStore(explorer1, "poblaciones1"); |
|
187 |
transaction.add(dbstore1); |
|
188 |
FeatureStore dbstore2 = utils().openStore(explorer1, "poblaciones2"); |
|
189 |
transaction.add(dbstore2); |
|
190 |
FeatureStore dbstore3 = utils().openStore(explorer2, "poblaciones3"); |
|
191 |
transaction.add(dbstore3); |
|
192 |
|
|
193 |
dbstore1.edit(); |
|
194 |
dbstore2.edit(); |
|
195 |
dbstore3.edit(); |
|
196 |
|
|
197 |
Feature f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
198 |
EditableFeature ef = f.getEditable(); |
|
199 |
ef.set("POB_NOMBRE", "Ibarra-1"); |
|
200 |
dbstore1.update(ef); |
|
201 |
|
|
202 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
203 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
204 |
|
|
205 |
transaction.commit(); |
|
206 |
|
|
207 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
208 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
209 |
|
|
210 |
transaction.dispose(); |
|
211 |
|
|
212 |
|
|
213 |
} catch (Throwable th) { |
|
214 |
LOGGER.warn("", th); |
|
215 |
throw th; |
|
216 |
} |
|
217 |
} |
|
218 |
|
|
219 |
protected void testTransaction3() throws Exception { |
|
220 |
Feature f = null; |
|
221 |
EditableFeature ef = null; |
|
222 |
try { |
|
223 |
if (!utils().isTheDatabaseAvailable()) { |
|
224 |
return; |
|
225 |
} |
|
226 |
|
|
227 |
List<Pair<org.apache.log4j.Logger, Level>> loggers = get_loggers(JDBCUtils.class, ResulSetControlerBase.class, "org.gvsig.fmap.dal.store.h2.H2SpatialHelper"); |
|
228 |
set_level(loggers, Level.INFO); |
|
229 |
|
|
230 |
FeatureStore sourceStore = utils().openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/esp_poblaciones-nogeom.csv"); |
|
231 |
JDBCServerExplorer explorer1 = utils().openServerExplorer("testTransaction1"); |
|
232 |
JDBCServerExplorer explorer2 = utils().openServerExplorer("testTransaction2"); |
|
233 |
|
|
234 |
utils().info_jdbc(explorer1); |
|
235 |
|
|
236 |
// Importamos el CSV en la bbdd |
|
237 |
LOGGER.info("Creating table 'poblaciones' in h2 temporary database."); |
|
238 |
utils().drop_tables(explorer1, "poblaciones1", "poblaciones2", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
239 |
utils().create_table_from(explorer1, "poblaciones1", sourceStore); |
|
240 |
utils().create_table_from(explorer1, "poblaciones2", sourceStore); |
|
241 |
utils().insert_into_from(explorer1, "poblaciones1", sourceStore, FeatureStore.MODE_APPEND); |
|
242 |
utils().insert_into_from(explorer1, "poblaciones2", sourceStore, FeatureStore.MODE_APPEND); |
|
243 |
|
|
244 |
utils().drop_tables(explorer2, "poblaciones3", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
245 |
utils().create_table_from(explorer2, "poblaciones3", sourceStore); |
|
246 |
utils().insert_into_from(explorer2, "poblaciones3", sourceStore, FeatureStore.MODE_APPEND); |
|
247 |
|
|
248 |
DataTransaction transaction = DALLocator.getDataManager().createTransaction(); |
|
249 |
transaction.begin(); |
|
250 |
|
|
251 |
transaction.add(explorer1); |
|
252 |
transaction.add(explorer2); |
|
253 |
|
|
254 |
FeatureStore dbstore1 = utils().openStore(explorer1, "poblaciones1"); |
|
255 |
transaction.add(dbstore1); |
|
256 |
FeatureStore dbstore2 = utils().openStore(explorer1, "poblaciones2"); |
|
257 |
transaction.add(dbstore2); |
|
258 |
FeatureStore dbstore3 = utils().openStore(explorer2, "poblaciones3"); |
|
259 |
transaction.add(dbstore3); |
|
260 |
|
|
261 |
dbstore1.edit(); |
|
262 |
dbstore2.edit(); |
|
263 |
dbstore3.edit(); |
|
264 |
|
|
265 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
266 |
ef = f.getEditable(); |
|
267 |
ef.set("POB_NOMBRE", "Ibarra-1"); |
|
268 |
dbstore1.update(ef); |
|
269 |
|
|
270 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
271 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
272 |
|
|
273 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
274 |
ef = f.getEditable(); |
|
275 |
ef.set("POB_NOMBRE", "Ibarra-2"); |
|
276 |
dbstore2.update(ef); |
|
277 |
|
|
278 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
279 |
assertEquals("", "Ibarra-2", f.getString("POB_NOMBRE")); |
|
280 |
|
|
281 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
282 |
ef = f.getEditable(); |
|
283 |
ef.set("POB_NOMBRE", "Ibarra-3"); |
|
284 |
dbstore3.update(ef); |
|
285 |
|
|
286 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
287 |
assertEquals("", "Ibarra-3", f.getString("POB_NOMBRE")); |
|
288 |
|
|
289 |
transaction.commit(); |
|
290 |
|
|
291 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
292 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
293 |
|
|
294 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
295 |
assertEquals("", "Ibarra-2", f.getString("POB_NOMBRE")); |
|
296 |
|
|
297 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
298 |
assertEquals("", "Ibarra-3", f.getString("POB_NOMBRE")); |
|
299 |
|
|
300 |
transaction.dispose(); |
|
301 |
|
|
302 |
|
|
303 |
} catch (Throwable th) { |
|
304 |
LOGGER.warn("", th); |
|
305 |
throw th; |
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
protected void testTransaction4() throws Exception { |
|
310 |
Feature f = null; |
|
311 |
EditableFeature ef = null; |
|
312 |
try { |
|
313 |
if (!utils().isTheDatabaseAvailable()) { |
|
314 |
return; |
|
315 |
} |
|
316 |
|
|
317 |
List<Pair<org.apache.log4j.Logger, Level>> loggers = get_loggers(JDBCUtils.class, ResulSetControlerBase.class, "org.gvsig.fmap.dal.store.h2.H2SpatialHelper"); |
|
318 |
set_level(loggers, Level.INFO); |
|
319 |
|
|
320 |
FeatureStore sourceStore = utils().openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/esp_poblaciones-nogeom.csv"); |
|
321 |
JDBCServerExplorer explorer1 = utils().openServerExplorer("testTransaction1"); |
|
322 |
JDBCServerExplorer explorer2 = utils().openServerExplorer("testTransaction2"); |
|
323 |
|
|
324 |
utils().info_jdbc(explorer1); |
|
325 |
|
|
326 |
// Importamos el CSV en la bbdd |
|
327 |
LOGGER.info("Creating table 'poblaciones' in h2 temporary database."); |
|
328 |
utils().drop_tables(explorer1, "poblaciones1", "poblaciones2", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
329 |
utils().create_table_from(explorer1, "poblaciones1", sourceStore); |
|
330 |
utils().create_table_from(explorer1, "poblaciones2", sourceStore); |
|
331 |
utils().insert_into_from(explorer1, "poblaciones1", sourceStore, FeatureStore.MODE_APPEND); |
|
332 |
utils().insert_into_from(explorer1, "poblaciones2", sourceStore, FeatureStore.MODE_APPEND); |
|
333 |
|
|
334 |
utils().drop_tables(explorer2, "poblaciones3", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
335 |
utils().create_table_from(explorer2, "poblaciones3", sourceStore); |
|
336 |
utils().insert_into_from(explorer2, "poblaciones3", sourceStore, FeatureStore.MODE_APPEND); |
|
337 |
|
|
338 |
DataTransaction transaction = DALLocator.getDataManager().createTransaction(); |
|
339 |
transaction.begin(); |
|
340 |
|
|
341 |
transaction.add(explorer1); |
|
342 |
transaction.add(explorer2); |
|
343 |
|
|
344 |
FeatureStore dbstore1 = utils().openStore(explorer1, "poblaciones1"); |
|
345 |
transaction.add(dbstore1); |
|
346 |
FeatureStore dbstore2 = utils().openStore(explorer1, "poblaciones2"); |
|
347 |
transaction.add(dbstore2); |
|
348 |
FeatureStore dbstore3 = utils().openStore(explorer2, "poblaciones3"); |
|
349 |
transaction.add(dbstore3); |
|
350 |
|
|
351 |
dbstore1.edit(); |
|
352 |
dbstore2.edit(); |
|
353 |
dbstore3.edit(); |
|
354 |
|
|
355 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
356 |
ef = f.getEditable(); |
|
357 |
ef.set("POB_NOMBRE", "Ibarra-1"); |
|
358 |
dbstore1.update(ef); |
|
359 |
|
|
360 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
361 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
362 |
|
|
363 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
364 |
ef = f.getEditable(); |
|
365 |
ef.set("POB_NOMBRE", "Ibarra-2"); |
|
366 |
dbstore2.update(ef); |
|
367 |
|
|
368 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
369 |
assertEquals("", "Ibarra-2", f.getString("POB_NOMBRE")); |
|
370 |
|
|
371 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
372 |
ef = f.getEditable(); |
|
373 |
ef.set("POB_NOMBRE", "Ibarra-3"); |
|
374 |
dbstore3.update(ef); |
|
375 |
|
|
376 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
377 |
assertEquals("", "Ibarra-3", f.getString("POB_NOMBRE")); |
|
378 |
|
|
379 |
transaction.rollback(); |
|
380 |
|
|
381 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
382 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
383 |
|
|
384 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
385 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
386 |
|
|
387 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
388 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
389 |
|
|
390 |
transaction.dispose(); |
|
391 |
|
|
392 |
|
|
393 |
} catch (Throwable th) { |
|
394 |
LOGGER.warn("", th); |
|
395 |
throw th; |
|
396 |
} |
|
397 |
} |
|
398 |
|
|
399 |
protected void testTransaction5() throws Exception { |
|
400 |
Feature f = null; |
|
401 |
EditableFeature ef = null; |
|
402 |
try { |
|
403 |
if (!utils().isTheDatabaseAvailable()) { |
|
404 |
return; |
|
405 |
} |
|
406 |
|
|
407 |
List<Pair<org.apache.log4j.Logger, Level>> loggers = get_loggers(JDBCUtils.class, ResulSetControlerBase.class, "org.gvsig.fmap.dal.store.h2.H2SpatialHelper"); |
|
408 |
set_level(loggers, Level.INFO); |
|
409 |
|
|
410 |
FeatureStore sourceStore = utils().openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/esp_poblaciones-nogeom.csv"); |
|
411 |
JDBCServerExplorer explorer1 = utils().openServerExplorer("testTransaction1"); |
|
412 |
JDBCServerExplorer explorer2 = utils().openServerExplorer("testTransaction2"); |
|
413 |
|
|
414 |
utils().info_jdbc(explorer1); |
|
415 |
|
|
416 |
// Importamos el CSV en la bbdd |
|
417 |
LOGGER.info("Creating table 'poblaciones' in h2 temporary database."); |
|
418 |
utils().drop_tables(explorer1, "poblaciones1", "poblaciones2", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
419 |
utils().create_table_from(explorer1, "poblaciones1", sourceStore); |
|
420 |
utils().create_table_from(explorer1, "poblaciones2", sourceStore); |
|
421 |
utils().insert_into_from(explorer1, "poblaciones1", sourceStore, FeatureStore.MODE_APPEND); |
|
422 |
utils().insert_into_from(explorer1, "poblaciones2", sourceStore, FeatureStore.MODE_APPEND); |
|
423 |
|
|
424 |
utils().drop_tables(explorer2, "poblaciones3", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
425 |
utils().create_table_from(explorer2, "poblaciones3", sourceStore); |
|
426 |
utils().insert_into_from(explorer2, "poblaciones3", sourceStore, FeatureStore.MODE_APPEND); |
|
427 |
|
|
428 |
DataTransaction transaction = DALLocator.getDataManager().createTransaction(); |
|
429 |
transaction.begin(); |
|
430 |
|
|
431 |
transaction.add(explorer1); |
|
432 |
transaction.add(explorer2); |
|
433 |
|
|
434 |
FeatureStore dbstore1 = utils().openStore(explorer1, "poblaciones1"); |
|
435 |
transaction.add(dbstore1); |
|
436 |
FeatureStore dbstore2 = utils().openStore(explorer1, "poblaciones2"); |
|
437 |
transaction.add(dbstore2); |
|
438 |
FeatureStore dbstore3 = utils().openStore(explorer2, "poblaciones3"); |
|
439 |
transaction.add(dbstore3); |
|
440 |
|
|
441 |
dbstore1.edit(); |
|
442 |
dbstore2.edit(); |
|
443 |
dbstore3.edit(); |
|
444 |
|
|
445 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
446 |
ef = f.getEditable(); |
|
447 |
ef.set("POB_NOMBRE", "Ibarra-1"); |
|
448 |
dbstore1.update(ef); |
|
449 |
|
|
450 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
451 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
452 |
|
|
453 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
454 |
ef = f.getEditable(); |
|
455 |
ef.set("POB_NOMBRE", "Ibarra-2"); |
|
456 |
dbstore2.update(ef); |
|
457 |
|
|
458 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
459 |
assertEquals("", "Ibarra-2", f.getString("POB_NOMBRE")); |
|
460 |
|
|
461 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
462 |
ef = f.getEditable(); |
|
463 |
ef.set("POB_NOMBRE", "Ibarra-3"); |
|
464 |
dbstore3.update(ef); |
|
465 |
|
|
466 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
467 |
assertEquals("", "Ibarra-3", f.getString("POB_NOMBRE")); |
|
468 |
|
|
469 |
dbstore2.finishEditing(); |
|
470 |
dbstore3.finishEditing(); |
|
471 |
|
|
472 |
transaction.rollback(); |
|
473 |
|
|
474 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
475 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
476 |
|
|
477 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
478 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
479 |
|
|
480 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
481 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
482 |
|
|
483 |
transaction.dispose(); |
|
484 |
|
|
485 |
|
|
486 |
} catch (Throwable th) { |
|
487 |
LOGGER.warn("", th); |
|
488 |
throw th; |
|
489 |
} |
|
490 |
} |
|
491 |
|
|
492 |
protected void testTransaction6() throws Exception { |
|
493 |
Feature f = null; |
|
494 |
EditableFeature ef = null; |
|
495 |
try { |
|
496 |
if (!utils().isTheDatabaseAvailable()) { |
|
497 |
return; |
|
498 |
} |
|
499 |
|
|
500 |
List<Pair<org.apache.log4j.Logger, Level>> loggers = get_loggers(JDBCUtils.class, ResulSetControlerBase.class, "org.gvsig.fmap.dal.store.h2.H2SpatialHelper"); |
|
501 |
set_level(loggers, Level.INFO); |
|
502 |
|
|
503 |
FeatureStore sourceStore = utils().openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/esp_poblaciones-nogeom.csv"); |
|
504 |
JDBCServerExplorer explorer1 = utils().openServerExplorer("testTransaction1"); |
|
505 |
JDBCServerExplorer explorer2 = utils().openServerExplorer("testTransaction2"); |
|
506 |
|
|
507 |
utils().info_jdbc(explorer1); |
|
508 |
|
|
509 |
// Importamos el CSV en la bbdd |
|
510 |
LOGGER.info("Creating table 'poblaciones' in h2 temporary database."); |
|
511 |
utils().drop_tables(explorer1, "poblaciones1", "poblaciones2", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
512 |
utils().create_table_from(explorer1, "poblaciones1", sourceStore); |
|
513 |
utils().create_table_from(explorer1, "poblaciones2", sourceStore); |
|
514 |
utils().insert_into_from(explorer1, "poblaciones1", sourceStore, FeatureStore.MODE_APPEND); |
|
515 |
utils().insert_into_from(explorer1, "poblaciones2", sourceStore, FeatureStore.MODE_APPEND); |
|
516 |
|
|
517 |
utils().drop_tables(explorer2, "poblaciones3", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
518 |
utils().create_table_from(explorer2, "poblaciones3", sourceStore); |
|
519 |
utils().insert_into_from(explorer2, "poblaciones3", sourceStore, FeatureStore.MODE_APPEND); |
|
520 |
|
|
521 |
DataTransaction transaction = DALLocator.getDataManager().createTransaction(); |
|
522 |
transaction.begin(); |
|
523 |
|
|
524 |
transaction.add(explorer1); |
|
525 |
transaction.add(explorer2); |
|
526 |
|
|
527 |
FeatureStore dbstore1 = utils().openStore(explorer1, "poblaciones1"); |
|
528 |
transaction.add(dbstore1); |
|
529 |
FeatureStore dbstore2 = utils().openStore(explorer1, "poblaciones2"); |
|
530 |
transaction.add(dbstore2); |
|
531 |
FeatureStore dbstore3 = utils().openStore(explorer2, "poblaciones3"); |
|
532 |
transaction.add(dbstore3); |
|
533 |
|
|
534 |
dbstore1.edit(FeatureStore.MODE_FULLEDIT); |
|
535 |
dbstore2.edit(FeatureStore.MODE_PASS_THROUGH); |
|
536 |
dbstore3.edit(FeatureStore.MODE_FULLEDIT); |
|
537 |
|
|
538 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
539 |
ef = f.getEditable(); |
|
540 |
ef.set("POB_NOMBRE", "Ibarra-1"); |
|
541 |
dbstore1.update(ef); |
|
542 |
|
|
543 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
544 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
545 |
|
|
546 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
547 |
ef = f.getEditable(); |
|
548 |
ef.set("POB_NOMBRE", "Ibarra-2"); |
|
549 |
dbstore2.update(ef); |
|
550 |
|
|
551 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
552 |
assertEquals("", "Ibarra-2", f.getString("POB_NOMBRE")); |
|
553 |
|
|
554 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
555 |
ef = f.getEditable(); |
|
556 |
ef.set("POB_NOMBRE", "Ibarra-3"); |
|
557 |
dbstore3.update(ef); |
|
558 |
|
|
559 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
560 |
assertEquals("", "Ibarra-3", f.getString("POB_NOMBRE")); |
|
561 |
|
|
562 |
dbstore2.finishEditing(); |
|
563 |
dbstore3.finishEditing(); |
|
564 |
|
|
565 |
transaction.rollback(); |
|
566 |
|
|
567 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
568 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
569 |
|
|
570 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
571 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
572 |
|
|
573 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
574 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
575 |
|
|
576 |
transaction.dispose(); |
|
577 |
|
|
578 |
|
|
579 |
} catch (Throwable th) { |
|
580 |
LOGGER.warn("", th); |
|
581 |
throw th; |
|
582 |
} |
|
583 |
} |
|
584 |
|
|
585 |
protected void testTransaction7() throws Exception { |
|
586 |
Feature f = null; |
|
587 |
EditableFeature ef = null; |
|
588 |
try { |
|
589 |
if (!utils().isTheDatabaseAvailable()) { |
|
590 |
return; |
|
591 |
} |
|
592 |
|
|
593 |
List<Pair<org.apache.log4j.Logger, Level>> loggers = get_loggers(JDBCUtils.class, ResulSetControlerBase.class, "org.gvsig.fmap.dal.store.h2.H2SpatialHelper"); |
|
594 |
set_level(loggers, Level.INFO); |
|
595 |
|
|
596 |
FeatureStore sourceStore = utils().openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/esp_poblaciones-nogeom.csv"); |
|
597 |
JDBCServerExplorer explorer1 = utils().openServerExplorer("testTransaction1"); |
|
598 |
JDBCServerExplorer explorer2 = utils().openServerExplorer("testTransaction2"); |
|
599 |
|
|
600 |
utils().info_jdbc(explorer1); |
|
601 |
|
|
602 |
// Importamos el CSV en la bbdd |
|
603 |
LOGGER.info("Creating table 'poblaciones' in h2 temporary database."); |
|
604 |
utils().drop_tables(explorer1, "poblaciones1", "poblaciones2", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
605 |
utils().create_table_from(explorer1, "poblaciones1", sourceStore); |
|
606 |
utils().create_table_from(explorer1, "poblaciones2", sourceStore); |
|
607 |
utils().insert_into_from(explorer1, "poblaciones1", sourceStore, FeatureStore.MODE_APPEND); |
|
608 |
utils().insert_into_from(explorer1, "poblaciones2", sourceStore, FeatureStore.MODE_APPEND); |
|
609 |
|
|
610 |
utils().drop_tables(explorer2, "poblaciones3", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
611 |
utils().create_table_from(explorer2, "poblaciones3", sourceStore); |
|
612 |
utils().insert_into_from(explorer2, "poblaciones3", sourceStore, FeatureStore.MODE_APPEND); |
|
613 |
|
|
614 |
DataTransaction transaction = DALLocator.getDataManager().createTransaction(); |
|
615 |
transaction.begin(); |
|
616 |
|
|
617 |
transaction.add(explorer1); |
|
618 |
transaction.add(explorer2); |
|
619 |
|
|
620 |
FeatureStore dbstore1 = utils().openStore(explorer1, "poblaciones1"); |
|
621 |
transaction.add(dbstore1); |
|
622 |
FeatureStore dbstore2 = utils().openStore(explorer1, "poblaciones2"); |
|
623 |
transaction.add(dbstore2); |
|
624 |
FeatureStore dbstore3 = utils().openStore(explorer2, "poblaciones3"); |
|
625 |
transaction.add(dbstore3); |
|
626 |
|
|
627 |
dbstore1.edit(FeatureStore.MODE_FULLEDIT); |
|
628 |
dbstore2.edit(FeatureStore.MODE_PASS_THROUGH); |
|
629 |
dbstore3.edit(FeatureStore.MODE_FULLEDIT); |
|
630 |
|
|
631 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
632 |
ef = f.getEditable(); |
|
633 |
ef.set("POB_NOMBRE", "Ibarra-1"); |
|
634 |
dbstore1.update(ef); |
|
635 |
|
|
636 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
637 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
638 |
|
|
639 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
640 |
ef = f.getEditable(); |
|
641 |
ef.set("POB_NOMBRE", "Ibarra-2"); |
|
642 |
dbstore2.update(ef); |
|
643 |
|
|
644 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
645 |
assertEquals("", "Ibarra-2", f.getString("POB_NOMBRE")); |
|
646 |
|
|
647 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
648 |
ef = f.getEditable(); |
|
649 |
ef.set("POB_NOMBRE", "Ibarra-3"); |
|
650 |
dbstore3.update(ef); |
|
651 |
|
|
652 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
653 |
assertEquals("", "Ibarra-3", f.getString("POB_NOMBRE")); |
|
654 |
|
|
655 |
dbstore2.delete("COD_POBLACION <> 1003"); |
|
656 |
assertEquals("", 1L, dbstore2.getFeatureCount()); |
|
657 |
dbstore2.finishEditing(); |
|
658 |
dbstore2.edit(FeatureStore.MODE_APPEND); |
|
659 |
for (int i = 0; i < 100; i++) { |
|
660 |
f = dbstore2.createNewFeature(); |
|
661 |
ef = f.getEditable(); |
|
662 |
ef.set("COD_POBLACION",100000+i); |
|
663 |
ef.set("POB_NOMBRE","Aqui"+i); |
|
664 |
ef.set("COD_PROVINCIA",1); |
|
665 |
dbstore2.insert(ef); |
|
666 |
} |
|
667 |
dbstore2.finishEditing(); |
|
668 |
|
|
669 |
dbstore3.finishEditing(); |
|
670 |
|
|
671 |
assertEquals("", 101L, dbstore2.getFeatureSet().size()); |
|
672 |
assertEquals("", 101L, dbstore2.getFeatureCount()); |
|
673 |
|
|
674 |
transaction.rollback(); |
|
675 |
|
|
676 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
677 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
678 |
|
|
679 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
680 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
681 |
|
|
682 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
683 |
assertEquals("", "Ibarra", f.getString("POB_NOMBRE")); |
|
684 |
|
|
685 |
assertEquals("", sourceStore.getFeatureCount(), dbstore2.getFeatureSet().size()); |
|
686 |
assertEquals("", sourceStore.getFeatureCount(), dbstore2.getFeatureCount()); |
|
687 |
|
|
688 |
transaction.dispose(); |
|
689 |
|
|
690 |
|
|
691 |
} catch (Throwable th) { |
|
692 |
LOGGER.warn("", th); |
|
693 |
throw th; |
|
694 |
} |
|
695 |
} |
|
696 |
|
|
697 |
protected void testTransaction8() throws Exception { |
|
698 |
Feature f = null; |
|
699 |
EditableFeature ef = null; |
|
700 |
try { |
|
701 |
if (!utils().isTheDatabaseAvailable()) { |
|
702 |
return; |
|
703 |
} |
|
704 |
|
|
705 |
List<Pair<org.apache.log4j.Logger, Level>> loggers = get_loggers(JDBCUtils.class, ResulSetControlerBase.class, "org.gvsig.fmap.dal.store.h2.H2SpatialHelper"); |
|
706 |
set_level(loggers, Level.INFO); |
|
707 |
|
|
708 |
FeatureStore sourceStore = utils().openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/esp_poblaciones-nogeom.csv"); |
|
709 |
JDBCServerExplorer explorer1 = utils().openServerExplorer("testTransaction1"); |
|
710 |
JDBCServerExplorer explorer2 = utils().openServerExplorer("testTransaction2"); |
|
711 |
|
|
712 |
utils().info_jdbc(explorer1); |
|
713 |
|
|
714 |
// Importamos el CSV en la bbdd |
|
715 |
LOGGER.info("Creating table 'poblaciones' in h2 temporary database."); |
|
716 |
utils().drop_tables(explorer1, "poblaciones1", "poblaciones2", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
717 |
utils().create_table_from(explorer1, "poblaciones1", sourceStore); |
|
718 |
utils().create_table_from(explorer1, "poblaciones2", sourceStore); |
|
719 |
utils().insert_into_from(explorer1, "poblaciones1", sourceStore, FeatureStore.MODE_APPEND); |
|
720 |
utils().insert_into_from(explorer1, "poblaciones2", sourceStore, FeatureStore.MODE_APPEND); |
|
721 |
|
|
722 |
utils().drop_tables(explorer2, "poblaciones3", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME); |
|
723 |
utils().create_table_from(explorer2, "poblaciones3", sourceStore); |
|
724 |
utils().insert_into_from(explorer2, "poblaciones3", sourceStore, FeatureStore.MODE_APPEND); |
|
725 |
|
|
726 |
DataTransaction transaction = DALLocator.getDataManager().createTransaction(); |
|
727 |
transaction.begin(); |
|
728 |
|
|
729 |
transaction.add(explorer1); |
|
730 |
transaction.add(explorer2); |
|
731 |
|
|
732 |
FeatureStore dbstore1 = utils().openStore(explorer1, "poblaciones1"); |
|
733 |
transaction.add(dbstore1); |
|
734 |
FeatureStore dbstore2 = utils().openStore(explorer1, "poblaciones2"); |
|
735 |
transaction.add(dbstore2); |
|
736 |
FeatureStore dbstore3 = utils().openStore(explorer2, "poblaciones3"); |
|
737 |
transaction.add(dbstore3); |
|
738 |
|
|
739 |
dbstore1.edit(FeatureStore.MODE_FULLEDIT); |
|
740 |
dbstore2.edit(FeatureStore.MODE_PASS_THROUGH); |
|
741 |
dbstore3.edit(FeatureStore.MODE_FULLEDIT); |
|
742 |
|
|
743 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
744 |
ef = f.getEditable(); |
|
745 |
ef.set("POB_NOMBRE", "Ibarra-1"); |
|
746 |
dbstore1.update(ef); |
|
747 |
|
|
748 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
749 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
750 |
|
|
751 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
752 |
ef = f.getEditable(); |
|
753 |
ef.set("POB_NOMBRE", "Ibarra-2"); |
|
754 |
dbstore2.update(ef); |
|
755 |
|
|
756 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
757 |
assertEquals("", "Ibarra-2", f.getString("POB_NOMBRE")); |
|
758 |
|
|
759 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
760 |
ef = f.getEditable(); |
|
761 |
ef.set("POB_NOMBRE", "Ibarra-3"); |
|
762 |
dbstore3.update(ef); |
|
763 |
|
|
764 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
765 |
assertEquals("", "Ibarra-3", f.getString("POB_NOMBRE")); |
|
766 |
|
|
767 |
dbstore2.delete("COD_POBLACION <> 1003"); |
|
768 |
assertEquals("", 1L, dbstore2.getFeatureCount()); |
|
769 |
dbstore2.finishEditing(); |
|
770 |
dbstore2.edit(FeatureStore.MODE_APPEND); |
|
771 |
for (int i = 0; i < 100; i++) { |
|
772 |
f = dbstore2.createNewFeature(); |
|
773 |
ef = f.getEditable(); |
|
774 |
ef.set("COD_POBLACION",100000+i); |
|
775 |
ef.set("POB_NOMBRE","Aqui"+i); |
|
776 |
ef.set("COD_PROVINCIA",1); |
|
777 |
dbstore2.insert(ef); |
|
778 |
} |
|
779 |
dbstore2.finishEditing(); |
|
780 |
|
|
781 |
dbstore3.finishEditing(); |
|
782 |
|
|
783 |
assertEquals("", 101L, dbstore2.getFeatureSet().size()); |
|
784 |
assertEquals("", 101L, dbstore2.getFeatureCount()); |
|
785 |
|
|
786 |
transaction.commit(); |
|
787 |
|
|
788 |
f = dbstore1.findFirst("COD_POBLACION = 1003"); |
|
789 |
assertEquals("", "Ibarra-1", f.getString("POB_NOMBRE")); |
|
790 |
|
|
791 |
f = dbstore2.findFirst("COD_POBLACION = 1003"); |
|
792 |
assertEquals("", "Ibarra-2", f.getString("POB_NOMBRE")); |
|
793 |
|
|
794 |
f = dbstore3.findFirst("COD_POBLACION = 1003"); |
|
795 |
assertEquals("", "Ibarra-3", f.getString("POB_NOMBRE")); |
|
796 |
|
|
797 |
assertEquals("", 101L, dbstore2.getFeatureSet().size()); |
|
798 |
assertEquals("", 101L, dbstore2.getFeatureCount()); |
|
799 |
|
|
800 |
transaction.dispose(); |
|
801 |
|
|
802 |
|
|
803 |
} catch (Throwable th) { |
|
804 |
LOGGER.warn("", th); |
|
805 |
throw th; |
|
806 |
} |
|
807 |
} |
|
808 |
|
|
809 |
} |
|
810 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/JDBCServerExplorer.java | ||
---|---|---|
27 | 27 |
import org.gvsig.fmap.dal.DataStore; |
28 | 28 |
import org.gvsig.fmap.dal.DataStoreParameters; |
29 | 29 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
30 |
import org.gvsig.fmap.dal.SupportTransactions; |
|
30 | 31 |
import org.gvsig.fmap.dal.exception.DataException; |
31 | 32 |
import org.gvsig.fmap.dal.exception.RemoveException; |
32 | 33 |
import org.gvsig.fmap.dal.feature.FeatureType; |
... | ... | |
35 | 36 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
36 | 37 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
37 | 38 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecuteSQLException; |
39 |
import org.omg.IOP.TransactionService; |
|
38 | 40 |
|
39 | 41 |
|
40 |
public interface JDBCServerExplorer extends ResourceConsumer, org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer { |
|
42 |
public interface JDBCServerExplorer extends ResourceConsumer, org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer, SupportTransactions {
|
|
41 | 43 |
|
42 | 44 |
public static int SHOW_TABLES_AND_VIEWS = 0; |
43 | 45 |
public static int SHOW_TABLES = 1; |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/DataTransactionConnection.java | ||
---|---|---|
1 |
/* |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
18 |
* |
|
19 |
* For any additional information, do not hesitate to contact us |
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
21 |
*/ |
|
22 |
|
|
23 |
package org.gvsig.fmap.dal.store.jdbc2.spi; |
|
24 |
|
|
25 |
import java.sql.Connection; |
|
26 |
import java.sql.SQLException; |
|
27 |
import org.gvsig.fmap.dal.exception.DataException; |
|
28 |
import org.gvsig.fmap.dal.spi.DataTransactionServices; |
|
29 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
* @author gvSIG Team |
|
34 |
*/ |
|
35 |
public class DataTransactionConnection implements DataTransactionServices.ConnectionService<Connection> { |
|
36 |
|
|
37 |
private final String id; |
|
38 |
private final Connection connection; |
|
39 |
|
|
40 |
public DataTransactionConnection(String id, Connection connection) { |
|
41 |
this.id = id; |
|
42 |
this.connection = connection; |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public String getId() { |
|
47 |
return this.id; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public void begin() throws DataException { |
|
52 |
try { |
|
53 |
this.connection.setAutoCommit(false); |
|
54 |
} catch (SQLException ex) { |
|
55 |
throw new JDBCSQLException(ex); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public void commit() throws DataException { |
|
61 |
try { |
|
62 |
this.connection.commit(); |
|
63 |
} catch (SQLException ex) { |
|
64 |
throw new JDBCSQLException(ex); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public void rollback() throws DataException { |
|
70 |
try { |
|
71 |
this.connection.rollback(); |
|
72 |
} catch (SQLException ex) { |
|
73 |
throw new JDBCSQLException(ex); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public Connection get() { |
|
79 |
return this.connection; |
|
80 |
} |
|
81 |
|
|
82 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/SRSSolver.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
28 | 28 |
|
29 | 29 |
public interface SRSSolver { |
30 | 30 |
|
31 | 31 |
void add(Object databaseCode, String applicationAbbrev); |
32 | 32 |
|
33 |
String getApplicationAbbrev(Connection connection, Object databaseCode); |
|
33 |
String getApplicationAbbrev(JDBCConnection connection, Object databaseCode);
|
|
34 | 34 |
|
35 |
Object getDatabaseCode(Connection connection, String applicationAbbrev); |
|
35 |
Object getDatabaseCode(JDBCConnection connection, String applicationAbbrev);
|
|
36 | 36 |
|
37 |
boolean hasApplicationAbbrev(Connection connection, String applicationAbbrev); |
|
37 |
boolean hasApplicationAbbrev(JDBCConnection connection, String applicationAbbrev);
|
|
38 | 38 |
|
39 |
boolean hasDatabaseCode(Connection connection, Object databaseCode); |
|
39 |
boolean hasDatabaseCode(JDBCConnection connection, Object databaseCode);
|
|
40 | 40 |
|
41 |
public IProjection getProjection(Connection connection, Object databaseCode); |
|
41 |
public IProjection getProjection(JDBCConnection connection, Object databaseCode);
|
|
42 | 42 |
|
43 |
public Object getDatabaseCode(Connection connection, IProjection projection); |
|
43 |
public Object getDatabaseCode(JDBCConnection connection, IProjection projection);
|
|
44 | 44 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/CountOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import java.sql.ResultSet; |
28 | 27 |
import java.sql.SQLException; |
29 | 28 |
import java.sql.Statement; |
... | ... | |
46 | 45 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
47 | 46 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
48 | 47 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
48 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
49 | 49 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
50 | 50 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
51 | 51 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE; |
... | ... | |
84 | 84 |
} |
85 | 85 |
|
86 | 86 |
@Override |
87 |
public final Object perform(Connection conn) throws DataException { |
|
87 |
public final Object perform(JDBCConnection conn) throws DataException {
|
|
88 | 88 |
return this.count(conn); |
89 | 89 |
} |
90 | 90 |
|
... | ... | |
276 | 276 |
return sql; |
277 | 277 |
} |
278 | 278 |
|
279 |
public long count(Connection conn) throws DataException { |
|
279 |
public long count(JDBCConnection conn) throws DataException {
|
|
280 | 280 |
|
281 | 281 |
String sql = this.getSQL(); |
282 | 282 |
Statement st = null; |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/ResultSetForSetProviderOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import java.util.ArrayList; |
28 | 27 |
import java.util.HashMap; |
29 | 28 |
import java.util.List; |
... | ... | |
46 | 45 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
47 | 46 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder.FeatureQueryOrderMember; |
48 | 47 |
import org.gvsig.fmap.dal.feature.FeatureType; |
48 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
49 | 49 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
50 | 50 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
51 | 51 |
import org.gvsig.fmap.dal.store.jdbc2.ResulSetControler.ResultSetEntry; |
... | ... | |
103 | 103 |
} |
104 | 104 |
|
105 | 105 |
@Override |
106 |
public Object perform(Connection conn) throws DataException { |
|
106 |
public Object perform(JDBCConnection conn) throws DataException {
|
|
107 | 107 |
throw new UnsupportedOperationException("Not supported yet."); |
108 | 108 |
} |
109 | 109 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/FetchFeatureProviderByReferenceOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import java.sql.PreparedStatement; |
28 | 27 |
import java.sql.ResultSet; |
29 | 28 |
import java.sql.SQLException; |
... | ... | |
36 | 35 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
37 | 36 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
38 | 37 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
38 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
39 | 39 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
40 | 40 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
41 | 41 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
... | ... | |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
@Override |
66 |
public final Object perform(Connection conn) throws DataException { |
|
66 |
public final Object perform(JDBCConnection conn) throws DataException {
|
|
67 | 67 |
FeatureProvider feature = fetchFeatureProviderByReference(conn); |
68 | 68 |
return feature; |
69 | 69 |
} |
... | ... | |
128 | 128 |
} |
129 | 129 |
|
130 | 130 |
public FeatureProvider fetchFeatureProviderByReference( |
131 |
Connection conn |
|
131 |
JDBCConnection conn
|
|
132 | 132 |
) throws DataException { |
133 | 133 |
|
134 | 134 |
List<FeatureAttributeDescriptor> columns = new ArrayList<>(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/DeletePassThroughOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import java.sql.Statement; |
28 | 27 |
import org.gvsig.expressionevaluator.Expression; |
29 | 28 |
import org.gvsig.fmap.dal.exception.DataException; |
29 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
30 | 30 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
31 | 31 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
32 | 32 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
... | ... | |
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
@Override |
52 |
public final Object perform(Connection conn) throws DataException { |
|
52 |
public final Object perform(JDBCConnection conn) throws DataException {
|
|
53 | 53 |
return execute(this.table, this.filter); |
54 | 54 |
} |
55 | 55 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/CalculateEnvelopeOfColumnOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import java.sql.ResultSet; |
28 | 27 |
import java.sql.SQLException; |
29 | 28 |
import java.sql.Statement; |
... | ... | |
34 | 33 |
import org.gvsig.fmap.dal.exception.DataException; |
35 | 34 |
import org.gvsig.fmap.dal.feature.FeatureType; |
36 | 35 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
36 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
37 | 37 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
38 | 38 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
39 | 39 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
... | ... | |
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
@Override |
74 |
public final Object perform(Connection conn) throws DataException { |
|
74 |
public final Object perform(JDBCConnection conn) throws DataException {
|
|
75 | 75 |
Envelope env = calculateEnvelopeOfColumn(conn); |
76 | 76 |
return env; |
77 | 77 |
} |
... | ... | |
175 | 175 |
return sql; |
176 | 176 |
} |
177 | 177 |
|
178 |
public Envelope calculateEnvelopeOfColumn(Connection conn) throws DataException { |
|
178 |
public Envelope calculateEnvelopeOfColumn(JDBCConnection conn) throws DataException {
|
|
179 | 179 |
if (this.helper.hasSpatialFunctions()) { |
180 | 180 |
return calculateEnvelopeOfColumnWithAggregate(conn); |
181 | 181 |
} else { |
... | ... | |
183 | 183 |
} |
184 | 184 |
} |
185 | 185 |
|
186 |
protected Envelope calculateEnvelopeOfColumnWithAggregate(Connection conn) throws DataException { |
|
186 |
protected Envelope calculateEnvelopeOfColumnWithAggregate(JDBCConnection conn) throws DataException {
|
|
187 | 187 |
String sql = this.getSQL(); |
188 | 188 |
|
189 | 189 |
Statement st = null; |
... | ... | |
227 | 227 |
} |
228 | 228 |
} |
229 | 229 |
|
230 |
protected Envelope calculateEnvelopeOfColumnWithoutAggregate(Connection conn) throws DataException { |
|
230 |
protected Envelope calculateEnvelopeOfColumnWithoutAggregate(JDBCConnection conn) throws DataException {
|
|
231 | 231 |
// crear una sql que devuelva un resultarSet |
232 | 232 |
//bucle |
233 | 233 |
// iif instacia de string: cast string |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/ConnectionOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import org.gvsig.fmap.dal.exception.DataException; |
27 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
28 | 28 |
|
29 | 29 |
|
30 | 30 |
public interface ConnectionOperation { |
31 |
public Object perform(Connection conn) throws DataException ; |
|
31 |
public Object perform(JDBCConnection conn) throws DataException ;
|
|
32 | 32 |
public Object perform(); |
33 | 33 |
public boolean needTransaction(); |
34 | 34 |
public boolean continueTransactionAllowed(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/TableIsEmptyOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import java.sql.ResultSet; |
28 | 27 |
import java.sql.SQLException; |
29 | 28 |
import java.sql.Statement; |
... | ... | |
35 | 34 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
36 | 35 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
37 | 36 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
37 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
38 | 38 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
39 | 39 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
40 | 40 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE; |
... | ... | |
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
@Override |
74 |
public final Object perform(Connection conn) throws DataException { |
|
74 |
public final Object perform(JDBCConnection conn) throws DataException {
|
|
75 | 75 |
return this.tableIsEmpty(conn); |
76 | 76 |
} |
77 | 77 |
|
... | ... | |
120 | 120 |
return sql; |
121 | 121 |
} |
122 | 122 |
|
123 |
public boolean tableIsEmpty(Connection conn) throws DataException { |
|
123 |
public boolean tableIsEmpty(JDBCConnection conn) throws DataException {
|
|
124 | 124 |
String sql = this.getSQL(); |
125 | 125 |
|
126 | 126 |
Statement st = null; |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/ExecuteOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import java.sql.ResultSet; |
28 | 27 |
import java.sql.Statement; |
29 | 28 |
import org.apache.commons.lang3.StringUtils; |
30 | 29 |
import org.gvsig.fmap.dal.exception.DataException; |
30 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
31 | 31 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
32 | 32 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
33 | 33 |
|
... | ... | |
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
@Override |
47 |
public final Object perform(Connection conn) throws DataException { |
|
47 |
public final Object perform(JDBCConnection conn) throws DataException {
|
|
48 | 48 |
return execute(sql); |
49 | 49 |
} |
50 | 50 |
|
... | ... | |
101 | 101 |
|
102 | 102 |
protected void closeConnection(Object result) throws Exception { |
103 | 103 |
if (!(result instanceof ResultSet)) { |
104 |
helper.closeConnection(this.getConnection());
|
|
104 |
this.getConnection().close();
|
|
105 | 105 |
conn = null; |
106 | 106 |
} |
107 | 107 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/PerformChangesOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import java.sql.PreparedStatement; |
28 | 27 |
import java.sql.SQLException; |
29 | 28 |
import java.sql.Statement; |
... | ... | |
47 | 46 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
48 | 47 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecuteSQLException; |
49 | 48 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
49 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
50 | 50 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
51 | 51 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
52 | 52 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
... | ... | |
104 | 104 |
} |
105 | 105 |
|
106 | 106 |
@Override |
107 |
public Object perform(Connection conn) throws DataException { |
|
107 |
public Object perform(JDBCConnection conn) throws DataException {
|
|
108 | 108 |
if (typeChanged) { |
109 | 109 |
this.performUpdateTable(conn); |
110 | 110 |
} |
... | ... | |
153 | 153 |
return sql; |
154 | 154 |
} |
155 | 155 |
|
156 |
public void performDeletes(Connection conn) throws DataException { |
|
156 |
public void performDeletes(JDBCConnection conn) throws DataException {
|
|
157 | 157 |
JDBCSQLBuilderBase sqlbuilder = createSQLBuilder(); |
158 | 158 |
String sql = getDeleteSQL(sqlbuilder); |
159 | 159 |
perform_batchmode(conn, this.deleteds, sqlbuilder, sql, new Invocable() { |
... | ... | |
213 | 213 |
return sql; |
214 | 214 |
} |
215 | 215 |
|
216 |
public void performInserts(Connection conn) throws DataException { |
|
216 |
public void performInserts(JDBCConnection conn) throws DataException {
|
|
217 | 217 |
JDBCSQLBuilderBase sqlbuilder = createSQLBuilder(); |
218 | 218 |
String sql = getInsertSQL(sqlbuilder); |
219 | 219 |
perform_batchmode(conn, this.inserteds, sqlbuilder, sql, new Invocable() { |
... | ... | |
286 | 286 |
return sql; |
287 | 287 |
} |
288 | 288 |
|
289 |
public void performUpdates(Connection conn) throws DataException { |
|
289 |
public void performUpdates(JDBCConnection conn) throws DataException {
|
|
290 | 290 |
JDBCSQLBuilderBase sqlbuilder = createSQLBuilder(); |
291 | 291 |
String sql = getUpdateSQL(sqlbuilder); |
292 | 292 |
perform_batchmode(conn, this.updateds, sqlbuilder, sql, new Invocable() { |
... | ... | |
302 | 302 |
} |
303 | 303 |
|
304 | 304 |
|
305 |
private void perform_batchmode(Connection conn, Iterator elements, JDBCSQLBuilderBase sqlbuilder, String sql, Invocable fillPreparedStatement) throws DataException { |
|
305 |
private void perform_batchmode(JDBCConnection conn, Iterator elements, JDBCSQLBuilderBase sqlbuilder, String sql, Invocable fillPreparedStatement) throws DataException {
|
|
306 | 306 |
PreparedStatement preparedStatement; |
307 | 307 |
Disposable[] disposableParameters; |
308 | 308 |
try { |
... | ... | |
542 | 542 |
return sqls; |
543 | 543 |
} |
544 | 544 |
|
545 |
public void performUpdateTable(Connection conn) throws DataException { |
|
545 |
public void performUpdateTable(JDBCConnection conn) throws DataException {
|
|
546 | 546 |
|
547 | 547 |
List<String> sqls = this.getUpdateTableSQLs(); |
548 | 548 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/UpdateTableStatisticsOperation.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
25 | 25 |
|
26 |
import java.sql.Connection; |
|
27 | 26 |
import java.sql.SQLException; |
28 | 27 |
import java.sql.Statement; |
29 | 28 |
import java.util.List; |
... | ... | |
31 | 30 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
32 | 31 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
33 | 32 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
33 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection; |
|
34 | 34 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
35 | 35 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
36 | 36 |
|
... | ... | |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
@Override |
56 |
public final Object perform(Connection conn) throws DataException { |
|
56 |
public final Object perform(JDBCConnection conn) throws DataException {
|
|
57 | 57 |
this.updateTableStatistics(conn); |
58 | 58 |
return true; |
Also available in: Unified diff