001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdbc.sql;
012:
013: /**
014: * This is responsible for generating and validating names for different
015: * JDBC entities (tables, columns, indexes and constraints). The SqlDriver
016: * for each store creates and configures a name generator instance for the
017: * store. This may be replaced by a user configured generator.
018: *
019: * @keep-all
020: *
021: */
022: public interface JdbcNameGenerator {
023:
024: /**
025: * This is called immediately after the name generator has been constructed
026: * to indicate which database is in use.
027: * @param db Database type (mssql, sybase, oracle, informix et al.).
028: */
029: public void setDatabaseType(String db);
030:
031: /**
032: * Add a table name specified in jdo meta data.
033: *
034: * @exception IllegalArgumentException if the name is invalid
035: * (e.g. 'duplicate table name' or 'invalid character XXX in name'
036: * etc.)
037: */
038: public void addTableName(String name)
039: throws IllegalArgumentException;
040:
041: /**
042: * Remove all information about table.
043: */
044: public void removeTableName(String name);
045:
046: /**
047: * Generate a table name for a persistent class. The name generator must
048: * 'add' it.
049: *
050: * @see #addTableName
051: */
052: public String generateClassTableName(String className);
053:
054: /**
055: * Generate a table name for a link table (normally used to hold the values
056: * of a collection). The name generator must 'add' it.
057: *
058: * @param tableName The table on the 1 side of the the link
059: * @param fieldName The field the link table is for
060: * @param elementTableName The table on the n side of the link or null if
061: * none (e.g. a link table for a collection of String's)
062: *
063: * @see #addTableName
064: */
065: public String generateLinkTableName(String tableName,
066: String fieldName, String elementTableName);
067:
068: /**
069: * Add the primary key constaint name specified in jdo meta data.
070: * @exception IllegalArgumentException if it is invalid
071: */
072: public void addPkConstraintName(String tableName,
073: String pkConstraintName) throws IllegalArgumentException;
074:
075: /**
076: * Generate a name for the primary key constaint for tableName. The name
077: * generator must add it.
078: *
079: * @see #addPkConstraintName
080: */
081: public String generatePkConstraintName(String tableName);
082:
083: /**
084: * Add the referential integrity constaint name specified in jdo meta data.
085: * @exception IllegalArgumentException if it is invalid
086: */
087: public void addRefConstraintName(String tableName,
088: String refConstraintName) throws IllegalArgumentException;
089:
090: /**
091: * Generate a name for a referential integrity constaint for tableName.
092: * The name generator must add it.
093: *
094: * @param tableName The table with the constraint
095: * @param refTableName The table being referenced
096: * @param fkNames The names of the foreign keys in tableName
097: * @param refPkNames The names of the primary key of refTableName
098: *
099: * @see #addRefConstraintName
100: */
101: public String generateRefConstraintName(String tableName,
102: String refTableName, String[] fkNames, String[] 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 tableName, String columnName)
112: throws IllegalArgumentException;
113:
114: /**
115: * Does the table contain the column?
116: */
117: public boolean isColumnInTable(String tableName, String 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 generateDatastorePKName(String tableName);
124:
125: /**
126: * Generate and add the name for a classId column.
127: * @see #addColumnName
128: */
129: public String generateClassIdColumnName(String tableName);
130:
131: /**
132: * Generate and add the name for a field column.
133: */
134: public String generateFieldColumnName(String tableName,
135: String fieldName, 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 tableName,
151: String fieldName, String[] columnNames,
152: String refTableName, String[] refPkNames, boolean otherRefs)
153: throws IllegalArgumentException;
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 tableName,
167: String fieldName, String[] columnNames)
168: throws IllegalArgumentException;
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 tableName,
180: String[] mainTablePkNames, String[] 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 generateLinkTableSequenceName(String 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 tableName,
202: String[] valuePkNames, String valueClassName,
203: String[] 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 generateLinkTableValueName(String tableName,
214: Class 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 tableName, String indexName)
221: throws IllegalArgumentException;
222:
223: /**
224: * Generate and add an index name.
225: * @see #addIndexName
226: */
227: public String generateIndexName(String tableName,
228: String[] columnNames);
229:
230: }
|