001: /*
002: * Copyright (C) 2006 Rob Manning
003: * manningr@users.sourceforge.net
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: */
019: package net.sourceforge.squirrel_sql.fw.dialects;
020:
021: import java.sql.SQLException;
022: import java.sql.Types;
023: import java.util.List;
024:
025: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
026: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
027: import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
028: import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
029: import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
030:
031: /**
032: * An extension to the standard Hibernate Pointbase dialect
033: */
034: public class PointbaseDialect extends
035: org.hibernate.dialect.PointbaseDialect implements
036: HibernateDialect {
037:
038: public PointbaseDialect() {
039: super ();
040: registerColumnType(Types.BIGINT, "bigint");
041: registerColumnType(Types.BINARY, "blob(8K)");
042: registerColumnType(Types.BIT, "smallint");
043: registerColumnType(Types.BLOB, 2000000000, "blob($l)");
044: registerColumnType(Types.BLOB, "blob(2000000000)");
045: registerColumnType(Types.BOOLEAN, "smallint");
046: registerColumnType(Types.CHAR, 4054, "char($l)");
047: registerColumnType(Types.CHAR, 2000000000, "clob($l)");
048: registerColumnType(Types.CHAR, "clob(2000000000)");
049: registerColumnType(Types.CLOB, 2000000000, "clob($l)");
050: registerColumnType(Types.CLOB, "clob(2000000000)");
051: registerColumnType(Types.DATE, "date");
052: registerColumnType(Types.DECIMAL, "decimal($p)");
053: registerColumnType(Types.DOUBLE, "float($p)");
054: registerColumnType(Types.FLOAT, "float($p)");
055: registerColumnType(Types.INTEGER, "int");
056: registerColumnType(Types.LONGVARBINARY, 2000000000, "blob($l)");
057: registerColumnType(Types.LONGVARBINARY, "blob(2000000000)");
058: registerColumnType(Types.LONGVARCHAR, 2000000000, "clob($l)");
059: registerColumnType(Types.LONGVARCHAR, "clob(2000000000)");
060: registerColumnType(Types.NUMERIC, "bigint");
061: registerColumnType(Types.REAL, "real");
062: registerColumnType(Types.SMALLINT, "smallint");
063: registerColumnType(Types.TIME, "time");
064: registerColumnType(Types.TIMESTAMP, "timestamp");
065: registerColumnType(Types.TINYINT, "smallint");
066: registerColumnType(Types.VARBINARY, 2000000000, "blob($l)");
067: registerColumnType(Types.VARBINARY, "blob(2000000000)");
068: registerColumnType(Types.VARCHAR, 4054, "varchar($l)");
069: registerColumnType(Types.VARCHAR, 2000000000, "clob($l)");
070: registerColumnType(Types.VARCHAR, "clob(2000000000)");
071: }
072:
073: /* (non-Javadoc)
074: * @see net.sourceforge.squirrel_sql.plugins.dbcopy.dialects.HibernateDialect#canPasteTo(net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType)
075: */
076: public boolean canPasteTo(IDatabaseObjectInfo info) {
077: boolean result = true;
078: DatabaseObjectType type = info.getDatabaseObjectType();
079: if (type.getName().equalsIgnoreCase("database")) {
080: result = false;
081: }
082: return result;
083: }
084:
085: /* (non-Javadoc)
086: * @see net.sourceforge.squirrel_sql.plugins.dbcopy.dialects.HibernateDialect#supportsSchemasInTableDefinition()
087: */
088: public boolean supportsSchemasInTableDefinition() {
089: return true;
090: }
091:
092: /* (non-Javadoc)
093: * @see net.sourceforge.squirrel_sql.plugins.dbcopy.dialects.HibernateDialect#getLengthFunction()
094: */
095: public String getLengthFunction(int dataType) {
096: return "length";
097: }
098:
099: /* (non-Javadoc)
100: * @see net.sourceforge.squirrel_sql.plugins.dbcopy.dialects.HibernateDialect#getMaxFunction()
101: */
102: public String getMaxFunction() {
103: return "max";
104: }
105:
106: /* (non-Javadoc)
107: * @see net.sourceforge.squirrel_sql.plugins.dbcopy.dialects.HibernateDialect#getMaxPrecision(int)
108: */
109: public int getMaxPrecision(int dataType) {
110: if (dataType == Types.DOUBLE || dataType == Types.FLOAT) {
111: return 48;
112: } else {
113: return 31;
114: }
115: }
116:
117: /* (non-Javadoc)
118: * @see net.sourceforge.squirrel_sql.plugins.dbcopy.dialects.HibernateDialect#getMaxScale(int)
119: */
120: public int getMaxScale(int dataType) {
121: return getMaxPrecision(dataType);
122: }
123:
124: /* (non-Javadoc)
125: * @see net.sourceforge.squirrel_sql.plugins.dbcopy.dialects.HibernateDialect#getPrecisionDigits(int, int)
126: */
127: public int getPrecisionDigits(int columnSize, int dataType) {
128: return columnSize;
129: }
130:
131: /* (non-Javadoc)
132: * @see net.sourceforge.squirrel_sql.plugins.dbcopy.dialects.HibernateDialect#getColumnLength(int, int)
133: */
134: public int getColumnLength(int columnSize, int dataType) {
135: return columnSize;
136: }
137:
138: /**
139: * The string which identifies this dialect in the dialect chooser.
140: *
141: * @return a descriptive name that tells the user what database this dialect
142: * is design to work with.
143: */
144: public String getDisplayName() {
145: return "Pointbase";
146: }
147:
148: /**
149: * Returns boolean value indicating whether or not this dialect supports the
150: * specified database product/version.
151: *
152: * @param databaseProductName the name of the database as reported by
153: * DatabaseMetaData.getDatabaseProductName()
154: * @param databaseProductVersion the version of the database as reported by
155: * DatabaseMetaData.getDatabaseProductVersion()
156: * @return true if this dialect can be used for the specified product name
157: * and version; false otherwise.
158: */
159: public boolean supportsProduct(String databaseProductName,
160: String databaseProductVersion) {
161: if (databaseProductName == null) {
162: return false;
163: }
164: if (databaseProductName.trim().toLowerCase().startsWith(
165: "pointbase")) {
166: // We don't yet have the need to discriminate by version.
167: return true;
168: }
169: return false;
170: }
171:
172: /**
173: * Returns the SQL statement to use to add a column to the specified table
174: * using the information about the new column specified by info.
175: * @param info information about the new column such as type, name, etc.
176: *
177: * @return
178: * @throws UnsupportedOperationException if the database doesn't support
179: * adding columns after a table has already been created.
180: */
181: public String[] getColumnAddSQL(TableColumnInfo info)
182: throws UnsupportedOperationException {
183: return new String[] { DialectUtils.getColumnAddSQL(info, this ,
184: true, false, true) };
185: }
186:
187: /**
188: * Returns a boolean value indicating whether or not this database dialect
189: * supports dropping columns from tables.
190: *
191: * @return true if the database supports dropping columns; false otherwise.
192: */
193: public boolean supportsDropColumn() {
194: return true;
195: }
196:
197: /**
198: * Returns the SQL that forms the command to drop the specified colum in the
199: * specified table.
200: *
201: * @param tableName the name of the table that has the column
202: * @param columnName the name of the column to drop.
203: * @return
204: * @throws UnsupportedOperationException if the database doesn't support
205: * dropping columns.
206: */
207: public String getColumnDropSQL(String tableName, String columnName) {
208: return DialectUtils.getColumnDropSQL(tableName, columnName);
209: }
210:
211: /**
212: * Returns the SQL that forms the command to drop the specified table. If
213: * cascade contraints is supported by the dialect and cascadeConstraints is
214: * true, then a drop statement with cascade constraints clause will be
215: * formed.
216: *
217: * @param iTableInfo the table to drop
218: * @param cascadeConstraints whether or not to drop any FKs that may
219: * reference the specified table.
220: * @return the drop SQL command.
221: */
222: public List<String> getTableDropSQL(ITableInfo iTableInfo,
223: boolean cascadeConstraints, boolean isMaterializedView) {
224: // TODO: Need to verify this
225: return DialectUtils.getTableDropSQL(iTableInfo, true,
226: cascadeConstraints, false, DialectUtils.CASCADE_CLAUSE,
227: false);
228: }
229:
230: /**
231: * Returns the SQL that forms the command to add a primary key to the
232: * specified table composed of the given column names.
233: *
234: * alter table pktest add constraint pk_pktest primary key (pkcol)
235: *
236: * @param pkName the name of the constraint
237: * @param columnNames the columns that form the key
238: * @return
239: */
240: public String[] getAddPrimaryKeySQL(String pkName,
241: TableColumnInfo[] columns, ITableInfo ti) {
242: return new String[] { DialectUtils.getAddPrimaryKeySQL(ti,
243: pkName, columns, false) };
244: }
245:
246: /**
247: * Returns a boolean value indicating whether or not this dialect supports
248: * adding comments to columns.
249: *
250: * @return true if column comments are supported; false otherwise.
251: */
252: public boolean supportsColumnComment() {
253: return false;
254: }
255:
256: /**
257: * Returns the SQL statement to use to add a comment to the specified
258: * column of the specified table.
259: * @param info information about the column such as type, name, etc.
260: * @return
261: * @throws UnsupportedOperationException if the database doesn't support
262: * annotating columns with a comment.
263: */
264: public String getColumnCommentAlterSQL(TableColumnInfo info)
265: throws UnsupportedOperationException {
266: int featureId = DialectUtils.COLUMN_COMMENT_ALTER_TYPE;
267: String msg = DialectUtils
268: .getUnsupportedMessage(this , featureId);
269: throw new UnsupportedOperationException(msg);
270: }
271:
272: /**
273: * Returns a boolean value indicating whether or not this database dialect
274: * supports changing a column from null to not-null and vice versa.
275: *
276: * @return true if the database supports dropping columns; false otherwise.
277: */
278: public boolean supportsAlterColumnNull() {
279: return false;
280: }
281:
282: /**
283: * Returns the SQL used to alter the specified column to not allow null
284: * values
285: *
286: * @param info the column to modify
287: * @return the SQL to execute
288: */
289: public String getColumnNullableAlterSQL(TableColumnInfo info) {
290: int featureId = DialectUtils.COLUMN_NULL_ALTER_TYPE;
291: String msg = DialectUtils
292: .getUnsupportedMessage(this , featureId);
293: throw new UnsupportedOperationException(msg);
294: }
295:
296: /**
297: * Returns a boolean value indicating whether or not this database dialect
298: * supports renaming columns.
299: *
300: * @return true if the database supports changing the name of columns;
301: * false otherwise.
302: */
303: public boolean supportsRenameColumn() {
304: return false;
305: }
306:
307: /**
308: * Returns the SQL that is used to change the column name.
309: *
310: *
311: * @param from the TableColumnInfo as it is
312: * @param to the TableColumnInfo as it wants to be
313: *
314: * @return the SQL to make the change
315: */
316: public String getColumnNameAlterSQL(TableColumnInfo from,
317: TableColumnInfo to) {
318: int featureId = DialectUtils.COLUMN_NAME_ALTER_TYPE;
319: String msg = DialectUtils
320: .getUnsupportedMessage(this , featureId);
321: throw new UnsupportedOperationException(msg);
322: }
323:
324: /**
325: * Returns a boolean value indicating whether or not this dialect supports
326: * modifying a columns type.
327: *
328: * @return true if supported; false otherwise
329: */
330: public boolean supportsAlterColumnType() {
331: return false;
332: }
333:
334: /**
335: * Returns the SQL that is used to change the column type.
336: *
337: * @param from the TableColumnInfo as it is
338: * @param to the TableColumnInfo as it wants to be
339: *
340: * @return the SQL to make the change
341: * @throw UnsupportedOperationException if the database doesn't support
342: * modifying column types.
343: */
344: public List<String> getColumnTypeAlterSQL(TableColumnInfo from,
345: TableColumnInfo to) throws UnsupportedOperationException {
346: int featureId = DialectUtils.COLUMN_TYPE_ALTER_TYPE;
347: String msg = DialectUtils
348: .getUnsupportedMessage(this , featureId);
349: throw new UnsupportedOperationException(msg);
350: }
351:
352: /**
353: * Returns a boolean value indicating whether or not this database dialect
354: * supports changing a column's default value.
355: *
356: * @return true if the database supports modifying column defaults; false
357: * otherwise
358: */
359: public boolean supportsAlterColumnDefault() {
360: return false;
361: }
362:
363: /**
364: * Returns the SQL command to change the specified column's default value
365: *
366: * @param info the column to modify and it's default value.
367: * @return SQL to make the change
368: */
369: public String getColumnDefaultAlterSQL(TableColumnInfo info) {
370: int featureId = DialectUtils.COLUMN_DEFAULT_ALTER_TYPE;
371: String msg = DialectUtils
372: .getUnsupportedMessage(this , featureId);
373: throw new UnsupportedOperationException(msg);
374: }
375:
376: /**
377: * Returns the SQL command to drop the specified table's primary key.
378: *
379: * alter table <tableName> drop constraint <pkName>
380: *
381: * @param pkName the name of the primary key that should be dropped
382: * @param tableName the name of the table whose primary key should be
383: * dropped
384: * @return
385: */
386: public String getDropPrimaryKeySQL(String pkName, String tableName) {
387: return DialectUtils.getDropPrimaryKeySQL(pkName, tableName,
388: true, false);
389: }
390:
391: /**
392: * Returns the SQL command to drop the specified table's foreign key
393: * constraint.
394: *
395: * @param fkName the name of the foreign key that should be dropped
396: * @param tableName the name of the table whose foreign key should be
397: * dropped
398: * @return
399: */
400: public String getDropForeignKeySQL(String fkName, String tableName) {
401: return DialectUtils.getDropForeignKeySQL(fkName, tableName);
402: }
403:
404: /**
405: * Returns the SQL command to create the specified table.
406: *
407: * @param tables the tables to get create statements for
408: * @param md the metadata from the ISession
409: * @param prefs preferences about how the resultant SQL commands should be
410: * formed.
411: * @param isJdbcOdbc whether or not the connection is via JDBC-ODBC bridge.
412: *
413: * @return the SQL that is used to create the specified table
414: */
415: public List<String> getCreateTableSQL(List<ITableInfo> tables,
416: ISQLDatabaseMetaData md, CreateScriptPreferences prefs,
417: boolean isJdbcOdbc) throws SQLException {
418: return DialectUtils.getCreateTableSQL(tables, md, this, prefs,
419: isJdbcOdbc);
420: }
421:
422: }
|