1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "NConnection.hxx"
21 #include "NDatabaseMetaData.hxx"
22 #include "NCatalog.hxx"
23 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <com/sun/star/sdbc/TransactionIsolation.hpp>
25 #include "NPreparedStatement.hxx"
26 #include "NStatement.hxx"
27 #include <comphelper/extract.hxx>
28 #include <connectivity/dbexception.hxx>
29 #include <comphelper/processfactory.hxx>
30 #include <comphelper/sequence.hxx>
31 #include <rtl/ustring.hxx>
33 using namespace connectivity::evoab
;
34 using namespace dbtools
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::beans
;
39 using namespace ::com::sun::star::sdbcx
;
40 using namespace ::com::sun::star::sdbc
;
41 using namespace ::com::sun::star::lang
;
43 OEvoabConnection::OEvoabConnection(OEvoabDriver
& _rDriver
)
44 : OSubComponent
<OEvoabConnection
, OConnection_BASE
>( static_cast<cppu::OWeakObject
*>(&_rDriver
), this )
46 , m_eSDBCAddressType(SDBCAddress::EVO_LOCAL
)
51 OEvoabConnection::~OEvoabConnection()
53 ::osl::MutexGuard
aGuard( m_aMutex
);
62 void SAL_CALL
OEvoabConnection::release() throw()
69 IMPLEMENT_SERVICE_INFO(OEvoabConnection
, "com.sun.star.sdbc.drivers.evoab.Connection", "com.sun.star.sdbc.Connection")
72 void OEvoabConnection::construct(const OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
)
74 osl_atomic_increment( &m_refCount
);
75 SAL_INFO("connectivity.evoab2", "OEvoabConnection::construct()::url = " << url
);
78 const char* pPwd
= "password";
80 const PropertyValue
*pIter
= info
.getConstArray();
81 const PropertyValue
*pEnd
= pIter
+ info
.getLength();
82 for(;pIter
!= pEnd
;++pIter
)
84 if(pIter
->Name
.equalsAscii(pPwd
))
86 pIter
->Value
>>= sPassword
;
91 if ( url
== "sdbc:address:evolution:groupwise" )
92 setSDBCAddressType(SDBCAddress::EVO_GWISE
);
93 else if ( url
== "sdbc:address:evolution:ldap" )
94 setSDBCAddressType(SDBCAddress::EVO_LDAP
);
96 setSDBCAddressType(SDBCAddress::EVO_LOCAL
);
98 setPassword(OUStringToOString(sPassword
,RTL_TEXTENCODING_UTF8
));
99 osl_atomic_decrement( &m_refCount
);
103 OUString SAL_CALL
OEvoabConnection::nativeSQL( const OUString
& _sSql
) throw(SQLException
, RuntimeException
, std::exception
)
105 // when you need to transform SQL92 to you driver specific you can do it here
109 Reference
< XDatabaseMetaData
> SAL_CALL
OEvoabConnection::getMetaData( ) throw(SQLException
, RuntimeException
, std::exception
)
111 ::osl::MutexGuard
aGuard( m_aMutex
);
112 checkDisposed(OConnection_BASE::rBHelper
.bDisposed
);
114 Reference
< XDatabaseMetaData
> xMetaData
= m_xMetaData
;
117 xMetaData
= new OEvoabDatabaseMetaData(this);
118 m_xMetaData
= xMetaData
;
124 css::uno::Reference
< XTablesSupplier
> OEvoabConnection::createCatalog()
126 ::osl::MutexGuard
aGuard( m_aMutex
);
127 Reference
< XTablesSupplier
> xTab
= m_xCatalog
;
130 OEvoabCatalog
*pCat
= new OEvoabCatalog(this);
137 Reference
< XStatement
> SAL_CALL
OEvoabConnection::createStatement( ) throw(SQLException
, RuntimeException
, std::exception
)
139 ::osl::MutexGuard
aGuard( m_aMutex
);
140 checkDisposed(OConnection_BASE::rBHelper
.bDisposed
);
142 OStatement
* pStmt
= new OStatement(this);
144 Reference
< XStatement
> xStmt
= pStmt
;
145 m_aStatements
.push_back(WeakReferenceHelper(*pStmt
));
149 Reference
< XPreparedStatement
> SAL_CALL
OEvoabConnection::prepareStatement( const OUString
& sql
) throw(SQLException
, RuntimeException
, std::exception
)
151 ::osl::MutexGuard
aGuard( m_aMutex
);
152 checkDisposed(OConnection_BASE::rBHelper
.bDisposed
);
154 OEvoabPreparedStatement
* pStmt
= new OEvoabPreparedStatement( this );
155 Reference
< XPreparedStatement
> xStmt
= pStmt
;
156 pStmt
->construct( sql
);
158 m_aStatements
.push_back(WeakReferenceHelper(*pStmt
));
162 Reference
< XPreparedStatement
> SAL_CALL
OEvoabConnection::prepareCall( const OUString
& /*sql*/ ) throw( SQLException
, RuntimeException
, std::exception
)
164 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::prepareCall", *this );
167 sal_Bool SAL_CALL
OEvoabConnection::isClosed( ) throw(SQLException
, RuntimeException
, std::exception
)
169 ::osl::MutexGuard
aGuard( m_aMutex
);
170 return OConnection_BASE::rBHelper
.bDisposed
;
175 void SAL_CALL
OEvoabConnection::close( ) throw(SQLException
, RuntimeException
, std::exception
)
177 { // we just dispose us
178 ::osl::MutexGuard
aGuard( m_aMutex
);
179 checkDisposed(OConnection_BASE::rBHelper
.bDisposed
);
186 Any SAL_CALL
OEvoabConnection::getWarnings( ) throw(SQLException
, RuntimeException
, std::exception
)
188 return m_aWarnings
.getWarnings();
190 void SAL_CALL
OEvoabConnection::clearWarnings( ) throw(SQLException
, RuntimeException
, std::exception
)
192 m_aWarnings
.clearWarnings();
196 void OEvoabConnection::disposing()
198 // we noticed that we should be destroyed in near future so we have to dispose our statements
199 ::osl::MutexGuard
aGuard(m_aMutex
);
200 OConnection_BASE::disposing();
204 // -------------------------------- stubbed methods ------------------------------------------------
205 void SAL_CALL
OEvoabConnection::setAutoCommit( sal_Bool
/*autoCommit*/ ) throw(SQLException
, RuntimeException
, std::exception
)
207 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setAutoCommit", *this );
209 sal_Bool SAL_CALL
OEvoabConnection::getAutoCommit( ) throw(SQLException
, RuntimeException
, std::exception
)
213 void SAL_CALL
OEvoabConnection::commit( ) throw(SQLException
, RuntimeException
, std::exception
)
216 void SAL_CALL
OEvoabConnection::rollback( ) throw(SQLException
, RuntimeException
, std::exception
)
219 void SAL_CALL
OEvoabConnection::setReadOnly( sal_Bool
/*readOnly*/ ) throw(SQLException
, RuntimeException
, std::exception
)
221 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setReadOnly", *this );
223 sal_Bool SAL_CALL
OEvoabConnection::isReadOnly( ) throw(SQLException
, RuntimeException
, std::exception
)
227 void SAL_CALL
OEvoabConnection::setCatalog( const OUString
& /*catalog*/ ) throw(SQLException
, RuntimeException
, std::exception
)
229 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setCatalog", *this );
232 OUString SAL_CALL
OEvoabConnection::getCatalog( ) throw(SQLException
, RuntimeException
, std::exception
)
236 void SAL_CALL
OEvoabConnection::setTransactionIsolation( sal_Int32
/*level*/ ) throw(SQLException
, RuntimeException
, std::exception
)
238 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setTransactionIsolation", *this );
241 sal_Int32 SAL_CALL
OEvoabConnection::getTransactionIsolation( ) throw(SQLException
, RuntimeException
, std::exception
)
243 return TransactionIsolation::NONE
;
246 Reference
< css::container::XNameAccess
> SAL_CALL
OEvoabConnection::getTypeMap( ) throw(SQLException
, RuntimeException
, std::exception
)
248 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::getTypeMap", *this );
251 void SAL_CALL
OEvoabConnection::setTypeMap( const Reference
< css::container::XNameAccess
>& /*typeMap*/ ) throw(SQLException
, RuntimeException
, std::exception
)
253 ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setTypeMap", *this );
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */