Example usage for java.sql Timestamp valueOf

List of usage examples for java.sql Timestamp valueOf

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) 

Source Link

Document

Obtains an instance of Timestamp from a LocalDateTime object, with the same year, month, day of month, hours, minutes, seconds and nanos date-time value as the provided LocalDateTime .

Usage

From source file:org.openmrs.module.mirebalaisreports.library.EncounterDataLibraryTest.java

@Test
public void testVisitStopDatetime() throws Exception {
    context.setBaseEncounters(encounterIdSet);
    EncounterDataDefinition definition = library.getVisitStopDatetime();
    EvaluatedEncounterData data = encounterDataService.evaluate(definition, context);
    assertThat((Timestamp) data.getData().get(e1.getId()), is(Timestamp.valueOf("2013-10-14 04:30:00")));
    assertThat((Timestamp) data.getData().get(e2.getId()), is(Timestamp.valueOf("2013-10-14 04:30:00")));
    assertThat((Timestamp) data.getData().get(e3.getId()), is(Timestamp.valueOf("2013-10-14 04:30:00")));
}

From source file:com.gigaspaces.persistency.metadata.DefaultSpaceDocumentMapper.java

private Object fromSpecialType(DBObject value) {
    String type = (String) value.get(Constants.TYPE);
    String val = (String) value.get(Constants.VALUE);

    if (BigInteger.class.getName().equals(type))
        return new BigInteger(val);
    else if (BigDecimal.class.getName().equals(type))
        return new BigDecimal(val);
    else if (Byte.class.getName().equals(type))
        return Byte.valueOf(val);
    else if (Float.class.getName().equals(type))
        return Float.valueOf(val);
    else if (Character.class.getName().equals(type))
        return toCharacter(val);
    else if (Class.class.getName().equals(type))
        return toClass(val);
    else if (Locale.class.getName().equals(type))
        return toLocale(val);
    else if (URI.class.getName().equals(type))
        return URI.create(val);
    else if (Timestamp.class.getName().equals(type))
        return Timestamp.valueOf(val);

    throw new IllegalArgumentException("unkown value: " + value);
}

From source file:com.hp.rest.GenericResource.java

@POST
@Path("/putImage")
@Consumes(MediaType.APPLICATION_JSON)/* w ww .j av  a2  s.  com*/
public Response putImage(String pData) {

    // pair to object
    ObjectMapper mapper = new ObjectMapper();
    DataInfo data = new DataInfo();
    try {
        //         File jsonFile = new File(jsonFilePath);
        data = mapper.readValue(pData, DataInfo.class);
        //System.out.println(track.getMMaKhachHang());
    } catch (JsonGenerationException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    Date today = new Date();

    String name = data.getNhanVien() + "-" + df.format(today) + "-" + today.getHours() + "-"
            + today.getMinutes() + "-" + today.getSeconds() + ".jpg";

    String path = ServletActionContext.getServletContext().getRealPath("/db_customers/");

    //Create new folder
    File file = new File(path + "/" + data.getKhachHang());
    if (!file.exists()) {
        if (file.mkdir()) {
            System.out.println("Directory is created!");
        } else {
            System.out.println("Failed to create directory!");
        }
    }

    System.out.println(path + "/" + data.getKhachHang() + "/" + name);
    //Save
    saveImage(data.getNoiDung(), (path + "/" + data.getKhachHang() + "/" + name));

    //Save in database
    CustomerImageDAO customerImageDAO = new CustomerImageDAOImpl();
    CustomerImage customerImage = new CustomerImage();
    customerImage.setId(name);
    customerImage.setName(name);
    customerImage.setCustomerID(data.getKhachHang());
    customerImage.setStaffID(data.getNhanVien());
    customerImage.setTime(Timestamp.valueOf(df2.format(today)));
    customerImage.setStatus(false);

    boolean status = customerImageDAO.saveOrUpdate(customerImage);

    //save track staff 
    StaffHistoryDAO staffHistoryDAO = new StaffHistoryDAOImpl();
    StaffHistory staffHistory = new StaffHistory();
    staffHistory = staffHistoryDAO.getStaffHistory(data.getKhachHang(), df.format(today));

    if (staffHistory == null) {
        byte[] b = data.getTenKhachHang().getBytes(Charset.forName("UTF-8"));
        String str = new String(b);

        System.out.println(data.getTenKhachHang() + "\n" + str);
        staffHistory = new StaffHistory();
        staffHistory.setStaff(data.getNhanVien());
        staffHistory.setCustomer(data.getKhachHang());
        staffHistory.setCustomerName(str);
        staffHistory.setStartTime(Timestamp.valueOf(df2.format(today)));
        //staffHistory.setNote();

        staffHistoryDAO.saveOrUpdate(staffHistory);
    }

    //            String output = pTrack.toString();
    System.out.println(status + " ____ " + data.getNhanVien() + "___ " + data.getKhachHang());
    return Response.status(200).entity("______ Success").build();
}

From source file:net.tradelib.misc.StrategyText.java

public static void buildOrdersCsv(String dbUrl, String strategy, LocalDate date, String csvPath)
        throws Exception {
    Connection con = DriverManager.getConnection(dbUrl);

    CSVPrinter printer = null;//from w ww. java 2 s  . c  om
    if (csvPath != null) {
        // Add withHeader for headers
        printer = CSVFormat.DEFAULT.withDelimiter(',').withHeader(CSV_HEADER)
                .print(new BufferedWriter(new FileWriter(csvPath)));
    }

    int rollMethod = 2;

    DatabaseMetaData dmd = con.getMetaData();
    String driverName = dmd.getDriverName();
    String query = "";
    if (driverName.startsWith("MySQL")) {
        query = STRATEGY_ORDER_QUERY_MYSQL;
    } else {
        query = STRATEGY_ORDER_QUERY;
    }

    PreparedStatement pstmt = con.prepareStatement(query);
    pstmt.setString(1, strategy);
    pstmt.setTimestamp(2, Timestamp.valueOf(date.atStartOfDay()));
    ResultSet rs = pstmt.executeQuery();
    while (rs.next()) {
        JsonObject jo = new Gson().fromJson(rs.getString(9), JsonObject.class);
        JsonArray ja = jo.get("orders").getAsJsonArray();

        int ndays = rs.getInt(12);
        String contract = "";
        if (rollMethod == 1) {
            if (ndays > 1) {
                contract = rs.getString(10);
            } else {
                contract = rs.getString(11);
            }
        } else if (rollMethod == 2) {
            contract = rs.getString(15);
        }

        for (int ii = 0; ii < ja.size(); ++ii) {
            JsonObject jorder = ja.get(ii).getAsJsonObject();

            switch (jorder.get("type").getAsString()) {
            case "EXIT_LONG_STOP":
                // Action
                printer.print("SELL");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("STP");
                // LmtPrice
                printer.print("");
                // AuxPrice
                printer.print(formatOrderPrice(jorder.get("stop_price").getAsBigDecimal()));
                printer.println();
                break;

            case "EXIT_SHORT_STOP":
                // Action
                printer.print("BUY");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("STP");
                // LmtPrice
                printer.print("");
                // AuxPrice
                printer.print(formatOrderPrice(jorder.get("stop_price").getAsBigDecimal()));
                printer.println();
                break;

            case "ENTER_LONG":
                // Action
                printer.print("BUY");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("MKT");
                // LmtPrice
                printer.print("");
                // AuxPrice
                printer.print("");
                printer.println();
                break;

            case "ENTER_SHORT":
                // Action
                printer.print("SELL");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("MKT");
                // LmtPrice
                printer.print("");
                // AuxPrice
                printer.print("");
                printer.println();
                break;

            case "ENTER_LONG_STOP":
                // Action
                printer.print("BUY");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("STP");
                // LmtPrice
                printer.print("");
                // AuxPrice
                printer.print(formatOrderPrice(jorder.get("stop_price").getAsBigDecimal()));
                printer.println();
                break;

            case "ENTER_LONG_STOP_LIMIT":
                // Action
                printer.print("BUY");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("STP LMT");
                // LmtPrice
                printer.print(formatOrderPrice(jorder.get("limit_price").getAsBigDecimal()));
                // AuxPrice
                printer.print(formatOrderPrice(jorder.get("stop_price").getAsBigDecimal()));
                printer.println();
                break;

            case "ENTER_SHORT_STOP":
                // Action
                printer.print("SELL");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("STP");
                // LmtPrice
                printer.print("");
                // AuxPrice
                printer.print(formatOrderPrice(jorder.get("stop_price").getAsBigDecimal()));
                printer.println();
                break;

            case "ENTER_SHORT_STOP_LIMIT":
                // Action
                printer.print("SELL");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("STP LMT");
                // LmtPrice
                printer.print(formatOrderPrice(jorder.get("limit_price").getAsBigDecimal()));
                // AuxPrice
                printer.print(formatOrderPrice(jorder.get("stop_price").getAsBigDecimal()));
                printer.println();
                break;

            case "EXIT_LONG":
                // Action
                printer.print("SELL");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("MKT");
                // LmtPrice
                printer.print("");
                // AuxPrice
                printer.print("");
                printer.println();
                break;

            case "EXIT_SHORT":
                // Action
                printer.print("BUY");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("MKT");
                // LmtPrice
                printer.print("");
                // AuxPrice
                printer.print("");
                printer.println();
                break;

            case "EXIT_SHORT_STOP_LIMIT":
                // Action
                printer.print("BUY");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("STP LMT");
                // LmtPrice
                printer.print(formatOrderPrice(jorder.get("limit_price").getAsBigDecimal()));
                // AuxPrice
                printer.print(formatOrderPrice(jorder.get("stop_price").getAsBigDecimal()));
                printer.println();
                break;

            case "EXIT_LONG_STOP_LIMIT":
                // Action
                printer.print("SELL");
                // Quantity
                printer.print(jorder.get("quantity").getAsLong());
                // Symbol
                printer.print(rs.getString(4));
                // SecType
                printer.print(rs.getString(14));
                // LastTradingDayOrContractMonth
                printer.print(contract);
                // Exchange
                printer.print(rs.getString(13));
                // OrderType
                printer.print("STP LMT");
                // LmtPrice
                printer.print(formatOrderPrice(jorder.get("limit_price").getAsBigDecimal()));
                // AuxPrice
                printer.print(formatOrderPrice(jorder.get("stop_price").getAsBigDecimal()));
                printer.println();
                break;
            }
        }

        if (printer != null)
            printer.flush();
    }
}

From source file:de.fraunhofer.iosb.ilt.sta.persistence.postgres.PropertyHelper.java

private static TimeInterval intervalFromTimes(Timestamp timeStart, Timestamp timeEnd) {
    if (timeStart == null) {
        timeStart = Timestamp.valueOf(LocalDateTime.MAX);
    }//from  w w w . j av  a 2  s  . co m
    if (timeEnd == null) {
        timeEnd = Timestamp.valueOf(LocalDateTime.MIN);
    }
    if (timeEnd.before(timeStart)) {
        return null;
    } else {
        return TimeInterval.create(timeStart.getTime(), timeEnd.getTime());
    }
}

From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java

public java.util.Date parseDate(int type, String value, boolean useVariableDates) {
    if (StringUtils.isNotBlank(value)) {
        try {//w w  w. j  a va 2s. c  o m
            boolean useTimestamp = (type == Types.TIMESTAMP)
                    || (type == Types.DATE && getDdlBuilder().getDatabaseInfo().isDateOverridesToTimestamp());

            if (useVariableDates && value.startsWith("${curdate")) {
                long time = Long.parseLong(value.substring(10, value.length() - 1));
                if (value.substring(9, 10).equals("-")) {
                    time *= -1L;
                }
                time += System.currentTimeMillis();
                if (useTimestamp) {
                    return new Timestamp(time);
                }
                return new Date(time);
            } else {
                if (useTimestamp) {
                    return parseTimestamp(type, value);
                } else if (type == Types.TIME) {
                    if (value.indexOf(".") == 8) {
                        /*
                         * Firebird (at least) captures fractional seconds
                         * in time fields which need to be parsed by
                         * Timestamp.valueOf
                         */
                        return Timestamp.valueOf("1970-01-01 " + value);
                    } else {
                        return FormatUtils.parseDate(value, FormatUtils.TIME_PATTERNS);
                    }
                } else {
                    return FormatUtils.parseDate(value, FormatUtils.TIMESTAMP_PATTERNS);
                }
            }
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        return null;
    }
}

From source file:org.shengrui.oa.util.UtilDateTime.java

/**
 * /*from   ww  w  . j a v  a  2 s . c o  m*/
 * @param date
 * @param daySeed
 * @return
 */
public static Date geDay(Date date, int daySeed) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.DAY_OF_MONTH, daySeed);
    String dstr = toDateString(calendar.getTime());
    return Timestamp.valueOf(dstr + " 00:00:00");
    //return calendar.getTime();
}

