DB2DialectExt.java

Index Score
net.sourceforge.squirrel_sql.fw.dialects
Squirrel SQL

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
PARAMSNumber of formal parameter declarations
DECL_COMMENTSComments in declarations
INTERFACE_COMPLEXITYInterface complexity
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
DOC_COMMENTNumber of javadoc comment lines
SIZESize of the file in bytes
COMMENTSComment lines
FUNCTIONSNumber of function declarations
LINESNumber of lines in the source file
UNIQUE_OPERANDSNumber of unique operands
EXEC_COMMENTSComments in executable code
PROGRAM_VOCABHalstead program vocabulary
RETURNSNumber of return points from functions
OPERANDSNumber of operands
LOCLines of code
PROGRAM_LENGTHHalstead program length
ELOCEffective lines of code
OPERATORSNumber of operators
LINE_COMMENTNumber of line comments
LOGICAL_LINESNumber of statements
BLOCKSNumber of blocks
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0144JAVA0144 Line exceeds maximum M characters
CYCLOMATICCyclomatic complexity
JAVA0076JAVA0076 Use of magic number
EXITSProcedure exits
JAVA0034JAVA0034 Missing braces in if statement
JAVA0138JAVA0138 N parameters defined for method (maximum: M)
JAVA0145JAVA0145 Tab character used in source file
JAVA0081JAVA0081 Boolean literal in comparison
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
WHITESPACENumber of whitespace lines
JAVA0071JAVA0071 Strings compared with ==
JAVA0128JAVA0128 Public constructor in non-public class
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0020JAVA0020 Field name does not have required form
JAVA0117JAVA0117 Missing javadoc: method 'method'
LOOPSNumber of loops
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
UNIQUE_OPERATORSNumber of unique operators
/* * Copyright (C) 2006 Rob Manning * manningr@users.sourceforge.net * * 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 static net.sourceforge.squirrel_sql.fw.dialects.DialectUtils.CYCLE_CLAUSE; import static net.sourceforge.squirrel_sql.fw.dialects.DialectUtils.NO_CYCLE_CLAUSE; import java.sql.SQLException; import java.sql.Types; import java.util.ArrayList; import java.util.Arrays; 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.JDBCTypeMapper; import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo; import net.sourceforge.squirrel_sql.fw.util.StringUtilities; import org.antlr.stringtemplate.StringTemplate; import org.hibernate.HibernateException; /** * An extension to the standard Hibernate DB2 dialect */ public class DB2DialectExt extends CommonHibernateDialect implements HibernateDialect { private class DB2DialectHelper extends org.hibernate.dialect.DB2Dialect { public DB2DialectHelper() { super(); registerColumnType(Types.BIGINT, "bigint"); registerColumnType(Types.BINARY, 254, "char($l) for bit data"); registerColumnType(Types.BINARY, "blob"); registerColumnType(Types.BIT, "smallint"); // DB2 spec says max=2147483647, but the driver throws an exception registerColumnType(Types.BLOB, 1073741823, "blob($l)"); registerColumnType(Types.BLOB, "blob(1073741823)"); registerColumnType(Types.BOOLEAN, "smallint"); registerColumnType(Types.CHAR, 254, "char($l)"); registerColumnType(Types.CHAR, 4000, "varchar($l)"); registerColumnType(Types.CHAR, 32700, "long varchar"); registerColumnType(Types.CHAR, 1073741823, "clob($l)"); registerColumnType(Types.CHAR, "clob(1073741823)"); // DB2 spec says max=2147483647, but the driver throws an exception registerColumnType(Types.CLOB, 1073741823, "clob($l)"); registerColumnType(Types.CLOB, "clob(1073741823)"); registerColumnType(Types.DATE, "date"); registerColumnType(Types.DECIMAL, "decimal($p,$s)"); registerColumnType(Types.DOUBLE, "float($p)"); registerColumnType(Types.FLOAT, "float($p)"); registerColumnType(Types.INTEGER, "int"); registerColumnType(Types.LONGVARBINARY, 32700, "long varchar for bit data"); registerColumnType(Types.LONGVARBINARY, 1073741823, "blob($l)"); registerColumnType(Types.LONGVARBINARY, "blob(1073741823)"); registerColumnType(Types.LONGVARCHAR, 32700, "long varchar"); // DB2 spec says max=2147483647, but the driver throws an exception registerColumnType(Types.LONGVARCHAR, 1073741823, "clob($l)"); registerColumnType(Types.LONGVARCHAR, "clob(1073741823)"); 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, 254, "varchar($l) for bit data"); registerColumnType(Types.VARBINARY, "blob"); // The driver throws an exception for varchar with length > 3924 registerColumnType(Types.VARCHAR, 3924, "varchar($l)"); registerColumnType(Types.VARCHAR, 32700, "long varchar"); // DB2 spec says max=2147483647, but the driver throws an exception registerColumnType(Types.VARCHAR, 1073741823, "clob($l)"); registerColumnType(Types.VARCHAR, "clob(1073741823)"); // The registrations below are made in support for new types introduced in Java6 // Replace "-8" with Types.ROWID when Java6 is the minimum supported version registerColumnType(-8, "int"); // Replace "-9" with Types.NVARCHAR when Java6 is the minimum supported version registerColumnType(-9, 1073741823, "clob($l)"); registerColumnType(-9, "clob(1073741823)"); // Replace "-15" with Types.NCHAR when Java6 is the minimum supported version registerColumnType(-15, "char($l)"); // Replace "-16" with Types.LONGNVARCHAR when Java6 is the minimum supported version registerColumnType(-16, "longvarchar"); // Replace "2009" with Types.SQLXML when Java6 is the minimum supported version registerColumnType(2009, "clob"); // Replace "2011" with Types.NCLOB when Java6 is the minimum supported version registerColumnType(2011, "clob"); } } /** extended hibernate dialect used in this wrapper */ private DB2DialectHelper _dialect = new DB2DialectHelper(); /** * @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getTypeName(int, int, int, int) */ @Override public String getTypeName(int code, int length, int precision, 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(IDatabaseObjectInfo info) { boolean result = true; DatabaseObjectType type = info.getDatabaseObjectType(); if (type.getName().equalsIgnoreCase("database")) { result = false; } return result; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getLengthFunction(int) */ public String getLengthFunction(int dataType) { return "length"; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getMaxFunction() */ public String getMaxFunction() { return "max"; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getMaxPrecision(int) */ public int getMaxPrecision(int dataType) { if (dataType == Types.DOUBLE || dataType == Types.FLOAT) { return 53; } else { return 31; } } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getMaxScale(int) */ public int getMaxScale(int dataType) { if (dataType == Types.DOUBLE || dataType == Types.FLOAT) { // double and float have no scale - that is DECIMAL_DIGITS is null. // Assume that is because it's variable - "floating" point. return 0; } else { return getMaxPrecision(dataType); } } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getPrecisionDigits(int, int) */ public int getPrecisionDigits(int columnSize, int dataType) { return columnSize; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getColumnLength(int, int) */ public int getColumnLength(int columnSize, 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. */ public String getDisplayName() { return "DB2"; } /** * 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. */ public boolean supportsProduct(String databaseProductName, String databaseProductVersion) { if (databaseProductName == null) { return false; } if (databaseProductName.trim().startsWith("DB2")) { // We don't yet have the need to discriminate by version. return true; } return false; } /** * Returns the SQL statement to use to add a column to the specified table using the information about the * new column specified by info. * * @param info * information about the new column such as type, name, etc. * @return * @throws UnsupportedOperationException * if the database doesn't support adding columns after a table has already been created. */ public String[] getAddColumnSQL(TableColumnInfo info, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) throws UnsupportedOperationException { final String qualifedTableName = DialectUtils.shapeQualifiableIdentifier(info.getTableName(), qualifier, prefs, this); final String shapedColumnName = DialectUtils.shapeIdentifier(info.getColumnName(), prefs, this); ArrayList<String> result = new ArrayList<String>(); StringBuffer addColumn = new StringBuffer(); addColumn.append("ALTER TABLE "); addColumn.append(qualifedTableName); addColumn.append(" ADD "); addColumn.append(shapedColumnName); addColumn.append(" "); addColumn.append(getTypeName(info.getDataType(), info.getColumnSize(), info.getColumnSize(), info.getDecimalDigits())); if (info.getDefaultValue() != null) { addColumn.append(" WITH DEFAULT "); if (JDBCTypeMapper.isNumberType(info.getDataType())) { addColumn.append(info.getDefaultValue()); } else { addColumn.append("'"); addColumn.append(info.getDefaultValue()); addColumn.append("'"); } } result.add(addColumn.toString()); if (info.isNullable() == "NO") { // ALTER TABLE <TABLENAME> ADD CONSTRAINT NULL_FIELD CHECK (<FIELD> IS NOT // NULL) StringBuffer notnull = new StringBuffer(); notnull.append("ALTER TABLE "); notnull.append(qualifedTableName); notnull.append(" ADD CONSTRAINT "); // TODO: should the constraint name simply be the column name or something more like a constraint // name? notnull.append(shapedColumnName); notnull.append(" CHECK ("); notnull.append(shapedColumnName); notnull.append(" IS NOT NULL)"); result.add(notnull.toString()); } if (info.getRemarks() != null && !"".equals(info.getRemarks())) { result.add(getColumnCommentAlterSQL(info, qualifier, prefs)); } return result.toArray(new String[result.size()]); } /** * Returns the SQL statement to use to add a comment to the specified column of the specified table. * * @param tableName * the name of the table to create the SQL for. * @param columnName * the name of the column to create the SQL for. * @param comment * the comment to add. * @param qualifier TODO * @param prefs TODO * @param dialect TODO * @return * @throws UnsupportedOperationException * if the database doesn't support annotating columns with a comment. */ public String getColumnCommentAlterSQL(String tableName, String columnName, String comment, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs, HibernateDialect dialect) throws UnsupportedOperationException { return DialectUtils.getColumnCommentAlterSQL(tableName, columnName, comment, qualifier, prefs, dialect); } /** * 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. */ 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. */ public String getColumnDropSQL(String tableName, String columnName, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { // alter table <tablename> drop column <columnName> 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. */ public List<String> getTableDropSQL(ITableInfo iTableInfo, boolean cascadeConstraints, boolean isMaterializedView, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { return DialectUtils.getTableDropSQL(iTableInfo, false, 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 table_name ADD CONSTRAINT contraint_name PRIMARY KEY (column_name) * * @param pkName * the name of the constraint * @param columnNames * the columns that form the key * @return */ public String[] getAddPrimaryKeySQL(String pkName, TableColumnInfo[] columns, ITableInfo ti, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { return new String[] { DialectUtils.getAddPrimaryKeySQL(ti, pkName, columns, false, qualifier, prefs, this) }; } /** * Returns a boolean value indicating whether or not this dialect supports adding comments to columns. * * @return true if column comments are supported; false otherwise. */ public boolean supportsColumnComment() { return true; } /** * 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. */ public String getColumnCommentAlterSQL(TableColumnInfo info, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) throws UnsupportedOperationException { return DialectUtils.getColumnCommentAlterSQL(info, qualifier, prefs, this); } /** * Returns a boolean value indicating whether or not this database dialect supports changing a column from * null to not-null and vice versa. * * @return true if the database supports dropping columns; false otherwise. */ public boolean supportsAlterColumnNull() { return true; } /** * Update: DB2 version 9.5 appears to support altering column nullability just fine via: ALTER TABLE * table_name ALTER COLUMN column_name SET NOT NULL So, I'll use that Returns the SQL used to alter the * specified column to not allow null values This appears to work: ALTER TABLE table_name ADD CONSTRAINT * constraint_name CHECK (column_name IS NOT NULL) However, the jdbc driver still reports the column as * nullable - which means I can't reliably display the correct value for this attribute in the UI. I tried * this alternate syntax and it fails with an exception: ALTER TABLE table_name ALTER COLUMN column_name * SET NOT NULL Error: com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, * SQLERRMC: NOT;ER COLUMN mychar SET;DEFAULT, SQL State: 42601, Error Code: -104 I don't see how I can * practically support changing column nullability in DB2. * * @param info * the column to modify * @return the SQL to execute */ public String[] getColumnNullableAlterSQL(TableColumnInfo info, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { ArrayList<String> result = new ArrayList<String>(); boolean nullable = info.isNullable().equalsIgnoreCase("yes"); result.addAll(Arrays.asList(getColumnNullableAlterSQL(info, nullable, qualifier, prefs))); /* DB2 needs to reorg table after changing nullabolity */ StringBuilder reorgSql = new StringBuilder(); reorgSql.append("CALL SYSPROC.ADMIN_CMD('REORG TABLE "); reorgSql.append(DialectUtils.shapeQualifiableIdentifier(info.getTableName(), qualifier, prefs, this)); reorgSql.append("')"); result.add(reorgSql.toString()); return result.toArray(new String[result.size()]); } /** * Returns an SQL statement that alters the specified column nullability. * * @param info * the column to modify * @param nullable * whether or not the column should allow nulls after being altered * @param qualifier * qualifier of the table * @param prefs * preferences for generated sql scripts * @return */ private String[] getColumnNullableAlterSQL(TableColumnInfo info, boolean nullable, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { ArrayList<String> sql = new ArrayList<String>(); StringBuilder result = new StringBuilder(); result.append("ALTER TABLE "); result.append(DialectUtils.shapeQualifiableIdentifier(info.getTableName(), qualifier, prefs, this)); result.append(" "); result.append(DialectUtils.ALTER_COLUMN_CLAUSE); result.append(" "); result.append(DialectUtils.shapeIdentifier(info.getColumnName(), prefs, this)); result.append(" SET "); if (nullable) { result.append("NULL"); } else { result.append("NOT NULL"); } sql.add(result.toString()); sql.add(getTableReorgSql(info.getTableName(), qualifier, prefs)); return sql.toArray(new String[sql.size()]); } /** * Returns a boolean value indicating whether or not this database dialect supports renaming columns. * * @return true if the database supports changing the name of columns; false otherwise. */ public boolean supportsRenameColumn() { return false; } /** * Returns the SQL that is used to change the column name. * * @param from * the TableColumnInfo as it is * @param to * the TableColumnInfo as it wants to be * @return the SQL to make the change */ public String getColumnNameAlterSQL(TableColumnInfo from, TableColumnInfo to, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { int featureId = DialectUtils.COLUMN_NAME_ALTER_TYPE; 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 */ public boolean supportsAlterColumnType() { return true; } /** * Returns the SQL that is used to change the column type. ALTER TABLE table_name ALTER COLUMN column_name * SET DATA TYPE data_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. */ public List<String> getColumnTypeAlterSQL(TableColumnInfo from, TableColumnInfo to, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) throws UnsupportedOperationException { // "ALTER TABLE $tableName$ " + // "ALTER $columnName$ SET DATA TYPE $dataType$"; String templateString = ST_ALTER_COLUMN_SET_DATA_TYPE_STYLE_ONE; StringTemplate st = new StringTemplate(templateString); HashMap<String, String> valuesMap = DialectUtils.getValuesMap(ST_TABLE_NAME_KEY, from.getTableName()); valuesMap.put(ST_COLUMN_NAME_KEY, from.getColumnName()); valuesMap.put(ST_DATA_TYPE_KEY, DialectUtils.getTypeName(to, this)); ArrayList<String> result = new ArrayList<String>(); result.add(DialectUtils.bindAttributes(this, st, valuesMap, qualifier, prefs)); return result; } /** * Returns a boolean value indicating whether or not this database dialect supports changing a column's * default value. * * @return true if the database supports modifying column defaults; false otherwise */ public boolean supportsAlterColumnDefault() { return true; } /** * Returns the SQL command to change the specified column's default value ALTER TABLE EMPLOYEE ALTER COLUMN * WORKDEPTSET SET DEFAULT '123' * * @param info * the column to modify and it's default value. * @return SQL to make the change */ public String getColumnDefaultAlterSQL(TableColumnInfo info, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { String alterClause = DialectUtils.ALTER_COLUMN_CLAUSE; String defaultClause = DialectUtils.SET_DEFAULT_CLAUSE; return DialectUtils.getColumnDefaultAlterSQL(this, info, alterClause, false, defaultClause, qualifier, prefs); } /** * Returns the SQL command to drop the specified table's primary key. * * @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 */ public String getDropPrimaryKeySQL(String pkName, String tableName, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { return DialectUtils.getDropPrimaryKeySQL(pkName, tableName, false, 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 */ public String getDropForeignKeySQL(String fkName, 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 */ public List<String> getCreateTableSQL(List<ITableInfo> tables, ISQLDatabaseMetaData md, CreateScriptPreferences prefs, boolean isJdbcOdbc) throws SQLException { return DialectUtils.getCreateTableSQL(tables, md, this, prefs, isJdbcOdbc); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getDialectType() */ public DialectType getDialectType() { return DialectType.DB2; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getIndexAccessMethodsTypes() */ public String[] getIndexAccessMethodsTypes() { return new String[] {}; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getIndexStorageOptions() */ public String[] getIndexStorageOptions() { // TODO Auto-generated method stub return null; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.CommonHibernateDialect#getAddAutoIncrementSQL(net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo, java.lang.String, net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ @Override public String[] getAddAutoIncrementSQL(TableColumnInfo column, String sequenceName, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { ArrayList<String> result = new ArrayList<String>(); /* * DB2 doesn't support adding an auto-increment column once the table has already been created. So this * can simulate one using trigger on the table to access a sequence. Found this idea at wikibooks: * http://en.wikibooks.org/wiki/SQL_dialects_reference/Data_structure_definition/Auto-increment_column * CREATE SEQUENCE sequence_name; CREATE TABLE table_name ( column_name INT ); CREATE TRIGGER * insert_trigger NO CASCADE BEFORE INSERT ON table_name REFERENCING NEW AS n FOR EACH ROW SET * n.column_name = NEXTVAL FOR sequence_name; */ final String tableName = column.getTableName(); final String columnName = column.getColumnName(); result.add(getCreateSequenceSQL(sequenceName.toString(), "1", "1", null, "1", null, false, qualifier, prefs)); StringBuilder triggerSql = new StringBuilder(); triggerSql.append("CREATE TRIGGER "); triggerSql.append(columnName); triggerSql.append("_trigger \n"); triggerSql.append("NO CASCADE BEFORE INSERT ON "); triggerSql.append(tableName); triggerSql.append(" REFERENCING NEW AS n \n"); triggerSql.append("FOR EACH ROW \n"); triggerSql.append("SET n."); triggerSql.append(columnName); triggerSql.append(" = NEXTVAL FOR "); triggerSql.append(sequenceName); result.add(triggerSql.toString()); return result.toArray(new String[result.size()]); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getAddAutoIncrementSQL(net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo, * DatabaseObjectQualifier, net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) * * @deprecated use the version that accepts the sequence name instead. */ public String[] getAddAutoIncrementSQL(TableColumnInfo column, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { final String tableName = column.getTableName(); final String columnName = column.getColumnName(); final StringBuilder sequenceName = new StringBuilder(); sequenceName.append(tableName.toUpperCase()).append("_"); sequenceName.append(columnName.toUpperCase()).append("_SEQ"); return getAddAutoIncrementSQL(column, sequenceName.toString(), qualifier, prefs); } /** * @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) */ public String[] getAddForeignKeyConstraintSQL(String localTableName, String refTableName, String constraintName, Boolean deferrable, Boolean initiallyDeferred, Boolean matchFull, boolean autoFKIndex, String fkIndexName, Collection<String[]> localRefColumns, String onUpdateAction, String onDeleteAction, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { Boolean deferrableNotSupported = null; Boolean initiallyDeferredNotSupported = null; Boolean matchFullNotSupported = null; return DialectUtils.getAddForeignKeyConstraintSQL(localTableName, refTableName, constraintName, deferrableNotSupported, initiallyDeferredNotSupported, matchFullNotSupported, autoFKIndex, fkIndexName, localRefColumns, onUpdateAction, onDeleteAction, qualifier, prefs, this); } private String getTableReorgSql(String tableName, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { /* DB2 needs to reorg table after changing nullabolity */ StringBuilder reorgSql = new StringBuilder(); reorgSql.append("CALL SYSPROC.ADMIN_CMD('REORG TABLE "); reorgSql.append(DialectUtils.shapeQualifiableIdentifier(tableName, qualifier, prefs, this)); reorgSql.append("')"); return reorgSql.toString(); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getAddUniqueConstraintSQL(java.lang.String, * java.lang.String, TableColumnInfo[], * net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String[] getAddUniqueConstraintSQL(String tableName, String constraintName, TableColumnInfo[] columns, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { ArrayList<String> result = new ArrayList<String>(); // DB2 requires that columns be not-null before applying a unique constraint for (TableColumnInfo column : columns) { if (column.isNullable().equalsIgnoreCase("YES")) { result.addAll(Arrays.asList(getColumnNullableAlterSQL(column, false, qualifier, prefs))); } } result.add(DialectUtils.getAddUniqueConstraintSQL(tableName, constraintName, columns, qualifier, prefs, this)); return result.toArray(new String[result.size()]); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#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) */ public String[] getAlterSequenceSQL(String sequenceName, String increment, String minimum, String maximum, String restart, String cache, boolean cycle, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { String cycleClause = NO_CYCLE_CLAUSE; if (cycle == true) { cycleClause = CYCLE_CLAUSE; } return new String[] { DialectUtils.getAlterSequenceSQL(sequenceName, increment, minimum, maximum, restart, cache, cycleClause, qualifier, prefs, this) }; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#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) */ public String getCreateIndexSQL(String indexName, String tableName, String accessMethod, String[] columns, boolean unique, String tablespace, String constraints, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { StringBuilder result = new StringBuilder(); result.append("CREATE "); if (unique) { result.append("UNIQUE "); } result.append(" INDEX "); result.append(DialectUtils.shapeQualifiableIdentifier(indexName, qualifier, prefs, this)); result.append(" ON "); result.append(DialectUtils.shapeQualifiableIdentifier(tableName, qualifier, prefs, this)); result.append("("); for (String column : columns) { result.append(column); result.append(","); } result.setLength(result.length() - 1); result.append(")"); return result.toString(); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#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) */ public String getCreateSequenceSQL(String sequenceName, String increment, String minimum, String maximum, String start, String cache, boolean cycle, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { return DialectUtils.getCreateSequenceSQL(sequenceName, increment, minimum, maximum, start, cache, null, qualifier, prefs, this); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getCreateTableSQL(java.lang.String, * java.util.List, java.util.List, net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences, * net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier) */ public String getCreateTableSQL(String tableName, List<TableColumnInfo> columns, List<TableColumnInfo> primaryKeys, SqlGenerationPreferences prefs, DatabaseObjectQualifier qualifier) { return DialectUtils.getCreateTableSQL(tableName, columns, primaryKeys, prefs, qualifier, this); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getCreateViewSQL(java.lang.String, * java.lang.String, java.lang.String, * net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String getCreateViewSQL(String viewName, String definition, String checkOption, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { return DialectUtils.getCreateViewSQL(viewName, definition, checkOption, qualifier, prefs, this); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getDropConstraintSQL(java.lang.String, * java.lang.String, net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String getDropConstraintSQL(String tableName, String constraintName, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { return DialectUtils.getDropConstraintSQL(tableName, constraintName, qualifier, prefs, this); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getDropIndexSQL(String, java.lang.String, * boolean, net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String getDropIndexSQL(String tableName, String indexName, boolean cascade, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { Boolean cascadeNotSupported = null; return DialectUtils.getDropIndexSQL(indexName, cascadeNotSupported, qualifier, prefs, this); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getDropSequenceSQL(java.lang.String, * boolean, net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String getDropSequenceSQL(String sequenceName, boolean cascade, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { return DialectUtils.getDropSequenceSQL(sequenceName, false, qualifier, prefs, this); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getDropViewSQL(java.lang.String, boolean, * net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String getDropViewSQL(String viewName, boolean cascade, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { Boolean cascadeNotSupported = null; return DialectUtils.getDropViewSQL(viewName, cascadeNotSupported, qualifier, prefs, this); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getInsertIntoSQL(java.lang.String, * java.util.List, java.lang.String, net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String getInsertIntoSQL(String tableName, List<String> columns, String valuesPart, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { return DialectUtils.getInsertIntoSQL(tableName, columns, valuesPart, qualifier, prefs, this); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getRenameTableSQL(java.lang.String, * java.lang.String, net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String getRenameTableSQL(String oldTableName, String newTableName, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { // RENAME TABLE <tablename> TO <newtablename>; StringBuilder sql = new StringBuilder(); sql.append("RENAME TABLE "); sql.append(DialectUtils.shapeQualifiableIdentifier(oldTableName, qualifier, prefs, this)); sql.append(" "); sql.append(" TO "); sql.append(DialectUtils.shapeIdentifier(newTableName, prefs, this)); return sql.toString(); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getRenameViewSQL(java.lang.String, * java.lang.String, net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String[] getRenameViewSQL(String oldViewName, String newViewName, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { final int featureId = DialectUtils.RENAME_VIEW_TYPE; final String msg = DialectUtils.getUnsupportedMessage(this, featureId); throw new UnsupportedOperationException(msg); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsViewDefinition() */ public boolean supportsViewDefinition() { return true; } public String getViewDefinitionSQL(String viewName, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { /* * SELECT 'CREATE VIEW <newViewName> AS ' || SUBSTR(TEXT , LOCATE('as', TEXT)+2, LENGTH(TEXT)) FROM * SYSCAT.VIEWS WHERE VIEWSCHEMA = '<schema>' AND VIEWNAME = '<oldViewName>'; */ StringBuilder createViewSql = new StringBuilder(); createViewSql.append("SELECT TEXT "); createViewSql.append(" FROM SYSCAT.VIEWS "); createViewSql.append("WHERE VIEWSCHEMA = '"); createViewSql.append(qualifier.getSchema()); createViewSql.append("' AND UPPER(VIEWNAME) = '"); createViewSql.append(viewName.toUpperCase()); createViewSql.append("'"); return createViewSql.toString(); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getSequenceInformationSQL(java.lang.String, * net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String getSequenceInformationSQL(String sequenceName, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { // SELECT // SEQSCHEMA,SEQNAME,DEFINER,DEFINERTYPE,OWNER,OWNERTYPE,SEQID,SEQTYPE,INCREMENT,START,MAXVALUE,MINVALUE, // NEXTCACHEFIRSTVALUE,CYCLE,CACHE,ORDER,DATATYPEID,SOURCETYPEID,CREATE_TIME,ALTER_TIME,PRECISION,ORIGIN,REMARKS // FROM SYSCAT.SEQUENCES // WHERE SEQNAME = ? // and SEQSCHEMA = <schema> StringBuilder result = new StringBuilder(); result.append("SELECT NEXTCACHEFIRSTVALUE, MAXVALUE, MINVALUE, CACHE, INCREMENT, CYCLE "); result.append("FROM SYSCAT.SEQUENCES "); result.append("WHERE "); if (qualifier.getSchema() != null) { result.append("SEQSCHEMA = upper('" + qualifier.getSchema() + "') AND "); } // TODO: figure out why bind variables aren't working result.append("SEQNAME = '"); result.append(sequenceName); result.append("'"); return result.toString(); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getUpdateSQL(java.lang.String, * java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], * net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String[] getUpdateSQL(String tableName, String[] setColumns, String[] setValues, String[] fromTables, String[] whereColumns, String[] whereValues, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { String templateStr = ""; if (fromTables != null) { templateStr = ST_UPDATE_CORRELATED_QUERY_STYLE_ONE; } else { templateStr = ST_UPDATE_STYLE_ONE; } StringTemplate st = new StringTemplate(templateStr); return DialectUtils.getUpdateSQL(st, tableName, setColumns, setValues, fromTables, whereColumns, whereValues, qualifier, prefs, this); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsAccessMethods() */ public boolean supportsAccessMethods() { return false; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsAddForeignKeyConstraint() */ public boolean supportsAddForeignKeyConstraint() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsAddUniqueConstraint() */ public boolean supportsAddUniqueConstraint() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsAlterSequence() */ public boolean supportsAlterSequence() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsAutoIncrement() */ public boolean supportsAutoIncrement() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsCheckOptionsForViews() */ public boolean supportsCheckOptionsForViews() { return false; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsCreateIndex() */ public boolean supportsCreateIndex() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsCreateSequence() */ public boolean supportsCreateSequence() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsCreateTable() */ public boolean supportsCreateTable() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsCreateView() */ public boolean supportsCreateView() { return true; } public boolean supportsDropConstraint() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsDropIndex() */ public boolean supportsDropIndex() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsDropSequence() */ public boolean supportsDropSequence() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsDropView() */ public boolean supportsDropView() { return true; } public boolean supportsEmptyTables() { // TODO Auto-generated method stub return false; } public boolean supportsIndexes() { // TODO Auto-generated method stub return false; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsInsertInto() */ public boolean supportsInsertInto() { return true; } public boolean supportsMultipleRowInserts() { // TODO Auto-generated method stub return false; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsRenameTable() */ public boolean supportsRenameTable() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsRenameView() */ public boolean supportsRenameView() { return false; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsSequence() */ public boolean supportsSequence() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsSequenceInformation() */ public boolean supportsSequenceInformation() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsTablespace() */ public boolean supportsTablespace() { return false; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsUpdate() */ public boolean supportsUpdate() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsAddColumn() */ public boolean supportsAddColumn() { return true; } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#getQualifiedIdentifier(java.lang.String, * net.sourceforge.squirrel_sql.fw.dialects.DatabaseObjectQualifier, * net.sourceforge.squirrel_sql.fw.dialects.SqlGenerationPreferences) */ public String getQualifiedIdentifier(String identifier, DatabaseObjectQualifier qualifier, SqlGenerationPreferences prefs) { String schema = qualifier.getSchema(); String catalog = qualifier.getCatalog(); StringBuilder result = new StringBuilder(); if (!StringUtilities.isEmpty(catalog)) { result.append(DialectUtils.shapeIdentifier(catalog, prefs, this)); result.append("."); } if (!StringUtilities.isEmpty(schema)) { result.append(DialectUtils.shapeIdentifier(schema, prefs, this)); result.append("."); } result.append(DialectUtils.shapeIdentifier(identifier, prefs, this)); return result.toString(); } /** * @see net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect#supportsCorrelatedSubQuery() */ public boolean supportsCorrelatedSubQuery() { return true; } }

The table below shows all metrics for DB2DialectExt.java.

MetricValueDescription
BLOCKS106.00Number of blocks
BLOCK_COMMENT32.00Number of block comment lines
COMMENTS477.00Comment lines
COMMENT_DENSITY 0.94Comment density
COMPARISONS20.00Number of comparison operators
CYCLOMATIC102.00Cyclomatic complexity
DECL_COMMENTS78.00Comments in declarations
DOC_COMMENT410.00Number of javadoc comment lines
ELOC507.00Effective lines of code
EXEC_COMMENTS30.00Comments in executable code
EXITS69.00Procedure exits
FUNCTIONS82.00Number of function declarations
HALSTEAD_DIFFICULTY64.88Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY274.00Interface complexity
JAVA0001 1.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 1.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 1.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 1.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA007616.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 1.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 1.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011053.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 3.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 1.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 5.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 1.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 6.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 7.00JAVA0144 Line exceeds maximum M characters
JAVA01451837.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 0.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1322.00Number of lines in the source file
LINE_COMMENT35.00Number of line comments
LOC716.00Lines of code
LOGICAL_LINES295.00Number of statements
LOOPS 0.00Number of loops
NEST_DEPTH 3.00Maximum nesting depth
OPERANDS1625.00Number of operands
OPERATORS2620.00Number of operators
PARAMS182.00Number of formal parameter declarations
PROGRAM_LENGTH4245.00Halstead program length
PROGRAM_VOCAB595.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS92.00Number of return points from functions
SIZE45244.00Size of the file in bytes
UNIQUE_OPERANDS551.00Number of unique operands
UNIQUE_OPERATORS44.00Number of unique operators
WHITESPACE129.00Number of whitespace lines