Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dal / src-test / org / gvsig / fmap / dal / feature / testediting / DeleteFirstAndLastFeature.java @ 26061

History | View | Annotate | Download (3.17 KB)

1
/* 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.testediting;
32

    
33
import java.util.Iterator;
34

    
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.exception.DataRuntimeException;
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 EditStore {
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
                try {
69
                        set = this.store.getFeatureSet();
70
                } catch (DataException e) {
71
                        finishedError(e);
72
                        return;
73
                }
74

    
75
                try {
76
                        long size = set.getSize();
77
                        Iterator iter = null;
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
                        set.dispose();
146
                }
147
        }
148

    
149

    
150
}