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 / workspace / tables / TopologyplanTable.java @ 3315
History | View | Annotate | Download (5.65 KB)
1 |
package org.gvsig.vcsgis.lib.workspace.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.vcsgis.lib.VCSGisTopologyPlan; |
17 |
import org.gvsig.vcsgis.lib.VCSGisTopologyPlanImpl; |
18 |
import static org.gvsig.vcsgis.lib.VCSGisUtils.updateMessageDigest; |
19 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
20 |
|
21 |
/**
|
22 |
*
|
23 |
* @author gvSIG Team
|
24 |
*/
|
25 |
@SuppressWarnings("UseSpecificCatch") |
26 |
public class TopologyplanTable extends AbstractTable { |
27 |
|
28 |
public static final String TABLE_NAME = "VCSGIS_TOPOLOGYPLANS"; |
29 |
|
30 |
private static final String COD_TOPOLOGYPLAN = "COD_TOPOLOGYPLAN"; |
31 |
private static final String TOPPLAN_NAME = "TOPP_NAME"; |
32 |
private static final String TOPPLAN_DESCRIPTION = "TOPP_DESCRIPTION"; |
33 |
private static final String TOPPLAN_DATA = "TOPP_DATA"; |
34 |
|
35 |
public static final FeatureType featureType() { |
36 |
DataManager dataManager = DALLocator.getDataManager(); |
37 |
EditableFeatureType ft = dataManager.createFeatureType(); |
38 |
ft.setLabel("VCSGIS TopologyPlans");
|
39 |
ft.getTags().set("ID", TABLE_NAME);
|
40 |
ft.add(COD_TOPOLOGYPLAN, DataTypes.STRING) |
41 |
.setSize(40)
|
42 |
.setIsPrimaryKey(true)
|
43 |
.setLabel("Code")
|
44 |
.setReadOnly(true);
|
45 |
ft.add(TOPPLAN_NAME, DataTypes.STRING) |
46 |
.setIsIndexed(true)
|
47 |
.setAllowIndexDuplicateds(true)
|
48 |
.setSize(50)
|
49 |
.setLabel("Name");
|
50 |
ft.add(TOPPLAN_DESCRIPTION, DataTypes.STRING) |
51 |
.setSize(10240)
|
52 |
.setLabel("Description");
|
53 |
ft.add(TOPPLAN_DATA, DataTypes.STRING) |
54 |
.setSize(10240)
|
55 |
.setLabel("Serialized topology plan in json.");
|
56 |
|
57 |
return ft.getNotEditableCopy();
|
58 |
} |
59 |
|
60 |
public TopologyplanTable() {
|
61 |
super(TABLE_NAME, featureType());
|
62 |
} |
63 |
|
64 |
public String getByCode(VCSGisWorkspace workspace, String topologyPlanCode) { |
65 |
FeatureStore store = null;
|
66 |
try {
|
67 |
store = workspace.getFeatureStore(TABLE_NAME); |
68 |
Feature f = store.findFirst("\""+COD_TOPOLOGYPLAN+"\"='"+topologyPlanCode+"'"); |
69 |
if( f==null ) { |
70 |
return null; |
71 |
} |
72 |
return f.getString(TOPPLAN_DATA);
|
73 |
} catch (Exception ex) { |
74 |
throw new RuntimeException("Can't retrieve topology plan '"+topologyPlanCode+"'.", ex); |
75 |
} finally {
|
76 |
DisposeUtils.disposeQuietly(store); |
77 |
} |
78 |
} |
79 |
|
80 |
|
81 |
public String getHashCode(VCSGisWorkspace workspace) { |
82 |
FeatureStore store = null;
|
83 |
DisposableFeatureSetIterable changes = null;
|
84 |
try {
|
85 |
MessageDigest md = MessageDigest.getInstance("MD5"); |
86 |
store = workspace.getFeatureStore(TABLE_NAME); |
87 |
changes = store.getFeatureSet().iterable(); |
88 |
for (Feature change : changes) {
|
89 |
updateMessageDigest(md, change, COD_TOPOLOGYPLAN); |
90 |
updateMessageDigest(md, change, TOPPLAN_NAME); |
91 |
updateMessageDigest(md, change, TOPPLAN_DESCRIPTION); |
92 |
updateMessageDigest(md, change, TOPPLAN_DATA); |
93 |
} |
94 |
String hash = Hex.encodeHexString(md.digest());
|
95 |
return hash;
|
96 |
} catch (Exception ex) { |
97 |
throw new RuntimeException("Can't retrieve hash of topology plans.", ex); |
98 |
} finally {
|
99 |
DisposeUtils.dispose(changes); |
100 |
DisposeUtils.dispose(store); |
101 |
} |
102 |
} |
103 |
|
104 |
public static class TopologyPlanRow extends AbstractRow implements VCSGisTopologyPlan { |
105 |
|
106 |
public TopologyPlanRow(VCSGisWorkspace workspace) {
|
107 |
super(workspace, TABLE_NAME, COD_TOPOLOGYPLAN);
|
108 |
} |
109 |
|
110 |
public TopologyPlanRow(VCSGisWorkspace workspace, Feature feature) {
|
111 |
super(workspace, TABLE_NAME, COD_TOPOLOGYPLAN, feature);
|
112 |
} |
113 |
|
114 |
|
115 |
@Override
|
116 |
public String getTopologyPlanCode() { |
117 |
return this.getString(COD_TOPOLOGYPLAN); |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public String getName() { |
122 |
return this.getString(TOPPLAN_NAME); |
123 |
} |
124 |
|
125 |
@Override
|
126 |
public String getDescription() { |
127 |
return this.getString(TOPPLAN_DESCRIPTION); |
128 |
} |
129 |
|
130 |
@Override
|
131 |
public String getData() { |
132 |
return this.getString(TOPPLAN_DATA); |
133 |
} |
134 |
|
135 |
@Override
|
136 |
public String getLabel() { |
137 |
return this.getName(); |
138 |
} |
139 |
|
140 |
@Override
|
141 |
public VCSGisTopologyPlan getValue() {
|
142 |
return this; |
143 |
} |
144 |
|
145 |
@Override
|
146 |
public void copyFrom(VCSGisTopologyPlan other) { |
147 |
this.set(COD_TOPOLOGYPLAN,other.getTopologyPlanCode());
|
148 |
this.set(TOPPLAN_NAME,other.getName());
|
149 |
this.set(TOPPLAN_DESCRIPTION,other.getDescription());
|
150 |
this.set(TOPPLAN_DATA,other.getData());
|
151 |
} |
152 |
|
153 |
@Override
|
154 |
public JsonObject toJson() {
|
155 |
return this.toJsonBuilder().build(); |
156 |
} |
157 |
|
158 |
@Override
|
159 |
public JsonObjectBuilder toJsonBuilder() {
|
160 |
return VCSGisTopologyPlanImpl.toJsonBuilder(this); |
161 |
} |
162 |
|
163 |
@Override
|
164 |
public String toString() { |
165 |
return VCSGisTopologyPlanImpl.toString(this); |
166 |
} |
167 |
} |
168 |
} |