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

The following examples show how to use org.hibernate.engine.jdbc.env.spi.SchemaNameResolver. 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: lams   Source File: JdbcEnvironmentImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private String determineCurrentSchemaName(
		DatabaseMetaData databaseMetaData,
		ServiceRegistry serviceRegistry,
		Dialect dialect) throws SQLException {
	final SchemaNameResolver schemaNameResolver;

	final Object setting = serviceRegistry.getService( ConfigurationService.class ).getSettings().get( SCHEMA_NAME_RESOLVER );
	if ( setting == null ) {
		schemaNameResolver = dialect.getSchemaNameResolver();
	}
	else {
		schemaNameResolver = serviceRegistry.getService( StrategySelector.class ).resolveDefaultableStrategy(
				SchemaNameResolver.class,
				setting,
				dialect.getSchemaNameResolver()
		);
	}

	try {
		return schemaNameResolver.resolveSchemaName( databaseMetaData.getConnection(), dialect );
	}
	catch (Exception e) {
		log.debug( "Unable to resolve connection default schema", e );
		return null;
	}
}
 
Example 2
private SchemaNameResolver determineAppropriateResolverDelegate(Connection connection) {
	// unfortunately Connection#getSchema is only available in Java 1.7 and above
	// and Hibernate still baselines on 1.6.  So for now, use reflection and
	// leverage the Connection#getSchema method if it is available.
	try {
		final Class<? extends Connection> jdbcConnectionClass = connection.getClass();
		final Method getSchemaMethod = jdbcConnectionClass.getMethod( "getSchema" );
		if ( getSchemaMethod != null && getSchemaMethod.getReturnType().equals( String.class ) ) {
			try {
				// If the JDBC driver does not implement the Java 7 spec, but the JRE is Java 7
				// then the getSchemaMethod is not null but the call to getSchema() throws an java.lang.AbstractMethodError
				connection.getSchema();
				return new SchemaNameResolverJava17Delegate();
			}
			catch (java.lang.AbstractMethodError e) {
				log.debugf( "Unable to use Java 1.7 Connection#getSchema" );
				return SchemaNameResolverFallbackDelegate.INSTANCE;
			}
		}
		else {
			log.debugf( "Unable to use Java 1.7 Connection#getSchema" );
			return SchemaNameResolverFallbackDelegate.INSTANCE;
		}
	}
	catch (Exception ignore) {
		log.debugf(
				"Unable to use Java 1.7 Connection#getSchema : An error occurred trying to resolve the connection default schema resolver: "
						+ ignore.getMessage() );
		return SchemaNameResolverFallbackDelegate.INSTANCE;
	}
}
 
Example 3
@Override
public String resolveSchemaName(Connection connection, Dialect dialect) throws SQLException {
	// NOTE: delegate should not be cached in DefaultSchemaNameResolver because,
	//       in the case of multiple data sources, there may be a data source that
	//       requires a different delegate. See HHH-12392.
	final SchemaNameResolver delegate = determineAppropriateResolverDelegate( connection );
	return delegate.resolveSchemaName( connection, dialect );
}
 
Example 4
@Override
public SchemaNameResolver getSchemaNameResolver() {
  throw new UnsupportedOperationException(
      "No schema name resolver supported by " + getClass().getName());
}
 
Example 5
Source Project: keycloak   Source File: DelegatingDialect.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SchemaNameResolver getSchemaNameResolver() {
    return getInstance().getSchemaNameResolver();
}
 
Example 6
Source Project: lams   Source File: Dialect.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the strategy for determining the schema name of a Connection
 *
 * @return The schema name resolver strategy
 */
public SchemaNameResolver getSchemaNameResolver() {
	return DefaultSchemaNameResolver.INSTANCE;
}