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.arindra.project.accounting.controllers.PurchaseOrderController.java

@RequestMapping(method = RequestMethod.GET, value = "/create_demo")
public void createDemoPurchaseOrder() {//@PathVariable("username") String username, @PathVariable("password") String password,@PathVariable("limit") Integer limit){
    PurchaseOrder purchaseOrder = new PurchaseOrder("1", new Timestamp(new Date().getTime()), null, null,
            new Long(0));
    PurchaseOrderDetail purchaseOrderDetail = new PurchaseOrderDetail(1, null, new Long(10), 1);

    purchaseOrderRepo.save(purchaseOrder);
    purchaseOrderDetailRepo.save(purchaseOrderDetail);
}

From source file:gov.nih.nci.cabig.caaers.web.validation.validator.AdverseEventReportingPeriodValidatorTest.java

private void setupAdverseEventReportingPeriod() {
    adverseEventReportingPeriod = Fixtures.createReportingPeriod();
    adverseEventReportingPeriod.setStartDate(new Timestamp(100));
    adverseEventReportingPeriod.setEndDate(new Timestamp(200));
    adverseEventReportingPeriod.addAdverseEvent(new AdverseEvent());
    adverseEventReportingPeriod.addAdverseEvent(new AdverseEvent());
    adverseEventReportingPeriod.setTreatmentAssignment(new TreatmentAssignment());
    AdverseEventCtcTerm aeCtcTerm = new AdverseEventCtcTerm();
    aeCtcTerm.setCtcTerm(Fixtures.createCtcTerm("testTerm", "testCode"));
    adverseEventReportingPeriod.getAdverseEvents().get(0).setAdverseEventCtcTerm(aeCtcTerm);
    aeCtcTerm.setCtcTerm(Fixtures.createCtcTerm("testTerm2", "testCode2"));
    adverseEventReportingPeriod.getAdverseEvents().get(1).setAdverseEventCtcTerm(aeCtcTerm);
}

From source file:com.caibojian.iotservice.IOTCallback.java

