KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 package org.apache.cayenne.jpa.map;
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25
26 import javax.persistence.TableGenerator;
27
28 /**
29  * A primary key generator based on a database table.
30  *
31  * @author Andrus Adamchik
32  */

33 public class JpaTableGenerator {
34
35     protected String JavaDoc name;
36     protected String JavaDoc table;
37     protected String JavaDoc catalog;
38     protected String JavaDoc schema;
39     protected String JavaDoc pkColumnName;
40     protected String JavaDoc valueColumnName;
41     protected String JavaDoc pkColumnValue;
42     protected int initialValue = 0;
43     protected int allocationSize = 50;
44
45     protected Collection JavaDoc<JpaUniqueConstraint> uniqueConstraints;
46
47     public JpaTableGenerator() {
48
49     }
50
51     public JpaTableGenerator(TableGenerator annotation) {
52         name = annotation.name();
53         table = annotation.table();
54         catalog = annotation.catalog();
55         schema = annotation.schema();
56         pkColumnName = annotation.pkColumnName();
57         valueColumnName = annotation.valueColumnName();
58         pkColumnValue = annotation.pkColumnValue();
59         initialValue = annotation.initialValue();
60         allocationSize = annotation.allocationSize();
61
62         getUniqueConstraints();
63         for (int i = 0; i < annotation.uniqueConstraints().length; i++) {
64             uniqueConstraints.add(new JpaUniqueConstraint(
65                     annotation.uniqueConstraints()[i]));
66         }
67     }
68
69     public int getAllocationSize() {
70         return allocationSize;
71     }
72
73     public void setAllocationSize(int allocationSize) {
74         this.allocationSize = allocationSize;
75     }
76
77     public String JavaDoc getCatalog() {
78         return catalog;
79     }
80
81     public void setCatalog(String JavaDoc catalog) {
82         this.catalog = catalog;
83     }
84
85     public int getInitialValue() {
86         return initialValue;
87     }
88
89     public void setInitialValue(int initialValue) {
90         this.initialValue = initialValue;
91     }
92
93     /**
94      * Returns table generator name.
95      * <h3>Specification Documenatation</h3>
96      * <p>
97      * <b>Description:</b> A unique generator name that can be referenced by one or more
98      * classes to be the generator for id values.
99      * </p>
100      */

101     public String JavaDoc getName() {
102         return name;
103     }
104
105     public void setName(String JavaDoc name) {
106         this.name = name;
107     }
108
109     public String JavaDoc getPkColumnName() {
110         return pkColumnName;
111     }
112
113     public void setPkColumnName(String JavaDoc pkColumnName) {
114         this.pkColumnName = pkColumnName;
115     }
116
117     public String JavaDoc getPkColumnValue() {
118         return pkColumnValue;
119     }
120
121     public void setPkColumnValue(String JavaDoc pkColumnValue) {
122         this.pkColumnValue = pkColumnValue;
123     }
124
125     public String JavaDoc getSchema() {
126         return schema;
127     }
128
129     public void setSchema(String JavaDoc schema) {
130         this.schema = schema;
131     }
132
133     /**
134      * Returns table generator table name.
135      * <h3>Specification Documentation</h3>
136      * <p>
137      * <b>Description:</b> Name of table that stores the generated id value.
138      * </p>
139      * <p>
140      * <b>Default:</b> Name is chosen by persistence provider.
141      * </p>
142      */

143     public String JavaDoc getTable() {
144         return table;
145     }
146
147     public void setTable(String JavaDoc table) {
148         this.table = table;
149     }
150
151     public String JavaDoc getValueColumnName() {
152         return valueColumnName;
153     }
154
155     public void setValueColumnName(String JavaDoc valueColumnName) {
156         this.valueColumnName = valueColumnName;
157     }
158
159     public Collection JavaDoc<JpaUniqueConstraint> getUniqueConstraints() {
160         if (uniqueConstraints == null) {
161             uniqueConstraints = new ArrayList JavaDoc<JpaUniqueConstraint>(2);
162         }
163
164         return uniqueConstraints;
165     }
166 }
167
Popular Tags