1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 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; 47 48 public class RowSet implements XRowSet, XRow 49 { 50 private XRowSet m_rowSet; 51 private XRow m_row; 52 private XPropertySet m_rowSetProps; 53 54 public RowSet( XComponentContext _context, String _dataSource, int _commandType, String _command ) 55 { 56 try 57 { 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 ); 63 64 m_rowSet = (XRowSet)UnoRuntime.queryInterface( XRowSet.class, m_rowSetProps ); 65 m_row = (XRow)UnoRuntime.queryInterface( XRow.class, m_rowSetProps ); 66 } 67 catch ( Exception e ) 68 { 69 e.printStackTrace(System.err); 70 throw new java.lang.InstantiationError(); 71 } 72 } 73 74 // misc 75 public int getColumnCount() 76 { 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(); 82 } 83 84 // XRowSet 85 public void execute() throws SQLException 86 { 87 m_rowSet.execute(); 88 } 89 90 public void addRowSetListener( XRowSetListener _listener ) 91 { 92 m_rowSet.addRowSetListener( _listener ); 93 } 94 95 public void removeRowSetListener( XRowSetListener _listener ) 96 { 97 m_rowSet.removeRowSetListener( _listener ); 98 } 99 100 public boolean next() throws SQLException 101 { 102 return m_rowSet.next(); 103 } 104 105 public boolean isBeforeFirst() throws SQLException 106 { 107 return m_rowSet.isBeforeFirst(); 108 } 109 110 public boolean isAfterLast() throws SQLException 111 { 112 return m_rowSet.isAfterLast(); 113 } 114 115 public boolean isFirst() throws SQLException 116 { 117 return m_rowSet.isFirst(); 118 } 119 120 public boolean isLast() throws SQLException 121 { 122 return m_rowSet.isLast(); 123 } 124 125 public void beforeFirst() throws SQLException 126 { 127 m_rowSet.beforeFirst(); 128 } 129 130 public void afterLast() throws SQLException 131 { 132 m_rowSet.afterLast(); 133 } 134 135 public boolean first() throws SQLException 136 { 137 return m_rowSet.first(); 138 } 139 140 public boolean last() throws SQLException 141 { 142 return m_rowSet.last(); 143 } 144 145 public int getRow() throws SQLException 146 { 147 return m_rowSet.getRow(); 148 } 149 150 public boolean absolute(int i) throws SQLException 151 { 152 return m_rowSet.absolute(i); 153 } 154 155 public boolean relative(int i) throws SQLException 156 { 157 return m_rowSet.relative(i); 158 } 159 160 public boolean previous() throws SQLException 161 { 162 return m_rowSet.previous(); 163 } 164 165 public void refreshRow() throws SQLException 166 { 167 m_rowSet.refreshRow(); 168 } 169 170 public boolean rowUpdated() throws SQLException 171 { 172 return m_rowSet.rowUpdated(); 173 } 174 175 public boolean rowInserted() throws SQLException 176 { 177 return m_rowSet.rowInserted(); 178 } 179 180 public boolean rowDeleted() throws SQLException 181 { 182 return m_rowSet.rowDeleted(); 183 } 184 185 // XRow 186 public Object getStatement() throws SQLException 187 { 188 return m_rowSet.getStatement(); 189 } 190 191 public boolean wasNull() throws SQLException 192 { 193 return m_row.wasNull(); 194 } 195 196 public String getString(int i) throws SQLException 197 { 198 return m_row.getString(i); 199 } 200 201 public boolean getBoolean(int i) throws SQLException 202 { 203 return m_row.getBoolean(i); 204 } 205 206 public byte getByte(int i) throws SQLException 207 { 208 return m_row.getByte(i); 209 } 210 211 public short getShort(int i) throws SQLException 212 { 213 return m_row.getShort(i); 214 } 215 216 public int getInt(int i) throws SQLException 217 { 218 return m_row.getInt(i); 219 } 220 221 public long getLong(int i) throws SQLException 222 { 223 return m_row.getLong(i); 224 } 225 226 public float getFloat(int i) throws SQLException 227 { 228 return m_row.getFloat(i); 229 } 230 231 public double getDouble(int i) throws SQLException 232 { 233 return m_row.getDouble(i); 234 } 235 236 public byte[] getBytes(int i) throws SQLException 237 { 238 return m_row.getBytes(i); 239 } 240 241 public Date getDate(int i) throws SQLException 242 { 243 return m_row.getDate(i); 244 } 245 246 public Time getTime(int i) throws SQLException 247 { 248 return m_row.getTime(i); 249 } 250 251 public DateTime getTimestamp(int i) throws SQLException 252 { 253 return m_row.getTimestamp(i); 254 } 255 256 public XInputStream getBinaryStream(int i) throws SQLException 257 { 258 return m_row.getBinaryStream(i); 259 } 260 261 public XInputStream getCharacterStream(int i) throws SQLException 262 { 263 return m_row.getCharacterStream(i); 264 } 265 266 public Object getObject(int i, XNameAccess xNameAccess) throws SQLException 267 { 268 return m_row.getObject(i, xNameAccess); 269 } 270 271 public XRef getRef(int i) throws SQLException 272 { 273 return m_row.getRef(i); 274 } 275 276 public XBlob getBlob(int i) throws SQLException 277 { 278 return m_row.getBlob(i); 279 } 280 281 public XClob getClob(int i) throws SQLException 282 { 283 return m_row.getClob(i); 284 } 285 286 public XArray getArray(int i) throws SQLException 287 { 288 return m_row.getArray(i); 289 } 290 }; 291