public void processMessage(String message, String topic) {
    System.out.println(message);//from   w w  w . j  a  v a  2 s .  c o m
    User user1 = new User();
    user1.setAccount("caibojian");
    user1.setAge(20);
    user1.setId(0);
    user1.setName("");

    User user2 = new User();
    user2.setAccount("test");
    user2.setAge(20);
    user2.setId(1);
    user2.setName("");

    MyMessage recMsg = null;
    MyMessage sendMsg = null;
    String sendMsgs = null;
    String toTopic = null;

    String time = new Timestamp(System.currentTimeMillis()).toString();
    System.out.println("=>Recieved at : " + time + "  ,Topic: " + topic + "  ,Message:" + message);
    System.out.println("");
    switch (topic) {
    case Constants.IOT_TOPOIC_LOGIN:

        sendMsg = new MyMessage();
        recMsg = JsonUtil.fromJson(new String(message), MyMessage.class);
        if (Constants.MYMSG_TYPE_LOGIN_REQ == recMsg.getMsgType()) {
            User user = JsonUtil.fromJson(recMsg.getContent(), User.class);
            // ====???=====
            System.out.println(user.getAccount() + "====" + user.getPassword());
            if ("caibojian".equals(user.getAccount())) {
                user1.setOnline(true);
                sendMsg.setContent(JsonUtil.toJson(user1));
            } else if ("test".equals(user.getAccount())) {
                user2.setOnline(true);
                sendMsg.setContent(JsonUtil.toJson(user2));
            } else {
                user.setOnline(false);
            }
            sendMsg.setToId(user.getUuid());

            sendMsg.setDate(new Date());
            sendMsg.setFromId("system");
            sendMsg.setMsgType(Constants.MYMSG_TYPE_LOGIN_RESP);
            sendMsgs = JsonUtil.toJson(sendMsg);
            // ====???=====

            toTopic = user.getUuid();
            try {
                MQTTPublisher loginPublisher = new MQTTPublisher(toTopic, sendMsgs,
                        clientId + "-MYMSG_TYPE_LOGIN_RESP" + rand.nextInt(100000), true);
                new Thread(loginPublisher).start();
                log.info(sendMsgs);
            } catch (MqttException e) {
                e.printStackTrace();
            }
        }
        break;
    case Constants.IOT_TOPOIC_GETFRIENDS:

        System.out.println("-------IOT_TOPOIC_GETFRIENDS");
        sendMsg = new MyMessage();
        recMsg = JsonUtil.fromJson(new String(message), MyMessage.class);
        List<Friends> friends = new ArrayList<Friends>();
        // for (int i=0; i<100; i++){
        // Friends friend = new Friends();
        // friend.setId(i);
        // friend.setAge(i);
        // friend.setOnline(true);
        // friend.setUserId(i);
        // friend.setName("??"+i);
        // Random random = new Random();
        // int a=random.nextInt(5);
        // friend.setFriendsGroupId(a);
        // friends.add(friend);
        // }
        Friends friend1 = new Friends();
        friend1.setId(1);
        friend1.setAge(20);
        friend1.setOnline(true);
        friend1.setUserId(1);
        friend1.setName("");
        Random random = new Random();
        int a = random.nextInt(5);
        friend1.setFriendsGroupId(a);

        Friends friend0 = new Friends();
        friend0.setId(0);
        friend0.setAge(20);
        friend0.setOnline(true);
        friend0.setUserId(0);
        friend0.setName("");
        friend0.setFriendsGroupId(a);

        if ("0".equals(recMsg.getFromId())) {
            friends.add(friend1);
        } else if ("1".equals(recMsg.getFromId())) {
            friends.add(friend0);
        }

        sendMsg.setToId(recMsg.getFromId());
        sendMsg.setContent(JsonUtil.toJson(friends));
        sendMsg.setDate(new Date());
        sendMsg.setFromId("system");
        sendMsg.setMsgType(Constants.MYMSG_TYPE_GETFRIENDS_RESP);
        sendMsgs = JsonUtil.toJson(sendMsg);

        toTopic = recMsg.getFromId();

        try {
            MQTTPublisher getFriendsPublisher = new MQTTPublisher(toTopic, sendMsgs,
                    clientId + "-MYMSG_TYPE_LOGIN_RESP" + rand.nextInt(100000), true);
            new Thread(getFriendsPublisher).start();
            log.info(sendMsgs);
        } catch (MqttException e) {
            e.printStackTrace();
        }
        break;
    case Constants.IOT_TOPOIC_GETFRIENDSGROUP:

        System.out.println("-------IOT_TOPOIC_GETFRIENDSGROUP");
        sendMsg = new MyMessage();
        recMsg = JsonUtil.fromJson(new String(message), MyMessage.class);
        List<FriendsGroup> friendsGroups = new ArrayList<FriendsGroup>();
        for (int i = 0; i < 5; i++) {
            FriendsGroup friendsGroup = new FriendsGroup();
            friendsGroup.setId(i);
            friendsGroup.setName("?" + i);
            friendsGroup.setPosition(i);
            friendsGroups.add(friendsGroup);
        }

        sendMsg.setToId(recMsg.getFromId());
        sendMsg.setContent(JsonUtil.toJson(friendsGroups));
        sendMsg.setDate(new Date());
        sendMsg.setFromId("system");
        sendMsg.setMsgType(Constants.MYMSG_TYPE_GETFRIENDSGROUP_RESP);
        sendMsgs = JsonUtil.toJson(sendMsg);

        toTopic = recMsg.getFromId();

        try {
            MQTTPublisher getFriendsGroupPublisher = new MQTTPublisher(toTopic, sendMsgs,
                    clientId + "-MYMSG_TYPE_LOGIN_RESP" + rand.nextInt(100000), true);
            new Thread(getFriendsGroupPublisher).start();
            log.info(sendMsgs);
        } catch (MqttException e) {
            e.printStackTrace();
        }
        break;
    case Constants.IOT_TOPOIC_LEDCONTROL:
        System.out.println("-------IOT_TOPOIC_LEDCONTROL");
        sendMsg = new MyMessage();

        recMsg = JsonUtil.fromJson(new String(message), MyMessage.class);
        if ("0".equals(recMsg.getContent())) {
            PinState state = ControlGpio.getState();
            if (state == PinState.LOW) {
                ControlGpio.ledOn();
            }
        } else {
            PinState state = ControlGpio.getState();
            if (state == PinState.HIGH) {
                ControlGpio.ledOff();
            }
        }
    default:
        break;
    }
}

