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 / DeleteFirstAndLastFeature.java @ 40559
History | View | Annotate | Download (3.28 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /*
|
||
25 | * AUTHORS (In addition to CIT):
|
||
26 | * 2009 IVER T.I. S.A. {{Task}}
|
||
27 | */
|
||
28 | |||
29 | /**
|
||
30 | *
|
||
31 | */
|
||
32 | package org.gvsig.fmap.dal.feature.testmulithread; |
||
33 | |||
34 | import org.gvsig.fmap.dal.exception.DataException; |
||
35 | import org.gvsig.fmap.dal.exception.DataRuntimeException; |
||
36 | import org.gvsig.tools.dispose.DisposableIterator; |
||
37 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
38 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
39 | import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
||
40 | |||
41 | /**
|
||
42 | * @author jmvivo
|
||
43 | *
|
||
44 | */
|
||
45 | public class DeleteFirstAndLastFeature extends StoreTask { |
||
46 | |||
47 | /**
|
||
48 | * @param store
|
||
49 | * @param timeToWait
|
||
50 | */
|
||
51 | public DeleteFirstAndLastFeature(String id, FeatureStore store) { |
||
52 | super(id, store);
|
||
53 | } |
||
54 | |||
55 | /**
|
||
56 | * @param store
|
||
57 | * @param timeToWait
|
||
58 | */
|
||
59 | public DeleteFirstAndLastFeature(String id, FeatureStore store, int timeToWait) { |
||
60 | super(id, store, timeToWait);
|
||
61 | } |
||
62 | |||
63 | public void run() { |
||
64 | if (!this.startProcess()) { |
||
65 | return;
|
||
66 | } |
||
67 | FeatureSet set; |
||
68 | DisposableIterator iter = null;
|
||
69 | try {
|
||
70 | set = this.store.getFeatureSet();
|
||
71 | } catch (DataException e) {
|
||
72 | finishedError(e); |
||
73 | return;
|
||
74 | } |
||
75 | |||
76 | try {
|
||
77 | long size = set.getSize();
|
||
78 | try {
|
||
79 | |||
80 | iter = set.iterator(); |
||
81 | |||
82 | if (!iter.hasNext()) {
|
||
83 | finishedNoOk(); |
||
84 | return;
|
||
85 | } |
||
86 | iter.next(); |
||
87 | |||
88 | try {
|
||
89 | iter.remove(); |
||
90 | size--; |
||
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 | |||
104 | |||
105 | if (size != set.getSize()) {
|
||
106 | finishedNoOk(); |
||
107 | return;
|
||
108 | } |
||
109 | |||
110 | while (iter.hasNext()) {
|
||
111 | iter.next(); |
||
112 | } |
||
113 | } catch (ConcurrentDataModificationException e) {
|
||
114 | finishedConcurrentError(e); |
||
115 | return;
|
||
116 | } catch (DataException e) {
|
||
117 | finishedError(e); |
||
118 | return;
|
||
119 | } |
||
120 | try {
|
||
121 | |||
122 | iter.remove(); |
||
123 | size--; |
||
124 | } catch (DataRuntimeException e) {
|
||
125 | if (e.getCause() instanceof ConcurrentDataModificationException) { |
||
126 | finishedConcurrentError(e); |
||
127 | return;
|
||
128 | } |
||
129 | finishedError(e); |
||
130 | return;
|
||
131 | |||
132 | } catch (RuntimeException e) { |
||
133 | finishedError(e); |
||
134 | return;
|
||
135 | } |
||
136 | if (size != set.getSize()) {
|
||
137 | finishedNoOk(); |
||
138 | } else {
|
||
139 | finishedOk(); |
||
140 | } |
||
141 | } catch (Throwable e) { |
||
142 | finishedError(e); |
||
143 | return;
|
||
144 | } finally {
|
||
145 | iter.dispose(); |
||
146 | set.dispose(); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | |||
151 | } |