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 .
20 #ifndef INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DATABASECONTEXT_HXX
21 #define INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DATABASECONTEXT_HXX
23 #include <sal/config.h>
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/compbase3.hxx>
46 #include <cppuhelper/interfacecontainer.hxx>
48 #include <boost/shared_ptr.hpp>
50 // needed for registration
51 namespace com
{ namespace sun
{ namespace star
{
54 class XMultiServiceFactory
;
55 class IllegalArgumentException
;
61 class DatabaseDocumentLoader
;
63 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
64 ODatabaseContext_CreateInstance(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&);
66 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::lang::XServiceInfo
67 , ::com::sun::star::sdb::XDatabaseContext
68 , ::com::sun::star::lang::XUnoTunnel
69 > DatabaseAccessContext_Base
;
71 class ODatabaseContext
:public DatabaseAccessContext_Base
72 ,public ::basic::BasicManagerCreationListener
75 /** loads the given object from the given URL
76 @throws WrappedTargetException
77 if an error occurs accessing the URL via the UCB
79 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> loadObjectFromURL(const OUString
& _rName
,const OUString
& _sURL
);
80 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> getObject( const OUString
& _rURL
);
82 /** sets all properties which were transient at the data source. e.g. password
83 @param _sURL The file URL of the data source
84 @param _xObject The data source itself.
86 void setTransientProperties(const OUString
& _sURL
, ODatabaseModelImpl
& _rDataSourceModel
);
88 /** creates a new data source
90 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
91 impl_createNewDataSource();
94 ::osl::Mutex m_aMutex
;
95 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
98 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XAggregation
>
99 m_xDBRegistrationAggregate
;
100 ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XDatabaseRegistrations
>
101 m_xDatabaseRegistrations
;
103 typedef std::map
<OUString
, ODatabaseModelImpl
*> ObjectCache
;
104 ObjectCache m_aDatabaseObjects
;
106 typedef std::map
< OUString
, ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> > PropertyCache
;
107 PropertyCache m_aDatasourceProperties
;
108 // as we hold our data sources weak, we have to cache all properties on the data sources which are
109 // transient but stored as long as the session lasts. The database context is the session (as it lives
110 // as long as the session does), but the data sources may die before the session does, and then be
111 // recreated afterwards. So it's our (the context's) responsibility to store the session-persistent
114 ::cppu::OInterfaceContainerHelper m_aContainerListeners
;
115 DatabaseDocumentLoader
* m_pDatabaseDocumentLoader
;
118 ODatabaseContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& );
119 virtual ~ODatabaseContext();
122 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
124 // XSingleServiceFactory
125 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
createInstance( ) throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
126 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
createInstanceWithArguments( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& _rArguments
) throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
129 virtual OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
130 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
131 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
133 // XServiceInfo - static methods
134 static ::com::sun::star::uno::Sequence
< OUString
> getSupportedServiceNames_static() throw( ::com::sun::star::uno::RuntimeException
);
135 static OUString
getImplementationName_static() throw( ::com::sun::star::uno::RuntimeException
);
136 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
137 SAL_CALL
Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>&);
140 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
141 virtual sal_Bool SAL_CALL
hasElements( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
143 // XEnumerationAccess
144 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createEnumeration( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
147 virtual ::com::sun::star::uno::Any SAL_CALL
getByName( const OUString
& aName
) throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
148 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getElementNames( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
149 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
152 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
getRegisteredObject( const OUString
& Name
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
153 virtual void SAL_CALL
registerObject( const OUString
& Name
, const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& Object
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
154 virtual void SAL_CALL
revokeObject( const OUString
& Name
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
156 // XDatabaseRegistrations
157 virtual sal_Bool SAL_CALL
hasRegisteredDatabase( const OUString
& Name
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
158 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getRegistrationNames() throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
159 virtual OUString SAL_CALL
getDatabaseLocation( const OUString
& Name
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
160 virtual void SAL_CALL
registerDatabaseLocation( const OUString
& Name
, const OUString
& Location
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::ElementExistException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
161 virtual void SAL_CALL
revokeDatabaseLocation( const OUString
& Name
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::IllegalAccessException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
162 virtual void SAL_CALL
changeDatabaseLocation( const OUString
& Name
, const OUString
& NewLocation
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::IllegalAccessException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
163 virtual sal_Bool SAL_CALL
isDatabaseRegistrationReadOnly( const OUString
& Name
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
164 virtual void SAL_CALL
addDatabaseRegistrationsListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XDatabaseRegistrationsListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
165 virtual void SAL_CALL
removeDatabaseRegistrationsListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdb::XDatabaseRegistrationsListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
168 virtual void SAL_CALL
addContainerListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerListener
>& xListener
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
169 virtual void SAL_CALL
removeContainerListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerListener
>& xListener
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
171 // com::sun::star::lang::XUnoTunnel
172 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
173 static ::com::sun::star::uno::Sequence
< sal_Int8
> getUnoTunnelImplementationId();
175 void registerDatabaseDocument( ODatabaseModelImpl
& _rModelImpl
);
176 void revokeDatabaseDocument( const ODatabaseModelImpl
& _rModelImpl
);
177 void databaseDocumentURLChange(const OUString
& _sOldName
, const OUString
& _sNewName
);
178 void storeTransientProperties( ODatabaseModelImpl
& _rModelImpl
);
179 void appendAtTerminateListener(const ODatabaseModelImpl
& _rDataSourceModel
);
180 void removeFromTerminateListener(const ODatabaseModelImpl
& _rDataSourceModel
);
183 // BasicManagerCreationListener
184 virtual void onBasicManagerCreated(
185 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& _rxForDocument
,
186 BasicManager
& _rBasicManager
190 } // namespace dbaccess
192 #endif // INCLUDED_DBACCESS_SOURCE_CORE_DATAACCESS_DATABASECONTEXT_HXX
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */