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