001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.gl.dao.jdbc;
017:
018: import org.kuali.core.dao.jdbc.PlatformAwareDaoBaseJdbc;
019: import org.kuali.core.dbplatform.RawSQL;
020: import org.kuali.kfs.service.OptionsService;
021: import org.kuali.module.financial.service.UniversityDateService;
022:
023: /**
024: * A base class to support the JDBC operations done for AccountBalance inquiries
025: */
026: @RawSQL
027: public class AccountBalanceDaoJdbcBase extends PlatformAwareDaoBaseJdbc {
028: protected OptionsService optionsService;
029: protected UniversityDateService universityDateService;
030:
031: public OptionsService getOptionsService() {
032: return optionsService;
033: }
034:
035: public void setOptionsService(OptionsService optionsService) {
036: this .optionsService = optionsService;
037: }
038:
039: public UniversityDateService getUniversityDateService() {
040: return universityDateService;
041: }
042:
043: public void setUniversityDateService(
044: UniversityDateService universityDateService) {
045: this .universityDateService = universityDateService;
046: }
047:
048: /**
049: * Creates a String bounded with parantheses with count number of question marks, like this:
050: * (?, ?, ?) if count is 3. Right, for creating the SQL queries
051: *
052: * @param count the count of question marks
053: * @return the resulting String
054: */
055: protected String inString(int count) {
056: StringBuffer sb = new StringBuffer("(");
057: for (int i = 0; i < count; i++) {
058: sb.append('?');
059: if (i < count - 1) {
060: sb.append(',');
061: }
062: }
063: sb.append(')');
064: return sb.toString();
065: }
066:
067: /**
068: * Removes all cost share entries from the temporary holding table for this unique inquiry
069: *
070: * @param tableName the name of the temporary table to remove cost share entries from
071: * @param sessionIdColumn the name of the column in the temporary table that holds the unique id of the inquiry
072: * @param sessionId the unique id of the web session of the inquiring user
073: */
074: @RawSQL
075: protected void purgeCostShareEntries(String tableName,
076: String sessionIdColumn, String sessionId) {
077: getSimpleJdbcTemplate()
078: .update(
079: "DELETE FROM "
080: + tableName
081: + " WHERE "
082: + sessionIdColumn
083: + " = ? "
084: + " AND EXISTS (SELECT 1 FROM ca_a21_sub_acct_t a "
085: + " WHERE a.fin_coa_cd = "
086: + tableName
087: + ".fin_coa_cd AND a.account_nbr = "
088: + tableName
089: + ".account_nbr AND a.sub_acct_nbr = "
090: + tableName
091: + ".sub_acct_nbr AND a.sub_acct_typ_cd = 'CS')",
092: sessionId);
093: }
094:
095: /**
096: * Determines if the currently inquiring user has associated temporary pending entries in the temporary pending entry table
097: *
098: * @param sessionId the unique web id of the inquiring user
099: * @return true if this inquiring user has temporary pending entries, false otherwise
100: */
101: @RawSQL
102: protected boolean hasEntriesInPendingTable(String sessionId) {
103: return getSimpleJdbcTemplate()
104: .queryForInt(
105: "select count(*) as COUNT from gl_pending_entry_mt WHERE sesid = ?",
106: sessionId) != 0;
107: }
108:
109: /**
110: * Updates the fiscal year and account numbers of temporary pending entries for display
111: *
112: * @param universityFiscalYear the fiscal year to update all the temporary pending entries of this inquiry to
113: * @param sessionId the unique web id of the inquiring user
114: */
115: @RawSQL
116: protected void fixPendingEntryDisplay(Integer universityFiscalYear,
117: String sessionId) {
118: getSimpleJdbcTemplate()
119: .update(
120: "update GL_PENDING_ENTRY_MT set univ_fiscal_yr = ? where SESID = ?",
121: universityFiscalYear, sessionId);
122: getSimpleJdbcTemplate()
123: .update(
124: "update gl_pending_entry_mt set SUB_ACCT_NBR = '-----' where (SUB_ACCT_NBR is null or SUB_ACCT_NBR = ' ')");
125: }
126:
127: /**
128: * Deletes all entries in the temporary table for the given unique user
129: *
130: * @param tableName the table name to purge data from
131: * @param sessionIdColumn the name of the unique field on that table
132: * @param sessionId the unique value of the inquiry; basically, the unique web session id of the inquiring user
133: */
134: @RawSQL
135: protected void clearTempTable(String tableName,
136: String sessionIdColumn, String sessionId) {
137: getSimpleJdbcTemplate().update(
138: "DELETE from " + tableName + " WHERE "
139: + sessionIdColumn + " = ?", sessionId);
140: }
141: }
|