1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "NConnection.hxx"
27cdf0e10cSrcweir #include "NDatabaseMetaData.hxx"
28cdf0e10cSrcweir #include "NCatalog.hxx"
29cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/TransactionIsolation.hpp>
31cdf0e10cSrcweir #include <tools/urlobj.hxx>
32cdf0e10cSrcweir #include "NPreparedStatement.hxx"
33cdf0e10cSrcweir #include "NStatement.hxx"
34cdf0e10cSrcweir #include <comphelper/extract.hxx>
35cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
36cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
37cdf0e10cSrcweir #include <vos/process.hxx>
38cdf0e10cSrcweir #include <tools/debug.hxx>
39cdf0e10cSrcweir #include "NDebug.hxx"
40cdf0e10cSrcweir #include <comphelper/sequence.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace connectivity::evoab;
43cdf0e10cSrcweir using namespace vos;
44cdf0e10cSrcweir using namespace dbtools;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //------------------------------------------------------------------------------
47cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir using namespace ::com::sun::star::beans;
49cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
50cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
51cdf0e10cSrcweir using namespace ::com::sun::star::lang;
52cdf0e10cSrcweir 
implGetExceptionMsg(Exception & e,const::rtl::OUString & aExceptionType_)53cdf0e10cSrcweir ::rtl::OUString implGetExceptionMsg( Exception& e, const ::rtl::OUString& aExceptionType_ )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir      ::rtl::OUString aExceptionType = aExceptionType_;
56cdf0e10cSrcweir      if( aExceptionType.getLength() == 0 )
57cdf0e10cSrcweir          aExceptionType =  ::rtl::OUString::createFromAscii("Unknown" ) ;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir      ::rtl::OUString aTypeLine( RTL_CONSTASCII_USTRINGPARAM("\nType: " ) );
60cdf0e10cSrcweir      aTypeLine += aExceptionType;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir      ::rtl::OUString aMessageLine( RTL_CONSTASCII_USTRINGPARAM("\nMessage: " ) );
63cdf0e10cSrcweir          aMessageLine += ::rtl::OUString( e.Message );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	 ::rtl::OUString aMsg(aTypeLine);
66cdf0e10cSrcweir      aMsg += aMessageLine;
67cdf0e10cSrcweir          return aMsg;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir  // Exception type unknown
implGetExceptionMsg(Exception & e)71cdf0e10cSrcweir ::rtl::OUString implGetExceptionMsg( Exception& e )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir          ::rtl::OUString aMsg = implGetExceptionMsg( e, ::rtl::OUString() );
74cdf0e10cSrcweir          return aMsg;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir // --------------------------------------------------------------------------------
OEvoabConnection(OEvoabDriver & _rDriver)78cdf0e10cSrcweir OEvoabConnection::OEvoabConnection( OEvoabDriver& _rDriver )
79cdf0e10cSrcweir     :OSubComponent<OEvoabConnection, OConnection_BASE>( (::cppu::OWeakObject*)(&_rDriver), this )
80cdf0e10cSrcweir 	,m_rDriver(_rDriver)
81cdf0e10cSrcweir     ,m_xCatalog(NULL)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir }
84cdf0e10cSrcweir //-----------------------------------------------------------------------------
~OEvoabConnection()85cdf0e10cSrcweir OEvoabConnection::~OEvoabConnection()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	if(!isClosed()) {
90cdf0e10cSrcweir 		acquire();
91cdf0e10cSrcweir 		close();
92cdf0e10cSrcweir 	}
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //-----------------------------------------------------------------------------
release()96cdf0e10cSrcweir void SAL_CALL OEvoabConnection::release() throw()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	relase_ChildImpl();
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir // XServiceInfo
102cdf0e10cSrcweir // --------------------------------------------------------------------------------
103cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OEvoabConnection, "com.sun.star.sdbc.drivers.evoab.Connection", "com.sun.star.sdbc.Connection")
104cdf0e10cSrcweir 
105cdf0e10cSrcweir //-----------------------------------------------------------------------------
construct(const::rtl::OUString & url,const Sequence<PropertyValue> & info)106cdf0e10cSrcweir void OEvoabConnection::construct(const ::rtl::OUString& url, const Sequence< PropertyValue >& info)  throw(SQLException)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
109cdf0e10cSrcweir 	EVO_TRACE_STRING("OEvoabConnection::construct()::url = %s\n", url );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir  	::rtl::OUString sPassword;
112cdf0e10cSrcweir         const char* pPwd                = "password";
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         const PropertyValue *pIter      = info.getConstArray();
115cdf0e10cSrcweir         const PropertyValue *pEnd       = pIter + info.getLength();
116cdf0e10cSrcweir         for(;pIter != pEnd;++pIter)
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir                 if(!pIter->Name.compareToAscii(pPwd))
119cdf0e10cSrcweir                 {
120cdf0e10cSrcweir                         pIter->Value >>= sPassword;
121cdf0e10cSrcweir                         break;
122cdf0e10cSrcweir                 }
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	if (url.equalsAscii("sdbc:address:evolution:groupwise"))
126cdf0e10cSrcweir 		setSDBCAddressType(SDBCAddress::EVO_GWISE);
127cdf0e10cSrcweir 	else if (url.equalsAscii("sdbc:address:evolution:ldap"))
128cdf0e10cSrcweir 		setSDBCAddressType(SDBCAddress::EVO_LDAP);
129cdf0e10cSrcweir 	else
130cdf0e10cSrcweir 		setSDBCAddressType(SDBCAddress::EVO_LOCAL);
131cdf0e10cSrcweir 	setURL(url);
132cdf0e10cSrcweir 	setPassword(::rtl::OUStringToOString(sPassword,RTL_TEXTENCODING_UTF8));
133cdf0e10cSrcweir 	osl_decrementInterlockedCount( &m_refCount );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir // --------------------------------------------------------------------------------
nativeSQL(const::rtl::OUString & _sSql)137cdf0e10cSrcweir ::rtl::OUString SAL_CALL OEvoabConnection::nativeSQL( const ::rtl::OUString& _sSql ) throw(SQLException, RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	// when you need to transform SQL92 to you driver specific you can do it here
140cdf0e10cSrcweir 	return _sSql;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir // --------------------------------------------------------------------------------
getMetaData()143cdf0e10cSrcweir Reference< XDatabaseMetaData > SAL_CALL OEvoabConnection::getMetaData(  ) throw(SQLException, RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
146cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
149cdf0e10cSrcweir 	if(!xMetaData.is())
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		xMetaData = new OEvoabDatabaseMetaData(this);
152cdf0e10cSrcweir 		m_xMetaData = xMetaData;
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	return xMetaData;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir //------------------------------------------------------------------------------
createCatalog()158cdf0e10cSrcweir ::com::sun::star::uno::Reference< XTablesSupplier > OEvoabConnection::createCatalog()
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
161cdf0e10cSrcweir  	Reference< XTablesSupplier > xTab = m_xCatalog;
162cdf0e10cSrcweir  	if(!xTab.is())
163cdf0e10cSrcweir  	{
164cdf0e10cSrcweir  		OEvoabCatalog *pCat = new OEvoabCatalog(this);
165cdf0e10cSrcweir  		xTab = pCat;
166cdf0e10cSrcweir  		m_xCatalog = xTab;
167cdf0e10cSrcweir  	}
168cdf0e10cSrcweir  	return xTab;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir // --------------------------------------------------------------------------------
createStatement()171cdf0e10cSrcweir Reference< XStatement > SAL_CALL OEvoabConnection::createStatement(  ) throw(SQLException, RuntimeException)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
174cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 	OStatement* pStmt = new OStatement(this);
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	Reference< XStatement > xStmt = pStmt;
179cdf0e10cSrcweir 	m_aStatements.push_back(WeakReferenceHelper(*pStmt));
180cdf0e10cSrcweir 	return xStmt;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir // --------------------------------------------------------------------------------
prepareStatement(const::rtl::OUString & sql)183cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OEvoabConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
186cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	OEvoabPreparedStatement* pStmt = new OEvoabPreparedStatement( this );
189cdf0e10cSrcweir 	Reference< XPreparedStatement > xStmt = pStmt;
190cdf0e10cSrcweir     pStmt->construct( sql );
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	m_aStatements.push_back(WeakReferenceHelper(*pStmt));
193cdf0e10cSrcweir 	return xStmt;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
prepareCall(const::rtl::OUString &)196cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OEvoabConnection::prepareCall( const ::rtl::OUString& /*sql*/ ) throw( SQLException, RuntimeException)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this );
199cdf0e10cSrcweir     return NULL;
200cdf0e10cSrcweir }
isClosed()201cdf0e10cSrcweir sal_Bool SAL_CALL OEvoabConnection::isClosed(  ) throw(SQLException, RuntimeException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
204cdf0e10cSrcweir 	return OConnection_BASE::rBHelper.bDisposed;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir // --------------------------------------------------------------------------------
208cdf0e10cSrcweir // XCloseable
close()209cdf0e10cSrcweir void SAL_CALL OEvoabConnection::close(  ) throw(SQLException, RuntimeException)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	{  // we just dispose us
212cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
213cdf0e10cSrcweir 		checkDisposed(OConnection_BASE::rBHelper.bDisposed);
214cdf0e10cSrcweir 	}
215cdf0e10cSrcweir 	dispose();
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir // --------------------------------------------------------------------------------
219cdf0e10cSrcweir // XWarningsSupplier
getWarnings()220cdf0e10cSrcweir Any SAL_CALL OEvoabConnection::getWarnings(  ) throw(SQLException, RuntimeException)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     return m_aWarnings.getWarnings();
223cdf0e10cSrcweir }
clearWarnings()224cdf0e10cSrcweir void SAL_CALL OEvoabConnection::clearWarnings(  ) throw(SQLException, RuntimeException)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     m_aWarnings.clearWarnings();
227cdf0e10cSrcweir }
228cdf0e10cSrcweir //------------------------------------------------------------------------------
229cdf0e10cSrcweir 
disposing()230cdf0e10cSrcweir void OEvoabConnection::disposing()
231cdf0e10cSrcweir {
232cdf0e10cSrcweir 	// we noticed that we should be destroyed in near future so we have to dispose our statements
233cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
234cdf0e10cSrcweir     OConnection_BASE::disposing();
235cdf0e10cSrcweir 	dispose_ChildImpl();
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir // -------------------------------- stubbed methods ------------------------------------------------
setAutoCommit(sal_Bool)239cdf0e10cSrcweir void SAL_CALL OEvoabConnection::setAutoCommit( sal_Bool /*autoCommit*/ ) throw(SQLException, RuntimeException)
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XConnection::setAutoCommit", *this );
242cdf0e10cSrcweir }
getAutoCommit()243cdf0e10cSrcweir sal_Bool SAL_CALL OEvoabConnection::getAutoCommit(  ) throw(SQLException, RuntimeException)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir 	return sal_True;
246cdf0e10cSrcweir }
commit()247cdf0e10cSrcweir void SAL_CALL OEvoabConnection::commit(  ) throw(SQLException, RuntimeException)
248cdf0e10cSrcweir {
249cdf0e10cSrcweir }
rollback()250cdf0e10cSrcweir void SAL_CALL OEvoabConnection::rollback(  ) throw(SQLException, RuntimeException)
251cdf0e10cSrcweir {
252cdf0e10cSrcweir }
setReadOnly(sal_Bool)253cdf0e10cSrcweir void SAL_CALL OEvoabConnection::setReadOnly( sal_Bool /*readOnly*/ ) throw(SQLException, RuntimeException)
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XConnection::setReadOnly", *this );
256cdf0e10cSrcweir }
isReadOnly()257cdf0e10cSrcweir sal_Bool SAL_CALL OEvoabConnection::isReadOnly(  ) throw(SQLException, RuntimeException)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	return sal_False;
260cdf0e10cSrcweir }
setCatalog(const::rtl::OUString &)261cdf0e10cSrcweir void SAL_CALL OEvoabConnection::setCatalog( const ::rtl::OUString& /*catalog*/ ) throw(SQLException, RuntimeException)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XConnection::setCatalog", *this );
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
getCatalog()266cdf0e10cSrcweir ::rtl::OUString SAL_CALL OEvoabConnection::getCatalog(  ) throw(SQLException, RuntimeException)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	return ::rtl::OUString();
269cdf0e10cSrcweir }
setTransactionIsolation(sal_Int32)270cdf0e10cSrcweir void SAL_CALL OEvoabConnection::setTransactionIsolation( sal_Int32 /*level*/ ) throw(SQLException, RuntimeException)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XConnection::setTransactionIsolation", *this );
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
getTransactionIsolation()275cdf0e10cSrcweir sal_Int32 SAL_CALL OEvoabConnection::getTransactionIsolation(  ) throw(SQLException, RuntimeException)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir 	return TransactionIsolation::NONE;
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
getTypeMap()280cdf0e10cSrcweir Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OEvoabConnection::getTypeMap(  ) throw(SQLException, RuntimeException)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XConnection::getTypeMap", *this );
283cdf0e10cSrcweir 	return NULL;
284cdf0e10cSrcweir }
setTypeMap(const Reference<::com::sun::star::container::XNameAccess> &)285cdf0e10cSrcweir void SAL_CALL OEvoabConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
286cdf0e10cSrcweir {
287cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this );
288cdf0e10cSrcweir }
289