|
| 1 | +package org.hibernate.test.dialect.functional; |
| 2 | + |
| 3 | +import java.sql.Connection; |
| 4 | +import java.sql.SQLException; |
| 5 | +import java.util.HashMap; |
| 6 | +import java.util.Map; |
| 7 | +import java.util.Optional; |
| 8 | +import java.util.stream.StreamSupport; |
| 9 | + |
| 10 | +import org.hibernate.boot.registry.StandardServiceRegistry; |
| 11 | +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
| 12 | +import org.hibernate.cfg.AvailableSettings; |
| 13 | +import org.hibernate.cfg.Environment; |
| 14 | +import org.hibernate.dialect.MariaDBDialect; |
| 15 | +import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; |
| 16 | +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; |
| 17 | +import org.hibernate.engine.jdbc.spi.JdbcServices; |
| 18 | +import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorMariaDBDatabaseImpl; |
| 19 | +import org.hibernate.tool.schema.extract.spi.ExtractionContext; |
| 20 | +import org.hibernate.tool.schema.extract.spi.SequenceInformation; |
| 21 | +import org.hibernate.testing.RequiresDialect; |
| 22 | +import org.hibernate.testing.TestForIssue; |
| 23 | +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; |
| 24 | + |
| 25 | +import org.junit.AfterClass; |
| 26 | +import org.junit.Assert; |
| 27 | +import org.junit.BeforeClass; |
| 28 | +import org.junit.Test; |
| 29 | + |
| 30 | +import static org.hibernate.testing.transaction.TransactionUtil.doInAutoCommit; |
| 31 | + |
| 32 | +/** |
| 33 | + * @author Jan Schatteman |
| 34 | + */ |
| 35 | +@RequiresDialect(value = MariaDBDialect.class) |
| 36 | +public class MariaDBExtractSequenceInformationTest extends BaseCoreFunctionalTestCase { |
| 37 | + |
| 38 | + private final static String hhh15665SeqName = "HHH-15665-seq"; |
| 39 | + |
| 40 | + private final static Map<String, Object> settings = new HashMap<>(3); |
| 41 | + |
| 42 | + static { |
| 43 | + settings.put( AvailableSettings.URL, Environment.getProperties().getProperty( AvailableSettings.URL ) ); |
| 44 | + settings.put( AvailableSettings.USER, Environment.getProperties().getProperty( AvailableSettings.USER ) ); |
| 45 | + settings.put( AvailableSettings.PASS, Environment.getProperties().getProperty( AvailableSettings.PASS ) ); |
| 46 | + } |
| 47 | + |
| 48 | + @BeforeClass |
| 49 | + public static void setUp() throws Exception { |
| 50 | + doInAutoCommit( settings, "CREATE SEQUENCE IF NOT EXISTS `" + hhh15665SeqName + "`" ); |
| 51 | + } |
| 52 | + |
| 53 | + @AfterClass |
| 54 | + public static void tearDown() throws SQLException { |
| 55 | + doInAutoCommit( settings, "DROP SEQUENCE IF EXISTS `" + hhh15665SeqName + "`" ); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + @TestForIssue( jiraKey = "HHH-15665" ) |
| 60 | + public void testExtractSequenceInformationForSqlServerWithCaseSensitiveCollation() { |
| 61 | + StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings( settings ).build(); |
| 62 | + JdbcEnvironment jdbcEnvironment = ssr.getService( JdbcEnvironment.class ); |
| 63 | + JdbcConnectionAccess bootstrapJdbcConnectionAccess = ssr.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess(); |
| 64 | + |
| 65 | + try ( Connection connection = bootstrapJdbcConnectionAccess.obtainConnection() ) { |
| 66 | + Iterable<SequenceInformation> sequenceInformations = SequenceInformationExtractorMariaDBDatabaseImpl.INSTANCE.extractMetadata( |
| 67 | + new ExtractionContext.EmptyExtractionContext() { |
| 68 | + @Override |
| 69 | + public Connection getJdbcConnection() { |
| 70 | + return connection; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public JdbcEnvironment getJdbcEnvironment() { |
| 75 | + return jdbcEnvironment; |
| 76 | + } |
| 77 | + } ); |
| 78 | + |
| 79 | + Assert.assertNotNull( sequenceInformations ); |
| 80 | + |
| 81 | + Optional<SequenceInformation> seq = StreamSupport.stream( sequenceInformations.spliterator(), false ) |
| 82 | + .filter( |
| 83 | + sequence -> hhh15665SeqName.equals( sequence.getSequenceName() |
| 84 | + .getSequenceName() |
| 85 | + .getText() ) |
| 86 | + ) |
| 87 | + .findFirst(); |
| 88 | + |
| 89 | + Assert.assertTrue( hhh15665SeqName + " not found", seq.isPresent() ); |
| 90 | + } |
| 91 | + catch ( SQLException e ) { |
| 92 | + Assert.fail( "Sequence information for " + hhh15665SeqName + " was not retrieved: " + e.getMessage() ); |
| 93 | + } |
| 94 | + finally { |
| 95 | + StandardServiceRegistryBuilder.destroy( ssr ); |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments