Revision: 4863 http://sourceforge.net/p/jump-pilot/code/4863 Author: michaudm Date: 2016-03-25 19:03:29 +0000 (Fri, 25 Mar 2016) Log Message: ----------- Making writable datastore more generic
Modified Paths: -------------- core/trunk/src/com/vividsolutions/jump/datastore/h2/H2DSMetadata.java core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreDataSourceFactory.java core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java Modified: core/trunk/src/com/vividsolutions/jump/datastore/h2/H2DSMetadata.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/datastore/h2/H2DSMetadata.java 2016-03-25 10:47:15 UTC (rev 4862) +++ core/trunk/src/com/vividsolutions/jump/datastore/h2/H2DSMetadata.java 2016-03-25 19:03:29 UTC (rev 4863) @@ -55,4 +55,20 @@ String sql = this.getGeoColumnsQuery(datasetName); return getGeometryAttributes(sql, datasetName); } + + @Override + public String getAddGeometryColumnStatement(String schemaName, String tableName, + String geometryColumn, int srid, String geometryType, int dim) { + String schematable = SQLUtil.compose(schemaName, tableName); + return "ALTER TABLE " + schematable + " ADD COLUMN \"" + geometryColumn + "\" GEOMETRY;"; + } + + @Override + public String getAddSpatialIndexStatement(String schemaName, String tableName, String geometryColumn) { + // Geometry index creation is different on different spatial databases + // Do not add if it is not defined + String schematable = SQLUtil.compose(schemaName, tableName); + String indexname = tableName + "_" + geometryColumn + "_idx"; + return "CREATE SPATIAL INDEX " + indexname + " ON " + schematable + "(" + geometryColumn + ");"; + } } Modified: core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java 2016-03-25 10:47:15 UTC (rev 4862) +++ core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java 2016-03-25 19:03:29 UTC (rev 4863) @@ -117,7 +117,7 @@ WritableDataStoreDataSource ds = DataStoreDataSourceFactory.createWritableDataStoreDataSource( connectionDescriptor, datasetName, geometryAttributeName, - identifierAttributeName, true); + identifierAttributeName, true, workbenchContext); ds.setMaxFeature(limit); ds.setWhereClause(whereClause); ds.setLimitedToView(limitedToView); Modified: core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreDataSourceFactory.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreDataSourceFactory.java 2016-03-25 10:47:15 UTC (rev 4862) +++ core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreDataSourceFactory.java 2016-03-25 19:03:29 UTC (rev 4863) @@ -1,6 +1,7 @@ package org.openjump.core.ui.plugin.datastore; import com.vividsolutions.jump.I18N; +import com.vividsolutions.jump.workbench.WorkbenchContext; import com.vividsolutions.jump.workbench.datastore.ConnectionDescriptor; import org.openjump.core.ui.plugin.datastore.postgis2.PostGISDataStoreDataSource; @@ -17,12 +18,13 @@ String datasetName, String geometryAttributeName, String externalPKName, - boolean tableAlreadyCreated) throws Exception { + boolean tableAlreadyCreated, + WorkbenchContext context) throws Exception { WritableDataStoreDataSource source; String driverName = connectionDescriptor.getDataStoreDriverClassName(); if (driverName.equals(com.vividsolutions.jump.datastore.postgis.PostgisDataStoreDriver.class.getName())) { source = new PostGISDataStoreDataSource( - connectionDescriptor, datasetName, geometryAttributeName, externalPKName); + connectionDescriptor, datasetName, geometryAttributeName, externalPKName, context); source.setTableAlreadyCreated(tableAlreadyCreated); } else { throw new Exception(I18N.getMessage(KEY + ".no-writable-datastore-datasource", driverName)); Modified: core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java 2016-03-25 10:47:15 UTC (rev 4862) +++ core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java 2016-03-25 19:03:29 UTC (rev 4863) @@ -7,9 +7,12 @@ import javax.swing.JOptionPane; import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jump.datastore.DataStoreConnection; +import com.vividsolutions.jump.datastore.DataStoreDriver; import com.vividsolutions.jump.datastore.SQLUtil; import com.vividsolutions.jump.datastore.spatialdatabases.SpatialDatabasesDSConnection; -import com.vividsolutions.jump.datastore.spatialdatabases.SpatialDatabasesSQLBuilder; +import com.vividsolutions.jump.workbench.WorkbenchContext; +import com.vividsolutions.jump.workbench.datastore.ConnectionManager; import org.openjump.core.ui.plugin.datastore.transaction.DataStoreTransactionManager; import org.openjump.core.ui.plugin.datastore.transaction.Evolution; import org.openjump.core.ui.plugin.datastore.transaction.EvolutionOperationException; @@ -64,7 +67,7 @@ // Ordered Map of evolutions // Map is indexed by FID in order to merge successive evolutions of a feature efficiently - final private LinkedHashMap<Integer,Evolution> evolutions = new LinkedHashMap<Integer,Evolution>(); + final private LinkedHashMap<Integer,Evolution> evolutions = new LinkedHashMap<>(); // See setTableAlreadyCreated() private boolean tableAlreadyCreated = true; @@ -90,7 +93,8 @@ public WritableDataStoreDataSource(ConnectionDescriptor connectionDescriptor, String datasetName, String geometryAttributeName, - String externalPKName) { + String externalPKName, + WorkbenchContext context) { setProperties(CollectionUtil.createMap(new Object[]{ CONNECTION_DESCRIPTOR_KEY, connectionDescriptor, DATASET_NAME_KEY, datasetName, @@ -107,6 +111,7 @@ //getProperties().put(CREATE_TABLE, false); getProperties().put(CREATE_PK, false); getProperties().put(SRID_KEY, 0); + this.context = context; } public void setLimitedToView(boolean limitedToView) { @@ -190,15 +195,16 @@ getGeometryDimension(featureCollection, 3) : (Integer)getProperties().get(GEOM_DIM_KEY); + DataStoreDriver driver = ConnectionManager.instance(context) + .getDriver(connectionDescriptor.getDataStoreDriverClassName()); SpatialDatabasesDSConnection conn = - (PostgisDSConnection)new PostgisDataStoreDriver() - .createConnection(connectionDescriptor.getParameterList()); + (SpatialDatabasesDSConnection)connectionDescriptor.createConnection(driver); java.sql.Connection jdbcConn = conn.getJdbcConnection(); try { jdbcConn.setAutoCommit(false); if (!tableAlreadyCreated) { Logger.debug("Update mode: create table"); - boolean exists = tableExists(conn); + boolean exists = tableExists(jdbcConn); if (exists && !confirmOverwrite()) return; if (exists) { deleteTableQuery(conn); @@ -489,8 +495,8 @@ /** * Check if this [schema.]table exists in this database. */ - private boolean tableExists(SpatialDatabasesDSConnection conn) throws SQLException { - DatabaseMetaData metadata = conn.getJdbcConnection().getMetaData(); + private boolean tableExists(java.sql.Connection conn) throws SQLException { + DatabaseMetaData metadata = conn.getMetaData(); return metadata.getTables(null, schemaName, tableName, new String[]{"TABLE"}).next(); } Modified: core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java 2016-03-25 10:47:15 UTC (rev 4862) +++ core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java 2016-03-25 19:03:29 UTC (rev 4863) @@ -7,6 +7,7 @@ import com.vividsolutions.jump.datastore.SQLUtil; import com.vividsolutions.jump.datastore.spatialdatabases.SpatialDatabasesDSConnection; +import com.vividsolutions.jump.workbench.WorkbenchContext; import org.openjump.core.ui.plugin.datastore.WritableDataStoreDataSource; import com.vividsolutions.jts.geom.Coordinate; @@ -36,8 +37,9 @@ ConnectionDescriptor connectionDescriptor, String datasetName, String geometryAttributeName, - String identifierAttributeName) { - super(connectionDescriptor, datasetName, geometryAttributeName, identifierAttributeName); + String identifierAttributeName, + WorkbenchContext context) { + super(connectionDescriptor, datasetName, geometryAttributeName, identifierAttributeName, context); } /** ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140 _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel