Example usage for java.sql Timestamp Timestamp

List of usage examples for java.sql Timestamp Timestamp

Introduction

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

Prototype

public Timestamp(long time) 

Source Link

Document

Constructs a Timestamp object using a milliseconds time value.

Usage

From source file:fr.paris.lutece.plugins.crm.service.demand.DemandService.java

/**
 * Update a demand/*ww  w  .ja v  a 2  s  .c  o m*/
 * @param demand the demand
 */
public void update(Demand demand) {
    if (demand != null) {
        demand.setDateModification(new Timestamp(new Date().getTime()));
        DemandHome.update(demand);
    }
}

From source file:monitoring.tools.AppTweak.java

protected void apiCall() throws MalformedURLException, IOException, JSONException, ParseException {

    String timeStamp = new Timestamp((new Date()).getTime()).toString();

    JSONObject data = urlConnection();//from   ww w  .j a  v a 2s . c  om

    List<MonitoringData> dataList = new ArrayList<>();
    JSONArray reviews = data.getJSONArray("content");
    for (int i = 0; i < reviews.length(); ++i) {

        JSONObject obj = reviews.getJSONObject(i);

        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss z");
        Date date = format.parse(obj.getString("date"));

        if (date.compareTo(stamp) > 0) {

            Iterator<?> keys = obj.keys();
            MonitoringData review = new MonitoringData();

            while (keys.hasNext()) {
                String key = (String) keys.next();
                if (key.equals("id"))
                    review.setReviewID(obj.getString("id"));
                else if (key.equals("author"))
                    review.setAuthorName(obj.getJSONObject("author").getString("name"));
                else if (key.equals("title"))
                    review.setReviewTitle(obj.getString("title"));
                else if (key.equals("body"))
                    review.setReviewText(obj.getString("body"));
                else if (key.equals("date"))
                    review.setTimeStamp(obj.getString("date"));
                else if (key.equals("rating"))
                    review.setStarRating(String.valueOf(obj.getInt("rating")));
                else if (key.equals("version"))
                    review.setAppVersion(obj.getString("version"));
            }

            dataList.add(review);
        }
    }
    //kafka.generateResponseKafka(dataList, timeStamp, id, confId, params.getKafkaTopic());
    kafka.generateResponseIF(dataList, timeStamp, id, confId, params.getKafkaTopic());
    logger.debug("Data sent to kafka endpoint");
    ++id;
}

From source file:com.heliumv.factory.impl.ZeiterfassungCall.java

private Timestamp updateTimeWithNow(Timestamp theirsTs) {
    if (theirsTs == null)
        return null;

    Calendar theirs = Calendar.getInstance();
    theirs.setTimeInMillis(theirsTs.getTime());

    Calendar mine = Calendar.getInstance();
    theirs.set(Calendar.HOUR, mine.get(Calendar.HOUR));
    theirs.set(Calendar.MINUTE, mine.get(Calendar.MINUTE));
    theirs.set(Calendar.SECOND, 0);

    return new Timestamp(theirs.getTimeInMillis());
}

From source file:uk.org.funcube.fcdw.server.extract.csv.WodCsvExtractor.java

/**
 * @param wod24/*from   w w w . j av  a2  s .com*/
 * @param fileLocation
 */
