2003-10-16 Pedro Mart�nez Juli� <yoros@wanadoo.es>
[mono.git] / mcs / class / Npgsql / Npgsql / NpgsqlMediator.cs
1 // created on 30/7/2002 at 00:31
2
3 // Npgsql.NpgsqlMediator.cs
4 // 
5 // Author:
6 //      Francisco Jr. (fxjrlists@yahoo.com.br)
7 //
8 //      Copyright (C) 2002 The Npgsql Development Team
9 //      npgsql-general@gborg.postgresql.org
10 //      http://gborg.postgresql.org/project/npgsql/projdisplay.php
11 //
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
16 // 
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 // Lesser General Public License for more details.
21 // 
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26 using System;
27 using System.Text;
28 using System.Collections;
29
30 namespace Npgsql
31 {
32         ///<summary>
33         /// This class is responsible for serving as bridge between the backend 
34         /// protocol handling and the core classes. It is used as the mediator for
35         /// exchanging data generated/sent from/to backend.
36         /// </summary>
37         /// 
38         
39         internal sealed class NpgsqlMediator
40         {
41                 private ArrayList                                                       _errorMessages;
42                 private ArrayList                                                       _resultSets;
43                 private ArrayList                                                       _responses;
44           private ArrayList             _notifications;
45                 
46                 private NpgsqlRowDescription    _rd;
47                 private ArrayList                                                       _rows;
48                 
49                 
50                 public NpgsqlMediator()
51                 {
52                         _errorMessages = new ArrayList();
53                         _resultSets = new ArrayList();
54                         _responses = new ArrayList();
55                   _notifications = new ArrayList();
56                 }
57                                                 
58                 public void Reset()
59                 {
60                         _errorMessages.Clear();
61                         _resultSets.Clear();
62                         _responses.Clear();
63                   _notifications.Clear();
64                         _rd = null;
65                 }
66                 
67                 public ArrayList Errors
68                 {
69                         get
70                         {
71                                 return _errorMessages;
72                         }
73                 }
74                 
75                 public ArrayList Notifications
76                 {
77                   get
78                   {
79                     return _notifications;
80                   }
81                   
82                 }
83                 
84                 public void AddNotification(NpgsqlNotificationEventArgs data)
85                 {
86                   _notifications.Add(data);
87                 }
88  
89
90                 
91                 public void AddCompletedResponse(String response)
92                 {
93                         if (_rd != null)
94                         {
95                                 // Finished receiving the resultset. Add it to the buffer.
96                                 _resultSets.Add(new NpgsqlResultSet(_rd, _rows));
97                                 
98                                 // Add a placeholder response.
99                                 _responses.Add(null);
100                                 
101                                 // Discard the RowDescription.
102                                 _rd = null;
103                         }
104                         else
105                         {
106                                 // Add a placeholder resultset.
107                                 _resultSets.Add(null);
108                                 // It was just a non query string. Just add the response.
109                                 _responses.Add(response);
110                         }
111                                                 
112                 }
113                 
114                 public void AddRowDescription(NpgsqlRowDescription rowDescription)
115                 {
116                         _rd = rowDescription;
117                         _rows = new ArrayList();
118                 }
119                 
120                 public void AddAsciiRow(NpgsqlAsciiRow asciiRow)
121                 {
122                         _rows.Add(asciiRow);
123                 }
124                 
125                 public void AddBinaryRow(NpgsqlBinaryRow asciiRow)
126                 {
127                         _rows.Add(asciiRow);
128                 }
129                 
130                 
131                 public void AddBackendKeydata(NpgsqlBackEndKeyData keydata)
132                 {
133                         _responses.Add(keydata);        //hack  
134                 }
135                 
136                 public ArrayList GetResultSets()
137                 {
138                         return _resultSets;
139                 }
140                 
141                 public ArrayList GetCompletedResponses()
142                 {
143                         return _responses;
144                 }
145                 
146                 public NpgsqlBackEndKeyData GetBackEndKeyData()
147                 {
148                         return (NpgsqlBackEndKeyData)_responses[0];     //hack
149                 }
150                 
151                 
152         }
153 }