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