summaryrefslogtreecommitdiff
path: root/connectivity/qa/connectivity/tools/RowSet.java
blob: e5b2545c2c53c7909b6ff2781ec2e446defb4484 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

package connectivity.tools;

import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XIndexAccess;
import com.sun.star.container.XNameAccess;
import com.sun.star.io.XInputStream;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XArray;
import com.sun.star.sdbc.XBlob;
import com.sun.star.sdbc.XClob;
import com.sun.star.sdbc.XRef;
import com.sun.star.sdbc.XRow;
import com.sun.star.sdbc.XRowSet;
import com.sun.star.sdbc.XRowSetListener;
import com.sun.star.sdbcx.XColumnsSupplier;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.Date;
import com.sun.star.util.DateTime;
import com.sun.star.util.Time;

public class RowSet implements XRowSet, XRow
{
    private XRowSet                 m_rowSet;
    private XRow                    m_row;
    private XPropertySet            m_rowSetProps;

    public RowSet( XMultiServiceFactory _orb, String _dataSource, int _commandType, String _command )
    {
        try
        {
            m_rowSetProps = UnoRuntime.queryInterface( XPropertySet.class, _orb.createInstance( "com.sun.star.sdb.RowSet" ) );
            m_rowSetProps.setPropertyValue( "DataSourceName", _dataSource );
            m_rowSetProps.setPropertyValue( "CommandType", Integer.valueOf( _commandType ) );
            m_rowSetProps.setPropertyValue( "Command", _command );

            m_rowSet = UnoRuntime.queryInterface( XRowSet.class, m_rowSetProps );
            m_row = UnoRuntime.queryInterface( XRow.class, m_rowSetProps );
        }
        catch ( Exception e )
        {
            e.printStackTrace(System.err);
            throw new java.lang.InstantiationError();
        }
    }

    // misc
    public int getColumnCount()
    {
        XColumnsSupplier suppCols = UnoRuntime.queryInterface(
            XColumnsSupplier.class, m_rowSet );
        XIndexAccess columns = UnoRuntime.queryInterface(
            XIndexAccess.class, suppCols.getColumns() );
        return columns.getCount();
    }

    // XRowSet
    public void execute() throws SQLException
    {
        m_rowSet.execute();
    }

    public void addRowSetListener( XRowSetListener _listener )
    {
        m_rowSet.addRowSetListener( _listener );
    }

    public void removeRowSetListener( XRowSetListener _listener )
    {
        m_rowSet.removeRowSetListener( _listener );
    }

    public boolean next() throws SQLException
    {
        return m_rowSet.next();
    }

    public boolean isBeforeFirst() throws SQLException
    {
        return m_rowSet.isBeforeFirst();
    }

    public boolean isAfterLast() throws SQLException
    {
        return m_rowSet.isAfterLast();
    }

    public boolean isFirst() throws SQLException
    {
        return m_rowSet.isFirst();
    }

    public boolean isLast() throws SQLException
    {
        return m_rowSet.isLast();
    }

    public void beforeFirst() throws SQLException
    {
        m_rowSet.beforeFirst();
    }

    public void afterLast() throws SQLException
    {
        m_rowSet.afterLast();
    }

    public boolean first() throws SQLException
    {
        return m_rowSet.first();
    }

    public boolean last() throws SQLException
    {
        return m_rowSet.last();
    }

    public int getRow() throws SQLException
    {
        return m_rowSet.getRow();
    }

    public boolean absolute(int i) throws SQLException
    {
        return m_rowSet.absolute(i);
    }

    public boolean relative(int i) throws SQLException
    {
        return m_rowSet.relative(i);
    }

    public boolean previous() throws SQLException
    {
        return m_rowSet.previous();
    }

    public void refreshRow() throws SQLException
    {
        m_rowSet.refreshRow();
    }

    public boolean rowUpdated() throws SQLException
    {
        return m_rowSet.rowUpdated();
    }

    public boolean rowInserted() throws SQLException
    {
        return m_rowSet.rowInserted();
    }

    public boolean rowDeleted() throws SQLException
    {
        return m_rowSet.rowDeleted();
    }

    // XRow
    public Object getStatement() throws SQLException
    {
        return m_rowSet.getStatement();
    }

    public boolean wasNull() throws SQLException
    {
        return m_row.wasNull();
    }

    public String getString(int i) throws SQLException
    {
        return m_row.getString(i);
    }

    public boolean getBoolean(int i) throws SQLException
    {
        return m_row.getBoolean(i);
    }

    public byte getByte(int i) throws SQLException
    {
        return m_row.getByte(i);
    }

    public short getShort(int i) throws SQLException
    {
        return m_row.getShort(i);
    }

    public int getInt(int i) throws SQLException
    {
        return m_row.getInt(i);
    }

    public long getLong(int i) throws SQLException
    {
        return m_row.getLong(i);
    }

    public float getFloat(int i) throws SQLException
    {
        return m_row.getFloat(i);
    }

    public double getDouble(int i) throws SQLException
    {
        return m_row.getDouble(i);
    }

    public byte[] getBytes(int i) throws SQLException
    {
        return m_row.getBytes(i);
    }

    public Date getDate(int i) throws SQLException
    {
        return m_row.getDate(i);
    }

    public Time getTime(int i) throws SQLException
    {
        return m_row.getTime(i);
    }

    public DateTime getTimestamp(int i) throws SQLException
    {
        return m_row.getTimestamp(i);
    }

    public XInputStream getBinaryStream(int i) throws SQLException
    {
        return m_row.getBinaryStream(i);
    }

    public XInputStream getCharacterStream(int i) throws SQLException
    {
        return m_row.getCharacterStream(i);
    }

    public Object getObject(int i, XNameAccess xNameAccess) throws SQLException
    {
        return m_row.getObject(i, xNameAccess);
    }

    public XRef getRef(int i) throws SQLException
    {
        return m_row.getRef(i);
    }

    public XBlob getBlob(int i) throws SQLException
    {
        return m_row.getBlob(i);
    }

    public XClob getClob(int i) throws SQLException
    {
        return m_row.getClob(i);
    }

    public XArray getArray(int i) throws SQLException
    {
        return m_row.getArray(i);
    }

    public void dispose()
    {
        if ( m_rowSet == null )
            return;
        XComponent rowSetComp = UnoRuntime.queryInterface( XComponent.class, m_rowSet );
        rowSetComp.dispose();
    }
}