001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.docsearch.dao;
018:
019: import java.sql.Connection;
020: import java.sql.ResultSet;
021: import java.sql.SQLException;
022: import java.sql.Statement;
023: import java.util.ArrayList;
024: import java.util.List;
025:
026: import org.apache.ojb.broker.PersistenceBroker;
027: import org.apache.ojb.broker.accesslayer.LookupException;
028: import org.springmodules.orm.ojb.OjbFactoryUtils;
029: import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
030:
031: import edu.iu.uis.eden.docsearch.DocSearchCriteriaVO;
032: import edu.iu.uis.eden.docsearch.DocumentSearchGenerator;
033: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
034:
035: public class DocumentSearchDAOOjbImpl extends
036: PersistenceBrokerDaoSupport implements DocumentSearchDAO {
037:
038: public static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(DocumentSearchDAOOjbImpl.class);
040:
041: public List getList(
042: DocumentSearchGenerator documentSearchGenerator,
043: DocSearchCriteriaVO criteria)
044: throws EdenUserNotFoundException {
045: LOG.info("start getList");
046:
047: List docList = new ArrayList();
048: PersistenceBroker broker = null;
049: Connection conn = null;
050: Statement statement = null;
051: ResultSet rs = null;
052: try {
053: broker = getPersistenceBroker(false);
054: conn = broker.serviceConnectionManager().getConnection();
055: String sql = documentSearchGenerator
056: .generateSearchSql(criteria);
057: LOG.debug("Executing document search w/page size="
058: + DocSearchCriteriaVO.SEARCH_RESULT_FETCH_SIZE
059: + ": " + sql);
060: statement = conn.createStatement(
061: ResultSet.TYPE_SCROLL_INSENSITIVE,
062: ResultSet.CONCUR_READ_ONLY);
063: // new paging for patch
064: statement
065: .setFetchSize(DocSearchCriteriaVO.SEARCH_RESULT_FETCH_SIZE);
066: // statement.setMaxRows(DocSearchCriteriaVO.SEARCH_RESULT_CAP+1);
067: // ...end paging
068: rs = statement.executeQuery(sql);
069: // TODO delyea - look at refactoring
070: docList = documentSearchGenerator.processResultSet(rs,
071: criteria);
072: } catch (SQLException sqle) {
073: String errorMsg = "SQLException: " + sqle.getMessage();
074: LOG.error("getList() " + errorMsg, sqle);
075: throw new RuntimeException(errorMsg, sqle);
076: } catch (LookupException le) {
077: String errorMsg = "LookupException: " + le.getMessage();
078: LOG.error("getList() " + errorMsg, le);
079: throw new RuntimeException(errorMsg, le);
080: } finally {
081: if (rs != null) {
082: try {
083: rs.close();
084: } catch (SQLException e) {
085: LOG.warn("Could not close result set.");
086: }
087: }
088: if (statement != null) {
089: try {
090: statement.close();
091: } catch (SQLException e) {
092: LOG.warn("Could not close statement.");
093: }
094: }
095: if (broker != null) {
096: try {
097: OjbFactoryUtils.releasePersistenceBroker(broker,
098: this .getPersistenceBrokerTemplate()
099: .getPbKey());
100: } catch (Exception e) {
101: LOG.error("Failed closing connection: "
102: + e.getMessage(), e);
103: }
104: }
105: }
106:
107: LOG.info("end getlist");
108: return docList;
109: }
110: //
111: // protected Platform getPlatform() {
112: // return (Platform)GlobalResourceLoader.getService(KEWServiceLocator.DB_PLATFORM);
113: // }
114: }
|