Package com.impossibl.postgres.types

Examples of com.impossibl.postgres.types.Type


  private void coerceParameters() throws SQLException {

    for (int c = 0, sz = parameterTypes.size(); c < sz; ++c) {

      Type parameterType = parameterTypes.get(c);
      Object parameterValue = parameterValues.get(c);

      if (parameterValue != null) {

        Class<?> targetType = mapSetType(parameterType);
View Full Code Here


    if (defaultTypes == null)
      return list;

    for (int c = 0, sz = list.size(); c < sz; ++c) {

      Type type = list.get(c);
      if (type == null)
        type = defaultTypes.get(c);

      list.set(c, type);
    }
View Full Code Here

    if (sourceTypes == null)
      return list;

    for (int c = 0, sz = list.size(); c < sz; ++c) {

      Type type = sourceTypes.get(c);
      if (type != null) {
        list.set(c, type);
      }
    }
View Full Code Here

  @Test
  public void testIntervalToStringCoercion() throws SQLException {
    Interval interval = new Interval("1 year 3 months");
    PGConnectionImpl pgConnectionImpl = _conn.unwrap(PGConnectionImpl.class);
    Type type = pgConnectionImpl.getRegistry().loadType("Interval");
    String coercedStringValue = SQLTypeUtils.coerceToString(interval, type, pgConnectionImpl);

    assertEquals("@ 1 years 3 months 0 days 0 hours 0 minutes 0.000000 seconds", coercedStringValue);
  }
View Full Code Here

    @Override
    public Range<?> decode(Type type, Short typeLength, Integer typeModifier, ByteBuf buffer, Context context) throws IOException {

      RangeType rangeType = (RangeType) type;
      Type baseType = rangeType.getBase();

      Range<?> instance = null;

      int length = buffer.readInt();

      if (length != -1) {

        Range.Flags flags = new Range.Flags(buffer.readByte());
        Object[] values = new Object[2];

        if (flags.hasLowerBound()) {

          values[0] = baseType.getBinaryCodec().decoder.decode(baseType, null, null, buffer, context);
        }

        if (flags.hasUpperBound()) {

          values[1] = baseType.getBinaryCodec().decoder.decode(baseType, null, null, buffer, context);
        }

        instance = new Range<Object>(flags, values);
      }
View Full Code Here

      if (val != null) {

        int writeStart = buffer.writerIndex();

        RangeType rangeType = (RangeType) type;
        Type baseType = rangeType.getBase();

        Range<?> range = (Range<?>) val;

        buffer.writeByte(range.getFlags().getValue());

        if (range.getFlags().hasLowerBound()) {

          baseType.getBinaryCodec().encoder.encode(baseType, buffer, range.getLowerBound(), context);
        }

        if (range.getFlags().hasUpperBound()) {

          baseType.getBinaryCodec().encoder.encode(baseType, buffer, range.getUpperBound(), context);
        }

        // Set length
        buffer.setInt(writeStart - 4, buffer.writerIndex() - writeStart);
      }
View Full Code Here

    @Override
    public Range<?> decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {

      RangeType rangeType = (RangeType) type;
      Type baseType = rangeType.getBase();

      boolean lowerInc = false, upperInc = false;
      Object lower = null, upper = null;

      if (buffer.charAt(0) == '[') {
        lowerInc = true;
      }

      if (buffer.charAt(buffer.length() - 1) == ']') {
        upperInc = true;
      }

      CharSequence lowerTxt = buffer.subSequence(1, findBound(buffer, 1));
      if (lowerTxt.length() != 0) {
        lower = baseType.getTextCodec().decoder.decode(baseType, null, null, lowerTxt, context);
      }

      CharSequence upperTxt = buffer.subSequence(2 + lowerTxt.length(), buffer.length() - 1);
      if (upperTxt.length() != 0) {
        upper = baseType.getTextCodec().decoder.decode(baseType, null, null, upperTxt, context);
      }

      return Range.create(lower, lowerInc, upper, upperInc);
    }
View Full Code Here

        for (int c = 0; c < itemCount; ++c) {

          ResultField field = resultBatch.fields.get(c);

          Type fieldType = field.typeRef.get();

          Type.Codec.Decoder decoder = fieldType.getCodec(field.format).decoder;

          Object fieldVal = decoder.decode(fieldType, field.typeLength, field.typeModifier, buffer, context);

          resultSetters.get(c).set(rowInstance, fieldVal);
        }
View Full Code Here

    @Override
    public void encode(Type type, ByteBuf buffer, Object value, Context context) throws IOException {

      DomainType domainType = (DomainType) type;
      Type baseType = domainType.getBase();

      baseType.getBinaryCodec().encoder.encode(baseType, buffer, value, context);
    }
View Full Code Here

    @Override
    public int length(Type type, Object val, Context context) throws IOException {

      DomainType domainType = (DomainType) type;
      Type baseType = domainType.getBase();

      return baseType.getBinaryCodec().encoder.length(baseType, val, context);
    }
View Full Code Here

TOP

Related Classes of com.impossibl.postgres.types.Type

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.