use of org.onebusaway.gtfs_transformer.collections.IdKeyMatch in project onebusaway-gtfs-modules by OneBusAway.
the class EntitiesTransformStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
for (MatchAndTransform modification : _modifications) {
TypedEntityMatch match = modification.getMatch();
Class<?> entityType = match.getType();
EntityTransformStrategy transform = modification.getTransform();
if (IdKey.class.isAssignableFrom(entityType)) {
IdKeyMatch keyMatch = (IdKeyMatch) match.getPropertyMatches();
transform.run(context, dao, keyMatch.getKey());
} else {
Collection<Object> entities = new ArrayList<Object>(dao.getAllEntitiesForType(entityType));
for (Object object : entities) {
if (match.isApplicableToObject(object)) {
transform.run(context, dao, object);
}
}
}
}
}
use of org.onebusaway.gtfs_transformer.collections.IdKeyMatch in project onebusaway-gtfs-modules by OneBusAway.
the class RetainEntitiesTransformStrategy method run.
@SuppressWarnings("unchecked")
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
if (_retentionMatchesByType.isEmpty())
return;
EntityRetentionGraph graph = new EntityRetentionGraph(dao);
graph.setRetainBlocks(_retainBlocks);
for (Map.Entry<Class<?>, List<EntityRetention>> entry : _retentionMatchesByType.entrySet()) {
Class<?> entityType = entry.getKey();
List<EntityRetention> retentions = entry.getValue();
if (IdKey.class.isAssignableFrom(entityType)) {
for (EntityRetention retention : retentions) {
TypedEntityMatch typedMatch = retention.getMatch();
IdKeyMatch match = (IdKeyMatch) typedMatch.getPropertyMatches();
graph.retain(match.getKey(), retention.isRetainUp());
}
} else {
Collection<Object> entities = new ArrayList<Object>(dao.getAllEntitiesForType(entityType));
for (Object object : entities) {
for (EntityRetention retention : retentions) {
EntityMatch match = retention.getMatch();
if (match.isApplicableToObject(object))
graph.retain(object, retention.isRetainUp());
}
}
}
}
for (Class<?> entityClass : GtfsEntitySchemaFactory.getEntityClasses()) {
List<Object> objectsToRemove = new ArrayList<Object>();
for (Object entity : dao.getAllEntitiesForType(entityClass)) {
if (!graph.isRetained(entity))
objectsToRemove.add(entity);
}
for (Object toRemove : objectsToRemove) dao.removeEntity((IdentityBean<Serializable>) toRemove);
}
}
Aggregations