1 |
|
# |
2 |
|
# This file is part of GNU Enterprise. |
3 |
|
# |
4 |
|
# GNU Enterprise is free software; you can redistribute it |
5 |
|
# and/or modify it under the terms of the GNU General Public |
6 |
|
# License as published by the Free Software Foundation; either |
7 |
|
# version 2, or (at your option) any later version. |
8 |
|
# |
9 |
|
# GNU Enterprise is distributed in the hope that it will be |
10 |
|
# useful, but WITHOUT ANY WARRANTY; without even the implied |
11 |
|
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
12 |
|
# PURPOSE. See the GNU General Public License for more details. |
13 |
|
# |
14 |
|
# You should have received a copy of the GNU General Public |
15 |
|
# License along with program; see the file COPYING. If not, |
16 |
|
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
|
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
|
# |
19 |
|
# Copyright 2000-2003 Free Software Foundation |
20 |
|
# |
21 |
|
# FILE: |
22 |
|
# appserver/DataObject.py |
23 |
|
# |
24 |
|
# DESCRIPTION: |
25 |
|
# Implementation of dbdriver for use with GNUe Application Server. |
26 |
|
# |
27 |
|
# NOTES: |
28 |
|
# |
29 |
|
# HISTORY: |
30 |
|
# |
31 |
|
|
32 |
|
__all__ = ['DataObject'] |
33 |
|
|
34 |
|
from gnue.common.datasources import GConditions, Exceptions |
35 |
|
from gnue.common.datasources.drivers.Base import DataObject as BaseDataObject |
36 |
|
from gnue.common.apps import GDebug |
37 |
|
from gnue.common.rpc import GComm |
38 |
|
|
39 |
|
import string |
40 |
|
import types |
41 |
|
import md5 |
42 |
|
import sys |
43 |
|
|
44 |
|
from ResultSet import * |
45 |
|
|
46 |
|
class DataObject(BaseDataObject): |
47 |
|
|
48 |
|
_resultSetClass = ResultSet |
49 |
|
|
50 |
|
|
51 |
|
def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""): |
52 |
|
# Standardize incomming conditions as a GConditions structre |
53 |
|
if type(conditions) == types.DictType: |
54 |
|
cond = GConditions.buildConditionFromDict(conditions) |
55 |
|
else: |
56 |
|
cond = conditions |
57 |
|
|
58 |
|
# Construct query object |
59 |
|
GDebug.printMesg(7,'Implicit Fields: %s' % self._fieldReferences) |
60 |
|
query = [] |
61 |
|
|
62 |
|
# Add conditionals |
63 |
|
query = GConditions.buildPrefixFromTree(cond._children[0] ) |
64 |
|
|
65 |
|
GDebug.printMesg(7,'Full query in prefix notation: %s' % query) |
66 |
|
|
67 |
|
return query |
68 |
|
|
69 |
|
|
70 |
|
def _createEmptyResultSet(self, readOnly=0, masterRecordSet=None): |
71 |
|
return self.createResultSet(readOnly=readOnly,\ |
72 |
|
conditions=GConditions.GCimpossible,\ |
73 |
|
masterRecordSet=masterRecordSet) |
74 |
|
|
75 |
|
def _createResultSet(self, conditions={}, readOnly=0, |
76 |
|
masterRecordSet=None, sql=""): |
77 |
|
|
78 |
|
GDebug.printMesg (5,"Setting up list object ..."); |
79 |
|
|
80 |
|
sort=[] |
81 |
|
filter=[] |
82 |
|
|
83 |
|
# the fieldnames seem to be stored in _fieldReferences |
84 |
|
fieldlist=self._fieldReferences.keys() |
85 |
|
|
86 |
|
GDebug.printMesg (5,"Using "+str(fieldlist)+" as fieldlist"); |
87 |
|
|
88 |
|
if hasattr(self,"order_by"): |
89 |
|
GDebug.printMesg (5,"Sorting list by fields '"+self.order_by+"'"); |
90 |
|
sort=string.splitfields(self.order_by,",") |
91 |
|
|
92 |
|
try: |
93 |
|
if conditions: |
94 |
|
GDebug.printMesg (5,"Setting Conditions ..."); |
95 |
|
filter = self._buildQuery(conditions) |
96 |
|
except self._connection._DatabaseError, err: |
97 |
|
raise Exceptions.ConnectionError, err |
98 |
|
|
99 |
|
try: |
100 |
|
listcursor = self._dataConnection.request(self.table,filter,sort,fieldlist,\ |
101 |
|
self._dataObject._unicodeMode) |
102 |
|
except Exception, msg: |
103 |
|
tmsg = _("Error during creation of object list \n\n --- %s ---)") % msg |
104 |
|
raise Exceptions.ConnectionError, tmsg |
105 |
|
|
106 |
|
rs = self._resultSetClass(self, cursor=listcursor, masterRecordSet=None) |
107 |
|
|
108 |
|
if readOnly: |
109 |
|
rs._readonly = readOnly |
110 |
|
|
111 |
|
return rs |
112 |
|
|