Skip to content

Commit

Permalink
[GEOT-6264] JDBC FeatureWriter-implementation annihilates input-data.
Browse files Browse the repository at this point in the history
  • Loading branch information
burkhard committed Mar 12, 2019
1 parent aff650a commit 8c68d9d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ nb-configuration.xml
workspace
*.db
.metadata
.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ public void init() throws SQLException, IOException {

// TODO: factory fid prefixing out
init(featureType.getTypeName() + "." + dataStore.encodeFID(key, rs, offset));

for (int k = 0; k < values.length; k++) // ensure initialized values GEOT-6264
getAttribute(k);
}

public SimpleFeatureType getFeatureType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2019, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.jdbc;

import org.geotools.data.FeatureWriter;
import org.geotools.data.Transaction;
import org.opengis.feature.simple.SimpleFeature;

/**
* JDBC {@link FeatureWriter}-implementation tampers with input-data.
*
* @author Burkhard Strauss
* @see GEOT-6264
*/
public abstract class JDBCFeatureWriterOnlineTest extends JDBCTestSupport {

public void testNext() throws Exception {

try (FeatureWriter writer =
dataStore.getFeatureWriter(tname("ft1"), Transaction.AUTO_COMMIT)) {
assertTrue(writer.hasNext());
final SimpleFeature feature = (SimpleFeature) writer.next();
assertTrue(feature.getAttribute(0).toString().equals("POINT (0 0)"));
assertTrue((Integer) feature.getAttribute(1) == 0);
assertTrue((Double) feature.getAttribute(2) == 0.0);
assertTrue(((String) feature.getAttribute(3)).equals("zero"));
}
try (FeatureWriter writer =
dataStore.getFeatureWriter(tname("ft1"), Transaction.AUTO_COMMIT)) {
assertTrue(writer.hasNext());
final SimpleFeature feature = (SimpleFeature) writer.next();
assertTrue(feature.getAttribute(0).toString().equals("POINT (0 0)"));
assertTrue((Integer) feature.getAttribute(1) == 0);
assertTrue((Double) feature.getAttribute(2) == 0.0);
assertTrue(((String) feature.getAttribute(3)).equals("zero"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2019, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.data.mysql;

import org.geotools.jdbc.JDBCFeatureWriterOnlineTest;
import org.geotools.jdbc.JDBCTestSetup;

/** @author Burkhard Strauss */
public class MySQLFeatureWriterOnlineTest extends JDBCFeatureWriterOnlineTest {

@Override
protected JDBCTestSetup createTestSetup() {
return new MySQLTestSetup();
}
}

0 comments on commit 8c68d9d

Please sign in to comment.