From source file:org.openvpms.archetype.test.TestHelper.java

/**
 * Helper to create a date-time given a string of the form
 * <em>yyyy-mm-dd hh:mm:ss</em>.
 *
 * @param value the value. May be {@code null}
 * @return the corresponding date-time or {@code null} if {@code value} is null
 *///  w w w  .j a v  a  2  s. c  o  m
public static Date getDatetime(String value) {
    return value != null ? new Date(Timestamp.valueOf(value).getTime()) : null; // use Date, for easy comparison
}

From source file:org.shengrui.oa.util.UtilDateTime.java

/**
 * //  w w w  . j a  v a  2s  . c  o m
 * @param date
 * @param weekString
 * @return
 */
public static Date getDayByWeekString(Date date, String weekString, Boolean byAdd) {
    if (week2int.containsKey(weekString) && date != null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        if (byAdd) {
            calendar.add(Calendar.DAY_OF_MONTH, 1);
        }
        int intWeek = calendar.get(Calendar.DAY_OF_WEEK) == 1 ? 8 : calendar.get(Calendar.DAY_OF_WEEK);
        while (true) {
            if (intWeek == week2int.get(weekString)) {
                String dstr = toDateString(calendar.getTime());
                return Timestamp.valueOf(dstr + " 00:00:00");
                //return calendar.getTime();
            }
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            intWeek = calendar.get(Calendar.DAY_OF_WEEK) == 1 ? 8 : calendar.get(Calendar.DAY_OF_WEEK);
        }
    }
    return null;
}

