KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > jpa > map > JpaBasic


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.jpa.map;
21
22 import java.sql.Types JavaDoc;
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     /**
51      * Returns default JDBC mapping for this basic attribute.
52      */

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 JavaDoc 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