View Javadoc
1   /*
2    * Copyright 2008 Lukas Lang
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   *
14   */
15  package org.exolab.castor.builder.info.nature;
16  
17  import org.castor.core.nature.BaseNature;
18  import org.exolab.castor.builder.info.FieldInfo;
19  
20  /**
21   * A JDO specific view of a {@link FieldInfo}. Implementation based on property access on
22   * {@link FieldInfo}.
23   * 
24   * @author Lukas Lang
25   * @since 1.2.1
26   */
27  public final class JDOFieldInfoNature extends BaseNature {
28  
29    /**
30     * Constant for the property name for the sql type of the column.
31     */
32    private static final String COLUMN_TYPE = "columntype";
33    /**
34     * Constant for the property name for the name of the column.
35     */
36    private static final String COLUMN_NAME = "columnname";
37    /**
38     * Constant for the property read only.
39     */
40    private static final String READONLY = "readonly";
41    /**
42     * Constant for the property dirty.
43     */
44    private static final String DIRTY = "dirty";
45  
46    /**
47     * Constructor taking a FieldInfo.
48     * 
49     * @param fieldInfo in focus.
50     */
51    public JDOFieldInfoNature(final FieldInfo fieldInfo) {
52      super(fieldInfo);
53    }
54  
55    /**
56     * Returns the fully qualified class name of the Nature.
57     * 
58     * @return the nature id.
59     * @see org.exolab.castor.builder.info.nature.Nature#getId()
60     */
61    public String getId() {
62      return getClass().getName();
63    }
64  
65    /**
66     * Retrieves the sql column name.
67     * 
68     * @return name of the column.
69     */
70    public String getColumnName() {
71      return (String) this.getProperty(COLUMN_NAME);
72    }
73  
74    /**
75     * Returns the sql type of the column.
76     * 
77     * @return the sql type.
78     */
79    public String getColumnType() {
80      return (String) this.getProperty(COLUMN_TYPE);
81    }
82  
83    /**
84     * Sets the sql column name.
85     * 
86     * @param columnName name of the column.
87     */
88    public void setColumnName(final String columnName) {
89      this.setProperty(COLUMN_NAME, columnName);
90    }
91  
92    /**
93     * Sets the column sql type.
94     * 
95     * @param sqlType of the column.
96     */
97    public void setColumnType(final String sqlType) {
98      this.setProperty(COLUMN_TYPE, sqlType);
99    }
100 
101   /**
102    * Returns true if no update on the column can be performed, false otherwise. Default value is
103    * false.
104    * 
105    * @return true if readonly, false if not or not set.
106    */
107   public boolean isReadOnly() {
108     return getBooleanPropertyDefaultFalse(READONLY);
109   }
110 
111   /**
112    * Sets the column read only.
113    * 
114    * @param readOnly true if read only.
115    */
116   public void setReadOnly(final boolean readOnly) {
117     setProperty(READONLY, Boolean.valueOf(readOnly));
118   }
119 
120   /**
121    * Returns true if field will NOT be checked against the database for modification, otherwise
122    * false. Default value is false.
123    * 
124    * @return true if field is not updated, false if not or not set.
125    */
126   public boolean isDirty() {
127     return getBooleanPropertyDefaultFalse(DIRTY);
128   }
129 
130   /**
131    * If set true, field will NOT be checked against the database for modification, otherwise set
132    * false.
133    * 
134    * @param dirty true if field should not be updated.
135    */
136   public void setDirty(final boolean dirty) {
137     setProperty(DIRTY, Boolean.valueOf(dirty));
138   }
139 
140 }