use of org.hibernate.boot.MetadataSources 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.MetadataSources 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.MetadataSources in project hibernate-orm by hibernate.
the class SequenceReadingTest method testSequenceReading.
@Test
public void testSequenceReading() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, MyExtendedH2Dialect.class).build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata();
metadata.validate();
try {
// try to update the schema
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
try {
// clean up
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
} catch (Exception ignore) {
}
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class SchemaExportWithGlobalQuotingEnabledTest method setUp.
@Before
public void setUp() {
serviceRegistry = new StandardServiceRegistryBuilder().applySetting(Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true").build();
metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(MyEntity.class).addAnnotatedClass(Role.class).buildMetadata();
System.out.println("********* Starting SchemaExport for START-UP *************************");
new SchemaExport().create(EnumSet.of(TargetType.STDOUT, TargetType.DATABASE), metadata);
System.out.println("********* Completed SchemaExport for START-UP *************************");
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class SchemaExportWithIndexAndDefaultSchema method setUp.
@Before
public void setUp() {
serviceRegistry = new StandardServiceRegistryBuilder().applySetting(Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true").applySetting(Environment.DEFAULT_SCHEMA, "public").build();
metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(MyEntity.class).buildMetadata();
System.out.println("********* Starting SchemaExport for START-UP *************************");
new SchemaExport().create(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), metadata);
System.out.println("********* Completed SchemaExport for START-UP *************************");
}
Aggregations