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: connectiontools.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_dbaccess.hxx"
34 #ifndef DBACCESS_CONNECTIONTOOLS_HXX
35 #include "connectiontools.hxx"
38 #ifndef DBACCESS_SOURCE_SDBTOOLS_CONNECTION_TABLENAME_HXX
39 #include "tablename.hxx"
41 #ifndef DBACCESS_SOURCE_SDBTOOLS_CONNECTION_OBJECTNAMES_HXX
42 #include "objectnames.hxx"
44 #ifndef DBACCESS_DATASOURCEMETADATA_HXX
45 #include "datasourcemetadata.hxx"
48 /** === begin UNO includes === **/
49 /** === end UNO includes === **/
51 #ifndef COMPHELPER_NAMEDVALUECOLLECTION_HXX
52 #include <comphelper/namedvaluecollection.hxx>
55 #include <connectivity/dbtools.hxx>
56 #include <connectivity/statementcomposer.hxx>
60 extern "C" void SAL_CALL
createRegistryInfo_ConnectionTools()
62 ::sdbtools::OAutoRegistration
< ::sdbtools::ConnectionTools
> aRegistration
;
65 //........................................................................
68 //........................................................................
70 /** === begin UNO using === **/
71 using namespace ::com::sun::star
;
72 using namespace ::com::sun::star::uno
;
73 using ::com::sun::star::uno::Reference
;
74 using ::com::sun::star::uno::RuntimeException
;
75 using ::com::sun::star::sdb::tools::XTableName
;
76 using ::com::sun::star::sdb::tools::XObjectNames
;
77 using ::com::sun::star::sdb::tools::XDataSourceMetaData
;
78 using ::com::sun::star::uno::Sequence
;
79 using ::com::sun::star::uno::XInterface
;
80 using ::com::sun::star::uno::Any
;
81 using ::com::sun::star::uno::Exception
;
82 using ::com::sun::star::sdbc::XConnection
;
83 using ::com::sun::star::lang::IllegalArgumentException
;
84 using ::com::sun::star::uno::XComponentContext
;
85 /** === end UNO using === **/
87 //====================================================================
89 //====================================================================
90 //--------------------------------------------------------------------
91 ConnectionTools::ConnectionTools( const ::comphelper::ComponentContext
& _rContext
)
92 :ConnectionDependentComponent( _rContext
)
96 //--------------------------------------------------------------------
97 ConnectionTools::~ConnectionTools()
101 //--------------------------------------------------------------------
102 Reference
< XTableName
> SAL_CALL
ConnectionTools::createTableName() throw (RuntimeException
)
104 EntryGuard
aGuard( *this );
105 return new TableName( getContext(), getConnection() );
108 //--------------------------------------------------------------------
109 Reference
< XObjectNames
> SAL_CALL
ConnectionTools::getObjectNames() throw (RuntimeException
)
111 EntryGuard
aGuard( *this );
112 return new ObjectNames( getContext(), getConnection() );
115 //--------------------------------------------------------------------
116 Reference
< XDataSourceMetaData
> SAL_CALL
ConnectionTools::getDataSourceMetaData() throw (RuntimeException
)
118 EntryGuard
aGuard( *this );
119 return new DataSourceMetaData( getContext(), getConnection() );
121 //--------------------------------------------------------------------
122 Reference
< container::XNameAccess
> SAL_CALL
ConnectionTools::getFieldsByCommandDescriptor( ::sal_Int32 commandType
, const ::rtl::OUString
& command
, Reference
< lang::XComponent
>& keepFieldsAlive
) throw (sdbc::SQLException
, RuntimeException
)
124 EntryGuard
aGuard( *this );
125 ::dbtools::SQLExceptionInfo aErrorInfo
;
126 Reference
< container::XNameAccess
> xRet
= ::dbtools::getFieldsByCommandDescriptor(getConnection(),commandType
,command
,keepFieldsAlive
,&aErrorInfo
);
127 if ( aErrorInfo
.isValid() )
128 aErrorInfo
.doThrow();
131 //--------------------------------------------------------------------
132 Reference
< sdb::XSingleSelectQueryComposer
> SAL_CALL
ConnectionTools::getComposer( ::sal_Int32 commandType
, const ::rtl::OUString
& command
) throw (::com::sun::star::uno::RuntimeException
)
134 EntryGuard
aGuard( *this );
135 dbtools::StatementComposer
aComposer(getConnection(), command
, commandType
, sal_True
);
136 aComposer
.setDisposeComposer(sal_False
);
137 return aComposer
.getComposer();
140 //--------------------------------------------------------------------
141 ::rtl::OUString SAL_CALL
ConnectionTools::getImplementationName() throw (RuntimeException
)
143 return getImplementationName_static();
146 //--------------------------------------------------------------------
147 ::sal_Bool SAL_CALL
ConnectionTools::supportsService(const ::rtl::OUString
& _ServiceName
) throw (RuntimeException
)
149 Sequence
< ::rtl::OUString
> aSupported( getSupportedServiceNames() );
150 const ::rtl::OUString
* begin
= aSupported
.getConstArray();
151 const ::rtl::OUString
* end
= aSupported
.getConstArray() + aSupported
.getLength();
152 return ::std::find( begin
, end
, _ServiceName
) != end
;
155 //--------------------------------------------------------------------
156 Sequence
< ::rtl::OUString
> SAL_CALL
ConnectionTools::getSupportedServiceNames() throw (RuntimeException
)
158 return getSupportedServiceNames_static();
161 //--------------------------------------------------------------------
162 ::rtl::OUString SAL_CALL
ConnectionTools::getImplementationName_static()
164 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dbaccess.ConnectionTools" ) );
167 //--------------------------------------------------------------------
168 Sequence
< ::rtl::OUString
> SAL_CALL
ConnectionTools::getSupportedServiceNames_static()
170 Sequence
< ::rtl::OUString
> aSupported( 1 );
171 aSupported
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.tools.ConnectionTools" ) );
175 //--------------------------------------------------------------------
176 Reference
< XInterface
> SAL_CALL
ConnectionTools::Create(const Reference
< XComponentContext
>& _rxContext
)
178 return *( new ConnectionTools( ::comphelper::ComponentContext( _rxContext
) ) );
181 //--------------------------------------------------------------------
182 void SAL_CALL
ConnectionTools::initialize(const Sequence
< Any
> & _rArguments
) throw (RuntimeException
, Exception
)
184 ::osl::MutexGuard
aGuard( getMutex() );
186 ::comphelper::NamedValueCollection
aArguments( _rArguments
);
188 Reference
< XConnection
> xConnection
;
189 aArguments
.get( "Connection" ) >>= xConnection
;
190 if ( !xConnection
.is() )
191 throw IllegalArgumentException();
193 setWeakConnection( xConnection
);
197 //........................................................................
198 } // namespace sdbtools
199 //........................................................................