Java Code Examples for org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder

The following examples show how to use org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: quarkus   Source File: QuarkusPostgreSQL10Dialect.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
        throws SQLException {
    // PostgreSQL considers unquoted identifiers lowercase
    // https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
    builder.setUnquotedCaseStrategy(IdentifierCaseStrategy.LOWER);
    // then delegate to the database metadata driver identifier casing selection
    // which can override these settings.
    return super.buildIdentifierHelper(builder, dbMetaData);
}
 
Example 2
Source Project: quarkus   Source File: QuarkusH2Dialect.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
        throws SQLException {
    // H2 by default consider identifiers as upper case
    // unless DATABASE_TO_UPPER=false but that's not the default
    // and Thomas Mueller says it's normal ANSI-SQL SQL-92 behavior
    // http://h2-database.66688.n3.nabble.com/Case-of-column-name-td3485519.html
    // http://www.h2database.com/html/grammar.html#name
    // DATABASE_TO_LOWER=TRUE will come with H2's next version as of Feb 2019 but only for PostgreSQL compat
    builder.setUnquotedCaseStrategy(IdentifierCaseStrategy.UPPER);
    // then delegate to the database metadata driver identifier casing selection
    // which can override these settings.
    return super.buildIdentifierHelper(builder, dbMetaData);
}
 
Example 3
Source Project: quarkus   Source File: QuarkusPostgreSQL95Dialect.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData)
        throws SQLException {
    // PostgreSQL considers unquoted identifiers lowercase
    // https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
    builder.setUnquotedCaseStrategy(IdentifierCaseStrategy.LOWER);
    // then delegate to the database metadata driver identifier casing selection
    // which can override these settings.
    return super.buildIdentifierHelper(builder, dbMetaData);
}
 
Example 4
Source Project: lams   Source File: JdbcEnvironmentImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor form used when the JDBC {@link java.sql.DatabaseMetaData} is not available.
 *
 * @param serviceRegistry The service registry
 * @param dialect The resolved dialect.
 */
public JdbcEnvironmentImpl(ServiceRegistryImplementor serviceRegistry, Dialect dialect) {
	this.dialect = dialect;

	final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class );

	NameQualifierSupport nameQualifierSupport = dialect.getNameQualifierSupport();
	if ( nameQualifierSupport == null ) {
		// assume both catalogs and schemas are supported
		nameQualifierSupport = NameQualifierSupport.BOTH;
	}
	this.nameQualifierSupport = nameQualifierSupport;

	this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, logWarnings( cfgService, dialect ) );

	final IdentifierHelperBuilder identifierHelperBuilder = IdentifierHelperBuilder.from( this );
	identifierHelperBuilder.setGloballyQuoteIdentifiers( globalQuoting( cfgService ) );
	identifierHelperBuilder.setSkipGlobalQuotingForColumnDefinitions( globalQuotingSkippedForColumnDefinitions( cfgService ) );
	identifierHelperBuilder.setAutoQuoteKeywords( autoKeywordQuoting( cfgService ) );
	identifierHelperBuilder.setNameQualifierSupport( nameQualifierSupport );

	IdentifierHelper identifierHelper = null;
	ExtractedDatabaseMetaDataImpl.Builder dbMetaDataBuilder = new ExtractedDatabaseMetaDataImpl.Builder( this );
	try {
		identifierHelper = dialect.buildIdentifierHelper( identifierHelperBuilder, null );
		dbMetaDataBuilder.setSupportsNamedParameters( dialect.supportsNamedParameters( null ) );
	}
	catch (SQLException sqle) {
		// should never ever happen
		log.debug( "There was a problem accessing DatabaseMetaData in building the JdbcEnvironment", sqle );
	}
	if ( identifierHelper == null ) {
		identifierHelper = identifierHelperBuilder.build();
	}
	this.identifierHelper = identifierHelper;

	this.extractedMetaDataSupport = dbMetaDataBuilder.build();

	this.currentCatalog = identifierHelper.toIdentifier(
			cfgService.getSetting( AvailableSettings.DEFAULT_CATALOG, StandardConverters.STRING )
	);
	this.currentSchema = Identifier.toIdentifier(
			cfgService.getSetting( AvailableSettings.DEFAULT_SCHEMA, StandardConverters.STRING )
	);

	this.qualifiedObjectNameFormatter = new QualifiedObjectNameFormatterStandardImpl( nameQualifierSupport );

	this.lobCreatorBuilder = LobCreatorBuilderImpl.makeLobCreatorBuilder();
}
 
