1 /* 2 * Copyright 2007 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.ole.gl.dataaccess.impl; 17 18 import org.kuali.rice.core.framework.persistence.jdbc.dao.PlatformAwareDaoBaseJdbc; 19 20 /** 21 * A base class to support the JDBC operations done for AccountBalance inquiries 22 */ 23 public class AccountBalanceDaoJdbcBase extends PlatformAwareDaoBaseJdbc { 24 25 26 /** 27 * Creates a String bounded with parantheses with count number of question marks, like this: (?, ?, ?) if count is 3. Right, for 28 * creating the SQL queries 29 * 30 * @param count the count of question marks 31 * @return the resulting String 32 */ 33 protected String inString(int count) { 34 StringBuffer sb = new StringBuffer("("); 35 for (int i = 0; i < count; i++) { 36 sb.append('?'); 37 if (i < count - 1) { 38 sb.append(','); 39 } 40 } 41 sb.append(')'); 42 return sb.toString(); 43 } 44 45 /** 46 * Removes all cost share entries from the temporary holding table for this unique inquiry 47 * 48 * @param tableName the name of the temporary table to remove cost share entries from 49 * @param sessionIdColumn the name of the column in the temporary table that holds the unique id of the inquiry 50 * @param sessionId the unique id of the web session of the inquiring user 51 */ 52 protected void purgeCostShareEntries(String tableName, String sessionIdColumn, String sessionId) { 53 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); 54 } 55 56 /** 57 * Determines if the currently inquiring user has associated temporary pending entries in the temporary pending entry table 58 * 59 * @param sessionId the unique web id of the inquiring user 60 * @return true if this inquiring user has temporary pending entries, false otherwise 61 */ 62 protected boolean hasEntriesInPendingTable(String sessionId) { 63 return getSimpleJdbcTemplate().queryForInt("select count(*) as COUNT from GL_PENDING_ENTRY_MT WHERE sesid = ?", sessionId) != 0; 64 } 65 66 /** 67 * Updates the fiscal year and account numbers of temporary pending entries for display 68 * 69 * @param universityFiscalYear the fiscal year to update all the temporary pending entries of this inquiry to 70 * @param sessionId the unique web id of the inquiring user 71 */ 72 protected void fixPendingEntryDisplay(Integer universityFiscalYear, String sessionId) { 73 getSimpleJdbcTemplate().update("update GL_PENDING_ENTRY_MT set univ_fiscal_yr = ? where SESID = ?", universityFiscalYear, sessionId); 74 getSimpleJdbcTemplate().update("update GL_PENDING_ENTRY_MT set SUB_ACCT_NBR = '-----' where (SUB_ACCT_NBR is null or SUB_ACCT_NBR = ' ')"); 75 } 76 77 /** 78 * Deletes all entries in the temporary table for the given unique user 79 * 80 * @param tableName the table name to purge data from 81 * @param sessionIdColumn the name of the unique field on that table 82 * @param sessionId the unique value of the inquiry; basically, the unique web session id of the inquiring user 83 */ 84 protected void clearTempTable(String tableName, String sessionIdColumn, String sessionId) { 85 getSimpleJdbcTemplate().update("DELETE from " + tableName + " WHERE " + sessionIdColumn + " = ?", sessionId); 86 } 87 }