Example usage for java.sql Time Time

List of usage examples for java.sql Time Time

Introduction

In this page you can find the example usage for java.sql Time Time.

Prototype

public Time(long time) 

Source Link

Document

Constructs a Time object using a milliseconds time value.

Usage

From source file:com.github.nmorel.gwtjackson.shared.options.DateOptionsTester.java

public void testSerializeDatesAsTimestamps(ObjectWriterTester<BeanWithDates> writer) {
    BeanWithDates bean = new BeanWithDates();
    bean.date = new Date(1345304756540l);
    bean.onlyDate = new Date(1345304756540l);
    bean.onlyDateTz = new Date(1345304756540l);
    bean.sqlDate = new java.sql.Date(1345304756541l);
    bean.sqlTime = new Time(1345304756542l);
    bean.sqlTimestamp = new Timestamp(1345304756543l);

    Map<Date, String> mapDate = new HashMap<Date, String>();
    mapDate.put(new Date(1345304756544l), "java.util.Date");
    bean.mapDate = mapDate;/*from  w  w w  .j av  a2  s .  com*/

    Map<java.sql.Date, String> mapSqlDate = new HashMap<java.sql.Date, String>();
    mapSqlDate.put(new java.sql.Date(1345304756545l), "java.sql.Date");
    bean.mapSqlDate = mapSqlDate;

    Map<Time, String> mapSqlTime = new HashMap<Time, String>();
    mapSqlTime.put(new Time(1345304756546l), "java.sql.Time");
    bean.mapSqlTime = mapSqlTime;

    Map<Timestamp, String> mapSqlTimestamp = new HashMap<Timestamp, String>();
    mapSqlTimestamp.put(new Timestamp(1345304756547l), "java.sql.Timestamp");
    bean.mapSqlTimestamp = mapSqlTimestamp;

    String expected = "{" + "\"date\":1345304756540," + "\"onlyDate\":\"/2012/08/18/\","
            + "\"onlyDateTz\":\"/2012/08/18/ +0000\"," + "\"sqlDate\":\"" + bean.sqlDate.toString() + "\","
            + "\"sqlTime\":\"" + bean.sqlTime.toString() + "\"," + "\"sqlTimestamp\":1345304756543,"
            + "\"mapDate\":{\"1345304756544\":\"java.util.Date\"},"
            + "\"mapSqlDate\":{\"1345304756545\":\"java.sql.Date\"},"
            + "\"mapSqlTime\":{\"1345304756546\":\"java.sql.Time\"},"
            + "\"mapSqlTimestamp\":{\"1345304756547\":\"java.sql.Timestamp\"}" + "}";

    assertEquals(expected, writer.write(bean));
}

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  va 2s. c o  m*/
        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:adalid.commons.util.TimeUtils.java

public static synchronized Time currentTime() {
    calendar.setTimeInMillis(currentTimeMillis());
    calendar.set(Calendar.YEAR, 1970);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    return new Time(calendar.getTimeInMillis());
}

From source file:com.qagen.osfe.core.utils.BeanPopulator.java

private static Time getTime(String name, String value, String format) {
    try {// w w  w  .j av  a  2 s  .co  m
        if ((format == null) || (format.trim().length() == 0)) {
            final String message = "Column, " + name
                    + " is define as a Time and must the attribute, format, defined.";
            throw new FeedErrorException(message);
        }

        final SimpleDateFormat formatter = new SimpleDateFormat(format);
        return new Time(formatter.parse(value).getTime());

    } catch (ParseException e) {
        throw new FeedErrorException(e);
    }
}

From source file:javasnack.cli.CliDbUnitCsvExportDemo.java

void setup(Connection conn) throws Exception {

    new T1().setup(conn);
    Calendar c = Calendar.getInstance();

    c.clear();//from  w  w  w.j  a  v  a2s.c om
    c.set(2000, 11, 31, 23, 59, 59);
    long insertTIM = c.getTimeInMillis();
    new T1(true, 10, new BigDecimal(20), 30.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \"World\"!").insertMe(conn);

    c.clear();
    c.set(2001, 0, 1, 12, 30, 15);
    insertTIM = c.getTimeInMillis();
    new T1(false, 20, new BigDecimal(30), 40.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \n\"World\"!").insertMe(conn);

    new T2().setup(conn);
    new T2(UnsignedByte.create0x00to0xFFString(), UnsignedByte.create0x00to0xFF(),
            UnsignedByte.create0x00to0xFF()).insertMe(conn);
}

From source file:com.qihang.winter.poi.excel.imports.CellValueServer.java

/**
 * ??//  w  ww . j  av  a2  s  . c  o m
 * 
 * @param xclass
 * @param cell
 * @param entity
 * @return
 */
private Object getCellValue(String xclass, Cell cell, ExcelImportEntity entity) {
    if (cell == null) {
        return "";
    }
    Object result = null;
    // ?,cell??
    if ("class java.util.Date".equals(xclass) || ("class java.sql.Time").equals(xclass)) {
        if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
            // ?
            result = cell.getDateCellValue();
        } else {
            cell.setCellType(Cell.CELL_TYPE_STRING);
            result = getDateData(entity, cell.getStringCellValue());
        }
        if (("class java.sql.Time").equals(xclass)) {
            result = new Time(((Date) result).getTime());
        }
    } else if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        result = cell.getNumericCellValue();
    } else if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) {
        result = cell.getBooleanCellValue();
    } else {
        result = cell.getStringCellValue();
    }
    return result;
}

From source file:TestPublicarEstablecimiento.java

@Test
@Transactional/*from  w  w  w.  j av a2s.  c om*/
@Rollback(true)
public void testRegistrarHabilitacionEstablecimiento() throws OperationFailedException {
    int limite = 100;
    ArrayList<Establecimiento> listaEsta = new ArrayList<>();
    for (int i = 50; i < limite; i++) {
        Establecimiento a = new Establecimiento(i, "nombre" + i, i + "3.123.123-1 sin revisar", "Autonorte" + i,
                new Time(700), new Time(1800), 2.0, "Puente Aranda", "1234567890", "34329084392084320939");
        listaEsta.add(a);
        logica.registrarEstablecimiento(a);
    }

    Establecimiento fd;
    for (int i = 50; i < limite; i++) {
        fd = logica.consultarEstablecimientoHabilitado(i);
        assertEquals(null, fd);
    }
    for (int i = 50; i < limite; i++) {
        logica.habilitarEstablecimiento(i);
        fd = logica.consultarEstablecimientoHabilitado(i);
        assertEquals(listaEsta.get(i - 50).getIdEstablecimiento(), fd.getIdEstablecimiento());
        assertEquals(listaEsta.get(i - 50).getNombre(), fd.getNombre());
        assertTrue(listaEsta.get(i - 50).getNit() != fd.getNit());
        assertEquals(listaEsta.get(i - 50).getDireccion(), fd.getDireccion());
        assertEquals(listaEsta.get(i - 50).getHoraInicio(), fd.getHoraInicio());
        assertEquals(listaEsta.get(i - 50).getHoraCierre(), fd.getHoraCierre());
        assertEquals(listaEsta.get(i - 50).getLocalidad(), fd.getLocalidad());
        assertEquals(listaEsta.get(i - 50).getTelefono(), fd.getTelefono());
    }
}

From source file:cp.server.app.ClientMultiThreadedExecution.java

public static void fetch() throws Exception {
    // Create an HttpClient with the ThreadSafeClientConnManager.
    // This connection manager must be used if more than one thread will
    // be using the HttpClient.
    // PoolingHttpClientConnectionManager cm = new
    // PoolingHttpClientConnectionManager();
    // cm.setMaxTotal(100);

    // CloseableHttpClient httpclient = HttpClients.custom()
    // .setConnectionManager(cm).build();
    ExecutorService pool = Executors.newFixedThreadPool(10);
    ServerDAO dao = new ServerDAO();
    List<Page> pages = null;
    Time ts = new Time(System.currentTimeMillis());
    int interval;

    try {/*from   w ww.ja  v a  2 s. co m*/
        // // before 10am, query with the comment yesterday
        // if (Integer.valueOf(ts.toString().substring(0, 2)) > 10)
        // {
        // interval = 1;
        // }
        // else
        // {
        // interval = 2;
        // }
        //
        // pages = dao.queryPagesByDayInterval(
        // ConnectionFactory.getConnection(), interval);
        //
        // System.out.println("load comments from " + pages.size() +
        // "pages.");
        // for (Page page : pages)
        // {
        // PAGESTACK.push(page.getUrl());
        // }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        // create an array of URIs to perform GETs on
        String[] urisToGet = { "http://sports.sina.com.cn", "http://news.sina.com.cn", "http://ent.sina.com.cn",
                "http://tech.sina.com.cn", "http://sports.sina.com.cn/o/2013-10-27/04016852444.shtml",
                "http://finance.sina.com.cn/china/20131027/043917125695.shtml",
                "http://sports.sina.com.cn/j/2013-10-27/06336852561.shtml",
                "http://sports.sina.com.cn/j/2013-10-26/21006851844.shtml" };

        for (int i = 0; i < 10000; i++) {
            for (int j = 0; j < urisToGet.length; j++) {
                PAGESTACK.push(urisToGet[j]);
            }
        }

        CountDownLatch cdl = new CountDownLatch(6);

        // create a thread for each URI
        GetThread[] threads = new GetThread[urisToGet.length];

        for (int i = 0; i < 4; i++) {
            // HttpGet httpget = new HttpGet(urisToGet[i]);
            threads[i] = new GetThread(urisToGet[i], i + 1, cdl);
        }

        // start the threads
        for (int j = 0; j < 4; j++) {
            pool.execute(threads[j]);
            // threads[j].start();
        }

        cdl.await();

    } finally {
        // httpclient.close();
        pool.shutdown();
    }
}

From source file:edu.eci.cosw.restcontrollers.RestControladorRegistrarReserva.java

@RequestMapping(value = "/prueba", method = RequestMethod.GET)
public Reservacion prueba() {
    Establecimiento tds = new Establecimiento(1, "nombnre", "123.123.123-1", "dsfdssdhfsfd", "dfdff-- -- - -",
            new Time(123), new Time(2345), 32.4, "dsfdssdffsdfsd", "35535345", "28947323473283984724",
            new HashSet<Instrumento>(), new HashSet<Sala>());
    Sala s = new Sala(2, tds, "dsfdsfds", "sadsaasdasdas", "dffsdfdss", new HashSet<Reservacion>());
    Reservacion d = new Reservacion(1, s, new Date(234), new Time(5), 43, new HashSet<Alquiler>());
    return d;/*from  ww  w.  j a v a  2  s.  co  m*/
}

From source file:org.sakaiproject.test.section.dataload.DataLoadTest.java

public void testLoadData() {
    // Load courses
    Course course1 = courseManager.createCourse("site1", "A Course for Site #1", false, false, true);
    Course course2 = courseManager.createCourse("site2", "A Course for Site #2", false, false, false);
    Course course3 = courseManager.createCourse("site3", "A Course for Site #3", false, false, false);

    // Load sections
    CourseSection lab1 = sectionManager.addSection(course1.getUuid(), "Lab 1", "section.category.lab",
            Integer.valueOf(20), "Dank basement lab", new Time(new Date().getTime()),
            new Time(new Date().getTime()), true, false, true, false, false, false, false);
    CourseSection lab2 = sectionManager.addSection(course1.getUuid(), "Lab 2", "section.category.lab",
            Integer.valueOf(20), "Dank basement lab", new Time(new Date().getTime()),
            new Time(new Date().getTime()), false, true, false, true, false, false, false);
    CourseSection disc1 = sectionManager.addSection(course1.getUuid(), "Disc 1", "section.category.discussion",
            Integer.valueOf(30), "Sunny classroom", new Time(new Date().getTime()),
            new Time(new Date().getTime()), true, false, true, false, true, false, false);

    // Load students
    User studenta = userManager.createUser("studenta", "Joe Student", "Student, Joe", "jstudent");
    User studentb = userManager.createUser("studentb", "Jane Undergrad", "Undergrad, Jane", "jundergrad");
    User studentc = userManager.createUser("studentc", "Max Guest", "Guest, Max", "mguest");

    List studentList = new ArrayList();
    for (int i = 0; i < 100; i++) {
        studentList.add(userManager.createUser("student" + i, "Test Student " + i, "Student, Test " + i,
                "tstudent" + i));
    }// w w  w  . jav a2s  . c  o  m

    // Load TAs
    User ta1 = userManager.createUser("ta1", "Mike Grad", "Grad, Mike", "mgrad");
    User ta2 = userManager.createUser("ta2", "Sara Hyphenated-Elongated-Postdoc",
            "Hyphenated-Elongated-Postdoc, Sara", "shyphenatedelongatedpostdoc");

    // Load instructors
    User instructor1 = userManager.createUser("instructor1", "Bill Economist", "Economist, Bill", "beconomist");
    User instructor2 = userManager.createUser("instructor2", "Amber Philosopher", "Philosopher, Amber",
            "aphilosopher");

    // Load other people
    userManager.createUser("other1", "Other Person", "Person, Other", "operson");

    // Load enrollments into the courses
    courseManager.addEnrollment(studenta, course1);
    courseManager.addEnrollment(studenta, course2);
    courseManager.addEnrollment(studenta, course3);

    courseManager.addEnrollment(studentb, course1);
    courseManager.addEnrollment(studentb, course2);
    courseManager.addEnrollment(studentb, course3);

    courseManager.addEnrollment(studentc, course1);
    courseManager.addEnrollment(studentc, course2);
    courseManager.addEnrollment(studentc, course3);

    for (Iterator iter = studentList.iterator(); iter.hasNext();) {
        User user = (User) iter.next();
        courseManager.addEnrollment(user, course1);
        courseManager.addEnrollment(user, course2);
        courseManager.addEnrollment(user, course3);
    }

    // Load enrollments into sections
    try {
        sectionManager.addSectionMembership("studenta", Role.STUDENT, lab1.getUuid());
        sectionManager.addSectionMembership("studentb", Role.STUDENT, lab2.getUuid());
        sectionManager.addSectionMembership("studentc", Role.STUDENT, disc1.getUuid());
    } catch (RoleConfigurationException rce) {
        log.error(rce);
        fail();
    }

    // Load TAs into the course
    courseManager.addTA(ta1, course1);
    courseManager.addTA(ta1, course2);
    courseManager.addTA(ta1, course3);

    courseManager.addTA(ta2, course1);
    courseManager.addTA(ta2, course2);
    courseManager.addTA(ta2, course3);

    // Load TAs into the sections
    try {
        sectionManager.addSectionMembership("ta1", Role.TA, lab1.getUuid());
        sectionManager.addSectionMembership("ta1", Role.TA, disc1.getUuid());
        sectionManager.addSectionMembership("ta2", Role.TA, lab2.getUuid());
        sectionManager.addSectionMembership("ta2", Role.TA, disc1.getUuid());
    } catch (RoleConfigurationException rce) {
        log.error(rce);
        fail();
    }

    // Load instructors into the courses
    courseManager.addInstructor(instructor1, course1);
    courseManager.addInstructor(instructor2, course2);
    courseManager.addInstructor(instructor2, course3);
}