merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Forms / RowSet.java
blob2adb4a28589015b09613805030544cd7cff0aa6c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.container.XNameAccess;
31 import com.sun.star.io.XInputStream;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.sdbc.SQLException;
34 import com.sun.star.sdbc.XArray;
35 import com.sun.star.sdbc.XBlob;
36 import com.sun.star.sdbc.XClob;
37 import com.sun.star.sdbc.XRef;
38 import com.sun.star.sdbc.XRow;
39 import com.sun.star.sdbc.XRowSet;
40 import com.sun.star.sdbc.XRowSetListener;
41 import com.sun.star.sdbcx.XColumnsSupplier;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XComponentContext;
44 import com.sun.star.util.Date;
45 import com.sun.star.util.DateTime;
46 import com.sun.star.util.Time;
48 public class RowSet implements XRowSet, XRow
50 private XRowSet m_rowSet;
51 private XRow m_row;
52 private XPropertySet m_rowSetProps;
54 public RowSet( XComponentContext _context, String _dataSource, int _commandType, String _command )
56 try
58 m_rowSetProps = (XPropertySet)UnoRuntime.queryInterface(
59 XPropertySet.class, _context.getServiceManager().createInstanceWithContext( "com.sun.star.sdb.RowSet", _context ) );
60 m_rowSetProps.setPropertyValue( "DataSourceName", _dataSource );
61 m_rowSetProps.setPropertyValue( "CommandType", new Integer( _commandType ) );
62 m_rowSetProps.setPropertyValue( "Command", _command );
64 m_rowSet = (XRowSet)UnoRuntime.queryInterface( XRowSet.class, m_rowSetProps );
65 m_row = (XRow)UnoRuntime.queryInterface( XRow.class, m_rowSetProps );
67 catch ( Exception e )
69 e.printStackTrace(System.err);
70 throw new java.lang.InstantiationError();
74 // misc
75 public int getColumnCount()
77 XColumnsSupplier suppCols = (XColumnsSupplier)UnoRuntime.queryInterface(
78 XColumnsSupplier.class, m_rowSet );
79 XIndexAccess columns = (XIndexAccess)UnoRuntime.queryInterface(
80 XIndexAccess.class, suppCols.getColumns() );
81 return columns.getCount();
84 // XRowSet
85 public void execute() throws SQLException
87 m_rowSet.execute();
90 public void addRowSetListener( XRowSetListener _listener )
92 m_rowSet.addRowSetListener( _listener );
95 public void removeRowSetListener( XRowSetListener _listener )
97 m_rowSet.removeRowSetListener( _listener );
100 public boolean next() throws SQLException
102 return m_rowSet.next();
105 public boolean isBeforeFirst() throws SQLException
107 return m_rowSet.isBeforeFirst();
110 public boolean isAfterLast() throws SQLException
112 return m_rowSet.isAfterLast();
115 public boolean isFirst() throws SQLException
117 return m_rowSet.isFirst();
120 public boolean isLast() throws SQLException
122 return m_rowSet.isLast();
125 public void beforeFirst() throws SQLException
127 m_rowSet.beforeFirst();
130 public void afterLast() throws SQLException
132 m_rowSet.afterLast();
135 public boolean first() throws SQLException
137 return m_rowSet.first();
140 public boolean last() throws SQLException
142 return m_rowSet.last();
145 public int getRow() throws SQLException
147 return m_rowSet.getRow();
150 public boolean absolute(int i) throws SQLException
152 return m_rowSet.absolute(i);
155 public boolean relative(int i) throws SQLException
157 return m_rowSet.relative(i);
160 public boolean previous() throws SQLException
162 return m_rowSet.previous();
165 public void refreshRow() throws SQLException
167 m_rowSet.refreshRow();
170 public boolean rowUpdated() throws SQLException
172 return m_rowSet.rowUpdated();
175 public boolean rowInserted() throws SQLException
177 return m_rowSet.rowInserted();
180 public boolean rowDeleted() throws SQLException
182 return m_rowSet.rowDeleted();
185 // XRow
186 public Object getStatement() throws SQLException
188 return m_rowSet.getStatement();
191 public boolean wasNull() throws SQLException
193 return m_row.wasNull();
196 public String getString(int i) throws SQLException
198 return m_row.getString(i);
201 public boolean getBoolean(int i) throws SQLException
203 return m_row.getBoolean(i);
206 public byte getByte(int i) throws SQLException
208 return m_row.getByte(i);
211 public short getShort(int i) throws SQLException
213 return m_row.getShort(i);
216 public int getInt(int i) throws SQLException
218 return m_row.getInt(i);
221 public long getLong(int i) throws SQLException
223 return m_row.getLong(i);
226 public float getFloat(int i) throws SQLException
228 return m_row.getFloat(i);
231 public double getDouble(int i) throws SQLException
233 return m_row.getDouble(i);
236 public byte[] getBytes(int i) throws SQLException
238 return m_row.getBytes(i);
241 public Date getDate(int i) throws SQLException
243 return m_row.getDate(i);
246 public Time getTime(int i) throws SQLException
248 return m_row.getTime(i);
251 public DateTime getTimestamp(int i) throws SQLException
253 return m_row.getTimestamp(i);
256 public XInputStream getBinaryStream(int i) throws SQLException
258 return m_row.getBinaryStream(i);
261 public XInputStream getCharacterStream(int i) throws SQLException
263 return m_row.getCharacterStream(i);
266 public Object getObject(int i, XNameAccess xNameAccess) throws SQLException
268 return m_row.getObject(i, xNameAccess);
271 public XRef getRef(int i) throws SQLException
273 return m_row.getRef(i);
276 public XBlob getBlob(int i) throws SQLException
278 return m_row.getBlob(i);
281 public XClob getClob(int i) throws SQLException
283 return m_row.getClob(i);
286 public XArray getArray(int i) throws SQLException
288 return m_row.getArray(i);