KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > sql > JdbcNameGenerator


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.sql;
13
14 /**
15  * This is responsible for generating and validating names for different
16  * JDBC entities (tables, columns, indexes and constraints). The SqlDriver
17  * for each store creates and configures a name generator instance for the
18  * store. This may be replaced by a user configured generator.
19  *
20  * @keep-all
21  *
22  */

23 public interface JdbcNameGenerator {
24
25     /**
26      * This is called immediately after the name generator has been constructed
27      * to indicate which database is in use.
28      * @param db Database type (mssql, sybase, oracle, informix et al.).
29      */

30     public void setDatabaseType(String JavaDoc db);
31
32     /**
33      * Add a table name specified in jdo meta data.
34      *
35      * @exception IllegalArgumentException if the name is invalid
36      * (e.g. 'duplicate table name' or 'invalid character XXX in name'
37      * etc.)
38      */

39     public void addTableName(String JavaDoc name) throws IllegalArgumentException JavaDoc;
40
41     /**
42      * Remove all information about table.
43      */

44     public void removeTableName(String JavaDoc name);
45
46     /**
47      * Generate a table name for a persistent class. The name generator must
48      * 'add' it.
49      *
50      * @see #addTableName
51      */

52     public String JavaDoc generateClassTableName(String JavaDoc className);
53
54     /**
55      * Generate a table name for a link table (normally used to hold the values
56      * of a collection). The name generator must 'add' it.
57      *
58      * @param tableName The table on the 1 side of the the link
59      * @param fieldName The field the link table is for
60      * @param elementTableName The table on the n side of the link or null if
61      * none (e.g. a link table for a collection of String's)
62      *
63      * @see #addTableName
64      */

65     public String JavaDoc generateLinkTableName(String JavaDoc tableName, String JavaDoc fieldName,
66         String JavaDoc elementTableName);
67
68     /**
69      * Add the primary key constaint name specified in jdo meta data.
70      * @exception IllegalArgumentException if it is invalid
71      */

72     public void addPkConstraintName(String JavaDoc tableName, String JavaDoc pkConstraintName)
73             throws IllegalArgumentException JavaDoc;
74
75     /**
76      * Generate a name for the primary key constaint for tableName. The name
77      * generator must add it.
78      *
79      * @see #addPkConstraintName
80      */

81     public String JavaDoc generatePkConstraintName(String JavaDoc tableName);
82
83     /**
84      * Add the referential integrity constaint name specified in jdo meta data.
85      * @exception IllegalArgumentException if it is invalid
86      */

87     public void addRefConstraintName(String JavaDoc tableName, String JavaDoc refConstraintName)
88             throws IllegalArgumentException JavaDoc;
89
90     /**
91      * Generate a name for a referential integrity constaint for tableName.
92      * The name generator must add it.
93      *
94      * @param tableName The table with the constraint
95      * @param refTableName The table being referenced
96      * @param fkNames The names of the foreign keys in tableName
97      * @param refPkNames The names of the primary key of refTableName
98      *
99      * @see #addRefConstraintName
100      */

101     public String JavaDoc generateRefConstraintName(String JavaDoc tableName,
102         String JavaDoc refTableName, String JavaDoc[] fkNames, String JavaDoc[] refPkNames);
103
104     /**
105      * Add a column name. The tableName will have already been added.
106      *
107      * @exception IllegalArgumentException if the name is invalid
108      * (e.g. 'duplicate column name' or 'invalid character XXX in name'
109      * etc.)
110      */

111     public void addColumnName(String JavaDoc tableName, String JavaDoc columnName)
112             throws IllegalArgumentException JavaDoc;
113
114     /**
115      * Does the table contain the column?
116      */

117     public boolean isColumnInTable(String JavaDoc tableName, String JavaDoc columnName);
118
119     /**
120      * Generate and add a name for the primary key column for a PC class using
121      * datastore identity.
122      */

123     public String JavaDoc generateDatastorePKName(String JavaDoc tableName);
124
125     /**
126      * Generate and add the name for a classId column.
127      * @see #addColumnName
128      */

129     public String JavaDoc generateClassIdColumnName(String JavaDoc tableName);
130
131     /**
132      * Generate and add the name for a field column.
133      */

134     public String JavaDoc generateFieldColumnName(String JavaDoc tableName, String JavaDoc fieldName,
135         boolean primaryKey);
136
137     /**
138      * Generate and add names for one or more columns for a field that is
139      * a reference to another PC class. Some of the columns may already have
140      * names.
141      *
142      * @param columnNames Store the column names here (some may already have
143      * names if specified in the .jdo meta data)
144      * @param refTableName The table being referenced (null if not a JDBC class)
145      * @param refPkNames The names of the primary key columns of refTableName
146      * @param otherRefs Are there other field referencing the same class here?
147      *
148      * @exception IllegalArgumentException if any existing names are invalid
149      */

150     public void generateRefFieldColumnNames(String JavaDoc tableName,
151             String JavaDoc fieldName, String JavaDoc[] columnNames, String JavaDoc refTableName,
152             String JavaDoc[] refPkNames, boolean otherRefs)
153         throws IllegalArgumentException JavaDoc;
154
155     /**
156      * Generate and add names for one or more columns for a field that is
157      * a polymorphic reference to any other PC class. Some of the columns may
158      * already have names.
159      *
160      * @param columnNames Store the column names here (some may already have
161      * names if specified in the .jdo meta data). The class-id column
162      * is at index 0.
163      *
164      * @exception IllegalArgumentException if any existing names are invalid
165      */

166     public void generatePolyRefFieldColumnNames(String JavaDoc tableName,
167             String JavaDoc fieldName, String JavaDoc[] columnNames)
168         throws IllegalArgumentException JavaDoc;
169
170     /**
171      * Generate and add names for the column(s) in a link table that reference
172      * the primary key of the main table. Some of the columns may already
173      * have names which must be kept (no need to add them).
174      *
175      * @param tableName The link table
176      * @param mainTablePkNames The names of the main table primary key
177      * @param linkMainRefNames The corresponding column names in the link table
178      */

179     public void generateLinkTableMainRefNames(String JavaDoc tableName,
180             String JavaDoc[] mainTablePkNames, String JavaDoc[] linkMainRefNames);
181
182     /**
183      * Generate and add the name for a the column in a link table that stores
184      * the element sequence number.
185      */

186     public String JavaDoc generateLinkTableSequenceName(String JavaDoc tableName);
187
188     /**
189      * Generate and add names for the column(s) in a link table that reference
190      * the primary key of the value table. This is called for collections of
191      * PC classes. Some of the columns may already have names which must be
192      * kept (no need to add them).
193      *
194      * @param tableName The link table
195      * @param valuePkNames The names of the value table primary key (may be
196      * null if the value class is not stored in JDBC)
197      * @param valueClassName The name of the value class
198      * @param linkValueRefNames The corresponding column names in the link table
199      * @param key Is this a key in a link table for a map?
200      */

201     public void generateLinkTableValueRefNames(String JavaDoc tableName,
202             String JavaDoc[] valuePkNames, String JavaDoc valueClassName,
203             String JavaDoc[] linkValueRefNames, boolean key);
204
205     /**
206      * Generate and add the name for a the column in a link table that stores
207      * the value where the value is not a PC class (int, String etc).
208      *
209      * @param tableName The link table
210      * @param valueCls The value class
211      * @param key Is this a key in a link table for a map?
212      */

213     public String JavaDoc generateLinkTableValueName(String JavaDoc tableName,
214             Class JavaDoc valueCls, boolean key);
215
216     /**
217      * Add an index name. The tableName will have already been added.
218      * @exception IllegalArgumentException if it is invalid
219      */

220     public void addIndexName(String JavaDoc tableName, String JavaDoc indexName)
221             throws IllegalArgumentException JavaDoc;
222
223     /**
224      * Generate and add an index name.
225      * @see #addIndexName
226      */

227     public String JavaDoc generateIndexName(String JavaDoc tableName, String JavaDoc[] columnNames);
228
229 }
230
231
Popular Tags