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.module.ld.dataaccess.impl; 017 018 import org.apache.ojb.broker.metadata.MetadataManager; 019 import org.kuali.kfs.gl.dataaccess.LedgerBalancingDao; 020 import org.kuali.kfs.gl.dataaccess.impl.BalancingDaoJdbc; 021 import org.kuali.kfs.module.ld.LaborConstants; 022 import org.kuali.kfs.module.ld.businessobject.LaborBalanceHistory; 023 import org.kuali.kfs.module.ld.businessobject.LaborEntryHistory; 024 import org.kuali.kfs.module.ld.businessobject.LedgerBalance; 025 import org.kuali.kfs.module.ld.businessobject.LedgerEntry; 026 027 /** 028 * JDBC implementation of LedgerBalancingDao. This essentially is a copy of one table to another with 029 * group by in some cases. Hence the idea is that JDBC is much faster in this case then creating 030 * BO objects that are essentially not necessary. 031 */ 032 public class LaborBalancingDaoJdbc extends BalancingDaoJdbc implements LedgerBalancingDao { 033 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LaborBalancingDaoJdbc.class); 034 035 protected static final String BALANCE_LABOR_KEY_FIELDS = LaborConstants.ColumnNames.POSITION_NUMBER + ", " + LaborConstants.ColumnNames.EMPLOYEE_IDENTIFIER; 036 037 /** 038 * @see org.kuali.kfs.gl.dataaccess.LedgerBalancingDao#populateLedgerEntryHistory(java.lang.Integer) 039 */ 040 public int populateLedgerEntryHistory(Integer universityFiscalYear) { 041 String laborEntryTableName = MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(LedgerEntry.class).getFullTableName(); 042 String laborEntryHistoryTableName = MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(LaborEntryHistory.class).getFullTableName(); 043 044 String sql = "INSERT INTO " + laborEntryHistoryTableName + " (" + ENTRY_KEY_FIELDS + ", " + VER_NBR + ", " + LaborConstants.ColumnNames.TRANSACTION_LEDGER_ENTRY_AMOUNT + ", " + ROW_COUNT + ")" 045 + " SELECT " + ENTRY_KEY_FIELDS + ", 1, sum(" + LaborConstants.ColumnNames.TRANSACTION_LEDGER_ENTRY_AMOUNT + "), count(*)" 046 + " FROM " + laborEntryTableName 047 + " WHERE " + LaborConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR + " >= " + universityFiscalYear 048 + " GROUP BY " + ENTRY_KEY_FIELDS; 049 050 LOG.debug(sql); 051 052 return getSimpleJdbcTemplate().update(sql); 053 } 054 055 /** 056 * @see org.kuali.kfs.gl.dataaccess.LedgerBalancingDao#populateLedgerBalanceHistory(java.lang.Integer) 057 */ 058 public int populateLedgerBalanceHistory(Integer universityFiscalYear) { 059 String laborBalanceTableName = MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(LedgerBalance.class).getFullTableName(); 060 String laborBalanceHistoryTableName = MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(LaborBalanceHistory.class).getFullTableName(); 061 062 String sql = "INSERT INTO " + laborBalanceHistoryTableName + " (" + BALANCE_KEY_FIELDS + ", " + BALANCE_LABOR_KEY_FIELDS + ", " + VER_NBR + ", " + BALANCE_AMOUNT_FIELDS + ", " + BALANCE_MONTH_AMOUNT_FIELDS + ")" 063 + " SELECT " + BALANCE_KEY_FIELDS + ", " + BALANCE_LABOR_KEY_FIELDS + ", 1, " + BALANCE_AMOUNT_FIELDS + ", " + BALANCE_MONTH_AMOUNT_FIELDS 064 + " FROM " + laborBalanceTableName 065 + " WHERE " + LaborConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR + " >= " + universityFiscalYear; 066 067 LOG.debug(sql); 068 069 return getSimpleJdbcTemplate().update(sql); 070 } 071 }