1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NConnection.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "NConnection.hxx"
34 #include "NDatabaseMetaData.hxx"
35 #include "NCatalog.hxx"
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <com/sun/star/sdbc/TransactionIsolation.hpp>
38 #include <tools/urlobj.hxx>
39 #include "NPreparedStatement.hxx"
40 #include "NStatement.hxx"
41 #include <comphelper/extract.hxx>
42 #include <connectivity/dbexception.hxx>
43 #include <comphelper/processfactory.hxx>
44 #include <vos/process.hxx>
45 #include <tools/debug.hxx>
47 #include <comphelper/sequence.hxx>
49 using namespace connectivity::evoab
;
51 using namespace dbtools
;
53 //------------------------------------------------------------------------------
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::beans
;
56 using namespace ::com::sun::star::sdbcx
;
57 using namespace ::com::sun::star::sdbc
;
58 using namespace ::com::sun::star::lang
;
60 ::rtl::OUString
implGetExceptionMsg( Exception
& e
, const ::rtl::OUString
& aExceptionType_
)
62 ::rtl::OUString aExceptionType
= aExceptionType_
;
63 if( aExceptionType
.getLength() == 0 )
64 aExceptionType
= ::rtl::OUString::createFromAscii("Unknown" ) ;
66 ::rtl::OUString
aTypeLine( RTL_CONSTASCII_USTRINGPARAM("\nType: " ) );
67 aTypeLine
+= aExceptionType
;
69 ::rtl::OUString
aMessageLine( RTL_CONSTASCII_USTRINGPARAM("\nMessage: " ) );
70 aMessageLine
+= ::rtl::OUString( e
.Message
);
72 ::rtl::OUString
aMsg(aTypeLine
);
77 // Exception type unknown
78 ::rtl::OUString
implGetExceptionMsg( Exception
& e
)
80 ::rtl::OUString aMsg
= implGetExceptionMsg( e
, ::rtl::OUString() );
84 // --------------------------------------------------------------------------------
85 OEvoabConnection::OEvoabConnection( OEvoabDriver
& _rDriver
)
86 :OSubComponent
<OEvoabConnection
, OConnection_BASE
>( (::cppu::OWeakObject
*)(&_rDriver
), this )
91 //-----------------------------------------------------------------------------
92 OEvoabConnection::~OEvoabConnection()
94 ::osl::MutexGuard
aGuard( m_aMutex
);
102 //-----------------------------------------------------------------------------
103 void SAL_CALL
OEvoabConnection::release() throw()
109 // --------------------------------------------------------------------------------
110 IMPLEMENT_SERVICE_INFO(OEvoabConnection
, "com.sun.star.sdbc.drivers.evoab.Connection", "com.sun.star.sdbc.Connection")
112 //-----------------------------------------------------------------------------
113 void OEvoabConnection::construct(const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
)
115 osl_incrementInterlockedCount( &m_refCount
);
116 EVO_TRACE_STRING("OEvoabConnection::construct()::url = %s\n", url
);
118 ::rtl::OUString sPassword
;
119 const char* pPwd
= "password";
121 const PropertyValue
*pIter
= info
.getConstArray();
122 const PropertyValue
*pEnd
= pIter
+ info
.getLength();
123 for(;pIter
!= pEnd
;++pIter
)
125 if(!pIter
->Name
.compareToAscii(pPwd
))
127 pIter
->Value
>>= sPassword
;
132 if (url
.equalsAscii("sdbc:address:evolution:groupwise"))
133 setSDBCAddressType(SDBCAddress::EVO_GWISE
);
134 else if (url
.equalsAscii("sdbc:address:evolution:ldap"))
135 setSDBCAddressType(SDBCAddress::EVO_LDAP
);
137 setSDBCAddressType(SDBCAddress::EVO_LOCAL
);
139 setPassword(::rtl::OUStringToOString(sPassword
,RTL_TEXTENCODING_UTF8
));
140 osl_decrementInterlockedCount( &m_refCount
);
143 // --------------------------------------------------------------------------------
144 ::rtl::OUString SAL_CALL
OEvoabConnection::nativeSQL( const ::rtl::OUString
& _sSql
) throw(SQLException
, RuntimeException
)
146 // when you need to transform SQL92 to you driver specific you can do it here
149 // --------------------------------------------------------------------------------
150 Reference
< XDatabaseMetaData
> SAL_CALL
OEvoabConnection::getMetaData( ) throw(SQLException
, RuntimeException
)
152 ::osl::MutexGuard
aGuard( m_aMutex
);
153 checkDisposed(OConnection_BASE::rBHelper
.bDisposed
);
155 Reference
< XDatabaseMetaData
> xMetaData
= m_xMetaData
;
158 xMetaData
= new OEvoabDatabaseMetaData(this);
159 m_xMetaData
= xMetaData
;
164 //------------------------------------------------------------------------------
165 ::com::sun::star::uno::Reference
< XTablesSupplier
> OEvoabConnection::createCatalog()
167 ::osl::MutexGuard
aGuard( m_aMutex
);
168 Reference
< XTablesSupplier
> xTab
= m_xCatalog
;
171 OEvoabCatalog
*pCat
= new OEvoabCatalog(this);
177 // --------------------------------------------------------------------------------
178 Reference
< XStatement
> SAL_CALL
OEvoabConnection::createStatement( ) throw(SQLException
, RuntimeException
)
180 ::osl::MutexGuard
aGuard( m_aMutex
);
181 checkDisposed(OConnection_BASE::rBHelper
.bDisposed
);
183 OStatement
* pStmt
= new OStatement(this);
185 Reference
< XStatement
> xStmt
= pStmt
;
186 m_aStatements
.push_back(WeakReferenceHelper(*pStmt
));
189 // --------------------------------------------------------------------------------
190 Reference
< XPreparedStatement
> SAL_CALL
OEvoabConnection::prepareStatement( const ::rtl::OUString
& sql
) throw(SQLException
, RuntimeException
)
192 ::osl::MutexGuard
aGuard( m_aMutex
);
193 checkDisposed(OConnection_BASE::rBHelper
.bDisposed
);
195 OEvoabPreparedStatement
* pStmt
= new OEvoabPreparedStatement( this );
196 Reference
< XPreparedStatement
> xStmt
= pStmt
;
197 pStmt
->construct( sql
);
199 m_aStatements
.push_back(WeakReferenceHelper(*pStmt
));
203 Reference
< XPreparedStatement
> SAL_CALL
OEvoabConnection::prepareCall( const ::rtl::OUString
& /*sql*/ ) throw( SQLException
, RuntimeException
)
205 ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this );
208 sal_Bool SAL_CALL
OEvoabConnection::isClosed( ) throw(SQLException
, RuntimeException
)
210 ::osl::MutexGuard
aGuard( m_aMutex
);
211 return OConnection_BASE::rBHelper
.bDisposed
;
214 // --------------------------------------------------------------------------------
216 void SAL_CALL
OEvoabConnection::close( ) throw(SQLException
, RuntimeException
)
218 { // we just dispose us
219 ::osl::MutexGuard
aGuard( m_aMutex
);
220 checkDisposed(OConnection_BASE::rBHelper
.bDisposed
);
225 // --------------------------------------------------------------------------------
227 Any SAL_CALL
OEvoabConnection::getWarnings( ) throw(SQLException
, RuntimeException
)
229 return m_aWarnings
.getWarnings();
231 void SAL_CALL
OEvoabConnection::clearWarnings( ) throw(SQLException
, RuntimeException
)
233 m_aWarnings
.clearWarnings();
235 //------------------------------------------------------------------------------
237 void OEvoabConnection::disposing()
239 // we noticed that we should be destroyed in near future so we have to dispose our statements
240 ::osl::MutexGuard
aGuard(m_aMutex
);
241 OConnection_BASE::disposing();
245 // -------------------------------- stubbed methods ------------------------------------------------
246 void SAL_CALL
OEvoabConnection::setAutoCommit( sal_Bool
/*autoCommit*/ ) throw(SQLException
, RuntimeException
)
248 ::dbtools::throwFeatureNotImplementedException( "XConnection::setAutoCommit", *this );
250 sal_Bool SAL_CALL
OEvoabConnection::getAutoCommit( ) throw(SQLException
, RuntimeException
)
254 void SAL_CALL
OEvoabConnection::commit( ) throw(SQLException
, RuntimeException
)
257 void SAL_CALL
OEvoabConnection::rollback( ) throw(SQLException
, RuntimeException
)
260 void SAL_CALL
OEvoabConnection::setReadOnly( sal_Bool
/*readOnly*/ ) throw(SQLException
, RuntimeException
)
262 ::dbtools::throwFeatureNotImplementedException( "XConnection::setReadOnly", *this );
264 sal_Bool SAL_CALL
OEvoabConnection::isReadOnly( ) throw(SQLException
, RuntimeException
)
268 void SAL_CALL
OEvoabConnection::setCatalog( const ::rtl::OUString
& /*catalog*/ ) throw(SQLException
, RuntimeException
)
270 ::dbtools::throwFeatureNotImplementedException( "XConnection::setCatalog", *this );
273 ::rtl::OUString SAL_CALL
OEvoabConnection::getCatalog( ) throw(SQLException
, RuntimeException
)
275 return ::rtl::OUString();
277 void SAL_CALL
OEvoabConnection::setTransactionIsolation( sal_Int32
/*level*/ ) throw(SQLException
, RuntimeException
)
279 ::dbtools::throwFeatureNotImplementedException( "XConnection::setTransactionIsolation", *this );
282 sal_Int32 SAL_CALL
OEvoabConnection::getTransactionIsolation( ) throw(SQLException
, RuntimeException
)
284 return TransactionIsolation::NONE
;
287 Reference
< ::com::sun::star::container::XNameAccess
> SAL_CALL
OEvoabConnection::getTypeMap( ) throw(SQLException
, RuntimeException
)
289 ::dbtools::throwFeatureNotImplementedException( "XConnection::getTypeMap", *this );
292 void SAL_CALL
OEvoabConnection::setTypeMap( const Reference
< ::com::sun::star::container::XNameAccess
>& /*typeMap*/ ) throw(SQLException
, RuntimeException
)
294 ::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this );