1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _SORTDYNRES_HXX 29 #define _SORTDYNRES_HXX 30 31 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32 #include <com/sun/star/lang/XTypeProvider.hpp> 33 #include <com/sun/star/lang/XServiceInfo.hpp> 34 #include <com/sun/star/lang/XComponent.hpp> 35 #include <com/sun/star/ucb/NumberedSortingInfo.hpp> 36 #include <com/sun/star/sdbc/XResultSet.hpp> 37 #include <com/sun/star/ucb/XDynamicResultSet.hpp> 38 #include <com/sun/star/ucb/XDynamicResultSetListener.hpp> 39 #include <com/sun/star/ucb/ListenerAlreadySetException.hpp> 40 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp> 41 #include <cppuhelper/weak.hxx> 42 #include <osl/mutex.hxx> 43 #include <ucbhelper/macros.hxx> 44 #include "sortresult.hxx" 45 46 namespace cppu { 47 class OInterfaceContainerHelper; 48 } 49 50 //----------------------------------------------------------------------------- 51 52 #define NUMBERED_SORTINGINFO com::sun::star::ucb::NumberedSortingInfo 53 #define RUNTIMEEXCEPTION com::sun::star::uno::RuntimeException 54 #define REFERENCE com::sun::star::uno::Reference 55 #define SEQUENCE com::sun::star::uno::Sequence 56 #define EVENTOBJECT com::sun::star::lang::EventObject 57 #define XEVENTLISTENER com::sun::star::lang::XEventListener 58 #define XMULTISERVICEFACTORY com::sun::star::lang::XMultiServiceFactory 59 #define XRESULTSET com::sun::star::sdbc::XResultSet 60 #define SQLEXCEPTION com::sun::star::sdbc::SQLException 61 #define XANYCOMPAREFACTORY com::sun::star::ucb::XAnyCompareFactory 62 #define XDYNAMICRESULTSET com::sun::star::ucb::XDynamicResultSet 63 #define XDYNAMICRESULTSETLISTENER com::sun::star::ucb::XDynamicResultSetListener 64 #define LISTENERALREADYSETEXCEPTION com::sun::star::ucb::ListenerAlreadySetException 65 66 #define DYNAMIC_RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedDynamicResultSet" 67 #define DYNAMIC_RESULTSET_FACTORY_NAME "com.sun.star.ucb.SortedDynamicResultSetFactory" 68 69 //----------------------------------------------------------------------------- 70 class SortedDynamicResultSetListener; 71 72 class SortedDynamicResultSet: 73 public cppu::OWeakObject, 74 public com::sun::star::lang::XTypeProvider, 75 public com::sun::star::lang::XServiceInfo, 76 public com::sun::star::ucb::XDynamicResultSet 77 { 78 cppu::OInterfaceContainerHelper *mpDisposeEventListeners; 79 80 REFERENCE < XDYNAMICRESULTSETLISTENER > mxListener; 81 REFERENCE < XDYNAMICRESULTSETLISTENER > mxOwnListener; 82 83 REFERENCE < XRESULTSET > mxOne; 84 REFERENCE < XRESULTSET > mxTwo; 85 REFERENCE < XDYNAMICRESULTSET > mxOriginal; 86 SEQUENCE < NUMBERED_SORTINGINFO > maOptions; 87 REFERENCE < XANYCOMPAREFACTORY > mxCompFac; 88 REFERENCE < XMULTISERVICEFACTORY > mxSMgr; 89 90 SortedResultSet* mpOne; 91 SortedResultSet* mpTwo; 92 SortedDynamicResultSetListener* mpOwnListener; 93 94 EventList maActions; 95 osl::Mutex maMutex; 96 sal_Bool mbGotWelcome :1; 97 sal_Bool mbUseOne :1; 98 sal_Bool mbStatic :1; 99 100 private: 101 102 void SendNotify(); 103 104 public: 105 SortedDynamicResultSet( const REFERENCE < XDYNAMICRESULTSET > &xOriginal, 106 const SEQUENCE < NUMBERED_SORTINGINFO > &aOptions, 107 const REFERENCE < XANYCOMPAREFACTORY > &xCompFac, 108 const REFERENCE < XMULTISERVICEFACTORY > &xSMgr ); 109 110 ~SortedDynamicResultSet(); 111 112 //----------------------------------------------------------------- 113 // XInterface 114 //----------------------------------------------------------------- 115 XINTERFACE_DECL() 116 117 //----------------------------------------------------------------- 118 // XTypeProvider 119 //----------------------------------------------------------------- 120 XTYPEPROVIDER_DECL() 121 122 //----------------------------------------------------------------- 123 // XServiceInfo 124 //----------------------------------------------------------------- 125 XSERVICEINFO_NOFACTORY_DECL() 126 127 //----------------------------------------------------------------- 128 // XComponent 129 //----------------------------------------------------------------- 130 virtual void SAL_CALL 131 dispose() throw( RUNTIME_EXCEPTION ); 132 133 virtual void SAL_CALL 134 addEventListener( const REFERENCE< XEVENTLISTENER >& Listener ) 135 throw( RUNTIME_EXCEPTION ); 136 137 virtual void SAL_CALL 138 removeEventListener( const REFERENCE< XEVENTLISTENER >& Listener ) 139 throw( RUNTIME_EXCEPTION ); 140 141 //----------------------------------------------------------------- 142 // XDynamicResultSet 143 //----------------------------------------------------------------- 144 virtual REFERENCE< XRESULTSET > SAL_CALL 145 getStaticResultSet( ) 146 throw( LISTENERALREADYSETEXCEPTION, RUNTIMEEXCEPTION ); 147 148 virtual void SAL_CALL 149 setListener( const REFERENCE< XDYNAMICRESULTSETLISTENER >& Listener ) 150 throw( LISTENERALREADYSETEXCEPTION, RUNTIMEEXCEPTION ); 151 152 virtual void SAL_CALL 153 connectToCache( const REFERENCE< XDYNAMICRESULTSET > & xCache ) 154 throw( LISTENERALREADYSETEXCEPTION, 155 com::sun::star::ucb::AlreadyInitializedException, 156 com::sun::star::ucb::ServiceNotFoundException, 157 RUNTIMEEXCEPTION ); 158 159 virtual sal_Int16 SAL_CALL 160 getCapabilities() 161 throw( RUNTIMEEXCEPTION ); 162 163 //----------------------------------------------------------------- 164 // own methods: 165 //----------------------------------------------------------------- 166 virtual void SAL_CALL 167 impl_disposing( const EVENTOBJECT& Source ) 168 throw( RUNTIMEEXCEPTION ); 169 170 virtual void SAL_CALL 171 impl_notify( const ::com::sun::star::ucb::ListEvent& Changes ) 172 throw( RUNTIMEEXCEPTION ); 173 }; 174 175 //----------------------------------------------------------------------------- 176 177 class SortedDynamicResultSetListener: 178 public cppu::OWeakObject, 179 public com::sun::star::ucb::XDynamicResultSetListener 180 { 181 SortedDynamicResultSet *mpOwner; 182 osl::Mutex maMutex; 183 184 public: 185 SortedDynamicResultSetListener( SortedDynamicResultSet *mOwner ); 186 ~SortedDynamicResultSetListener(); 187 188 //----------------------------------------------------------------- 189 // XInterface 190 //----------------------------------------------------------------- 191 XINTERFACE_DECL() 192 193 //----------------------------------------------------------------- 194 // XEventListener ( base of XDynamicResultSetListener ) 195 //----------------------------------------------------------------- 196 virtual void SAL_CALL 197 disposing( const EVENTOBJECT& Source ) 198 throw( RUNTIMEEXCEPTION ); 199 200 //----------------------------------------------------------------- 201 // XDynamicResultSetListener 202 //----------------------------------------------------------------- 203 virtual void SAL_CALL 204 notify( const ::com::sun::star::ucb::ListEvent& Changes ) 205 throw( RUNTIMEEXCEPTION ); 206 207 //----------------------------------------------------------------- 208 // own methods: 209 //----------------------------------------------------------------- 210 void SAL_CALL impl_OwnerDies(); 211 }; 212 213 //----------------------------------------------------------------------------- 214 215 class SortedDynamicResultSetFactory: 216 public cppu::OWeakObject, 217 public com::sun::star::lang::XTypeProvider, 218 public com::sun::star::lang::XServiceInfo, 219 public com::sun::star::ucb::XSortedDynamicResultSetFactory 220 { 221 222 REFERENCE< XMULTISERVICEFACTORY > mxSMgr; 223 224 public: 225 226 SortedDynamicResultSetFactory( 227 const REFERENCE< XMULTISERVICEFACTORY > & rSMgr); 228 229 ~SortedDynamicResultSetFactory(); 230 231 //----------------------------------------------------------------- 232 // XInterface 233 //----------------------------------------------------------------- 234 XINTERFACE_DECL() 235 236 //----------------------------------------------------------------- 237 // XTypeProvider 238 //----------------------------------------------------------------- 239 XTYPEPROVIDER_DECL() 240 241 //----------------------------------------------------------------- 242 // XServiceInfo 243 //----------------------------------------------------------------- 244 XSERVICEINFO_DECL() 245 246 //----------------------------------------------------------------- 247 // XSortedDynamicResultSetFactory 248 249 virtual REFERENCE< XDYNAMICRESULTSET > SAL_CALL 250 createSortedDynamicResultSet( 251 const REFERENCE< XDYNAMICRESULTSET > & Source, 252 const SEQUENCE< NUMBERED_SORTINGINFO > & Info, 253 const REFERENCE< XANYCOMPAREFACTORY > & CompareFactory ) 254 throw( RUNTIMEEXCEPTION ); 255 }; 256 257 #endif 258