org.hibernate.cfg.reveng.dialect.H2MetaDataDialect Maven / Gradle / Ivy
package org.hibernate.cfg.reveng.dialect;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.tool.util.ReflectHelper;
/**
* MetaData dialect that work around tweaks in the H2 database.
*
* @author Max Rydahl Andersen
*
*/
public class H2MetaDataDialect extends JDBCMetaDataDialect {
private static boolean understandsCatalogName = true;
public H2MetaDataDialect() {
super();
try {
Class> constants = ReflectHelper.classForName( "org.h2.engine.Constants" );
Integer build = (Integer)constants.getDeclaredField( "BUILD_ID" ).get( null );
if ( build.intValue() < 55 ) {
understandsCatalogName = false;
}
}
catch( Throwable e ) {
// ignore (probably H2 not in the classpath)
}
}
protected void putTablePart(Map element, ResultSet tableRs) throws SQLException {
super.putTablePart( element, tableRs );
if ( !understandsCatalogName ) {
element.put( "TABLE_CAT", null );
}
}
protected void putExportedKeysPart(Map element, ResultSet rs) throws SQLException {
super.putExportedKeysPart( element, rs );
if ( !understandsCatalogName ) {
element.put( "PKTABLE_CAT", null );
}
}
public Iterator