Java Code Examples for org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder#from()

The following examples show how to use org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder#from() . 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 File: JdbcEnvironmentImpl.java    From lams with 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 2
Source File: JdbcEnvironmentImpl.java    From lams with 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 3
Source File: JdbcEnvironmentImpl.java    From lams with 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()
	);
}