List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:com.ideabase.repository.test.TestCaseRepositoryHelper.java
public static List<Integer> fixCreateItemsWithRandomName(final RepositoryService pRepositoryService, final int pNumberOfItems) { final List<Integer> itemIds = new ArrayList<Integer>(); final String dummyName = String.valueOf((System.currentTimeMillis() + Math.random())).replace(".", ""); final String dummyEmail = String.valueOf((System.currentTimeMillis() + Math.random()) + "@somewherein.net") .replace(".", ""); for (int i = 0; i < pNumberOfItems; i++) { final GenericItem item = new GenericItem(); item.addField("vendor", "test" + i); item.addField("name", i + dummyName); item.addField("email", i + dummyEmail); item.addField("currentTime", String.valueOf(System.currentTimeMillis())); item.setTitle(i + dummyName);/*from w w w . j a v a 2 s. c om*/ item.setCreatedOn(new Timestamp(System.currentTimeMillis())); item.setLastUpdatedOn(item.getCreatedOn()); itemIds.add(pRepositoryService.save(item)); } return itemIds; }
From source file:com.matrimony.database.UserDAO.java
public static User register(User user) throws EmailAlready, ContactNumberAlready { if (findByEmail(user.getEmail()) != null) { throw new STException.EmailAlready("Add user: email already"); } else if (findByContactNumber(user.getContactNumber()) != null) { throw new STException.ContactNumberAlready("Add user: contact number already"); } else {/*from w w w . j a v a 2 s.c o m*/ Timestamp now = new Timestamp(System.currentTimeMillis()); if (user.getPassword() != null) { user.setSalt(HashUtil.generateSalt(UUID.randomUUID().toString())); user.setPassword(HashUtil.hashPassword(user.getPassword(), user.getSalt())); } user.setCreateAt(now); // ADD USER add(user); UserPreferenceDAO.initUserPrefrence(user); String emailOrPhone = user.getEmail() != null ? user.getEmail() : user.getContactNumber(); User temp = findByEmailOrContactNumberOrUsername(emailOrPhone); temp.setUsername(temp.getId()); // UPDATE USERNAME FOR USER Update(temp); return temp; } }
From source file:fr.mby.opa.picsimpl.service.BasicProposalService.java
@Override public ProposalBag createBag(final String name, final String description, final long branchId) { Assert.hasText(name, "No name supplied !"); final ProposalBag bag = new ProposalBag(); bag.setCreationTime(new Timestamp(System.currentTimeMillis())); bag.setName(name);// w w w .j a v a2 s .c om bag.setDescription(description); bag.setCommited(false); final ProposalBag createdBag = this.proposalDao.createBag(bag, branchId); return createdBag; }
From source file:bq.jpa.demo.datetype.service.EmployeeService.java
@Transactional public Employee create() { Employee employee = new Employee(); employee.setEmployeeName("bq"); employee.setGender('m'); employee.setFamilymember((short) 5); employee.setOnline(false);/*w ww . j ava 2s . co m*/ employee.setRetired(false); employee.setSalary(10000); employee.setSaleAmount(new BigDecimal("10000000")); Calendar date = Calendar.getInstance(); date.set(1980, 8, 18); employee.setBirthday(date.getTime()); employee.setLastLoginTime(new Timestamp(System.currentTimeMillis())); employee.setTimeFrom(Time.valueOf("08:30:00")); employee.setType(EmployeeType.FULL_TIME_EMPLOYEE); Address homeAddress = new Address(); homeAddress.setNumber("88"); homeAddress.setRoad("Rich"); homeAddress.setCity("New York"); homeAddress.setState("NY"); homeAddress.setCountry("USA"); employee.setHomeAddress(homeAddress); //read png file try { employee.setPicture(readImage("/datetype/picture.png")); } catch (IOException e) { e.printStackTrace(); employee.setPicture(null); } // read txt file try { employee.setResume(readFile("/datetype/resume.txt")); } catch (IOException | URISyntaxException e) { e.printStackTrace(); employee.setResume(null); } em.persist(employee); return employee; }
From source file:net.mindengine.oculus.frontend.service.test.JdbcTestDAO.java
@Override public long create(Test test) throws Exception { PreparedStatement ps = getConnection().prepareStatement( "insert into tests (name, description, project_id, author_id, date, mapping, group_id, content, automated) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); ps.setString(1, test.getName());/* www . ja v a 2s .co m*/ ps.setString(2, test.getDescription()); ps.setLong(3, test.getProjectId()); ps.setLong(4, test.getAuthorId()); ps.setTimestamp(5, new Timestamp(test.getDate().getTime())); ps.setString(6, test.getMapping()); ps.setLong(7, test.getGroupId()); ps.setString(8, test.getContent()); ps.setBoolean(9, test.getAutomated()); logger.info(ps); ps.executeUpdate(); ResultSet rs = ps.getGeneratedKeys(); Long testId = 0L; if (rs.next()) { testId = rs.getLong(1); } /* * Increasing the tests_count value for current project */ update("update projects set tests_count=tests_count+1 where id = :id", "id", test.getProjectId()); return testId; }
From source file:com.parallax.server.blocklyprop.security.BlocklyPropSessionDao.java
protected SessionRecord convert(Session session) { SimpleSession ssession = (SimpleSession) session; SessionRecord sessionRecord = new SessionRecord(); sessionRecord.setIdsession(session.getId().toString()); sessionRecord.setStarttimestamp(new Timestamp(session.getStartTimestamp().getTime())); sessionRecord.setLastaccesstime(new Timestamp(session.getLastAccessTime().getTime())); sessionRecord.setTimeout(session.getTimeout()); sessionRecord.setHost(session.getHost()); if (ssession.getAttributes() != null) { HashMap<Object, Object> attributes = (HashMap<Object, Object>) ssession.getAttributes(); sessionRecord.setAttributes(SerializationUtils.serialize(attributes)); }//from w w w . j a v a2 s. c o m return sessionRecord; }
From source file:controller.ISLogin.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); try (PrintWriter out = response.getWriter()) { String email = request.getParameter("email"); String password = request.getParameter("password"); JSONObject object = new JSONObject(); if (email != null && password != null) { String sql = "SELECT * FROM user WHERE email = ? AND password = SHA1(?)"; try (PreparedStatement statement = conn.prepareStatement(sql)) { statement.setString(1, email); statement.setString(2, password); ResultSet result = statement.executeQuery(); if (result.next()) { int u_id = result.getInt("u_id"); String uuid = UUID.randomUUID().toString().replaceAll("-", ""); Calendar time = Calendar.getInstance(); time.setTime(new Date()); time.add(Calendar.HOUR, 2); conn.setAutoCommit(false); String delete = "DELETE from token WHERE u_id = ?"; String insert = "INSERT INTO token (access_token, u_id, expiry_date)" + "VALUES (?, ?, ?)"; try (PreparedStatement deleteStatement = conn.prepareStatement(delete); PreparedStatement insertStatement = conn.prepareStatement(insert);) { deleteStatement.setInt(1, u_id); Timestamp timestamp = new Timestamp(time.getTimeInMillis()); insertStatement.setString(1, uuid); insertStatement.setInt(2, u_id); insertStatement.setTimestamp(3, timestamp); deleteStatement.execute(); insertStatement.execute(); object.put("token", uuid); object.put("expiry_date", timestamp.getTime()); conn.commit();/*from w w w .j a va2 s . co m*/ } finally { conn.setAutoCommit(true); } } else { object.put("error", "Invalid email or password"); } } catch (SQLException e) { e.printStackTrace(); } } else { object.put("error", "Empty email or password"); } out.println(object.toString()); } }
From source file:com.teamglokk.muni.utilities.Transaction.java
/** * Full data constructor with option to autosave * @param instance// w w w. j a v a 2 s.c o m * @param town_Name * @param player * @param reason * @param payment * @param item_payment * @param autosave */ public Transaction(Muni instance, String town_Name, String player, String reason, double payment, int item_payment, boolean autosave) { plugin = instance; playerName = player; townName = town_Name; type = reason; amount = payment; item_amount = item_payment; datetime = new Timestamp(System.currentTimeMillis()); // = Calendar.getInstance(); //time = Calendar.getInstance(); if (autosave) { saveTrans(); } }
From source file:com.silverpeas.gallery.dao.OrderDAO.java
/** * Updates the status of an order.//from w w w . java 2s . c o m * @param con * @param order * @throws SQLException */ private static void updateOrderStatus(Connection con, Order order) throws SQLException { executeUpdate(con, "update SC_Gallery_Order set processDate = ?, processUser = ? where orderId = ?", new Timestamp(new Date().getTime()), order.getProcessUserId(), order.getOrderId()); }
From source file:com.recomdata.grails.rositaui.utils.SignalService.java
public void sendConsole(Long stepId, String message) { try {/*from ww w . j av a 2s. c o m*/ consolePs.setLong(1, stepId); consolePs.setTimestamp(2, new Timestamp(new java.util.Date().getTime())); consolePs.setString(3, message); consolePs.execute(); } catch (SQLException e) { e.printStackTrace(); } }