/** * {@inheritDoc} */ @Override public void process(DbFeature<T> data, ResultSet resultSet) throws SQLException { int sequence; // Get the entity sequence number. sequence = resultSet.getInt("sequence_id"); listener.process(new DbOrderedFeature<T>(data.getEntityId(), data.getFeature(), sequence), resultSet); } }
/** * {@inheritDoc} */ @Override public void process(T data, ResultSet resultSet) throws SQLException { long id; // Get the owning entity id. id = resultSet.getLong("id"); listener.process(new DbFeature<T>(id, data), resultSet); } }
/** * {@inheritDoc} */ @Override public void store(StoreWriter sw, StoreClassRegister scr) { super.store(sw, scr); sw.writeInteger(sequenceId); }
/** * {@inheritDoc} */ public int compare(DbFeature<T> o1, DbFeature<T> o2) { long idDelta; idDelta = o1.getEntityId() - o2.getEntityId(); if (idDelta < 0) { return -1; } else if (idDelta > 0) { return 1; } return 0; } }
/** * Loads all instances of this feature for the specified entity from the database. * * @param entityId * The unique identifier of the entity. * @return All instances of this feature type for the entity. */ public Collection<Tef> getAllRaw(long entityId) { Collection<Tdb> dbFeatures; Collection<Tef> rawFeatures; dbFeatures = getAll(entityId); rawFeatures = new ArrayList<Tef>(dbFeatures.size()); for (Tdb dbFeature : dbFeatures) { rawFeatures.add(dbFeature.getFeature()); } return rawFeatures; }
/** * {@inheritDoc} */ public int compare(DbFeature<T> o1, DbFeature<T> o2) { long idDelta; idDelta = o1.getEntityId() - o2.getEntityId(); if (idDelta < 0) { return -1; } else if (idDelta > 0) { return 1; } return 0; } }
/** * Loads all instances of this feature for the specified entity from the database. * * @param entityId * The unique identifier of the entity. * @return All instances of this feature type for the entity. */ public Collection<Tef> getAllRaw(long entityId) { Collection<Tdb> dbFeatures; Collection<Tef> rawFeatures; dbFeatures = getAll(entityId); rawFeatures = new ArrayList<Tef>(dbFeatures.size()); for (Tdb dbFeature : dbFeatures) { rawFeatures.add(dbFeature.getFeature()); } return rawFeatures; }
/** * {@inheritDoc} */ @Override public void process(DbFeature<T> data, ResultSet resultSet) throws SQLException { int sequence; // Get the entity sequence number. sequence = resultSet.getInt("sequence_id"); listener.process(new DbOrderedFeature<T>(data.getEntityId(), data.getFeature(), sequence), resultSet); } }
/** * {@inheritDoc} */ @Override public void process(T data, ResultSet resultSet) throws SQLException { long id; // Get the owning entity id. id = resultSet.getLong("id"); listener.process(new DbFeature<T>(id, data), resultSet); } }
/** * Adds the specified features to the database. * * @param features * The features to add. */ public void addAll(Collection<Tdb> features) { if (insertStatement == null) { insertStatement = prepareStatement(entityFeatureBuilder.getSqlInsert(1)); } for (Tdb feature : features) { try { entityFeatureBuilder.populateEntityParameters(insertStatement, 1, feature); insertStatement.executeUpdate(); } catch (SQLException e) { throw new OsmosisRuntimeException( "Insert failed for " + entityFeatureBuilder.getEntityName() + " " + feature.getEntityId() + "." ); } } }
entity.getTags().add(dbTag.getFeature());
/** * {@inheritDoc} */ @Override public void store(StoreWriter sw, StoreClassRegister scr) { super.store(sw, scr); sw.writeInteger(sequenceId); }
/** * {@inheritDoc} */ @Override public int populateEntityParameters(PreparedStatement statement, int initialIndex, DbFeature<Tag> entityFeature) { try { int prmIndex; Tag tag; tag = entityFeature.getFeature(); prmIndex = initialIndex; statement.setLong(prmIndex++, entityFeature.getEntityId()); statement.setString(prmIndex++, tag.getKey()); statement.setString(prmIndex++, tag.getValue()); return prmIndex; } catch (SQLException e) { throw new OsmosisRuntimeException( "Unable to populate tag parameters for entity " + parentEntityName + " " + entityFeature.getEntityId() + "." ); } } }
/** * Adds the specified tags to the database. * * @param entityId * The identifier of the entity to add these features to. * @param tags * The features to add. */ private void addTags(long entityId, Collection<Tag> tags) { Collection<DbFeature<Tag>> dbList; dbList = new ArrayList<DbFeature<Tag>>(tags.size()); for (Tag tag : tags) { dbList.add(new DbFeature<Tag>(entityId, tag)); } tagDao.addAll(dbList); }
/** * {@inheritDoc} */ @Override public void populateFeatures(Te entity) { // Add all applicable tags to the entity. while (source.hasNext() && source.peekNext().getEntityId() == entity.getId()) { featureLoader.getFeatureCollection(entity).add(source.next().getFeature()); } }
/** * Process the node tags. * * @param node The node to be processed. */ private void addNodeTags(Node node) { for (Tag tag : node.getTags()) { nodeTagBuffer.add(new DbFeatureHistory<DbFeature<Tag>>(new DbFeature<Tag>(node.getId(), tag), node .getVersion())); } flushNodeTags(false); }
/** * Sets tag values as bind variable parameters to a tag insert query. * * @param statement The prepared statement to add the values to. * @param initialIndex The offset index of the first variable to set. * @param dbEntityTag The entity tag containing the data to be inserted. */ private void populateEntityTagParameters(PreparedStatement statement, int initialIndex, DbFeatureHistory<DbFeature<Tag>> dbEntityTag) { int prmIndex; Tag tag; prmIndex = initialIndex; tag = dbEntityTag.getFeature().getFeature(); try { statement.setLong(prmIndex++, dbEntityTag.getFeature().getEntityId()); statement.setString(prmIndex++, tag.getKey()); statement.setString(prmIndex++, tag.getValue()); statement.setInt(prmIndex++, dbEntityTag.getVersion()); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to set a prepared statement parameter for an entity tag.", e); } }
/** * Process the relation tags. * * @param relation The relation to be processed. */ private void addRelationTags(Relation relation) { for (Tag tag : relation.getTags()) { relationTagBuffer.add(new DbFeatureHistory<DbFeature<Tag>>(new DbFeature<Tag>(relation.getId(), tag), relation.getVersion())); } flushRelationTags(false); }
/** * Sets tag values as bind variable parameters to a tag insert query. * * @param statement The prepared statement to add the values to. * @param initialIndex The offset index of the first variable to set. * @param dbEntityTag The entity tag containing the data to be inserted. */ private void populateEntityTagParameters(PreparedStatement statement, int initialIndex, DbFeatureHistory<DbFeature<Tag>> dbEntityTag) { int prmIndex; Tag tag; prmIndex = initialIndex; tag = dbEntityTag.getFeature().getFeature(); try { statement.setLong(prmIndex++, dbEntityTag.getFeature().getEntityId()); statement.setString(prmIndex++, tag.getKey()); statement.setString(prmIndex++, tag.getValue()); statement.setInt(prmIndex++, dbEntityTag.getVersion()); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to set a prepared statement parameter for an entity tag.", e); } }
/** * Process the way tags. * * @param way The way to be processed. */ private void addWayTags(Way way) { for (Tag tag : way.getTags()) { wayTagBuffer.add(new DbFeatureHistory<DbFeature<Tag>>(new DbFeature<Tag>(way.getId(), tag), way .getVersion())); } flushWayTags(false); }