~ubuntu-branches/ubuntu/hardy/gnue-common/hardy

« back to all changes in this revision

Viewing changes to src/datasources/drivers/appserver/appserver/ResultSet.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-03-09 11:06:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050309110631-8gvvn39q7tjz1kj6
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# GNU Enterprise Datasource Library - Driver for GNUe-AppServer
 
2
#
 
3
# Copyright 2000-2005 Free Software Foundation
 
4
#
 
5
# This file is part of GNU Enterprise.
 
6
#
 
7
# GNU Enterprise is free software; you can redistribute it
 
8
# and/or modify it under the terms of the GNU General Public
 
9
# License as published by the Free Software Foundation; either
 
10
# version 2, or (at your option) any later version.
 
11
#
 
12
# GNU Enterprise is distributed in the hope that it will be
 
13
# useful, but WITHOUT ANY WARRANTY; without even the implied
 
14
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 
15
# PURPOSE. See the GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public
 
18
# License along with program; see the file COPYING. If not,
 
19
# write to the Free Software Foundation, Inc., 59 Temple Place
 
20
# - Suite 330, Boston, MA 02111-1307, USA.
 
21
#
 
22
# $Id: ResultSet.py 6851 2005-01-03 20:59:28Z jcater $
 
23
 
 
24
from gnue.common.datasources.drivers import Base
 
25
 
 
26
import RecordSet
 
27
 
 
28
# =============================================================================
 
29
# ResultSet class
 
30
# =============================================================================
 
31
 
 
32
class ResultSet (Base.ResultSet):
 
33
  """
 
34
  Handles a resultset (i.e. a list) in the GNUe-AppServer backend.
 
35
  """
 
36
  # This is actually never used
 
37
  _recordSetClass = RecordSet.RecordSet
 
38
 
 
39
  # ---------------------------------------------------------------------------
 
40
  # Initialization
 
41
  # ---------------------------------------------------------------------------
 
42
 
 
43
  def __init__ (self, dataObject, sm, session_id, list_id, classname,
 
44
                fieldlist, fetchcount, readOnly, masterRecordSet):
 
45
 
 
46
    Base.ResultSet.__init__ (self, dataObject,
 
47
                             masterRecordSet = masterRecordSet)
 
48
    self._readOnly = readOnly
 
49
 
 
50
    self.__sm = sm
 
51
    self.__session_id = session_id
 
52
    self.__list_id = list_id
 
53
    self.__classname = classname
 
54
    self.__fieldlist = fieldlist
 
55
    self.__fetchcount = fetchcount
 
56
 
 
57
    if self.__list_id:
 
58
      self.__position = 0               # current fetch position in resultset
 
59
      self._recordCount = self.__sm.count (self.__session_id, self.__list_id)
 
60
    else:
 
61
      # Empty result set
 
62
      self.__position = -1
 
63
      self._recordCount = 0
 
64
 
 
65
  # ---------------------------------------------------------------------------
 
66
  # Fetch next records
 
67
  # ---------------------------------------------------------------------------
 
68
 
 
69
  def _loadNextRecord (self):
 
70
 
 
71
    if self.__position == -1:
 
72
      return False
 
73
 
 
74
    records = self.__sm.fetch (self.__session_id,
 
75
                               self.__list_id,
 
76
                               self.__position,
 
77
                               self.__fetchcount)
 
78
    if not records:
 
79
      self.__position = -1
 
80
      return False
 
81
 
 
82
    if len (records) < self.__fetchcount:
 
83
      self.__position = -1
 
84
    else:
 
85
      self.__position += len (records)
 
86
 
 
87
    for record in records:
 
88
      dict = {}
 
89
      j = 0
 
90
      for fieldName in ['gnue_id'] + self.__fieldlist:
 
91
        dict [fieldName] = record [j]
 
92
        j += 1
 
93
 
 
94
      r = RecordSet.RecordSet (self, self.__sm, self.__session_id,
 
95
                               self.__classname, dict)
 
96
      self._cachedRecords.append (r)
 
97
 
 
98
    return True
 
99
 
 
100
  # ---------------------------------------------------------------------------
 
101
  # Create an empty record
 
102
  # ---------------------------------------------------------------------------
 
103
 
 
104
  def _createEmptyRecord (self):
 
105
    return RecordSet.RecordSet (self, self.__sm, self.__session_id,
 
106
                                self.__classname)