use of org.hibernate.tool.schema.internal.SchemaCreatorImpl in project hibernate-orm by hibernate.
the class IndividuallySchemaValidatorImplTest method testMissingColumn.
@Test
public void testMissingColumn() throws Exception {
MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(NoNameColumn.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
Map<String, Object> settings = new HashMap<>();
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
connectionProvider.configure(properties());
final GenerationTargetToDatabase schemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, new JdbcConnectionAccessImpl(connectionProvider)));
try {
new SchemaCreatorImpl(ssr).doCreation(metadata, serviceRegistry, settings, true, schemaGenerator);
metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(NameColumn.class);
metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
try {
getSchemaValidator(metadata);
Assert.fail("SchemaManagementException expected");
} catch (SchemaManagementException e) {
assertEquals("Schema-validation: missing column [name] in table [SomeSchema.ColumnEntity]", e.getMessage());
}
} finally {
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, false, schemaGenerator);
serviceRegistry.destroy();
connectionProvider.stop();
}
}
use of org.hibernate.tool.schema.internal.SchemaCreatorImpl in project hibernate-orm by hibernate.
the class JoinColumnOverrideTest method testBlownPrecision.
@Test
@TestForIssue(jiraKey = "ANN-748")
public void testBlownPrecision() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, "SQLServer").build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Bunny.class).addAnnotatedClass(PointyTooth.class).addAnnotatedClass(TwinkleToes.class).buildMetadata();
boolean foundPointyToothCreate = false;
boolean foundTwinkleToesCreate = false;
List<String> commands = new SchemaCreatorImpl(ssr).generateCreationCommands(metadata, false);
for (String command : commands) {
log.debug(command);
if (expectedSqlPointyTooth.equals(command)) {
foundPointyToothCreate = true;
} else if (expectedSqlTwinkleToes.equals(command)) {
foundTwinkleToesCreate = true;
}
}
assertTrue("Expected create table command for PointyTooth entity not found", foundPointyToothCreate);
assertTrue("Expected create table command for TwinkleToes entity not found", foundTwinkleToesCreate);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.schema.internal.SchemaCreatorImpl in project hibernate-orm by hibernate.
the class NullablePrimaryKeyTest method testGeneratedSql.
@Test
@SuppressWarnings("unchecked")
public void testGeneratedSql() {
Map settings = new HashMap();
settings.putAll(Environment.getProperties());
settings.put(AvailableSettings.DIALECT, SQLServerDialect.class.getName());
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(settings);
try {
MetadataSources ms = new MetadataSources(serviceRegistry);
ms.addAnnotatedClass(Address.class);
ms.addAnnotatedClass(Person.class);
final Metadata metadata = ms.buildMetadata();
final List<String> commands = new SchemaCreatorImpl(serviceRegistry).generateCreationCommands(metadata, false);
for (String s : commands) {
log.debug(s);
}
String expectedMappingTableSql = "create table personAddress (address_id numeric(19,0), " + "person_id numeric(19,0) not null, primary key (person_id))";
Assert.assertEquals("Wrong SQL", expectedMappingTableSql, commands.get(2));
} catch (Exception e) {
Assert.fail(e.getMessage());
} finally {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
use of org.hibernate.tool.schema.internal.SchemaCreatorImpl in project hibernate-orm by hibernate.
the class UniqueDelegateTest method testUniqueDelegateConsulted.
@Test
@TestForIssue(jiraKey = "HHH-10203")
public void testUniqueDelegateConsulted() {
final Metadata metadata = new MetadataSources(ssr).addResource("org/hibernate/test/hbm/uk/person_unique.hbm.xml").buildMetadata();
final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget();
new SchemaCreatorImpl(ssr).doCreation(metadata, false, target);
assertThat(getAlterTableToAddUniqueKeyCommandCallCount, equalTo(1));
assertThat(getColumnDefinitionUniquenessFragmentCallCount, equalTo(1));
assertThat(getTableCreationUniqueConstraintsFragmentCallCount, equalTo(1));
new SchemaDropperImpl(ssr).doDrop(metadata, false, target);
// unique keys are not dropped explicitly
assertThat(getAlterTableToAddUniqueKeyCommandCallCount, equalTo(1));
assertThat(getColumnDefinitionUniquenessFragmentCallCount, equalTo(1));
assertThat(getTableCreationUniqueConstraintsFragmentCallCount, equalTo(1));
}
use of org.hibernate.tool.schema.internal.SchemaCreatorImpl in project hibernate-orm by hibernate.
the class CollectionPkTest method verifyPkNameUsed.
private void verifyPkNameUsed(String mappingResource, String expectedName) {
final Metadata metadata = new MetadataSources(ssr).addResource(mappingResource).buildMetadata();
final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget();
new SchemaCreatorImpl(ssr).doCreation(metadata, false, target);
assertTrue("Expected foreign-key name [" + expectedName + "] not seen in schema creation output", target.containedText(expectedName));
}
Aggregations