ImplicitCollectionIterator.cpp 2.16 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/

#include "ImplicitCollectionIterator.h"
#include "CollectionBase/CollectionDescription.h"

#include "PersistencySvc/IContainer.h"
#include "PersistencySvc/ITokenIterator.h"

#include "PersistentDataModel/Token.h"

pool::ImplicitCollectionIterator::
ImplicitCollectionIterator( pool::IContainer& container,
                            const pool::ICollectionDescription& description )
      :
      m_container( container ),
      m_tokenIterator( 0 ),
      m_token( 0 )
{
   TokenList        tokenList;
   tokenList.extend( description.eventReferenceColumnName() );
   m_rowBuffer.setTokenList( tokenList );
}


pool::ImplicitCollectionIterator::~ImplicitCollectionIterator()
{
  if ( m_token ) m_token->release();
  delete m_tokenIterator;
}


void
pool::ImplicitCollectionIterator::
setCondition( const std::string& whereClause,
              coral::AttributeList*,
              TokenList* )
{
   m_whereClause += whereClause;
}


pool::ICollectionCursor&
pool::ImplicitCollectionIterator::execute()
{
   m_tokenIterator = m_container.tokens( m_whereClause );
   return *this;
}



const std::string&
pool::ImplicitCollectionIterator::whereClause() const
{
  return m_whereClause;
}



bool
pool::ImplicitCollectionIterator::next()
{
   if( m_token ) {
      m_token->release();
      m_token = 0;
   }
   if( m_tokenIterator )
      m_token = m_tokenIterator->next();
   return (m_token!=0);
}

Token*
pool::ImplicitCollectionIterator::token() const
{
  return m_token;
}

const pool::CollectionRowBuffer&
pool::ImplicitCollectionIterator::currentRow() const
{
   m_token->setData( &*m_rowBuffer.tokenList().begin() );
   return m_rowBuffer;
}


bool
pool::ImplicitCollectionIterator::seek (long long int position)
{
  IPositionSeek* ies = dynamic_cast<IPositionSeek*> (m_tokenIterator);
  if (!ies)
    return false;
  // We'll have to do a next() to read the event.
  // So subtract one here to compensate for that.
  return ies->seek (position - 1);
}


int
pool::ImplicitCollectionIterator::size ()
{
  ICollectionSize* ics = dynamic_cast<ICollectionSize*> (m_tokenIterator);
  if (!ics)
    return 0;
  return ics->size();
}