2

Sorry for my english, I hope you can understand ;) I'am using geotools 8.4 version. I try to copy all features from SDE Table(TEST.DBO.MM_SOURCE) to another SDE Table(TEST.DBO.MM_TEST). All features are copied correctly, but they are not stored in main table (TEST.DBO.MM_TEST). When I open ArcMap, edit some feature in TEST.DBO.MM_TEST and save, all features are back in main table. Both SDE tables are registered as versioned and moving edits to base. What I must do to store all features in main table?

Here is my java code:

String server = "localhost";
String port = "5151";
String database = "Test";
String user = "sa";
String password = "sa";
String version = "dbo.Default";

connector = new SDEConnector();
connector.setConnectionParameters(server, port, database, user, password, version);
connector.connect();

SimpleFeatureStore dataStore =
        (SimpleFeatureStore) connector.getDataStore().getFeatureSource("TEST.DBO.MM_TEST");

SimpleFeatureCollection fc1 = connector.getFeatureCollection("TEST.DBO.MM_SOURCE")
SimpleFeatureCollection fc2 = dataStore.getFeatures();

SimpleFeatureIterator iterator = fc1.features();
while (iterator.hasNext()) {
    SimpleFeature feature = iterator.next();
    Geometry geometry = (Geometry) feature.getDefaultGeometry();

    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(fc2.getSchema());
    builder.set("Shape", geometry);
    builder.set("P1", feature.getAttribute("P1"));
    builder.set("P2", feature.getAttribute("P2"));
    builder.set("Source_OID", 829023);
    builder.set("Marker", 10);

    SimpleFeature sf = builder.buildFeature(null);
    // SimpleFeature sf = builder.buildFeature(builder.createDefaultFeatureId());

    List<SimpleFeature> list = new ArrayList<SimpleFeature>();
    list.add(sf);

    dataStore.addFeatures(DataUtilities.collection(list));
}
iterator.close();
time = System.currentTimeMillis() - time;
System.out.println(time);

1 Answer 1

1

You need to commit the changes to the datastore. You'll need some code like:

 if (featureSource instanceof SimpleFeatureStore) {
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;

        featureStore.setTransaction(transaction);
        try {
            featureStore.addFeatures(collection);
            transaction.commit();

        } catch (Exception problem) {
            problem.printStackTrace();
            transaction.rollback();

        } finally {
            transaction.close();
        }
        System.exit(0); // success!
    } else {
        System.out.println(typeName + " does not support read/write access");
        System.exit(1);
    }

See this tutorial for more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.