1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #ifndef DBACCESS_ROWSETCACHEITERATOR_HXX
27 #include "RowSetCacheIterator.hxx"
28 #endif
29 #ifndef DBACCESS_CORE_API_ROWSETCACHE_HXX
30 #include "RowSetCache.hxx"
31 #endif
32 #ifndef DBACCESS_CORE_API_ROWSETBASE_HXX
33 #include "RowSetBase.hxx"
34 #endif
35 #include <rtl/logfile.hxx>
36 
37 using namespace dbaccess;
ORowSetCacheIterator(const ORowSetCacheIterator & _rRH)38 ORowSetCacheIterator::ORowSetCacheIterator(const ORowSetCacheIterator& _rRH)
39 : m_aIter(_rRH.m_aIter)
40 , m_pCache(_rRH.m_pCache)
41 ,m_pRowSet(_rRH.m_pRowSet)
42 {
43     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetCacheIterator::ORowSetCacheIterator" );
44 }
45 // -----------------------------------------------------------------------------
operator ORowSetMatrix::iterator()46 ORowSetCacheIterator::operator ORowSetMatrix::iterator()
47 {
48 	return m_aIter->second.aIterator;
49 }
50 // -----------------------------------------------------------------------------
operator =(const ORowSetCacheIterator & _rRH)51 ORowSetCacheIterator& ORowSetCacheIterator::operator =(const ORowSetCacheIterator& _rRH)
52 {
53 	if(this == &_rRH)
54 		return *this;
55 
56 	m_pCache = _rRH.m_pCache;
57 	m_aIter	 = _rRH.m_aIter;
58 	m_pRowSet = _rRH.m_pRowSet;
59 
60 	return *this;
61 }
62 // -----------------------------------------------------------------------------
operator =(const ORowSetMatrix::iterator & _rIter)63 ORowSetCacheIterator& ORowSetCacheIterator::operator =(const ORowSetMatrix::iterator& _rIter)
64 {
65 	m_aIter->second.aIterator = _rIter;
66 	return *this;
67 }
68 // -----------------------------------------------------------------------------
operator *()69 ORowSetRow& ORowSetCacheIterator::operator *()
70 {
71 	return *m_aIter->second.aIterator;
72 }
73 // -----------------------------------------------------------------------------
operator *() const74 const ORowSetRow& ORowSetCacheIterator::operator *() const
75 {
76 	if ( !m_pRowSet->isInsertRow() && m_aIter->second.aIterator == m_pCache->m_pMatrix->end() )
77 	{
78 		OSL_ENSURE(m_aIter->second.aBookmark.hasValue(),"bookmark has no value!");
79 		OSL_VERIFY(m_pCache->moveToBookmark(m_aIter->second.aBookmark));
80 		m_aIter->second.aIterator = m_pCache->m_aMatrixIter;
81 	}
82 	return *m_aIter->second.aIterator;
83 }
84 // -----------------------------------------------------------------------------
operator ->()85 ORowSetMatrix::iterator& ORowSetCacheIterator::operator ->()
86 {
87 	return m_aIter->second.aIterator;
88 }
89 // -----------------------------------------------------------------------------
operator ->() const90 const ORowSetMatrix::iterator& ORowSetCacheIterator::operator ->() const
91 {
92 	if ( !m_pRowSet->isInsertRow() && m_aIter->second.aIterator == m_pCache->m_pMatrix->end() )
93 	{
94 		OSL_ENSURE(m_aIter->second.aBookmark.hasValue(),"bookmark has no value!");
95 		OSL_VERIFY(m_pCache->moveToBookmark(m_aIter->second.aBookmark));
96 		m_aIter->second.aIterator = m_pCache->m_aMatrixIter;
97 	}
98 	return m_aIter->second.aIterator;
99 }
100 // -----------------------------------------------------------------------------
operator <=(const ORowSetMatrix::iterator & _rRH) const101 bool ORowSetCacheIterator::operator <=(const ORowSetMatrix::iterator& _rRH) const
102 {
103 	return m_aIter->second.aIterator <= _rRH;
104 }
105 // -----------------------------------------------------------------------------
operator <(const ORowSetMatrix::iterator & _rRH) const106 bool ORowSetCacheIterator::operator <(const ORowSetMatrix::iterator& _rRH) const
107 {
108 	return m_aIter->second.aIterator < _rRH;
109 }
110 // -----------------------------------------------------------------------------
operator !=(const ORowSetMatrix::iterator & _rRH) const111 bool ORowSetCacheIterator::operator !=(const ORowSetMatrix::iterator& _rRH) const
112 {
113 	return m_aIter->second.aIterator != _rRH;
114 }
115 // -----------------------------------------------------------------------------
operator ==(const ORowSetMatrix::iterator & _rRH) const116 bool ORowSetCacheIterator::operator ==(const ORowSetMatrix::iterator& _rRH) const
117 {
118 	return m_aIter->second.aIterator == _rRH;
119 }
120 // -----------------------------------------------------------------------------
setBookmark(const::com::sun::star::uno::Any & _rBookmark)121 void ORowSetCacheIterator::setBookmark(const ::com::sun::star::uno::Any&	_rBookmark)
122 {
123     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetCacheIterator::setBookmark" );
124 	m_aIter->second.aBookmark = _rBookmark;
125 }
126 // -----------------------------------------------------------------------------
isNull() const127 sal_Bool ORowSetCacheIterator::isNull() const
128 {
129     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetCacheIterator::isNull" );
130 	sal_Bool bRet = !m_pCache || !m_pRowSet || m_aIter == m_pCache->m_aCacheIterators.end();
131 	if ( !bRet )
132 	{
133 		ORowSetCacheIterator_Helper aHelper = m_aIter->second;
134 		bRet = ( m_pRowSet->isInsertRow()
135 			?
136 			m_aIter->second.aIterator == m_pCache->m_pInsertMatrix->end()
137 			:
138 			m_aIter->second.aIterator == m_pCache->m_pMatrix->end()
139 		);
140 	}
141 	return  bRet;
142 }
143 // -----------------------------------------------------------------------------
getMutex() const144 ::osl::Mutex* ORowSetCacheIterator::getMutex() const
145 {
146     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetCacheIterator::getMutex" );
147 	return m_pRowSet ? m_pRowSet->getMutex() : NULL;
148 }
149