build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / dbaccess / source / core / dataaccess / databasecontext.hxx
blob14f4a0ba956825cefb02267d5a5d13f18bb477b7
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 #ifndef INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DATABASECONTEXT_HXX
21 #define INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DATABASECONTEXT_HXX
23 #include <sal/config.h>
25 #include <map>
27 #include "ModelImpl.hxx"
29 #include <com/sun/star/container/ElementExistException.hpp>
30 #include <com/sun/star/container/XContainer.hpp>
31 #include <com/sun/star/container/XEnumerationAccess.hpp>
32 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #include <com/sun/star/lang/XEventListener.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37 #include <com/sun/star/lang/XUnoTunnel.hpp>
38 #include <com/sun/star/sdb/XDatabaseContext.hpp>
39 #include <com/sun/star/sdb/XDatabaseEnvironment.hpp>
40 #include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
41 #include <com/sun/star/uno/XNamingService.hpp>
42 #include <com/sun/star/uno/XAggregation.hpp>
44 #include <basic/basicmanagerrepository.hxx>
45 #include <cppuhelper/compbase.hxx>
46 #include <cppuhelper/interfacecontainer.hxx>
48 // needed for registration
49 namespace com { namespace sun { namespace star {
50 namespace lang
52 class XMultiServiceFactory;
53 class IllegalArgumentException;
55 } } }
57 namespace dbaccess
59 class DatabaseDocumentLoader;
61 typedef ::cppu::WeakComponentImplHelper< css::lang::XServiceInfo
62 , css::sdb::XDatabaseContext
63 , css::lang::XUnoTunnel
64 > DatabaseAccessContext_Base;
66 class ODatabaseContext :public DatabaseAccessContext_Base
67 ,public ::basic::BasicManagerCreationListener
69 private:
70 /** loads the given object from the given URL
71 @throws WrappedTargetException
72 if an error occurs accessing the URL via the UCB
74 css::uno::Reference< css::uno::XInterface > loadObjectFromURL(const OUString& _rName,const OUString& _sURL);
75 css::uno::Reference< css::uno::XInterface > getObject( const OUString& _rURL );
77 /** sets all properties which were transient at the data source. e.g. password
78 @param _sURL The file URL of the data source
79 @param _xObject The data source itself.
81 void setTransientProperties(const OUString& _sURL, ODatabaseModelImpl& _rDataSourceModel );
83 /** creates a new data source
85 css::uno::Reference< css::uno::XInterface >
86 impl_createNewDataSource();
88 protected:
89 ::osl::Mutex m_aMutex;
90 css::uno::Reference< css::uno::XComponentContext >
91 m_aContext;
93 css::uno::Reference< css::uno::XAggregation >
94 m_xDBRegistrationAggregate;
95 css::uno::Reference< css::sdb::XDatabaseRegistrations >
96 m_xDatabaseRegistrations;
98 typedef std::map<OUString, ODatabaseModelImpl*> ObjectCache;
99 ObjectCache m_aDatabaseObjects;
101 typedef std::map< OUString, css::uno::Sequence< css::beans::PropertyValue > > PropertyCache;
102 PropertyCache m_aDatasourceProperties;
103 // as we hold our data sources weak, we have to cache all properties on the data sources which are
104 // transient but stored as long as the session lasts. The database context is the session (as it lives
105 // as long as the session does), but the data sources may die before the session does, and then be
106 // recreated afterwards. So it's our (the context's) responsibility to store the session-persistent
107 // properties.
109 ::comphelper::OInterfaceContainerHelper2 m_aContainerListeners;
110 DatabaseDocumentLoader* m_pDatabaseDocumentLoader;
112 public:
113 explicit ODatabaseContext( const css::uno::Reference< css::uno::XComponentContext >& );
114 virtual ~ODatabaseContext() override;
116 // OComponentHelper
117 virtual void SAL_CALL disposing() override;
119 // XSingleServiceFactory
120 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) override;
121 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const css::uno::Sequence< css::uno::Any >& _rArguments ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) override;
123 // XServiceInfo
124 virtual OUString SAL_CALL getImplementationName( ) throw(css::uno::RuntimeException, std::exception) override;
125 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(css::uno::RuntimeException, std::exception) override;
126 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(css::uno::RuntimeException, std::exception) override;
128 // XServiceInfo - static methods
129 /// @throws css::uno::RuntimeException
130 static css::uno::Sequence< OUString > getSupportedServiceNames_static() throw( css::uno::RuntimeException );
131 /// @throws css::uno::RuntimeException
132 static OUString getImplementationName_static() throw( css::uno::RuntimeException );
133 static css::uno::Reference< css::uno::XInterface >
134 SAL_CALL Create(const css::uno::Reference< css::uno::XComponentContext >&);
136 // XElementAccess
137 virtual css::uno::Type SAL_CALL getElementType( ) throw(css::uno::RuntimeException, std::exception) override;
138 virtual sal_Bool SAL_CALL hasElements( ) throw(css::uno::RuntimeException, std::exception) override;
140 // XEnumerationAccess
141 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) throw(css::uno::RuntimeException, std::exception) override;
143 // XNameAccess
144 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) throw(css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
145 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) throw(css::uno::RuntimeException, std::exception) override;
146 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(css::uno::RuntimeException, std::exception) override;
148 // XNamingService
149 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRegisteredObject( const OUString& Name ) throw(css::uno::Exception, css::uno::RuntimeException, std::exception) override;
150 virtual void SAL_CALL registerObject( const OUString& Name, const css::uno::Reference< css::uno::XInterface >& Object ) throw(css::uno::Exception, css::uno::RuntimeException, std::exception) override;
151 virtual void SAL_CALL revokeObject( const OUString& Name ) throw(css::uno::Exception, css::uno::RuntimeException, std::exception) override;
153 // XDatabaseRegistrations
154 virtual sal_Bool SAL_CALL hasRegisteredDatabase( const OUString& Name ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) override;
155 virtual css::uno::Sequence< OUString > SAL_CALL getRegistrationNames() throw (css::uno::RuntimeException, std::exception) override;
156 virtual OUString SAL_CALL getDatabaseLocation( const OUString& Name ) throw (css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) override;
157 virtual void SAL_CALL registerDatabaseLocation( const OUString& Name, const OUString& Location ) throw (css::lang::IllegalArgumentException, css::container::ElementExistException, css::uno::RuntimeException, std::exception) override;
158 virtual void SAL_CALL revokeDatabaseLocation( const OUString& Name ) throw (css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception) override;
159 virtual void SAL_CALL changeDatabaseLocation( const OUString& Name, const OUString& NewLocation ) throw (css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::IllegalAccessException, css::uno::RuntimeException, std::exception) override;
160 virtual sal_Bool SAL_CALL isDatabaseRegistrationReadOnly( const OUString& Name ) throw (css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) override;
161 virtual void SAL_CALL addDatabaseRegistrationsListener( const css::uno::Reference< css::sdb::XDatabaseRegistrationsListener >& Listener ) throw (css::uno::RuntimeException, std::exception) override;
162 virtual void SAL_CALL removeDatabaseRegistrationsListener( const css::uno::Reference< css::sdb::XDatabaseRegistrationsListener >& Listener ) throw (css::uno::RuntimeException, std::exception) override;
164 // XContainer
165 virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) throw(css::uno::RuntimeException, std::exception) override;
166 virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) throw(css::uno::RuntimeException, std::exception) override;
168 // css::lang::XUnoTunnel
169 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) throw(css::uno::RuntimeException, std::exception) override;
170 static css::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
172 void registerDatabaseDocument( ODatabaseModelImpl& _rModelImpl);
173 void revokeDatabaseDocument( const ODatabaseModelImpl& _rModelImpl);
174 void databaseDocumentURLChange(const OUString& _sOldName, const OUString& _sNewName);
175 void storeTransientProperties( ODatabaseModelImpl& _rModelImpl);
176 void appendAtTerminateListener(const ODatabaseModelImpl& _rDataSourceModel);
177 void removeFromTerminateListener(const ODatabaseModelImpl& _rDataSourceModel);
179 private:
180 // BasicManagerCreationListener
181 virtual void onBasicManagerCreated(
182 const css::uno::Reference< css::frame::XModel >& _rxForDocument,
183 BasicManager& _rBasicManager
184 ) override;
187 } // namespace dbaccess
189 #endif // INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DATABASECONTEXT_HXX
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */