Java Code Examples for java.sql.Date#getTime()

The following examples show how to use java.sql.Date#getTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testForceRangeScanKeepsFilters() throws SQLException {
    ensureTableCreated(getUrl(), TestUtil.ENTITY_HISTORY_TABLE_NAME);
    String tenantId = "000000000000001";
    String keyPrefix = "002";
    String query = "select /*+ RANGE_SCAN */ ORGANIZATION_ID, PARENT_ID, CREATED_DATE, ENTITY_HISTORY_ID from " + TestUtil.ENTITY_HISTORY_TABLE_NAME + 
            " where ORGANIZATION_ID=? and SUBSTR(PARENT_ID, 1, 3) = ? and  CREATED_DATE >= ? and CREATED_DATE < ? order by ORGANIZATION_ID, PARENT_ID, CREATED_DATE, ENTITY_HISTORY_ID limit 6";
    Date startTime = new Date(System.currentTimeMillis());
    Date stopTime = new Date(startTime.getTime() + TestUtil.MILLIS_IN_DAY);
    List<Object> binds = Arrays.<Object>asList(tenantId, keyPrefix, startTime, stopTime);
    StatementContext context = compileStatement(query, binds, 6);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertTrue(filter instanceof RowKeyComparisonFilter);

    byte[] expectedStartRow = ByteUtil.concat(
        PVarchar.INSTANCE.toBytes(tenantId), StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix),15), PDate.INSTANCE.toBytes(startTime));
    assertArrayEquals(expectedStartRow, scan.getStartRow());
    byte[] expectedStopRow = ByteUtil.concat(
        PVarchar.INSTANCE.toBytes(tenantId), StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)),15), PDate.INSTANCE.toBytes(stopTime));
    assertArrayEquals(expectedStopRow, scan.getStopRow());
}
 
Example 2
Source File: ProductMetricsIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testDateSubtractionCompareDate() throws Exception {
    long ts = nextTimestamp();
    String tenantId = getOrganizationId();
    String query = "SELECT feature FROM PRODUCT_METRICS WHERE organization_id = ? and date - 1 >= ?"; 
    String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(url, props);
    try {
        Date startDate = new Date(System.currentTimeMillis());
        Date endDate = new Date(startDate.getTime() + 9 * QueryConstants.MILLIS_IN_DAY);
        initDateTableValues(tenantId, getSplits(tenantId), ts, startDate);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        statement.setDate(2, endDate);
        ResultSet rs = statement.executeQuery();
        assertTrue(rs.next());
        assertEquals("F", rs.getString(1));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example 3
Source File: ProductMetricsIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testEqualsRound() throws Exception {
    String tablename=generateUniqueName();
    String tenantId = getOrganizationId();
    String query = "SELECT feature FROM "+tablename+" WHERE organization_id = ? and trunc(\"DATE\",'DAY')=?";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        Date startDate = new Date(System.currentTimeMillis());
        Date equalDate = new Date((startDate.getTime() + 2 * QueryConstants.MILLIS_IN_DAY)/ QueryConstants.MILLIS_IN_DAY*QueryConstants.MILLIS_IN_DAY);
        initDateTableValues(tablename, tenantId, getSplits(tenantId), startDate, 1.0);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        statement.setDate(2, equalDate);
        ResultSet rs = statement.executeQuery();
        assertTrue(rs.next());
        assertEquals("C", rs.getString(1));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example 4
Source File: DateTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test19() {

    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertTrue(d.equals(d2), "Error d != d2");
}
 
Example 5
Source File: DateTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test8() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertFalse(d.before(d2), "Error d.before(d2) = true");
    assertFalse(d2.before(d), "Error d2.before(d) = true");
}
 
Example 6
Source File: DateTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test4() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertFalse(d.after(d2), "Error d.after(d2) = true");
    assertFalse(d2.after(d), "Error d2.after(d) = true");
}
 
Example 7
Source File: DateTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test4() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertFalse(d.after(d2), "Error d.after(d2) = true");
    assertFalse(d2.after(d), "Error d2.after(d) = true");
}
 
Example 8
Source File: DateTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test4() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertFalse(d.after(d2), "Error d.after(d2) = true");
    assertFalse(d2.after(d), "Error d2.after(d) = true");
}
 
