3 using System.Data.SqlTypes;
7 namespace System.Data.OracleClient {
8 public sealed class OracleLob : Stream, ICloneable, INullable {
11 public static readonly new OracleLob Null = new OracleLob ();
13 internal OracleConnection connection;
14 bool isBatched = false;
26 internal OracleLob () {
30 #endregion // Constructors
34 public override bool CanRead {
35 get { return (IsNull || isOpen); }
38 public override bool CanSeek {
39 get { return (IsNull || isOpen); }
42 public override bool CanWrite {
43 get { return isOpen; }
46 public int ChunkSize {
49 AssertConnectionIsOpen ();
50 AssertObjectNotDisposed ();
51 throw new NotImplementedException ();
55 public OracleConnection Connection {
56 get { return connection; }
59 public bool IsBatched {
60 get { return isBatched; }
64 get { return !notNull; }
67 public bool IsTemporary {
69 AssertConnectionIsOpen ();
70 AssertObjectNotDisposed ();
71 throw new NotImplementedException ();
75 public override long Length {
77 AssertConnectionIsOpen ();
78 AssertObjectNotDisposed ();
79 throw new NotImplementedException ();
83 public OracleType LobType {
87 public override long Position {
89 AssertConnectionIsOpen ();
90 AssertObjectNotDisposed ();
94 AssertConnectionIsOpen ();
95 AssertObjectNotDisposed ();
100 public object Value {
102 AssertObjectNotDisposed ();
106 byte[] buffer = null;
108 int len = (int) Length;
110 // LOB is not Null, but it is Empty
111 if (LobType == OracleType.Clob)
113 else // OracleType.Blob
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);
125 buffer = new byte [len];
126 Read (buffer, 0, len);
132 #endregion // Properties
137 public void Append (OracleLob source) {
139 throw new ArgumentNullException ();
140 if (Connection.State == ConnectionState.Closed)
141 throw new InvalidOperationException ();
142 throw new NotImplementedException ();
145 void AssertAmountIsEven (long amount, string argName) {
147 throw new ArgumentOutOfRangeException ("CLOB and NCLOB parameters require even number of bytes for this argument.");
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);
157 void AssertConnectionIsOpen () {
158 if (connection.State == ConnectionState.Closed)
159 throw new InvalidOperationException ("Invalid operation. The connection is closed.");
162 void AssertObjectNotDisposed () {
164 throw new ObjectDisposedException ("OracleLob");
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 ();
173 public void BeginBatch () {
174 BeginBatch (OracleLobOpenMode.ReadOnly);
177 public void BeginBatch (OracleLobOpenMode mode) {
178 AssertConnectionIsOpen ();
179 AssertObjectNotDisposed ();
185 public object Clone () {
186 throw new NotImplementedException ();
190 public override void Close () {
194 public long CopyTo (OracleLob destination) {
195 return CopyTo (0, destination, 0, Length);
198 public long CopyTo (OracleLob destination, long destinationOffset) {
199 return CopyTo (0, destination, destinationOffset, Length);
202 public long CopyTo (long sourceOffset, OracleLob destination, long destinationOffset, long amount) {
203 if (destination.IsNull)
204 throw new ArgumentNullException ();
206 AssertAmountIsValid (sourceOffset, "sourceOffset");
207 AssertAmountIsValid (destinationOffset, "destinationOffset");
208 AssertAmountIsValid (amount, "amount");
209 AssertTransactionExists ();
210 AssertConnectionIsOpen ();
212 throw new NotImplementedException ();
216 public void Dispose () {
217 throw new NotImplementedException ();
220 public void EndBatch () {
221 AssertConnectionIsOpen ();
222 AssertObjectNotDisposed ();
227 public long Erase () {
228 return Erase (0, Length);
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 ();
237 AssertAmountIsValid (offset, "offset");
238 AssertAmountIsValid (amount, "amount");
240 throw new NotImplementedException ();
243 public override void Flush () {
247 public override int Read (byte[] buffer, int offset, int count) {
249 throw new ArgumentNullException ();
251 AssertAmountIsValid (offset, "offset");
252 AssertAmountIsValid (count, "count");
253 AssertConnectionIsOpen ();
254 AssertObjectNotDisposed ();
256 throw new NotImplementedException ();
259 byte[] output = new byte[count];
261 output.CopyTo (buffer, offset);
262 position += bytesRead;
267 public override long Seek (long offset, SeekOrigin origin) {
268 long newPosition = position;
271 case SeekOrigin.Begin:
272 newPosition = offset;
274 case SeekOrigin.Current:
275 newPosition += offset;
278 newPosition = Length + offset;
282 if (newPosition > Length)
283 throw new ArgumentOutOfRangeException ();
285 position = newPosition;
290 public override void SetLength (long value) {
291 AssertAmountIsValid (value, "value");
292 AssertTransactionExists ();
293 AssertConnectionIsOpen ();
294 AssertObjectNotDisposed ();
296 throw new NotImplementedException ();
301 public override void Write (byte[] buffer, int offset, int count) {
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 ();
315 if (offset + count == buffer.Length && offset == 0)
318 value = new byte[count];
319 Array.Copy (buffer, offset, value, 0, count);
322 throw new NotImplementedException ();
324 // position += locator.Write (value, (uint) Position, (uint) value.Length, LobType);
327 #endregion // Methods