1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: databasecontext.hxx,v $
10 * $Revision: 1.17.2.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_
32 #define _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_
34 #ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_
35 #include <com/sun/star/container/XEnumerationAccess.hpp>
37 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
38 #include <com/sun/star/container/XNameAccess.hpp>
40 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
41 #include <com/sun/star/uno/XNamingService.hpp>
43 #ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
44 #include <com/sun/star/lang/XUnoTunnel.hpp>
46 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
47 #include <com/sun/star/lang/XServiceInfo.hpp>
49 #ifndef _COM_SUN_STAR_SDB_XDATABASEENVIRONMENT_HPP_
50 #include <com/sun/star/sdb/XDatabaseEnvironment.hpp>
52 #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
53 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
55 #ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
56 #include <com/sun/star/container/XContainer.hpp>
58 #ifndef _CPPUHELPER_COMPBASE7_HXX_
59 #include <cppuhelper/compbase7.hxx>
61 #ifndef _COMPHELPER_STLTYPES_HXX_
62 #include <comphelper/stl_types.hxx>
64 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
65 #include <comphelper/componentcontext.hxx>
67 #ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
68 #include <cppuhelper/interfacecontainer.hxx>
70 #ifndef _COM_SUN_STAR_CONTAINER_ELEMENTEXISTEXCEPTION_HPP_
71 #include <com/sun/star/container/ElementExistException.hpp>
73 #ifndef _COM_SUN_STAR_LANG_XEVENTLISTENER_HPP_
74 #include <com/sun/star/lang/XEventListener.hpp>
76 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
77 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
79 #ifndef _DBA_COREDATAACCESS_MODELIMPL_HXX_
80 #include "ModelImpl.hxx"
82 #ifndef BASICMANAGERREPOSITORY_HXX
83 #include <basic/basicmanagerrepository.hxx>
86 #include <boost/shared_ptr.hpp>
88 // needed for registration
89 namespace com
{ namespace sun
{ namespace star
{
92 class XMultiServiceFactory
;
93 class IllegalArgumentException
;
97 //........................................................................
100 //........................................................................
101 class DatabaseDocumentLoader
;
102 //============================================================
104 //============================================================
105 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
106 ODatabaseContext_CreateInstance(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&);
108 typedef ::cppu::WeakComponentImplHelper7
< ::com::sun::star::lang::XServiceInfo
109 , ::com::sun::star::container::XEnumerationAccess
110 , ::com::sun::star::container::XNameAccess
111 , ::com::sun::star::uno::XNamingService
112 , ::com::sun::star::container::XContainer
113 , ::com::sun::star::lang::XSingleServiceFactory
114 , ::com::sun::star::lang::XUnoTunnel
115 > DatabaseAccessContext_Base
;
117 class ODatabaseContext
:public DatabaseAccessContext_Base
118 ,public ::basic::BasicManagerCreationListener
121 /** loads the given object from the given URL
122 @throws WrappedTargetException
123 if an error occurs accessing the URL via the UCB
126 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> loadObjectFromURL(const ::rtl::OUString
& _rName
,const ::rtl::OUString
& _sURL
);
127 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> getObject(const ::rtl::OUString
& _rName
);
129 /** retrieves the URL for a given registration name, if any
130 @returns <FALSE/> if and only if there exists a registration for the given name
131 @throws IllegalArgumentException if the name is empty
133 bool getURLForRegisteredObject( const ::rtl::OUString
& _rRegisteredName
, ::rtl::OUString
& _rURL
);
135 /** sets all properties which were transient at the data source. e.g. password
136 @param _sURL The file URL of the data source
137 @param _xObject The data source itself.
139 void setTransientProperties(const ::rtl::OUString
& _sURL
, ODatabaseModelImpl
& _rDataSourceModel
);
141 /** creates a new data source
143 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
144 impl_createNewDataSource();
147 ::osl::Mutex m_aMutex
;
148 ::comphelper::ComponentContext m_aContext
;
150 DECLARE_STL_USTRINGACCESS_MAP( ODatabaseModelImpl
*, ObjectCache
);
151 ObjectCache m_aDatabaseObjects
;
153 DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>, PropertyCache
);
154 PropertyCache m_aDatasourceProperties
;
155 // as we hold our data sources weak, we have to cache all properties on the data sources which are
156 // transient but stored as long as the session lasts. The database context is the session (as it lives
157 // as long as the session does), but the data sources may die before the session does, and then be
158 // recreated afterwards. So it's our (the context's) responsibility to store the session-persistent
161 ::cppu::OInterfaceContainerHelper m_aContainerListeners
;
162 DatabaseDocumentLoader
* m_pDatabaseDocumentLoader
;
165 ODatabaseContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& );
166 virtual ~ODatabaseContext();
170 virtual void SAL_CALL
disposing(void);
172 // ::com::sun::star::lang::XSingleServiceFactory
173 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
);
174 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
);
176 // ::com::sun::star::lang::XServiceInfo
177 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
);
178 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
);
179 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
);
181 // ::com::sun::star::lang::XServiceInfo - static methods
182 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException
);
183 static ::rtl::OUString
getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException
);
184 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
185 SAL_CALL
Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>&);
187 // ::com::sun::star::container::XElementAccess
188 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType( ) throw(::com::sun::star::uno::RuntimeException
);
189 virtual sal_Bool SAL_CALL
hasElements( ) throw(::com::sun::star::uno::RuntimeException
);
191 // ::com::sun::star::container::XEnumerationAccess
192 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
createEnumeration( ) throw(::com::sun::star::uno::RuntimeException
);
194 // ::com::sun::star::container::XNameAccess
195 virtual ::com::sun::star::uno::Any SAL_CALL
getByName( const ::rtl::OUString
& aName
) throw(::com::sun::star::container::NoSuchElementException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
);
196 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getElementNames( ) throw(::com::sun::star::uno::RuntimeException
);
197 virtual sal_Bool SAL_CALL
hasByName( const ::rtl::OUString
& aName
) throw(::com::sun::star::uno::RuntimeException
);
199 // ::com::sun::star::uno::XNamingService
200 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
getRegisteredObject( const ::rtl::OUString
& Name
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
201 virtual void SAL_CALL
registerObject( const ::rtl::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
);
202 virtual void SAL_CALL
revokeObject( const ::rtl::OUString
& Name
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
204 // ::com::sun::star::container::XContainer
205 virtual void SAL_CALL
addContainerListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerListener
>& xListener
) throw(::com::sun::star::uno::RuntimeException
);
206 virtual void SAL_CALL
removeContainerListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XContainerListener
>& xListener
) throw(::com::sun::star::uno::RuntimeException
);
208 // com::sun::star::lang::XUnoTunnel
209 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
) throw(::com::sun::star::uno::RuntimeException
);
210 static ::com::sun::star::uno::Sequence
< sal_Int8
> getUnoTunnelImplementationId();
212 void registerPrivate(const ::rtl::OUString
& _sName
213 ,const ::rtl::Reference
<ODatabaseModelImpl
>& _pModelImpl
);
214 void deregisterPrivate(const ::rtl::OUString
& _sName
);
215 void nameChangePrivate(const ::rtl::OUString
& _sOldName
, const ::rtl::OUString
& _sNewName
);
216 void storeTransientProperties( ODatabaseModelImpl
& _rModelImpl
);
217 void appendAtTerminateListener(const ODatabaseModelImpl
& _rDataSourceModel
);
218 void removeFromTerminateListener(const ODatabaseModelImpl
& _rDataSourceModel
);
221 // BasicManagerCreationListener
222 virtual void onBasicManagerCreated(
223 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& _rxForDocument
,
224 BasicManager
& _rBasicManager
228 //........................................................................
229 } // namespace dbaccess
230 //........................................................................
232 #endif // _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_