LibreOffice Module dbaccess (master) 1
databasecontext.hxx
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#pragma once
21
22#include <sal/config.h>
23
24#include <config_features.h>
25
26#include <map>
27
28#include "ModelImpl.hxx"
29
30#include <com/sun/star/lang/XServiceInfo.hpp>
31#include <com/sun/star/sdb/XDatabaseContext.hpp>
32#include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
33#include <com/sun/star/uno/XAggregation.hpp>
34
35#if HAVE_FEATURE_SCRIPTING
36#include <basic/basrdll.hxx>
37#endif
38
41
42// needed for registration
43namespace com::sun::star {
44 namespace lang
45 {
46 class XMultiServiceFactory;
47 class IllegalArgumentException;
48 }
49}
50
51namespace dbaccess
52{
53class DatabaseDocumentLoader;
54
55typedef ::cppu::WeakComponentImplHelper< css::lang::XServiceInfo
56 , css::sdb::XDatabaseContext
58
61{
62private:
67 css::uno::Reference< css::uno::XInterface > loadObjectFromURL(const OUString& _rName,const OUString& _sURL);
68 css::uno::Reference< css::uno::XInterface > getObject( const OUString& _rURL );
69
74 void setTransientProperties(const OUString& _sURL, ODatabaseModelImpl& _rDataSourceModel );
75
78 css::uno::Reference< css::uno::XInterface >
80
81#if HAVE_FEATURE_SCRIPTING
82 BasicDLL m_aBasicDLL;
83#endif
84
85 ::osl::Mutex m_aMutex;
86 css::uno::Reference< css::uno::XComponentContext >
88
89 css::uno::Reference< css::uno::XAggregation >
91 css::uno::Reference< css::sdb::XDatabaseRegistrations >
93
94 typedef std::map<OUString, ODatabaseModelImpl*> ObjectCache;
96
97 typedef std::map< OUString, css::uno::Sequence< css::beans::PropertyValue > > PropertyCache;
99 // as we hold our data sources weak, we have to cache all properties on the data sources which are
100 // transient but stored as long as the session lasts. The database context is the session (as it lives
101 // as long as the session does), but the data sources may die before the session does, and then be
102 // recreated afterwards. So it's our (the context's) responsibility to store the session-persistent
103 // properties.
104
107
108public:
109 explicit ODatabaseContext( const css::uno::Reference< css::uno::XComponentContext >& );
110 virtual ~ODatabaseContext() override;
111
112 // OComponentHelper
113 virtual void SAL_CALL disposing() override;
114
115 // XSingleServiceFactory
116 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( ) override;
117 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const css::uno::Sequence< css::uno::Any >& _rArguments ) override;
118
119 // XServiceInfo
120 virtual OUString SAL_CALL getImplementationName( ) override;
121 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
122 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
123
124 // XElementAccess
125 virtual css::uno::Type SAL_CALL getElementType( ) override;
126 virtual sal_Bool SAL_CALL hasElements( ) override;
127
128 // XEnumerationAccess
129 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) override;
130
131 // XNameAccess
132 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
133 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
134 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
135
136 // XNamingService
137 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRegisteredObject( const OUString& Name ) override;
138 virtual void SAL_CALL registerObject( const OUString& Name, const css::uno::Reference< css::uno::XInterface >& Object ) override;
139 virtual void SAL_CALL revokeObject( const OUString& Name ) override;
140
141 // XDatabaseRegistrations
142 virtual sal_Bool SAL_CALL hasRegisteredDatabase( const OUString& Name ) override;
143 virtual css::uno::Sequence< OUString > SAL_CALL getRegistrationNames() override;
144 virtual OUString SAL_CALL getDatabaseLocation( const OUString& Name ) override;
145 virtual void SAL_CALL registerDatabaseLocation( const OUString& Name, const OUString& Location ) override;
146 virtual void SAL_CALL revokeDatabaseLocation( const OUString& Name ) override;
147 virtual void SAL_CALL changeDatabaseLocation( const OUString& Name, const OUString& NewLocation ) override;
148 virtual sal_Bool SAL_CALL isDatabaseRegistrationReadOnly( const OUString& Name ) override;
149 virtual void SAL_CALL addDatabaseRegistrationsListener( const css::uno::Reference< css::sdb::XDatabaseRegistrationsListener >& Listener ) override;
150 virtual void SAL_CALL removeDatabaseRegistrationsListener( const css::uno::Reference< css::sdb::XDatabaseRegistrationsListener >& Listener ) override;
151
152 // XContainer
153 virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
154 virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
155
157 void revokeDatabaseDocument( const ODatabaseModelImpl& _rModelImpl);
158 void databaseDocumentURLChange(const OUString& _sOldName, const OUString& _sNewName);
160 void appendAtTerminateListener(const ODatabaseModelImpl& _rDataSourceModel);
161 void removeFromTerminateListener(const ODatabaseModelImpl& _rDataSourceModel);
162
163private:
164 // BasicManagerCreationListener
165 virtual void onBasicManagerCreated(
166 const css::uno::Reference< css::frame::XModel >& _rxForDocument,
167 BasicManager& _rBasicManager
168 ) override;
169};
170
171} // namespace dbaccess
172
173/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL changeDatabaseLocation(const OUString &Name, const OUString &NewLocation) override
virtual void SAL_CALL registerObject(const OUString &Name, const css::uno::Reference< css::uno::XInterface > &Object) override
ODatabaseContext(const css::uno::Reference< css::uno::XComponentContext > &)
virtual void SAL_CALL removeDatabaseRegistrationsListener(const css::uno::Reference< css::sdb::XDatabaseRegistrationsListener > &Listener) override
css::uno::Reference< css::uno::XComponentContext > m_aContext
void removeFromTerminateListener(const ODatabaseModelImpl &_rDataSourceModel)
virtual css::uno::Sequence< OUString > SAL_CALL getRegistrationNames() override
css::uno::Reference< css::uno::XAggregation > m_xDBRegistrationAggregate
virtual OUString SAL_CALL getDatabaseLocation(const OUString &Name) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRegisteredObject(const OUString &Name) override
void databaseDocumentURLChange(const OUString &_sOldName, const OUString &_sNewName)
virtual sal_Bool SAL_CALL isDatabaseRegistrationReadOnly(const OUString &Name) override
virtual void onBasicManagerCreated(const css::uno::Reference< css::frame::XModel > &_rxForDocument, BasicManager &_rBasicManager) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
std::map< OUString, css::uno::Sequence< css::beans::PropertyValue > > PropertyCache
PropertyCache m_aDatasourceProperties
virtual void SAL_CALL addDatabaseRegistrationsListener(const css::uno::Reference< css::sdb::XDatabaseRegistrationsListener > &Listener) override
virtual void SAL_CALL disposing() override
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
::comphelper::OInterfaceContainerHelper3< css::container::XContainerListener > m_aContainerListeners
std::map< OUString, ODatabaseModelImpl * > ObjectCache
void setTransientProperties(const OUString &_sURL, ODatabaseModelImpl &_rDataSourceModel)
sets all properties which were transient at the data source.
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL hasElements() override
void storeTransientProperties(ODatabaseModelImpl &_rModelImpl)
void registerDatabaseDocument(ODatabaseModelImpl &_rModelImpl)
virtual void SAL_CALL revokeObject(const OUString &Name) override
void revokeDatabaseDocument(const ODatabaseModelImpl &_rModelImpl)
virtual sal_Bool SAL_CALL hasRegisteredDatabase(const OUString &Name) override
css::uno::Reference< css::uno::XInterface > loadObjectFromURL(const OUString &_rName, const OUString &_sURL)
loads the given object from the given URL
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual ~ODatabaseContext() override
void appendAtTerminateListener(const ODatabaseModelImpl &_rDataSourceModel)
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance() override
virtual void SAL_CALL revokeDatabaseLocation(const OUString &Name) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL registerDatabaseLocation(const OUString &Name, const OUString &Location) override
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Reference< css::sdb::XDatabaseRegistrations > m_xDatabaseRegistrations
css::uno::Reference< css::uno::XInterface > getObject(const OUString &_rURL)
rtl::Reference< DatabaseDocumentLoader > m_xDatabaseDocumentLoader
css::uno::Reference< css::uno::XInterface > impl_createNewDataSource()
creates a new data source
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(const css::uno::Sequence< css::uno::Any > &_rArguments) override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
::cppu::WeakComponentImplHelper< css::lang::XServiceInfo, css::sdb::XDatabaseContext > DatabaseAccessContext_Base
unsigned char sal_Bool