1 /*
2 * Copyright 2008 Lukas Lang, Filip Hianik
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package org.exolab.castor.builder.info.nature.relation;
18
19 import java.util.List;
20
21 import org.castor.core.nature.BaseNature;
22 import org.exolab.castor.builder.info.FieldInfo;
23
24 /**
25 * A {@link JDOOneToManyNature} defines typed properties needed in the context a
26 * one-to-many relation between two {@link FieldInfo}s.
27 *
28 * @author Lukas Lang, Filip Hianik
29 * @since 1.2.1
30 */
31 public class JDOOneToManyNature extends BaseNature {
32
33 /**
34 * Property key for foreign key.
35 */
36 private static final String MANY_KEY = "manykey";
37 /**
38 * Property key for the property read only.
39 */
40 private static final String READONLY = "readonly";
41 /**
42 * Property key for the property dirty.
43 */
44 private static final String DIRTY = "dirty";
45
46 /**
47 * Constructor taking a {@link FieldInfo}.
48 *
49 * @param field
50 * The field.
51 */
52 public JDOOneToManyNature(final FieldInfo field) {
53 super(field);
54 }
55
56 /**
57 * Returns the Nature Id.
58 *
59 * @see org.castor.core.nature.Nature#getId()
60 * @return The fully qualified {@link Class} name.
61 */
62 public String getId() {
63 return getClass().getName();
64 }
65
66 /**
67 * Returns true if no update on the column can be performed, false
68 * otherwise. Default value is false.
69 *
70 * @return true if readonly, false if not or not set.
71 */
72 public boolean isReadOnly() {
73 return getBooleanPropertyDefaultFalse(READONLY);
74 }
75
76 /**
77 * Sets the column read only.
78 *
79 * @param readOnly
80 * true if read only.
81 */
82 public void setReadOnly(final boolean readOnly) {
83 setProperty(READONLY, new Boolean(readOnly));
84 }
85
86 /**
87 * Returns true if field will NOT be checked against the database for
88 * modification, otherwise false. Default value is false.
89 *
90 * @return true if field is not updated, false if not or not set.
91 */
92 public boolean isDirty() {
93 return getBooleanPropertyDefaultFalse(DIRTY);
94 }
95
96 /**
97 * If set true, field will NOT be checked against the database for
98 * modification, otherwise set false.
99 *
100 * @param dirty
101 * true if field should not be updated.
102 */
103 public void setDirty(final boolean dirty) {
104 setProperty(DIRTY, new Boolean(dirty));
105 }
106
107 /**
108 * Returns a List of {@String}s holding the columns of the foreign
109 * key. Keep in mind that by contract of
110 * <code>addPrimaryKey(String foreignKey)</code> the order is not
111 * guaranteed.
112 *
113 * @return the names of the foreign key's columns or null if no keys added
114 * before.
115 */
116 public List<String> getForeignKeys() {
117 return (List<String>) this.getProperty(MANY_KEY);
118 }
119
120 /**
121 * Adds a column to the foreign key. By contract, the order of the key
122 * columns is not guaranteed and depends on the returned List implementation
123 * the {@link BaseNature} is using.
124 *
125 * @param column
126 * The column name.
127 */
128 public void addForeignKey(final String column) {
129 List<String> foreignKey = getPropertyAsList(MANY_KEY);
130 foreignKey.add(column);
131 }
132
133 }