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:net.chrisrichardson.foodToGo.restaurantNotificationService.tsImpl.dao.MarkOrdersAsSentCallback.java

public Map makeMapForOrder(OrderDTO order, NotificationDetails notification) {
    Map map = new HashMap();
    map.put("orderId", order.getOrderId());
    map.put("version", new Integer(order.getBizVersion()));
    map.put("messageId", notification.getMessageId());
    map.put("timestamp", new Timestamp(notification.getTimestamp().getTime()));
    return map;/*w  ww.  ja v  a 2 s.  com*/
}

From source file:fr.mby.opa.pics.web.controller.AlbumController.java

@ResponseBody
@ResponseStatus(value = HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
public Album createAlbumJson(@Valid @RequestBody final Album album) throws Exception {
    Assert.notNull(album, "No Album supplied !");

    album.setCreationTime(new Timestamp(System.currentTimeMillis()));
    album.setLocked(false);//from   w w w.  jav  a2s  .co m

    this.albumDao.createAlbum(album);

    return album;
}

From source file:org.cloudfoundry.identity.uaa.codestore.CodeStoreEndpointsTests.java

@Test
public void testGenerateCode() throws Exception {
    String data = "{}";
    Timestamp expiresAt = new Timestamp(System.currentTimeMillis() + 60000);
    ExpiringCode expiringCode = new ExpiringCode(null, expiresAt, data);

    ExpiringCode result = codeStoreEndpoints.generateCode(expiringCode);

    assertNotNull(result);//from  w  w  w .ja va2 s.  c  o m

    assertNotNull(result.getCode());
    assertTrue(result.getCode().trim().length() > 0);

    assertEquals(expiresAt, result.getExpiresAt());

    assertEquals(data, result.getData());
}

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

@Override
public Session create(final Session entity) {
    final String sql = "insert into t_session (entity_id,subject_id,created_on,last_accessed_on,timeout,host) values (?,?,?,?,?,cast(? as inet))";
    final SessionImpl session = new SessionImpl(entity);
    session.setEntityId(UUID.randomUUID());
    session.validate();//from   w  ww.  j a v a2s . c  o m
    jdbc.update(sql, session.getEntityId(), session.getSubjectId(), new Timestamp(session.getCreatedOn()),
            new Timestamp(session.getLastAccessedOn()), session.getTimeoutSeconds(), session.getHost());

    return session;
}

From source file:org.dcache.chimera.PgSQL95FsSqlDriver.java

/**
  */*from  w  w  w . j a  v a2 s .  c o m*/
  * adds a new location for the inode
  *
  * @param inode
  * @param type
  * @param location
  */
void addInodeLocation(FsInode inode, int type, String location) {
    _jdbc.update(
            "INSERT INTO t_locationinfo (inumber,itype,ilocation,ipriority,ictime,iatime,istate) VALUES(?,?,?,?,?,?,?) "
                    + "ON CONFLICT ON CONSTRAINT t_locationinfo_pkey DO NOTHING",
            ps -> {
                Timestamp now = new Timestamp(System.currentTimeMillis());
                ps.setLong(1, inode.ino());
                ps.setInt(2, type);
                ps.setString(3, location);
                ps.setInt(4, 10); // default priority
                ps.setTimestamp(5, now);
                ps.setTimestamp(6, now);
                ps.setInt(7, 1); // online
            });
}

From source file:jerry.c2c.action.UploadProductAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {

    String target = "result";
    String resultPageTitle = "error";
    String msgTitle = "error";
    String msgContent = "error";
    NewProductForm productForm = (NewProductForm) form;
    HttpSession session = request.getSession();
    Item item = new Item();

    try {/*from   w  w  w . j av  a  2  s. c o m*/
        BeanUtils.copyProperties(item, productForm);
        item.setCreateTime(DateTimeUtil.getCurrentTimestamp());
        Timestamp createTime = DateTimeUtil.getCurrentTimestamp();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_YEAR, productForm.getDays());
        Timestamp endTime = new Timestamp(calendar.getTimeInMillis());
        item.setBelongTo((Shop) session.getAttribute("user_shop"));
        item.setCreateTime(createTime);
        item.setEndTime(endTime);
        Category category = categoryService.getById(productForm.getCategoryId());
        item.setCategory(category);
        itemService.save(item);
        this.handleUploadImage(productForm.getImageFile(), item.getBelongTo().getName(), item.getId());
        resultPageTitle = "??";
        msgTitle = "??";
        msgContent = "?(" + item.getName() + ")?";
    } catch (IllegalAccessException e) {
        itemService.delete(item);
        resultPageTitle = "?";
        msgTitle = "?";
        msgContent = "?,?:" + e.getMessage();
    } catch (InvocationTargetException e) {
        itemService.delete(item);
        resultPageTitle = "?";
        msgTitle = "?";
        msgContent = "?,?:" + e.getMessage();
    } catch (IOException e) {
        itemService.delete(item);
        e.printStackTrace();
        resultPageTitle = "?";
        msgTitle = "?";
        msgContent = "?,?:" + e.getMessage();
    } catch (BusinessException e) {
        itemService.delete(item);
        e.printStackTrace();
        resultPageTitle = "?";
        msgTitle = "?";
        msgContent = "?,?:" + e.getMessage();
    } finally {
        request.setAttribute("title", resultPageTitle);
        request.setAttribute("message_title", msgTitle);
        request.setAttribute("message_content", msgContent);
    }
    return mapping.findForward(target);
}

