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:com.synnex.saas.platform.core.Startup.java

@PostConstruct
public void addSampleData() {
    Calendar cal = Calendar.getInstance();
    for (int i = 0; i < 3; i++) {
        TransactionStatus tx = transactionManager.getTransaction(new DefaultTransactionDefinition());
        String tenantId = UUID.randomUUID().toString();
        Tenant tenant = new Tenant();
        tenant.setHost("t" + (i + 1) + ".synnex.com:8085");
        tenant.setName("Tenant-" + (i + 1));
        cal.add(Calendar.DAY_OF_YEAR, 100);
        tenant.setRegisterDate(new Timestamp(System.currentTimeMillis()));
        tenant.setExpiredDate(new Timestamp(cal.getTimeInMillis()));
        tenant.setTenantId(tenantId);/*from w  ww .j  a  va 2 s. c om*/
        // Create sample users
        for (int j = 0; j < 10; j++) {
            // User
            TransactionStatus txTenant = transactionManager.getTransaction(new DefaultTransactionDefinition());
            emTenant.setProperty("tenant_id", tenantId);
            emTenant.setProperty("eclipselink.session-name", "multi-tenant-" + tenantId);
            User user = new User();
            user.setUserName("t" + (j + 1));
            user.setNickName("Steven Li");
            MessageDigestPasswordEncoder digest = new MessageDigestPasswordEncoder("md5");
            user.setPassword(digest.encodePassword("password", "123"));
            user.setEnabled(true);
            cal = Calendar.getInstance();
            cal.add(Calendar.DAY_OF_YEAR, 10);
            user.setRegisterDate(new Timestamp(System.currentTimeMillis()));
            user.setExpiredDate(new Timestamp(cal.getTimeInMillis()));
            emTenant.persist(user);
            transactionManager.commit(txTenant);
        }

        // Create sample code
        for (int j = 0; j < 200; j++) {
            // User
            TransactionStatus txTenant = transactionManager.getTransaction(new DefaultTransactionDefinition());
            emTenant.setProperty("tenant_id", tenantId);
            emTenant.setProperty("eclipselink.session-name", "multi-tenant-" + tenantId);

            // Code
            Code code = new Code();
            code.setName("SSSS");
            emTenant.persist(code);
            transactionManager.commit(txTenant);
        }
        em.persist(tenant);
        transactionManager.commit(tx);
    }
}

From source file:gov.nih.nci.cabig.caaers.service.security.PasswordManagerServiceImpl.java

private boolean validateToken(User user, String token) throws CaaersSystemException {
    if (user.getTokenTime().after(
            new Timestamp(new Date().getTime() - passwordPolicyService.getPasswordPolicy().getTokenTimeout()))
            && StringUtils.equals(user.getToken(), token))
        return true;
    throw new CaaersSystemException("Invalid token.");
}

From source file:com.josue.lottery.eap.persistence.entity.rest.Resource.java

public void setDateUpdated(Date dateUpdated) {
    this.dateUpdated = new Timestamp(dateUpdated.getTime());
}

From source file:dsd.dao.RawDataDAO.java

