// see if there is anything at all to do, if both sides have no changes there
// is no point eating away a revision number (this avoid the local revision number to
// skyrocket for nothing if there are frequent synchronisations)
String tableName = request.getTypeName().getLocalPart();
VersioningFeatureStore fs = (VersioningFeatureStore) ds.getFeatureSource(tableName);
FeatureStore history = (FeatureStore) ds.getFeatureSource(SYNCH_HISTORY);
PropertyIsEqualTo ftSyncRecord = ff.equals(ff.property("table_name"), ff.literal(tableName));
TransactionType changes = request.getTransaction();
int changesCount = core.countChanges(changes);
// ... if we have no changes from remote
if(changesCount == 0) {
// ... and we have no changes locally
String lastLocalRevisionId = lastLocalRevision != -1 ? String.valueOf(lastLocalRevision) : "FIRST";
if(fs.getLog(lastLocalRevisionId, "LAST", null, null, 1).size() == 0) {
// add a new record without the need to grab a new local revision
// (if necessary, that is, if at least the Central revision changed or if
// we don't have a synch history at all)
long newCentralRevision = request.getToVersion();
if(lastCentralRevision != newCentralRevision || record == null) {
SimpleFeatureType hft = (SimpleFeatureType) history.getSchema();
SimpleFeature f = SimpleFeatureBuilder.build(hft, new Object[] { tableName,
lastLocalRevision, newCentralRevision }, null);
history.addFeatures(DataUtilities.collection(f));
}
// ... let's just return directly, no need to store or do anything
return new PostDiffResponseType();
}
}
// setup the commit message and author
transaction.putProperty(VersioningDataStore.AUTHOR, "gss");
transaction.putProperty(VersioningDataStore.MESSAGE, "Applying " + changesCount
+ " changes coming from Central on layer '" + tableName + "'");
// grab the feature stores and bind them all to the same transaction
VersioningFeatureStore conflicts = (VersioningFeatureStore) ds
.getFeatureSource(SYNCH_CONFLICTS);
conflicts.setTransaction(transaction);
history.setTransaction(transaction);
fs.setTransaction(transaction);
// get a hold on a revision number early so that we don't get concurrent changes
// from the user (the datastore will make it so that no new revision numbers will
// be generated until we commit or rollback this transaction
long newLocalRevision = Long.parseLong(conflicts.getVersion());
// apply changes
LOGGER.info("About to apply " + core.countChanges(changes)
+ " changes coming from Central");
if (core.countChanges(changes) > 0) {