Statistics
| Revision:

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 @ 40435

History | View | Annotate | Download (3.23 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.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 DeleteFirstAndLastFeature extends StoreTask {
45

    
46
        /**
47
         * @param store
48
         * @param timeToWait
49
         */
50
        public DeleteFirstAndLastFeature(String id, FeatureStore store) {
51
                super(id, store);
52
        }
53

    
54
        /**
55
         * @param store
56
         * @param timeToWait
57
         */
58
        public DeleteFirstAndLastFeature(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

    
75
                try {
76
                        long size = set.getSize();
77
                        try {
78

    
79
                                iter = set.iterator();
80

    
81
                                if (!iter.hasNext()) {
82
                                        finishedNoOk();
83
                                        return;
84
                                }
85
                                iter.next();
86

    
87
                                try {
88
                                        iter.remove();
89
                                        size--;
90
                                } catch (DataRuntimeException e) {
91
                                        if (e.getCause() instanceof ConcurrentDataModificationException) {
92
                                                finishedConcurrentError(e);
93
                                                return;
94
                                        }
95
                                        finishedError(e);
96
                                        return;
97

    
98
                                } catch (RuntimeException e) {
99
                                        finishedError(e);
100
                                        return;
101
                                }
102

    
103

    
104
                                if (size != set.getSize()) {
105
                                        finishedNoOk();
106
                                        return;
107
                                }
108

    
109
                                while (iter.hasNext()) {
110
                                        iter.next();
111
                                }
112
                        } catch (ConcurrentDataModificationException e) {
113
                                finishedConcurrentError(e);
114
                                return;
115
                        } catch (DataException e) {
116
                                finishedError(e);
117
                                return;
118
                        }
119
                        try {
120

    
121
                                iter.remove();
122
                                size--;
123
                        } catch (DataRuntimeException e) {
124
                                if (e.getCause() instanceof ConcurrentDataModificationException) {
125
                                        finishedConcurrentError(e);
126
                                        return;
127
                                }
128
                                finishedError(e);
129
                                return;
130

    
131
                        } catch (RuntimeException e) {
132
                                finishedError(e);
133
                                return;
134
                        }
135
                        if (size != set.getSize()) {
136
                                finishedNoOk();
137
                        } else {
138
                                finishedOk();
139
                        }
140
                } catch (Throwable e) {
141
                        finishedError(e);
142
                        return;
143
                } finally {
144
                        iter.dispose();
145
                        set.dispose();
146
                }
147
        }
148

    
149

    
150
}