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

History | View | Annotate | Download (3.2 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 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, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.feature.testmulithread;
25

    
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.exception.DataRuntimeException;
28
import org.gvsig.tools.dispose.DisposableIterator;
29
import org.gvsig.fmap.dal.feature.FeatureSet;
30
import org.gvsig.fmap.dal.feature.FeatureStore;
31
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
32

    
33
/**
34
 * @author jmvivo
35
 *
36
 */
37
public class DeleteFirstAndLastFeature extends StoreTask {
38

    
39
        /**
40
         * @param store
41
         * @param timeToWait
42
         */
43
        public DeleteFirstAndLastFeature(String id, FeatureStore store) {
44
                super(id, store);
45
        }
46

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

    
55
        public void run() {
56
                if (!this.startProcess()) {
57
                        return;
58
                }
59
                FeatureSet set;
60
                DisposableIterator iter = null;
61
                try {
62
                        set = this.store.getFeatureSet();
63
                } catch (DataException e) {
64
                        finishedError(e);
65
                        return;
66
                }
67

    
68
                try {
69
                        long size = set.getSize();
70
                        try {
71

    
72
                                iter = set.fastIterator();
73

    
74
                                if (!iter.hasNext()) {
75
                                        finishedNoOk();
76
                                        return;
77
                                }
78
                                iter.next();
79

    
80
                                try {
81
                                        iter.remove();
82
                                        size--;
83
                                } catch (DataRuntimeException e) {
84
                                        if (e.getCause() instanceof ConcurrentDataModificationException) {
85
                                                finishedConcurrentError(e);
86
                                                return;
87
                                        }
88
                                        finishedError(e);
89
                                        return;
90

    
91
                                } catch (RuntimeException e) {
92
                                        finishedError(e);
93
                                        return;
94
                                }
95

    
96

    
97
                                if (size != set.getSize()) {
98
                                        finishedNoOk();
99
                                        return;
100
                                }
101

    
102
                                while (iter.hasNext()) {
103
                                        iter.next();
104
                                }
105
                        } catch (ConcurrentDataModificationException e) {
106
                                finishedConcurrentError(e);
107
                                return;
108
                        } catch (DataException e) {
109
                                finishedError(e);
110
                                return;
111
                        }
112
                        try {
113

    
114
                                iter.remove();
115
                                size--;
116
                        } catch (DataRuntimeException e) {
117
                                if (e.getCause() instanceof ConcurrentDataModificationException) {
118
                                        finishedConcurrentError(e);
119
                                        return;
120
                                }
121
                                finishedError(e);
122
                                return;
123

    
124
                        } catch (RuntimeException e) {
125
                                finishedError(e);
126
                                return;
127
                        }
128
                        if (size != set.getSize()) {
129
                                finishedNoOk();
130
                        } else {
131
                                finishedOk();
132
                        }
133
                } catch (Throwable e) {
134
                        finishedError(e);
135
                        return;
136
                } finally {
137
                        iter.dispose();
138
                        set.dispose();
139
                }
140
        }
141

    
142

    
143
}