xref: /trunk/main/connectivity/qa/connectivity/tools/RowSet.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package connectivity.tools;
29 
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.container.XIndexAccess;
32 import com.sun.star.container.XNameAccess;
33 import com.sun.star.io.XInputStream;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.sdbc.SQLException;
37 import com.sun.star.sdbc.XArray;
38 import com.sun.star.sdbc.XBlob;
39 import com.sun.star.sdbc.XClob;
40 import com.sun.star.sdbc.XRef;
41 import com.sun.star.sdbc.XRow;
42 import com.sun.star.sdbc.XRowSet;
43 import com.sun.star.sdbc.XRowSetListener;
44 import com.sun.star.sdbcx.XColumnsSupplier;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.util.Date;
47 import com.sun.star.util.DateTime;
48 import com.sun.star.util.Time;
49 
50 public class RowSet implements XRowSet, XRow
51 {
52     private XRowSet                 m_rowSet;
53     private XRow                    m_row;
54     private XPropertySet            m_rowSetProps;
55 
56     public RowSet( XMultiServiceFactory _orb, String _dataSource, int _commandType, String _command )
57     {
58         try
59         {
60             m_rowSetProps = UnoRuntime.queryInterface( XPropertySet.class, _orb.createInstance( "com.sun.star.sdb.RowSet" ) );
61             m_rowSetProps.setPropertyValue( "DataSourceName", _dataSource );
62             m_rowSetProps.setPropertyValue( "CommandType", new Integer( _commandType ) );
63             m_rowSetProps.setPropertyValue( "Command", _command );
64 
65             m_rowSet = UnoRuntime.queryInterface( XRowSet.class, m_rowSetProps );
66             m_row = UnoRuntime.queryInterface( XRow.class, m_rowSetProps );
67         }
68         catch ( Exception e )
69         {
70             e.printStackTrace(System.err);
71             throw new java.lang.InstantiationError();
72         }
73     }
74 
75     // misc
76     public int getColumnCount()
77     {
78         XColumnsSupplier suppCols = (XColumnsSupplier)UnoRuntime.queryInterface(
79             XColumnsSupplier.class, m_rowSet );
80         XIndexAccess columns = (XIndexAccess)UnoRuntime.queryInterface(
81             XIndexAccess.class, suppCols.getColumns() );
82         return columns.getCount();
83     }
84 
85     // XRowSet
86     public void execute() throws SQLException
87     {
88         m_rowSet.execute();
89     }
90 
91     public void addRowSetListener( XRowSetListener _listener )
92     {
93         m_rowSet.addRowSetListener( _listener );
94     }
95 
96     public void removeRowSetListener( XRowSetListener _listener )
97     {
98         m_rowSet.removeRowSetListener( _listener );
99     }
100 
101     public boolean next() throws SQLException
102     {
103         return m_rowSet.next();
104     }
105 
106     public boolean isBeforeFirst() throws SQLException
107     {
108         return m_rowSet.isBeforeFirst();
109     }
110 
111     public boolean isAfterLast() throws SQLException
112     {
113         return m_rowSet.isAfterLast();
114     }
115 
116     public boolean isFirst() throws SQLException
117     {
118         return m_rowSet.isFirst();
119     }
120 
121     public boolean isLast() throws SQLException
122     {
123         return m_rowSet.isLast();
124     }
125 
126     public void beforeFirst() throws SQLException
127     {
128         m_rowSet.beforeFirst();
129     }
130 
131     public void afterLast() throws SQLException
132     {
133         m_rowSet.afterLast();
134     }
135 
136     public boolean first() throws SQLException
137     {
138         return m_rowSet.first();
139     }
140 
141     public boolean last() throws SQLException
142     {
143         return m_rowSet.last();
144     }
145 
146     public int getRow() throws SQLException
147     {
148         return m_rowSet.getRow();
149     }
150 
151     public boolean absolute(int i) throws SQLException
152     {
153         return m_rowSet.absolute(i);
154     }
155 
156     public boolean relative(int i) throws SQLException
157     {
158         return m_rowSet.relative(i);
159     }
160 
161     public boolean previous() throws SQLException
162     {
163         return m_rowSet.previous();
164     }
165 
166     public void refreshRow() throws SQLException
167     {
168         m_rowSet.refreshRow();
169     }
170 
171     public boolean rowUpdated() throws SQLException
172     {
173         return m_rowSet.rowUpdated();
174     }
175 
176     public boolean rowInserted() throws SQLException
177     {
178         return m_rowSet.rowInserted();
179     }
180 
181     public boolean rowDeleted() throws SQLException
182     {
183         return m_rowSet.rowDeleted();
184     }
185 
186     // XRow
187     public Object getStatement() throws SQLException
188     {
189         return m_rowSet.getStatement();
190     }
191 
192     public boolean wasNull() throws SQLException
193     {
194         return m_row.wasNull();
195     }
196 
197     public String getString(int i) throws SQLException
198     {
199         return m_row.getString(i);
200     }
201 
202     public boolean getBoolean(int i) throws SQLException
203     {
204         return m_row.getBoolean(i);
205     }
206 
207     public byte getByte(int i) throws SQLException
208     {
209         return m_row.getByte(i);
210     }
211 
212     public short getShort(int i) throws SQLException
213     {
214         return m_row.getShort(i);
215     }
216 
217     public int getInt(int i) throws SQLException
218     {
219         return m_row.getInt(i);
220     }
221 
222     public long getLong(int i) throws SQLException
223     {
224         return m_row.getLong(i);
225     }
226 
227     public float getFloat(int i) throws SQLException
228     {
229         return m_row.getFloat(i);
230     }
231 
232     public double getDouble(int i) throws SQLException
233     {
234         return m_row.getDouble(i);
235     }
236 
237     public byte[] getBytes(int i) throws SQLException
238     {
239         return m_row.getBytes(i);
240     }
241 
242     public Date getDate(int i) throws SQLException
243     {
244         return m_row.getDate(i);
245     }
246 
247     public Time getTime(int i) throws SQLException
248     {
249         return m_row.getTime(i);
250     }
251 
252     public DateTime getTimestamp(int i) throws SQLException
253     {
254         return m_row.getTimestamp(i);
255     }
256 
257     public XInputStream getBinaryStream(int i) throws SQLException
258     {
259         return m_row.getBinaryStream(i);
260     }
261 
262     public XInputStream getCharacterStream(int i) throws SQLException
263     {
264         return m_row.getCharacterStream(i);
265     }
266 
267     public Object getObject(int i, XNameAccess xNameAccess) throws SQLException
268     {
269         return m_row.getObject(i, xNameAccess);
270     }
271 
272     public XRef getRef(int i) throws SQLException
273     {
274         return m_row.getRef(i);
275     }
276 
277     public XBlob getBlob(int i) throws SQLException
278     {
279         return m_row.getBlob(i);
280     }
281 
282     public XClob getClob(int i) throws SQLException
283     {
284         return m_row.getClob(i);
285     }
286 
287     public XArray getArray(int i) throws SQLException
288     {
289         return m_row.getArray(i);
290     }
291 
292     public void dispose()
293     {
294         if ( m_rowSet == null )
295             return;
296         XComponent rowSetComp = UnoRuntime.queryInterface( XComponent.class, m_rowSet );
297         rowSetComp.dispose();
298     }
299 };
300