Package com.impossibl.postgres.api.data

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


    PreparedStatement pstmt = conn.prepareStatement("CREATE TEMP TABLE inet_tab (ip1 inet, ip2 inet, ip3 inet)");
    pstmt.executeUpdate();
    pstmt.close();

    pstmt = conn.prepareStatement("insert into inet_tab values (?,?,?)");
    InetAddr inet1;
    InetAddr inet2;
    pstmt.setObject(1, inet1 = new InetAddr("2001:4f8:3:ba:2e0:81ff:fe22:d1f1"));
    pstmt.setObject(2, inet2 = new InetAddr("192.168.100.128/25"));
    pstmt.setObject(3, null, Types.OTHER);
    pstmt.executeUpdate();
    pstmt.close();

    pstmt = conn.prepareStatement("select * from inet_tab");
    ResultSet rs = pstmt.executeQuery();
    assertTrue(rs.next());
    assertTrue(rs.getObject(1).getClass() == InetAddr.class);
    assertTrue(inet1.equals(rs.getObject(1)));
    assertTrue(rs.getObject(2).getClass() == InetAddr.class);
    assertTrue(inet2.equals(rs.getObject(2)));
    rs.getObject(3);
    assertTrue(rs.wasNull());
    rs.close();
    pstmt.close();
  }
View Full Code Here


          map.put("3", "three");
          return map;
        }

      } },
      {"inet", new InetAddr("2001:4f8:3:ba:2e0:81ff:fe22:d1f1/10")},
      {"cidr", new CidrAddr("2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128")},
      {"tid", new PGRowId(new Tid(0, (short) 1))},
    };

    List<Object[]> data = new ArrayList<>();
View Full Code Here

    public void encode(Type type, ByteBuf buffer, Object val, Context context) throws IOException {
      if (val == null) {
        buffer.writeInt(-1);
      }
      else {
        InetAddr inet = (InetAddr) val;
        byte[] addr = inet.getAddress();
        boolean ipV4 = inet.getFamily() == Family.IPv4;
        buffer.writeInt(ipV4 ? 8 : 20);
        buffer.writeByte(ipV4 ? PGSQL_AF_INET : PGSQL_AF_INET6);
        buffer.writeByte(inet.getMaskBits());
        buffer.writeByte(type.getName().equals("cidr") ? 0 : 1);
        buffer.writeByte(addr.length);
        buffer.writeBytes(addr);
      }
    }
View Full Code Here

      return PrimitiveType.Binary;
    }

    @Override
    public void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {
      InetAddr inet = (InetAddr) val;
      buffer.append(inet.toString());
    }
View Full Code Here

  static class InetObjectFactory implements NetworkObjectFactory<InetAddr> {

    @Override
    public InetAddr newNetworkObject(byte[] addr, short netmask) {
      return new InetAddr(addr, netmask);
    }
View Full Code Here

      return new InetAddr(addr, netmask);
    }

    @Override
    public InetAddr newNetworkObject(String v) {
      return new InetAddr(v);
    }
View Full Code Here

TOP

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

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.