Example 5
Source Project: lams   Source File: JdbcEnvironmentImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor form used from testing
 *
 * @param dialect The dialect
 */
public JdbcEnvironmentImpl(DatabaseMetaData databaseMetaData, Dialect dialect) throws SQLException {
	this.dialect = dialect;

	this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, false );

	this.extractedMetaDataSupport = new ExtractedDatabaseMetaDataImpl.Builder( this )
			.apply( databaseMetaData )
			.setSupportsNamedParameters( databaseMetaData.supportsNamedParameters() )
			.build();

	NameQualifierSupport nameQualifierSupport = dialect.getNameQualifierSupport();
	if ( nameQualifierSupport == null ) {
		nameQualifierSupport = determineNameQualifierSupport( databaseMetaData );
	}
	this.nameQualifierSupport = nameQualifierSupport;

	final IdentifierHelperBuilder identifierHelperBuilder = IdentifierHelperBuilder.from( this );
	identifierHelperBuilder.setNameQualifierSupport( nameQualifierSupport );
	IdentifierHelper identifierHelper = null;
	try {
		identifierHelper = dialect.buildIdentifierHelper( identifierHelperBuilder, databaseMetaData );
	}
	catch (SQLException sqle) {
		// should never ever happen
		log.debug( "There was a problem accessing DatabaseMetaData in building the JdbcEnvironment", sqle );
	}
	if ( identifierHelper == null ) {
		identifierHelper = identifierHelperBuilder.build();
	}
	this.identifierHelper = identifierHelper;

	this.currentCatalog = null;
	this.currentSchema = null;

	this.qualifiedObjectNameFormatter = new QualifiedObjectNameFormatterStandardImpl(
			nameQualifierSupport,
			databaseMetaData
	);

	this.lobCreatorBuilder = LobCreatorBuilderImpl.makeLobCreatorBuilder();
}
 
Example 6
Source Project: lams   Source File: JdbcEnvironmentImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * The main constructor form.  Builds a JdbcEnvironment using the available DatabaseMetaData
 *
 * @param serviceRegistry The service registry
 * @param dialect The resolved dialect
 * @param databaseMetaData The available DatabaseMetaData
 *
 * @throws SQLException
 */
public JdbcEnvironmentImpl(
		ServiceRegistryImplementor serviceRegistry,
		Dialect dialect,
		DatabaseMetaData databaseMetaData) throws SQLException {
	this.dialect = dialect;

	final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class );

	this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, logWarnings( cfgService, dialect ) );

	this.extractedMetaDataSupport = new ExtractedDatabaseMetaDataImpl.Builder( this )
			.apply( databaseMetaData )
			.setConnectionSchemaName( determineCurrentSchemaName( databaseMetaData, serviceRegistry, dialect ) )
			.setSupportsNamedParameters(dialect.supportsNamedParameters(databaseMetaData))
			.build();

	NameQualifierSupport nameQualifierSupport = dialect.getNameQualifierSupport();
	if ( nameQualifierSupport == null ) {
		nameQualifierSupport = determineNameQualifierSupport( databaseMetaData );
	}
	this.nameQualifierSupport = nameQualifierSupport;

	final IdentifierHelperBuilder identifierHelperBuilder = IdentifierHelperBuilder.from( this );
	identifierHelperBuilder.setGloballyQuoteIdentifiers( globalQuoting( cfgService ) );
	identifierHelperBuilder.setSkipGlobalQuotingForColumnDefinitions( globalQuotingSkippedForColumnDefinitions( cfgService ) );
	identifierHelperBuilder.setAutoQuoteKeywords( autoKeywordQuoting( cfgService ) );
	identifierHelperBuilder.setNameQualifierSupport( nameQualifierSupport );
	IdentifierHelper identifierHelper = null;
	try {
		identifierHelper = dialect.buildIdentifierHelper( identifierHelperBuilder, databaseMetaData );
	}
	catch (SQLException sqle) {
		// should never ever happen
		log.debug( "There was a problem accessing DatabaseMetaData in building the JdbcEnvironment", sqle );
	}
	if ( identifierHelper == null ) {
		identifierHelper = identifierHelperBuilder.build();
	}
	this.identifierHelper = identifierHelper;

	// and that current-catalog and current-schema happen after it
	this.currentCatalog = identifierHelper.toIdentifier( extractedMetaDataSupport.getConnectionCatalogName() );
	this.currentSchema = identifierHelper.toIdentifier( extractedMetaDataSupport.getConnectionSchemaName() );

	this.qualifiedObjectNameFormatter = new QualifiedObjectNameFormatterStandardImpl(
			nameQualifierSupport,
			databaseMetaData
	);

	this.typeInfoSet.addAll( TypeInfo.extractTypeInfo( databaseMetaData ) );

	this.lobCreatorBuilder = LobCreatorBuilderImpl.makeLobCreatorBuilder(
			cfgService.getSettings(),
			databaseMetaData.getConnection()
	);
}
 
