1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 import com.sun.star.beans.XPropertySet;
21 import com.sun.star.container.XIndexAccess;
22 import com.sun.star.container.XNameAccess;
23 import com.sun.star.io.XInputStream;
24 import com.sun.star.sdbc.SQLException;
25 import com.sun.star.sdbc.XArray;
26 import com.sun.star.sdbc.XBlob;
27 import com.sun.star.sdbc.XClob;
28 import com.sun.star.sdbc.XRef;
29 import com.sun.star.sdbc.XRow;
30 import com.sun.star.sdbc.XRowSet;
31 import com.sun.star.sdbc.XRowSetListener;
32 import com.sun.star.sdbcx.XColumnsSupplier;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XComponentContext;
35 import com.sun.star.util.Date;
36 import com.sun.star.util.DateTime;
37 import com.sun.star.util.Time;
38 
39 public class RowSet implements XRowSet, XRow
40 {
41     private XRowSet                 m_rowSet;
42     private XRow                    m_row;
43     private XPropertySet            m_rowSetProps;
44 
RowSet( XComponentContext _context, String _dataSource, int _commandType, String _command )45     public RowSet( XComponentContext _context, String _dataSource, int _commandType, String _command )
46     {
47         try
48         {
49             m_rowSetProps = UnoRuntime.queryInterface(
50                 XPropertySet.class, _context.getServiceManager().createInstanceWithContext( "com.sun.star.sdb.RowSet", _context ) );
51             m_rowSetProps.setPropertyValue( "DataSourceName", _dataSource );
52             m_rowSetProps.setPropertyValue( "CommandType", Integer.valueOf( _commandType ) );
53             m_rowSetProps.setPropertyValue( "Command", _command );
54 
55             m_rowSet = UnoRuntime.queryInterface( XRowSet.class, m_rowSetProps );
56             m_row = UnoRuntime.queryInterface( XRow.class, m_rowSetProps );
57         }
58         catch ( Exception e )
59         {
60             e.printStackTrace(System.err);
61             throw new java.lang.InstantiationError();
62         }
63     }
64 
65     // misc
getColumnCount()66     public int getColumnCount()
67     {
68         XColumnsSupplier suppCols = UnoRuntime.queryInterface(
69             XColumnsSupplier.class, m_rowSet );
70         XIndexAccess columns = UnoRuntime.queryInterface(
71             XIndexAccess.class, suppCols.getColumns() );
72         return columns.getCount();
73     }
74 
75     // XRowSet
execute()76     public void execute() throws SQLException
77     {
78         m_rowSet.execute();
79     }
80 
addRowSetListener( XRowSetListener _listener )81     public void addRowSetListener( XRowSetListener _listener )
82     {
83         m_rowSet.addRowSetListener( _listener );
84     }
85 
removeRowSetListener( XRowSetListener _listener )86     public void removeRowSetListener( XRowSetListener _listener )
87     {
88         m_rowSet.removeRowSetListener( _listener );
89     }
90 
next()91     public boolean next() throws SQLException
92     {
93         return m_rowSet.next();
94     }
95 
isBeforeFirst()96     public boolean isBeforeFirst() throws SQLException
97     {
98         return m_rowSet.isBeforeFirst();
99     }
100 
isAfterLast()101     public boolean isAfterLast() throws SQLException
102     {
103         return m_rowSet.isAfterLast();
104     }
105 
isFirst()106     public boolean isFirst() throws SQLException
107     {
108         return m_rowSet.isFirst();
109     }
110 
isLast()111     public boolean isLast() throws SQLException
112     {
113         return m_rowSet.isLast();
114     }
115 
beforeFirst()116     public void beforeFirst() throws SQLException
117     {
118         m_rowSet.beforeFirst();
119     }
120 
afterLast()121     public void afterLast() throws SQLException
122     {
123         m_rowSet.afterLast();
124     }
125 
first()126     public boolean first() throws SQLException
127     {
128         return m_rowSet.first();
129     }
130 
last()131     public boolean last() throws SQLException
132     {
133         return m_rowSet.last();
134     }
135 
getRow()136     public int getRow() throws SQLException
137     {
138         return m_rowSet.getRow();
139     }
140 
absolute(int i)141     public boolean absolute(int i) throws SQLException
142     {
143         return m_rowSet.absolute(i);
144     }
145 
relative(int i)146     public boolean relative(int i) throws SQLException
147     {
148         return m_rowSet.relative(i);
149     }
150 
previous()151     public boolean previous() throws SQLException
152     {
153         return m_rowSet.previous();
154     }
155 
refreshRow()156     public void refreshRow() throws SQLException
157     {
158         m_rowSet.refreshRow();
159     }
160 
rowUpdated()161     public boolean rowUpdated() throws SQLException
162     {
163         return m_rowSet.rowUpdated();
164     }
165 
rowInserted()166     public boolean rowInserted() throws SQLException
167     {
168         return m_rowSet.rowInserted();
169     }
170 
rowDeleted()171     public boolean rowDeleted() throws SQLException
172     {
173         return m_rowSet.rowDeleted();
174     }
175 
176     // XRow
getStatement()177     public Object getStatement() throws SQLException
178     {
179         return m_rowSet.getStatement();
180     }
181 
wasNull()182     public boolean wasNull() throws SQLException
183     {
184         return m_row.wasNull();
185     }
186 
getString(int i)187     public String getString(int i) throws SQLException
188     {
189         return m_row.getString(i);
190     }
191 
getBoolean(int i)192     public boolean getBoolean(int i) throws SQLException
193     {
194         return m_row.getBoolean(i);
195     }
196 
getByte(int i)197     public byte getByte(int i) throws SQLException
198     {
199         return m_row.getByte(i);
200     }
201 
getShort(int i)202     public short getShort(int i) throws SQLException
203     {
204         return m_row.getShort(i);
205     }
206 
getInt(int i)207     public int getInt(int i) throws SQLException
208     {
209         return m_row.getInt(i);
210     }
211 
getLong(int i)212     public long getLong(int i) throws SQLException
213     {
214         return m_row.getLong(i);
215     }
216 
getFloat(int i)217     public float getFloat(int i) throws SQLException
218     {
219         return m_row.getFloat(i);
220     }
221 
getDouble(int i)222     public double getDouble(int i) throws SQLException
223     {
224         return m_row.getDouble(i);
225     }
226 
getBytes(int i)227     public byte[] getBytes(int i) throws SQLException
228     {
229         return m_row.getBytes(i);
230     }
231 
getDate(int i)232     public Date getDate(int i) throws SQLException
233     {
234         return m_row.getDate(i);
235     }
236 
getTime(int i)237     public Time getTime(int i) throws SQLException
238     {
239         return m_row.getTime(i);
240     }
241 
getTimestamp(int i)242     public DateTime getTimestamp(int i) throws SQLException
243     {
244         return m_row.getTimestamp(i);
245     }
246 
getBinaryStream(int i)247     public XInputStream getBinaryStream(int i) throws SQLException
248     {
249         return m_row.getBinaryStream(i);
250     }
251 
getCharacterStream(int i)252     public XInputStream getCharacterStream(int i) throws SQLException
253     {
254         return m_row.getCharacterStream(i);
255     }
256 
getObject(int i, XNameAccess xNameAccess)257     public Object getObject(int i, XNameAccess xNameAccess) throws SQLException
258     {
259         return m_row.getObject(i, xNameAccess);
260     }
261 
getRef(int i)262     public XRef getRef(int i) throws SQLException
263     {
264         return m_row.getRef(i);
265     }
266 
getBlob(int i)267     public XBlob getBlob(int i) throws SQLException
268     {
269         return m_row.getBlob(i);
270     }
271 
getClob(int i)272     public XClob getClob(int i) throws SQLException
273     {
274         return m_row.getClob(i);
275     }
276 
getArray(int i)277     public XArray getArray(int i) throws SQLException
278     {
279         return m_row.getArray(i);
280     }
281 }
282 
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
284