/** * INTERNAL: Execute the query building the objects directly from the database result-set. * * @exception DatabaseException - an error has occurred on the database * @return object - the first object found or null if none. */ protected Object executeObjectLevelReadQueryFromResultSet() throws DatabaseException { UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl) getSession(); DatabaseAccessor accessor = (DatabaseAccessor) unitOfWork.getAccessor(); DatabasePlatform platform = accessor.getPlatform(); DatabaseCall call = (DatabaseCall) getCall().clone(); call.setQuery(this); call.translate(this.translationRow, null, unitOfWork); Statement statement = null; ResultSet resultSet = null; boolean exceptionOccured = false; try { accessor.incrementCallCount(unitOfWork); statement = call.prepareStatement(accessor, this.translationRow, unitOfWork); resultSet = accessor.executeSelect(call, statement, unitOfWork); ResultSetMetaData metaData = resultSet.getMetaData(); Vector results = new Vector(); ObjectBuilder builder = this.descriptor.getObjectBuilder(); while (resultSet.next()) { results.add( builder.buildWorkingCopyCloneFromResultSet( this, this.joinedAttributeManager, resultSet, unitOfWork, accessor, metaData, platform)); } return results; } catch (SQLException exception) { exceptionOccured = true; DatabaseException commException = accessor.processExceptionForCommError(session, exception, call); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, call, accessor, unitOfWork, false); } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { accessor.releaseStatement(statement, call.getSQLString(), call, unitOfWork); } } catch (SQLException exception) { if (!exceptionOccured) { // in the case of an external connection pool the connection may be null after the // statement release // if it is null we will be unable to check the connection for a comm error and // therefore must return as if it was not a comm error. DatabaseException commException = accessor.processExceptionForCommError(session, exception, call); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, call, accessor, session, false); } } } }
/** getObject. */ public void test() throws Exception { PreparedStatement statement = connection.prepareStatement(sql); ResultSet result = statement.executeQuery(); int size = result.getMetaData().getColumnCount(); Vector rows = new Vector(); while (result.next()) { Vector row = new Vector(size); for (int column = 1; column <= size; column++) { Object value = result.getObject(column); value = ConversionManager.getDefaultManager().convertObject(value, ClassConstants.SQLDATE); row.add(value); } rows.add(row); } result.close(); statement.close(); }