
net.sourceforge.squirrel_sql.fw.dialects.PointbaseDialectExt Maven / Gradle / Ivy
/*
* Copyright (C) 2006 Rob Manning
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package net.sourceforge.squirrel_sql.fw.dialects;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
import org.antlr.stringtemplate.StringTemplate;
import org.hibernate.HibernateException;
/**
* A dialect delegate for the Pointbase database.
*/
public class PointbaseDialectExt extends CommonHibernateDialect implements HibernateDialect
{
private class PointbaseDialectHelper extends org.hibernate.dialect.PointbaseDialect
{
public PointbaseDialectHelper()
{
registerColumnType(Types.BIGINT, "bigint");
registerColumnType(Types.BINARY, "blob(8K)");
registerColumnType(Types.BIT, "smallint");
registerColumnType(Types.BLOB, 2000000000, "blob($l)");
registerColumnType(Types.BLOB, "blob(2000000000)");
registerColumnType(Types.BOOLEAN, "smallint");
registerColumnType(Types.CHAR, 4054, "char($l)");
registerColumnType(Types.CHAR, 2000000000, "clob($l)");
registerColumnType(Types.CHAR, "clob(2000000000)");
registerColumnType(Types.CLOB, 2000000000, "clob($l)");
registerColumnType(Types.CLOB, "clob(2000000000)");
registerColumnType(Types.DATE, "date");
registerColumnType(Types.DECIMAL, "decimal($p)");
registerColumnType(Types.DOUBLE, "float($p)");
registerColumnType(Types.FLOAT, "float($p)");
registerColumnType(Types.INTEGER, "int");
registerColumnType(Types.LONGVARBINARY, 2000000000, "blob($l)");
registerColumnType(Types.LONGVARBINARY, "blob(2000000000)");
registerColumnType(Types.LONGVARCHAR, 2000000000, "clob($l)");
registerColumnType(Types.LONGVARCHAR, "clob(2000000000)");
registerColumnType(Types.NUMERIC, "bigint");
registerColumnType(Types.REAL, "real");
registerColumnType(Types.SMALLINT, "smallint");
registerColumnType(Types.TIME, "time");
registerColumnType(Types.TIMESTAMP, "timestamp");
registerColumnType(Types.TINYINT, "smallint");
registerColumnType(Types.VARBINARY, 2000000000, "blob($l)");
registerColumnType(Types.VARBINARY, "blob(2000000000)");
registerColumnType(Types.VARCHAR, 4054, "varchar($l)");
registerColumnType(Types.VARCHAR, 2000000000, "clob($l)");
registerColumnType(Types.VARCHAR, "clob(2000000000)");
}
}
/** extended hibernate dialect used in this wrapper */
private final PointbaseDialectHelper _dialect = new PointbaseDialectHelper();
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getTypeName(int, int, int, int)
*/
@Override
public String getTypeName(final int code, final int length, final int precision, final int scale)
throws HibernateException
{
return _dialect.getTypeName(code, length, precision, scale);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#canPasteTo(net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo)
*/
@Override
public boolean canPasteTo(final IDatabaseObjectInfo info)
{
boolean result = true;
final DatabaseObjectType type = info.getDatabaseObjectType();
if (type.getName().equalsIgnoreCase("database"))
{
result = false;
}
return result;
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#supportsSchemasInTableDefinition()
*/
@Override
public boolean supportsSchemasInTableDefinition()
{
return true;
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getLengthFunction(int)
*/
@Override
public String getLengthFunction(final int dataType)
{
return "length";
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getMaxFunction()
*/
@Override
public String getMaxFunction()
{
return "max";
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getMaxPrecision(int)
*/
@Override
public int getMaxPrecision(final int dataType)
{
if (dataType == Types.DOUBLE || dataType == Types.FLOAT)
{
return 48;
}
else
{
return 31;
}
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getMaxScale(int)
*/
@Override
public int getMaxScale(final int dataType)
{
return getMaxPrecision(dataType);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getPrecisionDigits(int, int)
*/
@Override
public int getPrecisionDigits(final int columnSize, final int dataType)
{
return columnSize;
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getColumnLength(int, int)
*/
@Override
public int getColumnLength(final int columnSize, final int dataType)
{
return columnSize;
}
/**
* The string which identifies this dialect in the dialect chooser.
*
* @return a descriptive name that tells the user what database this dialect is design to work with.
*/
@Override
public String getDisplayName()
{
return "Pointbase";
}
/**
* Returns boolean value indicating whether or not this dialect supports the specified database
* product/version.
*
* @param databaseProductName
* the name of the database as reported by DatabaseMetaData.getDatabaseProductName()
* @param databaseProductVersion
* the version of the database as reported by DatabaseMetaData.getDatabaseProductVersion()
* @return true if this dialect can be used for the specified product name and version; false otherwise.
*/
@Override
public boolean supportsProduct(final String databaseProductName, final String databaseProductVersion)
{
if (databaseProductName == null) { return false; }
if (databaseProductName.trim().toLowerCase().startsWith("pointbase"))
{
// We don't yet have the need to discriminate by version.
return true;
}
return false;
}
/**
* Returns a boolean value indicating whether or not this database dialect supports dropping columns from
* tables.
*
* @return true if the database supports dropping columns; false otherwise.
*/
@Override
public boolean supportsDropColumn()
{
return true;
}
/**
* Returns the SQL that forms the command to drop the specified colum in the specified table.
*
* @param tableName
* the name of the table that has the column
* @param columnName
* the name of the column to drop.
* @return
* @throws UnsupportedOperationException
* if the database doesn't support dropping columns.
*/
@Override
public String getColumnDropSQL(final String tableName, final String columnName,
DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs)
{
return DialectUtils.getColumnDropSQL(tableName, columnName, qualifier, prefs, this);
}
/**
* Returns the SQL that forms the command to drop the specified table. If cascade contraints is supported
* by the dialect and cascadeConstraints is true, then a drop statement with cascade constraints clause
* will be formed.
*
* @param iTableInfo
* the table to drop
* @param cascadeConstraints
* whether or not to drop any FKs that may reference the specified table.
* @return the drop SQL command.
*/
@Override
public List getTableDropSQL(final ITableInfo iTableInfo, final boolean cascadeConstraints,
final boolean isMaterializedView, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs)
{
return DialectUtils.getTableDropSQL(iTableInfo, true, cascadeConstraints, false,
DialectUtils.CASCADE_CLAUSE, false, qualifier, prefs, this);
}
/**
* Returns the SQL that forms the command to add a primary key to the specified table composed of the given
* column names. alter table pktest add constraint pk_pktest primary key (pkcol)
*
* @param pkName
* the name of the constraint
* @param columnNames
* the columns that form the key
* @return
*/
@Override
public String[] getAddPrimaryKeySQL(final String pkName, final TableColumnInfo[] columns,
final ITableInfo ti, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs)
{
return new String[] { DialectUtils.getAddPrimaryKeySQL(ti, pkName, columns, false, qualifier, prefs,
this) };
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#supportsColumnComment()
*/
@Override
public boolean supportsColumnComment()
{
return false;
}
/**
* Returns the SQL statement to use to add a comment to the specified column of the specified table.
*
* @param info
* information about the column such as type, name, etc.
* @return
* @throws UnsupportedOperationException
* if the database doesn't support annotating columns with a comment.
*/
@Override
public String getColumnCommentAlterSQL(final TableColumnInfo info,
final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
throws UnsupportedOperationException
{
final int featureId = DialectUtils.COLUMN_COMMENT_ALTER_TYPE;
final String msg = DialectUtils.getUnsupportedMessage(this, featureId);
throw new UnsupportedOperationException(msg);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#supportsAlterColumnNull()
*/
@Override
public boolean supportsAlterColumnNull()
{
return false;
}
/**
* Returns the SQL used to alter the specified column to not allow null values
*
* @param info
* the column to modify
* @return the SQL to execute
*/
@Override
public String[] getColumnNullableAlterSQL(final TableColumnInfo info,
final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
{
final int featureId = DialectUtils.COLUMN_NULL_ALTER_TYPE;
final String msg = DialectUtils.getUnsupportedMessage(this, featureId);
throw new UnsupportedOperationException(msg);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#supportsRenameColumn()
*/
@Override
public boolean supportsRenameColumn()
{
return false;
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getColumnNameAlterSQL(net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo,
* net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo,
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String getColumnNameAlterSQL(final TableColumnInfo from, final TableColumnInfo to,
final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
{
final int featureId = DialectUtils.COLUMN_NAME_ALTER_TYPE;
final String msg = DialectUtils.getUnsupportedMessage(this, featureId);
throw new UnsupportedOperationException(msg);
}
/**
* Returns a boolean value indicating whether or not this dialect supports modifying a columns type.
*
* @return true if supported; false otherwise
*/
@Override
public boolean supportsAlterColumnType()
{
return true;
}
/**
* Returns the SQL that is used to change the column type.
*
* @param from
* the TableColumnInfo as it is
* @param to
* the TableColumnInfo as it wants to be
* @return the SQL to make the change
* @throw UnsupportedOperationException if the database doesn't support modifying column types.
*/
@Override
public List getColumnTypeAlterSQL(final TableColumnInfo from, final TableColumnInfo to,
final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
throws UnsupportedOperationException
{
// int featureId = DialectUtils.COLUMN_TYPE_ALTER_TYPE;
// String msg = DialectUtils.getUnsupportedMessage(this, featureId);
// throw new UnsupportedOperationException(msg);
// ALTER TABLE test3 ALTER COLUMN nullvc varchar(30)
final String alterClause = DialectUtils.ALTER_COLUMN_CLAUSE;
final String setClause = "";
return DialectUtils.getColumnTypeAlterSQL(this, alterClause, setClause, false, from, to, qualifier,
prefs);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#supportsAlterColumnDefault()
*/
@Override
public boolean supportsAlterColumnDefault()
{
return false;
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getColumnDefaultAlterSQL(net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo,
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String getColumnDefaultAlterSQL(final TableColumnInfo info,
final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
{
final int featureId = DialectUtils.COLUMN_DEFAULT_ALTER_TYPE;
final String msg = DialectUtils.getUnsupportedMessage(this, featureId);
throw new UnsupportedOperationException(msg);
}
/**
* Returns the SQL command to drop the specified table's primary key. alter table drop
* constraint
*
* @param pkName
* the name of the primary key that should be dropped
* @param tableName
* the name of the table whose primary key should be dropped
* @return
*/
@Override
public String getDropPrimaryKeySQL(final String pkName, final String tableName,
DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs)
{
return DialectUtils.getDropPrimaryKeySQL(pkName, tableName, true, false, qualifier, prefs, this);
}
/**
* Returns the SQL command to drop the specified table's foreign key constraint.
*
* @param fkName
* the name of the foreign key that should be dropped
* @param tableName
* the name of the table whose foreign key should be dropped
* @return
*/
@Override
public String getDropForeignKeySQL(final String fkName, final String tableName,
DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs)
{
return DialectUtils.getDropForeignKeySQL(fkName, tableName, qualifier, prefs, this);
}
/**
* Returns the SQL command to create the specified table.
*
* @param tables
* the tables to get create statements for
* @param md
* the metadata from the ISession
* @param prefs
* preferences about how the resultant SQL commands should be formed.
* @param isJdbcOdbc
* whether or not the connection is via JDBC-ODBC bridge.
* @return the SQL that is used to create the specified table
*/
@Override
public List getCreateTableSQL(final List tables, final ISQLDatabaseMetaData md,
final CreateScriptPreferences prefs, final boolean isJdbcOdbc) throws SQLException
{
return DialectUtils.getCreateTableSQL(tables, md, this, prefs, isJdbcOdbc);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getDialectType()
*/
@Override
public DialectType getDialectType()
{
return DialectType.POINTBASE;
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getIndexAccessMethodsTypes()
*/
@Override
public String[] getIndexAccessMethodsTypes()
{
return null;
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getIndexStorageOptions()
*/
@Override
public String[] getIndexStorageOptions()
{
return null;
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getAddAutoIncrementSQL(net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo,
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String[] getAddAutoIncrementSQL(final TableColumnInfo column,
final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
{
final int featureId = DialectUtils.ADD_AUTO_INCREMENT_TYPE;
final String msg = DialectUtils.getUnsupportedMessage(this, featureId);
throw new UnsupportedOperationException(msg);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getAddColumnSQL(net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo,
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String[] getAddColumnSQL(final TableColumnInfo column, final DatabaseObjectQualifier qualifier,
final SqlGenerationPreferences prefs)
{
final boolean addDefaultClause = true;
final boolean supportsNullQualifier = false;
final boolean addNullClause = true;
final String sql =
DialectUtils.getAddColumSQL(column, this, addDefaultClause, supportsNullQualifier, addNullClause,
qualifier, prefs);
return new String[] { sql };
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getAddForeignKeyConstraintSQL(java.lang.String,
* java.lang.String, java.lang.String, java.lang.Boolean, java.lang.Boolean, java.lang.Boolean,
* boolean, java.lang.String, java.util.Collection, java.lang.String, java.lang.String,
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String[] getAddForeignKeyConstraintSQL(final String localTableName, final String refTableName,
final String constraintName, final Boolean deferrable, final Boolean initiallyDeferred,
final Boolean matchFull, final boolean autoFKIndex, final String fkIndexName,
final Collection localRefColumns, final String onUpdateAction, final String onDeleteAction,
final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
{
final Boolean deferrableNotSupported = null;
final Boolean initiallyDeferredNotSupported = null;
final Boolean matchFullNotSupported = null;
return DialectUtils.getAddForeignKeyConstraintSQL(localTableName, refTableName, constraintName,
deferrableNotSupported, initiallyDeferredNotSupported, matchFullNotSupported, autoFKIndex,
fkIndexName, localRefColumns, onUpdateAction, onDeleteAction, qualifier, prefs, this);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getAddUniqueConstraintSQL(java.lang.String,
* java.lang.String, net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo[],
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String[] getAddUniqueConstraintSQL(final String tableName, final String constraintName,
final TableColumnInfo[] columns, final DatabaseObjectQualifier qualifier,
final SqlGenerationPreferences prefs)
{
// alter table FKTESTCHILDTABLE add CONSTRAINT foo_const UNIQUE (MYID)
// "ALTER TABLE $tableName$ " +
// "ADD CONSTRAINT $constraintName$ UNIQUE ($columnName; separator=\",\"$)";
final String templateStr = ST_ADD_UNIQUE_CONSTRAINT_STYLE_TWO;
final StringTemplate st = new StringTemplate(templateStr);
final String quotedConstraint = DialectUtils.shapeIdentifier(constraintName, prefs, this);
final HashMap valuesMap =
DialectUtils.getValuesMap(ST_TABLE_NAME_KEY, tableName, ST_CONSTRAINT_NAME_KEY, quotedConstraint);
return new String[] { DialectUtils.getAddUniqueConstraintSQL(st, valuesMap, columns, qualifier, prefs,
this) };
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getAlterSequenceSQL(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean,
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String[] getAlterSequenceSQL(final String sequenceName, final String increment,
final String minimum, final String maximum, final String restart, final String cache,
final boolean cycle, final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
{
final int featureId = DialectUtils.ALTER_SEQUENCE_TYPE;
final String msg = DialectUtils.getUnsupportedMessage(this, featureId);
throw new UnsupportedOperationException(msg);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getCreateIndexSQL(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String[], boolean, java.lang.String,
* java.lang.String, net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String getCreateIndexSQL(final String indexName, final String tableName, final String accessMethod,
final String[] columns, final boolean unique, final String tablespace, final String constraints,
final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
{
return DialectUtils.getCreateIndexSQL(indexName, tableName, accessMethod, columns, unique, tablespace,
constraints, qualifier, prefs, this);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getCreateSequenceSQL(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean,
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String getCreateSequenceSQL(final String sequenceName, final String increment,
final String minimum, final String maximum, final String start, final String cache,
final boolean cycle, final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
{
final int featureId = DialectUtils.CREATE_SEQUENCE_TYPE;
final String msg = DialectUtils.getUnsupportedMessage(this, featureId);
throw new UnsupportedOperationException(msg);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getCreateTableSQL(java.lang.String,
* java.util.List, java.util.List, net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences,
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier)
*/
@Override
public String getCreateTableSQL(final String tableName, final List columns,
final List primaryKeys, final SqlGenerationPreferences prefs,
final DatabaseObjectQualifier qualifier)
{
return DialectUtils.getCreateTableSQL(tableName, columns, primaryKeys, prefs, qualifier, this);
}
/**
* @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getCreateViewSQL(java.lang.String,
* java.lang.String, java.lang.String,
* net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier,
* net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences)
*/
@Override
public String getCreateViewSQL(final String viewName, final String definition, final String checkOption,
final DatabaseObjectQualifier qualifier, final SqlGenerationPreferences prefs)
{
// CREATE VIEW name [(view_col [, view_col …])]
// AS
© 2015 - 2025 Weber Informatics LLC | Privacy Policy