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.Org;
22: import org.kuali.module.chart.bo.PriorYearOrganization;
23: import org.kuali.module.chart.dao.PriorYearOrganizationDao;
24:
25: /**
26: * This class performs actions against the database through direct SQL command calls.
27: */
28: @RawSQL
29: public class PriorYearOrganizationDaoJdbc extends
30: PlatformAwareDaoBaseJdbc implements PriorYearOrganizationDao {
31:
32: /** Constant used to retrieve row counts for tables. Obj_Id value exists in all tables in DB. */
33: private static final String OBJ_ID = "OBJ_ID";
34:
35: /**
36: * This method purges all records in the Prior Year Organization table in the DB.
37: *
38: * @return Number of records that were purged.
39: * @see org.kuali.module.chart.dao.PriorYearOrganizationDao#purgePriorYearOrganizations()
40: */
41: @RawSQL
42: public int purgePriorYearOrganizations() {
43: String priorYrOrgTableName = MetadataManager.getInstance()
44: .getGlobalRepository().getDescriptorFor(
45: PriorYearOrganization.class).getFullTableName();
46:
47: // 1. Count how many rows are currently in the prior year org table
48: int count = getSimpleJdbcTemplate().queryForInt(
49: "SELECT COUNT(" + OBJ_ID + ") from "
50: + priorYrOrgTableName);
51:
52: // 2. Purge all the rows from the prior year org table
53: getSimpleJdbcTemplate().update(
54: "DELETE from " + priorYrOrgTableName);
55:
56: return count;
57: }
58:
59: /**
60: * This method copies all organization records from the current Org table to the Prior Year Organization table.
61: *
62: * @return Number of records that were copied.
63: * @see org.kuali.module.chart.dao.PriorYearOrganizationDao#copyCurrentOrganizationsToPriorYearTable()
64: */
65: @RawSQL
66: public int copyCurrentOrganizationsToPriorYearTable() {
67: String priorYrOrgTableName = MetadataManager.getInstance()
68: .getGlobalRepository().getDescriptorFor(
69: PriorYearOrganization.class).getFullTableName();
70: String orgTableName = MetadataManager.getInstance()
71: .getGlobalRepository().getDescriptorFor(Org.class)
72: .getFullTableName();
73:
74: // 1. Copy all the rows from the current org table to the prior year org table
75: getSimpleJdbcTemplate().update(
76: "INSERT into " + priorYrOrgTableName
77: + " SELECT * from " + orgTableName);
78:
79: // 2. Count how many rows are currently in the prior year org table
80: return getSimpleJdbcTemplate().queryForInt(
81: "SELECT COUNT(" + OBJ_ID + ") from "
82: + priorYrOrgTableName);
83: }
84:
85: }
|