1 19 20 package org.apache.cayenne.jpa.map; 21 22 import java.sql.Types ; 23 24 import javax.persistence.Basic; 25 import javax.persistence.EnumType; 26 import javax.persistence.FetchType; 27 import javax.persistence.TemporalType; 28 29 import org.apache.cayenne.dba.TypesMapping; 30 import org.apache.cayenne.util.TreeNodeChild; 31 32 public class JpaBasic extends JpaAttribute { 33 34 protected FetchType fetch = FetchType.EAGER; 35 protected boolean optional; 36 protected JpaColumn column; 37 protected boolean lob; 38 protected TemporalType temporal; 39 protected EnumType enumerated; 40 41 public JpaBasic() { 42 43 } 44 45 public JpaBasic(Basic basic) { 46 this.fetch = basic.fetch(); 47 this.optional = basic.optional(); 48 } 49 50 53 public int getDefaultJdbcType() { 54 55 if (getTemporal() != null) { 56 57 if (TemporalType.TIMESTAMP == getTemporal()) { 58 return Types.TIMESTAMP; 59 } 60 else if (TemporalType.DATE == getTemporal()) { 61 return Types.DATE; 62 } 63 else { 64 return Types.TIME; 65 } 66 } 67 else if (getEnumerated() != null) { 68 return (getEnumerated() == EnumType.ORDINAL) ? Types.INTEGER : Types.VARCHAR; 69 } 70 else { 71 return TypesMapping.getSqlTypeByJava(getPropertyDescriptor().getType()); 72 } 73 } 74 75 public FetchType getFetch() { 76 return fetch; 77 } 78 79 public void setFetch(FetchType fetchType) { 80 this.fetch = fetchType; 81 } 82 83 public boolean isOptional() { 84 return optional; 85 } 86 87 public void setOptional(boolean optional) { 88 this.optional = optional; 89 } 90 91 @TreeNodeChild 92 public JpaColumn getColumn() { 93 return column; 94 } 95 96 public void setColumn(JpaColumn column) { 97 this.column = column; 98 } 99 100 public EnumType getEnumerated() { 101 return enumerated; 102 } 103 104 public void setEnumerated(EnumType enumerated) { 105 this.enumerated = enumerated; 106 } 107 108 public boolean isLob() { 109 return lob; 110 } 111 112 public void setLob(boolean lob) { 113 this.lob = lob; 114 } 115 116 public void setLobTrue(Object value) { 117 setLob(true); 118 } 119 120 public TemporalType getTemporal() { 121 return temporal; 122 } 123 124 public void setTemporal(TemporalType temporal) { 125 this.temporal = temporal; 126 } 127 } 128 | Popular Tags |