Пример #1
0
    /** {@inheritDoc} */
    @SuppressWarnings({"BigDecimalEquals", "EqualsHashCodeCalledOnUrl", "RedundantIfStatement"})
    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;

      TestObject that = (TestObject) o;

      if (id != that.id) return false;
      if (!Arrays.equals(arrVal, that.arrVal)) return false;
      if (bigVal != null ? !bigVal.equals(that.bigVal) : that.bigVal != null) return false;
      if (boolVal != null ? !boolVal.equals(that.boolVal) : that.boolVal != null) return false;
      if (byteVal != null ? !byteVal.equals(that.byteVal) : that.byteVal != null) return false;
      if (dateVal != null ? !dateVal.equals(that.dateVal) : that.dateVal != null) return false;
      if (doubleVal != null ? !doubleVal.equals(that.doubleVal) : that.doubleVal != null)
        return false;
      if (f1 != null ? !f1.equals(that.f1) : that.f1 != null) return false;
      if (f2 != null ? !f2.equals(that.f2) : that.f2 != null) return false;
      if (f3 != null ? !f3.equals(that.f3) : that.f3 != null) return false;
      if (floatVal != null ? !floatVal.equals(that.floatVal) : that.floatVal != null) return false;
      if (intVal != null ? !intVal.equals(that.intVal) : that.intVal != null) return false;
      if (longVal != null ? !longVal.equals(that.longVal) : that.longVal != null) return false;
      if (shortVal != null ? !shortVal.equals(that.shortVal) : that.shortVal != null) return false;
      if (strVal != null ? !strVal.equals(that.strVal) : that.strVal != null) return false;
      if (timeVal != null ? !timeVal.equals(that.timeVal) : that.timeVal != null) return false;
      if (tsVal != null ? !tsVal.equals(that.tsVal) : that.tsVal != null) return false;
      if (urlVal != null ? !urlVal.equals(that.urlVal) : that.urlVal != null) return false;

      return true;
    }
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   Voto other = (Voto) obj;
   if (data == null) {
     if (other.data != null) return false;
   } else if (!data.equals(other.data)) return false;
   if (filme == null) {
     if (other.filme != null) return false;
   } else if (!filme.equals(other.filme)) return false;
   if (hora == null) {
     if (other.hora != null) return false;
   } else if (!hora.equals(other.hora)) return false;
   if (id == null) {
     if (other.id != null) return false;
   } else if (!id.equals(other.id)) return false;
   if (usuario == null) {
     if (other.usuario != null) return false;
   } else if (!usuario.equals(other.usuario)) return false;
   return true;
 }
