Example usage for java.sql Time Time

List of usage examples for java.sql Time Time

Introduction

In this page you can find the example usage for java.sql Time Time.

Prototype

@Deprecated(since = "1.2")
public Time(int hour, int minute, int second) 

Source Link

Document

Constructs a Time object initialized with the given values for the hour, minute, and second.

Usage

From source file:com.github.nmorel.gwtjackson.shared.options.DateOptionsTester.java

public void testDeserializeDatesAsTimestamps(ObjectReaderTester<BeanWithDates> reader) {

    String input = "{" + "\"date\":1345304756540," + "\"onlyDate\":1345304756540,"
            + "\"onlyDateTz\":1345304756540," + "\"sqlDate\":\"2012-08-18\"," + "\"sqlTime\":\"15:45:56\","
            + "\"sqlTimestamp\":1345304756543," + "\"mapDate\":{\"1345304756544\":\"java.util.Date\"}" + "}";

    BeanWithDates bean = reader.read(input);
    assertEquals(new Date(1345304756540l), bean.date);
    assertEquals(new Date(1345304756540l), bean.onlyDate);
    assertEquals(new Date(1345304756540l), bean.onlyDateTz);
    assertEquals(getUTCTime(2012, 8, 18, 0, 0, 0, 0), bean.sqlDate.getTime());
    assertEquals(new Time(15, 45, 56), bean.sqlTime);
    assertEquals(new java.sql.Timestamp(1345304756543l), bean.sqlTimestamp);

    Map<Date, String> mapDate = new HashMap<Date, String>();
    mapDate.put(new Date(1345304756544l), "java.util.Date");
    assertEquals(mapDate, bean.mapDate);

    // Jackson is not able to deserialize java.sql.* types as string so we don't bother testing it
}

From source file:com.github.nmorel.gwtjackson.shared.options.DateOptionsTester.java

@SuppressWarnings("deprecation")
public void testDeserializeDatesNotAsTimestamps(ObjectReaderTester<BeanWithDates> reader) {
    String input = "{" + "\"date\":\"2012-08-18T15:45:56.540+0000\"," + "\"onlyDate\":\"/2012/08/18/\","
            + "\"onlyDateTz\":\"/2012/08/18/ +0000\"," + "\"sqlDate\":\"2012-08-18\","
            + "\"sqlTime\":\"15:45:56\"," + "\"sqlTimestamp\":\"2012-08-18T15:45:56.543+0000\","
            + "\"mapDate\":{\"2012-08-18T15:45:56.544+0000\":\"java.util.Date\"}" + "}";

    BeanWithDates bean = reader.read(input);
    assertEquals(new Date(1345304756540l), bean.date);
    Date utcDate = getUTCDate(2012, 8, 18, 0, 0, 0, 0);
    assertEquals(utcDate, bean.onlyDate);
    assertEquals(utcDate, bean.onlyDateTz);
    assertEquals(utcDate, bean.sqlDate);
    assertEquals(new Time(15, 45, 56), bean.sqlTime);
    assertEquals(new java.sql.Timestamp(1345304756543l), bean.sqlTimestamp);

    Map<Date, String> mapDate = new HashMap<Date, String>();
    mapDate.put(new Date(1345304756544l), "java.util.Date");
    assertEquals(mapDate, bean.mapDate);

    // Jackson is not able to deserialize java.sql.* types as string so we don't bother testing it
}

From source file:com.github.nmorel.gwtjackson.shared.options.DateOptionsTester.java

