Description

GeoTools data stores always generate a new feature id when a new feature is being inserted. In some cases this is a requirement, such as in Shapefiles, where the id is the feature row number in the file. In other cases it's merely an implementation choice, such as the case of property data store or the JDBC data stores.

the primary key can be a multicolumn key whose content references other tables via foreign keys

the key itself has a business meaning (e.g., a social security number)

This proposal adds hints to allow:

a feature store to advertise the ability to use user provided feature id during inserts

a user to ask the feature id to be used during the import
Neither of them requires new API, thus this proposal is targeted towards both the 2.6.x and trunk branches.

To support advertisement QueryCapabilities gets a new method:

public class QueryCapabilities {
/**
* If true the datastore supports using the provided feature id in the data insertion
* workflow as opposed to generating a new id. In that case it will look into the user data
* map ({@link Feature#getUserData()}) for a {@link Hints#USE_EXISTING_FID} key associated to a
* {@link Boolean#TRUE} value, if the key/value pair is there an attempt to use the provided
* id will be made, and the operation will fail of the key cannot be parsed into a valid
* storage identifier.
* @return
*/
public boolean isUseExisingFIDSupported() {
return false;
}
}

To support uses in asking the FID to be used a new well know hint has been added, that need to be specified in the Feature user map (see example below):

pubilc class Hints {
...
/**
* When this key is used in the user data section of a feature and the feature store
* query capabilities reports being able to use provided feature ids the store will
* try to use the provided feature id during insertion, and will fail if the FID
* cannot be parsed into a valid storage identifier
*
* @since 2.7
*/
public static final Key USE_EXISTING_FID = new Key("org.geotools.fidPolicy.UseExisting");
}

Implementation wise the JDBC data stores and the property data store will be modified to support the USE_EXISTING_FID hint.