private void mockContext(final ImplicitNameSource source) { final MetadataBuildingContext context = Mockito.mock(MetadataBuildingContext.class); final InFlightMetadataCollector collector = Mockito.mock(InFlightMetadataCollector.class); final Database database = Mockito.mock(Database.class); final JdbcEnvironment jdbcEnvironment = Mockito.mock(JdbcEnvironment.class); final IdentifierHelper identifierHelper = Mockito.mock(IdentifierHelper.class); Mockito.when(identifierHelper.toIdentifier(ArgumentMatchers.anyString())).then(new Answer<Identifier>() { @Override public Identifier answer(final InvocationOnMock invocation) { return DatabaseIdentifier.toIdentifier((String)invocation.getArguments()[0]) ; } }); Mockito.when(jdbcEnvironment.getIdentifierHelper()).thenReturn(identifierHelper); Mockito.when(database.getJdbcEnvironment()).thenReturn(jdbcEnvironment); Mockito.when(collector.getDatabase()).thenReturn(database); Mockito.when(context.getMetadataCollector()).thenReturn(collector); Mockito.when(source.getBuildingContext()).thenReturn(context); }
private static void populateDatabaseModel(MetadataImplementor metadata, ExplicitSqmDomainMetamodel domainMetamodel) { final Database database = metadata.getDatabase(); final DatabaseModelImpl databaseModel = (DatabaseModelImpl) domainMetamodel.getDatabaseModel(); // todo : apply PhysicalNamingStrategy here, rather than as we create the "mapping model"? // todo : we need DatabaseModel to incorporate catalogs/schemas in some fashion // either like org.hibernate.boot.model.relational.Database does // or via catalogs/schemas-specific names for ( Namespace namespace : database.getNamespaces() ) { for ( Table mappingTable : namespace.getTables() ) { // todo : incorporate mapping Table's isAbstract indicator final org.hibernate.orm.persister.common.spi.Table table; if ( mappingTable instanceof DenormalizedTable ) { // this is akin to a UnionSubclassTable throw new NotYetImplementedException( "DenormalizedTable support not yet implemented" ); } else if ( mappingTable.getSubselect() != null ) { table = new DerivedTable( mappingTable.getSubselect() ); } else { // final JdbcEnvironment jdbcEnvironment = sessionFactory.getJdbcServices().getJdbcEnvironment(); // final String qualifiedTableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( // mappingTable.getQualifiedTableName(), // jdbcEnvironment.getDialect() // ); final String qualifiedTableName = mappingTable.getQualifiedTableName().render(); table = new PhysicalTable( qualifiedTableName ); } databaseModel.registerTable( table ); } } }
private void addAuxiliaryDatabaseObjects(Database database) { // Adding multiple times is a no-op database.addAuxiliaryDatabaseObject(SET); database.addAuxiliaryDatabaseObject(WAIT); }
public Database getDatabase() { return database; }