@SuppressWarnings("deprecation")
public void testDeserializeDatesNotAsTimestampsAndUseBrowserTimezone(ObjectReaderTester<BeanWithDates> reader) {
    String input = "{" + "\"date\":\"2012-08-18T15:45:56.540+0000\"," + "\"onlyDate\":\"/2012/08/18/\","
            + "\"onlyDateTz\":\"/2012/08/18/ +0000\"," + "\"sqlDate\":\"2012-08-18\","
            + "\"sqlTime\":\"15:45:56\"," + "\"sqlTimestamp\":\"2012-08-18T15:45:56.543+0000\","
            + "\"mapDate\":{\"2012-08-18T15:45:56.544+0000\":\"java.util.Date\"}" + "}";

    BeanWithDates bean = reader.read(input);
    assertEquals(new Date(1345304756540l), bean.date);
    Date utc = getUTCDate(2012, 8, 18, 0, 0, 0, 0);
    Date currentTz = new Date(112, 7, 18);
    assertEquals(currentTz, bean.onlyDate);
    assertEquals(utc, bean.onlyDateTz);// ww  w.  j av  a2s  . c o  m
    assertEquals(currentTz, bean.sqlDate);
    assertEquals(new Time(15, 45, 56), bean.sqlTime);
    assertEquals(new java.sql.Timestamp(1345304756543l), bean.sqlTimestamp);

    Map<Date, String> mapDate = new HashMap<Date, String>();
    mapDate.put(new Date(1345304756544l), "java.util.Date");
    assertEquals(mapDate, bean.mapDate);

    // Jackson is not able to deserialize java.sql.* types as string so we don't bother testing it
}

From source file:org.apache.sqoop.hcat.HCatalogExportTest.java

public void testDateTypes() throws Exception {
    final int TOTAL_RECORDS = 1 * 10;
    String table = getTableName().toUpperCase();
    ColumnGenerator[] cols = new ColumnGenerator[] {
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0), "date", Types.DATE,
                    HCatFieldSchema.Type.STRING, 0, 0, "2013-12-31", new Date(113, 11, 31), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1), "date", Types.DATE,
                    HCatFieldSchema.Type.DATE, 0, 0, new Date(113, 11, 31), new Date(113, 11, 31),
                    KeyType.NOT_A_KEY),//from   w w  w  . j  av a2  s  .c  o m
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2), "time", Types.TIME,
                    HCatFieldSchema.Type.STRING, 0, 0, "10:11:12", new Time(10, 11, 12), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(3), "timestamp", Types.TIMESTAMP,
                    HCatFieldSchema.Type.STRING, 0, 0, "2013-12-31 10:11:12",
                    new Timestamp(113, 11, 31, 10, 11, 12, 0), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(4), "timestamp", Types.TIMESTAMP,
                    HCatFieldSchema.Type.TIMESTAMP, 0, 0, new Timestamp(113, 11, 31, 10, 11, 12, 0),
                    new Timestamp(113, 11, 31, 10, 11, 12, 0), KeyType.NOT_A_KEY), };
    List<String> addlArgsArray = new ArrayList<String>();
    runHCatExport(addlArgsArray, TOTAL_RECORDS, table, cols);
}

From source file:org.apache.sqoop.hcat.HCatalogExportTest.java

public void testDateTypesToBigInt() throws Exception {
    final int TOTAL_RECORDS = 1 * 10;
    long offset = TimeZone.getDefault().getRawOffset();
    String table = getTableName().toUpperCase();
    ColumnGenerator[] cols = new ColumnGenerator[] {
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0), "date", Types.DATE,
                    HCatFieldSchema.Type.BIGINT, 0, 0, 0 - offset, new Date(70, 0, 1), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1), "time", Types.TIME,
                    HCatFieldSchema.Type.BIGINT, 0, 0, 36672000L - offset, new Time(10, 11, 12),
                    KeyType.NOT_A_KEY),/* w ww  . j  a v a2  s .c  o  m*/
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2), "timestamp", Types.TIMESTAMP,
                    HCatFieldSchema.Type.BIGINT, 0, 0, 36672000L - offset,
                    new Timestamp(70, 0, 1, 10, 11, 12, 0), KeyType.NOT_A_KEY), };
    List<String> addlArgsArray = new ArrayList<String>();
    addlArgsArray.add("--map-column-hive");
    addlArgsArray.add("COL0=bigint,COL1=bigint,COL2=bigint");
    runHCatExport(addlArgsArray, TOTAL_RECORDS, table, cols);
}

From source file:it.cyberdyne.dss.beans.PlaceTableBean.java

public void addPlace() {
    Time topen = new Time(8, 0, 0);
    Time tclose = new Time(18, 0, 0);
    placeList.add(new Place("None", 0.0, 0.0, 0, topen, tclose, "nowhere", loginBean.getLoggedId()));
}

From source file:it.cyberdyne.dss.beans.PlaceTableBean.java

public void addPlace(List<String> row) {
    String label = row.get(0);//w w w  .  jav a  2  s  .c o  m
    Double demandA = Double.parseDouble(row.get(1).replaceAll(",", "."));
    Double demandB = Double.parseDouble(row.get(2).replaceAll(",", "."));
    Integer serviceTime = Integer.parseInt(row.get(3));
    String[] tOpenH = row.get(4).split(":");
    String[] tCloseH = row.get(5).split(":");
    String place = row.get(6);
    Time tOpen = new Time(Integer.parseInt(tOpenH[0]), Integer.parseInt(tOpenH[1]), 0);
    Time tClose = new Time(Integer.parseInt(tCloseH[0]), Integer.parseInt(tCloseH[1]), 0);
    placeList.add(
            new Place(label, demandA, demandB, serviceTime, tOpen, tClose, place, loginBean.getLoggedId()));
}

From source file:com.google.visualization.datasource.util.SqlDataSourceHelperTest.java

/**
 * Tests the method buildDataTableRows./*from   w  ww  .  j  av a2s.c o  m*/
 *
 * @throws SQLException Thrown when the connection to the database failed.
 */
