View Javadoc
1   /*
2    * Copyright 2009 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.sys.batch.dataaccess.impl;
17  
18  import java.sql.Date;
19  import java.sql.PreparedStatement;
20  import java.sql.ResultSet;
21  import java.sql.SQLException;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.batch.dataaccess.LedgerReferenceValuePreparedStatementCachingDao;
27  import org.kuali.ole.sys.businessobject.OriginationCode;
28  import org.kuali.ole.sys.businessobject.SystemOptions;
29  import org.kuali.ole.sys.businessobject.UniversityDate;
30  
31  public class LedgerReferenceValuePreparedStatementCachingDaoJdbc extends AbstractPreparedStatementCachingDaoJdbc implements LedgerReferenceValuePreparedStatementCachingDao {
32      static final Map<String,String> sql = new HashMap<String,String>();
33      static {    
34          sql.put(RETRIEVE_PREFIX + UniversityDate.class, "select univ_fiscal_yr, univ_fiscal_prd_cd from SH_UNIV_DATE_T where univ_dt = ?");
35          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 = ?");
36          sql.put(RETRIEVE_PREFIX + OriginationCode.class, "select ROW_ACTV_IND from FS_ORIGIN_CODE_T where fs_origin_cd = ?");
37      }
38  
39      @Override
40      protected Map<String, String> getSql() {
41          return sql;
42      }
43  
44      public OriginationCode getOriginationCode(final String financialSystemOriginationCode) {
45          return new RetrievingJdbcWrapper<OriginationCode>() {
46              @Override
47              protected void populateStatement(PreparedStatement preparedStatement) throws SQLException {
48                  preparedStatement.setString(1, financialSystemOriginationCode);
49              }
50              @Override
51              protected OriginationCode extractResult(ResultSet resultSet) throws SQLException {
52                  OriginationCode originationCode = new OriginationCode();
53                  originationCode.setFinancialSystemOriginationCode(financialSystemOriginationCode);
54                  originationCode.setActive(OLEConstants.ParameterValues.YES.equals(resultSet.getString(1)) ? true : false);
55                  return originationCode;
56              }
57          }.get(OriginationCode.class);
58      }
59  
60      public SystemOptions getSystemOptions(final Integer fiscalYear) {
61          return new RetrievingJdbcWrapper<SystemOptions>() {
62              @Override
63              protected void populateStatement(PreparedStatement preparedStatement) throws SQLException {
64                  preparedStatement.setInt(1, fiscalYear);
65              }
66              @Override
67              protected SystemOptions extractResult(ResultSet resultSet) throws SQLException {
68                  SystemOptions systemOptions = new SystemOptions();
69                  systemOptions.setUniversityFiscalYear(fiscalYear);
70                  systemOptions.setActualFinancialBalanceTypeCd(resultSet.getString(1));
71                  systemOptions.setFinancialObjectTypeAssetsCd(resultSet.getString(2));
72                  systemOptions.setFinObjectTypeFundBalanceCd(resultSet.getString(3));
73                  systemOptions.setFinObjectTypeLiabilitiesCode(resultSet.getString(4));
74                  systemOptions.setCostShareEncumbranceBalanceTypeCd(resultSet.getString(12));
75                  systemOptions.setFinancialObjectTypeTransferExpenseCd(resultSet.getString(13));
76                  systemOptions.setExtrnlEncumFinBalanceTypCd(resultSet.getString(5));
77                  systemOptions.setIntrnlEncumFinBalanceTypCd(resultSet.getString(6));
78                  systemOptions.setPreencumbranceFinBalTypeCd(resultSet.getString(7));
79                  systemOptions.setFinObjTypeExpenditureexpCd(resultSet.getString(8));
80                  systemOptions.setFinObjTypeExpendNotExpCode(resultSet.getString(9));
81                  systemOptions.setFinObjTypeExpNotExpendCode(resultSet.getString(10));
82                  systemOptions.setBudgetCheckingBalanceTypeCd(resultSet.getString(11));
83                  return systemOptions;
84              }
85          }.get(SystemOptions.class);
86      }
87  
88      public UniversityDate getUniversityDate(final Date date) {
89          return new RetrievingJdbcWrapper<UniversityDate>() {
90              @Override
91              protected void populateStatement(PreparedStatement preparedStatement) throws SQLException {
92                  preparedStatement.setDate(1, date);
93              }
94              @Override
95              protected UniversityDate extractResult(ResultSet resultSet) throws SQLException {
96                  UniversityDate universityDate = new UniversityDate();
97                  universityDate.setUniversityDate(date);
98                  universityDate.setUniversityFiscalYear(resultSet.getInt(1));
99                  universityDate.setUniversityFiscalAccountingPeriod(resultSet.getString(2));
100                 return universityDate;
101             }
102         }.get(UniversityDate.class);
103     }
104 }