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