1*3334a7e6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*3334a7e6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*3334a7e6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*3334a7e6SAndrew Rist * distributed with this work for additional information 6*3334a7e6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*3334a7e6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*3334a7e6SAndrew Rist * "License"); you may not use this file except in compliance 9*3334a7e6SAndrew Rist * with the License. You may obtain a copy of the License at 10*3334a7e6SAndrew Rist * 11*3334a7e6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*3334a7e6SAndrew Rist * 13*3334a7e6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*3334a7e6SAndrew Rist * software distributed under the License is distributed on an 15*3334a7e6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*3334a7e6SAndrew Rist * KIND, either express or implied. See the License for the 17*3334a7e6SAndrew Rist * specific language governing permissions and limitations 18*3334a7e6SAndrew Rist * under the License. 19*3334a7e6SAndrew Rist * 20*3334a7e6SAndrew Rist *************************************************************/ 21*3334a7e6SAndrew Rist 22*3334a7e6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SVX_DBTOOLSCLIENT_HXX 25cdf0e10cSrcweir #define SVX_DBTOOLSCLIENT_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <connectivity/virtualdbtools.hxx> 28cdf0e10cSrcweir #include <osl/mutex.hxx> 29cdf0e10cSrcweir #include <osl/module.h> 30cdf0e10cSrcweir #include <tools/solar.h> 31cdf0e10cSrcweir #include <unotools/sharedunocomponent.hxx> 32cdf0e10cSrcweir #include "svx/svxdllapi.h" 33cdf0e10cSrcweir 34cdf0e10cSrcweir //........................................................................ 35cdf0e10cSrcweir namespace svxform 36cdf0e10cSrcweir { 37cdf0e10cSrcweir //........................................................................ 38cdf0e10cSrcweir 39cdf0e10cSrcweir typedef ::utl::SharedUNOComponent< ::com::sun::star::sdbc::XConnection > SharedConnection; 40cdf0e10cSrcweir 41cdf0e10cSrcweir //==================================================================== 42cdf0e10cSrcweir //= ODbtoolsClient 43cdf0e10cSrcweir //==================================================================== 44cdf0e10cSrcweir /** base class for classes which want to use dbtools features with load-on-call 45cdf0e10cSrcweir of the dbtools lib. 46cdf0e10cSrcweir */ 47cdf0e10cSrcweir class SVX_DLLPUBLIC ODbtoolsClient 48cdf0e10cSrcweir { 49cdf0e10cSrcweir private: 50cdf0e10cSrcweir static ::osl::Mutex s_aMutex; 51cdf0e10cSrcweir static sal_Int32 s_nClients; 52cdf0e10cSrcweir static oslModule s_hDbtoolsModule; 53cdf0e10cSrcweir static ::connectivity::simple::createDataAccessToolsFactoryFunction 54cdf0e10cSrcweir s_pFactoryCreationFunc; 55cdf0e10cSrcweir //add by BerryJia for fixing Bug97420 Time:2002-9-12-11:00(PRC time) 56cdf0e10cSrcweir mutable sal_Bool m_bCreateAlready; 57cdf0e10cSrcweir 58cdf0e10cSrcweir private: 59cdf0e10cSrcweir mutable ::rtl::Reference< ::connectivity::simple::IDataAccessToolsFactory > m_xDataAccessFactory; 60cdf0e10cSrcweir 61cdf0e10cSrcweir protected: 62cdf0e10cSrcweir ODbtoolsClient(); 63cdf0e10cSrcweir virtual ~ODbtoolsClient(); 64cdf0e10cSrcweir 65cdf0e10cSrcweir virtual bool ensureLoaded() const; 66cdf0e10cSrcweir 67cdf0e10cSrcweir protected: 68cdf0e10cSrcweir const ::rtl::Reference< ::connectivity::simple::IDataAccessToolsFactory >& getFactory() const69cdf0e10cSrcweir getFactory() const { return m_xDataAccessFactory; } 70cdf0e10cSrcweir 71cdf0e10cSrcweir private: 72cdf0e10cSrcweir static void registerClient(); 73cdf0e10cSrcweir static void revokeClient(); 74cdf0e10cSrcweir }; 75cdf0e10cSrcweir 76cdf0e10cSrcweir //==================================================================== 77cdf0e10cSrcweir //= OStaticDataAccessTools 78cdf0e10cSrcweir //==================================================================== 79cdf0e10cSrcweir class SVX_DLLPUBLIC OStaticDataAccessTools : public ODbtoolsClient 80cdf0e10cSrcweir { 81cdf0e10cSrcweir protected: 82cdf0e10cSrcweir mutable ::rtl::Reference< ::connectivity::simple::IDataAccessTools > m_xDataAccessTools; 83cdf0e10cSrcweir 84cdf0e10cSrcweir protected: 85cdf0e10cSrcweir virtual bool ensureLoaded() const; 86cdf0e10cSrcweir 87cdf0e10cSrcweir public: 88cdf0e10cSrcweir OStaticDataAccessTools(); 89cdf0e10cSrcweir getDataAccessTools() const90cdf0e10cSrcweir const ::rtl::Reference< ::connectivity::simple::IDataAccessTools >& getDataAccessTools() const { return m_xDataAccessTools; } 91cdf0e10cSrcweir 92cdf0e10cSrcweir // ------------------------------------------------ 93cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier> getNumberFormats( 94cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rxConn, 95cdf0e10cSrcweir sal_Bool _bAllowDefault 96cdf0e10cSrcweir ) const; 97cdf0e10cSrcweir 98cdf0e10cSrcweir // ------------------------------------------------ 99cdf0e10cSrcweir sal_Int32 getDefaultNumberFormat( 100cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xColumn, 101cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatTypes >& _xTypes, 102cdf0e10cSrcweir const ::com::sun::star::lang::Locale& _rLocale ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir // ------------------------------------------------ 105cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection_withFeedback( 106cdf0e10cSrcweir const ::rtl::OUString& _rDataSourceName, 107cdf0e10cSrcweir const ::rtl::OUString& _rUser, 108cdf0e10cSrcweir const ::rtl::OUString& _rPwd, 109cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory 110cdf0e10cSrcweir ) const SAL_THROW ( (::com::sun::star::sdbc::SQLException) ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir // ------------------------------------------------ 113cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> connectRowset( 114cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet, 115cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory, 116cdf0e10cSrcweir sal_Bool _bSetAsActiveConnection 117cdf0e10cSrcweir ) const SAL_THROW ( ( ::com::sun::star::sdbc::SQLException 118cdf0e10cSrcweir , ::com::sun::star::lang::WrappedTargetException 119cdf0e10cSrcweir , ::com::sun::star::uno::RuntimeException) ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir // ------------------------------------------------ 122cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getRowSetConnection( 123cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet) 124cdf0e10cSrcweir const SAL_THROW ( (::com::sun::star::uno::RuntimeException) ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir // ------------------------------------------------ 127cdf0e10cSrcweir void TransferFormComponentProperties( 128cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxOld, 129cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxNew, 130cdf0e10cSrcweir const ::com::sun::star::lang::Locale& _rLocale 131cdf0e10cSrcweir ) const; 132cdf0e10cSrcweir 133cdf0e10cSrcweir // ------------------------------------------------ 134cdf0e10cSrcweir ::rtl::OUString quoteName( 135cdf0e10cSrcweir const ::rtl::OUString& _rQuote, 136cdf0e10cSrcweir const ::rtl::OUString& _rName 137cdf0e10cSrcweir ) const; 138cdf0e10cSrcweir 139cdf0e10cSrcweir // ------------------------------------------------ 140cdf0e10cSrcweir ::rtl::OUString composeTableNameForSelect( 141cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 142cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable 143cdf0e10cSrcweir ) const; 144cdf0e10cSrcweir 145cdf0e10cSrcweir // ------------------------------------------------ 146cdf0e10cSrcweir ::com::sun::star::sdb::SQLContext prependContextInfo( 147cdf0e10cSrcweir ::com::sun::star::sdbc::SQLException& _rException, 148cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext, 149cdf0e10cSrcweir const ::rtl::OUString& _rContextDescription, 150cdf0e10cSrcweir const ::rtl::OUString& _rContextDetails 151cdf0e10cSrcweir ) const; 152cdf0e10cSrcweir 153cdf0e10cSrcweir // ------------------------------------------------ 154cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource > getDataSource( 155cdf0e10cSrcweir const ::rtl::OUString& _rsRegisteredName, 156cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory 157cdf0e10cSrcweir ) const; 158cdf0e10cSrcweir 159cdf0e10cSrcweir // ------------------------------------------------ 160cdf0e10cSrcweir /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::INSERT 161cdf0e10cSrcweir @param _rxCursorSet the property set 162cdf0e10cSrcweir */ 163cdf0e10cSrcweir sal_Bool canInsert(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const; 164cdf0e10cSrcweir 165cdf0e10cSrcweir // ------------------------------------------------ 166cdf0e10cSrcweir /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::UPDATE 167cdf0e10cSrcweir @param _rxCursorSet the property set 168cdf0e10cSrcweir */ 169cdf0e10cSrcweir sal_Bool canUpdate(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const; 170cdf0e10cSrcweir 171cdf0e10cSrcweir // ------------------------------------------------ 172cdf0e10cSrcweir /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::DELETE 173cdf0e10cSrcweir @param _rxCursorSet the property set 174cdf0e10cSrcweir */ 175cdf0e10cSrcweir sal_Bool canDelete(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const; 176cdf0e10cSrcweir 177cdf0e10cSrcweir // ------------------------------------------------ 178cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > 179cdf0e10cSrcweir getFieldsByCommandDescriptor( 180cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 181cdf0e10cSrcweir const sal_Int32 _nCommandType, 182cdf0e10cSrcweir const ::rtl::OUString& _rCommand, 183cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxKeepFieldsAlive, 184cdf0e10cSrcweir ::dbtools::SQLExceptionInfo* _pErrorInfo = NULL 185cdf0e10cSrcweir ) SAL_THROW( ( ) ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir // ------------------------------------------------ 188cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > 189cdf0e10cSrcweir getFieldNamesByCommandDescriptor( 190cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 191cdf0e10cSrcweir const sal_Int32 _nCommandType, 192cdf0e10cSrcweir const ::rtl::OUString& _rCommand, 193cdf0e10cSrcweir ::dbtools::SQLExceptionInfo* _pErrorInfo = NULL 194cdf0e10cSrcweir ) SAL_THROW( ( ) ); 195cdf0e10cSrcweir 196cdf0e10cSrcweir // ------------------------------------------------ 197cdf0e10cSrcweir bool isEmbeddedInDatabase( 198cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent, 199cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxActualConnection 200cdf0e10cSrcweir ); 201cdf0e10cSrcweir 202cdf0e10cSrcweir // ------------------------------------------------ 203cdf0e10cSrcweir bool isEmbeddedInDatabase( 204cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent 205cdf0e10cSrcweir ); 206cdf0e10cSrcweir }; 207cdf0e10cSrcweir 208cdf0e10cSrcweir //==================================================================== 209cdf0e10cSrcweir //= DBToolsObjectFactory 210cdf0e10cSrcweir //==================================================================== 211cdf0e10cSrcweir class SVX_DLLPUBLIC DBToolsObjectFactory : public ODbtoolsClient 212cdf0e10cSrcweir { 213cdf0e10cSrcweir public: 214cdf0e10cSrcweir DBToolsObjectFactory(); 215cdf0e10cSrcweir ~DBToolsObjectFactory(); 216cdf0e10cSrcweir 217cdf0e10cSrcweir // ------------------------------------------------ 218cdf0e10cSrcweir ::std::auto_ptr< ::dbtools::FormattedColumnValue > createFormattedColumnValue( 219cdf0e10cSrcweir const ::comphelper::ComponentContext& _rContext, 220cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >& _rxRowSet, 221cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn 222cdf0e10cSrcweir ); 223cdf0e10cSrcweir }; 224cdf0e10cSrcweir 225cdf0e10cSrcweir //........................................................................ 226cdf0e10cSrcweir } // namespace svxform 227cdf0e10cSrcweir //........................................................................ 228cdf0e10cSrcweir 229cdf0e10cSrcweir #endif // SVX_DBTOOLSCLIENT_HXX 230cdf0e10cSrcweir 231cdf0e10cSrcweir 232