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 @ 40435
History | View | Annotate | Download (2.92 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.feature.BaseTestEditableFeatureStore; |
35 |
import org.gvsig.tools.dispose.DisposableIterator; |
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 StoreTask { |
46 |
|
47 |
private BaseTestEditableFeatureStore test;
|
48 |
/**
|
49 |
* @param store
|
50 |
* @param timeToWait
|
51 |
*/
|
52 |
public InsertFeature(String id, FeatureStore store, |
53 |
BaseTestEditableFeatureStore test) { |
54 |
super(id, store);
|
55 |
this.test = test;
|
56 |
} |
57 |
|
58 |
/**
|
59 |
* @param store
|
60 |
* @param timeToWait
|
61 |
*/
|
62 |
public InsertFeature(String id, FeatureStore store, int timeToWait, |
63 |
BaseTestEditableFeatureStore test) { |
64 |
super(id, store, timeToWait);
|
65 |
this.test = test;
|
66 |
} |
67 |
|
68 |
public void run() { |
69 |
if (!this.startProcess()) { |
70 |
return;
|
71 |
} |
72 |
FeatureSet set; |
73 |
DisposableIterator iter = null;
|
74 |
try {
|
75 |
set = this.store.getFeatureSet();
|
76 |
} catch (DataException e) {
|
77 |
finishedError(e); |
78 |
return;
|
79 |
} |
80 |
try {
|
81 |
long size = set.getSize();
|
82 |
EditableFeature newFeature = this.store.createNewFeature(true); |
83 |
test.fillPrimaryKeyInserFeature(newFeature); |
84 |
|
85 |
|
86 |
long i = 0; |
87 |
try {
|
88 |
|
89 |
iter = set.iterator(); |
90 |
set.insert(newFeature); |
91 |
iter.dispose(); |
92 |
iter = set.iterator(); |
93 |
while (iter.hasNext()) {
|
94 |
iter.next(); |
95 |
i++; |
96 |
} |
97 |
} catch (ConcurrentDataModificationException e) {
|
98 |
finishedConcurrentError(e); |
99 |
return;
|
100 |
} catch (DataException e) {
|
101 |
finishedError(e); |
102 |
return;
|
103 |
} |
104 |
|
105 |
if ((size + 1 == set.getSize()) && (set.getSize() == i)) { |
106 |
finishedOk(); |
107 |
} else {
|
108 |
finishedNoOk(); |
109 |
} |
110 |
} catch (Throwable e) { |
111 |
finishedError(e); |
112 |
return;
|
113 |
} finally {
|
114 |
if (iter != null) { |
115 |
iter.dispose(); |
116 |
} |
117 |
if (set != null) { |
118 |
set.dispose(); |
119 |
} |
120 |
} |
121 |
} |
122 |
|
123 |
|
124 |
} |