Example 7
Source Project: keycloak   Source File: DelegatingDialect.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IdentifierHelper buildIdentifierHelper(
        IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData) throws SQLException {
    return getInstance().buildIdentifierHelper(builder, dbMetaData);
}
 
Example 8
Source Project: lams   Source File: DerbyDialect.java    License: GNU General Public License v2.0 3 votes vote down vote up
@Override
public IdentifierHelper buildIdentifierHelper(
		IdentifierHelperBuilder builder, DatabaseMetaData dbMetaData) throws SQLException {
	builder.applyIdentifierCasing( dbMetaData );

	builder.applyReservedWords( dbMetaData );

	builder.applyReservedWords( getKeywords() );

	builder.setNameQualifierSupport( getNameQualifierSupport() );

	return builder.build();
}
 
Example 9
Source Project: lams   Source File: Dialect.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Build the IdentifierHelper indicated by this Dialect for handling identifier conversions.
 * Returning {@code null} is allowed and indicates that Hibernate should fallback to building a
 * "standard" helper.  In the fallback path, any changes made to the IdentifierHelperBuilder
 * during this call will still be incorporated into the built IdentifierHelper.
 * <p/>
 * The incoming builder will have the following set:<ul>
 *     <li>{@link IdentifierHelperBuilder#isGloballyQuoteIdentifiers()}</li>
 *     <li>{@link IdentifierHelperBuilder#getUnquotedCaseStrategy()} - initialized to UPPER</li>
 *     <li>{@link IdentifierHelperBuilder#getQuotedCaseStrategy()} - initialized to MIXED</li>
 * </ul>
 * <p/>
 * By default Hibernate will do the following:<ul>
 *     <li>Call {@link IdentifierHelperBuilder#applyIdentifierCasing(DatabaseMetaData)}
 *     <li>Call {@link IdentifierHelperBuilder#applyReservedWords(DatabaseMetaData)}
 *     <li>Applies {@link AnsiSqlKeywords#sql2003()} as reserved words</li>
 *     <li>Applies the {#link #sqlKeywords} collected here as reserved words</li>
 *     <li>Applies the Dialect's NameQualifierSupport, if it defines one</li>
 * </ul>
 *
 * @param builder A semi-configured IdentifierHelper builder.
 * @param dbMetaData Access to the metadata returned from the driver if needed and if available.  WARNING: may be {@code null}
 *
 * @return The IdentifierHelper instance to use, or {@code null} to indicate Hibernate should use its fallback path
 *
 * @throws SQLException Accessing the DatabaseMetaData can throw it.  Just re-throw and Hibernate will handle.
 *
 * @see #getNameQualifierSupport()
 */
public IdentifierHelper buildIdentifierHelper(
		IdentifierHelperBuilder builder,
		DatabaseMetaData dbMetaData) throws SQLException {
	builder.applyIdentifierCasing( dbMetaData );

	builder.applyReservedWords( dbMetaData );
	builder.applyReservedWords( AnsiSqlKeywords.INSTANCE.sql2003() );
	builder.applyReservedWords( sqlKeywords );

	builder.setNameQualifierSupport( getNameQualifierSupport() );

	return builder.build();
}