private void writeFile(List<WholeOrbitDataEntity> wod, File fileLocation) {
    try {
        // use FileWriter constructor that specifies open for appending
        CsvWriter csvOutput = new CsvWriter(new FileWriter(fileLocation, true), ',');

        // write out the headers
        csvOutput.write("Satellite Date/Time UTC");
        csvOutput.write("Black Chassis deg. C");
        csvOutput.write("Silver Chassis deg. C");
        csvOutput.write("Black Panel deg. C");
        csvOutput.write("Silver Panel deg. C");
        csvOutput.write("Solar Panel +X deg. C");
        csvOutput.write("Solar Panel -X deg. C");
        csvOutput.write("Solar Panel +Y deg. C");
        csvOutput.write("Solar Panel -Y deg. C");
        csvOutput.write("Solar Panel X mV");
        csvOutput.write("Solar Panel Y mV");
        csvOutput.write("Solar Panel Z mV");
        csvOutput.write("Tot. Photo Curr. mA ");
        csvOutput.write("Battery mV");
        csvOutput.write("Tot. System Curr. mA");
        csvOutput.endRecord();

        long tsLong = 0;
        String c1 = "";
        String c2 = "";
        String c3 = "";
        String c4 = "";
        String c5 = "";
        String c6 = "";
        String c7 = "";
        String c8 = "";
        String c9 = "";
        String c10 = "";
        String c11 = "";
        String c12 = "";
        String c13 = "";
        String c14 = "";

        for (WholeOrbitDataEntity entity : wod) {

            Timestamp satelliteTime = new Timestamp(entity.getCreatedDate().getTime());

            if (tsLong == 0) {
                tsLong = satelliteTime.getTime();
                c1 = scale(entity.getC1(), -0.024, 75.244);
                c2 = scale(entity.getC2(), -0.024, 74.750);
                c3 = scale(entity.getC3(), -0.024, 75.039);
                c4 = scale(entity.getC4(), -0.024, 75.987);
                c5 = scale(entity.getC5(), -0.2073, 158.239);
                c6 = scale(entity.getC6(), -0.2083, 159.227);
                c7 = scale(entity.getC7(), -0.2076, 158.656);
                c8 = scale(entity.getC8(), -0.2087, 159.045);
                c9 = String.format("%4d", entity.getC9());
                c10 = String.format("%4d", entity.getC10());
                c11 = String.format("%4d", entity.getC11());
                c12 = String.format("%4d", entity.getC12());
                c13 = String.format("%4d", entity.getC13());
                c14 = String.format("%4d", entity.getC14());

                writeRecord(csvOutput, satelliteTime, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13,
                        c14);
            } else {

                final long timeDiff = satelliteTime.getTime() - tsLong;
                if (timeDiff > 60000) {
                    // fill in the gaps
                    long gaps = (timeDiff / 60000);
                    for (long i = 1; i < gaps; i++) {
                        Timestamp intervalTime = new Timestamp(tsLong + (60000 * i));
                        writeRecord(csvOutput, intervalTime, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12,
                                c13, c14);
                    }
                }

                c1 = scale(entity.getC1(), -0.024, 75.244);
                c2 = scale(entity.getC2(), -0.024, 74.750);
                c3 = scale(entity.getC3(), -0.024, 75.039);
                c4 = scale(entity.getC4(), -0.024, 75.987);
                c5 = scale(entity.getC5(), -0.2073, 158.239);
                c6 = scale(entity.getC6(), -0.2083, 159.227);
                c7 = scale(entity.getC7(), -0.2076, 158.656);
                c8 = scale(entity.getC8(), -0.2087, 159.045);
                c9 = String.format("%4d", entity.getC9());
                c10 = String.format("%4d", entity.getC10());
                c11 = String.format("%4d", entity.getC11());
                c12 = String.format("%4d", entity.getC12());
                c13 = String.format("%4d", entity.getC13());
                c14 = String.format("%4d", entity.getC14());

                writeRecord(csvOutput, satelliteTime, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13,
                        c14);

                tsLong = satelliteTime.getTime();
            }
        }

        csvOutput.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:biblivre3.circulation.access.JsonAccessHandler.java

private IFJson lendCard(HttpServletRequest request) {
    String cardIdString = request.getParameter("card_id");
    String userIdString = request.getParameter("user_id");
    if (StringUtils.isBlank(cardIdString)) {
        return new ErrorDTO("MESSAGE_ERROR_SELECT_USER", "warning");
    } else if (StringUtils.isBlank(userIdString)) {
        return new ErrorDTO("MESSAGE_ERROR_SELECT_CARD", "warning");
    }/*www .ja  va2  s.  c  o m*/
    UserDTO udto = null;
    try {
        udto = (new CirculationBO()).searchByUserId(Integer.valueOf(userIdString));
    } catch (Exception e) {
    }
    if (udto == null) {
        return new ErrorDTO("MESSAGE_USER_SERIAL_NOT_FOUND", "warning");
    }
    Integer cardId = 0;
    try {
        cardId = Integer.valueOf(cardIdString);
    } catch (Exception e) {
        return new ErrorDTO("MESSAGE_ERROR_SELECT_USER_CARD", "warning");
    }
    CardDTO cardDto = new CardBO().getCardById(cardId);
    if (!cardDto.getStatus().equals(CardStatus.AVAILABLE)) {
        return new ErrorDTO("MESSAGE_CARD_ALREADY_LENT", "warning");
    }
    AccessDTO existingAccess = bo.getByCardId(cardId);
    if (existingAccess != null) {
        return new ErrorDTO("MESSAGE_CARD_ALREADY_LENT", "warning");
    }
    existingAccess = bo.getByUserId(udto.getUserid());
    if (existingAccess != null) {
        return new ErrorDTO("MESSAGE_USER_ALREADY_HAS_CARD", "warning");
    }

    AccessDTO dto = new AccessDTO();
    dto.setSerialCard(cardId);
    dto.setSerialReader(udto.getUserid());
    dto.setEntranceDatetime(new Timestamp(new Date().getTime()));
    if (bo.insert(dto)) {
        return new SuccessDTO("SUCCESS_LEND_CARD");
    } else {
        return new ErrorDTO("ERROR_LEND_CARD", "warning");
    }
}

From source file:org.grails.datastore.gorm.events.DomainEventListener.java

protected void setVersion(final EntityAccess ea) {
    if (Number.class.isAssignableFrom(ea.getPropertyType("version"))) {
        ea.setProperty("version", 0);
    } else if (Timestamp.class.isAssignableFrom(ea.getPropertyType("version"))) {
        ea.setProperty("version", new Timestamp(System.currentTimeMillis()));
    } else if (Date.class.isAssignableFrom(ea.getPropertyType("version"))) {
        ea.setProperty("version", new Date());
    }/*from ww w.j  av a2  s .  c  om*/
}

From source file:strat.mining.multipool.stats.builder.MiddlecoinStatsBuilder.java

private void persistStats(GlobalStats globalStats) {
    Timestamp updateTime = new Timestamp(globalStats.getTime().getTime());
    Timestamp refreshTime = new Timestamp(System.currentTimeMillis());

    try {/*from  www. j a  v a  2s. c  o  m*/
        // Insert the global stats
        insertGlobalStats(globalStats, updateTime, refreshTime);
    } catch (Exception e) {
        LOGGER.warn("Failed to persist the global stats. {}", e);
    }

    long start = System.currentTimeMillis();

    // Then persist addresses stats
    int nbInserted = 0;
    List<AddressStats> addressStats = new ArrayList<>();
    for (Entry<String, AddressReport> entry : globalStats.getReport().entrySet()) {
        try {
            AddressStats createdAddressStats = createAddressStats(entry, updateTime, refreshTime);
            if (createdAddressStats != null) {
                addressStats.add(createdAddressStats);
            }
            nbInserted++;
        } catch (Exception e) {
            LOGGER.warn("Failed to persist the address stats {}. {}", entry.getKey(), e);
        }
    }

    addressStatsDAO.insertAddressStats(addressStats);

    PERF_LOGGER.info("{} addresses stats inserted in {} ms.", nbInserted, System.currentTimeMillis() - start);
}

From source file:com.azaptree.services.security.dao.SessionDAO.java

@Override
public boolean touchSession(final UUID sessionId) {
    Assert.notNull(sessionId, "sessionId is required");
    final String sql = "update t_session set last_accessed_on = ? where entity_id = ?";
    return jdbc.update(sql, new Timestamp(System.currentTimeMillis()), sessionId) > 0;
}

From source file:com.hangum.tadpole.engine.query.sql.TadpoleSystem_UserQuery.java

/**
 *   ?.//from w w  w. ja  v a2s  .  com
 * 
 * @param inputType
 * @param email
 * @param email_key
 * @param is_email_certification
 * @param passwd
 * @param roleType
 * @param name
 * @param language
 * @param timezone
 * @param approvalYn
 * @param use_otp
 * @param otp_secret
 * @param strAllowIP
 * @param strIsRegistDb
 * @param strIsSharedDb
 * @param intLimitAddDBCnt
 * @param serviceStart
 * @param serviceEnd
 * @return
 * @throws TadpoleSQLManagerException, SQLException
 */
public static UserDAO newUser(String inputType, String email, String email_key, String is_email_certification,
        String passwd, String roleType, String name, String language, String timezone, String approvalYn,
        String use_otp, String otp_secret, String strAllowIP) throws TadpoleSQLManagerException, SQLException {
    UserDAO loginDAO = new UserDAO();
    loginDAO.setInput_type(inputType);
    loginDAO.setEmail(email);
    loginDAO.setEmail_key(email_key);
    loginDAO.setIs_email_certification(is_email_certification);

    loginDAO.setPasswd(CipherManager.getInstance().encryption(passwd));
    loginDAO.setRole_type(roleType);

    loginDAO.setName(name);
    loginDAO.setLanguage(language);
    loginDAO.setTimezone(timezone);
    loginDAO.setApproval_yn(approvalYn);
    loginDAO.setUse_otp(use_otp);
    loginDAO.setOtp_secret(otp_secret);
    loginDAO.setAllow_ip(strAllowIP);

    loginDAO.setIs_regist_db(GetAdminPreference.getIsAddDB());
    loginDAO.setIs_shared_db(GetAdminPreference.getIsAddDB());
    loginDAO.setLimit_add_db_cnt(NumberUtils.toInt(GetAdminPreference.getDefaultAddDBCnt()));
    loginDAO.setService_start(new Timestamp(System.currentTimeMillis()));
    loginDAO.setService_end(new Timestamp(
            DateUtil.afterMonthToMillis(NumberUtils.toInt(GetAdminPreference.getServiceDurationDay()))));

    SqlMapClient sqlClient = TadpoleSQLManager.getInstance(TadpoleSystemInitializer.getUserDB());
    List isUser = sqlClient.queryForList("isUser", email); //$NON-NLS-1$

    if (isUser.isEmpty()) {
        UserDAO userdb = (UserDAO) sqlClient.insert("newUser", loginDAO); //$NON-NLS-1$
        TadpoleSystem_UserInfoData.initializeUserPreferenceData(userdb);

        return userdb;
    } else {
        throw new TadpoleRuntimeException(Messages.get().TadpoleSystem_UserQuery_3);
    }
}