Example 9
Source File: MoniterServiceImpl.java    From logistics-back with MIT License 5 votes vote down vote up
@Override
public List<GoodsBill> selectAllUnArrive() {
	List<GoodsBill> goodsBills = goodsBillDao.findAll();
	List<GoodsBill> goodsBillsUnArrive = new ArrayList<>();
	
	for(GoodsBill goodsBill:goodsBills) {
		System.out.println("goodsBill: " + goodsBill);
		CargoReceiptDetail cargoReceiptDetail = cargoReceiptDetailDao.findByGoodsBillDetailId(goodsBill.getGoodsBillCode()); //4.5
		System.out.println("cargoReceiptDetail:" + cargoReceiptDetail);
		CargoReceipt cargoReceipt = cargoReceiptDao.findByGoodsRevertBillCode(cargoReceiptDetail.getGoodsRevertBillId());  //4.6
		System.out.println(cargoReceipt);
		if (cargoReceipt == null) {
			continue;
		}
		
		Date arriveTime = cargoReceipt.getArriveTime();  //到货时间
		Date startCarryTime = cargoReceipt.getStartCarryTime();
		
		if(arriveTime != null && startCarryTime != null) {
			long difference = arriveTime.getTime() - startCarryTime.getTime();
			int day = (int) difference/(3600*24*1000);  //实际中转天数
			int cishu = (int) (goodsBill.getTransferFee()/1.3) ;//中转次数
			if(day > (cishu+1) ) {
				goodsBillsUnArrive.add(goodsBill);
			}	
		}
		
		
		
	}
	return goodsBillsUnArrive;
}
 
Example 10
Source File: DateTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test19() {

    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertTrue(d.equals(d2), "Error d != d2");
}
 
Example 11
Source File: DateColumnLocalDateMapper.java    From jadira with Apache License 2.0 5 votes vote down vote up
@Override
public LocalDate fromNonNullValue(Date value) {

    DateTime dateTime = new DateTime(value.getTime());
    LocalDate localDate = dateTime.toLocalDate();

    return localDate;
}
 
Example 12
Source File: EntityTestSuite.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
public void testFieldTypes() throws Exception {
    String id = "testFieldTypes";
    byte[] b = new byte[100000];
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) i;
    }
    Blob testBlob = new SerialBlob(b);
    String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    StringBuilder sb = new StringBuilder(alpha.length() * 1000);
    for (int i = 0; i < 1000; i++) {
        sb.append(alpha);
    }
    String clobStr = sb.toString();
    long currentMillis = System.currentTimeMillis();
    Date currentDate = Date.valueOf(new Date(currentMillis).toString());
    Time currentTime = Time.valueOf(new Time(currentMillis).toString());
    // Different databases have different precision for Timestamps, so
    // we will ignore fractional seconds.
    Timestamp currentTimestamp = new Timestamp(currentDate.getTime());
    BigDecimal fixedPoint = new BigDecimal("999999999999.999999");
    // Different databases have different precision for floating
    // point types, so we will use a simple decimal number.
    Double floatingPoint = 1.0123456789;
    Long numeric = Long.MAX_VALUE;
    try {
        GenericValue testValue = delegator.makeValue("TestFieldType", "testFieldTypeId", id);
        testValue.create();
        testValue.set("blobField", testBlob);
        testValue.set("byteArrayField", b);
        testValue.set("objectField", currentTimestamp);
        testValue.set("dateField", currentDate);
        testValue.set("timeField", currentTime);
        testValue.set("dateTimeField", currentTimestamp);
        testValue.set("fixedPointField", fixedPoint);
        testValue.set("floatingPointField", floatingPoint);
        testValue.set("numericField", numeric);
        testValue.set("clobField", clobStr);
        testValue.store();
        testValue = EntityQuery.use(delegator).from("TestFieldType").where("testFieldTypeId", id).queryOne();
        assertEquals("testFieldTypeId", id, testValue.get("testFieldTypeId"));
        Blob blob = (Blob) testValue.get("blobField");
        byte[] c = blob.getBytes(1, (int) blob.length());
        assertEquals("Byte array read from entity is the same length", b.length, c.length);
        for (int i = 0; i < b.length; i++) {
            assertEquals("Byte array data[" + i + "]", b[i], c[i]);
        }
        c = (byte[]) testValue.get("byteArrayField");
        assertEquals("Byte array read from entity is the same length", b.length, c.length);
        for (int i = 0; i < b.length; i++) {
            assertEquals("Byte array data[" + i + "]", b[i], c[i]);
        }
        assertEquals("objectField", currentTimestamp, testValue.get("objectField"));
        assertEquals("dateField", currentDate, testValue.get("dateField"));
        assertEquals("timeField", currentTime, testValue.get("timeField"));
        assertEquals("dateTimeField", currentTimestamp, testValue.get("dateTimeField"));
        assertEquals("fixedPointField", fixedPoint, testValue.get("fixedPointField"));
        assertEquals("floatingPointField", floatingPoint, testValue.get("floatingPointField"));
        assertEquals("numericField", numeric, testValue.get("numericField"));
        assertEquals("clobField", clobStr, testValue.get("clobField"));
        testValue.set("blobField", null);
        testValue.set("byteArrayField", null);
        testValue.set("objectField", null);
        testValue.set("dateField", null);
        testValue.set("timeField", null);
        testValue.set("dateTimeField", null);
        testValue.set("fixedPointField", null);
        testValue.set("floatingPointField", null);
        testValue.set("numericField", null);
        testValue.set("clobField", null);
        testValue.store();
        testValue = EntityQuery.use(delegator).from("TestFieldType").where("testFieldTypeId", id).queryOne();
        assertEquals("testFieldTypeId", id, testValue.get("testFieldTypeId"));
        assertNull("blobField null", testValue.get("blobField"));
        assertNull("byteArrayField null", testValue.get("byteArrayField"));
        assertNull("objectField null", testValue.get("objectField"));
        assertNull("dateField null", testValue.get("dateField"));
        assertNull("timeField null", testValue.get("timeField"));
        assertNull("dateTimeField null", testValue.get("dateTimeField"));
        assertNull("fixedPointField null", testValue.get("fixedPointField"));
        assertNull("floatingPointField null", testValue.get("floatingPointField"));
        assertNull("numericField null", testValue.get("numericField"));
        assertNull("clobField null", testValue.get("clobField"));
    } finally {
        // Remove all our newly inserted values.
        List<GenericValue> values = EntityQuery.use(delegator).from("TestFieldType").queryList();
        delegator.removeAll(values);
    }
}
 
