List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:net.mlw.vlh.adapter.jdbc.util.setter.Hibernate20CalendarSetter.java
/** * <ol>//from w ww.j a va 2 s .co m * <li>If filter value is instance of the Calendar, it will set it directly * to <code>PreparedStatement</code> query. </li> * <li>Otherwise it will set new Timestamp(with actual time) to query for * key.</li> * </ol> * * @see net.mlw.util.sql.StatementBuilder.Setter#set(java.sql.PreparedStatement, * int, java.lang.Object) */ public int set(PreparedStatement query, int index, Object value) throws SQLException, ParseException { long timeInMillis = 0; if (value instanceof Calendar) { timeInMillis = ((Calendar) value).getTimeInMillis(); } else { if (LOGGER.isWarnEnabled()) { LOGGER.warn("The key's index's='" + index + "' value='" + value + "' was expected as Calendar. Using actual time."); } timeInMillis = Calendar.getInstance().getTimeInMillis(); } query.setTimestamp(index++, new Timestamp(timeInMillis)); return index; }
From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.writers.BugsWriterTest.java
/** * Build the items to write./* w ww.j a v a2 s .c o m*/ * * @return items */ private List<BugBean> buildItems() { final Calendar cal = Calendar.getInstance(); final List<BugBean> items = new ArrayList<BugBean>(); final BugBean item1 = new BugBean(); item1.setId(BigInteger.ONE); item1.setProjectId(BigInteger.ONE); item1.setDescription("Description_1"); item1.setSummary("Summary_1"); item1.setDateSubmitted(new Timestamp(cal.getTimeInMillis())); item1.setLastUpdated(new Timestamp(cal.getTimeInMillis())); items.add(item1); return items; }
From source file:nl.edia.sakai.tool.skinmanager.impl.SkinArchiveServiceImpl.java
@Override public SkinArchive createSkinArchive(final String name, final InputStream file, final Date time, final String comment) { return (SkinArchive) getHibernateTemplate().execute(new HibernateCallback() { @Override// w w w .j a va 2 s . com public Object doInHibernate(Session session) throws HibernateException, SQLException { int myVersion = 0; Number myHighestVersion = (Number) session.createCriteria(SkinArchive.class) .add(Restrictions.eq("name", name)).setProjection(Projections.max("version")) .uniqueResult(); if (myHighestVersion != null) { myVersion = myHighestVersion.intValue() + 1; } SkinArchive mySkinArchive = new SkinArchive(); mySkinArchive.setActive(true); mySkinArchive.setLastModified(new Timestamp(time.getTime())); mySkinArchive.setName(name); mySkinArchive.setVersion(myVersion); mySkinArchive.setComment(comment); try { mySkinArchive.setFile(Hibernate.createBlob(file)); } catch (IOException e) { throw new HibernateException(e); } session.save(mySkinArchive); setSkinStatus(name, true); return mySkinArchive; } }); }
From source file:Classes.Database.java
/** * Converts a date to timestamp/*from w w w . ja v a 2 s. c om*/ * * @param date the date for converting * @return timestamp */ private Timestamp DateToTimestamp(Date date) { return new Timestamp(date.getTime()); }
From source file:dsd.dao.WorstCaseDAO.java
public static ArrayList<WorstPylonCase> GetAllForPeriod(Calendar startDate, Calendar endDate, boolean traffic, boolean debris) { try {/*from ww w .j av a 2 s. c o m*/ Connection con = DAOProvider.getDataSource().getConnection(); ArrayList<WorstPylonCase> worstCaseDataList = new ArrayList<WorstPylonCase>(); try { String tableName = GetTableNameForDataType(traffic, debris); 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()) { WorstPylonCase dataTuple = new WorstPylonCase(results.getInt(fields[0])); Pylon pylon = new Pylon(results.getInt(fields[0])); pylon.setN(results.getFloat(fields[1])); pylon.setTx(results.getFloat(fields[2])); pylon.setTy(results.getFloat(fields[3])); pylon.setMx(results.getFloat(fields[4])); pylon.setMy(results.getFloat(fields[5])); pylon.setM(results.getFloat(fields[6])); dataTuple.setPylon(pylon); dataTuple.setID(results.getLong("ID")); dataTuple.setComboNumber(results.getInt(fields[8])); dataTuple.setSafetyFactor(results.getFloat(fields[7])); dataTuple.setTimestamp(results.getTimestamp(fields[9]).getTime()); worstCaseDataList.add(dataTuple); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); return worstCaseDataList; } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:com.bdx.rainbow.spsy.controller.syjg.LicenseController.java
@RequestMapping(value = "/list") public ModelAndView list(Model model, PageInfo pageinfo, HttpServletRequest request) throws BusinessException { DubboEnterpriseLicense condition = new DubboEnterpriseLicense(); condition.setEnterpriseName(request.getParameter("enterpriseName")); condition.setLicenseCode(request.getParameter("licenseCode")); condition.setOrganizationCode(request.getParameter("organizationCode")); if (StringUtils.isNotBlank(request.getParameter("validDateStart"))) { condition.setValidDateStart(DateUtil.getTimestamp(request.getParameter("validDateStart"))); }//from ww w. j a v a 2 s. c om if (StringUtils.isNotBlank(request.getParameter("validDateEnd"))) { condition.setValidDateEnd(DateUtil.getTimestamp(request.getParameter("validDateEnd"))); } String type = request.getParameter("type") == null ? "" : request.getParameter("type"); if ("0".equals(type)) { condition.setInvalidDateStart(DateUtil.getCurrent()); } else if ("1".equals(type)) { condition.setInvalidDateStart(DateUtil.getCurrent()); condition.setInvalidDateEnd(new Timestamp(DateUtil.addMonth(new Date(), 1).getTime())); } else if ("-1".equals(type)) { condition.setInvalidDateEnd(DateUtil.getCurrent()); } Map<String, Object> resultMap = new HashMap<String, Object>(); try { resultMap = licenseService.getLicenses(condition, pageinfo.getPageStart(), pageinfo.getPageCount()); pageinfo.setTotalCount((Integer) resultMap.get("total")); model.addAttribute("rows", resultMap.get("list")); model.addAttribute("pageinfo", pageinfo); } catch (Exception e) { log.debug(e.getMessage(), e); } return new ModelAndView("/supLicense/licenseList"); }
From source file:com.saggezza.litetracker.track.PayloadMap.java
/** * {@inheritDoc}// w ww .j a va2 s.co m * @return */ public void setTimestamp() { String tstamp = new Timestamp(System.currentTimeMillis()).toString(); this.parameters.put("dtm", tstamp); // this.parameters.put("dtm", String.valueOf(System.currentTimeMillis())); }
From source file:churashima.action.manage.ExpensesAction.java
@Execute(validator = false) public String index() { Date date = new Date(); if (StringUtils.isEmpty(expensesForm.strDate)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); expensesForm.strDate = sdf.format(date); }//from ww w . ja v a 2s . c o m Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); ExpensesDao expensesDao = SingletonS2Container.getComponent(ExpensesDao.class); List<Expenses> expensesList = expensesDao.selectForSearch(null, null, null, null, null, null, null, null, new Timestamp(cal.getTimeInMillis())); expensesForm.expensesList = expensesList; // expensesForm.subjectId = null; expensesForm.place = null; expensesForm.name = null; expensesForm.price = BigDecimal.valueOf(0); expensesForm.comment = null; expensesForm.isExcludeTax = null; SubjectDao subjectDao = SingletonS2Container.getComponent(SubjectDao.class); expensesForm.subjectList = subjectDao.selectForSearch(null, Const.STATUS_STARTING); return "expenses.jsp"; }
From source file:com.bitranger.parknshop.task.OrderChecker.java
@Override public void run() { Timestamp now = new Timestamp(System.currentTimeMillis()); // 1. Check out-of-date unpaid order List<PsOrder> unpaidOrders = psOrderDao.findAll(OrderStatus.UNPAID); for (PsOrder psOrder : unpaidOrders) { Timestamp orderTimestamp = psOrder.getTimeCreated(); if (subtract(now, orderTimestamp).after(oneDay)) { psOrder.setStatus(OrderStatus.CANCELLED); psOrderDao.update(psOrder);/*from w ww . j a v a 2s . com*/ } } // 2. Check out-of-date paid order List<PsOrder> paidOrders = psOrderDao.findAll(OrderStatus.PAID); for (PsOrder psOrder : paidOrders) { Timestamp paidTimestamp = psOrder.getTimePaid(); if (subtract(now, paidTimestamp).after(threeDay)) { psOrder.setStatus(OrderStatus.CANCELLED); psOrderDao.update(psOrder); PsAdministrator psAdministrator = psAdministratorDao.findById(1); psAdministrator.setBalance(psAdministrator.getBalance() - psOrder.getPriceTotal()); psAdministratorDao.update(psAdministrator); } } // 3. Check out-of-date delivering order List<PsOrder> deliveringOrders = psOrderDao.findAll(OrderStatus.DELIVERING); for (PsOrder psOrder : deliveringOrders) { Timestamp deliverTimestamp = psOrder.getTimeBeginDeliver(); if (subtract(now, deliverTimestamp).after(sevenDay)) { psOrder.setStatus(OrderStatus.FINISHED); psOrderDao.update(psOrder); // @SuppressWarnings("unchecked") // List<PsSellerAcc> psSellerAccs = psSellerAccDao.findByProperty( // "id_seller", psOrder.getPsShop().getPsSeller().getId()); // PsSellerAcc account = psSellerAccs.get(0); // double balance = account.getBalance(); // account.setBalance(balance + psOrder.getPriceTotal()); // psSellerAccDao.update(account); PsSeller seller = psOrder.getPsShop().getPsSeller(); seller.setBalance(seller.getBalance() + psOrder.getPriceTotal()); psSellerDao.update(seller); PsAdministrator psAdministrator = psAdministratorDao.findById(1); psAdministrator.setBalance(psAdministrator.getBalance() - psOrder.getPriceTotal()); psAdministratorDao.update(psAdministrator); } } }
From source file:eionet.webq.task.RemoveExpiredUserFilesTask.java
/** * Perform removal task./*from www . j a v a 2 s . c o m*/ */ @Scheduled(cron = "0 0 0 * * *") @Transactional public void removeExpiredUserFiles() { Integer hoursAgo = getExpirationHours(); Date allowedDate = DateUtils.addHours(new Date(), -hoursAgo); LOGGER.info("Removing user files last modified before " + allowedDate + "(in storage more than " + hoursAgo + " hours). "); Session currentSession = factory.getCurrentSession(); List rowsAffected = currentSession.createCriteria(UserFile.class) .add(Restrictions.le("updated", new Timestamp(allowedDate.getTime()))).list(); for (Object row : rowsAffected) { currentSession.delete(row); } LOGGER.info("Removal successful. Removed " + rowsAffected + " files."); }