KickJava   Java API By Example, From Geeks To Geeks.

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


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.TemporalType;
25
26 import org.apache.cayenne.dba.TypesMapping;
27 import org.apache.cayenne.util.TreeNodeChild;
28
29 public class JpaId extends JpaAttribute {
30
31     protected JpaColumn column;
32     protected JpaGeneratedValue generatedValue;
33     protected TemporalType temporal;
34     protected JpaTableGenerator tableGenerator;
35     protected JpaSequenceGenerator sequenceGenerator;
36
37     /**
38      * Returns default JDBC mapping for this basic attribute.
39      */

40     public int getDefaultJdbcType() {
41
42         if (getTemporal() != null) {
43
44             if (TemporalType.TIMESTAMP == getTemporal()) {
45                 return Types.TIMESTAMP;
46             }
47             else if (TemporalType.DATE == getTemporal()) {
48                 return Types.DATE;
49             }
50             else {
51                 return Types.TIME;
52             }
53         }
54         else {
55             return TypesMapping.getSqlTypeByJava(getPropertyDescriptor().getType());
56         }
57     }
58
59     @TreeNodeChild
60     public JpaColumn getColumn() {
61         return column;
62     }
63
64     public void setColumn(JpaColumn column) {
65         this.column = column;
66     }
67
68     @TreeNodeChild
69     public JpaGeneratedValue getGeneratedValue() {
70         return generatedValue;
71     }
72
73     public void setGeneratedValue(JpaGeneratedValue generatedValue) {
74         this.generatedValue = generatedValue;
75     }
76
77     public TemporalType getTemporal() {
78         return temporal;
79     }
80
81     public void setTemporal(TemporalType temporal) {
82         this.temporal = temporal;
83     }
84
85     public JpaSequenceGenerator getSequenceGenerator() {
86         return sequenceGenerator;
87     }
88
89     public void setSequenceGenerator(JpaSequenceGenerator sequenceGenerator) {
90         this.sequenceGenerator = sequenceGenerator;
91     }
92
93     public JpaTableGenerator getTableGenerator() {
94         return tableGenerator;
95     }
96
97     public void setTableGenerator(JpaTableGenerator tableGenerator) {
98         this.tableGenerator = tableGenerator;
99     }
100 }
101
Popular Tags