HHH-6866 Removing commented out code and formatting. No functional changes.

This commit is contained in:
Hardy Ferentschik 2011-12-01 12:48:16 +01:00
parent 2e0e130cbe
commit 65b3e768fa
1 changed files with 129 additions and 153 deletions

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.dialect;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -38,6 +39,7 @@ import org.hibernate.type.StandardBasicTypes;
/**
* An SQL dialect for DB2.
*
* @author Gavin King
*/
public class DB2Dialect extends Dialect {
@ -99,7 +101,10 @@ public class DB2Dialect extends Dialect {
registerFunction( "julian_day", new StandardSQLFunction( "julian_day", StandardBasicTypes.INTEGER ) );
registerFunction( "microsecond", new StandardSQLFunction( "microsecond", StandardBasicTypes.INTEGER ) );
registerFunction("midnight_seconds", new StandardSQLFunction("midnight_seconds", StandardBasicTypes.INTEGER) );
registerFunction(
"midnight_seconds",
new StandardSQLFunction( "midnight_seconds", StandardBasicTypes.INTEGER )
);
registerFunction( "minute", new StandardSQLFunction( "minute", StandardBasicTypes.INTEGER ) );
registerFunction( "month", new StandardSQLFunction( "month", StandardBasicTypes.INTEGER ) );
registerFunction( "monthname", new StandardSQLFunction( "monthname", StandardBasicTypes.STRING ) );
@ -116,7 +121,10 @@ public class DB2Dialect extends Dialect {
registerFunction( "days", new StandardSQLFunction( "days", StandardBasicTypes.LONG ) );
registerFunction( "current_time", new NoArgSQLFunction( "current time", StandardBasicTypes.TIME, false ) );
registerFunction( "time", new StandardSQLFunction( "time", StandardBasicTypes.TIME ) );
registerFunction("current_timestamp", new NoArgSQLFunction("current timestamp", StandardBasicTypes.TIMESTAMP, false) );
registerFunction(
"current_timestamp",
new NoArgSQLFunction( "current timestamp", StandardBasicTypes.TIMESTAMP, false )
);
registerFunction( "timestamp", new StandardSQLFunction( "timestamp", StandardBasicTypes.TIMESTAMP ) );
registerFunction( "timestamp_iso", new StandardSQLFunction( "timestamp_iso", StandardBasicTypes.TIMESTAMP ) );
registerFunction( "week", new StandardSQLFunction( "week", StandardBasicTypes.INTEGER ) );
@ -169,18 +177,23 @@ public class DB2Dialect extends Dialect {
public String getAddColumnString() {
return "add column";
}
public boolean dropConstraints() {
return false;
}
public boolean supportsIdentityColumns() {
return true;
}
public String getIdentitySelectString() {
return "values identity_val_local()";
}
public String getIdentityColumnString() {
return "generated by default as identity"; //not null ... (start with 1) is implicit
}
public String getIdentityInsertString() {
return "default";
}
@ -188,9 +201,11 @@ public class DB2Dialect extends Dialect {
public String getSequenceNextValString(String sequenceName) {
return "values nextval for " + sequenceName;
}
public String getCreateSequenceString(String sequenceName) {
return "create sequence " + sequenceName;
}
public String getDropSequenceString(String sequenceName) {
return "drop sequence " + sequenceName + " restrict";
}
@ -210,58 +225,11 @@ public class DB2Dialect extends Dialect {
public boolean supportsLimit() {
return true;
}
public boolean supportsVariableLimit() {
return false;
}
// /**
// * Render the <tt>rownumber() over ( .... ) as rownumber_,</tt>
// * bit, that goes in the select list
// */
// private String getRowNumber(String sql) {
// StringBuffer rownumber = new StringBuffer(50)
// .append("rownumber() over(");
//
// int orderByIndex = sql.toLowerCase().indexOf("order by");
//
// if ( orderByIndex>0 && !hasDistinct(sql) ) {
// rownumber.append( sql.substring(orderByIndex) );
// }
//
// rownumber.append(") as rownumber_,");
//
// return rownumber.toString();
// }
//
// public String getLimitString(String sql, boolean hasOffset) {
// int startOfSelect = sql.toLowerCase().indexOf("select");
//
// StringBuffer pagingSelect = new StringBuffer( sql.length()+100 )
// .append( sql.substring(0, startOfSelect) ) // add the comment
// .append("select * from ( select ") // nest the main query in an outer select
// .append( getRowNumber(sql) ); // add the rownnumber bit into the outer query select list
//
// if ( hasDistinct(sql) ) {
// pagingSelect.append(" row_.* from ( ") // add another (inner) nested select
// .append( sql.substring(startOfSelect) ) // add the main query
// .append(" ) as row_"); // close off the inner nested select
// }
// else {
// pagingSelect.append( sql.substring( startOfSelect + 6 ) ); // add the main query
// }
//
// pagingSelect.append(" ) as temp_ where rownumber_ ");
//
// //add the restriction to the outer select
// if (hasOffset) {
// pagingSelect.append("between ?+1 and ?");
// }
// else {
// pagingSelect.append("<= ?");
// }
//
// return pagingSelect.toString();
// }
public String getLimitString(String sql, int offset, int limit) {
if ( offset == 0 ) {
return sql + " fetch first " + limit + " rows only";
@ -290,10 +258,6 @@ public String getLimitString(String sql, int offset, int limit) {
public int convertToFirstRowValue(int zeroBasedFirstResult) {
return zeroBasedFirstResult;
}
//
// private static boolean hasDistinct(String sql) {
// return sql.toLowerCase().indexOf("select distinct")>=0;
// }
public String getForUpdateString() {
return " for read only with rs";
@ -340,8 +304,20 @@ public String getLimitString(String sql, int offset, int limit) {
public static void main(String[] args) {
System.out.println( new DB2Dialect().getLimitString( "/*foo*/ select * from foos", true ) );
System.out.println( new DB2Dialect().getLimitString( "/*foo*/ select distinct * from foos", true ) );
System.out.println( new DB2Dialect().getLimitString("/*foo*/ select * from foos foo order by foo.bar, foo.baz", true) );
System.out.println( new DB2Dialect().getLimitString("/*foo*/ select distinct * from foos foo order by foo.bar, foo.baz", true) );
System.out
.println(
new DB2Dialect().getLimitString(
"/*foo*/ select * from foos foo order by foo.bar, foo.baz",
true
)
);
System.out
.println(
new DB2Dialect().getLimitString(
"/*foo*/ select distinct * from foos foo order by foo.bar, foo.baz",
true
)
);
}
public boolean supportsUnionAll() {