Revision 2183 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/LayerFactory.java
LayerFactory.java | ||
---|---|---|
45 | 45 |
import com.hardcode.driverManager.DriverManager; |
46 | 46 |
|
47 | 47 |
import com.hardcode.gdbms.engine.customQuery.QueryManager; |
48 |
import com.hardcode.gdbms.engine.data.DataSource; |
|
48 | 49 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
50 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
|
51 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
|
49 | 52 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
53 |
import com.hardcode.gdbms.engine.instruction.TableNotFoundException; |
|
54 |
import com.hardcode.gdbms.engine.values.Value; |
|
55 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
50 | 56 |
|
51 | 57 |
import com.iver.cit.gvsig.fmap.DriverException; |
58 |
import com.iver.cit.gvsig.fmap.ProgressListener; |
|
59 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
52 | 60 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
53 | 61 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
54 | 62 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
55 | 63 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
56 | 64 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
65 |
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
|
57 | 66 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
67 |
import com.iver.cit.gvsig.fmap.drivers.arcsde.ArcSdeDriver; |
|
58 | 68 |
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSDriver; |
59 | 69 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
60 | 70 |
import com.iver.cit.gvsig.fmap.operations.arcview.ArcJoin; |
61 | 71 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
62 | 72 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
73 |
import com.iver.utiles.StringUtilities; |
|
63 | 74 |
|
64 | 75 |
import org.apache.log4j.Logger; |
65 | 76 |
|
66 | 77 |
import org.cresques.cts.IProjection; |
78 |
//import org.hsqldb.lib.StringUtil; |
|
67 | 79 |
|
68 | 80 |
import java.awt.geom.Rectangle2D; |
69 | 81 |
|
70 | 82 |
import java.io.File; |
83 |
import java.io.IOException; |
|
71 | 84 |
|
72 | 85 |
import java.net.URL; |
73 | 86 |
|
74 | 87 |
import java.sql.ResultSet; |
75 | 88 |
import java.sql.SQLException; |
76 | 89 |
import java.sql.Statement; |
90 |
import java.sql.Types; |
|
77 | 91 |
import java.util.Enumeration; |
78 | 92 |
import java.util.TreeMap; |
79 | 93 |
|
... | ... | |
115 | 129 |
* |
116 | 130 |
* @throws DriverException |
117 | 131 |
* @throws DriverIOException |
118 |
* |
|
132 |
*/
|
|
119 | 133 |
public static FLayer createLayer(String layerName, String driverName, |
120 | 134 |
File f, IProjection proj) throws DriverException { |
121 | 135 |
//Se obtiene el driver que lee |
... | ... | |
135 | 149 |
|
136 | 150 |
return null; |
137 | 151 |
} |
138 |
*/ |
|
152 |
|
|
139 | 153 |
/** |
140 | 154 |
* Crea un RandomVectorialFile con el driver que se le pasa como par?metro |
141 | 155 |
* y guard?ndose el nombre del fichero para realizar los accesos, la capa |
... | ... | |
265 | 279 |
* |
266 | 280 |
* @throws UnsupportedOperationException |
267 | 281 |
*/ |
268 |
public static FLayer createLayer(WFSDriver driver, URL host,
|
|
282 |
public static FLayer createWFSLayer(String layerName,WFSDriver driver, URL host,
|
|
269 | 283 |
IProjection proj) { |
270 |
throw new UnsupportedOperationException(); |
|
284 |
//throw new UnsupportedOperationException(); |
|
285 |
FLyrVect layer=new FLyrVect(); |
|
286 |
//layer.setName(name); |
|
287 |
VectorialAdapter adapter=new WFSAdapter(); |
|
288 |
adapter.setDriver(driver); |
|
289 |
//WithDefaultLegend aux=(WithDefaultLegend)driver; |
|
290 |
|
|
291 |
layer.setName(layerName); |
|
292 |
layer.setSource(adapter); |
|
293 |
layer.setProjection(proj); |
|
294 |
try { |
|
295 |
layer.setLegend(LegendFactory.createSingleSymbolLegend( |
|
296 |
layer.getShapeType())); |
|
297 |
} catch (FieldNotFoundException e) { |
|
298 |
e.printStackTrace(); |
|
299 |
} catch (DriverException e) { |
|
300 |
e.printStackTrace(); |
|
301 |
} |
|
302 |
//layer.setHost(host); |
|
303 |
return layer; |
|
271 | 304 |
} |
305 |
public static FLayer createArcSDELayer(String layerName,ArcSdeDriver driver, IProjection proj) { |
|
306 |
//throw new UnsupportedOperationException(); |
|
307 |
FLyrVect layer=new FLyrVect(); |
|
308 |
VectorialAdapter adapter=new VectorialDBAdapter(); |
|
309 |
adapter.setDriver(driver); |
|
310 |
|
|
311 |
layer.setName(layerName); |
|
312 |
layer.setSource(adapter); |
|
313 |
layer.setProjection(proj); |
|
314 |
try { |
|
315 |
if (driver instanceof WithDefaultLegend) { |
|
316 |
WithDefaultLegend aux = (WithDefaultLegend) driver; |
|
317 |
adapter.start(); |
|
318 |
layer.setLegend((VectorialLegend) aux.getDefaultLegend()); |
|
319 |
adapter.stop(); |
|
320 |
} else { |
|
321 |
layer.setLegend(LegendFactory.createSingleSymbolLegend( |
|
322 |
layer.getShapeType())); |
|
323 |
} |
|
324 |
} catch (FieldNotFoundException e) { |
|
325 |
throw new UnsupportedOperationException(e.getMessage()); |
|
326 |
} catch (DriverIOException e) { |
|
327 |
throw new UnsupportedOperationException(e.getMessage()); |
|
328 |
} catch (DriverException e) { |
|
329 |
// TODO Auto-generated catch block |
|
330 |
e.printStackTrace(); |
|
331 |
} |
|
332 |
|
|
333 |
try { |
|
334 |
layer.setLegend(LegendFactory.createSingleSymbolLegend( |
|
335 |
layer.getShapeType())); |
|
336 |
} catch (FieldNotFoundException e) { |
|
337 |
e.printStackTrace(); |
|
338 |
} catch (DriverException e) { |
|
339 |
e.printStackTrace(); |
|
340 |
} |
|
341 |
return layer; |
|
342 |
} |
|
272 | 343 |
|
273 | 344 |
/** |
274 | 345 |
* Crea un RandomVectorialWFS con el driver que se le pasa como par?metro y |
... | ... | |
326 | 397 |
|
327 | 398 |
} |
328 | 399 |
|
400 |
/** |
|
401 |
* @param driver |
|
402 |
* @param layerName |
|
403 |
* @param object |
|
404 |
* @return |
|
405 |
* @throws SQLException |
|
406 |
* @throws DriverIOException |
|
407 |
* @throws IOException |
|
408 |
* @throws DriverLoadException |
|
409 |
* @throws com.hardcode.gdbms.engine.data.driver.DriverException |
|
410 |
* @throws NoSuchTableException |
|
411 |
* @throws ClassNotFoundException |
|
412 |
* @throws |
|
413 |
*/ |
|
414 |
public static FLayer createDisconnectedDBLayer(VectorialJDBCDriver driver, String layerName, IProjection proj, ProgressListener listener) throws SQLException, IOException, DriverIOException, DriverLoadException, NoSuchTableException, com.hardcode.gdbms.engine.data.driver.DriverException, ClassNotFoundException { |
|
415 |
VectorialDisconnectedDBAdapter dbAdapter = new VectorialDisconnectedDBAdapter(); |
|
416 |
dbAdapter.setDriver(driver); |
|
417 |
DataSource ds = dbAdapter.getRecordset(); |
|
418 |
ds.start(); |
|
419 |
String database = dataSourceFactory.getTempFile(); |
|
420 |
String[] fieldNames = new String[ds.getFieldCount() + 1]; |
|
421 |
System.arraycopy(ds.getFieldNames(), 0, fieldNames, 1, ds.getFieldCount()); |
|
422 |
fieldNames[0] = "the_geom"; |
|
423 |
int[] types = new int[fieldNames.length]; |
|
424 |
types[0] = Types.BINARY; |
|
425 |
for (int i = 1; i < types.length; i++) { |
|
426 |
types[i] = ds.getFieldType(i-1); |
|
427 |
} |
|
428 |
String dsName = dataSourceFactory.createTable(database, ds.getPKNames(), fieldNames, types); |
|
429 |
|
|
430 |
dataSourceFactory.addDBDataSourceByTable(dsName, null, 0, "sa", "", database, dsName, "GDBMS HSQLDB Transactional driver", null); |
|
431 |
DataSource local = dataSourceFactory.createRandomDataSource(dsName, DataSourceFactory.CLOSING_MANUAL_MODE); |
|
432 |
local.start(); |
|
433 |
DataWare dw = local.getDataSourceFactory().createDataWare(local, DataSourceFactory.DATA_WARE_COHERENT_ROW_ORDER); |
|
434 |
dw.start(); |
|
435 |
long t1 = System.currentTimeMillis(); |
|
436 |
dw.beginTrans(); |
|
437 |
|
|
438 |
if (listener == null){ |
|
439 |
listener = new ProgressListener() { |
|
440 |
/** |
|
441 |
* @see com.iver.cit.gvsig.fmap.ProgressListener#progress(int) |
|
442 |
*/ |
|
443 |
public void progress(int n) { |
|
444 |
//do nothing |
|
445 |
} |
|
446 |
}; |
|
447 |
} |
|
448 |
|
|
449 |
for (int i = 0; i < dbAdapter.getShapeCount(); i++) { |
|
450 |
Value[] row = new Value[ds.getFieldCount() + 1]; |
|
451 |
|
|
452 |
byte[] bytes = dbAdapter.getShape(i).toWKB(); |
|
453 |
row[0] = ValueFactory.createValue(bytes); |
|
454 |
|
|
455 |
for (int j = 0; j < ds.getFieldCount(); j++) { |
|
456 |
row[j+1] = ds.getFieldValue(i, j); |
|
457 |
} |
|
458 |
|
|
459 |
dw.insertFilledRow(row); |
|
460 |
listener.progress(100 * i / dbAdapter.getShapeCount()); |
|
461 |
} |
|
462 |
|
|
463 |
long t2 = System.currentTimeMillis(); |
|
464 |
dw.commitTrans(); |
|
465 |
long t3 = System.currentTimeMillis(); |
|
466 |
System.out.println((t2 - t1) + " - " + (t3 - t2)); |
|
467 |
dw.stop(); |
|
468 |
local.stop(); |
|
469 |
ds.stop(); |
|
470 |
VectorialJDBCDriver cacheDriver = (VectorialJDBCDriver) LayerFactory.getDM().getDriver("HSQLDB Driver"); |
|
471 |
Class.forName("org.hsqldb.jdbcDriver"); |
|
472 |
|
|
473 |
cacheDriver.setData(java.sql.DriverManager.getConnection("jdbc:hsqldb:file:" + database, "sa", ""), dsName, StringUtilities.getComaSeparated(local.getFieldNames()), "", local.getPrimaryKeys()[0]+1); |
|
474 |
cacheDriver.setWorkingArea(driver.getWorkingArea()); |
|
475 |
return createDBLayer(cacheDriver, layerName, proj); |
|
476 |
} |
|
329 | 477 |
|
478 |
|
|
330 | 479 |
/** |
331 | 480 |
* Obtiene el adaptador de un driver si ya se ha a?adido el origen de datos |
332 | 481 |
* o null si es un origen de datos nuevo |
... | ... | |
384 | 533 |
Throwable[] failures = driverManager.getLoadFailures(); |
385 | 534 |
|
386 | 535 |
for (int i = 0; i < failures.length; i++) { |
387 |
logger.error(failures[i]); |
|
536 |
logger.error("", failures[i]);
|
|
388 | 537 |
} |
389 | 538 |
|
390 | 539 |
getDataSourceFactory().setDriverManager(driverManager); |
540 |
getDataSourceFactory().initialize(); |
|
391 | 541 |
QueryManager.registerQuery(new ArcJoin()); |
392 | 542 |
} |
393 | 543 |
} |
... | ... | |
402 | 552 |
initializeDriverManager(); |
403 | 553 |
} |
404 | 554 |
|
555 |
|
|
405 | 556 |
/** |
406 | 557 |
* @return Returns the dataSourceFactory. |
407 | 558 |
*/ |
Also available in: Unified diff