List of usage examples for java.sql Date compareTo
public int compareTo(Date anotherDate)
From source file:Main.java
public static boolean validateBefor(Date d1, Date d2) { if (d1 == null || d2 == null) return false; return d1.compareTo(d2) >= 0; }
From source file:adalid.commons.util.ObjUtils.java
public static Integer compare(Object x, Object y) { if (x == null || y == null) { return null; }/* w w w.ja v a 2 s.co m*/ if (x instanceof Boolean && y instanceof Boolean) { Boolean bx = (Boolean) x; Boolean by = (Boolean) y; return bx.compareTo(by); } if (x instanceof String && y instanceof String) { String sx = (String) x; String sy = (String) y; return sx.compareTo(sy); } if (x instanceof Number && y instanceof Number) { BigDecimal nx = NumUtils.numberToBigDecimal(x); BigDecimal ny = NumUtils.numberToBigDecimal(y); return nx.compareTo(ny); } if (x instanceof java.util.Date && y instanceof java.util.Date) { java.util.Date dx = (java.util.Date) x; java.util.Date dy = (java.util.Date) y; return dx.compareTo(dy); } if (x instanceof String || y instanceof String) { String sx = toString(x); String sy = toString(y); if (sx != null && sy != null) { return sx.compareTo(sy); } } return null; }
From source file:com.intelligentz.appointmentz.controllers.addSession.java
@SuppressWarnings("Since15") @Override// w w w .ja v a 2 s .c o m public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try { String room_id = null; String doctor_id = null; String start_time = null; String date_picked = null; ArrayList<SessonCustomer> sessonCustomers = new ArrayList<>(); DiskFileItemFactory factory = new DiskFileItemFactory(); // maximum size that will be stored in memory factory.setSizeThreshold(maxMemSize); // Location to save data that is larger than maxMemSize. factory.setRepository(new File(filePath + "temp")); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // maximum file size to be uploaded. upload.setSizeMax(maxFileSize); // Parse the request to get file items. List fileItems = upload.parseRequest(req); // Process the uploaded file items Iterator i = fileItems.iterator(); while (i.hasNext()) { FileItem fi = (FileItem) i.next(); if (!fi.isFormField()) { // Get the uploaded file parameters String fieldName = fi.getFieldName(); String fileName = fi.getName(); String contentType = fi.getContentType(); boolean isInMemory = fi.isInMemory(); long sizeInBytes = fi.getSize(); // Write the file if (fileName.lastIndexOf("\\") >= 0) { filePath = filePath + fileName.substring(fileName.lastIndexOf("\\")); file = new File(filePath); } else { filePath = filePath + fileName.substring(fileName.lastIndexOf("\\") + 1); file = new File(filePath); } fi.write(file); Files.lines(Paths.get(filePath)).forEach((line) -> { String[] cust = line.split(","); sessonCustomers.add(new SessonCustomer(cust[0].trim(), Integer.parseInt(cust[1].trim()))); }); } else { if (fi.getFieldName().equals("room_id")) room_id = fi.getString(); else if (fi.getFieldName().equals("doctor_id")) doctor_id = fi.getString(); else if (fi.getFieldName().equals("start_time")) start_time = fi.getString(); else if (fi.getFieldName().equals("date_picked")) date_picked = fi.getString(); } } con = new connectToDB(); if (con.connect()) { Connection connection = con.getConnection(); Class.forName("com.mysql.jdbc.Driver"); Statement stmt = connection.createStatement(); String SQL, SQL1, SQL2; SQL1 = "insert into db_bro.session ( doctor_id, room_id, date, start_time) VALUES (?,?,?,?)"; PreparedStatement preparedStmt = connection.prepareStatement(SQL1); preparedStmt.setString(1, doctor_id); preparedStmt.setString(2, room_id); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH:mm"); try { java.util.Date d = formatter.parse(date_picked + "-" + start_time); Date d_sql = new Date(d.getTime()); java.util.Date N = new java.util.Date(); if (N.compareTo(d) > 0) { res.sendRedirect("./error.jsp?error=Invalid Date!"); } //String [] T = start_time.split(":"); //Time t = Time.valueOf(start_time); //Time t = new Time(Integer.parseInt(T[0]),Integer.parseInt(T[1]),0); //java.sql.Time t_sql = new java.sql.Date(d.getTime()); preparedStmt.setString(4, start_time + ":00"); preparedStmt.setDate(3, d_sql); } catch (ParseException e) { displayMessage(res, "Invalid Date!" + e.getLocalizedMessage()); } // execute the preparedstatement preparedStmt.execute(); SQL = "select * from db_bro.session ORDER BY session_id DESC limit 1"; ResultSet rs = stmt.executeQuery(SQL); boolean check = false; while (rs.next()) { String db_doctor_id = rs.getString("doctor_id"); String db_date_picked = rs.getString("date"); String db_start_time = rs.getString("start_time"); String db_room_id = rs.getString("room_id"); if ((doctor_id == null ? db_doctor_id == null : doctor_id.equals(db_doctor_id)) && (start_time == null ? db_start_time == null : (start_time + ":00").equals(db_start_time)) && (room_id == null ? db_room_id == null : room_id.equals(db_room_id)) && (date_picked == null ? db_date_picked == null : date_picked.equals(db_date_picked))) { check = true; //displayMessage(res,"Authentication Success!"); SQL2 = "insert into db_bro.session_customers ( session_id, mobile, appointment_num) VALUES (?,?,?)"; for (SessonCustomer sessonCustomer : sessonCustomers) { preparedStmt = connection.prepareStatement(SQL2); preparedStmt.setString(1, rs.getString("session_id")); preparedStmt.setString(2, sessonCustomer.getMobile()); preparedStmt.setInt(3, sessonCustomer.getAppointment_num()); preparedStmt.execute(); } try { connection.close(); } catch (SQLException e) { displayMessage(res, "SQLException"); } res.sendRedirect("./home"); } } if (!check) { try { connection.close(); } catch (SQLException e) { displayMessage(res, "SQLException"); } displayMessage(res, "SQL query Failed!"); } } else { con.showErrormessage(res); } /*res.setContentType("text/html");//setting the content type PrintWriter pw=res.getWriter();//get the stream to write the data //writing html in the stream pw.println("<html><body>"); pw.println("Welcome to servlet: "+username); pw.println("</body></html>"); pw.close();//closing the stream */ } catch (Exception ex) { Logger.getLogger(authenticate.class.getName()).log(Level.SEVERE, null, ex); displayMessage(res, "Error!" + ex.getLocalizedMessage()); } }
From source file:com.sfs.whichdoctor.dao.ItemDAOImpl.java
/** * Used to get a TreeMap of ItemBean details for a specified GUID number. * * @param guid the guid/*from ww w .j av a2s . com*/ * @param fullResults the full results * @param itemTypeVal the item type value * @param groupClassVal the group class value * @param object2GUID the object2 guid * @param startDate the start date * @param endDate the end date * * @return the tree map< string, item bean> * * @throws WhichDoctorDaoException the which doctor dao exception */ @SuppressWarnings("unchecked") public final TreeMap<String, ItemBean> load(final int guid, final boolean fullResults, final String itemTypeVal, final String groupClassVal, final int object2GUID, final String startDate, final String endDate) throws WhichDoctorDaoException { TreeMap<String, ItemBean> items = new TreeMap<String, ItemBean>(); String itemType = "Group"; String groupClass = "Members"; if (itemTypeVal != null) { itemType = itemTypeVal; } if (groupClass != null) { groupClass = groupClassVal; } if (StringUtils.equalsIgnoreCase(itemType, "Employer") || StringUtils.equalsIgnoreCase(itemType, "Employee")) { itemType = "Employment"; } java.util.Date dtStartDate = null; java.util.Date dtEndDate = null; DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK); try { dtStartDate = df.parse(startDate); } catch (Exception e) { dataLogger.debug("Error parsing start date: " + e.getMessage()); } try { dtEndDate = df.parse(endDate); } catch (Exception e) { dataLogger.debug("Error parsing end date: " + e.getMessage()); } if (dtStartDate != null && dtEndDate != null && dtStartDate.compareTo(dtEndDate) > 0) { /* Start date is greater than end date, switch around */ java.util.Date tempStartDate = dtStartDate; dtStartDate = dtEndDate; dtEndDate = tempStartDate; } StringBuffer loadItems = new StringBuffer(); ArrayList<Object> parameters = new ArrayList<Object>(); parameters.add(guid); parameters.add(itemType); loadItems.append(getLoadSQL(groupClass)); if (StringUtils.equalsIgnoreCase(groupClass, "Employers")) { loadItems.append(" AND items.Object2GUID = ? AND itemtype.Class = ?"); } else { loadItems.append(" AND items.Object1GUID = ? AND itemtype.Class = ?"); } if (object2GUID > 0) { loadItems.append(" AND items.Object2GUID = ?"); parameters.add(object2GUID); } dataLogger.info("Items for GUID: " + guid + " requested"); Collection<ItemBean> itemCollection = new ArrayList<ItemBean>(); try { itemCollection = this.getJdbcTemplateReader().query(loadItems.toString(), parameters.toArray(), new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadItem(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } for (ItemBean item : itemCollection) { if (item.display(dtStartDate, dtEndDate)) { items.put(item.getOrderIndex(), item); } } return items; }
From source file:com.mss.mirage.employee.general.EmployeeAction.java
public String myQuarterlyAppraisalEdit() { resultType = LOGIN;//from w w w. j a v a 2 s . c om if (httpServletRequest.getSession(false) != null && httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_USER_ID) != null) { userRoleId = Integer.parseInt(httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_ROLE_ID).toString()); loginId = httpServletRequest.getSession(false).getAttribute(ApplicationConstants.SESSION_USER_ID) .toString(); int isManager = Integer.parseInt(httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_IS_USER_MANAGER).toString()); // String workingCountry = httpServletRequest.getSession(false).getAttribute(ApplicationConstants.WORKING_COUNTRY).toString(); String livingCountry = httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.Living_COUNTRY).toString(); String userRoleName = httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_ROLE_NAME).toString(); resultType = "accessFailed"; if (AuthorizationManager.getInstance().isAuthorizedUser("QUARTERLY_APPRAISAL", userRoleId)) { try { boolean accessAllow = false; if (getEmpId() != 0 && getAppraisalId() != 0 && getLineId() != 0) { String emploginId = DataSourceDataProvider.getInstance().getLoginIdByEmpId(getEmpId()); Map myTeamMemebrs = new HashMap(); Map rolesMap = (Map) httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_MY_ROLES); String department = httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_MY_DEPT_ID).toString(); String access[] = Properties.getProperty("QuarterlyAppraisal.Access") .split(Pattern.quote(",")); List accessList = Arrays.asList(access); int sessionEmpId = Integer.parseInt(httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_EMP_ID).toString()); if (getCurretRole() != null && getCurretRole().equals("my")) { if (sessionEmpId == getEmpId()) { accessAllow = true; } } else if (getCurretRole() != null && getCurretRole().equals("team")) { String roleName = httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_ROLE_NAME).toString(); if (loginId.equals("rkalaga")) { accessAllow = true; } else if ((roleName.equals("Operations") && accessList.contains(loginId)) || (department.equals("Operations") && isManager == 1) || rolesMap.containsValue("Admin")) { accessAllow = true; } else { if (roleName.equalsIgnoreCase("Employee") && isManager == 1) { myTeamMemebrs = (Map) httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_MY_TEAM_MAP); if (myTeamMemebrs.containsKey(emploginId)) { accessAllow = true; } } if (roleName.equalsIgnoreCase("Operations")) { myTeamMemebrs = DataSourceDataProvider.getInstance().getInstance() .getEmployeeNamesByOperationsContactId((httpServletRequest .getSession(false) .getAttribute(ApplicationConstants.SESSION_EMP_ID).toString())); if (myTeamMemebrs.containsKey(emploginId)) { accessAllow = true; } } } } if (accessAllow) { // String quarterAppraisalDetails = ServiceLocator.getEmployeeService().getEmployeeResumeLocation(getId()); String result = ServiceLocator.getEmployeeService().quarterlyAppraisalEdit(getEmpId(), getAppraisalId(), getLineId()); setQuarterAppraisalDetails(result.split(Pattern.quote("@^$"))[0]); String remainingData[] = (result.split(Pattern.quote("@^$"))[1]) .split(Pattern.quote("#^$")); if (remainingData[0] != null && !"".equals(remainingData[0]) && !"_".equals(remainingData[0])) { setShortTermGoal(remainingData[0]); } if (remainingData[1] != null && !"".equals(remainingData[1]) && !"_".equals(remainingData[1])) { setShortTermGoalComments(remainingData[1]); } if (remainingData[2] != null && !"".equals(remainingData[2]) && !"_".equals(remainingData[2])) { setLongTermGoal(remainingData[2]); } if (remainingData[3] != null && !"".equals(remainingData[3]) && !"_".equals(remainingData[3])) { setLongTermGoalComments(remainingData[3]); } if (remainingData[4] != null && !"".equals(remainingData[4]) && !"_".equals(remainingData[4])) { setStrength(remainingData[4]); } if (remainingData[5] != null && !"".equals(remainingData[5]) && !"_".equals(remainingData[5])) { setStrengthsComments(remainingData[5]); } if (remainingData[6] != null && !"".equals(remainingData[6]) && !"_".equals(remainingData[6])) { setImprovements(remainingData[6]); } if (remainingData[7] != null && !"".equals(remainingData[7]) && !"_".equals(remainingData[7])) { setImprovementsComments(remainingData[7]); } if (remainingData[8] != null && !"".equals(remainingData[8]) && !"_".equals(remainingData[8])) { setOperationTeamStatus(remainingData[8]); } if (remainingData[9] != null && !"".equals(remainingData[9]) && !"_".equals(remainingData[9])) { setManagerRejectedComments(remainingData[9]); } if (remainingData[10] != null && !"".equals(remainingData[10]) && !"_".equals(remainingData[10])) { setOperationRejectedComments(remainingData[10]); } java.util.Date approvedDate = null; java.util.Date opeartionApprovedDate = null; if (remainingData[11] != null && !"".equals(remainingData[11]) && !"_".equals(remainingData[11])) { approvedDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(remainingData[11]); } if (remainingData[12] != null && !"".equals(remainingData[12]) && !"_".equals(remainingData[12])) { opeartionApprovedDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") .parse(remainingData[12]); } if (remainingData[13] != null && !"".equals(remainingData[13]) && !"_".equals(remainingData[13])) { setQuarterly(remainingData[13]); } if (remainingData[14] != null && !"".equals(remainingData[14]) && !"_".equals(remainingData[14])) { setStatus(remainingData[14]); } if (remainingData[15] != null && !"".equals(remainingData[15]) && !"_".equals(remainingData[15])) { setCurrStatus(remainingData[15]); } else { setCurrStatus(""); } if (approvedDate == null && opeartionApprovedDate == null) { setDayCount(0); } else { if (opeartionApprovedDate == null) { setDayCount(1); } else { if (approvedDate.compareTo(opeartionApprovedDate) > 0) { setDayCount(1); } else { setDayCount(2); } } } // setDeliveryKeyFactorsList(DataSourceDataProvider.getInstance().getDeliveryFactors()); // setTrainingKeyFactorsList(DataSourceDataProvider.getInstance().getTrainingFactors()); List empdetails = DataSourceDataProvider.getInstance() .getEmployeeInfoById(String.valueOf(empId)); if (empdetails.size() > 0) { setEmpName((String) empdetails.get(0)); setItgBatch((String) empdetails.get(1)); setEmpDateOFBirth((String) empdetails.get(2)); setPracticeId((String) empdetails.get(4)); setTitleId((String) empdetails.get(5)); if (isManager == 1) { setIsManager(true); } else { setIsManager(false); } } if (getCurretRole() == null || !getCurretRole().equals("team")) { setCurretRole("my"); } if (accessList.contains(loginId) || (department.equals("Operations") && isManager == 1) || rolesMap.containsValue("Admin")) { setAccessCount(1); } // searchPrepare(); // prepare(); resultType = SUCCESS; } } } catch (Exception ex) { //List errorMsgList = ExceptionToListUtility.errorMessages(ex); ex.printStackTrace(); httpServletRequest.getSession(false).setAttribute("errorMessage", ex.toString()); resultType = ERROR; } } //END-Authorization Checking } //Close Session Checking /* if (httpServletRequest.getParameter("quarterly") != null) { String empId = httpServletRequest.getParameter("empId"); String lineId = httpServletRequest.getParameter("lineId"); String appraisalId = httpServletRequest.getParameter("appraisalId"); String quarterly = httpServletRequest.getParameter("quarterly"); setEmpId(Integer.parseInt(empId)); setLineId(Integer.parseInt(lineId)); setAppraisalId(Integer.parseInt(appraisalId)); setQuarterly(quarterly); } */ return resultType; }
From source file:org.apache.hadoop.hive.ql.udf.UDFOPEqualOrGreaterThan.java
public Boolean evaluate(Date a, Date b) { Boolean r = null;/* ww w . j av a2s . c o m*/ if ((a == null) || (b == null)) { r = null; } else { r = Boolean.valueOf(a.compareTo(b) >= 0); } // LOG.info("evaluate(" + a + "," + b + ")=" + r); return r; }
From source file:org.apache.hadoop.hive.ql.udf.UDFOPEqualOrLessThan.java
public Boolean evaluate(Date a, Date b) { Boolean r = null;/* w ww . j a v a 2 s . c o m*/ if ((a == null) || (b == null)) { r = null; } else { r = Boolean.valueOf(a.compareTo(b) <= 0); } // LOG.info("evaluate(" + a + "," + b + ")=" + r); return r; }
From source file:org.apache.hadoop.hive.ql.udf.UDFOPGreaterThan.java
public Boolean evaluate(Date a, Date b) { Boolean r = null;// w w w. j av a2s . c om if ((a == null) || (b == null)) { r = null; } else { r = Boolean.valueOf(a.compareTo(b) > 0); } // LOG.info("evaluate(" + a + "," + b + ")=" + r); return r; }
From source file:org.apache.hadoop.hive.ql.udf.UDFOPLessThan.java
public Boolean evaluate(Date a, Date b) { Boolean r = null;//from www . ja v a 2s . c om if ((a == null) || (b == null)) { r = null; } else { r = Boolean.valueOf(a.compareTo(b) < 0); } // LOG.info("evaluate(" + a + "," + b + ")=" + r); return r; }
From source file:org.apache.hive.storage.jdbc.spitter.DateIntervalSplitter.java
@Override public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo typeInfo) {/*from ww w.j ava2 s. c om*/ List<MutablePair<String, String>> intervals = new ArrayList<>(); Date dateLower = Date.valueOf(lowerBound); Date dateUpper = Date.valueOf(upperBound); double dateInterval = (dateUpper.getTime() - dateLower.getTime()) / (double) numPartitions; Date splitDateLower, splitDateUpper; for (int i = 0; i < numPartitions; i++) { splitDateLower = new Date(Math.round(dateLower.getTime() + dateInterval * i)); splitDateUpper = new Date(Math.round(dateLower.getTime() + dateInterval * (i + 1))); if (splitDateLower.compareTo(splitDateUpper) < 0) { intervals .add(new MutablePair<String, String>(splitDateLower.toString(), splitDateUpper.toString())); } } return intervals; }