home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 2.9 KB | 91 lines |
- /*
- * @(#ResultSetEnumeration.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
-
- package symantec.itools.db.beans.jdbc;
-
- import java.sql.*;
- public class ResultSetEnumeration implements java.util.Enumeration
- {
- ResultSet m_ResultSet=null;
- ResultSetMetaData m_ResultSetMD;
- boolean m_RowAvailable;
- Class m_RowClass;
- ColumnMetaData cmd;
- String tableName;
-
- ResultSetEnumeration(ResultSet resultSet,
- ResultSetMetaData resultSetMD,
- Class rowClass, String tName) {
- m_ResultSet = resultSet;
- m_ResultSetMD = resultSetMD;
- m_RowAvailable = false;
- m_RowClass = rowClass;
- tableName=tName;
- }
-
- public void closeResultSet() throws SQLException{
- if(m_ResultSet!=null){
- m_ResultSet.close();
- }
- }
-
-
- public boolean hasMoreElements() {
- if (!m_RowAvailable) {
- try {
- if((m_RowAvailable = m_ResultSet.next())==false){
- m_ResultSet.close();
- }
- }
- catch (SQLException e) {
- // Swallow it. All we care is did it work or didn't it.
- }
- }
- return m_RowAvailable;
- }
-
- public Object nextElement() {
- RecordDefinition row = null;
- if (!m_RowAvailable) {
- m_RowAvailable = hasMoreElements();
- }
- if (m_RowAvailable) {
- m_RowAvailable = false;
- try {
- row = (RecordDefinition)m_RowClass.newInstance();
- // row.setTableName(tableName);
- row.initDataStorage();
- int numColumns = m_ResultSetMD.getColumnCount();
- Object objSwitch;
- for (int colIndex = 0; colIndex < numColumns; colIndex++) {
- try{
- objSwitch=row.getObjectFromResultSet(colIndex,m_ResultSet);
- if (m_ResultSet.wasNull()){
- objSwitch=null;
- }
- row.setValueAsObject( colIndex, objSwitch);
- ColumnMetaData cmd = (ColumnMetaData)row.getMemberModel(colIndex);
- cmd.setColumnState(ColumnMetaData.VALID_STATE);
- }
- // we can't bring up the value from the DB( the driver ??) so the
- // column is in a invalid state
- catch(SQLException sqe){
- ColumnMetaData cmd = (ColumnMetaData)row.getMemberModel(colIndex);
- cmd.setColumnState(ColumnMetaData.INVALID_STATE);
- }
-
- }
- } // end for each column
-
- catch (Exception e) {
- System.out.println(e.getMessage());
- }
- }
- row.bringUpToDate();
- return row;
- }
- }