Branch libreoffice-5-0-4
[LibreOffice.git] / odk / examples / DevelopersGuide / Forms / RowSet.java
blob8c0a1534a294b7638d5cb1836ffd31ab3a395474
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import com.sun.star.beans.XPropertySet;
20 import com.sun.star.container.XIndexAccess;
21 import com.sun.star.container.XNameAccess;
22 import com.sun.star.io.XInputStream;
23 import com.sun.star.sdbc.SQLException;
24 import com.sun.star.sdbc.XArray;
25 import com.sun.star.sdbc.XBlob;
26 import com.sun.star.sdbc.XClob;
27 import com.sun.star.sdbc.XRef;
28 import com.sun.star.sdbc.XRow;
29 import com.sun.star.sdbc.XRowSet;
30 import com.sun.star.sdbc.XRowSetListener;
31 import com.sun.star.sdbcx.XColumnsSupplier;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XComponentContext;
34 import com.sun.star.util.Date;
35 import com.sun.star.util.DateTime;
36 import com.sun.star.util.Time;
38 public class RowSet implements XRowSet, XRow
40 private XRowSet m_rowSet;
41 private XRow m_row;
42 private XPropertySet m_rowSetProps;
44 public RowSet( XComponentContext _context, String _dataSource, int _commandType, String _command )
46 try
48 m_rowSetProps = UnoRuntime.queryInterface(
49 XPropertySet.class, _context.getServiceManager().createInstanceWithContext( "com.sun.star.sdb.RowSet", _context ) );
50 m_rowSetProps.setPropertyValue( "DataSourceName", _dataSource );
51 m_rowSetProps.setPropertyValue( "CommandType", Integer.valueOf( _commandType ) );
52 m_rowSetProps.setPropertyValue( "Command", _command );
54 m_rowSet = UnoRuntime.queryInterface( XRowSet.class, m_rowSetProps );
55 m_row = UnoRuntime.queryInterface( XRow.class, m_rowSetProps );
57 catch ( Exception e )
59 e.printStackTrace(System.err);
60 throw new java.lang.InstantiationError();
64 // misc
65 public int getColumnCount()
67 XColumnsSupplier suppCols = UnoRuntime.queryInterface(
68 XColumnsSupplier.class, m_rowSet );
69 XIndexAccess columns = UnoRuntime.queryInterface(
70 XIndexAccess.class, suppCols.getColumns() );
71 return columns.getCount();
74 // XRowSet
75 public void execute() throws SQLException
77 m_rowSet.execute();
80 public void addRowSetListener( XRowSetListener _listener )
82 m_rowSet.addRowSetListener( _listener );
85 public void removeRowSetListener( XRowSetListener _listener )
87 m_rowSet.removeRowSetListener( _listener );
90 public boolean next() throws SQLException
92 return m_rowSet.next();
95 public boolean isBeforeFirst() throws SQLException
97 return m_rowSet.isBeforeFirst();
100 public boolean isAfterLast() throws SQLException
102 return m_rowSet.isAfterLast();
105 public boolean isFirst() throws SQLException
107 return m_rowSet.isFirst();
110 public boolean isLast() throws SQLException
112 return m_rowSet.isLast();
115 public void beforeFirst() throws SQLException
117 m_rowSet.beforeFirst();
120 public void afterLast() throws SQLException
122 m_rowSet.afterLast();
125 public boolean first() throws SQLException
127 return m_rowSet.first();
130 public boolean last() throws SQLException
132 return m_rowSet.last();
135 public int getRow() throws SQLException
137 return m_rowSet.getRow();
140 public boolean absolute(int i) throws SQLException
142 return m_rowSet.absolute(i);
145 public boolean relative(int i) throws SQLException
147 return m_rowSet.relative(i);
150 public boolean previous() throws SQLException
152 return m_rowSet.previous();
155 public void refreshRow() throws SQLException
157 m_rowSet.refreshRow();
160 public boolean rowUpdated() throws SQLException
162 return m_rowSet.rowUpdated();
165 public boolean rowInserted() throws SQLException
167 return m_rowSet.rowInserted();
170 public boolean rowDeleted() throws SQLException
172 return m_rowSet.rowDeleted();
175 // XRow
176 public Object getStatement() throws SQLException
178 return m_rowSet.getStatement();
181 public boolean wasNull() throws SQLException
183 return m_row.wasNull();
186 public String getString(int i) throws SQLException
188 return m_row.getString(i);
191 public boolean getBoolean(int i) throws SQLException
193 return m_row.getBoolean(i);
196 public byte getByte(int i) throws SQLException
198 return m_row.getByte(i);
201 public short getShort(int i) throws SQLException
203 return m_row.getShort(i);
206 public int getInt(int i) throws SQLException
208 return m_row.getInt(i);
211 public long getLong(int i) throws SQLException
213 return m_row.getLong(i);
216 public float getFloat(int i) throws SQLException
218 return m_row.getFloat(i);
221 public double getDouble(int i) throws SQLException
223 return m_row.getDouble(i);
226 public byte[] getBytes(int i) throws SQLException
228 return m_row.getBytes(i);
231 public Date getDate(int i) throws SQLException
233 return m_row.getDate(i);
236 public Time getTime(int i) throws SQLException
238 return m_row.getTime(i);
241 public DateTime getTimestamp(int i) throws SQLException
243 return m_row.getTimestamp(i);
246 public XInputStream getBinaryStream(int i) throws SQLException
248 return m_row.getBinaryStream(i);
251 public XInputStream getCharacterStream(int i) throws SQLException
253 return m_row.getCharacterStream(i);
256 public Object getObject(int i, XNameAccess xNameAccess) throws SQLException
258 return m_row.getObject(i, xNameAccess);
261 public XRef getRef(int i) throws SQLException
263 return m_row.getRef(i);
266 public XBlob getBlob(int i) throws SQLException
268 return m_row.getBlob(i);
271 public XClob getClob(int i) throws SQLException
273 return m_row.getClob(i);
276 public XArray getArray(int i) throws SQLException
278 return m_row.getArray(i);