Search in sources :

Example 1 with DataSourceCursorRuntimeException

use of org.jaffa.persistence.engines.jdbcengine.datasource.exceptions.DataSourceCursorRuntimeException in project jaffa-framework by jaffa-projects.

the class DataSourceCursor method fetchData.

/**
 * This will fetch additional data. Each row will be molded into a Persistent object
 * and added to the collection. It will invoke the PostLoad trigger of each Persistent object.
 * If all the data has been fetched, then the ResultSet will be closed.
 */
private void fetchData() throws SQLException, PostLoadFailedException, DataSourceCursorRuntimeException, IOException {
    if (!m_allRead) {
        for (int i = 0; i < m_dataSource.getHitlistSize().intValue(); i++) {
            if (m_pagingPlugin != null ? m_pagingPlugin.next(m_resultSet) : m_resultSet.next()) {
                try {
                    if (m_criteria.getGroupBys() != null || m_criteria.getFunctionEntries() != null) {
                        Map m = MoldingService.getFunctionQueryMap(m_criteria, m_classMetaData, m_resultSet, m_dataSource.getEngineType());
                        if (log.isDebugEnabled()) {
                            StringBuffer buf = new StringBuffer();
                            for (Iterator itr = m.entrySet().iterator(); itr.hasNext(); ) {
                                if (buf.length() > 0)
                                    buf.append(',');
                                Map.Entry me = (Map.Entry) itr.next();
                                buf.append(me.getKey() + "=" + me.getValue());
                            }
                            log.debug("Results from SQL functions:" + buf.toString());
                        }
                        m_collection.add(m);
                    } else {
                        IPersistent object = MoldingService.getObject(m_classMetaData, m_resultSet, m_dataSource.getEngineType());
                        if (log.isDebugEnabled()) {
                            log.debug("Fetched the Persistent object: " + object.toString());
                            log.debug("Invoking the PostLoad trigger of the Persistent object");
                        }
                        JdbcBridge.updatePersistentFlagsOnQuery(object, m_criteria);
                        object.postLoad();
                        m_collection.add(object);
                        m_dataSource.cacheObject(object);
                    }
                    if (log.isDebugEnabled())
                        log.debug("Current size of the retrieved record set is " + m_collection.size());
                } catch (ClassNotFoundException e) {
                    String str = "Error while molding a ResultSet into a Persistent object";
                    log.error(str, e);
                    throw new DataSourceCursorRuntimeException(str, e);
                } catch (InstantiationException e) {
                    String str = "Error while molding a ResultSet into a Persistent object";
                    log.error(str, e);
                    throw new DataSourceCursorRuntimeException(str, e);
                } catch (IllegalAccessException e) {
                    String str = "Error while molding a ResultSet into a Persistent object";
                    log.error(str, e);
                    throw new DataSourceCursorRuntimeException(str, e);
                } catch (InvocationTargetException e) {
                    String str = "Error while molding a ResultSet into a Persistent object";
                    log.error(str, e);
                    throw new DataSourceCursorRuntimeException(str, e);
                }
            } else {
                if (log.isDebugEnabled())
                    log.debug("Fetched in the complete result set. Invoking the closeStatement() method of the DataSource.");
                m_dataSource.closeStatement(m_statement);
                m_allRead = true;
                break;
            }
        }
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) DataSourceCursorRuntimeException(org.jaffa.persistence.engines.jdbcengine.datasource.exceptions.DataSourceCursorRuntimeException) IPersistent(org.jaffa.persistence.IPersistent) Iterator(java.util.Iterator) Map(java.util.Map)

Example 2 with DataSourceCursorRuntimeException

use of org.jaffa.persistence.engines.jdbcengine.datasource.exceptions.DataSourceCursorRuntimeException in project jaffa-framework by jaffa-projects.

the class DataSourceCursor method clear.

/**
 * Removes all of the elements from this collection.
 * Note: This will not have any effect on the Persistent store.
 * This will close the underlying ResultSet.
 * @throws DataSourceCursorRuntimeException if any error occurs in closing the underlying ResultSet.
 */
public void clear() throws DataSourceCursorRuntimeException {
    try {
        m_collection.clear();
        if (!m_allRead) {
            if (log.isDebugEnabled())
                log.debug("Cleared the internal Collection. Invoking the closeStatement() method of the DataSource.");
            m_dataSource.closeStatement(m_statement);
            m_allRead = true;
        }
    } catch (SQLException e) {
        String str = "Error in closing the ResultSet";
        log.error(str, e);
        throw new DataSourceCursorRuntimeException(str, e);
    }
}
Also used : DataSourceCursorRuntimeException(org.jaffa.persistence.engines.jdbcengine.datasource.exceptions.DataSourceCursorRuntimeException) SQLException(java.sql.SQLException)

Aggregations

DataSourceCursorRuntimeException (org.jaffa.persistence.engines.jdbcengine.datasource.exceptions.DataSourceCursorRuntimeException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 IPersistent (org.jaffa.persistence.IPersistent)1