Revision: 5153
http://sourceforge.net/p/jump-pilot/code/5153
Author: michaudm
Date: 2016-11-05 11:00:24 +0000 (Sat, 05 Nov 2016)
Log Message:
-----------
Writable PostGIS driver apply a ST_Multi transformation to geometries
if it detected that the distant table has a MultiGeometry constraint
(+ some cleaning in new postgis driver classes)
Modified Paths:
--------------
core/trunk/ChangeLog
core/trunk/src/com/vividsolutions/jump/workbench/ui/LayerNamePanel.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddDataStoreLayerWizard.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddDataStoreLayerWizardPanel.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerPanel.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizardPanel.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreSaveDriverPanel.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStorePanel.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStoreWizard.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/h2/H2DataStoreDataSource.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISSaveDataSourceQueryChooser.java
Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog 2016-11-05 06:40:20 UTC (rev 5152)
+++ core/trunk/ChangeLog 2016-11-05 11:00:24 UTC (rev 5153)
@@ -3,6 +3,10 @@
# 2. make sure that lines break at 80 chars for constricted display situations
#<-------------------------------- 80 chars
---------------------------------->#
+2016-1-05 mmichaud <[email protected]>
+ * Writable PostGIS driver apply a ST_Multi transformation to geometries
+ if it detected that the distant table has a MultiGeometry constraint
+
2016-11-04 mmichaud <[email protected]>
* Add two plugins to generate random values in an attribute
Modified:
core/trunk/src/com/vividsolutions/jump/workbench/ui/LayerNamePanel.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/LayerNamePanel.java
2016-11-05 06:40:20 UTC (rev 5152)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/LayerNamePanel.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -34,26 +34,34 @@
import java.util.Collection;
+import com.vividsolutions.jump.workbench.model.Category;
import com.vividsolutions.jump.workbench.model.Layer;
import com.vividsolutions.jump.workbench.model.LayerManagerProxy;
public interface LayerNamePanel extends LayerManagerProxy {
- public Collection getSelectedCategories();
- public Collection selectedNodes(Class c);
+
+ Collection<Category> getSelectedCategories();
+
+ Collection selectedNodes(Class c);
+
/**
* @deprecated implement LayerableNamePanel.getSelectedLayerables() instead
*/
@Deprecated
- public Layer[] getSelectedLayers();
- /**
+ Layer[] getSelectedLayers();
+
+ /**
* @return e.g. the first selected editable layer, otherwise the first
editable layer, otherwise null
*/
- public Layer chooseEditableLayer();
- public void addListener(LayerNamePanelListener listener);
- public void removeListener(LayerNamePanelListener listener);
+ Layer chooseEditableLayer();
+
+ void addListener(LayerNamePanelListener listener);
+
+ void removeListener(LayerNamePanelListener listener);
+
/**
* The parent window is closing.
*/
- public void dispose();
+ void dispose();
}
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddDataStoreLayerWizard.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddDataStoreLayerWizard.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddDataStoreLayerWizard.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -5,6 +5,7 @@
import javax.swing.SwingUtilities;
+import com.vividsolutions.jump.workbench.Logger;
import org.openjump.core.ccordsys.srid.SRIDStyle;
import org.openjump.core.ui.plugin.file.open.ChooseProjectPanel;
import org.openjump.core.ui.swing.wizard.AbstractWizardGroup;
@@ -73,8 +74,8 @@
SwingUtilities.invokeLater(new Runnable() {
public void run() {
for (final Layer layer : layers) {
- Collection<Category> selectedCategories =
workbenchContext.getLayerNamePanel()
- .getSelectedCategories();
+ Collection<Category> selectedCategories = workbenchContext
+ .getLayerableNamePanel().getSelectedCategories();
LayerManager layerManager = workbenchContext.getLayerManager();
String categoryName = StandardCategoryNames.WORKING;
if (!selectedCategories.isEmpty()) {
@@ -83,12 +84,14 @@
try {
workbenchContext.getLayerViewPanel().getViewport().update();
} catch (Exception e) {
+ Logger.warn("Exception thrown by AddDataStoreLayerWizard
during LayerViewPanel update", e);
//throw NoninvertibleTransformationException;
}
try {
layerManager.addLayerable(categoryName, layer);
} catch (Exception e) {
e.printStackTrace();
+ Logger.warn("Exception thrown by AddDataStoreLayerWizard while
adding the layer to the LayerManager", e);
}
}
}
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddDataStoreLayerWizardPanel.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddDataStoreLayerWizardPanel.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddDataStoreLayerWizardPanel.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -46,7 +46,7 @@
/**
* @return the dataStorePanel
*/
- public AddDatastoreLayerPanel getDataStorePanel() {
+ AddDatastoreLayerPanel getDataStorePanel() {
return dataStorePanel;
}
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerPanel.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerPanel.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerPanel.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -5,6 +5,7 @@
import com.vividsolutions.jump.datastore.PrimaryKeyColumn;
import com.vividsolutions.jump.task.TaskMonitor;
import com.vividsolutions.jump.util.LangUtil;
+import com.vividsolutions.jump.workbench.Logger;
import com.vividsolutions.jump.workbench.WorkbenchContext;
import com.vividsolutions.jump.workbench.datastore.ConnectionDescriptor;
import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
@@ -32,11 +33,12 @@
private static final String KEY =
AddWritableDataStoreLayerPanel.class.getName();
- private Map connectionDescriptorToDatasetNamesMap = new HashMap();
+ private Map<ConnectionDescriptor,String[]>
connectionDescriptorToDatasetNamesMap
+ = new HashMap<>();
- private JComboBox datasetComboBox = null;
- private JComboBox geometryAttributeComboBox = null;
- private JComboBox identifierAttributeComboBox = null;
+ private JComboBox<Object> datasetComboBox = null;
+ private JComboBox<GeometryColumn> geometryAttributeComboBox = null;
+ private JComboBox<PrimaryKeyColumn> identifierAttributeComboBox = null;
private JTextField maxFeaturesTextField = null;
private JTextArea whereTextArea = null;
//private JCheckBox cachingCheckBox = null;
@@ -53,9 +55,11 @@
});
}
- public static Object runInKillableThread( final String description,
- WorkbenchContext context, final
Block block ) {
- final Object[] result = new Object[]{null};
+ private static <T> T runInKillableThread( final String description,
+ WorkbenchContext context,
+ final Block<T> block ) {
+
+ final List<T> result = new ArrayList<>();
// ThreadedBasePlugIn displays a dialog that the user can
// use to kill the thread by pressing the close button
// [Jon Aquino 2005-03-14]
@@ -72,10 +76,10 @@
public void run(TaskMonitor monitor, PlugInContext context)
throws Exception {
monitor.report(description);
- result[0] = block.yield();
+ result.add(block.yield());
}
}, context, new TaskMonitorManager()).actionPerformed( null );
- return result[0];
+ return result.size()>0?result.get(0):null;
}
public String getDatasetName() {
@@ -83,12 +87,12 @@
((String)datasetComboBox.getSelectedItem()).trim() : null;
}
- public GeometryColumn getGeometryColumn() {
+ GeometryColumn getGeometryColumn() {
return geometryAttributeComboBox.getSelectedItem() != null ?
((GeometryColumn)geometryAttributeComboBox.getSelectedItem())
: null;
}
- public PrimaryKeyColumn getIdentifierColumn() throws Exception {
+ private PrimaryKeyColumn getIdentifierColumn() throws Exception {
Object selectedItem = identifierAttributeComboBox.getSelectedItem();
if (selectedItem != null) {
if (selectedItem instanceof PrimaryKeyColumn) {
@@ -101,12 +105,12 @@
}
}
- public String getGeometryAttributeName() {
+ String getGeometryAttributeName() {
return geometryAttributeComboBox.getSelectedItem() != null ?
getGeometryColumn().getName().trim() : null;
}
- public String getIdentifierAttributeName() throws Exception {
+ String getIdentifierAttributeName() throws Exception {
return identifierAttributeComboBox.getSelectedItem() != null ?
getIdentifierColumn().getName().trim() : null;
}
@@ -114,19 +118,19 @@
/**
* @return Integer.MAX_VALUE if the user has left the Max Features text
field blank.
*/
- public Integer getMaxFeatures() {
+ Integer getMaxFeatures() {
if (maxFeaturesTextField.getText() == null) return Integer.MAX_VALUE;
if (maxFeaturesTextField.getText().trim().length() == 0) return
Integer.MAX_VALUE;
if (maxFeaturesTextField.getText().trim().equals("-")) return
Integer.MAX_VALUE;
return new Integer(maxFeaturesTextField.getText().trim());
}
- public String getWhereClause() {
+ String getWhereClause() {
return getWhereClauseProper().toLowerCase().startsWith("where") ?
getWhereClauseProper().substring("where".length()).trim() :
getWhereClauseProper();
}
- public String getWhereClauseProper() {
+ String getWhereClauseProper() {
return whereTextArea.getText().trim();
}
@@ -138,19 +142,19 @@
// getCachingCheckBox().setSelected( caching );
//}
- public boolean isLimitedToView() {
+ boolean isLimitedToView() {
return getLimitedToViewCheckBox().isSelected();
}
- public void setLimitedToView( boolean limitedToView ) {
+ void setLimitedToView( boolean limitedToView ) {
getLimitedToViewCheckBox().setSelected( limitedToView );
}
- public boolean isManageConfictsActive() {
+ boolean isManageConfictsActive() {
return getManageConflictsCheckBox().isSelected();
}
- public void setManageConfictsActive( boolean manageConflicts ) {
+ void setManageConfictsActive( boolean manageConflicts ) {
getManageConflictsCheckBox().setSelected( manageConflicts );
}
@@ -183,7 +187,7 @@
private JComboBox getDatasetComboBox() {
if ( datasetComboBox == null ) {
- datasetComboBox = new JComboBox();
+ datasetComboBox = new JComboBox<>();
datasetComboBox.setPreferredSize( new Dimension( MAIN_COLUMN_WIDTH,
( int ) datasetComboBox.getPreferredSize().getHeight() ) );
datasetComboBox.setEditable( true );
@@ -219,7 +223,7 @@
private JComboBox getGeometryAttributeComboBox() {
if ( geometryAttributeComboBox == null ) {
- geometryAttributeComboBox = new JComboBox();
+ geometryAttributeComboBox = new JComboBox<>();
geometryAttributeComboBox.setPreferredSize( new Dimension(
MAIN_COLUMN_WIDTH, ( int )
geometryAttributeComboBox.getPreferredSize().getHeight() ) );
geometryAttributeComboBox.setEditable( true );
@@ -236,7 +240,7 @@
private JComboBox getIdentifierAttributeComboBox() {
if ( identifierAttributeComboBox == null ) {
- identifierAttributeComboBox = new JComboBox();
+ identifierAttributeComboBox = new JComboBox<>();
identifierAttributeComboBox.setPreferredSize( new Dimension(
MAIN_COLUMN_WIDTH, ( int )
identifierAttributeComboBox.getPreferredSize().getHeight() ) );
identifierAttributeComboBox.setEditable( true );
@@ -313,13 +317,13 @@
}
try {
GeometryColumn selectedGeometryColumn = getGeometryColumn();
- geometryAttributeComboBox.setModel( new DefaultComboBoxModel(
+ geometryAttributeComboBox.setModel( new DefaultComboBoxModel<>(
sortGeometryColumns( getGeometryAttributes(
getDatasetName(),
getConnectionDescriptor() ) ) ) );
geometryAttributeComboBox.setSelectedItem( selectedGeometryColumn
);
} catch ( Exception e ) {
getContext().getErrorHandler().handleThrowable( e );
- geometryAttributeComboBox.setModel( new DefaultComboBoxModel() );
+ geometryAttributeComboBox.setModel( new
DefaultComboBoxModel<GeometryColumn>() );
}
}
@@ -335,20 +339,20 @@
}
try {
PrimaryKeyColumn selectedIdentifierColumn = getIdentifierColumn();
- Object[] pks =
sortIdentifierColumns(getIdentifierAttributes(getDatasetName(),
+ PrimaryKeyColumn[] pks =
sortIdentifierColumns(getIdentifierAttributes(getDatasetName(),
getConnectionDescriptor()));
- identifierAttributeComboBox.setModel( new
DefaultComboBoxModel(pks));
+ identifierAttributeComboBox.setModel( new
DefaultComboBoxModel<>(pks));
if (pks.length > 0) {
// preserve the last used pk if pk list has not changed
identifierAttributeComboBox.setSelectedItem(
selectedIdentifierColumn );
}
} catch ( Exception e ) {
getContext().getErrorHandler().handleThrowable( e );
- identifierAttributeComboBox.setModel( new DefaultComboBoxModel() );
+ identifierAttributeComboBox.setModel( new
DefaultComboBoxModel<PrimaryKeyColumn>() );
}
}
- public Object[] sortGeometryColumns(java.util.List<GeometryColumn> list) {
+ private GeometryColumn[]
sortGeometryColumns(java.util.List<GeometryColumn> list) {
Collections.sort(list, new Comparator<GeometryColumn>() {
public int compare(GeometryColumn o1, GeometryColumn o2) {
return o1.getName().compareTo(o2.getName());
@@ -360,7 +364,7 @@
return list.toArray(new GeometryColumn[list.size()]);
}
- public Object[] sortIdentifierColumns(List<PrimaryKeyColumn> list) {
+ private PrimaryKeyColumn[] sortIdentifierColumns(List<PrimaryKeyColumn>
list) {
Collections.sort(list, new Comparator<PrimaryKeyColumn>() {
public int compare(PrimaryKeyColumn o1, PrimaryKeyColumn o2) {
return o1.getName().compareTo(o2.getName());
@@ -381,13 +385,13 @@
String[] datasetNames = datasetNames( getConnectionDescriptor() );
// avoid a NPE, if there are no spatial enabled tables in this
database
if (datasetNames != null) {
- datasetComboBox.setModel( new DefaultComboBoxModel(
+ datasetComboBox.setModel( new DefaultComboBoxModel<>(
sortByString( datasetNames) ) );
datasetComboBox.setSelectedItem( selectedDatasetName );
}
} catch ( Exception e ) {
getContext().getErrorHandler().handleThrowable( e );
- datasetComboBox.setModel( new DefaultComboBoxModel() );
+ datasetComboBox.setModel( new DefaultComboBoxModel<>() );
}
}
@@ -400,10 +404,10 @@
// Retrieve the dataset names using a ThreadedBasePlugIn, so
// that the user can kill the thread if desired
// [Jon Aquino 2005-03-16]
- return (List<GeometryColumn>) runInKillableThread(
+ return runInKillableThread(
I18N.get(KEY + ".retrieving-list-of-geometry-attributes"),
getContext(),
- new Block() {
- public Object yield() throws Exception {
+ new Block<List<GeometryColumn>>() {
+ public List<GeometryColumn> yield() throws Exception {
try {
return new PasswordPrompter().getOpenConnection(
connectionManager(), connectionDescriptor,
@@ -412,8 +416,8 @@
} catch ( Exception e ) {
// Can get here if dataset name is not found in the
// datastore [Jon Aquino 2005-03-16]
- e.printStackTrace( System.err );
- return new String[]{};
+ Logger.warn("Exception thrown while retrieving
GeometryColumns from the database", e);
+ return new ArrayList<>();
}
}
} );
@@ -428,10 +432,10 @@
// Retrieve the dataset names using a ThreadedBasePlugIn, so
// that the user can kill the thread if desired
// [Jon Aquino 2005-03-16]
- return (List<PrimaryKeyColumn>) runInKillableThread(
+ return runInKillableThread(
I18N.get(KEY + ".retrieving-list-of-geometry-attributes"),
getContext(),
- new Block() {
- public Object yield() throws Exception {
+ new Block<List<PrimaryKeyColumn>>() {
+ public List<PrimaryKeyColumn> yield() throws Exception {
try {
return new PasswordPrompter().getOpenConnection(
connectionManager(), connectionDescriptor,
@@ -440,8 +444,8 @@
} catch ( Exception e ) {
// Can get here if dataset name is not found in the
// datastore [Jon Aquino 2005-03-16]
- e.printStackTrace( System.err );
- return new String[]{};
+ Logger.warn("Exception thrown while retrieving
PrimaryKeyColumn from the database", e);
+ return new ArrayList<>();
}
}
} );
@@ -459,10 +463,10 @@
// Retrieve the dataset names using a ThreadedBasePlugIn, so
// that the user can kill the thread if desired
// [Jon Aquino 2005-03-11]
- String[] datasetNames = ( String[] ) runInKillableThread(
+ String[] datasetNames = runInKillableThread(
I18N.get(KEY + ".retrieving-list-of-tables"), getContext(),
- new Block() {
- public Object yield() throws Exception {
+ new Block<String[]>() {
+ public String[] yield() throws Exception {
return new PasswordPrompter().getOpenConnection(
connectionManager(), connectionDescriptor,
AddWritableDataStoreLayerPanel.this
).getMetadata()
@@ -471,12 +475,12 @@
} );
// Don't cache the dataset array if it is empty, as a problem
// likely occurred. [Jon Aquino 2005-03-14]
- if ( datasetNames.length != 0 ) {
+ if ( datasetNames != null && datasetNames.length != 0 ) {
connectionDescriptorToDatasetNamesMap.put( connectionDescriptor,
datasetNames );
}
- //}
- return ( String[] ) connectionDescriptorToDatasetNamesMap.get(
connectionDescriptor );
+
+ return connectionDescriptorToDatasetNamesMap.get( connectionDescriptor
);
}
private void initialize() {
@@ -536,7 +540,7 @@
} );
}
- public static interface Block {
- public Object yield() throws Exception;
+ public interface Block<T> {
+ T yield() throws Exception;
}
}
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizard.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -71,8 +71,8 @@
final Layer layer = createLayer(dataStorePanel, monitor);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
- Collection<Category> selectedCategories =
workbenchContext.getLayerNamePanel()
- .getSelectedCategories();
+ Collection<Category> selectedCategories =
workbenchContext
+
.getLayerableNamePanel().getSelectedCategories();
LayerManager layerManager =
workbenchContext.getLayerManager();
String categoryName = StandardCategoryNames.WORKING;
if (!selectedCategories.isEmpty()) {
@@ -82,6 +82,7 @@
workbenchContext.getLayerViewPanel().getViewport().update();
} catch (Exception e) {
//throw NoninvertibleTransformationException;
+ Logger.warn("Exception thrown by
AddWritableDataStoreLayerWizard while displaying data in the view", e);
}
layerManager.addLayerable(categoryName, layer);
}
@@ -123,6 +124,7 @@
ds.setLimitedToView(limitedToView);
ds.setManageConflicts(manageConflicts);
ds.setWorkbenchContext(workbenchContext);
+
ds.setMultiGeometry(panel.getGeometryColumn().getType().toLowerCase().startsWith("multi"));
ds.setCoordDimension(panel.getGeometryColumn().getCoordDimension());
ds.setSRID(panel.getGeometryColumn().getSRID());
@@ -144,6 +146,7 @@
Logger.info("Add layer '" + layer.getName() + "' to '" +
layerManager.getTask().getName() + "' using WritableDataStoreDataSource with
:");
Logger.info(" geometry column = " + geometryAttributeName);
+ Logger.info(" is_multi = " +
panel.getGeometryColumn().getType().toLowerCase().startsWith("multi"));
Logger.info(" coord_dimension = " +
panel.getGeometryColumn().getCoordDimension());
Logger.info(" srid = " + sridStyle.getSRID());
Logger.info(" external PK column = " + identifierAttributeName);
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizardPanel.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizardPanel.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/AddWritableDataStoreLayerWizardPanel.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -56,7 +56,6 @@
public boolean isInputValid() {
return true;
- //return validateInput() == nulldataStorePanel.isValid();
}
public void remove(InputChangedListener listener) {
@@ -65,7 +64,7 @@
/**
* @return the dataStorePanel
*/
- public AddWritableDataStoreLayerPanel getDataStorePanel() {
+ AddWritableDataStoreLayerPanel getDataStorePanel() {
return dataStorePanel;
}
}
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreSaveDriverPanel.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreSaveDriverPanel.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/DataStoreSaveDriverPanel.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -33,27 +33,28 @@
public static final String KEY = DataStoreSaveDriverPanel.class.getName();
- static final String WRITE_3D_GEOM = I18N.get(KEY +
".write-3d-geometries");
- static final String CONVERT_NAN_Z = I18N.get(KEY +
".convert-nan-z");
- static final String CREATE_DB_PK = I18N.get(KEY +
".create-database-primary-key");
- static final String NORMALIZED_TABLE_NAME = I18N.get(KEY +
".normalized-table-name-key");
- static final String NORMALIZED_COLUMN_NAMES = I18N.get(KEY +
".normalized-column-names-key");
+ private static final String WRITE_3D_GEOM = I18N.get(KEY +
".write-3d-geometries");
+ private static final String CONVERT_NAN_Z = I18N.get(KEY +
".convert-nan-z");
+ private static final String CREATE_DB_PK = I18N.get(KEY +
".create-database-primary-key");
+ private static final String NORMALIZED_TABLE_NAME = I18N.get(KEY +
".normalized-table-name-key");
+ private static final String NORMALIZED_COLUMN_NAMES = I18N.get(KEY +
".normalized-column-names-key");
// UI elements
private ConnectionPanel connectionPanel;
- private JComboBox tableComboBox;
+ private JComboBox<String> tableComboBox;
private JCheckBox createPrimaryKeyCheckBox;
private JCheckBox write3dGeomCheckBox;
+ //private JCheckBox writeMultiGeomCheckBox;
private JTextField convertNaNZTextField;
private JCheckBox normalizedTableNameCheckBox;
private JCheckBox normalizedColumnNamesCheckBox;
- private OKCancelPanel okCancelPanel;
+ private OKCancelPanel okCancelPanel = new OKCancelPanel();
// context variables
private WorkbenchContext wbContext;
private String lastUsedLayerName = null;
- private Map<String,String> layer2TableMap = new HashMap<String,String>();
- private DefaultComboBoxModel tableList = new DefaultComboBoxModel();
+ private Map<String,String> layer2TableMap = new HashMap<>();
+ private DefaultComboBoxModel<String> tableList = new
DefaultComboBoxModel<>();
public DataStoreSaveDriverPanel(PlugInContext context) {
try {
@@ -103,7 +104,7 @@
gbLayout.setConstraints(tableLabel, gbConstraints);
add(tableLabel);
- tableComboBox = new JComboBox(tableList);
+ tableComboBox = new JComboBox<>(tableList);
tableComboBox.setPrototypeDisplayValue("abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyz");
gbConstraints.gridx = 1;
gbLayout.setConstraints(tableComboBox, gbConstraints);
@@ -118,6 +119,13 @@
add(createPrimaryKeyCheckBox);
// Geometry dimension key checkbox
+ //writeMultiGeomCheckBox = new JCheckBox(WRITE_MULTI_GEOM);
+ //writeMultiGeomCheckBox.setSelected(false);
+ //gbConstraints.gridy += 1;
+ //gbLayout.setConstraints(writeMultiGeomCheckBox, gbConstraints);
+ //add(writeMultiGeomCheckBox);
+
+ // Geometry dimension key checkbox
write3dGeomCheckBox = new JCheckBox(WRITE_3D_GEOM);
write3dGeomCheckBox.setSelected(false);
gbConstraints.gridy += 1;
@@ -161,10 +169,10 @@
public void itemStateChanged(ItemEvent e) {
if (((JCheckBox)e.getSource()).isSelected()) {
tableComboBox.setSelectedItem(SQLUtil.normalize(
-
wbContext.getLayerNamePanel().getSelectedLayers()[0].getName()));
+
wbContext.getLayerableNamePanel().getSelectedLayers()[0].getName()));
} else {
tableComboBox.setSelectedItem(
-
wbContext.getLayerNamePanel().getSelectedLayers()[0].getName());
+
wbContext.getLayerableNamePanel().getSelectedLayers()[0].getName());
}
}
});
@@ -182,11 +190,11 @@
return I18N.get(this.getClass().getName() + ".title");
}
- class PanelAncestorListener implements AncestorListener {
+ private class PanelAncestorListener implements AncestorListener {
// called when the panel or an ancestor is made visible
// call layerChanged if the source layer has changed since last call
public void ancestorAdded(AncestorEvent e) {
- Layer[] layers = wbContext.getLayerNamePanel().getSelectedLayers();
+ Layer[] layers =
wbContext.getLayerableNamePanel().getSelectedLayers();
if (layers.length == 1) {
// call connectionChanged to refresh the list of tables
available
// in the database in case it has been changed by another
client
@@ -253,6 +261,10 @@
return createPrimaryKeyCheckBox.isSelected();
}
+ //public boolean writeCreateMultiGeometriesSelected() {
+ // return writeMultiGeomCheckBox.isSelected();
+ //}
+
public boolean writeCreate3dGeometriesSelected() {
return write3dGeomCheckBox.isSelected();
}
@@ -299,23 +311,10 @@
.getOpenConnection(connectionPanel.getConnectionDescriptor());
}
- // Warning : nothing says this is a PostGIS connection
- //private Connection getConnection() {
- // Connection connection = null;
- // try {
- // DataStoreConnection dsConnection = getDSConnection();
- // if (dsConnection == null || !(dsConnection instanceof
PostgisDSConnection)) return null;
- // connection = ((PostgisDSConnection)dsConnection).getConnection();
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- // return connection;
- //}
-
// Update table list to choose from, using database metadata
// Eventually add source layer name to the list if create option is
selected
private void updateTableList(DataStoreMetadata metadata) {
- Layer[] layers = wbContext.getLayerNamePanel().getSelectedLayers();
+ Layer[] layers = wbContext.getLayerableNamePanel().getSelectedLayers();
if (layers.length == 1) {
String layerName = layers[0].getName();
addItemToTableList(tableList, layerName);
@@ -334,9 +333,9 @@
/**
* Adds a new item to the model, without duplicate, and in alphabetical
order
*/
- private void addItemToTableList(DefaultComboBoxModel model, String item) {
+ private void addItemToTableList(DefaultComboBoxModel<String> model, String
item) {
for (int i = 0 ; i < model.getSize() ; i++) {
- String item_i = (String)model.getElementAt(i);
+ String item_i = model.getElementAt(i);
int compare = item.compareTo(item_i);
if (compare < 0) {
model.insertElementAt(item, i);
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStorePanel.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStorePanel.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStorePanel.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -96,6 +96,7 @@
setData(WritableDataStoreDataSource.CONNECTION_DESCRIPTOR_KEY,
getConnectionDescriptor());
setData(WritableDataStoreDataSource.DATASET_NAME_KEY,
getData(SaveWizardPlugIn.DATAKEY_SIMPLIFIED_LAYERNAME));
+ //setData(WritableDataStoreDataSource.MULTI_GEOMETRY_KEY,
writeCreateMultiGeometriesSelected());
setData(WritableDataStoreDataSource.GEOM_DIM_KEY,
writeCreate3dGeometriesSelected()?3:2);
setData(WritableDataStoreDataSource.NAN_Z_TO_VALUE_KEY, nanZToValue());
setData(WritableDataStoreDataSource.CREATE_PK,
isCreatePrimaryKeyColumnSelected());
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStoreWizard.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStoreWizard.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/SaveToDataStoreWizard.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -51,9 +51,9 @@
public void run(WizardDialog dialog, TaskMonitor monitor) throws Exception {
// plugin context is initialized too early, we have to use workbenchContext
// to get the current selected dataset
- Layer[] layers =
context.getWorkbenchContext().getLayerNamePanel().getSelectedLayers();
+ Layer[] layers =
context.getWorkbenchContext().getLayerableNamePanel().getSelectedLayers();
if (layers.length == 0) throw new Exception("No layer has been selected");
- Layer layer =
context.getWorkbenchContext().getLayerNamePanel().getSelectedLayers()[0];
+ Layer layer =
context.getWorkbenchContext().getLayerableNamePanel().getSelectedLayers()[0];
FeatureSchema schema =
layer.getFeatureCollectionWrapper().getFeatureSchema();
String geometryAttributeName =
schema.getAttributeName(schema.getGeometryIndex());
//dialog.setData(geomName);
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/WritableDataStoreDataSource.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -55,6 +55,7 @@
// Update options (write to database) : don't translate, these are map keys
public static final String EXTERNAL_PK_KEY = "External PK";
public static final String SRID_KEY = "SRID";
+ public static final String MULTI_GEOMETRY_KEY = "MultiGeometries";
public static final String GEOM_DIM_KEY = "Dimension";
public static final String NAN_Z_TO_VALUE_KEY = "NaN Z to value";
public static final String CREATE_PK = "Create PK";
@@ -119,6 +120,10 @@
getProperties().put(MANAGE_CONFLICTS, manageConflicts);
}
+ public void setMultiGeometry(boolean multi) {
+ getProperties().put(MULTI_GEOMETRY_KEY, multi);
+ }
+
public void setCoordDimension(int dbCoordDim) {
getProperties().put(GEOM_DIM_KEY, dbCoordDim);
}
@@ -192,6 +197,8 @@
String geometryColumn =
(String)getProperties().get(WritableDataStoreDataSource.GEOMETRY_ATTRIBUTE_NAME_KEY);
boolean createPrimaryKey =
(Boolean)getProperties().get(WritableDataStoreDataSource.CREATE_PK);
int srid = getProperties().get(SRID_KEY)==null ? 0 :
(Integer)getProperties().get(SRID_KEY);
+ boolean multi = getProperties().get(MULTI_GEOMETRY_KEY) ==
null ?
+ false :
(boolean)getProperties().get(MULTI_GEOMETRY_KEY);
int dim = getProperties().get(GEOM_DIM_KEY)==null?
getGeometryDimension(featureCollection, 3) :
(Integer)getProperties().get(GEOM_DIM_KEY);
@@ -215,7 +222,7 @@
// if createPrimaryKey=false, old gid will be
considered as a normal attribute
featureCollection.getFeatureSchema().removeExternalPrimaryKey();
createAndPopulateTable(conn,
- featureCollection, srid, "GEOMETRY", dim,
normalizedColumnNames);
+ featureCollection, srid, "GEOMETRY", multi,
dim, normalizedColumnNames);
if (createPrimaryKey) {
addDBPrimaryKey(conn, DEFAULT_PK_NAME);
// @TODO reload part is kept out of the
transaction because it uses
@@ -237,7 +244,7 @@
.length < featureSchema.getAttributeCount()) {
if (!confirmWriteDespiteDifferentSchemas()) return;
}
- commit(conn, srid, dim, normalizedColumnNames);
+ commit(conn, srid, multi, dim, normalizedColumnNames);
evolutions.clear();
}
jdbcConn.commit();
@@ -269,13 +276,13 @@
private void commit(SpatialDatabasesDSConnection conn,
- int srid, int dim, boolean normalizedColumnNames) throws
Exception {
+ int srid, boolean multi, int dim, boolean
normalizedColumnNames) throws Exception {
Logger.info("Evolutions to commit to " + schemaName + "." + tableName
+ " (PK=" + primaryKeyName +")");
for (Evolution evolution : evolutions.values()) {
if (evolution.getType() == Evolution.Type.CREATION) {
PreparedStatement pstmt = insertStatement(conn,
- evolution.getNewFeature().getSchema(),
normalizedColumnNames);
+ evolution.getNewFeature().getSchema(), multi,
normalizedColumnNames);
pstmt = setAttributeValues(pstmt, evolution.getNewFeature(),
srid, dim);
pstmt.execute();
Logger.info(" create new feature " +
evolution.getNewFeature().getID()+"/");
@@ -311,10 +318,10 @@
* @param fSchema feature schema
* @param normalizedColumnNames whether database column names should be
normalized (lowercase) or not
* @return a PreparedStatement
- * @throws SQLException
+ * @throws SQLException if an exception occurs during insert
*/
protected PreparedStatement insertStatement(SpatialDatabasesDSConnection
conn,
- FeatureSchema fSchema, boolean normalizedColumnNames) throws
SQLException {
+ FeatureSchema fSchema, boolean multi, boolean
normalizedColumnNames) throws SQLException {
StringBuilder sb = new StringBuilder("INSERT INTO " +
SQLUtil.compose(schemaName, tableName) + "(");
// create a column name list without datatypes, including geometry and
excluding primary key
@@ -326,7 +333,11 @@
for (int i = 0 ; i < fSchema.getAttributeCount() ; i++) {
if (fSchema.getExternalPrimaryKeyIndex() == i) continue;
if (fSchema.isAttributeReadOnly(i)) continue;
- sb.append(first?"?":",?");
+ if (multi && fSchema.getAttributeType(i) ==
AttributeType.GEOMETRY) {
+ sb.append(first ? "ST_Multi(?)" : ",ST_Multi(?)");
+ } else {
+ sb.append(first ? "?" : ",?");
+ }
first = false;
}
sb.append(");");
@@ -342,10 +353,12 @@
boolean quoted =
schema.getAttributeType(schema.getExternalPrimaryKeyIndex()) ==
AttributeType.STRING;
String quoteKey = quoted ? "'" : "";
- StringBuilder sb = new StringBuilder("UPDATE
").append(SQLUtil.compose(schemaName, tableName))
+ StringBuilder sb = new StringBuilder("UPDATE ")
+ .append(SQLUtil.compose(schemaName, tableName))
.append(" SET
\"").append(schema.getAttributeName(attribute)).append("\" = ?")
.append(" WHERE \"").append(primaryKeyName).append("\" = ")
.append(quoteKey).append(feature.getAttribute(primaryKeyName)).append(quoteKey).append(";");
+
PreparedStatement pstmt =
conn.getJdbcConnection().prepareStatement(sb.toString());
AttributeType type = schema.getAttributeType(attribute);
if (feature.getAttribute(attribute) == null) pstmt.setObject(1, null);
@@ -517,12 +530,12 @@
* @param geometryType geometry type
* @param dim geometry dimension
* @param normalizedColumnNames whether columns names have to be
normalized or not
- * @throws SQLException
+ * @throws SQLException if an exception occurs during table creation or
inserts
*/
abstract protected void createAndPopulateTable(
SpatialDatabasesDSConnection conn,
FeatureCollection fc,
- int srid, String geometryType, int dim,
+ int srid, String geometryType, boolean multi, int dim,
boolean normalizedColumnNames) throws SQLException;
@@ -535,7 +548,7 @@
// @TODO Bad design : it should be possible to do this kind of
post-processing
// in the loader (where layer name is known rather than in the datasource)
private void reloadDataFromDataStore(Connection conn, TaskMonitor monitor)
throws Exception {
- Layer[] selectedLayers =
JUMPWorkbench.getInstance().getContext().getLayerNamePanel().getSelectedLayers();
+ Layer[] selectedLayers =
JUMPWorkbench.getInstance().getContext().getLayerableNamePanel().getSelectedLayers();
if (selectedLayers != null && selectedLayers.length == 1) {
boolean oldFiringEvents =
JUMPWorkbench.getInstance().getContext().getLayerManager().isFiringEvents();
JUMPWorkbench.getInstance().getContext().getLayerManager().setFiringEvents(false);
@@ -557,7 +570,7 @@
* Return 3 if coll contains at least one 3d geometry, 2 if coll contains
* only 2d geometries and defaultDim if coll is empty.
*/
- public static int getGeometryDimension(FeatureCollection coll, int
defaultDim) {
+ private static int getGeometryDimension(FeatureCollection coll, int
defaultDim) {
if (coll.size() > 0) {
// will explore up to 1000 features regularly distributed in the
dataset
// if none of these feature has dim = 3, return 2, else return 3
@@ -574,7 +587,6 @@
} else return defaultDim;
}
-
private static int getGeometryDimension(Geometry g) {
Coordinate[] cc = g.getCoordinates();
for (Coordinate c : cc) {
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/h2/H2DataStoreDataSource.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/h2/H2DataStoreDataSource.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/h2/H2DataStoreDataSource.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -169,7 +169,7 @@
protected void createAndPopulateTable(
SpatialDatabasesDSConnection conn,
FeatureCollection fc,
- int srid, String geometryType, int dim,
+ int srid, String geometryType, boolean multi, int dim,
boolean normalizedColumnNames) throws SQLException {
FeatureSchema schema = fc.getFeatureSchema();
String geometryColumn = normalizedColumnNames ?
@@ -189,7 +189,7 @@
throw new SQLException("Error executing query: " +
conn.getMetadata()
.getAddGeometryColumnStatement(schemaName, tableName,
geometryColumn, srid, geometryType, dim), sqle);
}
- populateTable(conn, fc, null, srid, dim, normalizedColumnNames);
+ populateTable(conn, fc, null, srid, multi, dim, normalizedColumnNames);
try {
conn.getJdbcConnection().createStatement().execute(conn.getMetadata()
.getAddSpatialIndexStatement(schemaName, tableName,
geometryColumn));
@@ -200,8 +200,8 @@
}
private void populateTable(SpatialDatabasesDSConnection conn,
FeatureCollection fc, String primaryKey,
- int srid, int dim, boolean
normalizedColumnNames) throws SQLException {
- PreparedStatement statement = insertStatement(conn,
fc.getFeatureSchema(), normalizedColumnNames);
+ int srid, boolean multi, int dim, boolean
normalizedColumnNames) throws SQLException {
+ PreparedStatement statement = insertStatement(conn,
fc.getFeatureSchema(), multi, normalizedColumnNames);
int count = 0;
// There is an option to convert NaN values to any double value while
uploading
// z is changed without duplicating the geometry
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-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISDataStoreDataSource.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -174,7 +174,7 @@
protected void createAndPopulateTable(
SpatialDatabasesDSConnection conn,
FeatureCollection fc,
- int srid, String geometryType, int dim,
+ int srid, String geometryType, boolean multi, int dim,
boolean normalizedColumnNames) throws SQLException {
FeatureSchema schema = fc.getFeatureSchema();
String geometryColumn = normalizedColumnNames ?
@@ -198,7 +198,7 @@
throw new SQLException("Error executing query: " +
conn.getMetadata()
.getAddGeometryColumnStatement(schemaName, tableName,
geometryColumn, srid, geometryType, dim), sqle);
}
- populateTable(conn, fc, null, srid, dim, normalizedColumnNames);
+ populateTable(conn, fc, null, srid, multi, dim, normalizedColumnNames);
try {
conn.getJdbcConnection().createStatement().execute(conn.getMetadata()
.getAddSpatialIndexStatement(schemaName, tableName,
geometryColumn));
@@ -209,8 +209,8 @@
}
private void populateTable(SpatialDatabasesDSConnection conn,
FeatureCollection fc, String primaryKey,
- int srid, int dim, boolean
normalizedColumnNames) throws SQLException {
- PreparedStatement statement = insertStatement(conn,
fc.getFeatureSchema(), normalizedColumnNames);
+ int srid, boolean multi, int dim, boolean
normalizedColumnNames) throws SQLException {
+ PreparedStatement statement = insertStatement(conn,
fc.getFeatureSchema(), multi, normalizedColumnNames);
int count = 0;
// There is an option to convert NaN values to any double value while
uploading
// z is changed without duplicating the geometry
Modified:
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISSaveDataSourceQueryChooser.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISSaveDataSourceQueryChooser.java
2016-11-05 06:40:20 UTC (rev 5152)
+++
core/trunk/src/org/openjump/core/ui/plugin/datastore/postgis2/PostGISSaveDataSourceQueryChooser.java
2016-11-05 11:00:24 UTC (rev 5153)
@@ -23,11 +23,11 @@
public static final String KEY =
PostGISSaveDataSourceQueryChooser.class.getName();
- static final String ERROR = I18N.get(KEY + ".error");
- static final String NO_CONNECTION_CHOOSEN = I18N.get(KEY +
".no-connection-choosen");
- static final String NO_TABLE_CHOOSEN = I18N.get(KEY +
".no-table-choosen");
- static final String CONNECTION_IS_NOT_POSTGIS = I18N.get(KEY +
".selected-connection-is-not-postgis");
- static final String GID_ALREADY_EXISTS = I18N.get(KEY +
".gid-already-exists");
+ private static final String ERROR = I18N.get(KEY + ".error");
+ private static final String NO_CONNECTION_CHOOSEN = I18N.get(KEY +
".no-connection-choosen");
+ private static final String NO_TABLE_CHOOSEN = I18N.get(KEY +
".no-table-choosen");
+ private static final String CONNECTION_IS_NOT_POSTGIS = I18N.get(KEY +
".selected-connection-is-not-postgis");
+ private static final String GID_ALREADY_EXISTS = I18N.get(KEY +
".gid-already-exists");
private PlugInContext context;
private PostGISSaveDriverPanel panel;
@@ -57,7 +57,7 @@
* the returned collection only contains a single element.
* @see
com.vividsolutions.jump.workbench.datasource.DataSourceQueryChooser#getDataSourceQueries()
*/
- public Collection getDataSourceQueries() {
+ public Collection<DataSourceQuery> getDataSourceQueries() {
// Get the name of the table to update
String updateQuery =
(String)properties.get(WritableDataStoreDataSource.DATASET_NAME_KEY);
// Create a DataSourceQuery from a datasource, and a query
@@ -106,7 +106,7 @@
return false;
}
else {
- Layer[] layers =
context.getWorkbenchContext().getLayerNamePanel().getSelectedLayers();
+ Layer[] layers =
context.getWorkbenchContext().getLayerableNamePanel().getSelectedLayers();
if (layers.length == 1) {
FeatureSchema schema =
layers[0].getFeatureCollectionWrapper().getFeatureSchema();
if (schema.hasAttribute("gid") &&
panel.isCreatePrimaryKeyColumnSelected()) {
@@ -139,7 +139,7 @@
if (panel.isCreatePrimaryKeyColumnSelected()) {
properties.put(WritableDataStoreDataSource.EXTERNAL_PK_KEY,
WritableDataStoreDataSource.DEFAULT_PK_NAME);
}
- Layer[] layers =
context.getWorkbenchContext().getLayerNamePanel().getSelectedLayers();
+ Layer[] layers =
context.getWorkbenchContext().getLayerableNamePanel().getSelectedLayers();
if (layers.length == 1) {
FeatureSchema schema =
layers[0].getFeatureCollectionWrapper().getFeatureSchema();
properties.put(WritableDataStoreDataSource.GEOMETRY_ATTRIBUTE_NAME_KEY,
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel