Package com.impossibl.postgres.api.data

Examples of com.impossibl.postgres.api.data.Path


  @Test
  public void testPath() throws SQLException {
    try (PreparedStatement pstmt = conn.prepareStatement("CREATE TEMP TABLE path_tab (p1 path, p2 path, p3 path)")) {
      pstmt.executeUpdate();
    }
    Path p1 = GeometryParsers.INSTANCE.parsePath("[(678.6,454),(10,89),(124.6,0)]");
    Path p2 = GeometryParsers.INSTANCE.parsePath("((678.6,454),(10,89),(124.6,0))");
    try (PreparedStatement pstmt = conn.prepareStatement("insert into path_tab values (?,?,?)")) {
      pstmt.setObject(1, p1);
      pstmt.setObject(2, p2);
      pstmt.setObject(3, null, Types.OTHER);
      pstmt.executeUpdate();
    }

    try (PreparedStatement pstmt = conn.prepareStatement("select * from path_tab");
        ResultSet rs = pstmt.executeQuery()) {
      assertTrue(rs.next());
      assertTrue(rs.getObject(1).getClass() == Path.class);
      assertTrue(p1.equals(rs.getObject(1)));
      assertTrue(p2.equals(rs.getObject(2)));
      rs.getObject(3);
      assertTrue(rs.wasNull());
    }
  }
View Full Code Here


    @Override
    public void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {
      if (val == null) {
        return;
      }
      buffer.append(new Path((double[][]) val, true));
    }
View Full Code Here

        double[] point = new double[2];
        point[0] = buffer.readDouble();
        point[1] = buffer.readDouble();
        points[i] = point;
      }
      return new Path(points, closed);
    }
View Full Code Here

    public void encode(Type type, ByteBuf buffer, Object val, Context context) throws IOException {
      if (val == null) {
        buffer.writeInt(-1);
      }
      else {
        Path path = (Path) val;
        double[][] points = path.getPoints();
        // byte + int + npts * 2 points
        int size = 1 + 4 + (points == null ? 0 : points.length * 8 * 2);
        buffer.writeInt(size);
        buffer.writeByte(path.isClosed() ? 1 : 0);
        buffer.writeInt(points == null ? 0 : points.length);
        if (points != null) {
          for (int i = 0; i < points.length; ++i) {
            double[] point = points[i];
            buffer.writeDouble(point[0]);
View Full Code Here

TOP

Related Classes of com.impossibl.postgres.api.data.Path

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.