1 // created on 30/7/2002 at 00:31
3 // Npgsql.NpgsqlMediator.cs
6 // Francisco Jr. (fxjrlists@yahoo.com.br)
8 // Copyright (C) 2002 The Npgsql Development Team
9 // npgsql-general@gborg.postgresql.org
10 // http://gborg.postgresql.org/project/npgsql/projdisplay.php
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.
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.
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
28 using System
.Collections
;
29 using System
.Collections
.Specialized
;
34 /// This class is responsible for serving as bridge between the backend
35 /// protocol handling and the core classes. It is used as the mediator for
36 /// exchanging data generated/sent from/to backend.
39 internal sealed class NpgsqlMediator
42 // Expectations that depend on context.
43 // Non-default values must be set before collecting responses.
45 // Some kinds of messages only get one response, and do not
46 // expect a ready_for_query response.
47 private bool _require_ready_for_query
;
50 // Responses collected from the backend.
52 private ArrayList _errors
;
53 private ArrayList _notices
;
54 private ArrayList _resultSets
;
55 private ArrayList _responses
;
56 private ArrayList _notifications
;
57 private ListDictionary _parameters
;
58 private NpgsqlBackEndKeyData _backend_key_data
;
59 private NpgsqlRowDescription _rd
;
60 private ArrayList _rows
;
62 public NpgsqlMediator()
64 _require_ready_for_query
= true;
66 _errors
= new ArrayList();
67 _notices
= new ArrayList();
68 _resultSets
= new ArrayList();
69 _responses
= new ArrayList();
70 _notifications
= new ArrayList();
71 _parameters
= new ListDictionary(CaseInsensitiveComparer
.Default
);
72 _backend_key_data
= null;
75 public void ResetExpectations()
77 _require_ready_for_query
= true;
80 public void ResetResponses()
86 _notifications
.Clear();
88 _backend_key_data
= null;
94 public Boolean RequireReadyForQuery
98 return _require_ready_for_query
;
102 _require_ready_for_query
= value;
108 public NpgsqlRowDescription LastRowDescription
116 public ArrayList ResultSets
124 public ArrayList CompletedResponses
132 public ArrayList Errors
140 public ArrayList Notices
148 public ArrayList Notifications
152 return _notifications
;
156 public ListDictionary Parameters
164 public NpgsqlBackEndKeyData BackendKeyData
168 return _backend_key_data
;
172 public void AddNotification(NpgsqlNotificationEventArgs data
)
174 _notifications
.Add(data
);
177 public void AddCompletedResponse(String response
)
181 // Finished receiving the resultset. Add it to the buffer.
182 _resultSets
.Add(new NpgsqlResultSet(_rd
, _rows
));
184 // Add a placeholder response.
185 _responses
.Add(null);
187 // Discard the RowDescription.
192 // Add a placeholder resultset.
193 _resultSets
.Add(null);
194 // It was just a non query string. Just add the response.
195 _responses
.Add(response
);
200 public void AddRowDescription(NpgsqlRowDescription rowDescription
)
202 _rd
= rowDescription
;
203 _rows
= new ArrayList();
206 public void AddAsciiRow(NpgsqlAsciiRow asciiRow
)
211 public void AddBinaryRow(NpgsqlBinaryRow binaryRow
)
213 _rows
.Add(binaryRow
);
217 public void SetBackendKeydata(NpgsqlBackEndKeyData keydata
)
219 _backend_key_data
= keydata
;
222 public void AddParameterStatus(String Key
, NpgsqlParameterStatus PS
)
224 _parameters
[Key
] = PS
;