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