use of org.hibernate.boot.registry.StandardServiceRegistry in project giftcard-demo-series by AxonIQ.
the class PrimaryJpaConfig method main.
/**
**********************************************************************
* Simple utility to generate an initial version of the DDL
***********************************************************************
*/
public static void main(String[] args) {
Map<String, Object> settings = new HashMap<>();
settings.put("hibernate.dialect", PostgreSQL94Dialect.class);
settings.put("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class);
settings.put("hibernate.physical_naming_strategy", SpringPhysicalNamingStrategy.class);
StandardServiceRegistry standardServiceRegistry = new StandardServiceRegistryBuilder().applySettings(settings).build();
MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
metadataSources.addAnnotatedClass(TokenEntry.class);
metadataSources.addAnnotatedClass(CardSummary.class);
Metadata metadata = metadataSources.buildMetadata();
SchemaExport schemaExport = new SchemaExport((MetadataImplementor) metadata);
schemaExport.setFormat(true);
schemaExport.setDelimiter(";");
schemaExport.create(Target.SCRIPT);
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project JavaExercises by biblelamp.
the class HW2Lesson method createHibernateSession.
/**
* Creating a session
* @param driverName
* @param dbName
* @param mode [validate|update|create|create-drop]
*] * @return org.hibernate.Session
*/
private Session createHibernateSession(String driverName, String dbName, String mode) {
Session session = null;
try {
Map<String, String> settings = new HashMap<String, String>();
settings.put("hibernate.connection.driver_class", driverName);
settings.put("hibernate.connection.url", dbName);
settings.put("hibernate.connection.username", "");
settings.put("hibernate.connection.password", "");
settings.put("hibernate.dialect", "org.hibernate.dialect.SQLiteDialect");
settings.put("hibernate.show_sql", "true");
settings.put("hibernate.hbm2ddl.auto", mode);
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(settings).build();
session = new MetadataSources(registry).addAnnotatedClass(Product.class).getMetadataBuilder().build().getSessionFactoryBuilder().build().openSession();
} catch (Exception ex) {
ex.printStackTrace();
}
return session;
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project JTemplate by gk-brown.
the class EventServlet method init.
@Override
public void init() throws ServletException {
super.init();
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
session.save(new Event("Event 1", new Date()));
session.save(new Event("Event 2", new Date()));
session.save(new Event("Event 3", new Date()));
session.save(new Event("Event 4", new Date()));
session.save(new Event("Event 5", new Date()));
session.getTransaction().commit();
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project ignite by apache.
the class HibernateL2CacheSelfTest method startHibernate.
/**
* Starts Hibernate.
*
* @param accessType Cache access type.
* @param igniteInstanceName Ignite instance name.
* @return Session factory.
*/
private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
StandardServiceRegistryBuilder builder = registryBuilder();
for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet()) builder.applySetting(e.getKey(), e.getValue());
// Use the same cache for Entity and Entity2.
builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);
StandardServiceRegistry srvcRegistry = builder.build();
MetadataSources metadataSources = new MetadataSources(srvcRegistry);
for (Class entityClass : getAnnotatedClasses()) metadataSources.addAnnotatedClass(entityClass);
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (!entityBinding.isInherited())
((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
}
for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings()) collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName());
return metadata.buildSessionFactory();
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class TimestampsRegionImplTest method testClearTimestampsRegionInIsolated.
public void testClearTimestampsRegionInIsolated() throws Exception {
StandardServiceRegistryBuilder ssrb = createStandardServiceRegistryBuilder();
final StandardServiceRegistry registry = ssrb.build();
final StandardServiceRegistry registry2 = ssrb.build();
try {
final Properties properties = CacheTestUtil.toProperties(ssrb.getSettings());
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(registry, getCacheTestSupport());
InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(registry2, getCacheTestSupport());
TimestampsRegionImpl region = (TimestampsRegionImpl) regionFactory.buildTimestampsRegion(getStandardRegionName(REGION_PREFIX), properties);
TimestampsRegionImpl region2 = (TimestampsRegionImpl) regionFactory2.buildTimestampsRegion(getStandardRegionName(REGION_PREFIX), properties);
Account acct = new Account();
acct.setAccountHolder(new AccountHolder());
region.getCache().withFlags(Flag.FORCE_SYNCHRONOUS).put(acct, "boo");
} finally {
StandardServiceRegistryBuilder.destroy(registry);
StandardServiceRegistryBuilder.destroy(registry2);
}
}
Aggregations