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 .
22 #include <sal/config.h>
24 #include <config_features.h>
28 #include "ModelImpl.hxx"
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>
35 #if HAVE_FEATURE_SCRIPTING
36 #include <basic/basrdll.hxx>
39 #include <basic/basicmanagerrepository.hxx>
40 #include <cppuhelper/compbase.hxx>
42 // needed for registration
43 namespace com::sun::star
{
46 class XMultiServiceFactory
;
47 class IllegalArgumentException
;
53 class DatabaseDocumentLoader
;
55 typedef ::cppu::WeakComponentImplHelper
< css::lang::XServiceInfo
56 , css::sdb::XDatabaseContext
57 > DatabaseAccessContext_Base
;
59 class ODatabaseContext
:public DatabaseAccessContext_Base
60 ,public ::basic::BasicManagerCreationListener
63 /** loads the given object from the given URL
64 @throws WrappedTargetException
65 if an error occurs accessing the URL via the UCB
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
);
70 /** sets all properties which were transient at the data source. e.g. password
71 @param _sURL The file URL of the data source
72 @param _xObject The data source itself.
74 void setTransientProperties(const OUString
& _sURL
, ODatabaseModelImpl
& _rDataSourceModel
);
76 /** creates a new data source
78 css::uno::Reference
< css::uno::XInterface
>
79 impl_createNewDataSource();
81 #if HAVE_FEATURE_SCRIPTING
85 ::osl::Mutex m_aMutex
;
86 css::uno::Reference
< css::uno::XComponentContext
>
89 css::uno::Reference
< css::sdb::XDatabaseRegistrations
>
90 m_xDatabaseRegistrations
;
92 typedef std::map
<OUString
, ODatabaseModelImpl
*> ObjectCache
;
93 ObjectCache m_aDatabaseObjects
;
95 typedef std::map
< OUString
, css::uno::Sequence
< css::beans::PropertyValue
> > PropertyCache
;
96 PropertyCache m_aDatasourceProperties
;
97 // as we hold our data sources weak, we have to cache all properties on the data sources which are
98 // transient but stored as long as the session lasts. The database context is the session (as it lives
99 // as long as the session does), but the data sources may die before the session does, and then be
100 // recreated afterwards. So it's our (the context's) responsibility to store the session-persistent
103 ::comphelper::OInterfaceContainerHelper3
<css::container::XContainerListener
> m_aContainerListeners
;
104 rtl::Reference
<DatabaseDocumentLoader
> m_xDatabaseDocumentLoader
;
107 explicit ODatabaseContext( const css::uno::Reference
< css::uno::XComponentContext
>& );
108 virtual ~ODatabaseContext() override
;
111 virtual void SAL_CALL
disposing() override
;
113 // XSingleServiceFactory
114 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstance( ) override
;
115 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstanceWithArguments( const css::uno::Sequence
< css::uno::Any
>& _rArguments
) override
;
118 virtual OUString SAL_CALL
getImplementationName( ) override
;
119 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
120 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
123 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
124 virtual sal_Bool SAL_CALL
hasElements( ) override
;
126 // XEnumerationAccess
127 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createEnumeration( ) override
;
130 virtual css::uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
131 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames( ) override
;
132 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
135 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getRegisteredObject( const OUString
& Name
) override
;
136 virtual void SAL_CALL
registerObject( const OUString
& Name
, const css::uno::Reference
< css::uno::XInterface
>& Object
) override
;
137 virtual void SAL_CALL
revokeObject( const OUString
& Name
) override
;
139 // XDatabaseRegistrations
140 virtual sal_Bool SAL_CALL
hasRegisteredDatabase( const OUString
& Name
) override
;
141 virtual css::uno::Sequence
< OUString
> SAL_CALL
getRegistrationNames() override
;
142 virtual OUString SAL_CALL
getDatabaseLocation( const OUString
& Name
) override
;
143 virtual void SAL_CALL
registerDatabaseLocation( const OUString
& Name
, const OUString
& Location
) override
;
144 virtual void SAL_CALL
revokeDatabaseLocation( const OUString
& Name
) override
;
145 virtual void SAL_CALL
changeDatabaseLocation( const OUString
& Name
, const OUString
& NewLocation
) override
;
146 virtual sal_Bool SAL_CALL
isDatabaseRegistrationReadOnly( const OUString
& Name
) override
;
147 virtual void SAL_CALL
addDatabaseRegistrationsListener( const css::uno::Reference
< css::sdb::XDatabaseRegistrationsListener
>& Listener
) override
;
148 virtual void SAL_CALL
removeDatabaseRegistrationsListener( const css::uno::Reference
< css::sdb::XDatabaseRegistrationsListener
>& Listener
) override
;
151 virtual void SAL_CALL
addContainerListener( const css::uno::Reference
< css::container::XContainerListener
>& xListener
) override
;
152 virtual void SAL_CALL
removeContainerListener( const css::uno::Reference
< css::container::XContainerListener
>& xListener
) override
;
154 void registerDatabaseDocument( ODatabaseModelImpl
& _rModelImpl
);
155 void revokeDatabaseDocument( const ODatabaseModelImpl
& _rModelImpl
);
156 void databaseDocumentURLChange(const OUString
& _sOldName
, const OUString
& _sNewName
);
157 void storeTransientProperties( ODatabaseModelImpl
& _rModelImpl
);
158 void appendAtTerminateListener(const ODatabaseModelImpl
& _rDataSourceModel
);
159 void removeFromTerminateListener(const ODatabaseModelImpl
& _rDataSourceModel
);
162 // BasicManagerCreationListener
163 virtual void onBasicManagerCreated(
164 const css::uno::Reference
< css::frame::XModel
>& _rxForDocument
,
165 BasicManager
& _rBasicManager
169 } // namespace dbaccess
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */