Вопрос

Using the GeoTools WFS-T plugin, I have created a new row, and after a commit, I have a FeatureId whos .getId() returns an ugly string that looks something like this:

newmy_database:my_table.9223372036854775807

Aside from the fact that the word "new" at the beginning of "my_database" is a surprise, the number in no way reflects the primary key of the new row (which in this case is "23"). Fair enough, I thought this may be some internal numbering system. However, now I want a foreign key in another table to get the primary key of the new row in this one, and I'm not sure how to get the value from this FID. Some places suggest that you can use an FID in a query like this:

Filter filter = filterFactory.id(Collections.singleton(fid));
Query query = new Query(tableName, filter);
SimpleFeatureCollection features = simpleFeatureSource.getFeatures(query);

But this fails at parsing the FID, at the underscore of all places! That underscore was there when the row was created (I had to pass "my_database:my_table" as the table to add the row to).

I'm sure that either there is something wrong with the id, or I'm using it incorrectly somehow. Can anyone shed any light?

Это было полезно?

Решение

It appears as if a couple things are going wrong - and perhaps a bug report is needed.

The FeatureId with "new" at the beginning is a temporary id; that should be replaced with the real result once commit has been called.

There are a number of way to be aware of this:

1) You can listen for a BatchFeatureEvent; this offers the information on "temp id" -> "wfs id"

2) Internally this information is parsed from the Transaction Result returned from your WFS. The result is saved in the WFSTransactionState for you to access. This was before BatchFeatureEvent was invented.

Transaction transaction = new transaction("insert");
try {
     SimpleFeatureStore featureStore =
           (SimpleFeatureStore) wfs.getFeatureSource( typeName );
     featureStore.setTransaction( transaction );
     featureStore.addFeatures( DataUtilities.collection( feature ) );

     transaction.commit();

     // get the final feature id
     WFSTransactionState wfsts = (WFSTransactionState) transaction.getState(wfs);

     // In this example there is only one fid. Get it.
     String result = wfsts.getFids( typeName )[0];
}
finally {
     transaction.close();
}         

I have updated the documentation with the above example:

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top