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.lang.IllegalArgumentException;
31 import com.sun.star.lang.WrappedTargetException;
32 import com.sun.star.lib.uno.helper.ComponentBase;
33 import com.sun.star.sdbc.SQLException;
34 import com.sun.star.sdbc.XCloseable;
35 import com.sun.star.sdbc.XConnection;
36 import com.sun.star.sdbc.XMultipleResults;
37 import com.sun.star.sdbc.XResultSet;
38 import com.sun.star.sdbc.XStatement;
39 import com.sun.star.sdbc.XWarningsSupplier;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.util.XCancellable;
42 
43 public class PostgresqlStatement extends ComponentBase
44         implements XCloseable, XPropertySet, XCancellable, XStatement, XWarningsSupplier, XMultipleResults {
45 
46     private XStatement impl;
47     private XCloseable implCloseable;
48     private XPropertySet implPropertySet;
49     private XCancellable implCancellable;
50     private XWarningsSupplier implWarningsSupplier;
51     private XMultipleResults implMultipleResults;
52     private XConnection connection;
53 
PostgresqlStatement(XStatement impl, XConnection connection)54     public PostgresqlStatement(XStatement impl, XConnection connection) {
55         this.impl = impl;
56         this.implCloseable = UnoRuntime.queryInterface(XCloseable.class, impl);
57         this.implPropertySet = UnoRuntime.queryInterface(XPropertySet.class, impl);
58         this.implCancellable = UnoRuntime.queryInterface(XCancellable.class, impl);
59         this.implWarningsSupplier = UnoRuntime.queryInterface(XWarningsSupplier.class, impl);
60         this.implMultipleResults = UnoRuntime.queryInterface(XMultipleResults.class, impl);
61         this.connection = connection;
62     }
63 
64     // XComponentBase:
65 
66     @Override
postDisposing()67     protected void postDisposing() {
68         try {
69             implCloseable.close();
70         } catch (SQLException sqlException) {
71         }
72     }
73 
74     // XStatement:
75 
execute(String arg0)76     public boolean execute(String arg0) throws SQLException {
77         System.out.println(arg0);
78         return impl.execute(arg0);
79     }
80 
executeQuery(String arg0)81     public XResultSet executeQuery(String arg0) throws SQLException {
82         XResultSet results = impl.executeQuery(arg0);
83         return new PostgresqlResultSet(results, this);
84     }
85 
executeUpdate(String arg0)86     public int executeUpdate(String arg0) throws SQLException {
87         return impl.executeUpdate(arg0);
88     }
89 
getConnection()90     public XConnection getConnection() throws SQLException {
91         return connection;
92     }
93 
94     // XCloseable:
95 
close()96     public void close() throws SQLException {
97         dispose();
98     }
99 
100     // XPropertySet:
101 
addPropertyChangeListener(String arg0, XPropertyChangeListener arg1)102     public void addPropertyChangeListener(String arg0, XPropertyChangeListener arg1) throws UnknownPropertyException, WrappedTargetException {
103         implPropertySet.addPropertyChangeListener(arg0, arg1);
104     }
105 
addVetoableChangeListener(String arg0, XVetoableChangeListener arg1)106     public void addVetoableChangeListener(String arg0, XVetoableChangeListener arg1) throws UnknownPropertyException, WrappedTargetException {
107         implPropertySet.addVetoableChangeListener(arg0, arg1);
108     }
109 
getPropertySetInfo()110     public XPropertySetInfo getPropertySetInfo() {
111         return implPropertySet.getPropertySetInfo();
112     }
113 
getPropertyValue(String arg0)114     public Object getPropertyValue(String arg0) throws UnknownPropertyException, WrappedTargetException {
115         return implPropertySet.getPropertyValue(arg0);
116     }
117 
removePropertyChangeListener(String arg0, XPropertyChangeListener arg1)118     public void removePropertyChangeListener(String arg0, XPropertyChangeListener arg1) throws UnknownPropertyException, WrappedTargetException {
119         implPropertySet.removePropertyChangeListener(arg0, arg1);
120     }
121 
removeVetoableChangeListener(String arg0, XVetoableChangeListener arg1)122     public void removeVetoableChangeListener(String arg0, XVetoableChangeListener arg1) throws UnknownPropertyException, WrappedTargetException {
123         implPropertySet.removeVetoableChangeListener(arg0, arg1);
124     }
125 
setPropertyValue(String arg0, Object arg1)126     public void setPropertyValue(String arg0, Object arg1)
127             throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException {
128         implPropertySet.setPropertyValue(arg0, arg1);
129     }
130 
131     // XCancellable:
132 
cancel()133     public void cancel() {
134         implCancellable.cancel();
135     }
136 
137     // XWarningsSupplier:
138 
clearWarnings()139     public void clearWarnings() throws SQLException {
140         implWarningsSupplier.clearWarnings();
141     }
142 
getWarnings()143     public Object getWarnings() throws SQLException {
144         return implWarningsSupplier.getWarnings();
145     }
146 
147     // XMultipleResults:
148 
getMoreResults()149     public boolean getMoreResults() throws SQLException {
150         return implMultipleResults.getMoreResults();
151     }
152 
getResultSet()153     public XResultSet getResultSet() throws SQLException {
154         return new PostgresqlResultSet(implMultipleResults.getResultSet(), this);
155     }
156 
getUpdateCount()157     public int getUpdateCount() throws SQLException {
158         return implMultipleResults.getUpdateCount();
159     }
160 }
161