Package org.openstreetmap.osmosis.core.domain.v0_6

Examples of org.openstreetmap.osmosis.core.domain.v0_6.RelationMember


   */
  @Test
  public final void testProcessNormalRelation() {
    Relation relation =
      new Relation(new CommonEntityData(1234, 2, timestamp, new OsmUser(23, "someuser"), 0));
    relation.getMembers().add(new RelationMember(2345, EntityType.Node, "noderole"));
    relation.getMembers().add(new RelationMember(3456, EntityType.Way, "wayrole"));
    relation.getMembers().add(new RelationMember(4567, EntityType.Relation, "relationrole"));
    relation.getTags().add(new Tag("relationkey", "relationvalue"));
   
    testRelationWriter.process(relation);
    try {
      testBufferedWriter.flush();
View Full Code Here


   */
  @Test
  public final void testProcessRelationWithNoUser() {
    Relation relation =
      new Relation(new CommonEntityData(1234, 2, timestamp, OsmUser.NONE, 0));
    relation.getMembers().add(new RelationMember(2345, EntityType.Node, "noderole"));
    relation.getMembers().add(new RelationMember(3456, EntityType.Way, "wayrole"));
    relation.getMembers().add(new RelationMember(4567, EntityType.Relation, "relationrole"));
    relation.getTags().add(new Tag("relationkey", "relationvalue"));
   
    testRelationWriter.process(relation);
    try {
      testBufferedWriter.flush();
View Full Code Here

   */
  @Test
  public final void testProcessRelationNoTags() {
    Relation relation =
      new Relation(new CommonEntityData(1234, 2, timestamp, new OsmUser(23, "someuser"), 0));
    relation.getMembers().add(new RelationMember(2345, EntityType.Node, "noderole"));
    relation.getMembers().add(new RelationMember(3456, EntityType.Way, "wayrole"));
    relation.getMembers().add(new RelationMember(4567, EntityType.Relation, "relationrole"));
   
    testRelationWriter.process(relation);
    try {
      testBufferedWriter.flush();
    } catch (IOException e) {
View Full Code Here

            }
        }

        // Insert the members of the new relation into the history table.
        for (int i = 0; i < relationMemberList.size(); i++) {
            RelationMember relationMember;

            relationMember = relationMemberList.get(i);

            try {
                prmIndex = 1;
                insertRelationMemberStatement.setLong(prmIndex++, relation.getId());
                insertRelationMemberStatement.setInt(prmIndex++, relation.getVersion());
                insertRelationMemberStatement.setString(prmIndex++, memberTypeRenderer.render(relationMember
                        .getMemberType()));
                insertRelationMemberStatement.setLong(prmIndex++, relationMember.getMemberId());
                insertRelationMemberStatement.setString(prmIndex++, relationMember.getMemberRole());
                insertRelationMemberStatement.setInt(prmIndex++, i + 1);

                insertRelationMemberStatement.execute();

            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to insert history relation member with relation id="
                        + relation.getId() + ", member type=" + relationMember.getMemberId() + " and member id="
                        + relationMember.getMemberId() + ".", e);
            }
        }

        if (populateCurrentTables) {
            // Delete the existing relation tags from the current table.
            try {
                deleteRelationTagCurrentStatement.setLong(1, relation.getId());

                deleteRelationTagCurrentStatement.execute();

            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to delete current relation tags with id=" + relation.getId()
                        + ".", e);
            }
            // Delete the existing relation members from the current table.
            try {
                deleteRelationMemberCurrentStatement.setLong(1, relation.getId());

                deleteRelationMemberCurrentStatement.execute();

            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to delete current relation members with id="
                        + relation.getId() + ".", e);
            }

            // Update the relation if it already exists in the current table, otherwise insert it.
            try {
                exists = checkIfEntityExists(selectRelationCurrentCountStatement, relation.getId());

            } catch (SQLException e) {
                throw new OsmosisRuntimeException("Unable to check if current relation with id=" + relation.getId()
                        + " exists.", e);
            }
            if (exists) {
                // Update the relation in the current table.
                try {
                    prmIndex = 1;
                    updateRelationCurrentStatement.setInt(prmIndex++, relation.getVersion());
                    updateRelationCurrentStatement.setTimestamp(prmIndex++, new Timestamp(relation.getTimestamp()
                            .getTime()));
                    updateRelationCurrentStatement.setBoolean(prmIndex++, visible);
                    updateRelationCurrentStatement.setLong(prmIndex++, relation.getChangesetId());
                    updateRelationCurrentStatement.setLong(prmIndex++, relation.getId());

                    updateRelationCurrentStatement.execute();

                } catch (SQLException e) {
                    throw new OsmosisRuntimeException("Unable to update current relation with id=" + relation.getId()
                            + ".", e);
                }
            } else {
                // Insert the new node into the current table.
                try {
                    prmIndex = 1;
                    insertRelationCurrentStatement.setLong(prmIndex++, relation.getId());
                    insertRelationCurrentStatement.setInt(prmIndex++, relation.getVersion());
                    insertRelationCurrentStatement.setTimestamp(prmIndex++, new Timestamp(relation.getTimestamp()
                            .getTime()));
                    insertRelationCurrentStatement.setBoolean(prmIndex++, visible);
                    insertRelationCurrentStatement.setLong(prmIndex++, relation.getChangesetId());

                    insertRelationCurrentStatement.execute();

                } catch (SQLException e) {
                    throw new OsmosisRuntimeException("Unable to insert current relation with id=" + relation.getId()
                            + ".", e);
                }
            }

            // Insert the tags of the new relation into the current table.
            for (Tag tag : relation.getTags()) {
                try {
                    prmIndex = 1;
                    insertRelationTagCurrentStatement.setLong(prmIndex++, relation.getId());
                    insertRelationTagCurrentStatement.setString(prmIndex++, tag.getKey());
                    insertRelationTagCurrentStatement.setString(prmIndex++, tag.getValue());

                    insertRelationTagCurrentStatement.execute();

                } catch (SQLException e) {
                    throw new OsmosisRuntimeException("Unable to insert current relation tag with id="
                            + relation.getId() + " and key=(" + tag.getKey() + ").", e);
                }
            }

            // Insert the members of the new relation into the current table.
            for (int i = 0; i < relationMemberList.size(); i++) {
                RelationMember relationMember;

                relationMember = relationMemberList.get(i);

                try {
                    prmIndex = 1;
                    insertRelationMemberCurrentStatement.setLong(prmIndex++, relation.getId());
                    insertRelationMemberCurrentStatement.setString(prmIndex++, memberTypeRenderer.render(relationMember
                            .getMemberType()));
                    insertRelationMemberCurrentStatement.setLong(prmIndex++, relationMember.getMemberId());
                    insertRelationMemberCurrentStatement.setString(prmIndex++, relationMember.getMemberRole());
                    insertRelationMemberCurrentStatement.setInt(prmIndex++, i + 1);

                    insertRelationMemberCurrentStatement.execute();

                } catch (SQLException e) {
                    throw new OsmosisRuntimeException("Unable to insert current relation member with relation id="
                            + relation.getId() + ", member type=" + relationMember.getMemberId() + " and member id="
                            + relationMember.getMemberId() + ".", e);
                }
            }
        }
    }
