Package com.impossibl.postgres.api.data

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


      {"float4", 1.23f},
      {"int2", (short)234},
      {"float8", 2.34d},
      {"int8", (long)234},
      {"int4", 234},
      {"interval", new Interval(1, 2, 3)},
      {"money", new BigDecimal("2342.00")},
      {"name", "hi"},
      {"numeric", new BigDecimal("2342.00")},
      {"oid", 132},
      {"int4range", new Maker() {
View Full Code Here


    }
    else if (val instanceof Interval) {
      return (Interval) val;
    }
    else if (val instanceof String) {
      return new Interval((String) val);
    }

    throw createCoercionException(val.getClass(), Interval.class);
  }
View Full Code Here

      long timeMicros = buffer.readLong();
      int days = buffer.readInt();
      int months = buffer.readInt();

      return new Interval(months, days, timeMicros);
    }
View Full Code Here

        buffer.writeInt(-1);
      }
      else {

        Interval interval = (Interval) val;

        buffer.writeInt(16);
        buffer.writeLong(interval.getRawTime());
        buffer.writeInt(interval.getRawDays());
        buffer.writeInt(interval.getRawMonths());
      }

    }
View Full Code Here

    }

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

      return new Interval(buffer.toString());
    }
View Full Code Here

    }

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

      Interval ival = (Interval) val;

      buffer.
        append("@ ").
        append(ival.getYears()).append(" years ").
        append(ival.getMonths()).append(" months ").
        append(ival.getDays()).append(" days ").
        append(ival.getHours()).append(" hours ").
        append(ival.getMinutes()).append(" minutes ").
        append(format("%f", ival.getSeconds())).append(" seconds");

    }
View Full Code Here

  }

  @Test
  public void testOnlineTests() throws SQLException {
    PreparedStatement pstmt = _conn.prepareStatement("INSERT INTO testinterval VALUES (?)");
    pstmt.setObject(1, new Interval(2004, 13, 28, 0, 0, 43000.9013));
    pstmt.executeUpdate();
    pstmt.close();

    Statement stmt = _conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT v FROM testinterval");
    assertTrue(rs.next());
    Interval pgi = (Interval) rs.getObject(1);
    assertEquals(2005, pgi.getYears());
    assertEquals(1, pgi.getMonths());
    assertEquals(28, pgi.getDays());
    assertEquals(11, pgi.getHours());
    assertEquals(56, pgi.getMinutes());
    assertEquals(40.9013, pgi.getSeconds(), 0.000001);
    assertTrue(!rs.next());
    rs.close();
    stmt.close();
  }
View Full Code Here

    pstmt.close();
  }

  @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

  @Test
  public void testDaysHours() throws SQLException {
    Statement stmt = _conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT '101:12:00'::interval");
    assertTrue(rs.next());
    Interval i = (Interval) rs.getObject(1);
    assertEquals(0, i.getDays());
    assertEquals(101, i.getHours());
    assertEquals(12, i.getMinutes());
  }
View Full Code Here

    assertEquals(12, i.getMinutes());
  }

  @Test
  public void testAddRounding() {
    Interval pgi = new Interval(0, 0, 0, 0, 0, 0.6006);
    Calendar cal = Calendar.getInstance();
    long origTime = cal.getTime().getTime();
    pgi.addTo(cal);
    long newTime = cal.getTime().getTime();
    assertEquals(601, newTime - origTime);
    pgi.setSeconds(-0.6006);
    pgi.addTo(cal);
    assertEquals(origTime, cal.getTime().getTime());
  }
View Full Code Here

TOP

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

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.