View Javadoc
1   /*
2    * Copyright 2007 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.coa.dataaccess.impl;
17  
18  import org.apache.ojb.broker.metadata.MetadataManager;
19  import org.kuali.ole.coa.businessobject.Organization;
20  import org.kuali.ole.coa.businessobject.PriorYearOrganization;
21  import org.kuali.ole.coa.dataaccess.PriorYearOrganizationDao;
22  import org.kuali.rice.core.framework.persistence.jdbc.dao.PlatformAwareDaoBaseJdbc;
23  
24  /**
25   * This class performs actions against the database through direct SQL command calls.
26   */
27  public class PriorYearOrganizationDaoJdbc extends PlatformAwareDaoBaseJdbc implements PriorYearOrganizationDao {
28  
29      /** Constant used to retrieve row counts for tables. Obj_Id value exists in all tables in DB. */
30      private static final String OBJ_ID = "OBJ_ID";
31  
32      /**
33       * This method purges all records in the Prior Year Organization table in the DB.
34       * 
35       * @return Number of records that were purged.
36       * @see org.kuali.ole.coa.dataaccess.PriorYearOrganizationDao#purgePriorYearOrganizations()
37       */
38      public int purgePriorYearOrganizations() {
39          String priorYrOrgTableName = MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(PriorYearOrganization.class).getFullTableName();
40  
41          // 1. Count how many rows are currently in the prior year org table
42          int count = getSimpleJdbcTemplate().queryForInt("SELECT COUNT(" + OBJ_ID + ") from " + priorYrOrgTableName);
43  
44          // 2. Purge all the rows from the prior year org table
45          getSimpleJdbcTemplate().update("DELETE from " + priorYrOrgTableName);
46  
47          return count;
48      }
49  
50      /**
51       * This method copies all organization records from the current Org table to the Prior Year Organization table.
52       * 
53       * @return Number of records that were copied.
54       * @see org.kuali.ole.coa.dataaccess.PriorYearOrganizationDao#copyCurrentOrganizationsToPriorYearTable()
55       */
56      public int copyCurrentOrganizationsToPriorYearTable() {
57          String priorYrOrgTableName = MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(PriorYearOrganization.class).getFullTableName();
58          String orgTableName = MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(Organization.class).getFullTableName();
59  
60          // 1. Copy all the rows from the current org table to the prior year org table
61          getSimpleJdbcTemplate().update("INSERT into " + priorYrOrgTableName + " SELECT * from " + orgTableName);
62  
63          // 2. Count how many rows are currently in the prior year org table
64          return getSimpleJdbcTemplate().queryForInt("SELECT COUNT(" + OBJ_ID + ") from " + priorYrOrgTableName);
65      }
66  
67  }