1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef DBACCESS_CONNECTIONTOOLS_HXX 28cdf0e10cSrcweir #include "connectiontools.hxx" 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir #ifndef DBACCESS_SOURCE_SDBTOOLS_CONNECTION_TABLENAME_HXX 32cdf0e10cSrcweir #include "tablename.hxx" 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #ifndef DBACCESS_SOURCE_SDBTOOLS_CONNECTION_OBJECTNAMES_HXX 35cdf0e10cSrcweir #include "objectnames.hxx" 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir #ifndef DBACCESS_DATASOURCEMETADATA_HXX 38cdf0e10cSrcweir #include "datasourcemetadata.hxx" 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir 41cdf0e10cSrcweir /** === begin UNO includes === **/ 42cdf0e10cSrcweir /** === end UNO includes === **/ 43cdf0e10cSrcweir 44cdf0e10cSrcweir #ifndef COMPHELPER_NAMEDVALUECOLLECTION_HXX 45cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 46cdf0e10cSrcweir #endif 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include <connectivity/dbtools.hxx> 49cdf0e10cSrcweir #include <connectivity/statementcomposer.hxx> 50cdf0e10cSrcweir 51cdf0e10cSrcweir #include <algorithm> 52cdf0e10cSrcweir 53cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_ConnectionTools() 54cdf0e10cSrcweir { 55cdf0e10cSrcweir ::sdbtools::OAutoRegistration< ::sdbtools::ConnectionTools > aRegistration; 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir //........................................................................ 59cdf0e10cSrcweir namespace sdbtools 60cdf0e10cSrcweir { 61cdf0e10cSrcweir //........................................................................ 62cdf0e10cSrcweir 63cdf0e10cSrcweir /** === begin UNO using === **/ 64cdf0e10cSrcweir using namespace ::com::sun::star; 65cdf0e10cSrcweir using namespace ::com::sun::star::uno; 66cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 67cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 68cdf0e10cSrcweir using ::com::sun::star::sdb::tools::XTableName; 69cdf0e10cSrcweir using ::com::sun::star::sdb::tools::XObjectNames; 70cdf0e10cSrcweir using ::com::sun::star::sdb::tools::XDataSourceMetaData; 71cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 72cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 73cdf0e10cSrcweir using ::com::sun::star::uno::Any; 74cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 75cdf0e10cSrcweir using ::com::sun::star::sdbc::XConnection; 76cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException; 77cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext; 78cdf0e10cSrcweir /** === end UNO using === **/ 79cdf0e10cSrcweir 80cdf0e10cSrcweir //==================================================================== 81cdf0e10cSrcweir //= ConnectionTools 82cdf0e10cSrcweir //==================================================================== 83cdf0e10cSrcweir //-------------------------------------------------------------------- 84cdf0e10cSrcweir ConnectionTools::ConnectionTools( const ::comphelper::ComponentContext& _rContext ) 85cdf0e10cSrcweir :ConnectionDependentComponent( _rContext ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir //-------------------------------------------------------------------- 90cdf0e10cSrcweir ConnectionTools::~ConnectionTools() 91cdf0e10cSrcweir { 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir //-------------------------------------------------------------------- 95cdf0e10cSrcweir Reference< XTableName > SAL_CALL ConnectionTools::createTableName() throw (RuntimeException) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir EntryGuard aGuard( *this ); 98cdf0e10cSrcweir return new TableName( getContext(), getConnection() ); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir //-------------------------------------------------------------------- 102cdf0e10cSrcweir Reference< XObjectNames > SAL_CALL ConnectionTools::getObjectNames() throw (RuntimeException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir EntryGuard aGuard( *this ); 105cdf0e10cSrcweir return new ObjectNames( getContext(), getConnection() ); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir //-------------------------------------------------------------------- 109cdf0e10cSrcweir Reference< XDataSourceMetaData > SAL_CALL ConnectionTools::getDataSourceMetaData() throw (RuntimeException) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir EntryGuard aGuard( *this ); 112cdf0e10cSrcweir return new DataSourceMetaData( getContext(), getConnection() ); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir //-------------------------------------------------------------------- 115cdf0e10cSrcweir Reference< container::XNameAccess > SAL_CALL ConnectionTools::getFieldsByCommandDescriptor( ::sal_Int32 commandType, const ::rtl::OUString& command, Reference< lang::XComponent >& keepFieldsAlive ) throw (sdbc::SQLException, RuntimeException) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir EntryGuard aGuard( *this ); 118cdf0e10cSrcweir ::dbtools::SQLExceptionInfo aErrorInfo; 119cdf0e10cSrcweir Reference< container::XNameAccess > xRet = ::dbtools::getFieldsByCommandDescriptor(getConnection(),commandType,command,keepFieldsAlive,&aErrorInfo); 120cdf0e10cSrcweir if ( aErrorInfo.isValid() ) 121cdf0e10cSrcweir aErrorInfo.doThrow(); 122cdf0e10cSrcweir return xRet; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir //-------------------------------------------------------------------- 125cdf0e10cSrcweir Reference< sdb::XSingleSelectQueryComposer > SAL_CALL ConnectionTools::getComposer( ::sal_Int32 commandType, const ::rtl::OUString& command ) throw (::com::sun::star::uno::RuntimeException) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir EntryGuard aGuard( *this ); 128cdf0e10cSrcweir dbtools::StatementComposer aComposer(getConnection(), command, commandType, sal_True ); 129cdf0e10cSrcweir aComposer.setDisposeComposer(sal_False); 130cdf0e10cSrcweir return aComposer.getComposer(); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir //-------------------------------------------------------------------- 134cdf0e10cSrcweir ::rtl::OUString SAL_CALL ConnectionTools::getImplementationName() throw (RuntimeException) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir return getImplementationName_static(); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir //-------------------------------------------------------------------- 140cdf0e10cSrcweir ::sal_Bool SAL_CALL ConnectionTools::supportsService(const ::rtl::OUString & _ServiceName) throw (RuntimeException) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() ); 143cdf0e10cSrcweir const ::rtl::OUString* begin = aSupported.getConstArray(); 144cdf0e10cSrcweir const ::rtl::OUString* end = aSupported.getConstArray() + aSupported.getLength(); 145cdf0e10cSrcweir return ::std::find( begin, end, _ServiceName ) != end; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir //-------------------------------------------------------------------- 149cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ConnectionTools::getSupportedServiceNames() throw (RuntimeException) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir return getSupportedServiceNames_static(); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir //-------------------------------------------------------------------- 155cdf0e10cSrcweir ::rtl::OUString SAL_CALL ConnectionTools::getImplementationName_static() 156cdf0e10cSrcweir { 157cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dbaccess.ConnectionTools" ) ); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir //-------------------------------------------------------------------- 161cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ConnectionTools::getSupportedServiceNames_static() 162cdf0e10cSrcweir { 163cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported( 1 ); 164cdf0e10cSrcweir aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.tools.ConnectionTools" ) ); 165cdf0e10cSrcweir return aSupported; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir //-------------------------------------------------------------------- 169cdf0e10cSrcweir Reference< XInterface > SAL_CALL ConnectionTools::Create(const Reference< XComponentContext >& _rxContext ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir return *( new ConnectionTools( ::comphelper::ComponentContext( _rxContext ) ) ); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir //-------------------------------------------------------------------- 175cdf0e10cSrcweir void SAL_CALL ConnectionTools::initialize(const Sequence< Any > & _rArguments) throw (RuntimeException, Exception) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir ::osl::MutexGuard aGuard( getMutex() ); 178cdf0e10cSrcweir 179cdf0e10cSrcweir ::comphelper::NamedValueCollection aArguments( _rArguments ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir Reference< XConnection > xConnection; 182cdf0e10cSrcweir aArguments.get( "Connection" ) >>= xConnection; 183cdf0e10cSrcweir if ( !xConnection.is() ) 184cdf0e10cSrcweir throw IllegalArgumentException(); 185cdf0e10cSrcweir 186cdf0e10cSrcweir setWeakConnection( xConnection ); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir 190cdf0e10cSrcweir //........................................................................ 191cdf0e10cSrcweir } // namespace sdbtools 192cdf0e10cSrcweir //........................................................................ 193cdf0e10cSrcweir 194