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 package com.sun.star.sdbcx.comp.postgresql; 23 24 import com.sun.star.beans.PropertyVetoException; 25 import com.sun.star.beans.UnknownPropertyException; 26 import com.sun.star.beans.XPropertyChangeListener; 27 import com.sun.star.beans.XPropertySet; 28 import com.sun.star.beans.XPropertySetInfo; 29 import com.sun.star.beans.XVetoableChangeListener; 30 import com.sun.star.io.XInputStream; 31 import com.sun.star.lang.IllegalArgumentException; 32 import com.sun.star.lang.WrappedTargetException; 33 import com.sun.star.lib.uno.helper.ComponentBase; 34 import com.sun.star.sdbc.SQLException; 35 import com.sun.star.sdbc.XArray; 36 import com.sun.star.sdbc.XBlob; 37 import com.sun.star.sdbc.XClob; 38 import com.sun.star.sdbc.XCloseable; 39 import com.sun.star.sdbc.XConnection; 40 import com.sun.star.sdbc.XMultipleResults; 41 import com.sun.star.sdbc.XParameters; 42 import com.sun.star.sdbc.XPreparedBatchExecution; 43 import com.sun.star.sdbc.XPreparedStatement; 44 import com.sun.star.sdbc.XRef; 45 import com.sun.star.sdbc.XResultSet; 46 import com.sun.star.sdbc.XResultSetMetaData; 47 import com.sun.star.sdbc.XResultSetMetaDataSupplier; 48 import com.sun.star.sdbc.XWarningsSupplier; 49 import com.sun.star.uno.UnoRuntime; 50 import com.sun.star.util.Date; 51 import com.sun.star.util.DateTime; 52 import com.sun.star.util.Time; 53 import com.sun.star.util.XCancellable; 54 55 public class PostgresqlPreparedStatement extends ComponentBase 56 implements XPreparedStatement, XCloseable, XPropertySet, XCancellable, XResultSetMetaDataSupplier, XParameters, XPreparedBatchExecution, 57 XWarningsSupplier, XMultipleResults { 58 59 private XPreparedStatement impl; 60 private XCloseable implCloseable; 61 private XPropertySet implPropertySet; 62 private XCancellable implCancellable; 63 private XResultSetMetaDataSupplier implResultSetMetaDataSupplier; 64 private XParameters implParameters; 65 private XPreparedBatchExecution implPreparedBatchExecution; 66 private XWarningsSupplier implWarningsSupplier; 67 private XMultipleResults implMultipleResults; 68 private XConnection connection; 69 PostgresqlPreparedStatement(XPreparedStatement impl, XConnection connection)70 public PostgresqlPreparedStatement(XPreparedStatement impl, XConnection connection) { 71 this.impl = impl; 72 this.implCloseable = UnoRuntime.queryInterface(XCloseable.class, impl); 73 this.implPropertySet = UnoRuntime.queryInterface(XPropertySet.class, impl); 74 this.implCancellable = UnoRuntime.queryInterface(XCancellable.class, impl); 75 this.implResultSetMetaDataSupplier = UnoRuntime.queryInterface(XResultSetMetaDataSupplier.class, impl); 76 this.implParameters = UnoRuntime.queryInterface(XParameters.class, impl); 77 this.implPreparedBatchExecution = UnoRuntime.queryInterface(XPreparedBatchExecution.class, impl); 78 this.implWarningsSupplier = UnoRuntime.queryInterface(XWarningsSupplier.class, impl); 79 this.implMultipleResults = UnoRuntime.queryInterface(XMultipleResults.class, impl); 80 this.connection = connection; 81 } 82 83 // XComponentBase: 84 85 @Override postDisposing()86 protected void postDisposing() { 87 try { 88 implCloseable.close(); 89 } catch (SQLException sqlException) { 90 } 91 } 92 93 // XPreparedStatement: 94 execute()95 public boolean execute() throws SQLException { 96 return impl.execute(); 97 } 98 executeQuery()99 public XResultSet executeQuery() throws SQLException { 100 return new PostgresqlResultSet(impl.executeQuery(), this); 101 } 102 executeUpdate()103 public int executeUpdate() throws SQLException { 104 return impl.executeUpdate(); 105 } 106 getConnection()107 public XConnection getConnection() throws SQLException { 108 return connection; 109 } 110 111 // XCloseable: 112 close()113 public void close() throws SQLException { 114 dispose(); 115 } 116 117 // XPropertySet: 118 addPropertyChangeListener(String arg0, XPropertyChangeListener arg1)119 public void addPropertyChangeListener(String arg0, XPropertyChangeListener arg1) throws UnknownPropertyException, WrappedTargetException { 120 implPropertySet.addPropertyChangeListener(arg0, arg1); 121 } 122 addVetoableChangeListener(String arg0, XVetoableChangeListener arg1)123 public void addVetoableChangeListener(String arg0, XVetoableChangeListener arg1) throws UnknownPropertyException, WrappedTargetException { 124 implPropertySet.addVetoableChangeListener(arg0, arg1); 125 } 126 getPropertySetInfo()127 public XPropertySetInfo getPropertySetInfo() { 128 return implPropertySet.getPropertySetInfo(); 129 } 130 getPropertyValue(String arg0)131 public Object getPropertyValue(String arg0) throws UnknownPropertyException, WrappedTargetException { 132 return implPropertySet.getPropertyValue(arg0); 133 } 134 removePropertyChangeListener(String arg0, XPropertyChangeListener arg1)135 public void removePropertyChangeListener(String arg0, XPropertyChangeListener arg1) throws UnknownPropertyException, WrappedTargetException { 136 implPropertySet.removePropertyChangeListener(arg0, arg1); 137 } 138 removeVetoableChangeListener(String arg0, XVetoableChangeListener arg1)139 public void removeVetoableChangeListener(String arg0, XVetoableChangeListener arg1) throws UnknownPropertyException, WrappedTargetException { 140 implPropertySet.removeVetoableChangeListener(arg0, arg1); 141 } 142 setPropertyValue(String arg0, Object arg1)143 public void setPropertyValue(String arg0, Object arg1) 144 throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException { 145 implPropertySet.setPropertyValue(arg0, arg1); 146 } 147 148 // XCancellable: 149 cancel()150 public void cancel() { 151 implCancellable.cancel(); 152 } 153 154 // XResultSetMetaDataSupplier: 155 getMetaData()156 public XResultSetMetaData getMetaData() throws SQLException { 157 return new PostgresqlResultSetMetaData(implResultSetMetaDataSupplier.getMetaData()); 158 } 159 160 // XParameters: 161 clearParameters()162 public void clearParameters() throws SQLException { 163 implParameters.clearParameters(); 164 } 165 setArray(int arg0, XArray arg1)166 public void setArray(int arg0, XArray arg1) throws SQLException { 167 implParameters.setArray(arg0, arg1); 168 } 169 setBinaryStream(int arg0, XInputStream arg1, int arg2)170 public void setBinaryStream(int arg0, XInputStream arg1, int arg2) throws SQLException { 171 implParameters.setBinaryStream(arg0, arg1, arg2); 172 } 173 setBlob(int arg0, XBlob arg1)174 public void setBlob(int arg0, XBlob arg1) throws SQLException { 175 implParameters.setBlob(arg0, arg1); 176 } 177 setBoolean(int arg0, boolean arg1)178 public void setBoolean(int arg0, boolean arg1) throws SQLException { 179 implParameters.setBoolean(arg0, arg1); 180 } 181 setByte(int arg0, byte arg1)182 public void setByte(int arg0, byte arg1) throws SQLException { 183 implParameters.setByte(arg0, arg1); 184 } 185 setBytes(int arg0, byte[] arg1)186 public void setBytes(int arg0, byte[] arg1) throws SQLException { 187 implParameters.setBytes(arg0, arg1); 188 } 189 setCharacterStream(int arg0, XInputStream arg1, int arg2)190 public void setCharacterStream(int arg0, XInputStream arg1, int arg2) throws SQLException { 191 implParameters.setCharacterStream(arg0, arg1, arg2); 192 } 193 setClob(int arg0, XClob arg1)194 public void setClob(int arg0, XClob arg1) throws SQLException { 195 implParameters.setClob(arg0, arg1); 196 } 197 setDate(int arg0, Date arg1)198 public void setDate(int arg0, Date arg1) throws SQLException { 199 implParameters.setDate(arg0, arg1); 200 } 201 setDouble(int arg0, double arg1)202 public void setDouble(int arg0, double arg1) throws SQLException { 203 implParameters.setDouble(arg0, arg1); 204 } 205 setFloat(int arg0, float arg1)206 public void setFloat(int arg0, float arg1) throws SQLException { 207 implParameters.setFloat(arg0, arg1); 208 } 209 setInt(int arg0, int arg1)210 public void setInt(int arg0, int arg1) throws SQLException { 211 implParameters.setInt(arg0, arg1); 212 } 213 setLong(int arg0, long arg1)214 public void setLong(int arg0, long arg1) throws SQLException { 215 implParameters.setLong(arg0, arg1); 216 } 217 setNull(int arg0, int arg1)218 public void setNull(int arg0, int arg1) throws SQLException { 219 implParameters.setNull(arg0, arg1); 220 } 221 setObject(int arg0, Object arg1)222 public void setObject(int arg0, Object arg1) throws SQLException { 223 implParameters.setObject(arg0, arg1); 224 } 225 setObjectNull(int arg0, int arg1, String arg2)226 public void setObjectNull(int arg0, int arg1, String arg2) throws SQLException { 227 implParameters.setObjectNull(arg0, arg1, arg2); 228 } 229 setObjectWithInfo(int arg0, Object arg1, int arg2, int arg3)230 public void setObjectWithInfo(int arg0, Object arg1, int arg2, int arg3) throws SQLException { 231 implParameters.setObjectWithInfo(arg0, arg1, arg2, arg3); 232 } 233 setRef(int arg0, XRef arg1)234 public void setRef(int arg0, XRef arg1) throws SQLException { 235 implParameters.setRef(arg0, arg1); 236 } 237 setShort(int arg0, short arg1)238 public void setShort(int arg0, short arg1) throws SQLException { 239 implParameters.setShort(arg0, arg1); 240 } 241 setString(int arg0, String arg1)242 public void setString(int arg0, String arg1) throws SQLException { 243 implParameters.setString(arg0, arg1); 244 } 245 setTime(int arg0, Time arg1)246 public void setTime(int arg0, Time arg1) throws SQLException { 247 implParameters.setTime(arg0, arg1); 248 } 249 setTimestamp(int arg0, DateTime arg1)250 public void setTimestamp(int arg0, DateTime arg1) throws SQLException { 251 implParameters.setTimestamp(arg0, arg1); 252 } 253 254 // XPreparedBatchExecution: 255 addBatch()256 public void addBatch() throws SQLException { 257 implPreparedBatchExecution.addBatch(); 258 } 259 clearBatch()260 public void clearBatch() throws SQLException { 261 implPreparedBatchExecution.clearBatch(); 262 } 263 executeBatch()264 public int[] executeBatch() throws SQLException { 265 return implPreparedBatchExecution.executeBatch(); 266 } 267 268 // XWarningsSupplier: 269 clearWarnings()270 public void clearWarnings() throws SQLException { 271 implWarningsSupplier.clearWarnings(); 272 } 273 getWarnings()274 public Object getWarnings() throws SQLException { 275 return implWarningsSupplier.getWarnings(); 276 } 277 278 // XMultipleResults: 279 getMoreResults()280 public boolean getMoreResults() throws SQLException { 281 return implMultipleResults.getMoreResults(); 282 } 283 getResultSet()284 public XResultSet getResultSet() throws SQLException { 285 return new PostgresqlResultSet(implMultipleResults.getResultSet(), this); 286 } 287 getUpdateCount()288 public int getUpdateCount() throws SQLException { 289 return implMultipleResults.getUpdateCount(); 290 } 291 } 292