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 #ifndef SVX_DBTOOLSCLIENT_HXX 29 #define SVX_DBTOOLSCLIENT_HXX 30 31 #include <connectivity/virtualdbtools.hxx> 32 #include <osl/mutex.hxx> 33 #include <osl/module.h> 34 #include <tools/solar.h> 35 #include <unotools/sharedunocomponent.hxx> 36 #include "svx/svxdllapi.h" 37 38 //........................................................................ 39 namespace svxform 40 { 41 //........................................................................ 42 43 typedef ::utl::SharedUNOComponent< ::com::sun::star::sdbc::XConnection > SharedConnection; 44 45 //==================================================================== 46 //= ODbtoolsClient 47 //==================================================================== 48 /** base class for classes which want to use dbtools features with load-on-call 49 of the dbtools lib. 50 */ 51 class SVX_DLLPUBLIC ODbtoolsClient 52 { 53 private: 54 static ::osl::Mutex s_aMutex; 55 static sal_Int32 s_nClients; 56 static oslModule s_hDbtoolsModule; 57 static ::connectivity::simple::createDataAccessToolsFactoryFunction 58 s_pFactoryCreationFunc; 59 //add by BerryJia for fixing Bug97420 Time:2002-9-12-11:00(PRC time) 60 mutable sal_Bool m_bCreateAlready; 61 62 private: 63 mutable ::rtl::Reference< ::connectivity::simple::IDataAccessToolsFactory > m_xDataAccessFactory; 64 65 protected: 66 ODbtoolsClient(); 67 virtual ~ODbtoolsClient(); 68 69 virtual bool ensureLoaded() const; 70 71 protected: 72 const ::rtl::Reference< ::connectivity::simple::IDataAccessToolsFactory >& 73 getFactory() const { return m_xDataAccessFactory; } 74 75 private: 76 static void registerClient(); 77 static void revokeClient(); 78 }; 79 80 //==================================================================== 81 //= OStaticDataAccessTools 82 //==================================================================== 83 class SVX_DLLPUBLIC OStaticDataAccessTools : public ODbtoolsClient 84 { 85 protected: 86 mutable ::rtl::Reference< ::connectivity::simple::IDataAccessTools > m_xDataAccessTools; 87 88 protected: 89 virtual bool ensureLoaded() const; 90 91 public: 92 OStaticDataAccessTools(); 93 94 const ::rtl::Reference< ::connectivity::simple::IDataAccessTools >& getDataAccessTools() const { return m_xDataAccessTools; } 95 96 // ------------------------------------------------ 97 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier> getNumberFormats( 98 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _rxConn, 99 sal_Bool _bAllowDefault 100 ) const; 101 102 // ------------------------------------------------ 103 sal_Int32 getDefaultNumberFormat( 104 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xColumn, 105 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatTypes >& _xTypes, 106 const ::com::sun::star::lang::Locale& _rLocale ); 107 108 // ------------------------------------------------ 109 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection_withFeedback( 110 const ::rtl::OUString& _rDataSourceName, 111 const ::rtl::OUString& _rUser, 112 const ::rtl::OUString& _rPwd, 113 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory 114 ) const SAL_THROW ( (::com::sun::star::sdbc::SQLException) ); 115 116 // ------------------------------------------------ 117 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> connectRowset( 118 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet, 119 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory, 120 sal_Bool _bSetAsActiveConnection 121 ) const SAL_THROW ( ( ::com::sun::star::sdbc::SQLException 122 , ::com::sun::star::lang::WrappedTargetException 123 , ::com::sun::star::uno::RuntimeException) ); 124 125 // ------------------------------------------------ 126 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getRowSetConnection( 127 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _rxRowSet) 128 const SAL_THROW ( (::com::sun::star::uno::RuntimeException) ); 129 130 // ------------------------------------------------ 131 void TransferFormComponentProperties( 132 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxOld, 133 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxNew, 134 const ::com::sun::star::lang::Locale& _rLocale 135 ) const; 136 137 // ------------------------------------------------ 138 ::rtl::OUString quoteName( 139 const ::rtl::OUString& _rQuote, 140 const ::rtl::OUString& _rName 141 ) const; 142 143 // ------------------------------------------------ 144 ::rtl::OUString composeTableNameForSelect( 145 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 146 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable 147 ) const; 148 149 // ------------------------------------------------ 150 ::com::sun::star::sdb::SQLContext prependContextInfo( 151 ::com::sun::star::sdbc::SQLException& _rException, 152 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext, 153 const ::rtl::OUString& _rContextDescription, 154 const ::rtl::OUString& _rContextDetails 155 ) const; 156 157 // ------------------------------------------------ 158 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource > getDataSource( 159 const ::rtl::OUString& _rsRegisteredName, 160 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory 161 ) const; 162 163 // ------------------------------------------------ 164 /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::INSERT 165 @param _rxCursorSet the property set 166 */ 167 sal_Bool canInsert(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const; 168 169 // ------------------------------------------------ 170 /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::UPDATE 171 @param _rxCursorSet the property set 172 */ 173 sal_Bool canUpdate(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const; 174 175 // ------------------------------------------------ 176 /** check if the property "Privileges" supports ::com::sun::star::sdbcx::Privilege::DELETE 177 @param _rxCursorSet the property set 178 */ 179 sal_Bool canDelete(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxCursorSet) const; 180 181 // ------------------------------------------------ 182 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > 183 getFieldsByCommandDescriptor( 184 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 185 const sal_Int32 _nCommandType, 186 const ::rtl::OUString& _rCommand, 187 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxKeepFieldsAlive, 188 ::dbtools::SQLExceptionInfo* _pErrorInfo = NULL 189 ) SAL_THROW( ( ) ); 190 191 // ------------------------------------------------ 192 ::com::sun::star::uno::Sequence< ::rtl::OUString > 193 getFieldNamesByCommandDescriptor( 194 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 195 const sal_Int32 _nCommandType, 196 const ::rtl::OUString& _rCommand, 197 ::dbtools::SQLExceptionInfo* _pErrorInfo = NULL 198 ) SAL_THROW( ( ) ); 199 200 // ------------------------------------------------ 201 bool isEmbeddedInDatabase( 202 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent, 203 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxActualConnection 204 ); 205 206 // ------------------------------------------------ 207 bool isEmbeddedInDatabase( 208 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent 209 ); 210 }; 211 212 //==================================================================== 213 //= DBToolsObjectFactory 214 //==================================================================== 215 class SVX_DLLPUBLIC DBToolsObjectFactory : public ODbtoolsClient 216 { 217 public: 218 DBToolsObjectFactory(); 219 ~DBToolsObjectFactory(); 220 221 // ------------------------------------------------ 222 ::std::auto_ptr< ::dbtools::FormattedColumnValue > createFormattedColumnValue( 223 const ::comphelper::ComponentContext& _rContext, 224 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >& _rxRowSet, 225 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxColumn 226 ); 227 }; 228 229 //........................................................................ 230 } // namespace svxform 231 //........................................................................ 232 233 #endif // SVX_DBTOOLSCLIENT_HXX 234 235 236