final Identifier catalogLogicalName = namespace.getName().getCatalog(); final Identifier catalogPhysicalName = namespace.getPhysicalName().getCatalog(); if ( tryToCreateSchemas && namespace.getPhysicalName().getSchema() != null ) { applySqlStrings( dialect.getCreateSchemaCommand( namespace.getPhysicalName().getSchema().render( dialect ) ), formatter, options,
foreignKey.setReferencedTable( new Table( "table2" ) ); Name schemaName = new Name( new Identifier( "-", false ), new Identifier( "-", false ) ); InformationExtractor informationExtractor = Mockito.mock( InformationExtractor.class ); IdentifierHelper identifierHelper = new IdentifierHelperImpl();
@Test public void testQualifiedNameSeparator() throws Exception { Namespace.Name namespaceName = new Namespace.Name( Identifier.toIdentifier( "DB1" ), Identifier.toIdentifier( "PUBLIC" ) ); String expectedName = null; for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) { if ( !namespace.getName().equals( namespaceName ) ) { continue; } assertEquals( 1, namespace.getTables().size() ); expectedName = metadata().getDatabase().getJdbcEnvironment().getQualifiedObjectNameFormatter().format( namespace.getTables().iterator().next().getQualifiedTableName(), getDialect() ); } assertNotNull( expectedName ); SingleTableEntityPersister persister = (SingleTableEntityPersister) sessionFactory().getEntityPersister( Box.class.getName() ); assertEquals( expectedName, persister.getTableName() ); }
private DatabaseInformation getDatabaseInformation() { final ServiceRegistry serviceRegistry = metadataImplementor.getMetadataBuildingOptions().getServiceRegistry(); // final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class ); // final SchemaManagementTool schemaManagementTool = serviceRegistry.getService( SchemaManagementTool.class ); // final SchemaMigrator schemaMigrator = schemaManagementTool.getSchemaMigrator( cfgService.getSettings() ); final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); final JdbcConnectionAccess jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess(); final DatabaseInformation databaseInformation; try { databaseInformation = new DatabaseInformationImpl( serviceRegistry, serviceRegistry.getService( JdbcEnvironment.class ), jdbcConnectionAccess, metadataImplementor.getDatabase().getDefaultNamespace().getPhysicalName().getCatalog(), metadataImplementor.getDatabase().getDefaultNamespace().getPhysicalName().getSchema() ); } catch (SQLException e) { throw jdbcServices.getSqlExceptionHelper().convert( e, "Error creating DatabaseInformation for schema migration" ); } return databaseInformation; }
if ( tryToDropSchemas && namespace.getPhysicalName().getSchema() != null ) { applySqlStrings( dialect.getDropSchemaCommand( namespace.getPhysicalName().getSchema().render( dialect ) ), formatter, final Identifier catalogLogicalName = namespace.getName().getCatalog(); final Identifier catalogPhysicalName = namespace.getPhysicalName().getCatalog();
if ( database.getDefaultNamespace().getPhysicalName().getSchema() != null ) { params.setProperty( PersistentIdentifierGenerator.SCHEMA, database.getDefaultNamespace().getPhysicalName().getSchema().render( database.getDialect() ) ); if ( database.getDefaultNamespace().getPhysicalName().getCatalog() != null ) { params.setProperty( PersistentIdentifierGenerator.CATALOG, database.getDefaultNamespace().getPhysicalName().getCatalog().render( database.getDialect() ) );
if ( tryToCreateCatalogs || tryToCreateSchemas ) { if ( tryToCreateCatalogs ) { final Identifier catalogLogicalName = namespace.getName().getCatalog(); final Identifier catalogPhysicalName = namespace.getPhysicalName().getCatalog(); && namespace.getPhysicalName().getSchema() != null && !existingDatabase.schemaExists( namespace.getName() ) ) { applySqlStrings( false, dialect.getCreateSchemaCommand( namespace.getPhysicalName().getSchema().render( dialect ) ), formatter, options,
foreignKey.setReferencedTable( new Table( "table2" ) ); Name schemaName = new Name( new Identifier( "-", false ), new Identifier( "-", false ) ); InformationExtractor informationExtractor = Mockito.mock( InformationExtractor.class ); IdentifierHelper identifierHelper = new IdentifierHelperImpl();
fks.add( new ForeignKeyInformationImpl( new Identifier( "objectId2id_2", false ), new ArrayList<>() ) ); Mockito.when( informationExtractor.getForeignKeys( Mockito.any() ) ).thenReturn( fks ); Name schemaName = new Name( new Identifier( "-", false ), new Identifier( "-", false ) ); QualifiedTableName tableName = new QualifiedTableName( schemaName, new Identifier( "-", false ) ); TableInformation tableInformation = new TableInformationImpl( informationExtractor, identifierHelper, tableName, false, null );
fks.add( new ForeignKeyInformationImpl( new Identifier( "objectId2id", false ), new ArrayList<>() ) ); Mockito.when( informationExtractor.getForeignKeys( Mockito.any() ) ).thenReturn( fks ); Name schemaName = new Name( new Identifier( "-", false ), new Identifier( "-", false ) ); QualifiedTableName tableName = new QualifiedTableName( schemaName, new Identifier( "-", false ) ); TableInformation tableInformation = new TableInformationImpl( informationExtractor, identifierHelper, tableName, false, null );
private void processExportableProducers() { // for now we only handle id generators as ExportableProducers final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect(); final String defaultCatalog = extractName( getDatabase().getDefaultNamespace().getName().getCatalog(), dialect ); final String defaultSchema = extractName( getDatabase().getDefaultNamespace().getName().getSchema(), dialect ); for ( PersistentClass entityBinding : entityBindingMap.values() ) { if ( entityBinding.isInherited() ) { continue; } handleIdentifierValueBinding( entityBinding.getIdentifier(), dialect, defaultCatalog, defaultSchema, (RootClass) entityBinding ); } for ( Collection collection : collectionBindingMap.values() ) { if ( !IdentifierCollection.class.isInstance( collection ) ) { continue; } handleIdentifierValueBinding( ( (IdentifierCollection) collection ).getIdentifier(), dialect, defaultCatalog, defaultSchema, null ); } }
private InformationExtractorJdbcDatabaseMetaDataImplTest buildInformationExtractorJdbcDatabaseMetaDataImplTest() throws SQLException { Database database = metadata.getDatabase(); final ConnectionProvider connectionProvider = ssr.getService( ConnectionProvider.class ); DatabaseInformation dbInfo = new DatabaseInformationImpl( ssr, database.getJdbcEnvironment(), new DdlTransactionIsolatorTestingImpl( ssr, new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess( connectionProvider ) ), database.getDefaultNamespace().getName() ); ExtractionContextImpl extractionContext = new ExtractionContextImpl( ssr, database.getJdbcEnvironment(), ssr.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(), (ExtractionContext.DatabaseObjectAccess) dbInfo, database.getDefaultNamespace().getPhysicalName().getCatalog(), database.getDefaultNamespace().getPhysicalName().getSchema() ); return new InformationExtractorJdbcDatabaseMetaDataImplTest( extractionContext ); }
protected void migrateTable( Table table, TableInformation tableInformation, Dialect dialect, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) { final Database database = metadata.getDatabase(); //noinspection unchecked applySqlStrings( false, table.sqlAlterStrings( dialect, metadata, tableInformation, database.getDefaultNamespace().getPhysicalName().getCatalog(), database.getDefaultNamespace().getPhysicalName().getSchema() ), formatter, options, targets ); }
public DatabaseInformationImpl( ServiceRegistry serviceRegistry, JdbcEnvironment jdbcEnvironment, DdlTransactionIsolator ddlTransactionIsolator, Namespace.Name defaultNamespace) throws SQLException { this.jdbcEnvironment = jdbcEnvironment; this.extractionContext = new ImprovedExtractionContextImpl( serviceRegistry, jdbcEnvironment, ddlTransactionIsolator, defaultNamespace.getCatalog(), defaultNamespace.getSchema(), this ); // todo : make this pluggable this.extractor = new InformationExtractorJdbcDatabaseMetaDataImpl( extractionContext ); // because we do not have defined a way to locate sequence info by name initializeSequences(); }
private ColumnInformation getColumnInformation(String tableName, String columnName) { Name schemaName = new Name( new Identifier( "-", false ), new Identifier( "-", false ) ); TableInformation containingTableInformation = new TableInformationImpl( null, null, new QualifiedTableName( schemaName, new Identifier( tableName, false ) ), false, null ); Identifier columnIdentifier = new Identifier( columnName, false ); int typeCode = 0; String typeName = null; int columnSize = 0; int decimalDigits = 0; TruthValue nullable = null; ColumnInformationImpl columnInformation = new ColumnInformationImpl( containingTableInformation, columnIdentifier, typeCode, typeName, columnSize, decimalDigits, nullable ); return columnInformation; } }
public Sequence createSequence(Identifier logicalName, int initialValue, int increment) { if ( sequences.containsKey( logicalName ) ) { throw new HibernateException( "Sequence was already registered with that name [" + logicalName.toString() + "]" ); } final Identifier physicalName = physicalNamingStrategy.toPhysicalSequenceName( logicalName, jdbcEnvironment ); Sequence sequence = new Sequence( this.physicalName.getCatalog(), this.physicalName.getSchema(), physicalName, initialValue, increment ); sequences.put( logicalName, sequence ); return sequence; }
public Namespace(PhysicalNamingStrategy physicalNamingStrategy, JdbcEnvironment jdbcEnvironment, Name name) { this.physicalNamingStrategy = physicalNamingStrategy; this.jdbcEnvironment = jdbcEnvironment; this.name = name; this.physicalName = new Name( physicalNamingStrategy .toPhysicalCatalogName( name.getCatalog(), jdbcEnvironment ), physicalNamingStrategy .toPhysicalSchemaName( name.getSchema(), jdbcEnvironment ) ); log.debugf( "Created database namespace [logicalName=%s, physicalName=%s]", name.toString(), physicalName.toString() ); }
private static class AssociationTableNameSource implements ObjectNameSource { private final String explicitName; private final String logicalName; private AssociationTableNameSource(String explicitName, String logicalName) { this.explicitName = explicitName; this.logicalName = logicalName; } public String getExplicitName() { return explicitName; } public String getLogicalName() { return logicalName; } }
@Override public int hashCode() { return name.hashCode(); }
@Override public NameSpaceTablesInformation getTablesInformation(Namespace namespace) { return extractor.getTables( namespace.getPhysicalName().getCatalog(), namespace.getPhysicalName().getSchema() ); }