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.sys.batch.dataaccess.impl;
017
018 import java.sql.Date;
019 import java.sql.PreparedStatement;
020 import java.sql.ResultSet;
021 import java.sql.SQLException;
022 import java.util.HashMap;
023 import java.util.Map;
024
025 import org.kuali.kfs.sys.KFSConstants;
026 import org.kuali.kfs.sys.batch.dataaccess.LedgerReferenceValuePreparedStatementCachingDao;
027 import org.kuali.kfs.sys.businessobject.OriginationCode;
028 import org.kuali.kfs.sys.businessobject.SystemOptions;
029 import org.kuali.kfs.sys.businessobject.UniversityDate;
030
031 public class LedgerReferenceValuePreparedStatementCachingDaoJdbc extends AbstractPreparedStatementCachingDaoJdbc implements LedgerReferenceValuePreparedStatementCachingDao {
032 static final Map<String,String> sql = new HashMap<String,String>();
033 static {
034 sql.put(RETRIEVE_PREFIX + UniversityDate.class, "select univ_fiscal_yr, univ_fiscal_prd_cd from SH_UNIV_DATE_T where univ_dt = ?");
035 sql.put(RETRIEVE_PREFIX + SystemOptions.class, "select act_fin_bal_typ_cd, fobj_typ_asset_cd, fobj_typ_fndbal_cd, fobj_typ_lblty_cd, ext_enc_fbaltyp_cd, int_enc_fbaltyp_cd, pre_enc_fbaltyp_cd, fobjtp_xpnd_exp_cd, fobjtp_xpndnexp_cd, fobjtp_expnxpnd_cd, bdgt_chk_baltyp_cd, CSTSHR_ENCUM_FIN_BAL_TYP_CD, FIN_OBJECT_TYP_TRNFR_EXP_CD from FS_OPTION_T where univ_fiscal_yr = ?");
036 sql.put(RETRIEVE_PREFIX + OriginationCode.class, "select ROW_ACTV_IND from FS_ORIGIN_CODE_T where fs_origin_cd = ?");
037 }
038
039 @Override
040 protected Map<String, String> getSql() {
041 return sql;
042 }
043
044 public OriginationCode getOriginationCode(final String financialSystemOriginationCode) {
045 return new RetrievingJdbcWrapper<OriginationCode>() {
046 @Override
047 protected void populateStatement(PreparedStatement preparedStatement) throws SQLException {
048 preparedStatement.setString(1, financialSystemOriginationCode);
049 }
050 @Override
051 protected OriginationCode extractResult(ResultSet resultSet) throws SQLException {
052 OriginationCode originationCode = new OriginationCode();
053 originationCode.setFinancialSystemOriginationCode(financialSystemOriginationCode);
054 originationCode.setActive(KFSConstants.ParameterValues.YES.equals(resultSet.getString(1)) ? true : false);
055 return originationCode;
056 }
057 }.get(OriginationCode.class);
058 }
059
060 public SystemOptions getSystemOptions(final Integer fiscalYear) {
061 return new RetrievingJdbcWrapper<SystemOptions>() {
062 @Override
063 protected void populateStatement(PreparedStatement preparedStatement) throws SQLException {
064 preparedStatement.setInt(1, fiscalYear);
065 }
066 @Override
067 protected SystemOptions extractResult(ResultSet resultSet) throws SQLException {
068 SystemOptions systemOptions = new SystemOptions();
069 systemOptions.setUniversityFiscalYear(fiscalYear);
070 systemOptions.setActualFinancialBalanceTypeCd(resultSet.getString(1));
071 systemOptions.setFinancialObjectTypeAssetsCd(resultSet.getString(2));
072 systemOptions.setFinObjectTypeFundBalanceCd(resultSet.getString(3));
073 systemOptions.setFinObjectTypeLiabilitiesCode(resultSet.getString(4));
074 systemOptions.setCostShareEncumbranceBalanceTypeCd(resultSet.getString(12));
075 systemOptions.setFinancialObjectTypeTransferExpenseCd(resultSet.getString(13));
076 systemOptions.setExtrnlEncumFinBalanceTypCd(resultSet.getString(5));
077 systemOptions.setIntrnlEncumFinBalanceTypCd(resultSet.getString(6));
078 systemOptions.setPreencumbranceFinBalTypeCd(resultSet.getString(7));
079 systemOptions.setFinObjTypeExpenditureexpCd(resultSet.getString(8));
080 systemOptions.setFinObjTypeExpendNotExpCode(resultSet.getString(9));
081 systemOptions.setFinObjTypeExpNotExpendCode(resultSet.getString(10));
082 systemOptions.setBudgetCheckingBalanceTypeCd(resultSet.getString(11));
083 return systemOptions;
084 }
085 }.get(SystemOptions.class);
086 }
087
088 public UniversityDate getUniversityDate(final Date date) {
089 return new RetrievingJdbcWrapper<UniversityDate>() {
090 @Override
091 protected void populateStatement(PreparedStatement preparedStatement) throws SQLException {
092 preparedStatement.setDate(1, date);
093 }
094 @Override
095 protected UniversityDate extractResult(ResultSet resultSet) throws SQLException {
096 UniversityDate universityDate = new UniversityDate();
097 universityDate.setUniversityDate(date);
098 universityDate.setUniversityFiscalYear(resultSet.getInt(1));
099 universityDate.setUniversityFiscalAccountingPeriod(resultSet.getString(2));
100 return universityDate;
101 }
102 }.get(UniversityDate.class);
103 }
104 }