LibreOffice Module dbaccess (master) 1
unoDirectSql.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 <sal/config.h>
21
22#include "unoDirectSql.hxx"
23#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
24#include <com/sun/star/connection/XConnection.hpp>
25#include <com/sun/star/beans/PropertyValue.hpp>
26#include <directsql.hxx>
28#include <strings.hxx>
30#include <vcl/svapp.hxx>
31
32extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
34 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
35{
36 return cppu::acquire(new ::dbaui::ODirectSQLDialog(context));
37}
38
39namespace dbaui
40{
41
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::sdbcx;
47 using namespace ::com::sun::star::sdbc;
48
49 // ODirectSQLDialog
51 :ODirectSQLDialog_BASE( _rxORB )
52 {
53
54 }
55
57 {
58
59 }
60
61 css::uno::Sequence<sal_Int8> ODirectSQLDialog::getImplementationId()
62 {
63 return css::uno::Sequence<sal_Int8>();
64 }
65
67 {
68 return "com.sun.star.comp.sdb.DirectSQLDialog";
69 }
70 sal_Bool SAL_CALL ODirectSQLDialog::supportsService(const OUString& _rServiceName)
71 {
72 const css::uno::Sequence< OUString > aSupported(getSupportedServiceNames());
73 for (const OUString& s : aSupported)
74 if (s == _rServiceName)
75 return true;
76
77 return false;
78 }
79 css::uno::Sequence< OUString > SAL_CALL ODirectSQLDialog::getSupportedServiceNames( )
80 {
82 }
83
84 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL ODirectSQLDialog::getPropertySetInfo()
85 {
86 Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
87 return xInfo;
88 }
90 {
92 }
94 {
95 css::uno::Sequence< css::beans::Property > aProps;
96 describeProperties(aProps);
97 return new ::cppu::OPropertyArrayHelper(aProps);
98 }
99
100
101 std::unique_ptr<weld::DialogController> ODirectSQLDialog::createDialog(const css::uno::Reference<css::awt::XWindow>& rParent)
102 {
103 // obtain all the objects needed for the dialog
105 weld::Window* pParent = Application::GetFrameWeld(rParent);
106 if ( !xConnection.is() )
107 {
108 try
109 {
110 // the connection the row set is working with
111 ODatasourceConnector aDSConnector(m_aContext, pParent);
112 xConnection = aDSConnector.connect( m_sInitialSelection, nullptr );
113 }
114 catch( const Exception& )
115 {
116 DBG_UNHANDLED_EXCEPTION("dbaccess");
117 }
118 }
119 if (!xConnection.is())
120 {
121 // can't create the dialog if I have improper settings
122 return nullptr;
123 }
124
125 return std::make_unique<DirectSQLDialog>(pParent, xConnection);
126 }
127
128 void ODirectSQLDialog::implInitialize(const Any& _rValue)
129 {
130 PropertyValue aProperty;
131 if (_rValue >>= aProperty)
132 {
133 if (aProperty.Name == "InitialSelection")
134 {
135 OSL_VERIFY( aProperty.Value >>= m_sInitialSelection );
136 return;
137 }
138 else if (aProperty.Name == "ActiveConnection")
139 {
140 m_xActiveConnection.set( aProperty.Value, UNO_QUERY );
141 OSL_ENSURE( m_xActiveConnection.is(), "ODirectSQLDialog::implInitialize: invalid connection!" );
142 return;
143 }
144 }
146 }
147} // namespace dbaui
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
::cppu::IPropertyArrayHelper * getArrayHelper()
css::uno::Reference< css::sdbc::XConnection > connect(const OUString &_rDataSourceName, ::dbtools::SQLExceptionInfo *_pErrorInfo) const
creates a connection to the data source, displays the possible error to the user, or returns it
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual std::unique_ptr< weld::DialogController > createDialog(const css::uno::Reference< css::awt::XWindow > &rParent) override
virtual void implInitialize(const css::uno::Any &_rValue) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
css::uno::Reference< css::sdbc::XConnection > m_xActiveConnection
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual ~ODirectSQLDialog() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
ODirectSQLDialog(const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override=0
virtual OUString SAL_CALL getImplementationName() override=0
virtual void implInitialize(const css::uno::Any &_rValue)
css::uno::Reference< css::uno::XComponentContext > m_aContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
constexpr OUStringLiteral SERVICE_SDB_DIRECTSQLDIALOG
Definition: strings.hxx:249
unsigned char sal_Bool
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sdb_DirectSQLDialog_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)