001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.gl.dataaccess.impl; 017 018 import org.kuali.kfs.sys.service.OptionsService; 019 import org.kuali.kfs.sys.service.UniversityDateService; 020 import org.kuali.rice.kns.dao.jdbc.PlatformAwareDaoBaseJdbc; 021 022 /** 023 * A base class to support the JDBC operations done for AccountBalance inquiries 024 */ 025 public class AccountBalanceDaoJdbcBase extends PlatformAwareDaoBaseJdbc { 026 protected OptionsService optionsService; 027 protected UniversityDateService universityDateService; 028 029 public OptionsService getOptionsService() { 030 return optionsService; 031 } 032 033 public void setOptionsService(OptionsService optionsService) { 034 this.optionsService = optionsService; 035 } 036 037 public UniversityDateService getUniversityDateService() { 038 return universityDateService; 039 } 040 041 public void setUniversityDateService(UniversityDateService universityDateService) { 042 this.universityDateService = universityDateService; 043 } 044 045 046 /** 047 * Creates a String bounded with parantheses with count number of question marks, like this: 048 * (?, ?, ?) if count is 3. Right, for creating the SQL queries 049 * 050 * @param count the count of question marks 051 * @return the resulting String 052 */ 053 protected String inString(int count) { 054 StringBuffer sb = new StringBuffer("("); 055 for (int i = 0; i < count; i++) { 056 sb.append('?'); 057 if (i < count - 1) { 058 sb.append(','); 059 } 060 } 061 sb.append(')'); 062 return sb.toString(); 063 } 064 065 /** 066 * Removes all cost share entries from the temporary holding table for this unique inquiry 067 * 068 * @param tableName the name of the temporary table to remove cost share entries from 069 * @param sessionIdColumn the name of the column in the temporary table that holds the unique id of the inquiry 070 * @param sessionId the unique id of the web session of the inquiring user 071 */ 072 protected void purgeCostShareEntries(String tableName, String sessionIdColumn, String sessionId) { 073 getSimpleJdbcTemplate().update("DELETE FROM " + tableName + " WHERE " + sessionIdColumn + " = ? " + " AND EXISTS (SELECT 1 FROM CA_A21_SUB_ACCT_T a " + " WHERE a.fin_coa_cd = " + tableName + ".fin_coa_cd AND a.account_nbr = " + tableName + ".account_nbr AND a.sub_acct_nbr = " + tableName + ".sub_acct_nbr AND a.sub_acct_typ_cd = 'CS')", sessionId); 074 } 075 076 /** 077 * Determines if the currently inquiring user has associated temporary pending entries in the temporary pending entry table 078 * 079 * @param sessionId the unique web id of the inquiring user 080 * @return true if this inquiring user has temporary pending entries, false otherwise 081 */ 082 protected boolean hasEntriesInPendingTable(String sessionId) { 083 return getSimpleJdbcTemplate().queryForInt("select count(*) as COUNT from GL_PENDING_ENTRY_MT WHERE sesid = ?", sessionId) != 0; 084 } 085 086 /** 087 * Updates the fiscal year and account numbers of temporary pending entries for display 088 * 089 * @param universityFiscalYear the fiscal year to update all the temporary pending entries of this inquiry to 090 * @param sessionId the unique web id of the inquiring user 091 */ 092 protected void fixPendingEntryDisplay(Integer universityFiscalYear, String sessionId) { 093 getSimpleJdbcTemplate().update("update GL_PENDING_ENTRY_MT set univ_fiscal_yr = ? where SESID = ?", universityFiscalYear, sessionId); 094 getSimpleJdbcTemplate().update("update GL_PENDING_ENTRY_MT set SUB_ACCT_NBR = '-----' where (SUB_ACCT_NBR is null or SUB_ACCT_NBR = ' ')"); 095 } 096 097 /** 098 * Deletes all entries in the temporary table for the given unique user 099 * 100 * @param tableName the table name to purge data from 101 * @param sessionIdColumn the name of the unique field on that table 102 * @param sessionId the unique value of the inquiry; basically, the unique web session id of the inquiring user 103 */ 104 protected void clearTempTable(String tableName, String sessionIdColumn, String sessionId) { 105 getSimpleJdbcTemplate().update("DELETE from " + tableName + " WHERE " + sessionIdColumn + " = ?", sessionId); 106 } 107 }