001: /*
002:
003: Derby - Class org.apache.derby.iapi.types.DataValueFactory
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.types;
023:
024: import org.apache.derby.iapi.types.RowLocation;
025:
026: import org.apache.derby.iapi.error.StandardException;
027:
028: import java.sql.Date;
029: import java.sql.Time;
030: import java.sql.Timestamp;
031:
032: /**
033: * This interface is how we get constant data values of different types.
034: */
035:
036: public interface DataValueFactory {
037: /**
038: * Get a SQL int with the given value. A null argument means get
039: * a SQL null value. The second form uses the previous value (if non-null)
040: * to hold the return value.
041: *
042: */
043: NumberDataValue getDataValue(Integer value);
044:
045: NumberDataValue getDataValue(Integer value, NumberDataValue previous)
046: throws StandardException;
047:
048: /**
049: * Get a SQL int with a char value. A null argument means get
050: * a SQL null value. The second form uses the previous value (if non-null)
051: * to hold the return value.
052: *
053: */
054: public NumberDataValue getDataValue(char value);
055:
056: public NumberDataValue getDataValue(char value,
057: NumberDataValue previous) throws StandardException;
058:
059: /**
060: * Get a SQL smallint with the given value. A null argument means get
061: * a SQL null value. The second form uses the previous value (if non-null)
062: * to hold the return value.
063: *
064: */
065: NumberDataValue getDataValue(Short value);
066:
067: NumberDataValue getDataValue(Short value, NumberDataValue previous)
068: throws StandardException;
069:
070: /**
071: * Get a SQL TINYINT with the given value. A null argument means get
072: * a SQL null value. The second form uses the previous value (if non-null)
073: * to hold the return value.
074: *
075: */
076: NumberDataValue getDataValue(Byte value);
077:
078: NumberDataValue getDataValue(Byte value, NumberDataValue previous)
079: throws StandardException;
080:
081: /**
082: * Get a SQL bigint with the given value. A null argument means get
083: * a SQL null value. The second form uses the previous value (if non-null)
084: * to hold the return value.
085: *
086: */
087: NumberDataValue getDataValue(Long value);
088:
089: NumberDataValue getDataValue(Long value, NumberDataValue previous)
090: throws StandardException;
091:
092: /**
093: * Get a SQL real with the given value. A null argument means get
094: * a SQL null value. The second form uses the previous value (if non-null)
095: * to hold the return value.
096: *
097: */
098: NumberDataValue getDataValue(Float value) throws StandardException;
099:
100: NumberDataValue getDataValue(Float value, NumberDataValue previous)
101: throws StandardException;
102:
103: /**
104: * Get a SQL double precision with the given value. A null argument means
105: * a SQL null value. The second form uses the previous value (if non-null)
106: * to hold the return value.
107: *
108: * @exception StandardException Thrown on error
109: */
110: NumberDataValue getDataValue(Double value) throws StandardException;
111:
112: NumberDataValue getDataValue(Double value, NumberDataValue previous)
113: throws StandardException;
114:
115: /**
116: * Get a SQL boolean with the given value. A null argument means get
117: * a SQL null value. The second form uses the previous value (if non-null)
118: * to hold the return value.
119: *
120: */
121: BooleanDataValue getDataValue(Boolean value);
122:
123: BooleanDataValue getDataValue(Boolean value,
124: BooleanDataValue previous) throws StandardException;
125:
126: // ------ LONGVARBIT
127:
128: /**
129: * Get a SQL Long Bit Varying with the given value. A null argument means
130: * get a SQL null value. The second form uses the previous value (if
131: * non-null) to hold the return value.
132: *
133: * @exception StandardException Thrown on error
134: */
135: BitDataValue getLongVarbitDataValue(byte[] value)
136: throws StandardException;
137:
138: BitDataValue getLongVarbitDataValue(byte[] value,
139: BitDataValue previous) throws StandardException;
140:
141: // ------ BLOB
142:
143: /**
144: * Get a SQL Blob with the given value. A null argument means
145: * get a SQL null value. The second form uses the previous value (if
146: * non-null) to hold the return value.
147: *
148: * @exception StandardException Thrown on error
149: */
150: BitDataValue getBlobDataValue(byte[] value)
151: throws StandardException;
152:
153: BitDataValue getBlobDataValue(byte[] value, BitDataValue previous)
154: throws StandardException;
155:
156: // ------ BOOLEAN
157: /**
158: * Get a SQL boolean with the given value. A null argument means get
159: * a SQL null value. The second form uses the previous value (if non-null)
160: * to hold the return value.
161: *
162: * @exception StandardException Thrown on error
163: */
164: BooleanDataValue getDataValue(BooleanDataValue value)
165: throws StandardException;
166:
167: /**
168: * Get a SQL varchar with the given value. A null argument means get
169: * a SQL null value. The second form uses the previous value (if non-null)
170: * to hold the return value.
171: *
172: */
173: StringDataValue getVarcharDataValue(String value);
174:
175: StringDataValue getVarcharDataValue(String value,
176: StringDataValue previous) throws StandardException;
177:
178: /**
179: * Get a SQL long varchar with the given value. A null argument means
180: * get a SQL null value. The second form uses the previous value
181: * (if non-null) to hold the return value.
182: *
183: */
184: StringDataValue getLongvarcharDataValue(String value);
185:
186: StringDataValue getLongvarcharDataValue(String value,
187: StringDataValue previous) throws StandardException;
188:
189: /**
190: * Get a SQL Clob with the given value. A null argument means
191: * get a SQL null value. The second form uses the previous value
192: * (if non-null) to hold the return value.
193: *
194: */
195: StringDataValue getClobDataValue(String value);
196:
197: StringDataValue getClobDataValue(String value,
198: StringDataValue previous) throws StandardException;
199:
200: /**
201: * Get a SQL national varchar with the given value. A null argument means get
202: * a SQL null value. The second form uses the previous value (if non-null)
203: * to hold the return value.
204: */
205: StringDataValue getNationalVarcharDataValue(String value);
206:
207: StringDataValue getNationalVarcharDataValue(String value,
208: StringDataValue previous) throws StandardException;
209:
210: /**
211: * Get a SQL national long varchar with the given value. A null argument means
212: * get a SQL null value. The second form uses the previous value
213: * (if non-null) to hold the return value.
214: */
215: StringDataValue getNationalLongvarcharDataValue(String value);
216:
217: StringDataValue getNationalLongvarcharDataValue(String value,
218: StringDataValue previous) throws StandardException;
219:
220: /**
221: * Get a SQL national blob with the given value. A null argument means
222: * get a SQL null value. The second form uses the previous value
223: * (if non-null) to hold the return value.
224: */
225: StringDataValue getNClobDataValue(String value);
226:
227: StringDataValue getNClobDataValue(String value,
228: StringDataValue previous) throws StandardException;
229:
230: /**
231: * Get a User-defined data value with the given value and type name.
232: * A null argument means get a SQL null value. The second form uses
233: * the previous value (if non-null) hold the return value.
234: *
235: */
236: UserDataValue getDataValue(Object value);
237:
238: UserDataValue getDataValue(Object value, UserDataValue previous);
239:
240: /**
241: * Get a RefDataValue with the given value. A null argument means get
242: * a SQL null value. The second form uses the previous value (if non-null)
243: * to hold the return value.
244: *
245: */
246: RefDataValue getDataValue(RowLocation value);
247:
248: RefDataValue getDataValue(RowLocation value, RefDataValue previous);
249:
250: /**
251: * Get a SQL int with the given value. The second form re-uses the
252: * previous value, if non-null, as the data holder to return.
253: *
254: */
255: NumberDataValue getDataValue(int value);
256:
257: NumberDataValue getDataValue(int value, NumberDataValue previous)
258: throws StandardException;
259:
260: /**
261: * Get a SQL bigint with the given value. The second form re-uses the
262: * previous value, if non-null, as the data holder to return.
263: *
264: */
265: NumberDataValue getDataValue(long value);
266:
267: NumberDataValue getDataValue(long value, NumberDataValue previous)
268: throws StandardException;
269:
270: /**
271: * Get a SQL real with the given value. The second form
272: * re-uses the previous value, if non-null, as the data holder to return.
273: *
274: * @exception StandardException Thrown on error
275: */
276: NumberDataValue getDataValue(float value) throws StandardException;
277:
278: NumberDataValue getDataValue(float value, NumberDataValue previous)
279: throws StandardException;
280:
281: /**
282: * Get a SQL double precision with the given value. The second form
283: * re-uses the previous value, if non-null, as the data holder to return.
284: *
285: * @exception StandardException Thrown on error
286: */
287: NumberDataValue getDataValue(double value) throws StandardException;
288:
289: NumberDataValue getDataValue(double value, NumberDataValue previous)
290: throws StandardException;
291:
292: /**
293: * Get a SQL SMALLINT with the given value. The second form re-uses the
294: * previous value, if non-null, as the data holder to return.
295: *
296: */
297: NumberDataValue getDataValue(short value);
298:
299: NumberDataValue getDataValue(short value, NumberDataValue previous)
300: throws StandardException;
301:
302: /**
303: * Get a SQL TINYINT with the given value. The second form re-uses the
304: * previous value, if non-null, as the data holder to return.
305: *
306: */
307: NumberDataValue getDataValue(byte value);
308:
309: NumberDataValue getDataValue(byte value, NumberDataValue previous)
310: throws StandardException;
311:
312: /**
313: * Get a SQL DECIMAL with the given value. The second form re-uses the
314: * previous value, if non-null, as the data holder to return.
315: *
316: * @exception StandardException Thrown on error
317: */
318: NumberDataValue getDecimalDataValue(Number value)
319: throws StandardException;
320:
321: NumberDataValue getDecimalDataValue(Number value,
322: NumberDataValue previous) throws StandardException;
323:
324: /**
325: * Get a SQL DECIMAL with the given value.
326: *
327: * @exception StandardException Thrown on error
328: */
329: NumberDataValue getDecimalDataValue(Long value,
330: NumberDataValue previous) throws StandardException;
331:
332: /**
333: * Get a SQL DECIMAL with the given value. The second form re-uses the
334: * previous value, if non-null, as the data holder to return.
335: *
336: * @exception StandardException Thrown on error
337: */
338: NumberDataValue getDecimalDataValue(String value)
339: throws StandardException;
340:
341: NumberDataValue getDecimalDataValue(String value,
342: NumberDataValue previous) throws StandardException;
343:
344: /**
345: * Get a SQL boolean with the given value. The second form re-uses the
346: * previous value, if non-null, as the data holder to return.
347: *
348: */
349: BooleanDataValue getDataValue(boolean value);
350:
351: BooleanDataValue getDataValue(boolean value,
352: BooleanDataValue previous) throws StandardException;
353:
354: /**
355: * Get a SQL bit with the given value. The second form re-uses the
356: * previous value, if non-null, as the data holder to return.
357: *
358: * @exception StandardException Thrown on error
359: */
360: BitDataValue getBitDataValue(byte[] value) throws StandardException;
361:
362: BitDataValue getBitDataValue(byte[] value, BitDataValue previous)
363: throws StandardException;
364:
365: /**
366: * Get a SQL bit with the given value. The second form re-uses the
367: * previous value, if non-null, as the data holder to return.
368: *
369: * @exception StandardException Thrown on error
370: */
371: BitDataValue getVarbitDataValue(byte[] value)
372: throws StandardException;
373:
374: BitDataValue getVarbitDataValue(byte[] value, BitDataValue previous)
375: throws StandardException;
376:
377: /**
378: * Get a SQL char with the given value. A null argument means get
379: * a SQL null value. The second form re-uses the previous value,
380: * if non-null, as the data holder to return.
381: *
382: */
383: StringDataValue getCharDataValue(String value);
384:
385: StringDataValue getCharDataValue(String value,
386: StringDataValue previous) throws StandardException;
387:
388: /**
389: * Get a SQL national char with the given value. A null argument means get
390: * a SQL null value. The second form re-uses the previous value,
391: * if non-null, as the data holder to return.
392: */
393: StringDataValue getNationalCharDataValue(String value);
394:
395: StringDataValue getNationalCharDataValue(String value,
396: StringDataValue previous) throws StandardException;
397:
398: /**
399: * Get a SQL date with the given value. A null argument means get
400: * a SQL null value. The second form re-uses the previous value,
401: * if non-null, as the data holder to return.
402: *
403: */
404: DateTimeDataValue getDataValue(Date value) throws StandardException;
405:
406: DateTimeDataValue getDataValue(Date value,
407: DateTimeDataValue previous) throws StandardException;
408:
409: /**
410: * Get a SQL time with the given value. A null argument means get
411: * a SQL null value. The second form re-uses the previous value,
412: * if non-null, as the data holder to return.
413: *
414: */
415: DateTimeDataValue getDataValue(Time value) throws StandardException;
416:
417: DateTimeDataValue getDataValue(Time value,
418: DateTimeDataValue previous) throws StandardException;
419:
420: /**
421: * Get a SQL timestamp with the given value. A null argument means get
422: * a SQL null value. The second form re-uses the previous value,
423: * if non-null, as the data holder to return.
424: *
425: */
426: DateTimeDataValue getDataValue(Timestamp value)
427: throws StandardException;
428:
429: DateTimeDataValue getDataValue(Timestamp value,
430: DateTimeDataValue previous) throws StandardException;
431:
432: /**
433: * Implement the timestamp SQL function: construct a SQL timestamp from a string, or timestamp.
434: *
435: * @param operand Must be a timestamp or a string convertible to a timestamp.
436: */
437: DateTimeDataValue getTimestamp(DataValueDescriptor operand)
438: throws StandardException;
439:
440: /**
441: * Construct a SQL timestamp from a date and time.
442: *
443: * @param date Must be convertible to a date.
444: * @param time Must be convertible to a time.
445: */
446: DateTimeDataValue getTimestamp(DataValueDescriptor date,
447: DataValueDescriptor time) throws StandardException;
448:
449: /**
450: * Implements the SQL date function
451: *
452: * @param operand A date, timestamp, string or integer.
453: *
454: * @return the corresponding date value
455: *
456: * @exception StandardException if the syntax is invalid or the date is out of range.
457: */
458: public DateTimeDataValue getDate(DataValueDescriptor operand)
459: throws StandardException;
460:
461: /**
462: * @param dateStr A date in one of the DB2 standard date formats or the local format.
463: * @param isJdbcEscape If true then the timestamp must be in the JDBC timestamp escape format, otherwise it must
464: * be in the DB2 timestamp format.
465: * @return A DateTimeDataValue
466: *
467: * @exception StandardException if the syntax is invalid or the date is out of range.
468: */
469: public DateTimeDataValue getDateValue(String dateStr,
470: boolean isJdbcEscape) throws StandardException;
471:
472: /**
473: * @param timeStr A date in one of the DB2 standard time formats or the local format.
474: * @param isJdbcEscape If true then the timestamp must be in the JDBC time escape format, otherwise it must
475: * be in the DB2 time format.
476: * @return A DateTimeDataValue
477: *
478: * @exception StandardException if the syntax is invalid or the time is out of range.
479: */
480: public DateTimeDataValue getTimeValue(String timeStr,
481: boolean isJdbcEscape) throws StandardException;
482:
483: /**
484: * @param timestampStr A time in string format.
485: * @param isJdbcEscape If true then the time must be in the JDBC time escape format, otherwise it must
486: * be in the DB2 time format.
487: * @return An internal timestamp
488: *
489: * @exception StandardException if the syntax is invalid or the timestamp is out of range.
490: */
491: public DateTimeDataValue getTimestampValue(String timestampStr,
492: boolean isJdbcEscape) throws StandardException;
493:
494: /**
495: * Get a null XML value. The second form re-uses the previous value,
496: * if non-null, as the data holder to return.
497: */
498: XMLDataValue getXMLDataValue();
499:
500: XMLDataValue getXMLDataValue(XMLDataValue previous)
501: throws StandardException;
502:
503: /**
504: * Get a SQL int with a SQL null value. If the supplied value
505: * is null then get a new value, otherwise set it to null and return
506: * that value.
507: *
508: */
509: NumberDataValue getNullInteger(NumberDataValue dataValue);
510:
511: /**
512: * Get a SQL smallint with a SQL null value. If the supplied value
513: * is null then get a new value, otherwise set it to null and return
514: * that value.
515: */
516: NumberDataValue getNullShort(NumberDataValue dataValue);
517:
518: /**
519: * Get a SQL tinyint with a SQL null value. If the supplied value
520: * is null then get a new value, otherwise set it to null and return
521: * that value.
522: *
523: */
524: NumberDataValue getNullByte(NumberDataValue dataValue);
525:
526: /**
527: * Get a SQL bigint with a SQL null value. If the supplied value
528: * is null then get a new value, otherwise set it to null and return
529: * that value.
530: *
531: */
532: NumberDataValue getNullLong(NumberDataValue dataValue);
533:
534: /**
535: * Get a SQL float with a SQL null value. If the supplied value
536: * is null then get a new value, otherwise set it to null and return
537: * that value.
538: *
539: */
540: NumberDataValue getNullFloat(NumberDataValue dataValue);
541:
542: /**
543: * Get a SQL double with a SQL null value. If the supplied value
544: * is null then get a new value, otherwise set it to null and return
545: * that value.
546: *
547: */
548: NumberDataValue getNullDouble(NumberDataValue dataValue);
549:
550: /**
551: * Get a SQL Decimal/Numeric with a SQL null value. If the supplied value
552: * is null then get a new value, otherwise set it to null and return
553: * that value.
554: *
555: */
556: NumberDataValue getNullDecimal(NumberDataValue dataValue);
557:
558: /**
559: * Get a SQL boolean with a SQL null value. If the supplied value
560: * is null then get a new value, otherwise set it to null and return
561: * that value.
562: */
563: BooleanDataValue getNullBoolean(BooleanDataValue dataValue);
564:
565: /**
566: * Get a SQL Bit with a SQL null value. If the supplied value
567: * is null then get a new value, otherwise set it to null and return
568: * that value.
569: *
570: * @exception StandardException Thrown on error
571: */
572: BitDataValue getNullBit(BitDataValue dataValue)
573: throws StandardException;
574:
575: /**
576: * Get a SQL Bit Varying with a SQL null value. If the supplied value
577: * is null then get a new value, otherwise set it to null and return
578: * that value.
579: *
580: * @exception StandardException Thrown on error
581: */
582: BitDataValue getNullVarbit(BitDataValue dataValue)
583: throws StandardException;
584:
585: // --- LONGVARBIT
586: /**
587: * Get a SQL Long Bit Varying with a SQL null value. If the supplied
588: * value is null then get a new value, otherwise set it to null
589: * and return that value.
590: *
591: * @exception StandardException Thrown on error
592: */
593: BitDataValue getNullLongVarbit(BitDataValue dataValue)
594: throws StandardException;
595:
596: // --- BLOB
597: /**
598: * Get a SQL Blob with a SQL null value. If the supplied
599: * value is null then get a new value, otherwise set it to null
600: * and return that value.
601: *
602: * @exception StandardException Thrown on error
603: */
604: BitDataValue getNullBlob(BitDataValue dataValue)
605: throws StandardException;
606:
607: // ------ CHAR
608: /**
609: * Get a SQL char with a SQL null value. If the supplied value
610: * is null then get a new value, otherwise set it to null and return
611: * that value.
612: */
613: StringDataValue getNullChar(StringDataValue dataValue);
614:
615: /**
616: * Get a SQL varchar with a SQL null value. If the supplied value
617: * is null then get a new value, otherwise set it to null and return
618: * that value.
619: *
620: */
621: StringDataValue getNullVarchar(StringDataValue dataValue);
622:
623: /**
624: * Get a SQL long varchar with a SQL null value. If the supplied value
625: * is null then get a new value, otherwise set it to null and return
626: * that value.
627: *
628: */
629: StringDataValue getNullLongvarchar(StringDataValue dataValue);
630:
631: /**
632: * Get a SQL long varchar with a SQL null value. If the supplied value
633: * is null then get a new value, otherwise set it to null and return
634: * that value.
635: *
636: */
637: StringDataValue getNullClob(StringDataValue dataValue);
638:
639: /**
640: * Get a SQL national char with a SQL null value. If the supplied value
641: * is null then get a new value, otherwise set it to null and return
642: * that value.
643: */
644: StringDataValue getNullNationalChar(StringDataValue dataValue);
645:
646: /**
647: * Get a SQL national varchar with a SQL null value. If the supplied value
648: * is null then get a new value, otherwise set it to null and return
649: * that value.
650: *
651: */
652: StringDataValue getNullNationalVarchar(StringDataValue dataValue);
653:
654: /**
655: * Get a SQL national long varchar with a SQL null value. If the supplied value
656: * is null then get a new value, otherwise set it to null and return
657: * that value.
658: *
659: */
660: StringDataValue getNullNationalLongvarchar(StringDataValue dataValue);
661:
662: /**
663: * Get a SQL NCLOB with a SQL null value. If the supplied value
664: * is null then get a new value, otherwise set it to null and return
665: * that value.
666: *
667: */
668: StringDataValue getNullNClob(StringDataValue dataValue);
669:
670: /**
671: * Get a User-defined data value with a SQL null value. If the supplied value
672: * is null then get a new value, otherwise set it to null and return
673: * that value.
674: *
675: */
676: UserDataValue getNullObject(UserDataValue dataValue);
677:
678: /**
679: * Get a RefDataValue with a SQL null value. If the supplied value
680: * is null then get a new value, otherwise set it to null and return
681: * that value.
682: *
683: */
684: RefDataValue getNullRef(RefDataValue dataValue);
685:
686: /**
687: * Get a SQL date with a SQL null value. If the supplied value
688: * is null then get a new value, otherwise set it to null and return
689: * that value.
690: *
691: */
692: DateTimeDataValue getNullDate(DateTimeDataValue dataValue);
693:
694: /**
695: * Get a SQL time with a SQL null value. If the supplied value
696: * is null then get a new value, otherwise set it to null and return
697: * that value.
698: *
699: */
700: DateTimeDataValue getNullTime(DateTimeDataValue dataValue);
701:
702: /**
703: * Get a SQL timestamp with a SQL null value. If the supplied value
704: * is null then get a new value, otherwise set it to null and return
705: * that value.
706: */
707: DateTimeDataValue getNullTimestamp(DateTimeDataValue dataValue);
708:
709: /**
710: * Get an XML with a SQL null value. If the supplied value is
711: * null then get a new value, otherwise set it to null and return
712: * that value.
713: */
714: XMLDataValue getNullXML(XMLDataValue dataValue);
715: }
|