1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef DBACCESS_CONNECTIONTOOLS_HXX
32*cdf0e10cSrcweir #include "connectiontools.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #ifndef DBACCESS_SOURCE_SDBTOOLS_CONNECTION_TABLENAME_HXX
36*cdf0e10cSrcweir #include "tablename.hxx"
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir #ifndef DBACCESS_SOURCE_SDBTOOLS_CONNECTION_OBJECTNAMES_HXX
39*cdf0e10cSrcweir #include "objectnames.hxx"
40*cdf0e10cSrcweir #endif
41*cdf0e10cSrcweir #ifndef DBACCESS_DATASOURCEMETADATA_HXX
42*cdf0e10cSrcweir #include "datasourcemetadata.hxx"
43*cdf0e10cSrcweir #endif
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir /** === begin UNO includes === **/
46*cdf0e10cSrcweir /** === end UNO includes === **/
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #ifndef COMPHELPER_NAMEDVALUECOLLECTION_HXX
49*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
50*cdf0e10cSrcweir #endif
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
53*cdf0e10cSrcweir #include <connectivity/statementcomposer.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include <algorithm>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_ConnectionTools()
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir 	::sdbtools::OAutoRegistration< ::sdbtools::ConnectionTools > aRegistration;
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir //........................................................................
63*cdf0e10cSrcweir namespace sdbtools
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir //........................................................................
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 	/** === begin UNO using === **/
68*cdf0e10cSrcweir     using namespace ::com::sun::star;
69*cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
70*cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
71*cdf0e10cSrcweir     using ::com::sun::star::uno::RuntimeException;
72*cdf0e10cSrcweir     using ::com::sun::star::sdb::tools::XTableName;
73*cdf0e10cSrcweir     using ::com::sun::star::sdb::tools::XObjectNames;
74*cdf0e10cSrcweir     using ::com::sun::star::sdb::tools::XDataSourceMetaData;
75*cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
76*cdf0e10cSrcweir     using ::com::sun::star::uno::XInterface;
77*cdf0e10cSrcweir     using ::com::sun::star::uno::Any;
78*cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
79*cdf0e10cSrcweir     using ::com::sun::star::sdbc::XConnection;
80*cdf0e10cSrcweir     using ::com::sun::star::lang::IllegalArgumentException;
81*cdf0e10cSrcweir     using ::com::sun::star::uno::XComponentContext;
82*cdf0e10cSrcweir 	/** === end UNO using === **/
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	//====================================================================
85*cdf0e10cSrcweir 	//= ConnectionTools
86*cdf0e10cSrcweir 	//====================================================================
87*cdf0e10cSrcweir 	//--------------------------------------------------------------------
88*cdf0e10cSrcweir     ConnectionTools::ConnectionTools( const ::comphelper::ComponentContext& _rContext )
89*cdf0e10cSrcweir         :ConnectionDependentComponent( _rContext )
90*cdf0e10cSrcweir     {
91*cdf0e10cSrcweir     }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     //--------------------------------------------------------------------
94*cdf0e10cSrcweir     ConnectionTools::~ConnectionTools()
95*cdf0e10cSrcweir     {
96*cdf0e10cSrcweir     }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     //--------------------------------------------------------------------
99*cdf0e10cSrcweir     Reference< XTableName > SAL_CALL ConnectionTools::createTableName() throw (RuntimeException)
100*cdf0e10cSrcweir     {
101*cdf0e10cSrcweir         EntryGuard aGuard( *this );
102*cdf0e10cSrcweir         return new TableName( getContext(), getConnection() );
103*cdf0e10cSrcweir     }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     //--------------------------------------------------------------------
106*cdf0e10cSrcweir     Reference< XObjectNames > SAL_CALL ConnectionTools::getObjectNames() throw (RuntimeException)
107*cdf0e10cSrcweir     {
108*cdf0e10cSrcweir         EntryGuard aGuard( *this );
109*cdf0e10cSrcweir         return new ObjectNames( getContext(), getConnection() );
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     //--------------------------------------------------------------------
113*cdf0e10cSrcweir     Reference< XDataSourceMetaData > SAL_CALL ConnectionTools::getDataSourceMetaData() throw (RuntimeException)
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         EntryGuard aGuard( *this );
116*cdf0e10cSrcweir         return new DataSourceMetaData( getContext(), getConnection() );
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir     //--------------------------------------------------------------------
119*cdf0e10cSrcweir     Reference< container::XNameAccess > SAL_CALL ConnectionTools::getFieldsByCommandDescriptor( ::sal_Int32 commandType, const ::rtl::OUString& command, Reference< lang::XComponent >& keepFieldsAlive ) throw (sdbc::SQLException, RuntimeException)
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir         EntryGuard aGuard( *this );
122*cdf0e10cSrcweir         ::dbtools::SQLExceptionInfo aErrorInfo;
123*cdf0e10cSrcweir         Reference< container::XNameAccess > xRet = ::dbtools::getFieldsByCommandDescriptor(getConnection(),commandType,command,keepFieldsAlive,&aErrorInfo);
124*cdf0e10cSrcweir         if ( aErrorInfo.isValid() )
125*cdf0e10cSrcweir             aErrorInfo.doThrow();
126*cdf0e10cSrcweir         return xRet;
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir     //--------------------------------------------------------------------
129*cdf0e10cSrcweir     Reference< sdb::XSingleSelectQueryComposer > SAL_CALL ConnectionTools::getComposer( ::sal_Int32 commandType, const ::rtl::OUString& command ) throw (::com::sun::star::uno::RuntimeException)
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir         EntryGuard aGuard( *this );
132*cdf0e10cSrcweir         dbtools::StatementComposer aComposer(getConnection(), command, commandType, sal_True );
133*cdf0e10cSrcweir         aComposer.setDisposeComposer(sal_False);
134*cdf0e10cSrcweir         return aComposer.getComposer();
135*cdf0e10cSrcweir     }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir     //--------------------------------------------------------------------
138*cdf0e10cSrcweir     ::rtl::OUString SAL_CALL ConnectionTools::getImplementationName() throw (RuntimeException)
139*cdf0e10cSrcweir     {
140*cdf0e10cSrcweir         return getImplementationName_static();
141*cdf0e10cSrcweir     }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     //--------------------------------------------------------------------
144*cdf0e10cSrcweir     ::sal_Bool SAL_CALL ConnectionTools::supportsService(const ::rtl::OUString & _ServiceName) throw (RuntimeException)
145*cdf0e10cSrcweir     {
146*cdf0e10cSrcweir         Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
147*cdf0e10cSrcweir         const ::rtl::OUString* begin = aSupported.getConstArray();
148*cdf0e10cSrcweir         const ::rtl::OUString* end = aSupported.getConstArray() + aSupported.getLength();
149*cdf0e10cSrcweir         return ::std::find( begin, end, _ServiceName ) != end;
150*cdf0e10cSrcweir     }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     //--------------------------------------------------------------------
153*cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL ConnectionTools::getSupportedServiceNames() throw (RuntimeException)
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         return getSupportedServiceNames_static();
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     //--------------------------------------------------------------------
159*cdf0e10cSrcweir     ::rtl::OUString SAL_CALL ConnectionTools::getImplementationName_static()
160*cdf0e10cSrcweir     {
161*cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dbaccess.ConnectionTools" ) );
162*cdf0e10cSrcweir     }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir     //--------------------------------------------------------------------
165*cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL ConnectionTools::getSupportedServiceNames_static()
166*cdf0e10cSrcweir     {
167*cdf0e10cSrcweir         Sequence< ::rtl::OUString > aSupported( 1 );
168*cdf0e10cSrcweir         aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.tools.ConnectionTools" ) );
169*cdf0e10cSrcweir         return aSupported;
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     //--------------------------------------------------------------------
173*cdf0e10cSrcweir 	Reference< XInterface > SAL_CALL ConnectionTools::Create(const Reference< XComponentContext >& _rxContext )
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         return *( new ConnectionTools( ::comphelper::ComponentContext( _rxContext ) ) );
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     //--------------------------------------------------------------------
179*cdf0e10cSrcweir     void SAL_CALL ConnectionTools::initialize(const Sequence< Any > & _rArguments) throw (RuntimeException, Exception)
180*cdf0e10cSrcweir     {
181*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( getMutex() );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aArguments( _rArguments );
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         Reference< XConnection > xConnection;
186*cdf0e10cSrcweir         aArguments.get( "Connection" ) >>= xConnection;
187*cdf0e10cSrcweir         if ( !xConnection.is() )
188*cdf0e10cSrcweir             throw IllegalArgumentException();
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir         setWeakConnection( xConnection );
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir //........................................................................
195*cdf0e10cSrcweir } // namespace sdbtools
196*cdf0e10cSrcweir //........................................................................
197*cdf0e10cSrcweir 
198