From source file:com.aes.controller.EmpireController.java

@RequestMapping(value = "/examactions", method = RequestMethod.POST)
public String doAction7(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute UserDetails tempUser, BindingResult result, @RequestParam String action,
        Map<String, Object> map) {

    String courseId = request.getParameter("courseId");
    switch (action.toLowerCase()) {
    case "add":
        String examTitle = request.getParameter("examTitle");
        String examStart = request.getParameter("examStart");
        String examDue = request.getParameter("examDue");
        String timeLimit = request.getParameter("timeLimit");
        System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<" + examStart);
        System.out.println(examDue);
        Timestamp tsExamStart = Timestamp.valueOf(examStart.replace("T", " ") + ":00");
        System.out.println(tsExamStart);
        Timestamp tsExamDue = Timestamp.valueOf(examDue.replace("T", " ") + ":00");
        System.out.println(tsExamDue);
        Exam tempExam = new Exam();
        tempExam.setNumQuestions(this.getQuestionNumber(request));
        tempExam.setExamStart(tsExamStart);
        tempExam.setExamDue(tsExamDue);/*from   w  w w .  j a v  a 2s.  c o  m*/
        tempExam.setExamTitle(examTitle);
        tempExam.setTimeLimit(Float.valueOf(timeLimit));
        tempExam.setCourse(service.getCourseById(Integer.parseInt(courseId)));
        tempExam.setQuestionDetails(this.getQuestionDetails(request).toString());
        service.addExam(tempExam);
        break;
    case "delete":
        try {
            String examId = request.getParameter("examId");
            System.out.println(examId);
            service.deleteExam(Integer.parseInt(examId));
            map.put("message", "Exam successfully deleted.");
        } catch (Exception e) {
            map.put("message", "Unable to delete exam. Sorry.");
        }
        break;
    }
    map.put("exams", service.getAllExam());
    return "../../admin/exams_view";
}