Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jbreport/data/ResultSetAdapter.java


1   /*
2    * $Id: ResultSetAdapter.java,v 1.1.1.1 2000/08/31 13:14:33 grantfin Exp $
3    *
4    * jbReport - A reporting library for Java
5    * Copyright (C) 2000 Grant Finnemore <grantfin@users.sourceforge.net>
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 2 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   */
21  package jbreport.data;
22  
23  import java.sql.ResultSet;
24  import java.sql.SQLException;
25  
26  import jbreport.ReportException;
27  
28  /**
29   * This is an adapter for a ResultSet to make it compatible for the QueryResult
30   * interface.
31   *
32   * @author Grant Finnemore
33   * @version $Revision: 1.1.1.1 $
34   */
35  class ResultSetAdapter extends AbstractQueryResult implements QueryResult {
36  
37     /** The resultset from which data will be extracted */
38     private ResultSet rs;
39  
40     //
41     // Constructors
42     //
43  
44     public ResultSetAdapter(ResultSet rs) {
45        this.rs = rs;
46     }
47  
48     //
49     // Implementation methods
50     //
51  
52     public boolean next() throws ReportException {
53        try {
54           boolean result = rs.next();
55           if(result) {
56              doBreakChecks();
57           }
58           return result;
59        }
60        catch(SQLException e) {
61           throw new ReportException(e);
62        }
63     }
64  
65     public void close() throws ReportException {
66        try {
67           rs.close();
68        }
69        catch(SQLException e) {
70           throw new ReportException(e);
71        }
72     }
73  
74     public int indexForName(String columnName) throws ReportException {
75        try {
76           return rs.findColumn(columnName);
77        }
78        catch(SQLException e) {
79           throw new ReportException(e);
80        }
81     }
82  
83     public String nameForIndex(int columnIndex) throws ReportException {
84        try {
85           return rs.getMetaData().getColumnName(columnIndex);
86        }
87        catch(SQLException e) {
88           throw new ReportException(e);
89        }
90     }
91  
92     public String getString(int columnIndex) throws ReportException {
93        try {
94           return rs.getString(columnIndex);
95        }
96        catch(SQLException e) {
97           throw new ReportException(e);
98        }
99     }
100 
101    public boolean wasNull() throws ReportException {
102       try {
103          return rs.wasNull();
104       }
105       catch(SQLException e) {
106          throw new ReportException(e);
107       }
108    }
109 
110    public int getColumnCount() throws ReportException {
111       try {
112          return rs.getMetaData().getColumnCount();
113       }
114       catch(SQLException e) {
115          throw new ReportException(e);
116       }
117    }
118 }