Revision 614
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/castor/ProjectTable.java | ||
---|---|---|
1 | 1 |
package com.iver.cit.gvsig.project.castor; |
2 | 2 |
|
3 | 3 |
import com.hardcode.driverManager.DriverLoadException; |
4 |
import com.hardcode.gdbms.engine.data.DBDriver; |
|
4 |
|
|
5 | 5 |
import com.hardcode.gdbms.engine.data.DataSource; |
6 | 6 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
7 |
import com.hardcode.gdbms.engine.data.DataSourceFactory.DBDriverInfo; |
|
8 |
import com.hardcode.gdbms.engine.data.DataSourceFactory.DriverInfo; |
|
9 |
import com.hardcode.gdbms.engine.data.DataSourceFactory.FileDriverInfo; |
|
7 | 10 |
import com.hardcode.gdbms.engine.data.DriverException; |
8 | 11 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
9 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
|
10 |
import java.text.DateFormat; |
|
11 |
import java.util.Date; |
|
12 | 12 |
|
13 |
import com.hardcode.gdbms.engine.data.DriverException; |
|
14 | 13 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
15 | 14 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
16 |
import com.iver.cit.gvsig.fmap.layers.SelectionSupport; |
|
17 | 15 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
16 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
|
18 | 17 |
import com.iver.cit.gvsig.project.ProjectFactory; |
19 | 18 |
|
20 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
|
21 | 19 |
import com.iver.utiles.XMLEntity; |
22 | 20 |
|
23 |
import com.hardcode.gdbms.engine.data.DataSourceFactory.DriverInfo; |
|
24 |
import com.hardcode.gdbms.engine.data.DataSourceFactory.FileDriverInfo; |
|
25 |
import com.hardcode.gdbms.engine.data.DataSourceFactory.DBDriverInfo; |
|
26 |
|
|
27 | 21 |
import java.text.DateFormat; |
28 | 22 |
|
29 | 23 |
import java.util.Date; |
... | ... | |
38 | 32 |
private static int numTables = 0; |
39 | 33 |
private SelectableDataSource modelo; |
40 | 34 |
private String nameLayer; |
35 |
|
|
41 | 36 |
/* No es necesaria para operar, s?lo para guardar el proyecto */ |
42 | 37 |
private AlphanumericData associatedTable; |
43 | 38 |
|
... | ... | |
84 | 79 |
*/ |
85 | 80 |
public void setName(String string) { |
86 | 81 |
super.setName(string); |
87 |
if (modelo !=null){ |
|
82 |
|
|
83 |
if (modelo != null) { |
|
88 | 84 |
modelo.setName(string); |
89 | 85 |
} |
90 | 86 |
} |
... | ... | |
127 | 123 |
* @param baseName |
128 | 124 |
* @return |
129 | 125 |
* |
130 |
public static ProjectTable createTable(String viewName, FTable ftable) { |
|
131 |
Table t = new Table(); |
|
132 |
t.setName(viewName + " - Datos"); |
|
133 |
t.setCreationDate(DateFormat.getInstance().format(new Date())); |
|
134 |
t.setModelo(ftable); |
|
135 |
numTables++; |
|
136 |
return t; |
|
137 |
}*/ |
|
126 |
public static ProjectTable createTable(String viewName, FTable ftable) {
|
|
127 |
Table t = new Table();
|
|
128 |
t.setName(viewName + " - Datos");
|
|
129 |
t.setCreationDate(DateFormat.getInstance().format(new Date()));
|
|
130 |
t.setModelo(ftable);
|
|
131 |
numTables++;
|
|
132 |
return t;
|
|
133 |
}*/
|
|
138 | 134 |
|
139 | 135 |
/** |
140 | 136 |
* DOCUMENT ME! |
141 | 137 |
* |
142 | 138 |
* @return DOCUMENT ME! |
139 |
* |
|
143 | 140 |
* @throws DriverException |
144 | 141 |
*/ |
145 | 142 |
public XMLEntity getXMLEntity() throws DriverException { |
... | ... | |
147 | 144 |
xml.putProperty("nameClass", this.getClass().getName()); |
148 | 145 |
xml.putProperty("numTables", numTables); |
149 | 146 |
xml.addChild(modelo.getXMLEntity()); |
150 |
DriverInfo di=DataSourceFactory.getDriverInfo(modelo.getName()); |
|
151 |
xml.putProperty("driverName",di.driverName); |
|
152 |
xml.putProperty("name",di.name); |
|
153 |
xml.putProperty("dbms",di.dbms); |
|
154 |
if (associatedTable!=null){ |
|
155 |
xml.putProperty("nameLayer",((FLayer)associatedTable).getName()); |
|
147 |
|
|
148 |
DriverInfo di = DataSourceFactory.getDriverInfo(modelo.getName()); |
|
149 |
xml.putProperty("driverName", di.driverName); |
|
150 |
xml.putProperty("name", di.name); |
|
151 |
xml.putProperty("dbms", di.dbms); |
|
152 |
|
|
153 |
if (associatedTable != null) { |
|
154 |
xml.putProperty("nameLayer", ((FLayer) associatedTable).getName()); |
|
156 | 155 |
} |
157 |
if (di instanceof FileDriverInfo){ |
|
158 |
xml.putProperty("type","file"); |
|
159 |
xml.putProperty("file",((FileDriverInfo)di).file); |
|
160 |
}else if (di instanceof DBDriverInfo){ |
|
161 |
xml.putProperty("type","db"); |
|
162 |
DBDriverInfo dbdi=(DBDriverInfo)di; |
|
163 |
|
|
164 |
xml.putProperty("host",dbdi.host); |
|
165 |
xml.putProperty("port",dbdi.port); |
|
166 |
xml.putProperty("user",dbdi.user); |
|
167 |
xml.putProperty("password",dbdi.password); |
|
168 |
xml.putProperty("dbName",dbdi.dbName); |
|
169 |
xml.putProperty("tableName",dbdi.sqlQuery); |
|
170 |
xml.putProperty("driverInfo",dbdi.driverInfo); |
|
171 |
|
|
156 |
|
|
157 |
if (di instanceof FileDriverInfo) { |
|
158 |
xml.putProperty("type", "file"); |
|
159 |
xml.putProperty("file", ((FileDriverInfo) di).file); |
|
160 |
} else if (di instanceof DBDriverInfo) { |
|
161 |
xml.putProperty("type", "db"); |
|
162 |
|
|
163 |
DBDriverInfo dbdi = (DBDriverInfo) di; |
|
164 |
|
|
165 |
xml.putProperty("host", dbdi.host); |
|
166 |
xml.putProperty("port", dbdi.port); |
|
167 |
xml.putProperty("user", dbdi.user); |
|
168 |
xml.putProperty("password", dbdi.password); |
|
169 |
xml.putProperty("dbName", dbdi.dbName); |
|
170 |
xml.putProperty("tableName", dbdi.sqlQuery); |
|
171 |
xml.putProperty("driverInfo", dbdi.driverInfo); |
|
172 | 172 |
} |
173 |
|
|
173 | 174 |
return xml; |
174 | 175 |
} |
175 |
private void setProjectTable(ProjectTable pt){ |
|
176 |
numTables=ProjectTable.numTables; |
|
177 |
associatedTable=pt.associatedTable; |
|
178 |
modelo=pt.modelo; |
|
179 |
} |
|
180 |
public void setSelectionSupport(SelectionSupport ss){ |
|
181 |
modelo.setSelectionSupport(ss); |
|
182 |
} |
|
176 |
|
|
177 |
/*private void setProjectTable(ProjectTable pt){ |
|
178 |
numTables=ProjectTable.numTables; |
|
179 |
associatedTable=pt.associatedTable; |
|
180 |
modelo=pt.modelo; |
|
181 |
} |
|
182 |
*/ |
|
183 |
/*public void setSelectionSupport(SelectionSupport ss){ |
|
184 |
modelo.setSelectionSupport(ss); |
|
185 |
} |
|
186 |
*/ |
|
187 |
|
|
183 | 188 |
/** |
189 |
* DOCUMENT ME! |
|
190 |
* |
|
191 |
* @param xml DOCUMENT ME! |
|
192 |
* @param p DOCUMENT ME! |
|
193 |
* |
|
184 | 194 |
* @throws XMLException |
195 |
* |
|
185 | 196 |
* @see com.iver.cit.gvsig.project.castor.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity) |
186 | 197 |
*/ |
187 |
public void setXMLEntity(XMLEntity xml, Project p) throws XMLException { |
|
198 |
public void setXMLEntity(XMLEntity xml, Project p) |
|
199 |
throws XMLException { |
|
188 | 200 |
numTables = xml.getIntProperty("numViews"); |
189 |
if (xml.getStringProperty("nameLayer")!=null){ |
|
190 |
nameLayer=xml.getStringProperty("nameLayer"); |
|
201 |
|
|
202 |
if (xml.getStringProperty("nameLayer") != null) { |
|
203 |
nameLayer = xml.getStringProperty("nameLayer"); |
|
191 | 204 |
} |
192 |
if (xml.getStringProperty("type").equals("file")){ |
|
193 |
DataSourceFactory.addFileDataSource(xml.getStringProperty("driverName"),xml.getStringProperty("name"),xml.getStringProperty("file"),xml.getStringProperty("dbms")); |
|
205 |
|
|
206 |
if (xml.getStringProperty("type").equals("file")) { |
|
207 |
DataSourceFactory.addFileDataSource(xml.getStringProperty( |
|
208 |
"driverName"), xml.getStringProperty("name"), |
|
209 |
xml.getStringProperty("file"), xml.getStringProperty("dbms")); |
|
210 |
|
|
194 | 211 |
DataSource dataSource; |
212 |
|
|
195 | 213 |
try { |
196 |
dataSource = DataSourceFactory.createRandomDataSource(xml.getStringProperty("name")); |
|
214 |
dataSource = DataSourceFactory.createRandomDataSource(xml.getStringProperty( |
|
215 |
"name")); |
|
197 | 216 |
} catch (NoSuchTableException e) { |
198 | 217 |
throw new XMLException(e); |
199 | 218 |
} catch (DriverLoadException e) { |
200 | 219 |
throw new XMLException(e); |
201 | 220 |
} |
202 |
|
|
203 |
///modelo = new SelectableDataSource(xml.getStringProperty("name"), dataSource); |
|
204 |
ProjectTable pt=ProjectFactory.createTable(xml.getStringProperty("nameLayer"), new SelectableDataSource(xml.getStringProperty("name"), dataSource)); |
|
205 |
setProjectTable(pt); |
|
206 |
/*for (int i=0;i<p.getViews().size();i++){ |
|
207 |
//if (p.getViews().get(i) instanceof CommonOperations){ |
|
208 |
CommonOperations co=(CommonOperations)((ProjectView)p.getViews().get(i)); |
|
209 |
|
|
210 |
if (co.getName().equals(getNameLayer())){ |
|
211 |
try { |
|
212 |
setSelectionSupport(co.getRecordset().getSelectionSupport()); |
|
213 |
} catch (DriverLoadException e1) { |
|
214 |
throw new XMLException(e1); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
//} |
|
221 |
|
|
222 |
ProjectTable pt = ProjectFactory.createTable(xml.getStringProperty( |
|
223 |
"nameLayer"), |
|
224 |
new SelectableDataSource(xml.getStringProperty("name"), |
|
225 |
dataSource)); |
|
226 |
|
|
227 |
for (int i = 0; i < p.getViews().size(); i++) { |
|
228 |
FLayer layer = ((ProjectView) p.getViews().get(i)).getMapContext() |
|
229 |
.getLayers().getLayer(getNameLayer()); |
|
230 |
|
|
231 |
if (layer.getName().equals(getNameLayer())) { |
|
232 |
try { |
|
233 |
modelo = ((AlphanumericData) layer).getRecordset(); |
|
234 |
} catch (DriverLoadException e1) { |
|
235 |
throw new XMLException(e1); |
|
236 |
} |
|
237 |
|
|
238 |
numTables = ProjectTable.numTables; |
|
239 |
associatedTable = (AlphanumericData) layer; |
|
240 |
} |
|
219 | 241 |
} |
220 |
*/ |
|
221 |
for (int i=0;i<p.getViews().size();i++){ |
|
222 |
((ProjectView)p.getViews().get(i)).getMapContext().getLayers().getLayerByName(getNameLayer()); |
|
223 |
} |
|
224 |
}else if (xml.getStringProperty("type").equals("db")){ |
|
225 |
DataSourceFactory.addDBDataSource(xml.getStringProperty("name"),xml.getStringProperty("host"),xml.getIntProperty("port"),xml.getStringProperty("user"),xml.getStringProperty("password"),xml.getStringProperty("dbName"),xml.getStringProperty("tableName"),xml.getStringProperty("driverName")); |
|
242 |
} else if (xml.getStringProperty("type").equals("db")) { |
|
243 |
DataSourceFactory.addDBDataSource(xml.getStringProperty("name"), |
|
244 |
xml.getStringProperty("host"), xml.getIntProperty("port"), |
|
245 |
xml.getStringProperty("user"), |
|
246 |
xml.getStringProperty("password"), |
|
247 |
xml.getStringProperty("dbName"), |
|
248 |
xml.getStringProperty("tableName"), |
|
249 |
xml.getStringProperty("driverName")); |
|
226 | 250 |
} |
251 |
|
|
227 | 252 |
setName(xml.getStringProperty("name")); |
228 |
//}else{ |
|
229 |
|
|
230 |
|
|
231 |
//} |
|
232 |
///setModelo(dataSource); |
|
233 | 253 |
} |
234 | 254 |
|
235 | 255 |
/** |
236 | 256 |
* DOCUMENT ME! |
237 | 257 |
* |
238 |
* @return DOCUMENT ME! |
|
258 |
* @param associatedTable DOCUMENT ME! |
|
259 |
* |
|
260 |
* @throws DriverLoadException DOCUMENT ME! |
|
239 | 261 |
*/ |
240 |
/*private CommonOperations getAssociatedTable() { |
|
241 |
return associatedTable; |
|
242 |
} |
|
243 |
*/ |
|
262 |
|
|
263 |
public AlphanumericData getAssociatedTable() { |
|
264 |
return associatedTable; |
|
265 |
} |
|
266 |
|
|
267 |
|
|
244 | 268 |
/** |
245 | 269 |
* DOCUMENT ME! |
246 | 270 |
* |
247 | 271 |
* @param associatedTable DOCUMENT ME! |
272 |
* |
|
248 | 273 |
* @throws DriverLoadException |
249 |
* @throws DriverLoadException |
|
250 | 274 |
*/ |
251 |
public void setAssociatedTable(AlphanumericData associatedTable) throws DriverLoadException { |
|
275 |
public void setAssociatedTable(AlphanumericData associatedTable) |
|
276 |
throws DriverLoadException { |
|
252 | 277 |
this.associatedTable = associatedTable; |
253 |
setSelectionSupport(associatedTable.getRecordset().getSelectionSupport()); |
|
278 |
|
|
279 |
///setSelectionSupport(associatedTable.getRecordset().getSelectionSupport()); |
|
254 | 280 |
} |
255 |
public String getNameLayer(){ |
|
281 |
|
|
282 |
/** |
|
283 |
* DOCUMENT ME! |
|
284 |
* |
|
285 |
* @return DOCUMENT ME! |
|
286 |
*/ |
|
287 |
public String getNameLayer() { |
|
256 | 288 |
return nameLayer; |
257 | 289 |
} |
258 | 290 |
} |
Also available in: Unified diff