Code example for DatabaseMetaData

Methods: getDatabaseMajorVersiongetDatabaseMinorVersiongetDatabaseProductName

0
    private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
                                                                       StandardDialectResolver.class.getName());
 
	@Override 
    protected Dialect resolveDialectInternal(DatabaseMetaData metaData) throws SQLException {
		String databaseName = metaData.getDatabaseProductName();
		int databaseMajorVersion = metaData.getDatabaseMajorVersion();
 
		if ( "CUBRID".equalsIgnoreCase( databaseName ) ) {
			return new CUBRIDDialect(); 
		} 
 
		if ( "HSQL Database Engine".equals( databaseName ) ) {
			return new HSQLDialect(); 
		} 
 
		if ( "H2".equals( databaseName ) ) {
			return new H2Dialect(); 
		} 
 
		if ( "MySQL".equals( databaseName ) ) {
			return new MySQLDialect(); 
		} 
 
		if ( "PostgreSQL".equals( databaseName ) ) {
			final int databaseMinorVersion = metaData.getDatabaseMinorVersion();
			if ( databaseMajorVersion > 8 || ( databaseMajorVersion == 8 && databaseMinorVersion >= 2 ) ) {
				return new PostgreSQL82Dialect(); 
			} 
			return new PostgreSQL81Dialect(); 
		} 
 
		if ( "Apache Derby".equals( databaseName ) ) {
			final int databaseMinorVersion = metaData.getDatabaseMinorVersion();
            if ( databaseMajorVersion > 10 || ( databaseMajorVersion == 10 && databaseMinorVersion >= 7 ) ) {
				return new DerbyTenSevenDialect(); 
			} 
			else if ( databaseMajorVersion == 10 && databaseMinorVersion == 6 ) {
				return new DerbyTenSixDialect(); 
			} 
			else if ( databaseMajorVersion == 10 && databaseMinorVersion == 5 ) {
				return new DerbyTenFiveDialect(); 
			} 
			else { 
				return new DerbyDialect(); 
			} 
		} 
 
		if ( "ingres".equalsIgnoreCase( databaseName ) ) {
            switch ( databaseMajorVersion ) {
                case 9: 
                    int databaseMinorVersion = metaData.getDatabaseMinorVersion();
                    if (databaseMinorVersion > 2) {
                        return new Ingres9Dialect(); 
                    } 
                    return new IngresDialect(); 
                case 10: