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.ManyToOne; 26 27 import org.apache.cayenne.util.TreeNodeChild; 28 29 public class JpaManyToOne extends JpaRelationship { 30 31 protected boolean optional; 32 protected Collection <JpaJoinColumn> joinColumns; 33 protected JpaJoinTable joinTable; 34 35 public JpaManyToOne() { 36 37 } 38 39 public JpaManyToOne(ManyToOne annotation) { 40 if (!Void.TYPE.equals(annotation.targetEntity())) { 41 this.targetEntityName = annotation.targetEntity().getName(); 42 } 43 44 for (int i = 0; i < annotation.cascade().length; i++) { 45 if (cascade == null) { 46 cascade = new JpaCascade(); 47 } 48 cascade.getCascades().add(annotation.cascade()[i]); 49 } 50 51 fetch = annotation.fetch(); 52 optional = annotation.optional(); 53 } 54 55 @Override 56 public boolean isToMany() { 57 return false; 58 } 59 60 public boolean isOptional() { 61 return optional; 62 } 63 64 public void setOptional(boolean optional) { 65 this.optional = optional; 66 } 67 68 @TreeNodeChild(type = JpaJoinColumn.class) 69 public Collection <JpaJoinColumn> getJoinColumns() { 70 if (joinColumns == null) { 71 joinColumns = new ArrayList <JpaJoinColumn>(); 72 } 73 return joinColumns; 74 } 75 76 public JpaJoinTable getJoinTable() { 77 return joinTable; 78 } 79 80 public void setJoinTable(JpaJoinTable joinTable) { 81 this.joinTable = joinTable; 82 } 83 } 84 | Popular Tags |