svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / test / java / org / gvsig / fmap / dal / feature / testmulithread / DeleteLastFeature.java @ 40435
History | View | Annotate | Download (2.62 KB)
1 | 40435 | jjdelcerro | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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 2
|
||
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, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2009 IVER T.I. S.A. {{Task}}
|
||
26 | */
|
||
27 | |||
28 | /**
|
||
29 | *
|
||
30 | */
|
||
31 | package org.gvsig.fmap.dal.feature.testmulithread; |
||
32 | |||
33 | import org.gvsig.fmap.dal.exception.DataException; |
||
34 | import org.gvsig.fmap.dal.exception.DataRuntimeException; |
||
35 | import org.gvsig.tools.dispose.DisposableIterator; |
||
36 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
37 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
38 | import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
||
39 | |||
40 | /**
|
||
41 | * @author jmvivo
|
||
42 | *
|
||
43 | */
|
||
44 | public class DeleteLastFeature extends StoreTask { |
||
45 | |||
46 | /**
|
||
47 | * @param store
|
||
48 | * @param timeToWait
|
||
49 | */
|
||
50 | public DeleteLastFeature(String id, FeatureStore store) { |
||
51 | super(id, store);
|
||
52 | } |
||
53 | |||
54 | /**
|
||
55 | * @param store
|
||
56 | * @param timeToWait
|
||
57 | */
|
||
58 | public DeleteLastFeature(String id, FeatureStore store, int timeToWait) { |
||
59 | super(id, store, timeToWait);
|
||
60 | } |
||
61 | |||
62 | public void run() { |
||
63 | if (!this.startProcess()) { |
||
64 | return;
|
||
65 | } |
||
66 | FeatureSet set; |
||
67 | DisposableIterator iter = null;
|
||
68 | try {
|
||
69 | set = this.store.getFeatureSet();
|
||
70 | } catch (DataException e) {
|
||
71 | finishedError(e); |
||
72 | return;
|
||
73 | } |
||
74 | try {
|
||
75 | |||
76 | try {
|
||
77 | iter = set.iterator(); |
||
78 | while (iter.hasNext()) {
|
||
79 | iter.next(); |
||
80 | } |
||
81 | } catch (ConcurrentDataModificationException e) {
|
||
82 | finishedConcurrentError(e); |
||
83 | return;
|
||
84 | } catch (DataException e) {
|
||
85 | finishedError(e); |
||
86 | return;
|
||
87 | } |
||
88 | try {
|
||
89 | |||
90 | iter.remove(); |
||
91 | } catch (DataRuntimeException e) {
|
||
92 | if (e.getCause() instanceof ConcurrentDataModificationException) { |
||
93 | finishedConcurrentError(e); |
||
94 | return;
|
||
95 | } |
||
96 | finishedError(e); |
||
97 | return;
|
||
98 | |||
99 | } catch (RuntimeException e) { |
||
100 | finishedError(e); |
||
101 | return;
|
||
102 | } |
||
103 | finishedOk(); |
||
104 | } catch (Throwable e) { |
||
105 | finishedError(e); |
||
106 | return;
|
||
107 | } finally {
|
||
108 | iter.dispose(); |
||
109 | set.dispose(); |
||
110 | } |
||
111 | } |
||
112 | |||
113 | |||
114 | } |