1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "tablename.hxx"
22 #include "objectnames.hxx"
23 #include "datasourcemetadata.hxx"
25 #include <comphelper/namedvaluecollection.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <connectivity/dbtools.hxx>
28 #include <connectivity/statementcomposer.hxx>
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::uno
;
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::sdb::tools::XTableName
;
37 using ::com::sun::star::sdb::tools::XObjectNames
;
38 using ::com::sun::star::sdb::tools::XDataSourceMetaData
;
39 using ::com::sun::star::uno::Sequence
;
40 using ::com::sun::star::uno::XInterface
;
41 using ::com::sun::star::uno::Any
;
42 using ::com::sun::star::sdbc::XConnection
;
43 using ::com::sun::star::lang::IllegalArgumentException
;
44 using ::com::sun::star::uno::XComponentContext
;
47 ConnectionTools::ConnectionTools( const Reference
<XComponentContext
>& _rContext
)
48 :ConnectionDependentComponent( _rContext
)
52 ConnectionTools::~ConnectionTools()
56 Reference
< XTableName
> SAL_CALL
ConnectionTools::createTableName()
58 EntryGuard
aGuard( *this );
59 return new TableName( getContext(), getConnection() );
62 Reference
< XObjectNames
> SAL_CALL
ConnectionTools::getObjectNames()
64 EntryGuard
aGuard( *this );
65 return new ObjectNames( getContext(), getConnection() );
68 Reference
< XDataSourceMetaData
> SAL_CALL
ConnectionTools::getDataSourceMetaData()
70 EntryGuard
aGuard( *this );
71 return new DataSourceMetaData( getContext(), getConnection() );
73 Reference
< container::XNameAccess
> SAL_CALL
ConnectionTools::getFieldsByCommandDescriptor( ::sal_Int32 commandType
, const OUString
& command
, Reference
< lang::XComponent
>& keepFieldsAlive
)
75 EntryGuard
aGuard( *this );
76 ::dbtools::SQLExceptionInfo aErrorInfo
;
77 Reference
< container::XNameAccess
> xRet
= ::dbtools::getFieldsByCommandDescriptor(getConnection(),commandType
,command
,keepFieldsAlive
,&aErrorInfo
);
78 if ( aErrorInfo
.isValid() )
82 Reference
< sdb::XSingleSelectQueryComposer
> SAL_CALL
ConnectionTools::getComposer( ::sal_Int32 commandType
, const OUString
& command
)
84 EntryGuard
aGuard( *this );
85 dbtools::StatementComposer
aComposer(getConnection(), command
, commandType
, true );
86 aComposer
.setDisposeComposer(false);
87 return aComposer
.getComposer();
90 OUString SAL_CALL
ConnectionTools::getImplementationName()
92 return "com.sun.star.comp.dbaccess.ConnectionTools";
95 sal_Bool SAL_CALL
ConnectionTools::supportsService(const OUString
& ServiceName
)
97 return cppu::supportsService(this, ServiceName
);
100 Sequence
< OUString
> SAL_CALL
ConnectionTools::getSupportedServiceNames()
102 return { "com.sun.star.sdb.tools.ConnectionTools" };
105 void SAL_CALL
ConnectionTools::initialize(const Sequence
< Any
> & _rArguments
)
107 ::osl::MutexGuard
aGuard( getMutex() );
109 Reference
< XConnection
> xConnection
;
110 if (_rArguments
.getLength()==1 && (_rArguments
[0] >>= xConnection
))
115 ::comphelper::NamedValueCollection
aArguments( _rArguments
);
116 aArguments
.get( "Connection" ) >>= xConnection
;
118 if ( !xConnection
.is() )
119 throw IllegalArgumentException();
121 setWeakConnection( xConnection
);
124 } // namespace sdbtools
126 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
127 com_sun_star_comp_dbaccess_ConnectionTools_get_implementation(
128 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
130 return cppu::acquire(new sdbtools::ConnectionTools(context
));
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */