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