1 19 20 package org.apache.cayenne.jpa.map; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 25 import javax.persistence.OneToOne; 26 27 import org.apache.cayenne.util.TreeNodeChild; 28 29 public class JpaOneToOne extends JpaRelationship { 30 31 protected String mappedBy; 32 protected boolean optional; 33 34 protected Collection <JpaPrimaryKeyJoinColumn> primaryKeyJoinColumns; 35 protected Collection <JpaJoinColumn> joinColumns; 36 protected JpaJoinTable joinTable; 37 38 public JpaOneToOne() { 39 40 } 41 42 public JpaOneToOne(OneToOne annotation) { 43 if (!Void.TYPE.equals(annotation.targetEntity())) { 44 this.targetEntityName = annotation.targetEntity().getName(); 45 } 46 47 for (int i = 0; i < annotation.cascade().length; i++) { 48 if (cascade == null) { 49 cascade = new JpaCascade(); 50 } 51 cascade.getCascades().add(annotation.cascade()[i]); 52 } 53 54 fetch = annotation.fetch(); 55 optional = annotation.optional(); 56 mappedBy = annotation.mappedBy(); 57 } 58 59 @Override 60 public boolean isToMany() { 61 return false; 62 } 63 64 public boolean isOptional() { 65 return optional; 66 } 67 68 public void setOptional(boolean optional) { 69 this.optional = optional; 70 } 71 72 public String getMappedBy() { 73 return mappedBy; 74 } 75 76 public void setMappedBy(String mappedBy) { 77 this.mappedBy = mappedBy; 78 } 79 80 @TreeNodeChild(type = JpaPrimaryKeyJoinColumn.class) 81 public Collection <JpaPrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() { 82 if (primaryKeyJoinColumns == null) { 83 primaryKeyJoinColumns = new ArrayList <JpaPrimaryKeyJoinColumn>(); 84 } 85 return primaryKeyJoinColumns; 86 } 87 88 @TreeNodeChild(type = JpaJoinColumn.class) 89 public Collection <JpaJoinColumn> getJoinColumns() { 90 if (joinColumns == null) { 91 joinColumns = new ArrayList <JpaJoinColumn>(); 92 } 93 return joinColumns; 94 } 95 96 public JpaJoinTable getJoinTable() { 97 return joinTable; 98 } 99 100 public void setJoinTable(JpaJoinTable joinTable) { 101 this.joinTable = joinTable; 102 } 103 } 104 | Popular Tags |