/** * Wrap the raw name of a database object in it's Identifier form accounting for quoting from * any of:<ul> * <li>explicit quoting in the name itself</li> * <li>global request to quote all identifiers</li> * </ul> * <p/> * NOTE : quoting from database keywords happens only when building physical identifiers * * @param text The raw object name * * @return The wrapped Identifier form */ public Identifier toIdentifier(String text) { return text == null ? null : jdbcEnvironment.getIdentifierHelper().toIdentifier( text ); }
/** * Determine the name of the column used to store the generator value in * the db. * <p/> * Called during {@link #configure configuration} <b>when resolving to a * physical table</b>. * * @param params The params supplied in the generator config (plus some standard useful extras). * @param jdbcEnvironment The JDBC environment * @return The value column name */ @SuppressWarnings({"UnusedParameters", "WeakerAccess"}) protected Identifier determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment) { final String name = ConfigurationHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN ); return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ); }
protected QualifiedName determineGeneratorTableName(Properties params, JdbcEnvironment jdbcEnvironment) { final String tableName = ConfigurationHelper.getString( ID_TABLE, params, DEFAULT_TABLE ); if ( tableName.contains( "." ) ) { return QualifiedNameParser.INSTANCE.parse( tableName ); } else { // todo : need to incorporate implicit catalog and schema names final Identifier catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier( ConfigurationHelper.getString( CATALOG, params ) ); final Identifier schema = jdbcEnvironment.getIdentifierHelper().toIdentifier( ConfigurationHelper.getString( SCHEMA, params ) ); return new QualifiedNameParser.NameParts( catalog, schema, jdbcEnvironment.getIdentifierHelper().toIdentifier( tableName ) ); } }
@Override public Identifier handleExplicitName(String explicitName, MetadataBuildingContext buildingContext) { return buildingContext.getMetadataCollector() .getDatabase() .getJdbcEnvironment() .getIdentifierHelper() .toIdentifier( explicitName ); }
protected String determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment) { final String name = ConfigurationHelper.getString( VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN ); return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() ); }
@Override public Identifier handleExplicitName(String explicitName, MetadataBuildingContext buildingContext) { return buildingContext.getMetadataCollector() .getDatabase() .getJdbcEnvironment() .getIdentifierHelper() .toIdentifier( explicitName ); }
private Identifier toIdentifier(String tableName) { return buildingContext.getMetadataCollector() .getDatabase() .getJdbcEnvironment() .getIdentifierHelper() .toIdentifier( tableName ); }
protected String determineSegmentColumnName(Properties params, JdbcEnvironment jdbcEnvironment) { final String name = ConfigurationHelper.getString( PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN ); return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() ); }
/** * Easy hook to build an Identifier using the keyword safe IdentifierHelper. * * @param stringForm The String form of the name * @param buildingContext Access to the IdentifierHelper * * @return The identifier */ protected Identifier toIdentifier(String stringForm, MetadataBuildingContext buildingContext) { return buildingContext.getMetadataCollector() .getDatabase() .getJdbcEnvironment() .getIdentifierHelper() .toIdentifier( stringForm ); } }
/** * Determine the name of the column in which we will store the generator persistent value. * <p/> * Called during {@link #configure configuration}. * * @see #getValueColumnName() * @param params The params supplied in the generator config (plus some standard useful extras). * @param jdbcEnvironment The JDBC environment * @return The name of the value column */ @SuppressWarnings({"UnusedParameters", "WeakerAccess"}) protected String determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment) { final String name = ConfigurationHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN ); return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() ); }
/** * Determine the name of the column used to indicate the segment for each * row. This column acts as the primary key. * <p/> * Called during {@link #configure configuration}. * * @see #getSegmentColumnName() * @param params The params supplied in the generator config (plus some standard useful extras). * @param jdbcEnvironment The JDBC environment * @return The name of the segment column */ @SuppressWarnings({"UnusedParameters", "WeakerAccess"}) protected String determineSegmentColumnName(Properties params, JdbcEnvironment jdbcEnvironment) { final String name = ConfigurationHelper.getString( SEGMENT_COLUMN_PARAM, params, DEF_SEGMENT_COLUMN ); return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() ); }
@Override public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) { String baseName = name.render( context.getDialect() ); if ( baseName.equals( "table_a" ) ) { baseName = "tbl_a"; } return context.getIdentifierHelper().toIdentifier( baseName ); } }
protected QualifiedTableName determineIdTableName(JdbcEnvironment jdbcEnvironment, PersistentClass entityBinding) { final String entityPrimaryTableName = entityBinding.getTable().getName(); final String idTableName = getIdTableSupport().generateIdTableName( entityPrimaryTableName ); // by default no explicit catalog/schema return new QualifiedTableName( null, null, jdbcEnvironment.getIdentifierHelper().toIdentifier( idTableName ) ); }
@Override public Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment jdbcEnvironment) { final LinkedList<String> parts = splitAndReplace( name.getText() ); // Acme Corp says all sequences should end with _seq if ( !"seq".equalsIgnoreCase( parts.getLast() ) ) { parts.add( "seq" ); } return jdbcEnvironment.getIdentifierHelper().toIdentifier( join( parts ), name.isQuoted() ); }
@Override protected void initialize(MetadataBuildingOptions buildingOptions, SessionFactoryOptions sessionFactoryOptions) { final StandardServiceRegistry serviceRegistry = buildingOptions.getServiceRegistry(); final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class ); final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class ); final String catalogName = configService.getSetting( CATALOG, StandardConverters.STRING, configService.getSetting( AvailableSettings.DEFAULT_CATALOG, StandardConverters.STRING ) ); final String schemaName = configService.getSetting( SCHEMA, StandardConverters.STRING, configService.getSetting( AvailableSettings.DEFAULT_SCHEMA, StandardConverters.STRING ) ); this.catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier( catalogName ); this.schema = jdbcEnvironment.getIdentifierHelper().toIdentifier( schemaName ); this.dropIdTables = configService.getSetting( DROP_ID_TABLES, StandardConverters.BOOLEAN, false ); }
@Override public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment jdbcEnvironment) { return jdbcEnvironment.getIdentifierHelper().toIdentifier( applyPrefix( name.getText() ) ); }
@Override public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment jdbcEnvironment) { final List<String> parts = splitAndReplace( name.getText() ); return jdbcEnvironment.getIdentifierHelper().toIdentifier( join( parts ), name.isQuoted() ); }
@Override public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment jdbcEnvironment) { final List<String> parts = splitAndReplace( name.getText() ); return jdbcEnvironment.getIdentifierHelper().toIdentifier( join( parts ), name.isQuoted() ); }
@Test public void testAutoQuotingDisabled() { ServiceRegistry sr = ServiceRegistryTestingImpl.forUnitTesting( Collections.singletonMap( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, // true is the default, but to be sure... true ) ); Identifier identifier = sr.getService( JdbcEnvironment.class ).getIdentifierHelper().toIdentifier( "select" ); assertTrue( identifier.isQuoted() ); StandardServiceRegistryBuilder.destroy( sr ); sr = ServiceRegistryTestingImpl.forUnitTesting( Collections.singletonMap( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, false ) ); identifier = sr.getService( JdbcEnvironment.class ).getIdentifierHelper().toIdentifier( "select" ); assertFalse( identifier.isQuoted() ); StandardServiceRegistryBuilder.destroy( sr ); } }
@Test @TestForIssue( jiraKey = "HHH_9768" ) public void testAnsiSqlKeyword() { // END is ANSI SQL keyword JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class ); assertTrue( jdbcEnvironment.getIdentifierHelper().isReservedWord( "end" ) ); assertTrue( jdbcEnvironment.getIdentifierHelper().isReservedWord( "END" ) ); Identifier identifier = jdbcEnvironment.getIdentifierHelper().toIdentifier( "end" ); assertTrue( identifier.isQuoted() ); } }