Example 13
Source File: DateTests.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test10() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertTrue(d.compareTo(d2) == 0, "Error d.compareTo(d2) !=0");
}
 
Example 14
Source File: DateTests.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test3() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertFalse(d.after(d2), "Error d.after(d2) = true");
}
 
Example 15
Source File: DateTests.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test7() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertFalse(d2.before(d), "Error d2.before(d) = true");
}
 
Example 16
Source File: DateTests.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test10() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertTrue(d.compareTo(d2) == 0, "Error d.compareTo(d2) !=0");
}
 
Example 17
Source File: DateTests.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test3() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertFalse(d.after(d2), "Error d.after(d2) = true");
}
 
Example 18
Source File: ResultSetMultiTimeZoneIT.java    From snowflake-jdbc with Apache License 2.0 4 votes vote down vote up
@Test
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnGithubAction.class)
public void testGetDateAndTime() throws SQLException
{
  Connection connection = getConnection();
  Statement statement = connection.createStatement();
  statement.execute(
      "create or replace table dateTime(colA Date, colB Timestamp, colC Time)");

  java.util.Date today = new java.util.Date();
  Date date = buildDate(2016, 3, 20);
  Timestamp ts = new Timestamp(today.getTime());
  Time tm = new Time(12345678); // 03:25:45.678
  final String insertTime = "insert into datetime values(?, ?, ?)";
  PreparedStatement prepStatement = connection.prepareStatement(insertTime);
  prepStatement.setDate(1, date);
  prepStatement.setTimestamp(2, ts);
  prepStatement.setTime(3, tm);

  prepStatement.execute();

  TimeZone gmt = TimeZone.getTimeZone("GMT");
  Calendar cal = Calendar.getInstance(gmt);
  Date dateTZ = buildDateWithTZ(2016, 3, 20, gmt);
  ResultSet resultSet = statement.executeQuery("select * from datetime");
  resultSet.next();
  assertEquals(date, resultSet.getDate(1));
  assertEquals(date, resultSet.getDate("COLA"));

  // Note: Currently calendar does not affect getDate result
  assertEquals(resultSet.getDate(1), resultSet.getDate(1, cal));
  assertEquals(resultSet.getDate("COLA"), resultSet.getDate("COLA", cal));

  assertEquals(ts, resultSet.getTimestamp(2));
  assertEquals(ts, resultSet.getTimestamp("COLB"));
  assertEquals(tm, resultSet.getTime(3));
  assertEquals(tm, resultSet.getTime("COLC"));

  statement.execute("create or replace table datetime(colA timestamp_ltz, colB timestamp_ntz, colC timestamp_tz)");
  statement.execute("insert into dateTime values ('2019-01-01 17:17:17', '2019-01-01 17:17:17', '2019-01-01 " +
                    "17:17:17')");
  prepStatement =
      connection.prepareStatement("insert into datetime values(?, '2019-01-01 17:17:17', '2019-01-01 17:17:17')");
  Timestamp dateTime = new Timestamp(date.getTime());
  prepStatement.setTimestamp(1, dateTime);
  prepStatement.execute();
  resultSet = statement.executeQuery("select * from datetime");
  resultSet.next();
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  formatter.setTimeZone(TimeZone.getDefault());
  String d = formatter.format(resultSet.getDate("COLA"));
  assertEquals("2019-01-02 01:17:17", d);
  resultSet.next();
  assertEquals(date, resultSet.getDate(1));
  assertEquals(date, resultSet.getDate("COLA"));
  statement.execute("drop table if exists datetime");
  connection.close();
}
 
Example 19
Source File: DateTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test3() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertFalse(d.after(d2), "Error d.after(d2) = true");
}
 
Example 20
Source File: DateTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test3() {
    Date d = Date.valueOf("1961-08-30");
    Date d2 = new Date(d.getTime());
    assertFalse(d.after(d2), "Error d.after(d2) = true");
}