use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class HiloOptimizerConcurrencyTest method testTwoSessionsSerialGeneration.
@Test
public void testTwoSessionsSerialGeneration() {
createSchema = true;
rebuildSessionFactory();
StandardServiceRegistry serviceRegistry = serviceRegistry();
SessionFactoryImplementor sessionFactory = sessionFactory();
try {
final Session session1 = openSession();
try {
session1.beginTransaction();
HibPerson p = new HibPerson();
session1.save(p);
} finally {
session1.getTransaction().commit();
}
createSchema = false;
buildResources();
final Session session2 = openSession();
session2.beginTransaction();
try {
HibPerson p = new HibPerson();
session2.save(p);
} finally {
session2.getTransaction().commit();
}
for (int i = 2; i < 6; i++) {
session1.beginTransaction();
try {
HibPerson p = new HibPerson();
session1.save(p);
} finally {
session1.getTransaction().commit();
}
}
session2.beginTransaction();
try {
HibPerson p = new HibPerson();
session2.save(p);
} finally {
session2.getTransaction().commit();
}
session1.beginTransaction();
try {
HibPerson p = new HibPerson();
session1.save(p);
} finally {
session1.getTransaction().commit();
}
} catch (ConstraintViolationException cve) {
fail("ConstraintViolationException: " + cve.getMessage());
} finally {
releaseResources(serviceRegistry, sessionFactory);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SmokeTest method testEhcacheShortName.
@Test
public void testEhcacheShortName() {
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.CACHE_REGION_FACTORY, "ehcache").build();
assertThat(registry.getService(RegionFactory.class), instanceOf(EhcacheRegionFactory.class));
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SqlServerQuoteSchemaTest method test.
@Test
public void test() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE.toString()).build();
try {
output.deleteOnExit();
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
try {
String fileContent = new String(Files.readAllBytes(output.toPath()));
Pattern fileContentPattern = Pattern.compile("create table \\[my\\-schema\\]\\.\\[my_entity\\]");
Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
assertThat(fileContentMatcher.find(), is(true));
} catch (IOException e) {
fail(e.getMessage());
}
ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE.toString()).build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntityUpdated.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
try {
String fileContent = new String(Files.readAllBytes(output.toPath()));
Pattern fileContentPattern = Pattern.compile("alter table .*?\\.\\[my\\-schema\\]\\.\\[my_entity\\]");
Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
assertThat(fileContentMatcher.find(), is(true));
} catch (IOException e) {
fail(e.getMessage());
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class SchemaUpdateFormatterTest method testSetFormat.
@Test
public void testSetFormat() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").build();
try {
File output = File.createTempFile("update_script", ".sql");
output.deleteOnExit();
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(DELIMITER).setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
String outputContent = new String(Files.readAllBytes(output.toPath()));
// Old Macs use \r as a new line delimiter
outputContent = outputContent.replaceAll("\r", "\n");
// On Windows, \r\n would become \n\n, so we eliminate duplicates
outputContent = outputContent.replaceAll("\n\n", "\n");
Assert.assertTrue(Pattern.compile(AFTER_FORMAT).matcher(outputContent).matches());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class GeometryConverterTest method testConverterUsage.
@Test
public void testConverterUsage() {
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, GeoDBDialect.class).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(GeometryConverter.class).addAnnotatedClass(MyEntity.class);
final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
try (final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) metadataBuilder.build().buildSessionFactory()) {
final TypeConfiguration typeConfiguration = sessionFactory.getMetamodel().getTypeConfiguration();
assertThat(typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(Geometry.class), sameInstance(GeolatteGeometryJavaTypeDescriptor.INSTANCE));
// todo (5.3) : what to assert wrt to SqlTypeDescriptor? Anything?
final EntityPersister entityPersister = sessionFactory.getMetamodel().entityPersister(MyEntity.class);
final AttributeConverterTypeAdapter geometryAttributeType = assertTyping(AttributeConverterTypeAdapter.class, entityPersister.getPropertyType("geometry"));
final JpaAttributeConverter converter = assertTyping(JpaAttributeConverter.class, geometryAttributeType.getAttributeConverter());
assert GeometryConverter.class.equals(converter.getConverterBean().getBeanClass());
}
}
}
Aggregations