public void testBuildDataTableRows() throws SQLException {
    // Build Timestamp, Date ant Time objects for the date February 8, 2008
    // 09:01:10. Set their values in the table.
    GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    gc.set(2008, 1, 8, 9, 1, 10);
    // Set the milliseconds explicitly, otherwise the milliseconds from the
    // time the gc was initialized are used.
    gc.set(GregorianCalendar.MILLISECOND, 0);

    Date date = new Date(gc.getTimeInMillis());
    Time time = new Time(gc.get(GregorianCalendar.HOUR), gc.get(GregorianCalendar.MINUTE),
            gc.get(GregorianCalendar.SECOND));
    Timestamp timestamp = new Timestamp(gc.get(GregorianCalendar.YEAR) - 1900, gc.get(GregorianCalendar.MONTH),
            gc.get(GregorianCalendar.DAY_OF_MONTH), gc.get(GregorianCalendar.HOUR),
            gc.get(GregorianCalendar.MINUTE), gc.get(GregorianCalendar.SECOND), 0);

    // Create the table rows.
    List<Object> row1 = Lists.<Object>newArrayList(100, "Yaron", null, 'M', 1000, false, date, timestamp, time);
    List<Object> row2 = Lists.<Object>newArrayList(200, "Moran", "Bar", 'F', 2000, null, null, null, null);
    List<Object> row3 = Lists.<Object>newArrayList(300, "Shir", "Gal", 'F', null, true, null, null, null);
    rows.add(row1);
    rows.add(row2);
    rows.add(row3);

    // Get the mock result set for the table.
    ResultSet rs = new MockResultSet(rows, NUM_OF_COLS, labels, types);

    List<String> columnIdsList = Lists.newArrayList("id", "fname", "lname", "gender", "salary", "ismarried",
            "startdate", "timestamp", "time");

    // Get the table description using the mock result set.
    DataTable dataTable = SqlDataSourceHelper.buildColumns(rs, columnIdsList);
    assertNotNull(dataTable);

    // Make sure the number of columns in the table description is correct.
    assertEquals(NUM_OF_COLS, dataTable.getNumberOfColumns());

    // Get the columns description list.
    List<ColumnDescription> columnsDescriptionList = dataTable.getColumnDescriptions();

    // Make sure the type of each column is correct.
    assertEquals(ValueType.NUMBER, columnsDescriptionList.get(0).getType());
    assertEquals(ValueType.TEXT, columnsDescriptionList.get(1).getType());
    assertEquals(ValueType.TEXT, columnsDescriptionList.get(2).getType());
    assertEquals(ValueType.TEXT, columnsDescriptionList.get(3).getType());
    assertEquals(ValueType.NUMBER, columnsDescriptionList.get(4).getType());
    assertEquals(ValueType.BOOLEAN, columnsDescriptionList.get(5).getType());
    assertEquals(ValueType.DATE, columnsDescriptionList.get(6).getType());
    assertEquals(ValueType.DATETIME, columnsDescriptionList.get(7).getType());
    assertEquals(ValueType.TIMEOFDAY, columnsDescriptionList.get(8).getType());

    // Make sure the label of each column is correct.
    assertEquals("ID", columnsDescriptionList.get(0).getLabel());
    assertEquals("Fname", columnsDescriptionList.get(1).getLabel());
    assertEquals("Lname", columnsDescriptionList.get(2).getLabel());
    assertEquals("Gender", columnsDescriptionList.get(3).getLabel());
    assertEquals("Salary", columnsDescriptionList.get(4).getLabel());
    assertEquals("IsMarried", columnsDescriptionList.get(5).getLabel());
    assertEquals("StartDate", columnsDescriptionList.get(6).getLabel());
    assertEquals("TimeStamp", columnsDescriptionList.get(7).getLabel());
    assertEquals("Time", columnsDescriptionList.get(8).getLabel());

    // Build the table rows.
    SqlDataSourceHelper.buildRows(dataTable, rs);

    assertNotNull(dataTable);

    // Make sure the number of rows int the table is correct.
    assertEquals(3, dataTable.getNumberOfRows());

    // Make sure the type of the data table cells is correct.
    for (int i = 0; i < dataTable.getNumberOfRows(); i++) {
        assertEquals(ValueType.NUMBER, dataTable.getRow(i).getCell(0).getValue().getType());
        assertEquals(ValueType.TEXT, dataTable.getRow(i).getCell(1).getValue().getType());
        assertEquals(ValueType.TEXT, dataTable.getRow(i).getCell(2).getValue().getType());
        assertEquals(ValueType.TEXT, dataTable.getRow(i).getCell(3).getValue().getType());
        assertEquals(ValueType.NUMBER, dataTable.getRow(i).getCell(4).getValue().getType());
        assertEquals(ValueType.BOOLEAN, dataTable.getRow(i).getCell(5).getValue().getType());
        assertEquals(ValueType.DATE, dataTable.getRow(i).getCell(6).getValue().getType());
        assertEquals(ValueType.DATETIME, dataTable.getRow(i).getCell(7).getValue().getType());
        assertEquals(ValueType.TIMEOFDAY, dataTable.getRow(i).getCell(8).getValue().getType());
    }

    // Make sure the value of the data table cells is correct. For cells with
    // null value, check that the value equals to the null value format of the
    // specific type value.
    assertEquals(new NumberValue(100.0), dataTable.getRow(0).getCell(0).getValue());
    assertEquals("Yaron", dataTable.getRow(0).getCell(1).getValue().toString());
    assertEquals(new TextValue(""), dataTable.getRow(0).getCell(2).getValue());
    assertEquals("Bar", dataTable.getRow(1).getCell(2).getValue().toString());
    assertEquals("F", dataTable.getRow(1).getCell(3).getValue().toString());
    assertEquals(BooleanValue.getNullValue(), dataTable.getRow(1).getCell(5).getValue());
    assertEquals(NumberValue.getNullValue(), dataTable.getRow(2).getCell(4).getValue());
    assertEquals("true", dataTable.getRow(2).getCell(5).getValue().toString());
    assertEquals(dataTable.getRow(0).getCell(6).getValue().toString(), new DateValue(gc),
            dataTable.getRow(0).getCell(6).getValue());
    assertEquals(new DateTimeValue(gc), dataTable.getRow(0).getCell(7).getValue());
    assertEquals(new TimeOfDayValue(gc), dataTable.getRow(0).getCell(8).getValue());
    assertEquals(DateValue.getNullValue(), dataTable.getRow(1).getCell(6).getValue());
    assertEquals(DateTimeValue.getNullValue(), dataTable.getRow(2).getCell(7).getValue());
    assertEquals(TimeOfDayValue.getNullValue(), dataTable.getRow(2).getCell(8).getValue());
}

