001: /*
002:
003: Derby - Class org.apache.derby.iapi.types.DataValueFactoryImpl
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.NumberDataValue;
025: import org.apache.derby.iapi.types.BooleanDataValue;
026: import org.apache.derby.iapi.types.BitDataValue;
027: import org.apache.derby.iapi.types.DateTimeDataValue;
028: import org.apache.derby.iapi.types.StringDataValue;
029: import org.apache.derby.iapi.types.UserDataValue;
030: import org.apache.derby.iapi.types.RefDataValue;
031:
032: import org.apache.derby.iapi.types.DataValueFactory;
033: import org.apache.derby.iapi.types.DataValueDescriptor;
034:
035: import org.apache.derby.iapi.types.RowLocation;
036:
037: import org.apache.derby.iapi.error.StandardException;
038:
039: import org.apache.derby.iapi.services.sanity.SanityManager;
040:
041: import org.apache.derby.iapi.services.i18n.LocaleFinder;
042: import org.apache.derby.iapi.services.io.RegisteredFormatIds;
043: import org.apache.derby.iapi.services.io.StoredFormatIds;
044: import org.apache.derby.iapi.services.monitor.ModuleControl;
045:
046: import java.sql.Date;
047: import java.sql.Time;
048: import java.sql.Timestamp;
049: import java.util.Properties;
050:
051: import org.apache.derby.iapi.db.DatabaseContext;
052: import org.apache.derby.iapi.services.context.ContextService;
053:
054: /**
055: * Core implementation of DataValueFactory. Does not implement
056: * methods required to generate DataValueDescriptor implementations
057: * for the DECIMAL datatype. J2ME and J2SE require different implementations.
058: *
059: * @see DataValueFactory
060: */
061: abstract class DataValueFactoryImpl implements DataValueFactory,
062: ModuleControl {
063: LocaleFinder localeFinder;
064:
065: DataValueFactoryImpl() {
066: }
067:
068: /*
069: ** ModuleControl methods.
070: */
071:
072: /* (non-Javadoc)
073: * @see org.apache.derby.iapi.services.monitor.ModuleControl#boot(boolean, java.util.Properties)
074: */
075: public void boot(boolean create, Properties properties)
076: throws StandardException {
077:
078: DataValueDescriptor decimalImplementation = getNullDecimal(null);
079:
080: TypeId.decimalImplementation = decimalImplementation;
081: RegisteredFormatIds.TwoByte[StoredFormatIds.SQL_DECIMAL_ID] = decimalImplementation
082: .getClass().getName();
083:
084: // Generate a DECIMAL value represetentation of 0
085: decimalImplementation = decimalImplementation.getNewNull();
086: decimalImplementation.setValue(0L);
087: NumberDataType.ZERO_DECIMAL = decimalImplementation;
088:
089: }
090:
091: /* (non-Javadoc)
092: * @see org.apache.derby.iapi.services.monitor.ModuleControl#stop()
093: */
094: public void stop() {
095: }
096:
097: /**
098: * @see DataValueFactory#getDataValue
099: *
100: */
101: public NumberDataValue getDataValue(int value) {
102: return new SQLInteger(value);
103: }
104:
105: public NumberDataValue getDataValue(int value,
106: NumberDataValue previous) throws StandardException {
107: if (previous == null)
108: return new SQLInteger(value);
109: previous.setValue(value);
110: return previous;
111: }
112:
113: public NumberDataValue getDataValue(Integer value) {
114: if (value != null)
115: return new SQLInteger(value.intValue());
116: else
117: return new SQLInteger();
118: }
119:
120: public NumberDataValue getDataValue(Integer value,
121: NumberDataValue previous) throws StandardException {
122: if (previous == null) {
123: return getDataValue(value);
124: }
125:
126: previous.setValue(value);
127: return previous;
128: }
129:
130: public NumberDataValue getDataValue(char value) {
131: return new SQLInteger(value);
132: }
133:
134: public NumberDataValue getDataValue(char value,
135: NumberDataValue previous) throws StandardException {
136: if (previous == null)
137: return new SQLInteger(value);
138: previous.setValue(value);
139: return previous;
140: }
141:
142: public NumberDataValue getDataValue(short value) {
143: return new SQLSmallint(value);
144: }
145:
146: public NumberDataValue getDataValue(short value,
147: NumberDataValue previous) throws StandardException {
148: if (previous == null)
149: return new SQLSmallint(value);
150: previous.setValue(value);
151: return previous;
152: }
153:
154: public NumberDataValue getDataValue(Short value) {
155: if (value != null)
156: return new SQLSmallint(value.shortValue());
157: else
158: return new SQLSmallint();
159: }
160:
161: public NumberDataValue getDataValue(Short value,
162: NumberDataValue previous) throws StandardException {
163: if (previous == null)
164: return getDataValue(value);
165:
166: previous.setValue(value);
167: return previous;
168: }
169:
170: public NumberDataValue getDataValue(byte value) {
171: return new SQLTinyint(value);
172: }
173:
174: public NumberDataValue getDataValue(byte value,
175: NumberDataValue previous) throws StandardException {
176: if (previous == null)
177: return new SQLTinyint(value);
178: previous.setValue(value);
179: return previous;
180: }
181:
182: public NumberDataValue getDataValue(Byte value) {
183: if (value != null)
184: return new SQLTinyint(value.byteValue());
185: else
186: return new SQLTinyint();
187: }
188:
189: public NumberDataValue getDataValue(Byte value,
190: NumberDataValue previous) throws StandardException {
191: if (previous == null)
192: return getDataValue(value);
193:
194: previous.setValue(value);
195: return previous;
196: }
197:
198: public NumberDataValue getDataValue(long value) {
199: return new SQLLongint(value);
200: }
201:
202: public NumberDataValue getDataValue(long value,
203: NumberDataValue previous) throws StandardException {
204: if (previous == null)
205: return new SQLLongint(value);
206: previous.setValue(value);
207: return previous;
208: }
209:
210: public NumberDataValue getDataValue(Long value) {
211: if (value != null)
212: return new SQLLongint(value.longValue());
213: else
214: return new SQLLongint();
215: }
216:
217: public NumberDataValue getDataValue(Long value,
218: NumberDataValue previous) throws StandardException {
219: if (previous == null)
220: return getDataValue(value);
221:
222: previous.setValue(value);
223: return previous;
224: }
225:
226: public NumberDataValue getDataValue(float value)
227: throws StandardException {
228: return new SQLReal(value);
229: }
230:
231: public NumberDataValue getDataValue(float value,
232: NumberDataValue previous) throws StandardException {
233: if (previous == null)
234: return new SQLReal(value);
235: previous.setValue(value);
236: return previous;
237: }
238:
239: public NumberDataValue getDataValue(Float value)
240: throws StandardException {
241: if (value != null)
242: return new SQLReal(value.floatValue());
243: else
244: return new SQLReal();
245: }
246:
247: public NumberDataValue getDataValue(Float value,
248: NumberDataValue previous) throws StandardException {
249: if (previous == null)
250: return getDataValue(value);
251:
252: previous.setValue(value);
253: return previous;
254: }
255:
256: public NumberDataValue getDataValue(double value)
257: throws StandardException {
258: return new SQLDouble(value);
259: }
260:
261: public NumberDataValue getDataValue(double value,
262: NumberDataValue previous) throws StandardException {
263: if (previous == null)
264: return new SQLDouble(value);
265: previous.setValue(value);
266: return previous;
267: }
268:
269: public NumberDataValue getDataValue(Double value)
270: throws StandardException {
271: if (value != null)
272: return new SQLDouble(value.doubleValue());
273: else
274: return new SQLDouble();
275: }
276:
277: public NumberDataValue getDataValue(Double value,
278: NumberDataValue previous) throws StandardException {
279: if (previous == null)
280: return getDataValue(value);
281:
282: previous.setValue(value);
283: return previous;
284: }
285:
286: public final NumberDataValue getDecimalDataValue(Number value)
287: throws StandardException {
288: NumberDataValue ndv = getNullDecimal((NumberDataValue) null);
289: ndv.setValue(value);
290: return ndv;
291: }
292:
293: public final NumberDataValue getDecimalDataValue(Number value,
294: NumberDataValue previous) throws StandardException {
295: if (previous == null)
296: return getDecimalDataValue(value);
297:
298: previous.setValue(value);
299: return previous;
300: }
301:
302: public final NumberDataValue getDecimalDataValue(String value,
303: NumberDataValue previous) throws StandardException {
304: if (previous == null)
305: return getDecimalDataValue(value);
306:
307: previous.setValue(value);
308: return previous;
309: }
310:
311: public BooleanDataValue getDataValue(boolean value) {
312: return new SQLBoolean(value);
313: }
314:
315: public BooleanDataValue getDataValue(boolean value,
316: BooleanDataValue previous) throws StandardException {
317: if (previous == null)
318: return new SQLBoolean(value);
319:
320: previous.setValue(value);
321: return previous;
322: }
323:
324: public BooleanDataValue getDataValue(Boolean value) {
325: if (value != null)
326: return new SQLBoolean(value.booleanValue());
327: else
328: return new SQLBoolean();
329: }
330:
331: public BooleanDataValue getDataValue(Boolean value,
332: BooleanDataValue previous) throws StandardException {
333: if (previous == null)
334: return getDataValue(value);
335:
336: previous.setValue(value);
337: return previous;
338: }
339:
340: public BooleanDataValue getDataValue(BooleanDataValue value) {
341: if (value != null)
342: return value;
343: else
344: return new SQLBoolean();
345: }
346:
347: public BitDataValue getBitDataValue(byte[] value)
348: throws StandardException {
349: return new SQLBit(value);
350: }
351:
352: public BitDataValue getBitDataValue(byte[] value,
353: BitDataValue previous) throws StandardException {
354: if (previous == null)
355: return new SQLBit(value);
356: previous.setValue(value);
357: return previous;
358: }
359:
360: public BitDataValue getVarbitDataValue(byte[] value) {
361: return new SQLVarbit(value);
362: }
363:
364: public BitDataValue getVarbitDataValue(byte[] value,
365: BitDataValue previous) throws StandardException {
366: if (previous == null)
367: return new SQLVarbit(value);
368: previous.setValue(value);
369: return previous;
370: }
371:
372: // LONGVARBIT
373:
374: public BitDataValue getLongVarbitDataValue(byte[] value)
375: throws StandardException {
376: return new SQLLongVarbit(value);
377: }
378:
379: public BitDataValue getLongVarbitDataValue(byte[] value,
380: BitDataValue previous) throws StandardException {
381: if (previous == null)
382: return new SQLLongVarbit(value);
383: previous.setValue(value);
384: return previous;
385: }
386:
387: // BLOB
388: public BitDataValue getBlobDataValue(byte[] value)
389: throws StandardException {
390: return new SQLBlob(value);
391: }
392:
393: public BitDataValue getBlobDataValue(byte[] value,
394: BitDataValue previous) throws StandardException {
395: if (previous == null)
396: return new SQLBlob(value);
397: previous.setValue(value);
398: return previous;
399: }
400:
401: // CHAR
402: public StringDataValue getCharDataValue(String value) {
403: return new SQLChar(value);
404: }
405:
406: public StringDataValue getCharDataValue(String value,
407: StringDataValue previous) throws StandardException {
408: if (previous == null)
409: return new SQLChar(value);
410: previous.setValue(value);
411: return previous;
412: }
413:
414: public StringDataValue getVarcharDataValue(String value) {
415: return new SQLVarchar(value);
416: }
417:
418: public StringDataValue getVarcharDataValue(String value,
419: StringDataValue previous) throws StandardException {
420: if (previous == null)
421: return new SQLVarchar(value);
422: previous.setValue(value);
423: return previous;
424: }
425:
426: public StringDataValue getLongvarcharDataValue(String value) {
427: return new SQLLongvarchar(value);
428: }
429:
430: public StringDataValue getClobDataValue(String value) {
431: return new SQLClob(value);
432: }
433:
434: public StringDataValue getLongvarcharDataValue(String value,
435: StringDataValue previous) throws StandardException {
436: if (previous == null)
437: return new SQLLongvarchar(value);
438: previous.setValue(value);
439: return previous;
440: }
441:
442: public StringDataValue getClobDataValue(String value,
443: StringDataValue previous) throws StandardException {
444: if (previous == null)
445: return new SQLClob(value);
446: previous.setValue(value);
447: return previous;
448: }
449:
450: //
451: public StringDataValue getNationalCharDataValue(String value) {
452: return new SQLNationalChar(value, getLocaleFinder());
453: }
454:
455: public StringDataValue getNationalCharDataValue(String value,
456: StringDataValue previous) throws StandardException {
457: if (previous == null)
458: return new SQLNationalChar(value, getLocaleFinder());
459: previous.setValue(value);
460: return previous;
461: }
462:
463: public StringDataValue getNationalVarcharDataValue(String value) {
464: return new SQLNationalVarchar(value, getLocaleFinder());
465: }
466:
467: public StringDataValue getNationalVarcharDataValue(String value,
468: StringDataValue previous) throws StandardException {
469: if (previous == null)
470: return new SQLNationalVarchar(value, getLocaleFinder());
471: previous.setValue(value);
472: return previous;
473: }
474:
475: public StringDataValue getNationalLongvarcharDataValue(String value) {
476: return new SQLNationalLongvarchar(value, getLocaleFinder());
477: }
478:
479: public StringDataValue getNationalLongvarcharDataValue(
480: String value, StringDataValue previous)
481: throws StandardException {
482: if (previous == null)
483: return new SQLNationalLongvarchar(value, getLocaleFinder());
484: previous.setValue(value);
485: return previous;
486: }
487:
488: public StringDataValue getNClobDataValue(String value) {
489: return new SQLNClob(value, getLocaleFinder());
490: }
491:
492: public StringDataValue getNClobDataValue(String value,
493: StringDataValue previous) throws StandardException {
494: if (previous == null)
495: return new SQLNClob(value, getLocaleFinder());
496: previous.setValue(value);
497: return previous;
498: }
499:
500: public DateTimeDataValue getDataValue(Date value)
501: throws StandardException {
502: return new SQLDate(value);
503: }
504:
505: public DateTimeDataValue getDataValue(Date value,
506: DateTimeDataValue previous) throws StandardException {
507: if (previous == null)
508: return new SQLDate(value);
509: previous.setValue(value);
510: return previous;
511: }
512:
513: public DateTimeDataValue getDataValue(Time value)
514: throws StandardException {
515: return new SQLTime(value);
516: }
517:
518: public DateTimeDataValue getDataValue(Time value,
519: DateTimeDataValue previous) throws StandardException {
520: if (previous == null)
521: return new SQLTime(value);
522: previous.setValue(value);
523: return previous;
524: }
525:
526: public DateTimeDataValue getDataValue(Timestamp value)
527: throws StandardException {
528: return new SQLTimestamp(value);
529: }
530:
531: public DateTimeDataValue getDataValue(Timestamp value,
532: DateTimeDataValue previous) throws StandardException {
533: if (previous == null)
534: return new SQLTimestamp(value);
535: previous.setValue(value);
536: return previous;
537: }
538:
539: /**
540: * Implement the date SQL function: construct a SQL date from a string, number, or timestamp.
541: *
542: * @param operand Must be a date, a number, or a string convertible to a date.
543: *
544: * @exception StandardException standard error policy
545: */
546: public DateTimeDataValue getDate(DataValueDescriptor operand)
547: throws StandardException {
548: return SQLDate.computeDateFunction(operand, this );
549: }
550:
551: /**
552: * Implement the timestamp SQL function: construct a SQL timestamp from a string, or timestamp.
553: *
554: * @param operand Must be a timestamp or a string convertible to a timestamp.
555: *
556: * @exception StandardException standard error policy
557: */
558: public DateTimeDataValue getTimestamp(DataValueDescriptor operand)
559: throws StandardException {
560: return SQLTimestamp.computeTimestampFunction(operand, this );
561: }
562:
563: public DateTimeDataValue getTimestamp(DataValueDescriptor date,
564: DataValueDescriptor time) throws StandardException {
565: return new SQLTimestamp(date, time);
566: }
567:
568: public UserDataValue getDataValue(Object value) {
569: return new UserType(value);
570: }
571:
572: public UserDataValue getDataValue(Object value,
573: UserDataValue previous) {
574: if (previous == null)
575: return new UserType(value);
576: ((UserType) previous).setValue(value);
577: return previous;
578: }
579:
580: public RefDataValue getDataValue(RowLocation value) {
581: return new SQLRef(value);
582: }
583:
584: public RefDataValue getDataValue(RowLocation value,
585: RefDataValue previous) {
586: if (previous == null)
587: return new SQLRef(value);
588: previous.setValue(value);
589: return previous;
590: }
591:
592: public NumberDataValue getNullInteger(NumberDataValue dataValue) {
593: if (dataValue == null) {
594: return new SQLInteger();
595: } else {
596: dataValue.setToNull();
597: return dataValue;
598: }
599: }
600:
601: public NumberDataValue getNullShort(NumberDataValue dataValue) {
602: if (dataValue == null) {
603: return new SQLSmallint();
604: } else {
605: dataValue.setToNull();
606: return dataValue;
607: }
608: }
609:
610: public NumberDataValue getNullLong(NumberDataValue dataValue) {
611: if (dataValue == null) {
612: return new SQLLongint();
613: } else {
614: dataValue.setToNull();
615: return dataValue;
616: }
617: }
618:
619: public NumberDataValue getNullByte(NumberDataValue dataValue) {
620: if (dataValue == null) {
621: return new SQLTinyint();
622: } else {
623: dataValue.setToNull();
624: return dataValue;
625: }
626: }
627:
628: public NumberDataValue getNullFloat(NumberDataValue dataValue) {
629: if (dataValue == null) {
630: return new SQLReal();
631: } else {
632: dataValue.setToNull();
633: return dataValue;
634: }
635: }
636:
637: public NumberDataValue getNullDouble(NumberDataValue dataValue) {
638: if (dataValue == null) {
639: return new SQLDouble();
640: } else {
641: dataValue.setToNull();
642: return dataValue;
643: }
644: }
645:
646: public BooleanDataValue getNullBoolean(BooleanDataValue dataValue) {
647: if (dataValue == null) {
648: return new SQLBoolean();
649: } else {
650: dataValue.setToNull();
651: return dataValue;
652: }
653: }
654:
655: public BitDataValue getNullBit(BitDataValue dataValue)
656: throws StandardException {
657: if (dataValue == null) {
658: return getBitDataValue((byte[]) null);
659: } else {
660: dataValue.setToNull();
661: return dataValue;
662: }
663: }
664:
665: public BitDataValue getNullVarbit(BitDataValue dataValue)
666: throws StandardException {
667: if (dataValue == null) {
668: return getVarbitDataValue((byte[]) null);
669: } else {
670: dataValue.setToNull();
671: return dataValue;
672: }
673: }
674:
675: // LONGVARBIT
676: public BitDataValue getNullLongVarbit(BitDataValue dataValue)
677: throws StandardException {
678: if (dataValue == null) {
679: return getLongVarbitDataValue((byte[]) null);
680: } else {
681: dataValue.setToNull();
682: return dataValue;
683: }
684: }
685:
686: /// BLOB
687: public BitDataValue getNullBlob(BitDataValue dataValue)
688: throws StandardException {
689: if (dataValue == null) {
690: return getBlobDataValue((byte[]) null);
691: } else {
692: dataValue.setToNull();
693: return dataValue;
694: }
695: }
696:
697: // CHAR
698: public StringDataValue getNullChar(StringDataValue dataValue) {
699: if (dataValue == null) {
700: return getCharDataValue((String) null);
701: } else {
702: dataValue.setToNull();
703: return dataValue;
704: }
705: }
706:
707: public StringDataValue getNullVarchar(StringDataValue dataValue) {
708: if (dataValue == null) {
709: return getVarcharDataValue((String) null);
710: } else {
711: dataValue.setToNull();
712: return dataValue;
713: }
714: }
715:
716: public StringDataValue getNullLongvarchar(StringDataValue dataValue) {
717: if (dataValue == null) {
718: return getLongvarcharDataValue((String) null);
719: } else {
720: dataValue.setToNull();
721: return dataValue;
722: }
723: }
724:
725: public StringDataValue getNullClob(StringDataValue dataValue) {
726: if (dataValue == null) {
727: return getClobDataValue((String) null);
728: } else {
729: dataValue.setToNull();
730: return dataValue;
731: }
732: }
733:
734: public StringDataValue getNullNationalChar(StringDataValue dataValue) {
735: if (dataValue == null) {
736: return getNationalCharDataValue((String) null);
737: } else {
738: dataValue.setToNull();
739: return dataValue;
740: }
741: }
742:
743: public StringDataValue getNullNationalVarchar(
744: StringDataValue dataValue) {
745: if (dataValue == null) {
746: return getNationalVarcharDataValue((String) null);
747: } else {
748: dataValue.setToNull();
749: return dataValue;
750: }
751: }
752:
753: public StringDataValue getNullNationalLongvarchar(
754: StringDataValue dataValue) {
755: if (dataValue == null) {
756: return getNationalLongvarcharDataValue((String) null);
757: } else {
758: dataValue.setToNull();
759: return dataValue;
760: }
761: }
762:
763: public StringDataValue getNullNClob(StringDataValue dataValue) {
764: if (dataValue == null) {
765: return getNClobDataValue((String) null);
766: } else {
767: dataValue.setToNull();
768: return dataValue;
769: }
770: }
771:
772: public UserDataValue getNullObject(UserDataValue dataValue) {
773: if (dataValue == null) {
774: return getDataValue((Object) null);
775: } else {
776: dataValue.setToNull();
777: return dataValue;
778: }
779: }
780:
781: public RefDataValue getNullRef(RefDataValue dataValue) {
782: if (dataValue == null) {
783: return getDataValue((RowLocation) null);
784: } else {
785: dataValue.setToNull();
786: return dataValue;
787: }
788: }
789:
790: public DateTimeDataValue getNullDate(DateTimeDataValue dataValue) {
791: if (dataValue == null) {
792: try {
793: return getDataValue((Date) null);
794: } catch (StandardException se) {
795: if (SanityManager.DEBUG) {
796: SanityManager.THROWASSERT(
797: "Could not get a null date.", se);
798: }
799: return null;
800: }
801: } else {
802: dataValue.setToNull();
803: return dataValue;
804: }
805: }
806:
807: public DateTimeDataValue getNullTime(DateTimeDataValue dataValue) {
808: if (dataValue == null) {
809: try {
810: return getDataValue((Time) null);
811: } catch (StandardException se) {
812: if (SanityManager.DEBUG) {
813: SanityManager.THROWASSERT(
814: "Could not get a null time.", se);
815: }
816: return null;
817: }
818: } else {
819: dataValue.setToNull();
820: return dataValue;
821: }
822: }
823:
824: public DateTimeDataValue getNullTimestamp(
825: DateTimeDataValue dataValue) {
826: if (dataValue == null) {
827: try {
828: return getDataValue((Timestamp) null);
829: } catch (StandardException se) {
830: if (SanityManager.DEBUG) {
831: SanityManager.THROWASSERT(
832: "Could not get a null timestamp.", se);
833: }
834: return null;
835: }
836: } else {
837: dataValue.setToNull();
838: return dataValue;
839: }
840: }
841:
842: public DateTimeDataValue getDateValue(String dateStr,
843: boolean isJdbcEscape) throws StandardException {
844: return new SQLDate(dateStr, isJdbcEscape, getLocaleFinder());
845: } // end of getDateValue( String dateStr)
846:
847: public DateTimeDataValue getTimeValue(String timeStr,
848: boolean isJdbcEscape) throws StandardException {
849: return new SQLTime(timeStr, isJdbcEscape, getLocaleFinder());
850: } // end of getTimeValue( String timeStr)
851:
852: public DateTimeDataValue getTimestampValue(String timestampStr,
853: boolean isJdbcEscape) throws StandardException {
854: return new SQLTimestamp(timestampStr, isJdbcEscape,
855: getLocaleFinder());
856: } // end of getTimestampValue( String timestampStr)
857:
858: /**
859: * getXMLDataValue:
860: * Get a SQL null value with XML type.
861: * @return An XMLDataValue instance corresponding to a
862: * a NULL value.
863: */
864: public XMLDataValue getXMLDataValue() {
865: return new XML();
866: }
867:
868: /**
869: * getXMLDataValue:
870: * Get a null XML value. If a non-null XMLDataValue is
871: * received then re-use that instance, otherwise create
872: * a new one.
873: * @param previous An XMLDataValue instance to re-use.
874: * @return An XMLDataValue instance corresponding to a
875: * NULL value. If an XMLDataValue was received, the
876: * returned XMLDataValue is the same instance as the one
877: * received, but the actual data has been set to a
878: * SQL null value.
879: * @exception StandardException Thrown on error
880: */
881: public XMLDataValue getXMLDataValue(XMLDataValue previous)
882: throws StandardException {
883: return getNullXML(previous);
884: }
885:
886: /**
887: * getNullXML:
888: * Get an XML with a SQL null value. If the supplied value is
889: * null then get a new value, otherwise set it to null and return
890: * that value.
891: * @param dataValue An XMLDataValue instance to re-use.
892: * @return An XMLDataValue instance corresponding to a
893: * NULL value. If an XMLDataValue was received, the
894: * returned XMLDataValue is the same instance as the one
895: * received, but the actual data has been set to null.
896: */
897: public XMLDataValue getNullXML(XMLDataValue dataValue) {
898: if (dataValue == null)
899: return getXMLDataValue();
900: else {
901: dataValue.setToNull();
902: return dataValue;
903: }
904: }
905:
906: // RESOLVE: This is here to find the LocaleFinder (i.e. the Database)
907: // on first access. This is necessary because the Monitor can't find
908: // the Database at boot time, because the Database is not done booting.
909: // See LanguageConnectionFactory.
910: private LocaleFinder getLocaleFinder() {
911: if (localeFinder == null) {
912: DatabaseContext dc = (DatabaseContext) ContextService
913: .getContext(DatabaseContext.CONTEXT_ID);
914: if (dc != null)
915: localeFinder = dc.getDatabase();
916: }
917:
918: return localeFinder;
919: }
920: }
|