From source file:bookUtilities.AddBookServlet.java

private JSONObject addBook(String title, String cover, String author, String genre, String description,
        String language, String publisher, String fileURL) {

    JSONObject messageToReturn = new JSONObject();
    try {//  w  w w  . j  a v a2 s  . c  o m
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw");

        Statement st = con.createStatement();
        Calendar someDate = Calendar.getInstance();
        someDate.setTime(new Date());
        Timestamp stamp = new Timestamp(someDate.getTimeInMillis());
        String query = "DECLARE @newId UNIQUEIDENTIFIER; " + "SET @newid = NEWID(); "
                + "INSERT INTO [HardCover].[dbo].[Book] " + "VALUES (@newid, '" + title + "', '" + cover
                + "', '" + stamp + "', 5, 0, '" + language + "', '" + description + "', '" + publisher
                + "', 1); ";
        String[] authors = author.split(", ");
        String[] genres = genre.split(", ");
        String[] files = fileURL.split(", ");
        for (String s : authors) {
            query += "INSERT INTO [HardCover].[dbo].[Author] (AuthorName, BookId)" + "VALUES('" + s
                    + "', @newid); ";
        }
        for (String s : genres) {
            query += "INSERT INTO [HardCover].[dbo].[Genre] (Genre, BookId)" + "VALUES('" + s + "', @newid); ";
        }
        for (String s : files) {
            query += "INSERT INTO [HardCover].[dbo].[BookFileType] (FileType, DownloadLink, BookId)"
                    + "VALUES('pdf', '" + s + "', @newid); ";
        }
        st.executeUpdate(query);
        messageToReturn.put("message", "success");
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    return messageToReturn;
}

From source file:daos.BetalingDaoTest.java

@Before
public void setUp() {
    dbClearer.clearDatabase();/*from www.  j  ava 2 s .  com*/
    Session session = sessionFactory.openSession();

    session.beginTransaction();

    klant.setVoornaam("Theo");
    klant.setAchternaam("Tester");
    klant.setTussenvoegsel("de");
    klant.setEmail("ttest@nep.com");

    session.save(klant);
    klant.setIdKlant(1);

    b1.setKlant(klant);
    session.save(b1);

    f1.setFactuurDatum(new Timestamp(date.getTime()));
    f1.setBestelling(b1);
    session.save(f1);
    f1.setIdFactuur(1);

    bw.setBetaalwijze(0);
    session.save(bw);
    bw.setIdBetaalwijze(1);

    session.getTransaction().commit();
    session.close();
}

From source file:com.surevine.chat.openfire.audit.dao.JdbcAuditDAO.java

/**
 * {@inheritDoc}.//  w w  w  . j a va 2  s .  c  o m
 */
public void save(final AuditMessage auditMessage) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Saving audit message: " + auditMessage);
    }
    // Values being persisted
    Object[] args = { auditMessage.getEvent().toString(), auditMessage.getSender(), auditMessage.getReceiver(),
            new Timestamp(auditMessage.getEventTime().getTime()), auditMessage.getContent(),
            auditMessage.getSecurityLabel() };
    // SQL types for the arguments being persisted
    int[] argTypes = { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR,
            Types.VARCHAR };
    // Persist the audit message
    jdbcTemplate.update(INSERT, args, argTypes);
}

From source file:org.apache.niolex.config.dao.impl.ItemDaoImpl.java

/**
 * Override super method//w  ww  .jav  a 2  s.c o m
 * @see org.apache.niolex.config.dao.ItemDao#updateConfig(org.apache.niolex.config.bean.ConfigItem)
 */
@Override
public boolean updateConfig(ConfigItem item) {
    final String sql = "update config_info set value = ?, uurid = ? where groupid = ? and ckey = ? and updatetime = ?";
    Object[] param = new Object[] { item.getValue(), item.getuUid(), item.getGroupId(), item.getKey(),
            new Timestamp(item.getUpdateTime()) };
    return template.update(sql, param) > 0;
}

From source file:com.itesm.test.servlets.TasksServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String[] description = request.getParameterValues("description");
    String[] priority = request.getParameterValues("priority");
    String[] task_time = request.getParameterValues("task_time");
    String[] end_time = request.getParameterValues("end_time");
    PersonaVO personavo = (PersonaVO) request.getSession().getAttribute("persona");
    TaskManager taskManager = new TaskManager();
    for (int i = 0; i < priority.length; i++) {
        TaskVO wh = new TaskVO();
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
        SimpleDateFormat sdfTimeStamp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
        Date durationDate = null;
        Date end_date = null;/* w  w  w. ja v  a  2  s  . c  om*/
        try {
            durationDate = sdf.parse(task_time[i]);
            end_date = sdfTimeStamp.parse(end_time[i]);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        wh.setDuration(new Time(durationDate.getTime()));
        wh.setEnd_date(new Timestamp(end_date.getTime()));
        wh.setDescription(description[i]);
        wh.setPriority(Integer.parseInt(priority[i]));
        wh.setAgenda_id(personavo.getAgenda_id());
        System.out.println(wh.toString());
        taskManager.agregar(wh);
    }
    CreateSchedule createSchedule = new CreateSchedule(personavo);
    createSchedule.createSchedule();
    TaskDAO taskDAO = new TaskDAO();
    List<TaskVO> task_list = taskDAO.findByAgenda(personavo.getAgenda_id());
    ListIterator listIterator = task_list.listIterator();
    while (listIterator.hasNext()) {
        TaskVO task = (TaskVO) listIterator.next();
        if (task.getWork_hours_id() == null) {
            listIterator.remove();
        }
    }

    WorkHoursManager workHoursManager = new WorkHoursManager();
    List<WorkHoursVO> worksHours_list = workHoursManager.consultarPorAgenda(personavo.getAgenda_id());
    request.setAttribute("tasks", task_list);
    request.setAttribute("works", worksHours_list);
    RequestDispatcher rd = getServletContext().getRequestDispatcher("/schedule.jsp");
    rd.forward(request, response);

}

From source file:isl.FIMS.servlet.export.ExportSchema.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// ww w.j  a  v  a  2s .  c o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
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 {
            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("ExportSchema");
            String type = request.getParameter("type");
            request.setCharacterEncoding("UTF-8");

            ServletOutputStream outStream = response.getOutputStream();
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=\"" + "Schema_" + type + ".zip\"");
            File schemaFile = new File(this.schemaFolder + type + ".xsd");
            FileUtils.copyFile(schemaFile,
                    new File(currentDir + System.getProperty("file.separator") + type + ".xsd"));
            Utils.copySchemaReferences(this.schemaFolder + type + ".xsd", currentDir);

            File f = new File(currentDir + System.getProperty("file.separator") + "zip");
            f.mkdir();
            String zip = f.getAbsolutePath() + System.getProperty("file.separator") + "Schema_" + type + ".zip";

            Utils.createZip(zip, currentDir);
            Utils.downloadZip(outStream, new File(zip));

            Utils.deleteDir(currentDir);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:data.DefaultExchanger.java

protected Timestamp timestamp(long time) {
    if (time == 0l) {
        return null;
    } else {/* w  ww  .jav a  2  s  .c  o m*/
        return new Timestamp(time);
    }
}