use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class OneToOneSchemaTest method testUniqueKeyNotGeneratedViaAnnotations.
@Test
public void testUniqueKeyNotGeneratedViaAnnotations() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Parent.class).addAnnotatedClass(Child.class).buildMetadata();
Table childTable = metadata.getDatabase().getDefaultNamespace().locateTable(Identifier.toIdentifier("CHILD"));
assertFalse("UniqueKey was generated when it should not", childTable.getUniqueKeyIterator().hasNext());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class SchemaUpdateTableBackedSequenceTest method testCreateTableOnUpdate.
@Test
public void testCreateTableOnUpdate() throws SQLException {
Metadata metadata = new MetadataSources(ssr).buildMetadata();
Database database = metadata.getDatabase();
TableStructure tableStructure = new TableStructure(database.getJdbcEnvironment(), new QualifiedTableName(null, null, Identifier.toIdentifier("test_seq")), Identifier.toIdentifier("nextval"), 20, 30, Long.class);
tableStructure.registerExportables(database);
// lets make sure the InitCommand is there
assertEquals(1, database.getDefaultNamespace().getTables().size());
Table table = database.getDefaultNamespace().getTables().iterator().next();
assertEquals(1, table.getInitCommands().size());
final TargetImpl target = new TargetImpl();
ssr.getService(SchemaManagementTool.class).getSchemaMigrator(Collections.emptyMap()).doMigration(metadata, new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return true;
}
@Override
public Map getConfigurationValues() {
return ssr.getService(ConfigurationService.class).getSettings();
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
}, new TargetDescriptor() {
@Override
public EnumSet<TargetType> getTargetTypes() {
return EnumSet.of(TargetType.SCRIPT, TargetType.DATABASE);
}
@Override
public ScriptTargetOutput getScriptTargetOutput() {
return target;
}
});
assertTrue(target.found);
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
use of org.hibernate.boot.Metadata in project jbosstools-hibernate by jbosstools.
the class MetadataHelper method getMetadataFromMethod.
private static Metadata getMetadataFromMethod(Configuration configuration) {
Metadata result = null;
Method metadataMethod = getMethod("getMetadata", configuration);
if (metadataMethod != null) {
try {
metadataMethod.setAccessible(true);
result = (Metadata) metadataMethod.invoke(configuration, new Object[] {});
} catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
throw new RuntimeException(e);
}
}
return result;
}
use of org.hibernate.boot.Metadata in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testReadFromJDBC.
@Test
public void testReadFromJDBC() throws Exception {
Connection connection = DriverManager.getConnection("jdbc:h2:mem:test");
Statement statement = connection.createStatement();
statement.execute("CREATE TABLE FOO(id int primary key, bar varchar(255))");
JDBCMetaDataConfiguration jdbcMdCfg = new JDBCMetaDataConfiguration();
jdbcMdCfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
Metadata metadata = jdbcMdCfg.getMetadata();
Iterator<?> iterator = metadata.getEntityBindings().iterator();
jdbcMdCfg = new JDBCMetaDataConfiguration();
jdbcMdCfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
Assert.assertFalse(iterator.hasNext());
configurationFacade.readFromJDBC();
metadata = jdbcMdCfg.getMetadata();
iterator = metadata.getEntityBindings().iterator();
PersistentClass persistentClass = (PersistentClass) iterator.next();
Assert.assertEquals("Foo", persistentClass.getClassName());
statement.execute("DROP TABLE FOO");
connection.close();
}
use of org.hibernate.boot.Metadata in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testConfigure.
@Test
public void testConfigure() {
String fooClassName = "org.jboss.tools.hibernate.runtime.v_5_2.internal.test.Foo";
Metadata metadata = MetadataHelper.getMetadata(configuration);
Assert.assertNull(metadata.getEntityBinding(fooClassName));
configurationFacade.configure();
metadata = MetadataHelper.getMetadata(configuration);
Assert.assertNotNull(metadata.getEntityBinding(fooClassName));
}
Aggregations