Пример #3
0
  private void testDatetime() throws SQLException {
    trace("Test DATETIME");
    ResultSet rs;
    Object o;

    rs = stat.executeQuery("call date '99999-12-23'");
    rs.next();
    assertEquals("99999-12-23", rs.getString(1));
    rs = stat.executeQuery("call timestamp '99999-12-23 01:02:03.000'");
    rs.next();
    assertEquals("99999-12-23 01:02:03.0", rs.getString(1));
    rs = stat.executeQuery("call date '-99999-12-23'");
    rs.next();
    assertEquals("-99999-12-23", rs.getString(1));
    rs = stat.executeQuery("call timestamp '-99999-12-23 01:02:03.000'");
    rs.next();
    assertEquals("-99999-12-23 01:02:03.0", rs.getString(1));

    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE DATETIME)");
    stat.execute("INSERT INTO TEST VALUES(1,DATE '2011-11-11')");
    stat.execute("INSERT INTO TEST VALUES(2,TIMESTAMP '2002-02-02 02:02:02')");
    stat.execute("INSERT INTO TEST VALUES(3,TIMESTAMP '1800-1-1 0:0:0')");
    stat.execute("INSERT INTO TEST VALUES(4,TIMESTAMP '9999-12-31 23:59:59')");
    stat.execute("INSERT INTO TEST VALUES(5,NULL)");
    rs =
        stat.executeQuery(
            "SELECT 0 ID, " + "TIMESTAMP '9999-12-31 23:59:59' VALUE FROM TEST ORDER BY ID");
    assertResultSetMeta(
        rs,
        2,
        new String[] {"ID", "VALUE"},
        new int[] {Types.INTEGER, Types.TIMESTAMP},
        new int[] {10, 23},
        new int[] {0, 10});
    rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
    assertResultSetMeta(
        rs,
        2,
        new String[] {"ID", "VALUE"},
        new int[] {Types.INTEGER, Types.TIMESTAMP},
        new int[] {10, 23},
        new int[] {0, 10});
    rs.next();
    java.sql.Date date;
    java.sql.Time time;
    java.sql.Timestamp ts;
    date = rs.getDate(2);
    assertTrue(!rs.wasNull());
    time = rs.getTime(2);
    assertTrue(!rs.wasNull());
    ts = rs.getTimestamp(2);
    assertTrue(!rs.wasNull());
    trace("Date: " + date.toString() + " Time:" + time.toString() + " Timestamp:" + ts.toString());
    trace(
        "Date ms: "
            + date.getTime()
            + " Time ms:"
            + time.getTime()
            + " Timestamp ms:"
            + ts.getTime());
    trace("1970 ms: " + java.sql.Timestamp.valueOf("1970-01-01 00:00:00.0").getTime());
    assertEquals(java.sql.Timestamp.valueOf("2011-11-11 00:00:00.0").getTime(), date.getTime());
    assertEquals(java.sql.Timestamp.valueOf("1970-01-01 00:00:00.0").getTime(), time.getTime());
    assertEquals(java.sql.Timestamp.valueOf("2011-11-11 00:00:00.0").getTime(), ts.getTime());
    assertTrue(date.equals(java.sql.Date.valueOf("2011-11-11")));
    assertTrue(time.equals(java.sql.Time.valueOf("00:00:00")));
    assertTrue(ts.equals(java.sql.Timestamp.valueOf("2011-11-11 00:00:00.0")));
    assertFalse(rs.wasNull());
    o = rs.getObject(2);
    trace(o.getClass().getName());
    assertTrue(o instanceof java.sql.Timestamp);
    assertTrue(
        ((java.sql.Timestamp) o).equals(java.sql.Timestamp.valueOf("2011-11-11 00:00:00.0")));
    assertFalse(rs.wasNull());
    rs.next();

    date = rs.getDate("VALUE");
    assertTrue(!rs.wasNull());
    time = rs.getTime("VALUE");
    assertTrue(!rs.wasNull());
    ts = rs.getTimestamp("VALUE");
    assertTrue(!rs.wasNull());
    trace("Date: " + date.toString() + " Time:" + time.toString() + " Timestamp:" + ts.toString());
    assertEquals("2002-02-02", date.toString());
    assertEquals("02:02:02", time.toString());
    assertEquals("2002-02-02 02:02:02.0", ts.toString());
    rs.next();
    assertEquals("1800-01-01", rs.getDate("value").toString());
    assertEquals("00:00:00", rs.getTime("value").toString());
    assertEquals("1800-01-01 00:00:00.0", rs.getTimestamp("value").toString());
    rs.next();
    assertEquals("9999-12-31", rs.getDate("Value").toString());
    assertEquals("23:59:59", rs.getTime("Value").toString());
    assertEquals("9999-12-31 23:59:59.0", rs.getTimestamp("Value").toString());
    rs.next();
    assertTrue(rs.getDate("Value") == null && rs.wasNull());
    assertTrue(rs.getTime("vALUe") == null && rs.wasNull());
    assertTrue(rs.getTimestamp(2) == null && rs.wasNull());
    assertTrue(!rs.next());

    rs =
        stat.executeQuery(
            "SELECT DATE '2001-02-03' D, "
                + "TIME '14:15:16', "
                + "TIMESTAMP '2007-08-09 10:11:12.141516171' TS FROM TEST");
    rs.next();
    date = (Date) rs.getObject(1);
    time = (Time) rs.getObject(2);
    ts = (Timestamp) rs.getObject(3);
    assertEquals("2001-02-03", date.toString());
    assertEquals("14:15:16", time.toString());
    assertEquals("2007-08-09 10:11:12.141516171", ts.toString());

    stat.execute("DROP TABLE TEST");
  }