01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.chart.dao.jdbc;
17:
18: import org.apache.ojb.broker.metadata.MetadataManager;
19: import org.kuali.core.dao.jdbc.PlatformAwareDaoBaseJdbc;
20: import org.kuali.core.dbplatform.RawSQL;
21: import org.kuali.module.chart.bo.Account;
22: import org.kuali.module.chart.bo.PriorYearAccount;
23:
24: /**
25: * This class performs actions against the database through direct SQL command calls.
26: */
27: @RawSQL
28: public class PriorYearAccountDaoJdbc extends PlatformAwareDaoBaseJdbc {
29:
30: /** Constant used to retrieve row counts for tables. Obj_Id value exists in all tables in DB. */
31: private static final String OBJ_ID = "OBJ_ID";
32:
33: /**
34: * This method purges all records in the Prior Year Account table in the DB.
35: *
36: * @return Number of records that were purged.
37: */
38: @RawSQL
39: public int purgePriorYearAccounts() {
40: String priorYrAcctTableName = MetadataManager.getInstance()
41: .getGlobalRepository().getDescriptorFor(
42: PriorYearAccount.class).getFullTableName();
43:
44: // 1. Count how many rows are currently in the prior year acct table
45: int count = getSimpleJdbcTemplate().queryForInt(
46: "SELECT COUNT(" + OBJ_ID + ") from "
47: + priorYrAcctTableName);
48:
49: // 2. Purge all the rows from the prior year acct table
50: getSimpleJdbcTemplate().update(
51: "DELETE from " + priorYrAcctTableName);
52:
53: return count;
54: }
55:
56: /**
57: * This method copies all organization records from the current Account table to the Prior Year Account table.
58: *
59: * @return Number of records that were copied.
60: */
61: @RawSQL
62: public int copyCurrentAccountsToPriorYearTable() {
63: String priorYrAcctTableName = MetadataManager.getInstance()
64: .getGlobalRepository().getDescriptorFor(
65: PriorYearAccount.class).getFullTableName();
66: String acctTableName = MetadataManager.getInstance()
67: .getGlobalRepository().getDescriptorFor(Account.class)
68: .getFullTableName();
69:
70: // 1. Copy all the rows from the current org table to the prior year acct table
71: getSimpleJdbcTemplate().update(
72: "INSERT into " + priorYrAcctTableName
73: + " SELECT * from " + acctTableName);
74:
75: // 2. Count how many rows are currently in the prior year acct table
76: return getSimpleJdbcTemplate().queryForInt(
77: "SELECT COUNT(" + OBJ_ID + ") from "
78: + priorYrAcctTableName);
79: }
80: }
|