Statistics
| Revision:

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

History | View | Annotate | Download (2.53 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.feature.EditableFeature;
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 InsertFeature extends EditStore {
46

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

    
55
        /**
56
         * @param store
57
         * @param timeToWait
58
         */
59
        public InsertFeature(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
                try {
75
                        long size = set.getSize();
76
                        EditableFeature newFeature = this.store.createNewFeature(true);
77

    
78
                        long i = 0;
79
                        Iterator iter = null;
80
                        try {
81

    
82
                                iter = set.iterator();
83
                                set.insert(newFeature);
84
                                iter = set.iterator();
85
                                while (iter.hasNext()) {
86
                                        iter.next();
87
                                        i++;
88
                                }
89
                        } catch (ConcurrentDataModificationException e) {
90
                                finishedConcurrentError(e);
91
                                return;
92
                        } catch (DataException e) {
93
                                finishedError(e);
94
                                return;
95
                        }
96

    
97
                        if ((size + 1 == set.getSize()) && (set.getSize() == i)) {
98
                                finishedOk();
99
                        } else {
100
                                finishedNoOk();
101
                        }
102
                } catch (Throwable e) {
103
                        finishedError(e);
104
                        return;
105
                } finally {
106
                        set.dispose();
107
                }
108
        }
109

    
110

    
111
}