xref: /AOO41X/main/dbaccess/source/core/api/RowSetCacheIterator.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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_dbaccess.hxx"
30 #ifndef DBACCESS_ROWSETCACHEITERATOR_HXX
31 #include "RowSetCacheIterator.hxx"
32 #endif
33 #ifndef DBACCESS_CORE_API_ROWSETCACHE_HXX
34 #include "RowSetCache.hxx"
35 #endif
36 #ifndef DBACCESS_CORE_API_ROWSETBASE_HXX
37 #include "RowSetBase.hxx"
38 #endif
39 #include <rtl/logfile.hxx>
40 
41 using namespace dbaccess;
42 ORowSetCacheIterator::ORowSetCacheIterator(const ORowSetCacheIterator& _rRH)
43 : m_aIter(_rRH.m_aIter)
44 , m_pCache(_rRH.m_pCache)
45 ,m_pRowSet(_rRH.m_pRowSet)
46 {
47     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetCacheIterator::ORowSetCacheIterator" );
48 }
49 // -----------------------------------------------------------------------------
50 ORowSetCacheIterator::operator ORowSetMatrix::iterator()
51 {
52 	return m_aIter->second.aIterator;
53 }
54 // -----------------------------------------------------------------------------
55 ORowSetCacheIterator& ORowSetCacheIterator::operator =(const ORowSetCacheIterator& _rRH)
56 {
57 	if(this == &_rRH)
58 		return *this;
59 
60 	m_pCache = _rRH.m_pCache;
61 	m_aIter	 = _rRH.m_aIter;
62 	m_pRowSet = _rRH.m_pRowSet;
63 
64 	return *this;
65 }
66 // -----------------------------------------------------------------------------
67 ORowSetCacheIterator& ORowSetCacheIterator::operator =(const ORowSetMatrix::iterator& _rIter)
68 {
69 	m_aIter->second.aIterator = _rIter;
70 	return *this;
71 }
72 // -----------------------------------------------------------------------------
73 ORowSetRow& ORowSetCacheIterator::operator *()
74 {
75 	return *m_aIter->second.aIterator;
76 }
77 // -----------------------------------------------------------------------------
78 const ORowSetRow& ORowSetCacheIterator::operator *() const
79 {
80 	if ( !m_pRowSet->isInsertRow() && m_aIter->second.aIterator == m_pCache->m_pMatrix->end() )
81 	{
82 		OSL_ENSURE(m_aIter->second.aBookmark.hasValue(),"bookmark has no value!");
83 		OSL_VERIFY(m_pCache->moveToBookmark(m_aIter->second.aBookmark));
84 		m_aIter->second.aIterator = m_pCache->m_aMatrixIter;
85 	}
86 	return *m_aIter->second.aIterator;
87 }
88 // -----------------------------------------------------------------------------
89 ORowSetMatrix::iterator& ORowSetCacheIterator::operator ->()
90 {
91 	return m_aIter->second.aIterator;
92 }
93 // -----------------------------------------------------------------------------
94 const ORowSetMatrix::iterator& ORowSetCacheIterator::operator ->() const
95 {
96 	if ( !m_pRowSet->isInsertRow() && m_aIter->second.aIterator == m_pCache->m_pMatrix->end() )
97 	{
98 		OSL_ENSURE(m_aIter->second.aBookmark.hasValue(),"bookmark has no value!");
99 		OSL_VERIFY(m_pCache->moveToBookmark(m_aIter->second.aBookmark));
100 		m_aIter->second.aIterator = m_pCache->m_aMatrixIter;
101 	}
102 	return m_aIter->second.aIterator;
103 }
104 // -----------------------------------------------------------------------------
105 bool ORowSetCacheIterator::operator <=(const ORowSetMatrix::iterator& _rRH) const
106 {
107 	return m_aIter->second.aIterator <= _rRH;
108 }
109 // -----------------------------------------------------------------------------
110 bool ORowSetCacheIterator::operator <(const ORowSetMatrix::iterator& _rRH) const
111 {
112 	return m_aIter->second.aIterator < _rRH;
113 }
114 // -----------------------------------------------------------------------------
115 bool ORowSetCacheIterator::operator !=(const ORowSetMatrix::iterator& _rRH) const
116 {
117 	return m_aIter->second.aIterator != _rRH;
118 }
119 // -----------------------------------------------------------------------------
120 bool ORowSetCacheIterator::operator ==(const ORowSetMatrix::iterator& _rRH) const
121 {
122 	return m_aIter->second.aIterator == _rRH;
123 }
124 // -----------------------------------------------------------------------------
125 void ORowSetCacheIterator::setBookmark(const ::com::sun::star::uno::Any&	_rBookmark)
126 {
127     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetCacheIterator::setBookmark" );
128 	m_aIter->second.aBookmark = _rBookmark;
129 }
130 // -----------------------------------------------------------------------------
131 sal_Bool ORowSetCacheIterator::isNull() const
132 {
133     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetCacheIterator::isNull" );
134 	sal_Bool bRet = !m_pCache || !m_pRowSet || m_aIter == m_pCache->m_aCacheIterators.end();
135 	if ( !bRet )
136 	{
137 		ORowSetCacheIterator_Helper aHelper = m_aIter->second;
138 		bRet = ( m_pRowSet->isInsertRow()
139 			?
140 			m_aIter->second.aIterator == m_pCache->m_pInsertMatrix->end()
141 			:
142 			m_aIter->second.aIterator == m_pCache->m_pMatrix->end()
143 		);
144 	}
145 	return  bRet;
146 }
147 // -----------------------------------------------------------------------------
148 ::osl::Mutex* ORowSetCacheIterator::getMutex() const
149 {
150     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ORowSetCacheIterator::getMutex" );
151 	return m_pRowSet ? m_pRowSet->getMutex() : NULL;
152 }
153