LibreOffice Module connectivity (master) 1
NConnection.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "NConnection.hxx"
21#include "NDatabaseMetaData.hxx"
22#include "NCatalog.hxx"
23#include <com/sun/star/sdbc/TransactionIsolation.hpp>
25#include "NStatement.hxx"
27#include <rtl/ref.hxx>
28#include <rtl/ustring.hxx>
29#include <sal/log.hxx>
30
31using namespace connectivity::evoab;
32using namespace dbtools;
33
34
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::beans;
37using namespace ::com::sun::star::sdbcx;
38using namespace ::com::sun::star::sdbc;
39using namespace ::com::sun::star::lang;
40
41OEvoabConnection::OEvoabConnection(OEvoabDriver const & _rDriver)
42 : m_rDriver(_rDriver)
43 , m_eSDBCAddressType(SDBCAddress::EVO_LOCAL)
44{
45}
46
48{
49 ::osl::MutexGuard aGuard( m_aMutex );
50
51 if(!isClosed()) {
52 acquire();
53 close();
54 }
55}
56
57
58// XServiceInfo
59
60IMPLEMENT_SERVICE_INFO(OEvoabConnection, "com.sun.star.sdbc.drivers.evoab.Connection", "com.sun.star.sdbc.Connection")
61
62
63void OEvoabConnection::construct(const OUString& url, const Sequence< PropertyValue >& info)
64{
65 osl_atomic_increment( &m_refCount );
66 SAL_INFO("connectivity.evoab2", "OEvoabConnection::construct()::url = " << url );
67
68 OUString sPassword;
69 const char pPwd[] = "password";
70
71 const PropertyValue *pIter = info.getConstArray();
72 const PropertyValue *pEnd = pIter + info.getLength();
73 for(;pIter != pEnd;++pIter)
74 {
75 if(pIter->Name == pPwd)
76 {
77 pIter->Value >>= sPassword;
78 break;
79 }
80 }
81
82 if ( url == "sdbc:address:evolution:groupwise" )
83 setSDBCAddressType(SDBCAddress::EVO_GWISE);
84 else if ( url == "sdbc:address:evolution:ldap" )
85 setSDBCAddressType(SDBCAddress::EVO_LDAP);
86 else
87 setSDBCAddressType(SDBCAddress::EVO_LOCAL);
88 setURL(url);
89 setPassword(OUStringToOString(sPassword,RTL_TEXTENCODING_UTF8));
90 osl_atomic_decrement( &m_refCount );
91}
92
93
94OUString SAL_CALL OEvoabConnection::nativeSQL( const OUString& _sSql )
95{
96 // when you need to transform SQL92 to you driver specific you can do it here
97 return _sSql;
98}
99
101{
102 ::osl::MutexGuard aGuard( m_aMutex );
103 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
104
106 if(!xMetaData.is())
107 {
108 xMetaData = new OEvoabDatabaseMetaData(this);
109 m_xMetaData = xMetaData;
110 }
111
112 return xMetaData;
113}
114
115css::uno::Reference< XTablesSupplier > OEvoabConnection::createCatalog()
116{
117 ::osl::MutexGuard aGuard( m_aMutex );
119 if(!xTab.is())
120 {
121 xTab = new OEvoabCatalog(this);
122 m_xCatalog = xTab;
123 }
124 return xTab;
125}
126
128{
129 ::osl::MutexGuard aGuard( m_aMutex );
130 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
131
132 Reference< XStatement > xStmt = new OStatement(this);
133 m_aStatements.push_back(WeakReferenceHelper(xStmt));
134 return xStmt;
135}
136
138{
139 ::osl::MutexGuard aGuard( m_aMutex );
140 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
141
143 pStmt->construct( sql );
144
145 m_aStatements.push_back(WeakReferenceHelper(*pStmt));
146 return pStmt;
147}
148
150{
151 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::prepareCall", *this );
152 return nullptr;
153}
155{
156 ::osl::MutexGuard aGuard( m_aMutex );
157 return OConnection_BASE::rBHelper.bDisposed;
158}
159
160
161// XCloseable
163{
164 { // we just dispose us
165 ::osl::MutexGuard aGuard( m_aMutex );
166 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
167 }
168 dispose();
169}
170
171
172// XWarningsSupplier
174{
175 return m_aWarnings.getWarnings();
176}
178{
180}
181
182
184{
185 // we noticed that we should be destroyed in near future so we have to dispose our statements
186 ::osl::MutexGuard aGuard(m_aMutex);
188}
189
190// -------------------------------- stubbed methods ------------------------------------------------
191void SAL_CALL OEvoabConnection::setAutoCommit( sal_Bool /*autoCommit*/ )
192{
193 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setAutoCommit", *this );
194}
196{
197 return true;
198}
200{
201}
203{
204}
205void SAL_CALL OEvoabConnection::setReadOnly( sal_Bool /*readOnly*/ )
206{
207 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setReadOnly", *this );
208}
210{
211 return false;
212}
213void SAL_CALL OEvoabConnection::setCatalog( const OUString& /*catalog*/ )
214{
215 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setCatalog", *this );
216}
217
219{
220 return OUString();
221}
222void SAL_CALL OEvoabConnection::setTransactionIsolation( sal_Int32 /*level*/ )
223{
224 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setTransactionIsolation", *this );
225}
226
228{
229 return TransactionIsolation::NONE;
230}
231
233{
234 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::getTypeMap", *this );
235 return nullptr;
236}
238{
239 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setTypeMap", *this );
240}
241
242/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
connectivity::OWeakRefArray m_aStatements
Definition: TConnection.hxx:47
css::uno::WeakReference< css::sdbc::XDatabaseMetaData > m_xMetaData
Definition: TConnection.hxx:53
virtual void SAL_CALL disposing() override
Definition: TConnection.cxx:39
virtual void SAL_CALL commit() override
virtual void SAL_CALL setCatalog(const OUString &catalog) override
virtual sal_Bool SAL_CALL isReadOnly() override
virtual sal_Bool SAL_CALL isClosed() override
virtual void SAL_CALL rollback() override
css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog()
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
virtual sal_Bool SAL_CALL getAutoCommit() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
virtual void SAL_CALL setAutoCommit(sal_Bool autoCommit) override
css::uno::Reference< css::sdbcx::XTablesSupplier > m_xCatalog
Definition: NConnection.hxx:52
virtual OUString SAL_CALL getCatalog() override
virtual void SAL_CALL setReadOnly(sal_Bool readOnly) override
virtual sal_Int32 SAL_CALL getTransactionIsolation() override
virtual OUString SAL_CALL nativeSQL(const OUString &sql) override
Definition: NConnection.cxx:94
::dbtools::WarningsContainer m_aWarnings
Definition: NConnection.hxx:54
virtual void SAL_CALL close() override
virtual css::uno::Any SAL_CALL getWarnings() override
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
virtual void SAL_CALL clearWarnings() override
virtual void SAL_CALL setTypeMap(const css::uno::Reference< css::container::XNameAccess > &typeMap) override
virtual void SAL_CALL disposing() override
virtual void SAL_CALL setTransactionIsolation(sal_Int32 level) override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap() override
css::uno::Any getWarnings() const
ULONG m_refCount
#define SAL_INFO(area, stream)
IMPLEMENT_SERVICE_INFO(OStatement, "com.sun.star.comp.sdbcx.evoab.OStatement", "com.sun.star.sdbc.Statement")
void checkDisposed(bool _bThrow)
Definition: dbtools.cxx:1951
void throwFeatureNotImplementedSQLException(const OUString &_rFeatureName, const Reference< XInterface > &_rxContext, const Any &_rNextException)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Definition: pq_tools.cxx:100
void dispose()
unsigned char sal_Bool