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 / InsertFeature.java @ 40596

History | View | Annotate | Download (2.89 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.feature.BaseTestEditableFeatureStore;
28
import org.gvsig.tools.dispose.DisposableIterator;
29
import org.gvsig.fmap.dal.feature.EditableFeature;
30
import org.gvsig.fmap.dal.feature.FeatureSet;
31
import org.gvsig.fmap.dal.feature.FeatureStore;
32
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
33

    
34
/**
35
 * @author jmvivo
36
 *
37
 */
38
public class InsertFeature extends StoreTask {
39

    
40
        private BaseTestEditableFeatureStore test;
41
        /**
42
         * @param store
43
         * @param timeToWait
44
         */
45
        public InsertFeature(String id, FeatureStore store,
46
                        BaseTestEditableFeatureStore test) {
47
                super(id, store);
48
                this.test = test;
49
        }
50

    
51
        /**
52
         * @param store
53
         * @param timeToWait
54
         */
55
        public InsertFeature(String id, FeatureStore store, int timeToWait,
56
                        BaseTestEditableFeatureStore test) {
57
                super(id, store, timeToWait);
58
                this.test = test;
59
        }
60

    
61
        public void run() {
62
                if (!this.startProcess()) {
63
                        return;
64
                }
65
                FeatureSet set;
66
                DisposableIterator iter = null;
67
                try {
68
                        set = this.store.getFeatureSet();
69
                } catch (DataException e) {
70
                        finishedError(e);
71
                        return;
72
                }
73
                try {
74
                        long size = set.getSize();
75
                        EditableFeature newFeature = this.store.createNewFeature(true);
76
                        test.fillPrimaryKeyInserFeature(newFeature);
77

    
78

    
79
                        long i = 0;
80
                        try {
81

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

    
98
                        if ((size + 1 == set.getSize()) && (set.getSize() == i)) {
99
                                finishedOk();
100
                        } else {
101
                                finishedNoOk();
102
                        }
103
                } catch (Throwable e) {
104
                        finishedError(e);
105
                        return;
106
                } finally {
107
                        if (iter != null) {
108
                                iter.dispose();
109
                        }
110
                        if (set != null) {
111
                                set.dispose();
112
                        }
113
                }
114
        }
115

    
116

    
117
}