use of org.hibernate.tool.schema.internal.SchemaCreatorImpl in project hibernate-orm by hibernate.
the class SuppliedConnectionTest method prepareTest.
@Override
protected void prepareTest() throws Exception {
super.prepareTest();
try {
Connection conn = cp.getConnection();
try {
final GenerationTargetToDatabase target = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry(), conn), true);
new SchemaCreatorImpl(serviceRegistry()).doCreation(metadata(), false, target);
} finally {
cp.closeConnection(conn);
}
} catch (Throwable ignore) {
}
}
use of org.hibernate.tool.schema.internal.SchemaCreatorImpl in project hibernate-orm by hibernate.
the class AbstractMultiTenancyTest method sessionFactory.
protected SessionFactory sessionFactory(Map<String, Object> settings) {
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
for (Class annotatedClasses : getAnnotatedClasses()) {
metadataSources.addAnnotatedClass(annotatedClasses);
}
Metadata metadata = metadataSources.buildMetadata();
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
tool.injectServices(serviceRegistry);
final GenerationTargetToDatabase frontEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(FRONT_END_TENANT)));
final GenerationTargetToDatabase backEndSchemaGenerator = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProviderMap.get(BACK_END_TENANT)));
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, frontEndSchemaGenerator, backEndSchemaGenerator);
final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
return sessionFactoryBuilder.build();
}
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 ListMappingTest method testOrderColumnInNormalBiDirectonalModel.
@Test
public void testOrderColumnInNormalBiDirectonalModel() {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Order.class).addAnnotatedClass(LineItem.class).buildMetadata();
Collection lineItemsBinding = metadata.getCollectionBindings().iterator().next();
// make sure it was interpreted as a List (aka, as having an OrderColumn at all)
assertThat(lineItemsBinding, instanceOf(org.hibernate.mapping.List.class));
org.hibernate.mapping.List asList = (org.hibernate.mapping.List) lineItemsBinding;
// assert the OrderColumn details
final Column positionColumn = (Column) asList.getIndex().getColumnIterator().next();
assertThat(positionColumn.getName(), equalTo("position"));
// make sure the OrderColumn is part of the collection table
assertTrue(asList.getCollectionTable().containsColumn(positionColumn));
class TargetImpl extends GenerationTargetToStdout {
boolean found = false;
@Override
public void accept(String action) {
super.accept(action);
if (action.startsWith("create table t_line_item")) {
if (action.contains("position")) {
found = true;
}
}
}
}
TargetImpl target = new TargetImpl();
new SchemaCreatorImpl(ssr).doCreation(metadata, true, target);
assertTrue(target.found);
}
use of org.hibernate.tool.schema.internal.SchemaCreatorImpl in project hibernate-orm by hibernate.
the class CollectionKeyFkNameTest method verifyFkNameUsed.
private void verifyFkNameUsed(String mappingResource, String expectedName) {
final Metadata metadata = new MetadataSources(ssr).addResource(mappingResource).buildMetadata();
final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget();
new SchemaCreatorImpl(ssr).doCreation(metadata, ssr, ssr.getService(ConfigurationService.class).getSettings(), false, target);
assertTrue("Expected foreign-key name [" + expectedName + "] not seen in schema creation output", target.containedText(expectedName));
}
Aggregations