try {
for(final String deleted : this.deletedResources) {
final String[] info = this.extractResourceInfo(deleted);
// check if the collection still exists
final DBCollection col = this.getCollection(info[0]);
if ( col != null ) {
if ( col.findAndRemove(QueryBuilder.start(getPROP_PATH()).is(info[1]).get()) != null ) {
this.context.notifyRemoved(info);
}
}
}
for(final MongoDBResource changed : this.changedResources.values()) {
final DBCollection col = this.context.getDatabase().getCollection(changed.getCollection());
if ( col != null ) {
final String[] info = new String[] {changed.getCollection(),
changed.getProperties().get(getPROP_PATH()).toString()};
// create or update?
if ( changed.getProperties().get(PROP_ID) != null ) {
col.update(QueryBuilder.start(getPROP_PATH()).is(changed.getProperties().get(getPROP_PATH())).get(),
changed.getProperties());
this.context.notifyUpdated(info);
} else {
// create
col.save(changed.getProperties());
this.context.notifyUpdated(info);
}
} else {
throw new PersistenceException("Unable to create collection " + changed.getCollection(), null, changed.getPath(), null);
}