1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jdo.model.jdo;
18
19 /***
20 * This interface provides constants denoting the treatment of null values
21 * for persistent fields during storage in the data store.
22 *
23 * @author Michael Bouschen
24 */
25 public class NullValueTreatment
26 {
27 /***
28 * Constant representing converting a null value of a field of nullable type
29 * to the default value for the type in the datastore.
30 */
31 public static final int NONE = 0;
32
33 /***
34 * Constant representing throwing an exception when storing a null value of
35 * field of a nullable type that is mapped to non-nullable type in the
36 * datastore.
37 */
38 public static final int EXCEPTION = 1;
39
40 /***
41 * Constant representing converting a null value of a field of nullable type
42 * to the default value for the type in the datastore.
43 */
44 public static final int DEFAULT = 2;
45
46 /***
47 * Returns a string representation of the specified NullValueTreatment
48 * constant.
49 * @param nullValueTreatment the null value treatment, one of
50 * {@link #NONE}, {@link #EXCEPTION} or {@link #DEFAULT}
51 * @return the string representation of the NullValueTreatment constant
52 */
53 public static String toString(int nullValueTreatment)
54 {
55 switch (nullValueTreatment) {
56 case NONE :
57 return "none";
58 case EXCEPTION :
59 return "exception";
60 case DEFAULT :
61 return "default";
62 default:
63 return "UNSPECIFIED";
64 }
65 }
66
67 /***
68 * Returns the NullValueTreatment constant for the string representation.
69 * @param nullValueTreatment the string representation of the null value
70 * treatment
71 * @return the null value treatment, one of {@link #NONE},
72 * {@link #EXCEPTION} or {@link #DEFAULT}
73 **/
74 public static int toNullValueTreatment(String nullValueTreatment)
75 {
76 if ((nullValueTreatment == null) || (nullValueTreatment.length() == 0))
77 return NONE;
78
79 if ("none".equals(nullValueTreatment))
80 return NONE;
81 else if ("exception".equals(nullValueTreatment))
82 return EXCEPTION;
83 else if ("default".equals(nullValueTreatment))
84 return DEFAULT;
85 else
86 return NONE;
87 }
88 }