[hibernate-commits] Hibernate SVN: r16643 - core/trunk/core/src/main/java/org/hibernate/dialect.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Jun 1 11:14:58 EDT 2009


Author: steve.ebersole at jboss.com
Date: 2009-06-01 11:14:58 -0400 (Mon, 01 Jun 2009)
New Revision: 16643

Modified:
   core/trunk/core/src/main/java/org/hibernate/dialect/H2Dialect.java
Log:
HHH-3401 - H2 Database Dialect Fixes


Modified: core/trunk/core/src/main/java/org/hibernate/dialect/H2Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/H2Dialect.java	2009-05-31 23:41:31 UTC (rev 16642)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/H2Dialect.java	2009-06-01 15:14:58 UTC (rev 16643)
@@ -20,7 +20,6 @@
  * Free Software Foundation, Inc.
  * 51 Franklin Street, Fifth Floor
  * Boston, MA  02110-1301  USA
- *
  */
 package org.hibernate.dialect;
 
@@ -40,30 +39,32 @@
  * A dialect compatible with the H2 database.
  * 
  * @author Thomas Mueller
- *
  */
 public class H2Dialect extends Dialect {
 
     private String querySequenceString;
+
     public H2Dialect() {
         super();
-               
-        querySequenceString = "select sequence_name from information_schema.sequences";
-        try {
-        	// HHH-2300
-            Class constants = ReflectHelper.classForName( "org.h2.engine.Constants" );
-            Integer build = (Integer)constants.getDeclaredField("BUILD_ID" ).get(null);
-            int buildid = build.intValue();
-            if(buildid < 32) {
-                querySequenceString = "select name from information_schema.sequences";
-            }
-        } catch(Throwable e) {
-            // ignore (probably H2 not in the classpath)
-        }
-        registerColumnType(Types.BOOLEAN, "boolean");
+
+		querySequenceString = "select sequence_name from information_schema.sequences";
+		try {
+			// HHH-2300
+			Class constants = ReflectHelper.classForName( "org.h2.engine.Constants" );
+			Integer build = ( Integer ) constants.getDeclaredField( "BUILD_ID" ).get( null );
+			int buildid = build.intValue();
+			if ( buildid < 32 ) {
+				querySequenceString = "select name from information_schema.sequences";
+			}
+		}
+		catch ( Throwable e ) {
+			// ignore (probably H2 not in the classpath)
+		}
+
+		registerColumnType(Types.BOOLEAN, "boolean");
         registerColumnType(Types.BIGINT, "bigint");
         registerColumnType(Types.BINARY, "binary");
-        registerColumnType(Types.BIT, "bit");
+        registerColumnType(Types.BIT, "boolean");
         registerColumnType(Types.CHAR, "char($l)");
         registerColumnType(Types.DATE, "date");
         registerColumnType(Types.DECIMAL, "decimal($p,$s)");
@@ -165,7 +166,7 @@
 //        registerFunction("minute", new StandardSQLFunction("minute", Hibernate.INTEGER));
 //        registerFunction("month", new StandardSQLFunction("month", Hibernate.INTEGER));
         registerFunction("monthname", new StandardSQLFunction("monthname", Hibernate.STRING));
-        registerFunction("quater", new StandardSQLFunction("quater", Hibernate.INTEGER));
+        registerFunction("quarter", new StandardSQLFunction("quarter", Hibernate.INTEGER));
 //        registerFunction("second", new StandardSQLFunction("second", Hibernate.INTEGER));
         registerFunction("week", new StandardSQLFunction("week", Hibernate.INTEGER));
 //        registerFunction("year", new StandardSQLFunction("year", Hibernate.INTEGER));
@@ -179,7 +180,6 @@
         registerFunction("user", new NoArgSQLFunction("user", Hibernate.STRING));
 
         getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
-
     }
 
     public String getAddColumnString() {
@@ -215,11 +215,11 @@
     }
 
     public String getLimitString(String sql, boolean hasOffset) {
-        return new StringBuffer(sql.length() + 20).
-            append(sql).
-            append(hasOffset ? " limit ? offset ?" : " limit ?").
-            toString();
-    }
+		return new StringBuffer( sql.length() + 20 )
+				.append( sql )
+				.append( hasOffset ? " limit ? offset ?" : " limit ?" )
+				.toString();
+	}
     
     public boolean bindLimitParametersInReverseOrder() {
         return true;
@@ -266,7 +266,6 @@
     }
 
     private static ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter() {
-
         /**
          * Extract the name of the violated constraint from the given SQLException.
          *
@@ -274,19 +273,18 @@
          * @return The extracted constraint name.
          */
         public String extractConstraintName(SQLException sqle) {
-            String constraintName = null;
-            // 23000: Check constraint violation: {0}
-            // 23001: Unique index or primary key violation: {0}
-            if(sqle.getSQLState().startsWith("23")) {
-                String message = sqle.getMessage();
-                int idx = message.indexOf("violation: ");
-                if(idx > 0) {
-                    constraintName = message.substring(idx + "violation: ".length());
-                }
-            }
-            return constraintName;
+			String constraintName = null;
+			// 23000: Check constraint violation: {0}
+			// 23001: Unique index or primary key violation: {0}
+			if ( sqle.getSQLState().startsWith( "23" ) ) {
+				final String message = sqle.getMessage();
+				int idx = message.indexOf( "violation: " );
+				if ( idx > 0 ) {
+					constraintName = message.substring( idx + "violation: ".length() );
+				}
+			}
+			return constraintName;
         }
-
     };
 
     public boolean supportsTemporaryTables() {
@@ -319,4 +317,4 @@
 	public boolean supportsLobValueChangePropogation() {
 		return false;
 	}
-}
\ No newline at end of file
+}




More information about the hibernate-commits mailing list