org.hibernate.engine.jdbc.env.spi.NameQualifierSupport Java Examples

The following examples show how to use org.hibernate.engine.jdbc.env.spi.NameQualifierSupport. 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: QualifiedObjectNameFormatterStandardImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Format buildFormat(
		NameQualifierSupport nameQualifierSupport,
		String catalogSeparator,
		boolean catalogAtEnd) {
	switch ( nameQualifierSupport ) {
		case NONE: {
			return NoQualifierSupportFormat.INSTANCE;
		}
		case CATALOG: {
			return catalogAtEnd
					? new NameCatalogFormat( catalogSeparator )
					: new CatalogNameFormat( catalogSeparator );
		}
		case SCHEMA: {
			return SchemaNameFormat.INSTANCE;
		}
		default: {
			return catalogAtEnd
					? new SchemaNameCatalogFormat( catalogSeparator )
					: new CatalogSchemaNameFormat( catalogSeparator );
		}
	}
}
 
Example #2
Source File: JdbcEnvironmentImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private NameQualifierSupport determineNameQualifierSupport(DatabaseMetaData databaseMetaData) throws SQLException {
	final boolean supportsCatalogs = databaseMetaData.supportsCatalogsInTableDefinitions();
	final boolean supportsSchemas = databaseMetaData.supportsSchemasInTableDefinitions();

	if ( supportsCatalogs && supportsSchemas ) {
		return NameQualifierSupport.BOTH;
	}
	else if ( supportsCatalogs ) {
		return NameQualifierSupport.CATALOG;
	}
	else if ( supportsSchemas ) {
		return NameQualifierSupport.SCHEMA;
	}
	else {
		return NameQualifierSupport.NONE;
	}
}
 
Example #3
Source File: NormalizingIdentifierHelperImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public NormalizingIdentifierHelperImpl(
		JdbcEnvironment jdbcEnvironment,
		NameQualifierSupport nameQualifierSupport,
		boolean globallyQuoteIdentifiers,
		boolean globallyQuoteIdentifiersSkipColumnDefinitions,
		boolean autoQuoteKeywords,
		Set<String> reservedWords,
		IdentifierCaseStrategy unquotedCaseStrategy,
		IdentifierCaseStrategy quotedCaseStrategy) {
	this.jdbcEnvironment = jdbcEnvironment;
	this.nameQualifierSupport = nameQualifierSupport;
	this.globallyQuoteIdentifiers = globallyQuoteIdentifiers;
	this.globallyQuoteIdentifiersSkipColumnDefinitions = globallyQuoteIdentifiersSkipColumnDefinitions;
	this.autoQuoteKeywords = autoQuoteKeywords;
	if ( reservedWords != null ) {
		this.reservedWords.addAll( reservedWords );
	}
	this.unquotedCaseStrategy = unquotedCaseStrategy == null ? IdentifierCaseStrategy.UPPER : unquotedCaseStrategy;
	this.quotedCaseStrategy = quotedCaseStrategy == null ? IdentifierCaseStrategy.MIXED : quotedCaseStrategy;
}
 
Example #4
Source File: QualifiedObjectNameFormatterStandardImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public QualifiedObjectNameFormatterStandardImpl(
		NameQualifierSupport nameQualifierSupport,
		DatabaseMetaData databaseMetaData) throws SQLException {
	this(
			nameQualifierSupport,
			databaseMetaData.getCatalogSeparator(),
			!databaseMetaData.isCatalogAtStart()
	);
}
 
Example #5
Source File: TestingRegistryRule.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override @SuppressWarnings("unchecked")
public <R extends Service> R getService(Class<R> serviceRole) {
    if ( serviceRole == VertxInstance.class ) {
        return (R) vertxService;
    }
    else if ( serviceRole == JdbcEnvironment.class ) {
        return (R) new JdbcEnvironment() {
            @Override
            public Dialect getDialect() {
                return new MySQL8Dialect();
            }

            @Override
            public ExtractedDatabaseMetaData getExtractedDatabaseMetaData() {
                return null;
            }

            @Override
            public Identifier getCurrentCatalog() {
                return null;
            }

            @Override
            public Identifier getCurrentSchema() {
                return null;
            }

            @Override
            public QualifiedObjectNameFormatter getQualifiedObjectNameFormatter() {
                return null;
            }

            @Override
            public IdentifierHelper getIdentifierHelper() {
                return null;
            }

            @Override
            public NameQualifierSupport getNameQualifierSupport() {
                return null;
            }

            @Override
            public SqlExceptionHelper getSqlExceptionHelper() {
                return null;
            }

            @Override
            public LobCreatorBuilder getLobCreatorBuilder() {
                return null;
            }

            @Override
            public TypeInfo getTypeInfoForJdbcCode(int jdbcTypeCode) {
                return null;
            }
        };
    }
    else {
        throw new IllegalArgumentException( "This is a mock service - need to explicitly handle any service we might need during testing" );
    }
}
 
Example #6
Source File: QualifiedObjectNameFormatterStandardImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public QualifiedObjectNameFormatterStandardImpl(
		NameQualifierSupport nameQualifierSupport,
		String catalogSeparator,
		boolean catalogAtEnd) {
	this.format = buildFormat( nameQualifierSupport, catalogSeparator, catalogAtEnd );
}
 
Example #7
Source File: QualifiedObjectNameFormatterStandardImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public QualifiedObjectNameFormatterStandardImpl(NameQualifierSupport nameQualifierSupport) {
	// most dbs simply do <catalog>.<schema>.<name>
	this( nameQualifierSupport, ".", false );
}
 
Example #8
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 #9
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 #10
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()
	);
}
 
Example #11
Source File: JdbcEnvironmentImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public NameQualifierSupport getNameQualifierSupport() {
	return nameQualifierSupport;
}
 
Example #12
Source File: HSQLDialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public NameQualifierSupport getNameQualifierSupport() {
	return NameQualifierSupport.SCHEMA;
}
 
Example #13
Source File: AbstractHANADialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public NameQualifierSupport getNameQualifierSupport() {
	return NameQualifierSupport.SCHEMA;
}
 
Example #14
Source File: DelegatingDialect.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public NameQualifierSupport getNameQualifierSupport() {
    return getInstance().getNameQualifierSupport();
}
 
Example #15
Source File: Dialect.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * By default interpret this based on DatabaseMetaData.
 *
 * @return
 */
public NameQualifierSupport getNameQualifierSupport() {
	return null;
}