forked from hibernate/hibernate-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-7913 - Schema replacement in <subselect> / @subselect
- Loading branch information
Showing
8 changed files
with
451 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...core/src/main/java/org/hibernate/persister/entity/ExplicitSqlStringGenerationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.persister.entity; | ||
|
||
import org.hibernate.boot.model.naming.Identifier; | ||
import org.hibernate.boot.model.relational.QualifiedName; | ||
import org.hibernate.boot.model.relational.QualifiedSequenceName; | ||
import org.hibernate.boot.model.relational.QualifiedTableName; | ||
import org.hibernate.boot.model.relational.SqlStringGenerationContext; | ||
import org.hibernate.dialect.Dialect; | ||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; | ||
import org.hibernate.engine.jdbc.env.spi.QualifiedObjectNameFormatter; | ||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
|
||
/** | ||
* SqlStringGenerationContext implementation with support for overriding the | ||
* default catalog and schema | ||
* | ||
* @author Steve Ebersole | ||
*/ | ||
public class ExplicitSqlStringGenerationContext implements SqlStringGenerationContext { | ||
private final SessionFactoryImplementor factory; | ||
private final Identifier defaultCatalog; | ||
private final Identifier defaultSchema; | ||
|
||
public ExplicitSqlStringGenerationContext( | ||
String defaultCatalog, | ||
String defaultSchema, | ||
SessionFactoryImplementor factory) { | ||
this.factory = factory; | ||
this.defaultCatalog = defaultCatalog != null | ||
? toIdentifier( defaultCatalog ) | ||
: toIdentifier( factory.getSessionFactoryOptions().getDefaultCatalog() ); | ||
this.defaultSchema = defaultSchema != null | ||
? toIdentifier( defaultSchema ) | ||
: toIdentifier( factory.getSessionFactoryOptions().getDefaultSchema() ); | ||
} | ||
|
||
@Override | ||
public Dialect getDialect() { | ||
return factory.getJdbcServices().getDialect(); | ||
} | ||
|
||
@Override | ||
public Identifier toIdentifier(String text) { | ||
return factory.getJdbcServices().getJdbcEnvironment().getIdentifierHelper().toIdentifier( text ); | ||
} | ||
|
||
@Override | ||
public Identifier getDefaultCatalog() { | ||
return defaultCatalog; | ||
} | ||
|
||
@Override | ||
public Identifier getDefaultSchema() { | ||
return defaultSchema; | ||
} | ||
|
||
@Override | ||
public String format(QualifiedTableName qualifiedName) { | ||
return nameFormater().format( withDefaults( qualifiedName ), getDialect() ); | ||
} | ||
|
||
private QualifiedObjectNameFormatter nameFormater() { | ||
final JdbcEnvironment jdbcEnvironment = factory.getJdbcServices().getJdbcEnvironment(); | ||
//noinspection deprecation | ||
return jdbcEnvironment.getQualifiedObjectNameFormatter(); | ||
} | ||
|
||
@Override | ||
public String format(QualifiedSequenceName qualifiedName) { | ||
return nameFormater().format( withDefaults( qualifiedName ), getDialect() ); | ||
} | ||
|
||
@Override | ||
public String format(QualifiedName qualifiedName) { | ||
return nameFormater().format( withDefaults( qualifiedName ), getDialect() ); | ||
} | ||
|
||
@Override | ||
public String formatWithoutCatalog(QualifiedSequenceName qualifiedName) { | ||
QualifiedSequenceName nameToFormat; | ||
if ( qualifiedName.getCatalogName() != null | ||
|| qualifiedName.getSchemaName() == null && defaultSchema != null ) { | ||
nameToFormat = new QualifiedSequenceName( null, | ||
schemaWithDefault( qualifiedName.getSchemaName() ), qualifiedName.getSequenceName() ); | ||
} | ||
else { | ||
nameToFormat = qualifiedName; | ||
} | ||
return nameFormater().format( nameToFormat, getDialect() ); | ||
} | ||
|
||
@Override | ||
public boolean isMigration() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.