From source file:com.dangdang.ddframe.job.event.rdb.JobRdbEventStorage.java

boolean addJobTraceEvent(final JobTraceEvent traceEvent) {
    boolean result = false;
    if (needTrace(traceEvent.getLogLevel())) {
        String sql = "INSERT INTO `job_trace_log` (`id`, `job_name`, `hostname`, `message`, `failure_cause`, `creation_time`) VALUES (?, ?, ?, ?, ?, ?);";
        try (Connection conn = dataSource.getConnection();
                PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
            preparedStatement.setString(1, UUID.randomUUID().toString());
            preparedStatement.setString(2, traceEvent.getJobName());
            preparedStatement.setString(3, traceEvent.getHostname());
            preparedStatement.setString(4, traceEvent.getMessage());
            preparedStatement.setString(5, getFailureCause(traceEvent.getFailureCause()));
            preparedStatement.setTimestamp(6, new Timestamp(traceEvent.getCreationTime().getTime()));
            preparedStatement.execute();
            result = true;/*from   w  w  w  .  j  a  v  a  2 s  .  c o  m*/
        } catch (final SQLException ex) {
            // TODO ,???
            log.error(ex.getMessage());
        }
    }
    return result;
}

From source file:eionet.gdem.dcm.business.BackupManager.java

public void backupFile(String folderName, String fileName, String id, String user) {

    File origFile = new File(folderName, fileName);
    if (!origFile.exists()) {
        return; // there's nothing to backup since file does not exist
    }/*from   w w w . j  a va  2 s  .  c  om*/

    long timestamp = System.currentTimeMillis();
    String backupFileName = Constants.BACKUP_FILE_PREFIX + id + "_" + timestamp
            + fileName.substring(fileName.lastIndexOf("."));

    // backup folder is the subfolder
    String backupFolderName = folderName + File.separator + Constants.BACKUP_FOLDER_NAME;
    File backupFolder = new File(backupFolderName);
    if (!backupFolder.exists()) {
        backupFolder.mkdir(); // create backup folder if it does not exist
    }

    File backupFile = new File(backupFolderName, backupFileName);

    try {
        Utils.copyFile(origFile, backupFile);
        BackupDto backup = new BackupDto();
        backup.setFileName(backupFileName);
        backup.setQueryId(id);
        backup.setUser(user);
        backup.setTimestamp(new Timestamp(timestamp));
        backupDao.addBackup(backup);
    } catch (Exception e) {
        LOGGER.error("Unable to create backupfile - copy original file " + origFile.getPath() + " to "
                + backupFile.getPath() + ". " + e.toString());
        e.printStackTrace();
    }
}

From source file:name.richardson.james.bukkit.alias.PlayerListener.java

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerLogin(final AsyncPlayerPreLoginEvent event) {
    logger.log(Level.FINE, "Received {0}", event.getClass().getSimpleName());
    PlayerNameRecord playerNameRecord = playerNameRecordManager.create(event.getName());
    InetAddressRecord inetAddressRecord = inetAddressRecordManager.create(event.getAddress().getHostAddress());
    final Timestamp now = new Timestamp(System.currentTimeMillis());
    if (!playerNameRecord.getAddresses().contains(inetAddressRecord)) {
        playerNameRecord.getAddresses().add(inetAddressRecord);
    }//from w w w . j  ava  2s. c  o  m
    playerNameRecord.setLastSeen(now);
    inetAddressRecord.setLastSeen(now);
    playerNameRecordManager.save(playerNameRecord);
    inetAddressRecordManager.save(inetAddressRecord);
}

From source file:de.kaiserpfalzEdv.infopir.backend.db.BaseEntity.java

public void setCreatedDate(final DateTime timestamp) {
    created = new Timestamp(timestamp.getMillis());
}