public static ArrayList<RawData> GetAllForPeriod(Calendar startDate, Calendar endDate) {
    try {/*from  www. ja va 2  s. c  o m*/
        Connection con = DAOProvider.getDataSource().getConnection();
        ArrayList<RawData> rawDataList = new ArrayList<RawData>();
        try {
            Object[] parameters = new Object[2];
            parameters[0] = new Timestamp(startDate.getTimeInMillis());
            parameters[1] = new Timestamp(endDate.getTimeInMillis());
            ResultSet results = DAOProvider.SelectTableSecure(tableName, "*",
                    " timestamp >= ? and timestamp <= ? ", "", con, parameters);
            while (results.next()) {
                RawData dataTuple = new RawData();
                dataTuple.setRawDataID(results.getInt("ID"));
                dataTuple.setWindSpeed(results.getFloat(fields[0]));
                dataTuple.setWindDirection(results.getFloat(fields[1]));
                dataTuple.setHydrometer(results.getFloat(fields[2]));
                dataTuple.setSonar(results.getFloat(fields[3]));
                dataTuple.setSonarType(eSonarType.getSonarType(results.getInt(fields[4])));
                dataTuple.setTimestamp(results.getTimestamp(fields[5]).getTime());
                rawDataList.add(dataTuple);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        con.close();
        return rawDataList;
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return null;

}

From source file:fitmon.WorkoutApi.java

public StringBuilder apiGetInfo()
        throws ClientProtocolException, IOException, NoSuchAlgorithmException, InvalidKeyException {
    HttpClient client = new DefaultHttpClient();
    //HttpGet request = new HttpGet("http://platform.fatsecret.com/rest/server.api&"
    //                    + "oauth_consumer_key=5f2d9f7c250c4d75b9807a4f969363a7&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1408230438&"
    //                     + "oauth_nonce=abc&oauth_version=1.0&method=food.get&food_id=4384");
    //HttpResponse response = client.execute(request);
    //BufferedReader rd = new BufferedReader (new InputStreamReader(response.getEntity().getContent()));
    //StringBuilder sb = new StringBuilder();
    String base = URLEncoder.encode("GET") + "&";
    base += "http%3A%2F%2Fplatform.fatsecret.com%2Frest%2Fserver.api&";

    String params;//  ww w . j  a v  a 2  s .c  o m

    params = "format=json&";
    params += "method=exercises.get&";
    params += "oauth_consumer_key=5f2d9f7c250c4d75b9807a4f969363a7&"; // ur consumer key 
    params += "oauth_nonce=123&";
    params += "oauth_signature_method=HMAC-SHA1&";
    Date date = new java.util.Date();
    Timestamp ts = new Timestamp(date.getTime());
    params += "oauth_timestamp=" + ts.getTime() + "&";
    params += "oauth_version=1.0";
    //params += "search_expression=apple"; 

    String params2 = URLEncoder.encode(params);
    base += params2;
    //System.out.println(base);
    String line = "";

    String secret = "76172de2330a4e55b90cbd2eb44f8c63&";
    Mac sha256_HMAC = Mac.getInstance("HMACSHA1");
    SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HMACSHA1");
    sha256_HMAC.init(secret_key);
    String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(base.getBytes()));

    //$url = "http://platform.fatsecret.com/rest/server.api?".$params."&oauth_signature=".rawurlencode($sig); 
    HttpGet request = new HttpGet("http://platform.fatsecret.com/rest/server.api?" + params
            + "&oauth_signature=" + URLEncoder.encode(hash));
    HttpResponse response = client.execute(request);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    StringBuilder sb = new StringBuilder();

    //$url = "http://platform.fatsecret.com/rest/server.api?"+params+"&oauth_signature="+URLEncoder.encode(hash);
    //return url;

    while ((line = rd.readLine()) != null) {
        sb.append(line);
        //System.out.println(line);
    }
    //System.out.println(sb.toString());
    return sb;
}

From source file:fr.mby.opa.picsimpl.service.BasicSessionService.java

@Override
public Session createSession(final long pictureId, final long bagId, final String name,
        final String description) {
    Session session = null;/*from w w w  .  jav a 2 s. c  om*/

    final ProposalBag bag = this.proposalDao.findBag(bagId);

    final Picture picture = this.pictureDao.findPictureById(pictureId);

    if (bag != null && !bag.isCommited() && picture != null) {
        final Timestamp pictureCreationTime = picture.getCreationTime();

        session = new Session();
        session.setCreationTime(new Timestamp(System.currentTimeMillis()));
        session.setName(name);
        session.setDescription(description);
        session.setStartTime(pictureCreationTime);
        session.setEndTime(pictureCreationTime);
        final CasingProposal proposal = this.proposalService.createCasingProposal(pictureId, session);

        bag.getCasingProposals().add(proposal);
        try {
            this.proposalService.updateBag(bag);
        } catch (final ProposalBagNotFoundException e) {
            // Should not happened
            throw new IllegalStateException(e);
        } catch (final ProposalBagCommitedException e) {
            // Should not happened
            throw new IllegalStateException(e);
        }
    }

    return session;
}

From source file:org.dspace.app.util.AbstractDSpaceWebapp.java

/** Record that this application is running. */
public void register() {
    // Create the database entry
    Timestamp now = new Timestamp(started.getTime());
    try {//from   w w  w .  j  av a2s .  c o  m
        Context context = new Context();
        row = DatabaseManager.create(context, "Webapp");
        row.setColumn("AppName", kind);
        row.setColumn("URL", url);
        row.setColumn("Started", now);
        row.setColumn("isUI", isUI() ? 1 : 0); // update won't widen boolean to integer
        DatabaseManager.update(context, row);
        context.complete();
    } catch (SQLException e) {
        log.error("Failed to record startup in Webapp table.", e);
    }
}

From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.TimestampDataConverter.java

@Override
public Timestamp parsDate(String rawData) throws Exception {
    return StringUtils.isNotEmpty(rawData) ? new Timestamp(getDateFormatter().parse(rawData).getTime()) : null;
}

From source file:com.impetus.kundera.property.accessor.SQLTimestampAccessor.java

@Override
public Timestamp fromBytes(Class targetClass, byte[] b) {

    // String s;//  w ww.j  a va2 s  . co m
    // try
    // {
    // if(b == null)
    // {
    // return null;
    // }
    // s = new String(b, Constants.ENCODING);
    // }
    // catch (UnsupportedEncodingException e)
    // {
    // throw new PropertyAccessException(e);
    // }
    // return fromString(targetClass, s);
    try {
        if (b == null) {
            return null;
        }

        // In case date.getTime() is stored in DB.
        LongAccessor longAccessor = new LongAccessor();

        return new Timestamp(longAccessor.fromBytes(targetClass, b));
    } catch (Exception e) {
        log.error("Error occured, Caused by {}.", e);
        throw new PropertyAccessException(e);
    }
}

From source file:com.inkubator.hrm.service.impl.NotificationBroadcastAnnouncementMessagesListener.java

@Override
public void onMessage(Message message) {
    try {//from www .j  a  v  a2 s .c  o m
        String json = ((TextMessage) message).getText();
        Gson gson = JsonUtil.getHibernateEntityGsonBuilder().create();
        AnnouncementJsonModel model = gson.fromJson(json, AnnouncementJsonModel.class);

        /** proses untuk menggenerate log, sekaligus mengirim email per Announcement*/
        if (BooleanUtils.isTrue(model.getIsGeneratingAnnouncementLog())) {
            //creating announcement log (synchronous)
            JobParameters jobParameters = new JobParametersBuilder()
                    .addLong("announcementId", model.getAnnouncementId())
                    .addDate("planExecutionDate", model.getPlanExecutionDate())
                    .addDate("createdOn", new Timestamp(new Date().getTime())).toJobParameters();
            jobLauncher.run(jobAnnouncementLog, jobParameters);

            //broadcast email announcement (asynchronous / fire and forget)
            if (model.getViewModel() == HRMConstant.ANNOUNCEMENT_VIEW_MAIL) {
                jobParameters = new JobParametersBuilder().addLong("announcementId", model.getAnnouncementId())
                        .addDate("planExecutionDate", model.getPlanExecutionDate())
                        .addDate("createdOn", new Timestamp(new Date().getTime())).toJobParameters();
                jobLauncherAsync.run(jobEmailingAnnouncement, jobParameters);
            }
        }

        /** proses untuk mengirim email semua Announcement, yang memang belum dikirim */
        if (BooleanUtils.isTrue(model.getIsSendingAllEmailNotSent())) {
            JobParameters jobParameters = new JobParametersBuilder()
                    .addDate("createdOn", new Timestamp(new Date().getTime())).toJobParameters();
            jobLauncherAsync.run(jobEmailingAnnouncementNotSent, jobParameters);
        }

    } catch (Exception ex) {
        LOGGER.error("Error", ex);
    }
}