LibreOffice Module dbaccess (master) 1
connectiontools.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <connectiontools.hxx>
21#include "tablename.hxx"
22#include "objectnames.hxx"
24
29
30namespace sdbtools
31{
32
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;
45
46 // ConnectionTools
47 ConnectionTools::ConnectionTools( const Reference<XComponentContext>& _rContext )
49 {
50 }
51
53 {
54 }
55
56 Reference< XTableName > SAL_CALL ConnectionTools::createTableName()
57 {
58 EntryGuard aGuard( *this );
59 return new TableName( getContext(), getConnection() );
60 }
61
62 Reference< XObjectNames > SAL_CALL ConnectionTools::getObjectNames()
63 {
64 EntryGuard aGuard( *this );
65 return new ObjectNames( getContext(), getConnection() );
66 }
67
68 Reference< XDataSourceMetaData > SAL_CALL ConnectionTools::getDataSourceMetaData()
69 {
70 EntryGuard aGuard( *this );
72 }
73 Reference< container::XNameAccess > SAL_CALL ConnectionTools::getFieldsByCommandDescriptor( ::sal_Int32 commandType, const OUString& command, Reference< lang::XComponent >& keepFieldsAlive )
74 {
75 EntryGuard aGuard( *this );
77 Reference< container::XNameAccess > xRet = ::dbtools::getFieldsByCommandDescriptor(getConnection(),commandType,command,keepFieldsAlive,&aErrorInfo);
78 if ( aErrorInfo.isValid() )
79 aErrorInfo.doThrow();
80 return xRet;
81 }
82 Reference< sdb::XSingleSelectQueryComposer > SAL_CALL ConnectionTools::getComposer( ::sal_Int32 commandType, const OUString& command )
83 {
84 EntryGuard aGuard( *this );
85 dbtools::StatementComposer aComposer(getConnection(), command, commandType, true );
86 aComposer.setDisposeComposer(false);
87 return aComposer.getComposer();
88 }
89
91 {
92 return "com.sun.star.comp.dbaccess.ConnectionTools";
93 }
94
95 sal_Bool SAL_CALL ConnectionTools::supportsService(const OUString & ServiceName)
96 {
98 }
99
100 Sequence< OUString > SAL_CALL ConnectionTools::getSupportedServiceNames()
101 {
102 return { "com.sun.star.sdb.tools.ConnectionTools" };
103 }
104
105 void SAL_CALL ConnectionTools::initialize(const Sequence< Any > & _rArguments)
106 {
107 ::osl::MutexGuard aGuard( getMutex() );
108
109 Reference< XConnection > xConnection;
110 if (_rArguments.getLength()==1 && (_rArguments[0] >>= xConnection))
111 {
112 }
113 else
114 {
116 aArguments.get( "Connection" ) >>= xConnection;
117 }
118 if ( !xConnection.is() )
119 throw IllegalArgumentException();
120
121 setWeakConnection( xConnection );
122 }
123
124} // namespace sdbtools
125
126extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
128 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
129{
130 return cppu::acquire(new sdbtools::ConnectionTools(context));
131}
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setDisposeComposer(bool _bDoDispose)
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > const & getComposer()
a class for guarding methods of a connection-dependent component
const css::uno::Reference< css::uno::XComponentContext > & getContext() const
const css::uno::Reference< css::sdbc::XConnection > & getConnection() const
void setWeakConnection(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection)
sets the connection we depend on.
implements the css::sdb::tools::XConnectionTools functionality
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getFieldsByCommandDescriptor(::sal_Int32 commandType, const OUString &command, css::uno::Reference< css::lang::XComponent > &keepFieldsAlive) override
ConnectionTools(const css::uno::Reference< css::uno::XComponentContext > &_rContext)
constructs a ConnectionTools instance
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual css::uno::Reference< css::sdb::XSingleSelectQueryComposer > SAL_CALL getComposer(::sal_Int32 commandType, const OUString &command) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual ~ConnectionTools() override
virtual css::uno::Reference< css::sdb::tools::XDataSourceMetaData > SAL_CALL getDataSourceMetaData() override
virtual css::uno::Reference< css::sdb::tools::XObjectNames > SAL_CALL getObjectNames() override
virtual css::uno::Reference< css::sdb::tools::XTableName > SAL_CALL createTableName() override
virtual OUString SAL_CALL getImplementationName() override
default implementation for XDataSourceMetaData
default implementation for XObjectNames
Definition: objectnames.hxx:40
default implementation for XTableName
Definition: tablename.hxx:40
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_dbaccess_ConnectionTools_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Sequence< PropertyValue > aArguments
Definition: intercept.cxx:88
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool