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

History | View | Annotate | Download (2.97 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
/*
25
* AUTHORS (In addition to CIT):
26
* 2009 IVER T.I. S.A.   {{Task}}
27
*/
28

    
29
/**
30
 *
31
 */
32
package org.gvsig.fmap.dal.feature.testmulithread;
33

    
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore;
36
import org.gvsig.tools.dispose.DisposableIterator;
37
import org.gvsig.fmap.dal.feature.EditableFeature;
38
import org.gvsig.fmap.dal.feature.FeatureSet;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
41

    
42
/**
43
 * @author jmvivo
44
 *
45
 */
46
public class InsertFeature extends StoreTask {
47

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

    
59
        /**
60
         * @param store
61
         * @param timeToWait
62
         */
63
        public InsertFeature(String id, FeatureStore store, int timeToWait,
64
                        BaseTestEditableFeatureStore test) {
65
                super(id, store, timeToWait);
66
                this.test = test;
67
        }
68

    
69
        public void run() {
70
                if (!this.startProcess()) {
71
                        return;
72
                }
73
                FeatureSet set;
74
                DisposableIterator iter = null;
75
                try {
76
                        set = this.store.getFeatureSet();
77
                } catch (DataException e) {
78
                        finishedError(e);
79
                        return;
80
                }
81
                try {
82
                        long size = set.getSize();
83
                        EditableFeature newFeature = this.store.createNewFeature(true);
84
                        test.fillPrimaryKeyInserFeature(newFeature);
85

    
86

    
87
                        long i = 0;
88
                        try {
89

    
90
                                iter = set.iterator();
91
                                set.insert(newFeature);
92
                                iter.dispose();
93
                                iter = set.iterator();
94
                                while (iter.hasNext()) {
95
                                        iter.next();
96
                                        i++;
97
                                }
98
                        } catch (ConcurrentDataModificationException e) {
99
                                finishedConcurrentError(e);
100
                                return;
101
                        } catch (DataException e) {
102
                                finishedError(e);
103
                                return;
104
                        }
105

    
106
                        if ((size + 1 == set.getSize()) && (set.getSize() == i)) {
107
                                finishedOk();
108
                        } else {
109
                                finishedNoOk();
110
                        }
111
                } catch (Throwable e) {
112
                        finishedError(e);
113
                        return;
114
                } finally {
115
                        if (iter != null) {
116
                                iter.dispose();
117
                        }
118
                        if (set != null) {
119
                                set.dispose();
120
                        }
121
                }
122
        }
123

    
124

    
125
}