gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.lib / org.gvsig.vcsgis.lib.impl / src / main / java / org / gvsig / vcsgis / lib / repository / localdb / tables / TopologyplanRepoTable.java @ 3633
History | View | Annotate | Download (6.82 KB)
1 |
package org.gvsig.vcsgis.lib.repository.localdb.tables; |
---|---|
2 |
|
3 |
import java.security.MessageDigest; |
4 |
import javax.json.JsonObject; |
5 |
import org.apache.commons.codec.binary.Hex; |
6 |
import org.gvsig.fmap.dal.DALLocator; |
7 |
import org.gvsig.fmap.dal.DataManager; |
8 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
9 |
import org.gvsig.fmap.dal.feature.Feature; |
10 |
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable; |
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
12 |
import org.gvsig.fmap.dal.feature.FeatureType; |
13 |
import org.gvsig.json.JsonObjectBuilder; |
14 |
import org.gvsig.tools.dataTypes.DataTypes; |
15 |
import org.gvsig.tools.dispose.DisposeUtils; |
16 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
17 |
import static org.gvsig.vcsgis.lib.VCSGisManager.VCSGISCODELEN; |
18 |
import org.gvsig.vcsgis.lib.VCSGisTopologyPlan; |
19 |
import org.gvsig.vcsgis.lib.VCSGisTopologyPlanImpl; |
20 |
import static org.gvsig.vcsgis.lib.VCSGisUtils.updateMessageDigest; |
21 |
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldb; |
22 |
|
23 |
/**
|
24 |
*
|
25 |
* @author gvSIG Team
|
26 |
*/
|
27 |
@SuppressWarnings("UseSpecificCatch") |
28 |
public class TopologyplanRepoTable extends AbstractRepoTable { |
29 |
|
30 |
public static final String TABLE_NAME = "VCSGISREPO_TOPOLOGYPLANS"; |
31 |
|
32 |
public static final String COD_TOPOLOGYPLAN = "COD_TOPOLOGYPLAN"; |
33 |
public static final String TOPPLAN_NAME = "TOPP_NAME"; |
34 |
private static final String TOPPLAN_DESCRIPTION = "TOPP_DESCRIPTION"; |
35 |
private static final String TOPPLAN_DATA = "TOPP_DATA"; |
36 |
|
37 |
public static class TopologyplanRow extends AbstractRow implements VCSGisTopologyPlan { |
38 |
|
39 |
public TopologyplanRow(VCSGisRepositoryLocaldb repository) {
|
40 |
super(repository, TABLE_NAME, COD_TOPOLOGYPLAN, null); |
41 |
} |
42 |
|
43 |
public TopologyplanRow(VCSGisRepositoryLocaldb repository, Feature feature) {
|
44 |
super(repository, TABLE_NAME, COD_TOPOLOGYPLAN, feature);
|
45 |
} |
46 |
|
47 |
@Override
|
48 |
public String getTopologyPlanCode() { |
49 |
return this.getString(COD_TOPOLOGYPLAN); |
50 |
} |
51 |
|
52 |
@Override
|
53 |
public String getName() { |
54 |
return this.getString(TOPPLAN_NAME); |
55 |
} |
56 |
|
57 |
@Override
|
58 |
public String getDescription() { |
59 |
return this.getString(TOPPLAN_DESCRIPTION); |
60 |
} |
61 |
|
62 |
@Override
|
63 |
public String getData() { |
64 |
return this.getString(TOPPLAN_DATA); |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public String getLabel() { |
69 |
return this.getName(); |
70 |
} |
71 |
|
72 |
@Override
|
73 |
public VCSGisTopologyPlan getValue() {
|
74 |
return this; |
75 |
} |
76 |
|
77 |
@Override
|
78 |
public void copyFrom(VCSGisTopologyPlan other) { |
79 |
this.set(COD_TOPOLOGYPLAN,other.getTopologyPlanCode());
|
80 |
this.set(TOPPLAN_NAME,other.getName());
|
81 |
this.set(TOPPLAN_DESCRIPTION,other.getDescription());
|
82 |
this.set(TOPPLAN_DATA,other.getData());
|
83 |
} |
84 |
|
85 |
@Override
|
86 |
public JsonObject toJson() {
|
87 |
return this.toJsonBuilder().build(); |
88 |
} |
89 |
|
90 |
@Override
|
91 |
public JsonObjectBuilder toJsonBuilder() {
|
92 |
return VCSGisTopologyPlanImpl.toJsonBuilder(this); |
93 |
} |
94 |
|
95 |
@Override
|
96 |
public String toString() { |
97 |
return VCSGisTopologyPlanImpl.toString(this); |
98 |
} |
99 |
|
100 |
} |
101 |
|
102 |
public static final FeatureType featureType() { |
103 |
DataManager dataManager = DALLocator.getDataManager(); |
104 |
EditableFeatureType ft = dataManager.createFeatureType(); |
105 |
ft.setLabel("VCSGIS TopologyPlans");
|
106 |
ft.getTags().set("ID", TABLE_NAME);
|
107 |
ft.getTags().set(DynFormSPIManager.TAG_DYNFORM_HEIGHT, 300);
|
108 |
ft.getTags().set(DynFormSPIManager.TAG_DYNFORM_WIDTH, 570);
|
109 |
ft.getTags().set(DynFormSPIManager.TAG_DYNFORM_LAYOUTMODE, DynFormSPIManager.TAG_DYNFORM_LAYOUTMODE_VALUE_TABS); |
110 |
ft.add(COD_TOPOLOGYPLAN, DataTypes.STRING) |
111 |
.setSize(VCSGISCODELEN) |
112 |
.setIsPrimaryKey(true)
|
113 |
.setLabel("Code")
|
114 |
.setReadOnly(false)
|
115 |
.setDefaultFieldValue("<%=replace(UUID(),'-','')%>");
|
116 |
ft.add(TOPPLAN_NAME, DataTypes.STRING) |
117 |
.setIsIndexed(true)
|
118 |
.setAllowIndexDuplicateds(true)
|
119 |
.setSize(50)
|
120 |
.setLabel("Name");
|
121 |
ft.add(TOPPLAN_DESCRIPTION, DataTypes.STRING) |
122 |
.setDataProfileName("Text")
|
123 |
.setSize(10240)
|
124 |
.setLabel("Description");
|
125 |
ft.add(TOPPLAN_DATA, DataTypes.STRING) |
126 |
.setDataProfileName("Text")
|
127 |
.setSize(10240)
|
128 |
.setLabel("Serialized topology plan in json.")
|
129 |
.setGroup("Plan");
|
130 |
|
131 |
return ft.getNotEditableCopy();
|
132 |
} |
133 |
|
134 |
public TopologyplanRepoTable() {
|
135 |
super(TABLE_NAME, featureType());
|
136 |
} |
137 |
|
138 |
public String getByCode(VCSGisRepositoryLocaldb repository, String topologyPlanCode) { |
139 |
FeatureStore store = null;
|
140 |
try {
|
141 |
store = repository.getFeatureStore(TABLE_NAME); |
142 |
Feature f = store.findFirst("\"" + COD_TOPOLOGYPLAN + "\"='" + topologyPlanCode + "'"); |
143 |
if (f == null) { |
144 |
return null; |
145 |
} |
146 |
return f.getString(TOPPLAN_DATA);
|
147 |
} catch (Exception ex) { |
148 |
throw new RuntimeException("Can't retrieve topology plan '" + topologyPlanCode + "'.", ex); |
149 |
} finally {
|
150 |
DisposeUtils.disposeQuietly(store); |
151 |
} |
152 |
} |
153 |
|
154 |
public DisposableFeatureSetIterable getAll(VCSGisRepositoryLocaldb repository) {
|
155 |
FeatureStore store = null;
|
156 |
try {
|
157 |
store = repository.getFeatureStore(TABLE_NAME); |
158 |
DisposableFeatureSetIterable changes = store.getFeatureSet().iterable(); |
159 |
return changes;
|
160 |
} catch (Exception ex) { |
161 |
throw new RuntimeException("Can't retrieve all topology plans.", ex); |
162 |
} finally {
|
163 |
if( store!=null ) { |
164 |
DisposeUtils.dispose(store); |
165 |
} |
166 |
} |
167 |
} |
168 |
|
169 |
public String getHashCode(VCSGisRepositoryLocaldb repository) { |
170 |
FeatureStore store = null;
|
171 |
DisposableFeatureSetIterable changes = null;
|
172 |
try {
|
173 |
MessageDigest md = MessageDigest.getInstance("MD5"); |
174 |
store = repository.getFeatureStore(TABLE_NAME); |
175 |
changes = store.getFeatureSet().iterable(); |
176 |
for (Feature change : changes) {
|
177 |
updateMessageDigest(md, change, COD_TOPOLOGYPLAN); |
178 |
updateMessageDigest(md, change, TOPPLAN_NAME); |
179 |
updateMessageDigest(md, change, TOPPLAN_DESCRIPTION); |
180 |
updateMessageDigest(md, change, TOPPLAN_DATA); |
181 |
} |
182 |
String hash = Hex.encodeHexString(md.digest());
|
183 |
return hash;
|
184 |
} catch (Exception ex) { |
185 |
throw new RuntimeException("Can't retrieve hash of topology plans.", ex); |
186 |
} finally {
|
187 |
DisposeUtils.dispose(changes); |
188 |
DisposeUtils.dispose(store); |
189 |
} |
190 |
} |
191 |
} |