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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_ucb.hxx"
30 
31 #include <cacheddynamicresultset.hxx>
32 #include <com/sun/star/sdbc/XResultSet.hpp>
33 #include <cachedcontentresultset.hxx>
34 #include <osl/diagnose.h>
35 
36 using namespace com::sun::star::lang;
37 using namespace com::sun::star::sdbc;
38 using namespace com::sun::star::ucb;
39 using namespace com::sun::star::uno;
40 using namespace rtl;
41 
42 CachedDynamicResultSet::CachedDynamicResultSet(
43 		Reference< XDynamicResultSet > xOrigin
44 		, const Reference< XContentIdentifierMapping > & xContentMapping
45 		, const Reference< XMultiServiceFactory > & xSMgr )
46 		: DynamicResultSetWrapper( xOrigin, xSMgr )
47 		, m_xContentIdentifierMapping( xContentMapping )
48 {
49 	impl_init();
50 }
51 
52 CachedDynamicResultSet::~CachedDynamicResultSet()
53 {
54 	impl_deinit();
55 }
56 
57 //virtual
58 void SAL_CALL CachedDynamicResultSet
59 	::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet )
60 {
61 	DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet );
62 	OSL_ENSURE( m_xSourceResultOne.is(), "need source resultset" );
63 
64 	Reference< XResultSet > xCache(
65         new CachedContentResultSet( m_xSMgr, m_xSourceResultOne, m_xContentIdentifierMapping ) );
66 
67 	osl::Guard< osl::Mutex > aGuard( m_aMutex );
68 	m_xMyResultOne = xCache;
69 }
70 
71 //virtual
72 void SAL_CALL CachedDynamicResultSet
73 	::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet )
74 {
75 	DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet );
76 	OSL_ENSURE( m_xSourceResultTwo.is(), "need source resultset" );
77 
78 	Reference< XResultSet > xCache(
79         new CachedContentResultSet( m_xSMgr, m_xSourceResultTwo, m_xContentIdentifierMapping ) );
80 
81 	osl::Guard< osl::Mutex > aGuard( m_aMutex );
82 	m_xMyResultTwo = xCache;
83 }
84 
85 //--------------------------------------------------------------------------
86 // XInterface methods.
87 //--------------------------------------------------------------------------
88 XINTERFACE_COMMON_IMPL( CachedDynamicResultSet )
89 
90 Any SAL_CALL CachedDynamicResultSet
91 	::queryInterface( const Type&  rType )
92 	throw ( RuntimeException )
93 {
94 	//list all interfaces inclusive baseclasses of interfaces
95 
96 	Any aRet = DynamicResultSetWrapper::queryInterface( rType );
97 	if( aRet.hasValue() )
98 		return aRet;
99 
100 	aRet = cppu::queryInterface( rType,
101 				static_cast< XTypeProvider* >( this )
102 				, static_cast< XServiceInfo* >( this )
103 				);
104 	return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
105 }
106 
107 //--------------------------------------------------------------------------
108 // XTypeProvider methods.
109 //--------------------------------------------------------------------------
110 //list all interfaces exclusive baseclasses
111 XTYPEPROVIDER_IMPL_4( CachedDynamicResultSet
112 					, XTypeProvider
113 					, XServiceInfo
114 					, XDynamicResultSet
115 					, XSourceInitialization
116 					);
117 
118 //--------------------------------------------------------------------------
119 // XServiceInfo methods.
120 //--------------------------------------------------------------------------
121 
122 XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSet,
123 				 		   OUString::createFromAscii(
124 							"com.sun.star.comp.ucb.CachedDynamicResultSet" ),
125 				 		   OUString::createFromAscii(
126 							CACHED_DRS_SERVICE_NAME ) );
127 
128 //--------------------------------------------------------------------------
129 // own methds. ( inherited )
130 //--------------------------------------------------------------------------
131 //virtual
132 void SAL_CALL CachedDynamicResultSet
133 	::impl_disposing( const EventObject& Source )
134 	throw( RuntimeException )
135 {
136 	DynamicResultSetWrapper::impl_disposing( Source );
137 	m_xContentIdentifierMapping.clear();
138 }
139 
140 //--------------------------------------------------------------------------
141 //--------------------------------------------------------------------------
142 // class CachedDynamicResultSetFactory
143 //--------------------------------------------------------------------------
144 //--------------------------------------------------------------------------
145 
146 CachedDynamicResultSetFactory::CachedDynamicResultSetFactory(
147 		const Reference< XMultiServiceFactory > & rSMgr )
148 {
149 	m_xSMgr = rSMgr;
150 }
151 
152 CachedDynamicResultSetFactory::~CachedDynamicResultSetFactory()
153 {
154 }
155 
156 //--------------------------------------------------------------------------
157 // CachedDynamicResultSetFactory XInterface methods.
158 //--------------------------------------------------------------------------
159 
160 XINTERFACE_IMPL_3( CachedDynamicResultSetFactory,
161 				   XTypeProvider,
162 				   XServiceInfo,
163 				   XCachedDynamicResultSetFactory );
164 
165 //--------------------------------------------------------------------------
166 // CachedDynamicResultSetFactory XTypeProvider methods.
167 //--------------------------------------------------------------------------
168 
169 XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetFactory,
170 					  XTypeProvider,
171 				   	  XServiceInfo,
172 					  XCachedDynamicResultSetFactory );
173 
174 //--------------------------------------------------------------------------
175 // CachedDynamicResultSetFactory XServiceInfo methods.
176 //--------------------------------------------------------------------------
177 
178 XSERVICEINFO_IMPL_1( CachedDynamicResultSetFactory,
179 	 		   		 OUString::createFromAscii(
180 					 	"com.sun.star.comp.ucb.CachedDynamicResultSetFactory" ),
181 	 		   		 OUString::createFromAscii(
182 					 	CACHED_DRS_FACTORY_NAME ) );
183 
184 //--------------------------------------------------------------------------
185 // Service factory implementation.
186 //--------------------------------------------------------------------------
187 
188 ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetFactory );
189 
190 //--------------------------------------------------------------------------
191 // CachedDynamicResultSetFactory XCachedDynamicResultSetFactory methods.
192 //--------------------------------------------------------------------------
193 
194 //virtual
195 Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetFactory
196 	::createCachedDynamicResultSet(
197 		  const Reference< XDynamicResultSet > & SourceStub
198 		, const Reference< XContentIdentifierMapping > & ContentIdentifierMapping )
199 		throw( RuntimeException )
200 {
201 	Reference< XDynamicResultSet > xRet;
202 	xRet = new CachedDynamicResultSet( SourceStub, ContentIdentifierMapping, m_xSMgr );
203 	return xRet;
204 }
205 
206 
207