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

The following examples show how to use org.hibernate.engine.jdbc.env.spi.SchemaNameResolver. 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 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
Source File: DefaultSchemaNameResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: DefaultSchemaNameResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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
Source File: SpannerDialect.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public SchemaNameResolver getSchemaNameResolver() {
  throw new UnsupportedOperationException(
      "No schema name resolver supported by " + getClass().getName());
}
 
Example #5
Source File: DelegatingDialect.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public SchemaNameResolver getSchemaNameResolver() {
    return getInstance().getSchemaNameResolver();
}
 
Example #6
Source File: Dialect.java    From lams with 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;
}