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 import com.sun.star.beans.XPropertySet;
25 import com.sun.star.container.XIndexAccess;
26 import com.sun.star.container.XNameAccess;
27 import com.sun.star.io.XInputStream;
28 import com.sun.star.lang.XMultiServiceFactory;
29 import com.sun.star.sdbc.SQLException;
30 import com.sun.star.sdbc.XArray;
31 import com.sun.star.sdbc.XBlob;
32 import com.sun.star.sdbc.XClob;
33 import com.sun.star.sdbc.XRef;
34 import com.sun.star.sdbc.XRow;
35 import com.sun.star.sdbc.XRowSet;
36 import com.sun.star.sdbc.XRowSetListener;
37 import com.sun.star.sdbcx.XColumnsSupplier;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XComponentContext;
40 import com.sun.star.util.Date;
41 import com.sun.star.util.DateTime;
42 import com.sun.star.util.Time;
43 
44 public class RowSet implements XRowSet, XRow
45 {
46     private XRowSet                 m_rowSet;
47     private XRow                    m_row;
48     private XPropertySet            m_rowSetProps;
49 
RowSet( XComponentContext _context, String _dataSource, int _commandType, String _command )50     public RowSet( XComponentContext _context, String _dataSource, int _commandType, String _command )
51     {
52         try
53         {
54             m_rowSetProps = (XPropertySet)UnoRuntime.queryInterface(
55                 XPropertySet.class, _context.getServiceManager().createInstanceWithContext( "com.sun.star.sdb.RowSet", _context ) );
56             m_rowSetProps.setPropertyValue( "DataSourceName", _dataSource );
57             m_rowSetProps.setPropertyValue( "CommandType", new Integer( _commandType ) );
58             m_rowSetProps.setPropertyValue( "Command", _command );
59 
60             m_rowSet = (XRowSet)UnoRuntime.queryInterface( XRowSet.class, m_rowSetProps );
61             m_row = (XRow)UnoRuntime.queryInterface( XRow.class, m_rowSetProps );
62         }
63         catch ( Exception e )
64         {
65             e.printStackTrace(System.err);
66             throw new java.lang.InstantiationError();
67         }
68     }
69 
70     // misc
getColumnCount()71     public int getColumnCount()
72     {
73         XColumnsSupplier suppCols = (XColumnsSupplier)UnoRuntime.queryInterface(
74             XColumnsSupplier.class, m_rowSet );
75         XIndexAccess columns = (XIndexAccess)UnoRuntime.queryInterface(
76             XIndexAccess.class, suppCols.getColumns() );
77         return columns.getCount();
78     }
79 
80     // XRowSet
execute()81     public void execute() throws SQLException
82     {
83         m_rowSet.execute();
84     }
85 
addRowSetListener( XRowSetListener _listener )86     public void addRowSetListener( XRowSetListener _listener )
87     {
88         m_rowSet.addRowSetListener( _listener );
89     }
90 
removeRowSetListener( XRowSetListener _listener )91     public void removeRowSetListener( XRowSetListener _listener )
92     {
93         m_rowSet.removeRowSetListener( _listener );
94     }
95 
next()96     public boolean next() throws SQLException
97     {
98         return m_rowSet.next();
99     }
100 
isBeforeFirst()101     public boolean isBeforeFirst() throws SQLException
102     {
103         return m_rowSet.isBeforeFirst();
104     }
105 
isAfterLast()106     public boolean isAfterLast() throws SQLException
107     {
108         return m_rowSet.isAfterLast();
109     }
110 
isFirst()111     public boolean isFirst() throws SQLException
112     {
113         return m_rowSet.isFirst();
114     }
115 
isLast()116     public boolean isLast() throws SQLException
117     {
118         return m_rowSet.isLast();
119     }
120 
beforeFirst()121     public void beforeFirst() throws SQLException
122     {
123         m_rowSet.beforeFirst();
124     }
125 
afterLast()126     public void afterLast() throws SQLException
127     {
128         m_rowSet.afterLast();
129     }
130 
first()131     public boolean first() throws SQLException
132     {
133         return m_rowSet.first();
134     }
135 
last()136     public boolean last() throws SQLException
137     {
138         return m_rowSet.last();
139     }
140 
getRow()141     public int getRow() throws SQLException
142     {
143         return m_rowSet.getRow();
144     }
145 
absolute(int i)146     public boolean absolute(int i) throws SQLException
147     {
148         return m_rowSet.absolute(i);
149     }
150 
relative(int i)151     public boolean relative(int i) throws SQLException
152     {
153         return m_rowSet.relative(i);
154     }
155 
previous()156     public boolean previous() throws SQLException
157     {
158         return m_rowSet.previous();
159     }
160 
refreshRow()161     public void refreshRow() throws SQLException
162     {
163         m_rowSet.refreshRow();
164     }
165 
rowUpdated()166     public boolean rowUpdated() throws SQLException
167     {
168         return m_rowSet.rowUpdated();
169     }
170 
rowInserted()171     public boolean rowInserted() throws SQLException
172     {
173         return m_rowSet.rowInserted();
174     }
175 
rowDeleted()176     public boolean rowDeleted() throws SQLException
177     {
178         return m_rowSet.rowDeleted();
179     }
180 
181     // XRow
getStatement()182     public Object getStatement() throws SQLException
183     {
184         return m_rowSet.getStatement();
185     }
186 
wasNull()187     public boolean wasNull() throws SQLException
188     {
189         return m_row.wasNull();
190     }
191 
getString(int i)192     public String getString(int i) throws SQLException
193     {
194         return m_row.getString(i);
195     }
196 
getBoolean(int i)197     public boolean getBoolean(int i) throws SQLException
198     {
199         return m_row.getBoolean(i);
200     }
201 
getByte(int i)202     public byte getByte(int i) throws SQLException
203     {
204         return m_row.getByte(i);
205     }
206 
getShort(int i)207     public short getShort(int i) throws SQLException
208     {
209         return m_row.getShort(i);
210     }
211 
getInt(int i)212     public int getInt(int i) throws SQLException
213     {
214         return m_row.getInt(i);
215     }
216 
getLong(int i)217     public long getLong(int i) throws SQLException
218     {
219         return m_row.getLong(i);
220     }
221 
getFloat(int i)222     public float getFloat(int i) throws SQLException
223     {
224         return m_row.getFloat(i);
225     }
226 
getDouble(int i)227     public double getDouble(int i) throws SQLException
228     {
229         return m_row.getDouble(i);
230     }
231 
getBytes(int i)232     public byte[] getBytes(int i) throws SQLException
233     {
234         return m_row.getBytes(i);
235     }
236 
getDate(int i)237     public Date getDate(int i) throws SQLException
238     {
239         return m_row.getDate(i);
240     }
241 
getTime(int i)242     public Time getTime(int i) throws SQLException
243     {
244         return m_row.getTime(i);
245     }
246 
getTimestamp(int i)247     public DateTime getTimestamp(int i) throws SQLException
248     {
249         return m_row.getTimestamp(i);
250     }
251 
getBinaryStream(int i)252     public XInputStream getBinaryStream(int i) throws SQLException
253     {
254         return m_row.getBinaryStream(i);
255     }
256 
getCharacterStream(int i)257     public XInputStream getCharacterStream(int i) throws SQLException
258     {
259         return m_row.getCharacterStream(i);
260     }
261 
getObject(int i, XNameAccess xNameAccess)262     public Object getObject(int i, XNameAccess xNameAccess) throws SQLException
263     {
264         return m_row.getObject(i, xNameAccess);
265     }
266 
getRef(int i)267     public XRef getRef(int i) throws SQLException
268     {
269         return m_row.getRef(i);
270     }
271 
getBlob(int i)272     public XBlob getBlob(int i) throws SQLException
273     {
274         return m_row.getBlob(i);
275     }
276 
getClob(int i)277     public XClob getClob(int i) throws SQLException
278     {
279         return m_row.getClob(i);
280     }
281 
getArray(int i)282     public XArray getArray(int i) throws SQLException
283     {
284         return m_row.getArray(i);
285     }
286 };
287