|
| 1 | +/* |
| 2 | + * Hibernate, Relational Persistence for Idiomatic Java |
| 3 | + * |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
| 5 | + * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
| 6 | + */ |
| 7 | +package org.hibernate.test.schemaupdate; |
| 8 | + |
| 9 | +import javax.persistence.Entity; |
| 10 | +import javax.persistence.Id; |
| 11 | +import javax.persistence.Table; |
| 12 | + |
| 13 | +import org.hibernate.boot.MetadataSources; |
| 14 | +import org.hibernate.boot.registry.StandardServiceRegistry; |
| 15 | +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
| 16 | +import org.hibernate.boot.spi.MetadataImplementor; |
| 17 | +import org.hibernate.cfg.AvailableSettings; |
| 18 | +import org.hibernate.dialect.H2Dialect; |
| 19 | +import org.hibernate.tool.hbm2ddl.SchemaExport; |
| 20 | +import org.hibernate.tool.hbm2ddl.SchemaUpdate; |
| 21 | +import org.hibernate.tool.hbm2ddl.Target; |
| 22 | +import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl; |
| 23 | +import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; |
| 24 | + |
| 25 | +import org.hibernate.testing.RequiresDialect; |
| 26 | +import org.hibernate.testing.TestForIssue; |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +/** |
| 30 | + * Regression test fr a bug in org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl |
| 31 | + * |
| 32 | + * @author Steve Ebersole |
| 33 | + * |
| 34 | + * @see |
| 35 | + */ |
| 36 | +@TestForIssue( jiraKey = "HHH-9745" ) |
| 37 | +public class SequenceReadingTest { |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testSequenceReading() { |
| 41 | + StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() |
| 42 | + .applySetting( AvailableSettings.DIALECT, MyExtendedH2Dialect.class ) |
| 43 | + .build(); |
| 44 | + try { |
| 45 | + final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) |
| 46 | + .addAnnotatedClass( MyEntity.class ) |
| 47 | + .buildMetadata(); |
| 48 | + metadata.validate(); |
| 49 | + |
| 50 | + try { |
| 51 | + // try to update the schema |
| 52 | + new SchemaUpdate( metadata ).execute( Target.EXPORT ); |
| 53 | + } |
| 54 | + finally { |
| 55 | + try { |
| 56 | + // clean up |
| 57 | + new SchemaExport( metadata ).drop( Target.EXPORT ); |
| 58 | + } |
| 59 | + catch (Exception ignore) { |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + finally { |
| 64 | + StandardServiceRegistryBuilder.destroy( ssr ); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * An integral piece of the bug is Dialects which to not support sequence, so lets trick the test |
| 70 | + */ |
| 71 | + public static class MyExtendedH2Dialect extends H2Dialect { |
| 72 | + @Override |
| 73 | + public SequenceInformationExtractor getSequenceInformationExtractor() { |
| 74 | + return SequenceInformationExtractorNoOpImpl.INSTANCE; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public String getQuerySequencesString() { |
| 79 | + return null; |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + @Entity(name = "MyEntity") |
| 84 | + @Table(name = "my_entity") |
| 85 | + public static class MyEntity { |
| 86 | + @Id |
| 87 | + public Integer id; |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments