List of usage examples for java.sql Date toString
@SuppressWarnings("deprecation") public String toString()
From source file:org.jtotus.database.LocalJDBC.java
public HashMap<String, Double> fetchPeriodAsMap(String tableName, DateTime startDate, DateTime endDate) { HashMap<String, Double> retMap = new HashMap<String, Double>(); BigDecimal retValue = null;//from w ww .ja va2 s .c o m PreparedStatement pstm = null; java.sql.Date retDate = null; ResultSet results = null; Connection connection = null; try { String query = "SELECT CLOSE, DATE FROM " + this.normTableName(tableName) + " WHERE DATE>=? AND DATE<=? ORDER BY DATE ASC"; // this.createTable(connection, this.normTableName(tableName)); connection = this.getConnection(); pstm = connection.prepareStatement(query); java.sql.Date startSqlDate = new java.sql.Date(startDate.getMillis()); pstm.setDate(1, startSqlDate); java.sql.Date endSqlDate = new java.sql.Date(endDate.getMillis()); pstm.setDate(2, endSqlDate); System.out.printf("fetchPeriod : %s : %s\n", startSqlDate, endSqlDate); DateIterator iter = new DateIterator(startDate, endDate); results = pstm.executeQuery(); DateTime dateCheck; while (results.next()) { retValue = results.getBigDecimal(1); retDate = results.getDate(2); if (retValue == null || retDate == null) { System.err.println("Database is corrupted!"); System.exit(-1); } if (iter.hasNext()) { dateCheck = iter.nextInCalendar(); DateTime compCal = new DateTime(retDate.getTime()); if (debug) { if (retValue != null) { System.out.printf("Fetched:\'%s\' from \'%s\' : value:%f date:%s\n", "Closing Price", tableName, retValue.doubleValue(), retDate.toString()); } else { System.out.printf("Fetched:\'%s\' from \'%s\' : value:%s date:%s\n", "Closing Price", tableName, "is null", retDate.toString()); } } if (compCal.getDayOfMonth() == dateCheck.getDayOfMonth() && compCal.getMonthOfYear() == dateCheck.getMonthOfYear() && compCal.getYear() == dateCheck.getYear()) { retMap.put(formatter.print(compCal), retValue.doubleValue()); continue; } while (((compCal.getDayOfMonth() != dateCheck.getDayOfMonth()) || (compCal.getMonthOfYear() != dateCheck.getMonthOfYear()) || (compCal.getYear() != dateCheck.getYear())) && dateCheck.isBefore(compCal)) { if (fetcher != null) { BigDecimal failOverValue = getFetcher().fetchData(tableName, dateCheck, "CLOSE"); if (failOverValue != null) { retMap.put(formatter.print(dateCheck), retValue.doubleValue()); } if (iter.hasNext()) { System.err.printf("Warning : Miss matching dates for: %s - %s\n", retDate.toString(), dateCheck.toString()); dateCheck = iter.nextInCalendar(); continue; } } else { System.err.printf("Fatal missing fetcher : Miss matching dates: %s - %s\n", retDate.toString(), dateCheck.toString()); return null; } } } } while (iter.hasNext()) { retValue = getFetcher().fetchData(tableName, iter.nextInCalendar(), "CLOSE"); if (retValue != null) { retMap.put(formatter.print(iter.getCurrentAsCalendar()), retValue.doubleValue()); } } } catch (SQLException ex) { System.err.printf("LocalJDBC Unable to find date for:'%s' from'%s' Time" + startDate.toDate() + "\n", "Cosing Price", tableName); // ex.printStackTrace(); // SQLException xp = null; // while((xp = ex.getNextException()) != null) { // xp.printStackTrace(); // } } finally { try { if (results != null) results.close(); if (pstm != null) pstm.close(); if (connection != null) connection.close(); // System.out.printf("Max connect:%d in use:%d\n",mainPool.getMaxConnections(), mainPool.getActiveConnections()); // mainPool.dispose(); } catch (SQLException ex) { Logger.getLogger(LocalJDBC.class.getName()).log(Level.SEVERE, null, ex); } } return retMap; }
From source file:com.ichi2.anki.SyncClient.java
private void updateStats(JSONObject stats) { try {/*from w w w .j a va 2 s . c o m*/ // Update global stats Stats globalStats = Stats.globalStats(mDeck); globalStats.updateFromJson(stats.getJSONObject("global")); // Update daily stats Stats stat = new Stats(mDeck); JSONArray remoteDailyStats = stats.getJSONArray("daily"); int len = remoteDailyStats.length(); for (int i = 0; i < len; i++) { // Get a specific daily stat JSONObject remoteStat = remoteDailyStats.getJSONObject(i); Date dailyStatDate = Utils.ordinalToDate(remoteStat.getInt("day")); // If exists a statistic for this day, get it try { Long id = AnkiDatabaseManager.getDatabase(mDeck.getDeckPath()).queryScalar( "SELECT id FROM stats WHERE type = 1 AND day = \"" + dailyStatDate.toString() + "\""); stat.fromDB(id); } catch (SQLException e) { // If it does not exist, create a statistic for this day stat.create(Stats.STATS_DAY, dailyStatDate); } // Update daily stat stat.updateFromJson(remoteStat); } } catch (JSONException e) { Log.i(AnkiDroidApp.TAG, "JSONException = " + e.getMessage()); } }
From source file:org.kuali.coeus.common.budget.impl.print.BudgetBaseStream.java
/** * This method gets sum of calculatedCost from list of BudgetLineItem and * iterate through each budgetRateAndBase for BudgetExclusionsSortId1 based * on RateClassType LA_WITH_EB_VA and check key as startDate and endDate * // w w w.ja v a 2 s . c o m * @return ScaleTwoDecimal sum of calculatedCost */ protected ScaleTwoDecimal getCalculatedCostForBudgetExclusionsSortId1() { ScaleTwoDecimal calculatedCost = ScaleTwoDecimal.ZERO; for (BudgetLineItem budgetLineItem : budgetPeriod.getBudgetLineItems()) { Map<String, BudgetRateAndBase> laRateBaseMap = new HashMap<String, BudgetRateAndBase>(); for (BudgetRateAndBase budgetRateAndBase : budgetLineItem.getBudgetRateAndBaseList()) { if (budgetRateAndBase.getCalculatedCost() != null && isRateAndBaseOfRateClassTypeLAwithEBVA(budgetRateAndBase)) { Date startDate = budgetRateAndBase.getStartDate(); Date endDate = budgetRateAndBase.getEndDate(); String key = new StringBuilder(startDate.toString()).append(endDate.toString()).toString(); calculatedCost = calculatedCost.add(budgetRateAndBase.getCalculatedCost()); laRateBaseMap.put(key, budgetRateAndBase); } } } return calculatedCost; }
From source file:org.kuali.coeus.common.budget.impl.print.BudgetBaseStream.java
/** * This method sets reportTypeVO and add it to reportTypeVOList from list of * BudgetLineItem and iterate through BudgetRateAndBase for BudgetLASalary * based on RateClassType OTHER//from ww w .j a v a 2s . c o m * * @param reportTypeList */ protected void setBudgetLASalaryForBudgetRateAndBase(List<ReportType> reportTypeList) { List<ReportTypeVO> reportTypeVOList = new ArrayList<ReportTypeVO>(); for (BudgetLineItem budgetLineItem : budgetPeriod.getBudgetLineItems()) { Map<String, BudgetRateAndBase> laRateBaseMap = new HashMap<String, BudgetRateAndBase>(); for (BudgetRateAndBase budgetRateAndBase : budgetLineItem.getBudgetRateAndBaseList()) { if (isRateAndBaseOfRateClassTypeLAwithEBVA(budgetRateAndBase)) { Date startDate = budgetRateAndBase.getStartDate(); Date endDate = budgetRateAndBase.getEndDate(); String key = new StringBuilder(startDate.toString()).append(endDate.toString()).toString(); if (laRateBaseMap.containsKey(key)) { continue; } ReportTypeVO reportTypeVO = getReportTypeVOForBudgetLASalaryForRateBase(budgetLineItem, budgetRateAndBase); reportTypeVOList.add(reportTypeVO); laRateBaseMap.put(key, budgetRateAndBase); } } } setReportTypeBudgetLASalary(reportTypeList, reportTypeVOList); }
From source file:org.kuali.kra.budget.printing.xmlstream.BudgetBaseStream.java
/** * This method gets sum of calculatedCost from list of BudgetLineItem and * iterate through each budgetRateAndBase for BudgetExclusionsSortId1 based * on RateClassType LA_WITH_EB_VA and check key as startDate and endDate * /*from www . ja v a 2 s.c o m*/ * @return BudgetDecimal sum of calculatedCost */ protected BudgetDecimal getCalculatedCostForBudgetExclusionsSortId1() { BudgetDecimal calculatedCost = BudgetDecimal.ZERO; for (BudgetLineItem budgetLineItem : budgetPeriod.getBudgetLineItems()) { Map<String, BudgetRateAndBase> laRateBaseMap = new HashMap<String, BudgetRateAndBase>(); for (BudgetRateAndBase budgetRateAndBase : budgetLineItem.getBudgetRateAndBaseList()) { if (budgetRateAndBase.getCalculatedCost() != null && isRateAndBaseOfRateClassTypeLAwithEBVA(budgetRateAndBase)) { Date startDate = budgetRateAndBase.getStartDate(); Date endDate = budgetRateAndBase.getEndDate(); String key = new StringBuilder(startDate.toString()).append(endDate.toString()).toString(); if (laRateBaseMap.containsKey(key)) { continue; } calculatedCost = calculatedCost.add(budgetRateAndBase.getCalculatedCost()); laRateBaseMap.put(key, budgetRateAndBase); } } } return calculatedCost; }
From source file:pt.fct.di.benchmarks.TPCW_Riak.database.TPCW_Riak_Executor.java
public void CustomerRegistration(String costumer_id) throws Exception { String name = (BenchmarkUtil.getRandomAString(8, 13) + " " + BenchmarkUtil.getRandomAString(8, 15)); String[] names = name.split(" "); Random r = new Random(); int random_int = r.nextInt(1000); String key = names[0] + "_" + (costumer_id); String pass = names[0].charAt(0) + names[1].charAt(0) + "" + random_int; String first_name = names[0]; String last_name = names[1];//from w w w . j a v a 2 s . co m int phone = r.nextInt(999999999 - 100000000) + 100000000; String email = key + "@" + BenchmarkUtil.getRandomAString(2, 9) + ".com"; double discount = r.nextDouble(); String adress = "Street: " + (BenchmarkUtil.getRandomAString(8, 15) + " " + BenchmarkUtil.getRandomAString(8, 15)) + " number: " + r.nextInt(500); double C_BALANCE = 0.00; double C_YTD_PMT = (double) BenchmarkUtil.getRandomInt(0, 99999) / 100.0; GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_YEAR, -1 * BenchmarkUtil.getRandomInt(1, 730)); java.sql.Date C_SINCE = new java.sql.Date(cal.getTime().getTime()); cal.add(Calendar.DAY_OF_YEAR, BenchmarkUtil.getRandomInt(0, 60)); if (cal.after(new GregorianCalendar())) { cal = new GregorianCalendar(); } java.sql.Date C_LAST_LOGIN = new java.sql.Date(cal.getTime().getTime()); java.sql.Timestamp C_LOGIN = new java.sql.Timestamp(System.currentTimeMillis()); cal = new GregorianCalendar(); cal.add(Calendar.HOUR, 2); java.sql.Timestamp C_EXPIRATION = new java.sql.Timestamp(cal.getTime().getTime()); cal = BenchmarkUtil.getRandomDate(1880, 2000); java.sql.Date C_BIRTHDATE = new java.sql.Date(cal.getTime().getTime()); String C_DATA = BenchmarkUtil.getRandomAString(100, 500); String address_id = insertAdress(); Customer c = new Customer(costumer_id, key, pass, last_name, first_name, phone + "", email, C_SINCE.toString(), C_LAST_LOGIN.toString(), C_LOGIN.toString(), C_EXPIRATION.toString(), C_BALANCE, C_YTD_PMT, C_BIRTHDATE.toString(), C_DATA, discount, address_id); insert(costumer_id, "customer", c); }
From source file:org.kuali.kfs.module.ar.service.impl.ContractsGrantsInvoiceCreateDocumentServiceImpl.java
protected void writeErrorEntryByAward(ContractsAndGrantsBillingAward award, List<String> validationCategory, PrintStream printStream) throws IOException { // %15s %18s %20s %19s %15s %18s %23s %18s if (ObjectUtils.isNotNull(award)) { KualiDecimal cumulativeExpenses = KualiDecimal.ZERO; String awardBeginningDate; String awardEndingDate;/*from w w w. j a v a 2 s .c o m*/ String awardTotalAmount; String proposalNumber = award.getProposalNumber().toString(); Date beginningDate = award.getAwardBeginningDate(); Date endingDate = award.getAwardEndingDate(); KualiDecimal totalAmount = award.getAwardTotalAmount(); if (ObjectUtils.isNotNull(beginningDate)) { awardBeginningDate = beginningDate.toString(); } else { awardBeginningDate = "null award beginning date"; } if (ObjectUtils.isNotNull(endingDate)) { awardEndingDate = endingDate.toString(); } else { awardEndingDate = "null award ending date"; } if (ObjectUtils.isNotNull(totalAmount) && ObjectUtils.isNotNull(totalAmount.bigDecimalValue())) { awardTotalAmount = totalAmount.toString(); } else { awardTotalAmount = "null award total amount"; } if (CollectionUtils.isEmpty(award.getActiveAwardAccounts())) { writeToReport(proposalNumber, "", awardBeginningDate, awardEndingDate, awardTotalAmount, cumulativeExpenses.toString(), printStream); } else { final SystemOptions systemOptions = optionsService.getCurrentYearOptions(); // calculate cumulativeExpenses for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) { cumulativeExpenses = cumulativeExpenses.add( contractsGrantsInvoiceDocumentService.getBudgetAndActualsForAwardAccount(awardAccount, systemOptions.getActualFinancialBalanceTypeCd(), award.getAwardBeginningDate())); } boolean firstLineFlag = true; for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) { if (firstLineFlag) { writeToReport(proposalNumber, awardAccount.getAccountNumber(), awardBeginningDate, awardEndingDate, awardTotalAmount, cumulativeExpenses.toString(), printStream); firstLineFlag = false; } else { writeToReport("", awardAccount.getAccountNumber(), "", "", "", "", printStream); } } } } // To print all the errors from the validation category. for (String vCat : validationCategory) { printStream.printf("%s", " " + vCat); printStream.printf("\r\n"); } printStream.printf(REPORT_LINE_DIVIDER); printStream.printf("\r\n"); }
From source file:com.mss.mirage.employee.general.EmployeeAction.java
/** * Updated by vkandregula on 08132013// ww w.j a v a 2s . c o m * * Updated By Teja Kadamanti on 09/23/2016 */ public String doUpdateState() { resultType = LOGIN; int avaiable = 0; int stateCount = 0; if (httpServletRequest.getSession(false).getAttribute(ApplicationConstants.SESSION_USER_ID) != null) { userRoleId = Integer.parseInt(httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_ROLE_ID).toString()); resultType = "accessFailed"; if (AuthorizationManager.getInstance().isAuthorizedUser("DO_UPDATE_STATE_EMP", userRoleId)) { try { int result = DataSourceDataProvider.getInstance().getStatusDateCheck(getId(), getStateStartDate()); String flagVar = ""; java.sql.Date hireDate = null; hireDate = dataSourceDataProvider.getInstance() .getHireDateOfEmployeeBeforeAddingCurrentStatus(getId()); if (hireDate == null || ("1950-01-31" .equals(DateUtility.getInstance().convertDateToStringPayroll(hireDate)))) { setNavId(0); resultType = SUCCESS; resultMessage = "<font size='2' color='red'> Employee HireDate is not updated. Please update it !</font>"; httpServletRequest.setAttribute(ApplicationConstants.RESULT_MSG, resultMessage); flagVar = "add"; } if (hireDate != null && "".equals(flagVar)) { if (getStateStartDate().compareTo(hireDate) < 0) { setNavId(0); resultType = SUCCESS; resultMessage = "<font size='2' color='red'> Start Date should be greater than or equal to Employee HireDate'" + com.mss.mirage.util.DateUtility.getInstance() .convertToviewFormat(hireDate.toString()) + "' !</font>"; httpServletRequest.setAttribute(ApplicationConstants.RESULT_MSG, resultMessage); flagVar = "add"; } } if ("Available".equals(getEmpState())) { stateCount = DataSourceDataProvider.getInstance().getAvailableState(getId()); // System.out.println("availableState"+availableState); } employeeService = ServiceLocator.getEmployeeService(); boolean isHistoryInserted = false; int updatedRows = 0; setCurrentEmployeeState(employeeService.getStateVTO(this)); if ("".equals(flagVar)) { if (getTempVar() == 2) { setCreatedDate(DateUtility.getInstance().getCurrentMySqlDateTime()); if (stateCount > 0) { // resultMessage = "<font color=\"red\" size=\"2\">Sorry! Available record is already in Active state for this employee you can add new record by completing the prevoius one. </font>"; resultMessage = "<font color=\"red\" size=\"2\">Sorry! Available record is already in Active state for this employee you can add only one Active Available record . </font>"; httpServletRequest.setAttribute(ApplicationConstants.RESULT_MSG, resultMessage); } else { if (result > 0 && "Available".equals(getEmpState())) { resultMessage = "<font color=\"red\" size=\"2\">Start Date must be greater than previous status dates</font>"; httpServletRequest.setAttribute(ApplicationConstants.RESULT_MSG, resultMessage); } else { setCreatedBy(httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_USER_ID).toString()); if ("Available".equals(getEmpState())) { List projectList = DataSourceDataProvider.getInstance() .getProjectsListByContactId(getId()); avaiable = projectList.size(); String loginIdEmp = DataSourceDataProvider.getInstance() .getLoginIdByEmpId(getId()); if (getUpload() != null) { if (getUploadFileName() != null && !getUploadFileName().equals("")) { String basePath = Properties.getProperty("EmpResume.Attachments"); // File createPath = new File(basePath); String theFilePath = FileUploadUtility.getInstance() .filePathGeneration(basePath); String theFileName = FileUploadUtility.getInstance() .fileNameGeneration(getUploadFileName()); File theFile = new File( theFilePath + "//" + loginIdEmp + "//" + theFileName); setFilepath(theFile.toString()); /*copies the file to the destination*/ // System.err.println("Here..."+getUpload()); FileUtils.copyFile(getUpload(), theFile); // System.err.println("Here...1"); //boolean isInsert=ServiceLocator.getConsultantService().attachResume1(this); } } if (avaiable == 0) { isHistoryInserted = employeeService.insertStateHistory(this); } } else { isHistoryInserted = employeeService.insertStateHistory(this); } resultMessage = "<font color=\"green\" size=\"2\">Employee State has been successfully updated!</font>"; setProjectName(""); setSkillSet(""); setComments(""); if (avaiable > 0) { resultMessage = "<font color=\"red\" size=\"2\">this employee already allocated to project please contact to PMO!</font>"; } httpServletRequest.setAttribute(ApplicationConstants.RESULT_MSG, resultMessage); } } resultType = SUCCESS; } else if (getTempVar() == 1) { setModifiedBy(httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_USER_ID).toString()); setModifiedDate(DateUtility.getInstance().getCurrentMySqlDateTime()); getCurrentEmployeeState().setModifiedBy(httpServletRequest.getSession(false) .getAttribute(ApplicationConstants.SESSION_USER_ID).toString()); getCurrentEmployeeState() .setModifiedDate(DateUtility.getInstance().getCurrentMySqlDateTime()); if (getCurrId() == 0) { boolean isUpdateState = employeeService .updateEmployeeState(getCurrentEmployeeState()); if (isUpdateState) { resultMessage = "<font color=\"green\" size=\"2\">Employee State has been successfully updated!</font>"; setNavId(0); httpServletRequest.setAttribute(ApplicationConstants.RESULT_MSG, resultMessage); resultType = SUCCESS; setCreatedDate(DateUtility.getInstance().getCurrentMySqlDateTime()); //int recordId = employeeService.getRecentStateHistoryId(getLoginId()); //if(recordId == 0) { isHistoryInserted = employeeService.insertStateHistory(this); //}else { // updatedRows = employeeService.updateStateHistory(this,recordId); //} } else { setNavId(0); resultType = INPUT; resultMessage = "<font color=\"red\" size=\"2\">Sorry! Please Try again!</font>"; httpServletRequest.setAttribute(ApplicationConstants.RESULT_MSG, resultMessage); } } else { setCreatedDate(DateUtility.getInstance().getCurrentMySqlDateTime()); if ("Available".equals(getEmpState())) { String loginIdEmp = DataSourceDataProvider.getInstance() .getLoginIdByEmpId(getId()); if (getUpload() != null) { if (getUploadFileName() != null && !getUploadFileName().equals("")) { String basePath = Properties.getProperty("EmpResume.Attachments"); // File createPath = new File(basePath); String theFilePath = FileUploadUtility.getInstance() .filePathGeneration(basePath); String theFileName = FileUploadUtility.getInstance() .fileNameGeneration(getUploadFileName()); File theFile = new File( theFilePath + "//" + loginIdEmp + "//" + theFileName); setFilepath(theFile.toString()); /*copies the file to the destination*/ // System.err.println("Here..."+getUpload()); FileUtils.copyFile(getUpload(), theFile); // System.err.println("Here...1"); //boolean isInsert=ServiceLocator.getConsultantService().attachResume1(this); } } } updatedRows = employeeService.updateStateHistory(this, getCurrId()); if (updatedRows == 1) { setNavId(0); resultMessage = "<font color=\"green\" size=\"2\">Employee State has been successfully updated!</font>"; httpServletRequest.setAttribute(ApplicationConstants.RESULT_MSG, resultMessage); resultType = SUCCESS; } else { setNavId(0); resultType = INPUT; resultMessage = "<font color=\"red\" size=\"2\">Sorry! Please Try again!</font>"; httpServletRequest.setAttribute(ApplicationConstants.RESULT_MSG, resultMessage); } } } } setCurrId(0); setCurrentEmployee( employeeService.getEmployee(getCurrentEmployeeState().getEmpId(), getCurrId())); setDepartmentId(getCurrentEmployee().getDepartmentId()); setEmpId(getId()); setResultMessage(resultMessage); prepare(); } 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 return resultType; }