Search in sources :

Example 91 with StandardServiceRegistry

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);
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport)

Example 92 with StandardServiceRegistry

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;
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) MetadataSources(org.hibernate.boot.MetadataSources) Session(org.hibernate.Session) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 93 with StandardServiceRegistry

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();
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Date(java.util.Date) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Session(org.hibernate.Session)

Example 94 with StandardServiceRegistry

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();
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) Map(java.util.Map) HashMap(java.util.HashMap) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 95 with StandardServiceRegistry

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);
    }
}
Also used : TimestampsRegionImpl(org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl) Account(org.hibernate.test.cache.infinispan.functional.entities.Account) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Properties(java.util.Properties) AccountHolder(org.hibernate.test.cache.infinispan.functional.entities.AccountHolder) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Aggregations

StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)169 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)152 Test (org.junit.Test)121 MetadataSources (org.hibernate.boot.MetadataSources)118 Metadata (org.hibernate.boot.Metadata)56 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)39 PersistentClass (org.hibernate.mapping.PersistentClass)39 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)25 TestForIssue (org.hibernate.testing.TestForIssue)24 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)23 Properties (java.util.Properties)20 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)20 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)15 SessionFactory (org.hibernate.SessionFactory)14 Column (org.hibernate.mapping.Column)14 Property (org.hibernate.mapping.Property)14 Session (org.hibernate.Session)13 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)12 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)11 RootClass (org.hibernate.mapping.RootClass)11