/** * Non-identifiable entities (see * {@link AbstractNonIdentifiableSingleEntityMergeStrategy}) still have an id * of sorts: an integer id that we randomly generate on data import to * distinguish between the entities. To avoid id collisions in the output * feed, we reset this generated id before outputing it to the merged output * feed. * * @param context * @param entity */ private void resetGeneratedIds(GtfsMergeContext context, IdentityBean<?> entity) { Object id = entity.getId(); if (id != null && id instanceof Integer) { @SuppressWarnings("unchecked") IdentityBean<Integer> hasIntegerId = (IdentityBean<Integer>) entity; hasIntegerId.setId(0); } }
/** * Non-identifiable entities (see * {@link AbstractNonIdentifiableSingleEntityMergeStrategy}) still have an id * of sorts: an integer id that we randomly generate on data import to * distinguish between the entities. To avoid id collisions in the output * feed, we reset this generated id before outputing it to the merged output * feed. * * @param context * @param entity */ private void resetGeneratedIds(GtfsMergeContext context, IdentityBean<?> entity) { Object id = entity.getId(); if (id != null && id instanceof Integer) { @SuppressWarnings("unchecked") IdentityBean<Integer> hasIntegerId = (IdentityBean<Integer>) entity; hasIntegerId.setId(0); } }
@Override public int hashCode() { return getId().hashCode(); } }
/*************************************************************************** * {@link Object} **************************************************************************/ @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof IdentityBean<?>) || getClass() != obj.getClass()) return false; IdentityBean<?> entity = (IdentityBean<?>) obj; return getId().equals(entity.getId()); }
/** * Rename the id of the specified identity to avoid an raw GTFS identifier * collision in the merged output feed. * * @param context * @param entity */ @SuppressWarnings("unchecked") protected void rename(GtfsMergeContext context, IdentityBean<?> entity) { Object id = entity.getId(); if (id != null && id instanceof AgencyAndId) { IdentityBean<AgencyAndId> bean = (IdentityBean<AgencyAndId>) entity; AgencyAndId agencyAndId = bean.getId(); agencyAndId = MergeSupport.renameAgencyAndId(context, agencyAndId); bean.setId(agencyAndId); } } }
/*************************************************************************** * {@link Object} **************************************************************************/ @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof IdentityBean<?>) || getClass() != obj.getClass()) return false; IdentityBean<?> entity = (IdentityBean<?>) obj; return getId().equals(entity.getId()); }
private <T extends IdentityBean<AgencyAndId>> void bulkRenameAgencyId( Iterable<T> elements, String oldAgencyId, String newAgencyId) { for (T element : elements) { AgencyAndId id = element.getId(); if (id.getAgencyId().equals(oldAgencyId)) { AgencyAndId newId = new AgencyAndId(newAgencyId, id.getId()); element.setId(newId); } } }
@Override public <K extends Serializable, T extends IdentityBean<K>> void removeEntity( T entity) { Class<?> type = entity.getClass(); K id = entity.getId(); Map<Object, Object> byId = _entitiesByClassAndId.get(type); if (byId == null) { _log.warn("no stored entities type " + type); return; } Object found = byId.remove(id); if (found == null) _log.warn("no stored entity with type " + type + " and id " + id); }
private <T extends IdentityBean<AgencyAndId>> void bulkRenameAgencyId( Iterable<T> elements, String oldAgencyId, String newAgencyId) { for (T element : elements) { AgencyAndId id = element.getId(); if (id.getAgencyId().equals(oldAgencyId)) { AgencyAndId newId = new AgencyAndId(newAgencyId, id.getId()); element.setId(newId); } } }
@Override public <K extends Serializable, T extends IdentityBean<K>> void removeEntity( T entity) { Class<?> type = entity.getClass(); K id = entity.getId(); Map<Object, Object> byId = _entitiesByClassAndId.get(type); if (byId == null) { _log.warn("no stored entities type " + type); return; } Object found = byId.remove(id); if (found == null) _log.warn("no stored entity with type " + type + " and id " + id); }
/** * Rename the id of the specified identity to avoid an raw GTFS identifier * collision in the merged output feed. * * @param context * @param entity */ @SuppressWarnings("unchecked") protected void rename(GtfsMergeContext context, IdentityBean<?> entity) { Object id = entity.getId(); if (id != null && id instanceof AgencyAndId) { IdentityBean<AgencyAndId> bean = (IdentityBean<AgencyAndId>) entity; AgencyAndId agencyAndId = bean.getId(); AgencyAndId newAgencyAndId; if (this.getDuplicateRenamingStrategy() == EDuplicateRenamingStrategy.AGENCY) { newAgencyAndId = MergeSupport.renameAgencyAndId(agencyAndId.getAgencyId()+"-", agencyAndId); _log.debug(agencyAndId.toString() + " renamed(1) to " + newAgencyAndId); } else { newAgencyAndId = MergeSupport.renameAgencyAndId(context, agencyAndId); _log.debug(agencyAndId.toString() + " renamed(2) to " + newAgencyAndId); } bean.setId(newAgencyAndId); } }
public CacheKeyInfo createKey(Object object) { return new CacheKeyInfo(((IdentityBean<?>) object).getId(), false); } }
public CacheKeyInfo createKey(Object object) { return new CacheKeyInfo(((IdentityBean<?>) object).getId(), false); } }
@Override public void saveOrUpdateEntity(Object entity) { @SuppressWarnings("unchecked") IdentityBean<Serializable> bean = ((IdentityBean<Serializable>) entity); Object existing = getEntityForId(entity.getClass(), bean.getId()); // If the entity has already been inserted into storage, then we don't need // to save it if (existing == entity) return; saveEntity(entity); }
@Override public void saveOrUpdateEntity(Object entity) { @SuppressWarnings("unchecked") IdentityBean<Serializable> bean = ((IdentityBean<Serializable>) entity); Object existing = getEntityForId(entity.getClass(), bean.getId()); // If the entity has already been inserted into storage, then we don't need // to save it if (existing == entity) return; saveEntity(entity); }