They are system endpoints.
[mono.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient.jvm / OracleLob.cs
1
2 using System;
3 using System.Data.SqlTypes;
4 using System.IO;
5 using System.Text;
6
7 namespace System.Data.OracleClient {
8         public sealed class OracleLob : Stream, ICloneable, INullable {
9                 #region Fields
10
11                 public static readonly new OracleLob Null = new OracleLob ();
12
13                 internal OracleConnection connection;
14                 bool isBatched = false;
15                 bool isOpen = true;
16                 bool notNull = false;
17                 OracleType type;
18
19                 long length = -1;
20                 long position = 0;
21
22                 #endregion // Fields
23
24                 #region Constructors
25
26                 internal OracleLob () {
27                 }
28
29
30                 #endregion // Constructors
31
32                 #region Properties
33
34                 public override bool CanRead {
35                         get { return (IsNull || isOpen); }
36                 }
37
38                 public override bool CanSeek {
39                         get { return (IsNull || isOpen); }
40                 }
41
42                 public override bool CanWrite {
43                         get { return isOpen; }
44                 }
45
46                 public int ChunkSize {
47                         [MonoTODO]
48                         get { 
49                                 AssertConnectionIsOpen ();
50                                 AssertObjectNotDisposed ();
51                                 throw new NotImplementedException ();
52                         }
53                 }
54
55                 public OracleConnection Connection {
56                         get { return connection; }
57                 }
58
59                 public bool IsBatched {
60                         get { return isBatched; }
61                 }
62
63                 public bool IsNull {
64                         get { return !notNull; }
65                 }
66
67                 public bool IsTemporary {
68                         get { 
69                                 AssertConnectionIsOpen ();
70                                 AssertObjectNotDisposed ();
71                                 throw new NotImplementedException ();
72                         }
73                 }
74
75                 public override long Length {
76                         get { 
77                                 AssertConnectionIsOpen ();
78                                 AssertObjectNotDisposed ();
79                                 throw new NotImplementedException ();
80                         }
81                 }
82
83                 public OracleType LobType {
84                         get { return type; }
85                 }
86
87                 public override long Position {
88                         get { 
89                                 AssertConnectionIsOpen ();
90                                 AssertObjectNotDisposed ();
91                                 return position;
92                         }
93                         set {
94                                 AssertConnectionIsOpen ();
95                                 AssertObjectNotDisposed ();
96                                 position = value;
97                         }
98                 }
99
100                 public object Value {
101                         get { 
102                                 AssertObjectNotDisposed ();
103                                 if (IsNull)
104                                         return DBNull.Value;
105                                 
106                                 byte[] buffer = null;
107
108                                 int len = (int) Length;
109                                 if (len == 0) {
110                                         // LOB is not Null, but it is Empty
111                                         if (LobType == OracleType.Clob)
112                                                 return "";
113                                         else // OracleType.Blob
114                                                 return new byte[0];
115                                 }
116
117                                 if (LobType == OracleType.Clob) {
118                                         buffer = new byte [len];
119                                         Read (buffer, 0, len);
120                                         UnicodeEncoding encoding = new UnicodeEncoding ();
121                                         return encoding.GetString (buffer);
122                                 }
123                                 else {
124                                         // OracleType.Blob
125                                         buffer = new byte [len];
126                                         Read (buffer, 0, len);
127                                         return buffer;
128                                 }
129                         }
130                 }
131
132                 #endregion // Properties
133
134                 #region Methods
135
136                 [MonoTODO]
137                 public void Append (OracleLob source) {
138                         if (source.IsNull)
139                                 throw new ArgumentNullException ();
140                         if (Connection.State == ConnectionState.Closed)
141                                 throw new InvalidOperationException ();
142                         throw new NotImplementedException ();
143                 }
144
145                 void AssertAmountIsEven (long amount, string argName) {
146                         if (amount % 2 == 1)
147                                 throw new ArgumentOutOfRangeException ("CLOB and NCLOB parameters require even number of bytes for this argument.");
148                 }
149
150                 void AssertAmountIsValid (long amount, string argName) {
151                         if (amount > UInt32.MaxValue)
152                                 throw new ArgumentOutOfRangeException ("Argument too big.");
153                         if (LobType == OracleType.Clob || LobType == OracleType.NClob)
154                                 AssertAmountIsEven (amount, argName);
155                 }
156
157                 void AssertConnectionIsOpen () {
158                         if (connection.State == ConnectionState.Closed)
159                                 throw new InvalidOperationException ("Invalid operation. The connection is closed.");
160                 }
161
162                 void AssertObjectNotDisposed () {
163                         if (!isOpen)
164                                 throw new ObjectDisposedException ("OracleLob");
165                 }
166
167                 void AssertTransactionExists () {
168 //                      if (connection.Transaction == null)
169 //                              throw new InvalidOperationException ("Modifying a LOB requires that the connection be transacted.");
170                         throw new NotImplementedException ();
171                 }
172
173                 public void BeginBatch () {
174                         BeginBatch (OracleLobOpenMode.ReadOnly);
175                 }
176
177                 public void BeginBatch (OracleLobOpenMode mode) {
178                         AssertConnectionIsOpen ();
179                         AssertObjectNotDisposed ();
180
181                         isBatched = true;
182                 }
183
184                 [MonoTODO]
185                 public object Clone () {
186                         throw new NotImplementedException ();
187                 }
188
189                 [MonoTODO]
190                 public override void Close () {
191                         isOpen = false;
192                 }
193
194                 public long CopyTo (OracleLob destination) {
195                         return CopyTo (0, destination, 0, Length);
196                 }
197
198                 public long CopyTo (OracleLob destination, long destinationOffset) {
199                         return CopyTo (0, destination, destinationOffset, Length);
200                 }
201
202                 public long CopyTo (long sourceOffset, OracleLob destination, long destinationOffset, long amount) {
203                         if (destination.IsNull)
204                                 throw new ArgumentNullException ();
205
206                         AssertAmountIsValid (sourceOffset, "sourceOffset");
207                         AssertAmountIsValid (destinationOffset, "destinationOffset");
208                         AssertAmountIsValid (amount, "amount");
209                         AssertTransactionExists ();
210                         AssertConnectionIsOpen ();
211
212                         throw new NotImplementedException ();
213                 }
214
215                 [MonoTODO]
216                 public void Dispose () {
217                         throw new NotImplementedException ();
218                 }
219
220                 public void EndBatch () {
221                         AssertConnectionIsOpen ();
222                         AssertObjectNotDisposed ();
223
224                         isBatched = false;
225                 }
226
227                 public long Erase () {
228                         return Erase (0, Length);
229                 }
230
231                 public long Erase (long offset, long amount) {
232                         if (offset < 0 || amount < 0)
233                                 throw new ArgumentOutOfRangeException ("Must be a positive value.");
234                         if (offset + amount > Length)
235                                 throw new ArgumentOutOfRangeException ();
236
237                         AssertAmountIsValid (offset, "offset");
238                         AssertAmountIsValid (amount, "amount");
239
240                         throw new NotImplementedException ();
241                 }
242
243                 public override void Flush () {
244                         // No-op
245                 }
246
247                 public override int Read (byte[] buffer, int offset, int count) {
248                         if (buffer == null)
249                                 throw new ArgumentNullException ();
250
251                         AssertAmountIsValid (offset, "offset");
252                         AssertAmountIsValid (count, "count");
253                         AssertConnectionIsOpen ();
254                         AssertObjectNotDisposed ();
255
256                         throw new NotImplementedException ();
257
258                         int bytesRead;
259                         byte[] output = new byte[count];
260
261                         output.CopyTo (buffer, offset);
262                         position += bytesRead;
263                         return bytesRead;
264                 }
265
266                 [MonoTODO]
267                 public override long Seek (long offset, SeekOrigin origin) {
268                         long newPosition = position;
269
270                         switch (origin) {
271                                 case SeekOrigin.Begin:
272                                         newPosition = offset;
273                                         break;
274                                 case SeekOrigin.Current:
275                                         newPosition += offset;
276                                         break;
277                                 case SeekOrigin.End:
278                                         newPosition = Length + offset;
279                                         break;
280                         }
281
282                         if (newPosition > Length)
283                                 throw new ArgumentOutOfRangeException ();
284
285                         position = newPosition;
286                         return position;
287                 }
288
289                 [MonoTODO]
290                 public override void SetLength (long value) {
291                         AssertAmountIsValid (value, "value");
292                         AssertTransactionExists ();
293                         AssertConnectionIsOpen ();
294                         AssertObjectNotDisposed ();
295
296                         throw new NotImplementedException ();
297
298                         length = value;
299                 }
300
301                 public override void Write (byte[] buffer, int offset, int count) {
302                         if (buffer == null)
303                                 throw new ArgumentNullException ("Buffer is null.");
304                         if (offset < 0 || count < 0)
305                                 throw new ArgumentOutOfRangeException ("Must be a positive value.");
306                         if (offset + count > buffer.Length)
307                                 throw new ArgumentOutOfRangeException ("The offset and count values specified exceed the buffer provided.");
308                         AssertAmountIsValid (offset, "offset");
309                         AssertAmountIsValid (count, "count");
310                         AssertTransactionExists ();
311                         AssertConnectionIsOpen ();
312                         AssertObjectNotDisposed ();
313
314                         byte[] value = null;
315                         if (offset + count == buffer.Length && offset == 0)
316                                 value = buffer;
317                         else {
318                                 value = new byte[count];
319                                 Array.Copy (buffer, offset, value, 0, count);
320                         }
321
322                         throw new NotImplementedException ();
323
324 //                      position += locator.Write (value, (uint) Position, (uint) value.Length, LobType);
325                 }
326
327                 #endregion // Methods
328         }
329 }