List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:ma.glasnost.orika.test.converter.CloneableConverterNoSetAccessibleTestCase.java
@Test public void cloneableConverterWithoutSetAccessible() throws DatatypeConfigurationException { final SecurityManager initialSm = System.getSecurityManager(); try {//from www .j a v a 2 s.c o m System.setSecurityManager(new SecurityManager() { public void checkPermission(java.security.Permission perm) { if ("suppressAccessChecks".equals(perm.getName())) { for (StackTraceElement ste : new Throwable().getStackTrace()) { if (ste.getClassName().equals(CloneableConverter.class.getCanonicalName())) { throw new SecurityException("not permitted"); } } } } }); CloneableConverter cc = new CloneableConverter(SampleCloneable.class); MapperFactory factory = MappingUtil.getMapperFactory(); factory.getConverterFactory().registerConverter(cc); GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.YEAR, 10); XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance() .newXMLGregorianCalendar((GregorianCalendar) cal); cal.add(Calendar.MONTH, 3); ClonableHolder source = new ClonableHolder(); source.value = new SampleCloneable(); source.value.id = 5L; source.date = new Date(System.currentTimeMillis() + 100000); source.timestamp = new Timestamp(System.currentTimeMillis() + 50000); source.calendar = cal; source.xmlCalendar = xmlCal; ClonableHolder dest = factory.getMapperFacade().map(source, ClonableHolder.class); Assert.assertEquals(source.value, dest.value); Assert.assertNotSame(source.value, dest.value); Assert.assertEquals(source.date, dest.date); Assert.assertNotSame(source.date, dest.date); Assert.assertEquals(source.timestamp, dest.timestamp); Assert.assertNotSame(source.timestamp, dest.timestamp); Assert.assertEquals(source.calendar, dest.calendar); Assert.assertNotSame(source.calendar, dest.calendar); Assert.assertEquals(source.xmlCalendar, dest.xmlCalendar); Assert.assertNotSame(source.xmlCalendar, dest.xmlCalendar); } finally { System.setSecurityManager(initialSm); } }
From source file:org.ala.spatial.services.dao.ActionDAOImpl.java
@Override public void addAction(Action action) { logger.info("Adding a new " + action.getType() + " action by " + action.getEmail() + " via " + action.getAppid());/*from ww w. j a va 2 s. c o m*/ logger.info("\nlayers: " + action.getService().getLayers() + "\nextra: " + action.getService().getExtra()); action.setTime(new Timestamp(new Date().getTime())); SqlParameterSource sprm = new BeanPropertySqlParameterSource(action.getService()); Number serviceId = insertService.executeAndReturnKey(sprm); action.getService().setId(serviceId.longValue()); action.setServiceid(serviceId.longValue()); SqlParameterSource parameters = new BeanPropertySqlParameterSource(action); Number actionId = insertAction.executeAndReturnKey(parameters); action.setId(actionId.longValue()); }
From source file:net.mindengine.oculus.frontend.service.issue.JdbcIssueDAO.java
@Override public long createIssue(Issue issue) throws Exception { PreparedStatement ps = getConnection().prepareStatement( "insert into issues (name, link, summary, description, author_id, date, fixed, fixed_date, project_id, subproject_id) " + "values (?,?,?,?,?,?,?,?,?,?)"); ps.setString(1, issue.getName());//from w w w. ja va2 s.c o m ps.setString(2, issue.getLink()); ps.setString(3, issue.getSummary()); ps.setString(4, issue.getDescription()); ps.setLong(5, issue.getAuthorId()); ps.setTimestamp(6, new Timestamp(issue.getDate().getTime())); ps.setInt(7, issue.getFixed()); ps.setTimestamp(8, new Timestamp(issue.getFixedDate().getTime())); ps.setLong(9, issue.getProjectId()); ps.setLong(10, issue.getSubProjectId()); logger.info(ps); ps.execute(); ResultSet rs = ps.getGeneratedKeys(); if (rs.next()) { return rs.getLong(1); } return 0; }
From source file:com.bitranger.parknshop.seller.controller.SellerAdCtrl.java
@RequestMapping(value = "/seller/addAd", method = RequestMethod.POST) public void getItems(HttpServletRequest request, HttpServletResponse response) throws ParseException, IOException { String name = request.getParameter("adName"); String itemId = request.getParameter("itemId"); String startDate = request.getParameter("start"); String endDate = request.getParameter("end"); String weight = request.getParameter("weight"); String description = request.getParameter("description"); String picUrl = request.getParameter("pic-url"); System.out.println(/*www . j a va2 s. c o m*/ name + ": " + itemId + ";" + startDate + ";" + endDate + "; " + weight + ";" + description); PsItem $ = psItemDao.findById(Integer.parseInt(itemId)); SimpleDateFormat FMT = new SimpleDateFormat("yyyy-MM-dd"); PsPromotItem pi = new PsPromotItem(); pi.setPsItem($); pi.setDescription(description); pi.setTimeCreated(new Timestamp(System.currentTimeMillis())); pi.setPicUrl(picUrl); psPromotItemDAO.save(pi); PsAdItem ad = new PsAdItem(); ad.setIdPromot(pi.getId()); ad.setTimeStart(new Timestamp(FMT.parse(startDate).getTime())); ad.setTimeEnd(new Timestamp(FMT.parse(endDate).getTime())); ad.setWeight(Double.parseDouble(weight)); psAdItemDAO.save(ad); PrintWriter out = response.getWriter(); out.write("success"); out.flush(); out.close(); }
From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.writers.BugNotesWriterTest.java
/** * Build the items to write./*from w w w . jav a2s .c o m*/ * * @return items */ private List<BugBean> buildItems() { final Calendar cal = Calendar.getInstance(); final Timestamp date = new Timestamp(cal.getTimeInMillis()); final List<BugBean> items = new ArrayList<BugBean>(); final BugBean item1 = new BugBean(); final BugNoteBean note = new BugNoteBean(); note.setId(BigInteger.ONE); note.setBugId(BigInteger.ONE); note.setReporterId(BigInteger.ONE); note.setTextNote("note_1"); note.setDateSubmitted(date); note.setLastModified(date); item1.getNotes().add(note); items.add(item1); return items; }
From source file:cz.zcu.kiv.eegdatabase.wui.core.dto.FullPersonDTO.java
public FullPersonDTO() { dateOfBirth = new Timestamp(new Date().getTime()); }
From source file:me.hqm.plugindev.wget.WGET.java
/** * Bukkit logout event listener.//from w ww.j a v a 2s .c o m * @param event the quit event */ @EventHandler(priority = EventPriority.MONITOR) public void onPlayerLogout(PlayerQuitEvent event) { Player player = event.getPlayer(); WGUser alias = new WGUser(); Db db = Db.open(DB_URL); // Logout the user from the DB when they logout on the server. WGUser user = db.from(alias).where(alias.minecraftId).is(player.getUniqueId().toString()).selectFirst(); user.sessionExpires = new Timestamp(System.currentTimeMillis()); db.update(user); db.close(); }
From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.writers.BugHistoryWriterTest.java
/** * Build the items to write.//from w ww.ja va 2 s . c o m * * @return items */ private List<BugBean> buildItems() { final Calendar cal = Calendar.getInstance(); final Timestamp date = new Timestamp(cal.getTimeInMillis()); final List<BugBean> items = new ArrayList<BugBean>(); final BugBean item1 = new BugBean(); final BugHistoryBean hist = new BugHistoryBean(); hist.setBugId(BigInteger.ONE); hist.setUserId(BigInteger.ONE); hist.setOldValue("old"); hist.setNewValue("new"); hist.setHistoryType(BigInteger.TEN); hist.setDateModified(date); item1.getHistory().add(hist); items.add(item1); return items; }
From source file:isl.FIMS.servlet.export.ExportXML.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.initVars(request); String username = getUsername(request); boolean isGuest = this.getRights(username).equals("guest"); if (!isGuest) { try {//from w ww . j a v a2 s .c om String filePath = this.export_import_Folder; java.util.Date date = new java.util.Date(); Timestamp t = new Timestamp(date.getTime()); String currentDir = filePath + t.toString().replaceAll(":", "").replaceAll("\\s", ""); File saveDir = new File(currentDir); saveDir.mkdir(); Config conf = new Config("EksagwghXML"); String type = request.getParameter("type"); String id = request.getParameter("id"); request.setCharacterEncoding("UTF-8"); DBCollection col = new DBCollection(this.DBURI, this.systemDbCollection + type, this.DBuser, this.DBpassword); String collectionPath = UtilsQueries.getPathforFile(col, id + ".xml", id.split(type)[1]); col = new DBCollection(this.DBURI, collectionPath, this.DBuser, this.DBpassword); DBFile dbf = col.getFile(id + ".xml"); String isWritable = "true"; if (GetEntityCategory.getEntityCategory(type).equals("primary")) { isWritable = dbf .queryString("//admin/write='" + username + "'" + "or //admin/status='published'")[0]; } if (isWritable.equals("true")) { String[] res = dbf.queryString("//admin/refs/ref"); ServletOutputStream outStream = response.getOutputStream(); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=\"" + id + ".zip\""); writeFile(type, id, currentDir, username); for (int i = 0; i < res.length; i++) { Element e = Utils.getElement(res[i]); String sps_type = e.getAttribute("sps_type"); String sps_id = e.getAttribute("sps_id"); sps_id = sps_type + sps_id; writeFile(sps_type, sps_id, currentDir, username); } //check if any disk files to export ArrayList<String> externalFiles = new <String>ArrayList(); String q = "//*["; for (String attrSet : this.uploadAttributes) { String[] temp = attrSet.split("#"); String func = temp[0]; String attr = temp[1]; if (func.contains("text")) { q += "@" + attr + "]/text()"; } else { q = "data(//*[@" + attr + "]/@" + attr + ")"; } String[] result = dbf.queryString(q); for (String extFile : result) { externalFiles.add(extFile + "#" + attr); } } for (String extFile : externalFiles) { DBFile uploadsDBFile = new DBFile(this.DBURI, this.adminDbCollection, "Uploads.xml", this.DBuser, this.DBpassword); String attr = extFile.substring(extFile.lastIndexOf("#") + 1, extFile.length()); extFile = extFile.substring(0, extFile.lastIndexOf("#")); String mime = Utils.findMime(uploadsDBFile, extFile, attr); String path = ""; if (mime.equals("Photos")) { path = this.systemUploads + File.separator + type + File.separator + mime + File.separator + "original" + File.separator + extFile; } else { path = this.systemUploads + File.separator + type + File.separator + mime + File.separator + extFile; } File f = new File(path); if (f.exists()) { if (extFile.startsWith("../")) { extFile = extFile.replace("../", ""); File file = new File( currentDir + System.getProperty("file.separator") + id + ".xml"); if (!file.exists()) { file = new File( currentDir + System.getProperty("file.separator") + id + ".x3ml"); } if (file.exists()) { String content = FileUtils.readFileToString(file); content = content.replaceAll("../" + extFile, extFile); FileUtils.writeStringToFile(file, content); } } FileUtils.copyFile(f, new File(currentDir + System.getProperty("file.separator") + extFile)); } } File f = new File(currentDir + System.getProperty("file.separator") + "zip"); f.mkdir(); String zip = f.getAbsolutePath() + System.getProperty("file.separator") + id + ".zip"; Utils.createZip(zip, currentDir); Utils.downloadZip(outStream, new File(zip)); } else { String displayMsg = ""; response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); displayMsg = Messages.ACCESS_DENIED; StringBuilder xml = new StringBuilder( this.xmlStart(this.topmenu, username, this.pageTitle, this.lang, "", request)); xml.append("<Display>").append(displayMsg).append("</Display>\n"); xml.append(this.xmlEnd()); String xsl = conf.DISPLAY_XSL; try { XMLTransform xmlTrans = new XMLTransform(xml.toString()); xmlTrans.transform(out, xsl); } catch (DMSException e) { } out.close(); } Utils.deleteDir(currentDir); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:edu.depaul.armada.controller.LogRestfulControllerTest.java
@Test public void testGetLogsForPast24Hours() { List<ContainerMetric> results = logRestfulController.getLogsForPast24Hours(-1); assertNotNull(results);/*from w w w . ja va2s . co m*/ assertTrue(!results.isEmpty()); for (int hour = 0; hour < 24; hour++) { ContainerMetric cm = results.get(hour); assertTrue(cm.getCpu() == 0); assertTrue(cm.getDisk() == 0); assertTrue(cm.getMem() == 0); } Container container = TestUtil.newContainer(); for (int i = 0; i < 24; i++) { ContainerLog log = TestUtil.newContainerLog(); log.setTimestamp(new Timestamp(System.currentTimeMillis())); container.addLog(log); } for (int i = 0; i < 24; i++) { ContainerLog log = TestUtil.newContainerLog(); log.setTimestamp(new Timestamp(System.currentTimeMillis() - 24 * 60 * 60 * 1001)); container.addLog(log); } containerDao.store(container); List<ContainerLog> logs = containerDao.findWithContainerId(container.getId()).getLogs(); assertEquals(48, logs.size()); results = logRestfulController.getLogsForPast24Hours(container.getId()); assertNotNull("List of results was null!", results); assertEquals(24, results.size()); }