1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /************************************************************************* 3 * 4 * The Contents of this file are made available subject to the terms of 5 * the BSD license. 6 * 7 * Copyright 2000, 2010 Oracle and/or its affiliates. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 *************************************************************************/ 35 36 #ifndef INCLUDED_EXAMPLES_DATABASE_DRIVERSKELETON_SSTATEMENT_HXX 37 #define INCLUDED_EXAMPLES_DATABASE_DRIVERSKELETON_SSTATEMENT_HXX 38 39 #include <com/sun/star/sdbc/XStatement.hpp> 40 #include <com/sun/star/sdbc/XWarningsSupplier.hpp> 41 #include <com/sun/star/sdbc/XMultipleResults.hpp> 42 #include <com/sun/star/sdbc/XBatchExecution.hpp> 43 #include <com/sun/star/sdbc/XCloseable.hpp> 44 #include <com/sun/star/sdbc/SQLWarning.hpp> 45 #include <com/sun/star/util/XCancellable.hpp> 46 #include <cppuhelper/compbase5.hxx> 47 #include "SConnection.hxx" 48 #include <vector> 49 #include "OSubComponent.hxx" 50 #include <com/sun/star/lang/XServiceInfo.hpp> 51 52 namespace connectivity 53 { 54 namespace skeleton 55 { 56 57 typedef ::cppu::WeakComponentImplHelper5< ::com::sun::star::sdbc::XStatement, 58 ::com::sun::star::sdbc::XWarningsSupplier, 59 ::com::sun::star::util::XCancellable, 60 ::com::sun::star::sdbc::XCloseable, 61 ::com::sun::star::sdbc::XMultipleResults> OStatement_BASE; 62 63 // A base class for the normal statement and for the prepared statement 64 class OStatement_Base : public OBase_Mutex, 65 public OStatement_BASE, 66 public ::cppu::OPropertySetHelper, 67 public OPropertyArrayUsageHelper<OStatement_Base> 68 69 { 70 ::com::sun::star::sdbc::SQLWarning m_aLastWarning; 71 protected: 72 ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet> m_xResultSet; // The last ResultSet created 73 // for this Statement 74 75 ::std::vector< ::rtl::OUString> m_aBatchVector; 76 77 OConnection* m_pConnection; // The owning Connection object 78 protected: 79 80 void disposeResultSet(); 81 82 // OPropertyArrayUsageHelper 83 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 84 // OPropertySetHelper 85 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); 86 virtual sal_Bool SAL_CALL convertFastPropertyValue( 87 ::com::sun::star::uno::Any & rConvertedValue, 88 ::com::sun::star::uno::Any & rOldValue, 89 sal_Int32 nHandle, 90 const ::com::sun::star::uno::Any& rValue ); 91 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( 92 sal_Int32 nHandle, 93 const ::com::sun::star::uno::Any& rValue); 94 virtual void SAL_CALL getFastPropertyValue( 95 ::com::sun::star::uno::Any& rValue, 96 sal_Int32 nHandle) const; 97 virtual ~OStatement_Base(); 98 99 public: 100 ::cppu::OBroadcastHelper& rBHelper; 101 OStatement_Base(OConnection* _pConnection ); 102 using OStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >; 103 104 // OComponentHelper disposing()105 virtual void SAL_CALL disposing(){OStatement_BASE::disposing();} 106 // XInterface 107 virtual void SAL_CALL release() throw(); 108 virtual void SAL_CALL acquire() throw(); 109 // XInterface 110 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ); 111 //XTypeProvider 112 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ); 113 114 // XPropertySet 115 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ); 116 // XStatement 117 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( const ::rtl::OUString& sql ) ; 118 virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) ; 119 virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) ; 120 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( ) ; 121 // XWarningsSupplier 122 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ); 123 virtual void SAL_CALL clearWarnings( ); 124 // XCancellable 125 virtual void SAL_CALL cancel( ); 126 // XCloseable 127 virtual void SAL_CALL close( ); 128 // XMultipleResults 129 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet( ); 130 virtual sal_Int32 SAL_CALL getUpdateCount( ); 131 virtual sal_Bool SAL_CALL getMoreResults( ); 132 133 // other methods getOwnConnection() const134 OConnection* getOwnConnection() const { return m_pConnection;} 135 }; 136 137 class OStatement_BASE2 :public OStatement_Base 138 ,public OSubComponent<OStatement_BASE2, OStatement_BASE> 139 140 { 141 friend class OSubComponent<OStatement_BASE2, OStatement_BASE>; 142 public: OStatement_BASE2(OConnection * _pConnection)143 OStatement_BASE2(OConnection* _pConnection ) : OStatement_Base(_pConnection ), 144 OSubComponent<OStatement_BASE2, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this){} 145 // OComponentHelper 146 virtual void SAL_CALL disposing(); 147 // XInterface 148 virtual void SAL_CALL release() throw(); 149 }; 150 151 class OStatement : public OStatement_BASE2, 152 public ::com::sun::star::sdbc::XBatchExecution, 153 public ::com::sun::star::lang::XServiceInfo 154 { 155 protected: ~OStatement()156 virtual ~OStatement(){} 157 public: 158 // a constructor, which is required for returning objects: OStatement(OConnection * _pConnection)159 OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){} 160 DECLARE_SERVICE_INFO(); 161 162 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ); 163 virtual void SAL_CALL acquire() throw(); 164 virtual void SAL_CALL release() throw(); 165 // XBatchExecution 166 virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ); 167 virtual void SAL_CALL clearBatch( ); 168 virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ); 169 }; 170 } 171 } 172 173 #endif // INCLUDED_EXAMPLES_DATABASE_DRIVERSKELETON_SSTATEMENT_HXX 174 175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 176