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.relation;
16  
17  import java.util.List;
18  
19  import org.castor.core.nature.BaseNature;
20  import org.exolab.castor.builder.info.FieldInfo;
21  
22  /**
23   * A {@link JDOOneToOneNature} defines a one-to-one relation between two {@link FieldInfo}s.
24   * 
25   * @author Lukas Lang, Filip Hianik
26   */
27  public final class JDOOneToOneNature extends BaseNature {
28  
29    /**
30     * Property key for foreign key.
31     */
32    private static final String FOREIGN_KEY = "foreignkey";
33    /**
34     * Property key for the property read only.
35     */
36    private static final String READONLY = "readonly";
37    /**
38     * Property key for the property dirty.
39     */
40    private static final String DIRTY = "dirty";
41  
42    /**
43     * Constructor taking a {@link FieldInfo}.
44     * 
45     * @param field The field.
46     */
47    public JDOOneToOneNature(final FieldInfo field) {
48      super(field);
49    }
50  
51    /**
52     * Returns the Nature Id.
53     * 
54     * @see org.castor.core.nature.Nature#getId()
55     * @return The fully qualified {@link Class} name.
56     */
57    public String getId() {
58      return getClass().getName();
59    }
60  
61    /**
62     * Returns true if no update on the column can be performed, false otherwise. Default value is
63     * false.
64     * 
65     * @return true if readonly, false if not or not set.
66     */
67    public boolean isReadOnly() {
68      return getBooleanPropertyDefaultFalse(READONLY);
69    }
70  
71    /**
72     * Sets the column read only.
73     * 
74     * @param readOnly true if read only.
75     */
76    public void setReadOnly(final boolean readOnly) {
77      setProperty(READONLY, Boolean.valueOf(readOnly));
78    }
79  
80    /**
81     * Returns true if field will NOT be checked against the database for modification, otherwise
82     * false. Default value is false.
83     * 
84     * @return true if field is not updated, false if not or not set.
85     */
86    public boolean isDirty() {
87      return getBooleanPropertyDefaultFalse(DIRTY);
88    }
89  
90    /**
91     * If set true, field will NOT be checked against the database for modification, otherwise set
92     * false.
93     * 
94     * @param dirty true if field should not be updated.
95     */
96    public void setDirty(final boolean dirty) {
97      setProperty(DIRTY, Boolean.valueOf(dirty));
98    }
99  
100   /**
101    * Returns a List of {@String}s holding the columns of the foreign key. Keep in mind that by
102    * contract of <code>addPrimaryKey(String foreignKey)</code> the order is not guaranteed.
103    * 
104    * @return the names of the foreign key's columns or null if no keys added before.
105    */
106   @SuppressWarnings("unchecked")
107   public List<String> getForeignKeys() {
108     return (List<String>) this.getProperty(FOREIGN_KEY);
109   }
110 
111   /**
112    * Adds a column to the foreign key. By contract, the order of the key columns is not guaranteed
113    * and depends on the returned List implementation the {@link BaseNature} is using.
114    * 
115    * @param column The column name.
116    */
117   @SuppressWarnings("unchecked")
118   public void addForeignKey(final String column) {
119     List<String> foreignKey = getPropertyAsList(FOREIGN_KEY);
120     foreignKey.add(column);
121   }
122 
123 }