From d2a2fe8e239e3217172acc2ee2be2947c29e1d98 Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Fri, 23 Jun 2023 13:20:13 +0200 Subject: [PATCH] HBX-2390: Create a JBoss Tools adaptation layer in Hibernate Tools - Add new interface method 'org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactory.ConfigurationWrapper#readFromJDBC()' - Add new test case 'org.hibernate.tool.orm.jbt.wrp.ConfigurationWrapperFactoryTest#testReadFromJDBC()' Signed-off-by: Koen Aers --- .../jbt/wrp/ConfigurationWrapperFactory.java | 1 + .../wrp/ConfigurationWrapperFactoryTest.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactory.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactory.java index ec4bc7ef76..9db09b11de 100644 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactory.java +++ b/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactory.java @@ -64,6 +64,7 @@ static interface ConfigurationWrapper extends Wrapper { Iterator getClassMappings(); void setPreferBasicCompositeIds(boolean b); void setReverseEngineeringStrategy(RevengStrategy reverseEngineeringStrategy); + void readFromJDBC(); } static class ConfigurationWrapperInvocationHandler implements InvocationHandler { diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactoryTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactoryTest.java index 71f6e18144..8afbabda75 100644 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactoryTest.java +++ b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/ConfigurationWrapperFactoryTest.java @@ -666,6 +666,44 @@ public void testSetReverseEngineeringStrategy() { } } + @Test + public void testReadFromJDBC() throws Exception { + // For native configuration + try { + nativeConfigurationWrapper.readFromJDBC(); + fail(); + } catch (RuntimeException e) { + assertEquals( + e.getMessage(), + "Method 'readFromJDBC' should not be called on instances of " + NativeConfigurationWrapperImpl.class.getName()); + } + // For reveng configuration + Connection connection = DriverManager.getConnection("jdbc:h2:mem:test"); + Statement statement = connection.createStatement(); + statement.execute("CREATE TABLE FOO(id int primary key, bar varchar(255))"); + wrappedRevengConfiguration.setProperty("hibernate.connection.url", "jdbc:h2:mem:test"); + wrappedRevengConfiguration.setProperty("hibernate.default_schema", "PUBLIC"); + Metadata metadata = ((RevengConfiguration)wrappedRevengConfiguration).getMetadata(); + assertNull(metadata); + revengConfigurationWrapper.readFromJDBC(); + metadata = ((RevengConfiguration)wrappedRevengConfiguration).getMetadata(); + Iterator iterator = metadata.getEntityBindings().iterator(); + PersistentClass persistentClass = iterator.next(); + assertEquals("Foo", persistentClass.getClassName()); + statement.execute("DROP TABLE FOO"); + statement.close(); + connection.close(); + // For jpa configuration + try { + jpaConfigurationWrapper.readFromJDBC(); + fail(); + } catch (RuntimeException e) { + assertEquals( + e.getMessage(), + "Method 'readFromJDBC' should not be called on instances of " + JpaConfigurationWrapperImpl.class.getName()); + } + } + private void createPersistenceXml() throws Exception { File metaInf = new File(tempRoot, "META-INF"); metaInf.mkdirs();