View Full Code Here

   
    id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_REF));
    type = memberTypeParser.parse(reader.getAttributeValue(null, ATTRIBUTE_NAME_TYPE));
    role = reader.getAttributeValue(null, ATTRIBUTE_NAME_ROLE);
   
    RelationMember relationMember = new RelationMember(id, type, role);
   
    reader.nextTag();
    reader.nextTag();
   
    return relationMember;
View Full Code Here

    long memberId = 0;
    while (memberIdIterator.hasNext()) {
      MemberType memberType = memberTypeIterator.next();
      memberId += memberIdIterator.next();
      EntityType entityType;
      RelationMember member;

      if (memberType == MemberType.NODE) {
        entityType = EntityType.Node;
      } else if (memberType == MemberType.WAY) {
        entityType = EntityType.Way;
      } else if (memberType == MemberType.RELATION) {
        entityType = EntityType.Relation;
      } else {
        throw new OsmosisRuntimeException("Member type of " + memberType + " is not supported.");
      }

      member = new RelationMember(memberId, entityType, fieldDecoder.decodeString(memberRoleIterator.next()));

      members.add(member);
    }
  }
View Full Code Here

  @Override
  public void processRow(ResultSet resultSet) throws SQLException {
        long memberId;
        EntityType memberType;
        String memberRole;
        RelationMember relationMember;
       
    memberId = resultSet.getLong("member_id");
    memberType = memberTypeParser.parse(resultSet.getString("member_type"));
    memberRole = resultSet.getString("member_role");
   
    relationMember = new RelationMember(memberId, memberType, memberRole);
   
        listener.process(relationMember, resultSet);
  }
View Full Code Here

  @Override
  public DbOrderedFeature<RelationMember> buildEntity(ResultSet resultSet) {
    try {
      return new DbOrderedFeature<RelationMember>(
        resultSet.getLong("entity_id"),
        new RelationMember(
          resultSet.getLong("member_id"),
          memberTypeValueMapper.getEntityType(resultSet.getString("member_type")),
          resultSet.getString("member_role")
        ),
        resultSet.getInt("sequence_id")
View Full Code Here

  @Override
  public int populateEntityParameters(
      PreparedStatement statement, int initialIndex, DbOrderedFeature<RelationMember> entityFeature) {
    try {
      int prmIndex;
      RelationMember relationMember;
     
      relationMember = entityFeature.getFeature();
     
      prmIndex = initialIndex;
     
      statement.setLong(prmIndex++, entityFeature.getEntityId());
      statement.setLong(prmIndex++, relationMember.getMemberId());
      statement.setString(prmIndex++, memberTypeValueMapper.getMemberType(relationMember.getMemberType()));
      statement.setString(prmIndex++, relationMember.getMemberRole());
      statement.setInt(prmIndex++, entityFeature.getSequenceId());
     
      return prmIndex;
     
    } catch (SQLException e) {
View Full Code Here

                    etype = EntityType.Relation;
                } else {
                    assert false; // TODO; Illegal file?
                }

                nodes.add(new RelationMember(mid, etype, role));
            }
            // long id, int version, TimestampContainer timestampContainer,
            // OsmUser user,
            // long changesetId, Collection<Tag> tags,
            // List<RelationMember> members
View Full Code Here

TOP

Related Classes of org.openstreetmap.osmosis.core.domain.v0_6.RelationMember

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.