From source file:org.apache.sqoop.hcat.HCatalogImportTest.java

public void testDateTypes() throws Exception {
    final int TOTAL_RECORDS = 1 * 10;
    String table = getTableName().toUpperCase();
    ColumnGenerator[] cols = new ColumnGenerator[] {
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0), "date", Types.DATE,
                    HCatFieldSchema.Type.STRING, 0, 0, "2013-12-31", new Date(113, 11, 31), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1), "date", Types.DATE,
                    HCatFieldSchema.Type.DATE, 0, 0, new Date(113, 11, 31), new Date(113, 11, 31),
                    KeyType.NOT_A_KEY),/*w w  w .  ja  v a 2  s. c  o  m*/
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2), "time", Types.TIME,
                    HCatFieldSchema.Type.STRING, 0, 0, "10:11:12", new Time(10, 11, 12), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(3), "timestamp", Types.TIMESTAMP,
                    HCatFieldSchema.Type.STRING, 0, 0, "2013-12-31 10:11:12.0",
                    new Timestamp(113, 11, 31, 10, 11, 12, 0), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(4), "timestamp", Types.TIMESTAMP,
                    HCatFieldSchema.Type.TIMESTAMP, 0, 0, new Timestamp(113, 11, 31, 10, 11, 12, 0),
                    new Timestamp(113, 11, 31, 10, 11, 12, 0), KeyType.NOT_A_KEY), };
    List<String> addlArgsArray = new ArrayList<String>();
    setExtraArgs(addlArgsArray);
    runHCatImport(addlArgsArray, TOTAL_RECORDS, table, cols, null);
}

From source file:org.apache.sqoop.hcat.HCatalogImportTest.java

public void testDateTypesToBigInt() throws Exception {
    final int TOTAL_RECORDS = 1 * 10;
    long offset = TimeZone.getDefault().getRawOffset();
    String table = getTableName().toUpperCase();
    ColumnGenerator[] cols = new ColumnGenerator[] {
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0), "date", Types.DATE,
                    HCatFieldSchema.Type.BIGINT, 0, 0, 0 - offset, new Date(70, 0, 1), KeyType.NOT_A_KEY),
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1), "time", Types.TIME,
                    HCatFieldSchema.Type.BIGINT, 0, 0, 36672000L - offset, new Time(10, 11, 12),
                    KeyType.NOT_A_KEY),/*from   w ww.  j  ava  2s. c  o  m*/
            HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2), "timestamp", Types.TIMESTAMP,
                    HCatFieldSchema.Type.BIGINT, 0, 0, 36672000L - offset,
                    new Timestamp(70, 0, 1, 10, 11, 12, 0), KeyType.NOT_A_KEY), };
    List<String> addlArgsArray = new ArrayList<String>();
    addlArgsArray.add("--map-column-hive");
    addlArgsArray.add("COL0=bigint,COL1=bigint,COL2=bigint");
    setExtraArgs(addlArgsArray);
    runHCatImport(addlArgsArray, TOTAL_RECORDS, table, cols, null);
}