bump product version to 5.0.4.1
[LibreOffice.git] / dbaccess / source / sdbtools / connection / connectiontools.cxx
blob1f700203087e84f344992a94aa357f3e696146fc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "connectiontools.hxx"
21 #include "sdbt_services.hxx"
22 #include "tablename.hxx"
23 #include "objectnames.hxx"
24 #include "datasourcemetadata.hxx"
26 #include <comphelper/namedvaluecollection.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <connectivity/dbtools.hxx>
29 #include <connectivity/statementcomposer.hxx>
31 #include <algorithm>
33 extern "C" void SAL_CALL createRegistryInfo_ConnectionTools()
35 ::sdbtools::OAutoRegistration< ::sdbtools::ConnectionTools > aRegistration;
38 namespace sdbtools
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::RuntimeException;
45 using ::com::sun::star::sdb::tools::XTableName;
46 using ::com::sun::star::sdb::tools::XObjectNames;
47 using ::com::sun::star::sdb::tools::XDataSourceMetaData;
48 using ::com::sun::star::uno::Sequence;
49 using ::com::sun::star::uno::XInterface;
50 using ::com::sun::star::uno::Any;
51 using ::com::sun::star::uno::Exception;
52 using ::com::sun::star::sdbc::XConnection;
53 using ::com::sun::star::lang::IllegalArgumentException;
54 using ::com::sun::star::uno::XComponentContext;
56 // ConnectionTools
57 ConnectionTools::ConnectionTools( const Reference<XComponentContext>& _rContext )
58 :ConnectionDependentComponent( _rContext )
62 ConnectionTools::~ConnectionTools()
66 Reference< XTableName > SAL_CALL ConnectionTools::createTableName() throw (RuntimeException, std::exception)
68 EntryGuard aGuard( *this );
69 return new TableName( getContext(), getConnection() );
72 Reference< XObjectNames > SAL_CALL ConnectionTools::getObjectNames() throw (RuntimeException, std::exception)
74 EntryGuard aGuard( *this );
75 return new ObjectNames( getContext(), getConnection() );
78 Reference< XDataSourceMetaData > SAL_CALL ConnectionTools::getDataSourceMetaData() throw (RuntimeException, std::exception)
80 EntryGuard aGuard( *this );
81 return new DataSourceMetaData( getContext(), getConnection() );
83 Reference< container::XNameAccess > SAL_CALL ConnectionTools::getFieldsByCommandDescriptor( ::sal_Int32 commandType, const OUString& command, Reference< lang::XComponent >& keepFieldsAlive ) throw (sdbc::SQLException, RuntimeException, std::exception)
85 EntryGuard aGuard( *this );
86 ::dbtools::SQLExceptionInfo aErrorInfo;
87 Reference< container::XNameAccess > xRet = ::dbtools::getFieldsByCommandDescriptor(getConnection(),commandType,command,keepFieldsAlive,&aErrorInfo);
88 if ( aErrorInfo.isValid() )
89 aErrorInfo.doThrow();
90 return xRet;
92 Reference< sdb::XSingleSelectQueryComposer > SAL_CALL ConnectionTools::getComposer( ::sal_Int32 commandType, const OUString& command ) throw (::com::sun::star::uno::RuntimeException, std::exception)
94 EntryGuard aGuard( *this );
95 dbtools::StatementComposer aComposer(getConnection(), command, commandType, true );
96 aComposer.setDisposeComposer(false);
97 return aComposer.getComposer();
100 OUString SAL_CALL ConnectionTools::getImplementationName() throw (RuntimeException, std::exception)
102 return getImplementationName_static();
105 sal_Bool SAL_CALL ConnectionTools::supportsService(const OUString & _ServiceName) throw (RuntimeException, std::exception)
107 return cppu::supportsService(this, _ServiceName);
110 Sequence< OUString > SAL_CALL ConnectionTools::getSupportedServiceNames() throw (RuntimeException, std::exception)
112 return getSupportedServiceNames_static();
115 OUString SAL_CALL ConnectionTools::getImplementationName_static()
117 return OUString( "com.sun.star.comp.dbaccess.ConnectionTools" );
120 Sequence< OUString > SAL_CALL ConnectionTools::getSupportedServiceNames_static()
122 Sequence< OUString > aSupported( 1 );
123 aSupported[0] = "com.sun.star.sdb.tools.ConnectionTools";
124 return aSupported;
127 Reference< XInterface > SAL_CALL ConnectionTools::Create(const Reference< XComponentContext >& _rxContext )
129 return *( new ConnectionTools( Reference<XComponentContext>( _rxContext ) ) );
132 void SAL_CALL ConnectionTools::initialize(const Sequence< Any > & _rArguments) throw (RuntimeException, Exception, std::exception)
134 ::osl::MutexGuard aGuard( getMutex() );
136 Reference< XConnection > xConnection;
137 if (_rArguments.getLength()==1 && (_rArguments[0] >>= xConnection))
140 else
142 ::comphelper::NamedValueCollection aArguments( _rArguments );
143 aArguments.get( "Connection" ) >>= xConnection;
145 if ( !xConnection.is() )
146 throw IllegalArgumentException();
148 setWeakConnection( xConnection );
151 } // namespace sdbtools
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */