KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > generator > database > DDLTemplateFormatter


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * DDLTemplateFormatter.java
26  *
27  * Created on Jan 14, 2003
28  */

29
30 package com.sun.jdo.spi.persistence.generator.database;
31
32 import java.text.MessageFormat JavaDoc;
33
34 /*
35  * This class provides methods that format strings containing DDL. The
36  * resulting strings are dependent on a particular MappingPolicy.
37  *
38  * @author Jie Leng, Dave Bristor
39  */

40 // XXX FIXME This will not work in the unlikely event that 2 apps are being
41
// deployed at once. It has reset invoked in DDLGenerator.generateDDL, but
42
// if another generateDDL can happen simultaneously, we're in trouble.
43
class DDLTemplateFormatter {
44     /** Formatter for the start of "create table" DDL. */
45     private static MessageFormat JavaDoc createTableStart = null;
46
47     /** Formatter for "add constraint" DDL. */
48     private static MessageFormat JavaDoc alterTableAddConstraintStart = null;
49
50     /** Formatter for "drop constraing" DDL. */
51     private static MessageFormat JavaDoc alterTableDropConstraint = null;
52
53     /** Formatter for DDL for adding a PK constraint. */
54     private static MessageFormat JavaDoc primaryKeyConstraint = null;
55
56     /** Formatter for DDL for adding an FK constraint. */
57     private static MessageFormat JavaDoc foreignKeyConstraint = null;
58
59     /** Formatter for "drop table" DDL. */
60     private static MessageFormat JavaDoc dropTable = null;
61
62     
63     /**
64      * Prevent instantiation.
65      */

66     private DDLTemplateFormatter() {
67     }
68
69     /**
70      * Resets MessageFormats for code generation as per policy.
71      * @param mappingPolicy Policy that determines formatters provided by
72      * this class.
73      */

74     static void reset(MappingPolicy mappingPolicy) {
75         createTableStart = new MessageFormat JavaDoc(
76                 mappingPolicy.getCreateTableStart());
77
78         alterTableAddConstraintStart = new MessageFormat JavaDoc(
79                 mappingPolicy.getAlterTableAddConstraintStart());
80
81         alterTableDropConstraint = new MessageFormat JavaDoc(
82                 mappingPolicy.getAlterTableDropConstraint());
83
84         primaryKeyConstraint = new MessageFormat JavaDoc(
85                 mappingPolicy.getPrimaryKeyConstraint());
86
87         foreignKeyConstraint = new MessageFormat JavaDoc(
88                 mappingPolicy.getForeignKeyConstraint());
89
90         dropTable = new MessageFormat JavaDoc(
91                 mappingPolicy.getDropTable());
92     }
93
94     
95     /**
96      * @returns A String formatted for the start of "create table" DDL.
97      */

98     static String JavaDoc formatCreateTable(Object JavaDoc o) {
99         return createTableStart.format(o);
100     }
101
102     /**
103      * @returns A String formatted for "add constraint" DDL.
104      */

105     static String JavaDoc formatAlterTableAddConstraint(Object JavaDoc o) {
106         return alterTableAddConstraintStart.format(o);
107     }
108
109     /**
110      * @returns A String formatted for "drop constraint" DDL.
111      */

112     static String JavaDoc formatAlterTableDropConstraint(Object JavaDoc o) {
113         return alterTableDropConstraint.format(o);
114     }
115
116     /**
117      * @returns A String formatted for DDL for adding a PK constraint.
118      */

119     static String JavaDoc formatPKConstraint(Object JavaDoc o) {
120         return primaryKeyConstraint.format(o);
121     }
122
123     /**
124      * @returns A String formatted for DDL for adding an FK constraint.
125      */

126     static String JavaDoc formatFKConstraint(Object JavaDoc o) {
127         return foreignKeyConstraint.format(o);
128     }
129
130     /**
131      * @returns A String formatted for "drop table" DDL.
132      */

133     static String JavaDoc formatDropTable(Object JavaDoc o) {
134         return dropTable.format(o);
135     }
136 }
137
Popular Tags