View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software 
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License.
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"; //NOI18N
59          case EXCEPTION :
60              return "exception"; //NOI18N
61          case DEFAULT :
62              return "default"; //NOI18N
63          default:
64              return "UNSPECIFIED"; //NOI18N
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)) //NOI18N
81              return NONE;
82          else if ("exception".equals(nullValueTreatment)) //NOI18N
83              return EXCEPTION;
84          else if ("default".equals(nullValueTreatment)) //NOI18N
85              return DEFAULT;
86          else
87              return NONE;
88      }
89  }