Example usage for org.hibernate.cache.spi.access AccessType getExternalName

List of usage examples for org.hibernate.cache.spi.access AccessType getExternalName

Introduction

In this page you can find the example usage for org.hibernate.cache.spi.access AccessType getExternalName.

Prototype

public String getExternalName() 

Source Link

Document

Get the corresponding externalized name for this value.

Usage

From source file:org.apache.ignite.cache.hibernate.GridHibernateL2CacheSelfTest.java

License:Apache License

/**
 * @param accessType Hibernate L2 cache access type.
 * @param gridName Grid name./*  w w w  .j av  a2  s. c  o  m*/
 * @return Hibernate configuration.
 */
protected Configuration hibernateConfiguration(org.hibernate.cache.spi.access.AccessType accessType,
        String gridName) {
    Configuration cfg = new Configuration();

    cfg.addAnnotatedClass(Entity.class);
    cfg.addAnnotatedClass(Entity2.class);
    cfg.addAnnotatedClass(VersionedEntity.class);
    cfg.addAnnotatedClass(ChildEntity.class);
    cfg.addAnnotatedClass(ParentEntity.class);

    cfg.setCacheConcurrencyStrategy(ENTITY_NAME, accessType.getExternalName());
    cfg.setCacheConcurrencyStrategy(ENTITY2_NAME, accessType.getExternalName());
    cfg.setCacheConcurrencyStrategy(VERSIONED_ENTITY_NAME, accessType.getExternalName());
    cfg.setCacheConcurrencyStrategy(PARENT_ENTITY_NAME, accessType.getExternalName());
    cfg.setCollectionCacheConcurrencyStrategy(CHILD_COLLECTION_REGION, accessType.getExternalName());

    cfg.setProperty(HBM2DDL_AUTO, "create");

    cfg.setProperty(GENERATE_STATISTICS, "true");

    cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true");

    cfg.setProperty(USE_QUERY_CACHE, "true");

    cfg.setProperty(CACHE_REGION_FACTORY, GridHibernateRegionFactory.class.getName());

    cfg.setProperty(RELEASE_CONNECTIONS, "on_close");

    cfg.setProperty(GRID_NAME_PROPERTY, gridName);

    // Use the same cache for Entity and Entity2.
    cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);

    cfg.setProperty(DFLT_ACCESS_TYPE_PROPERTY, accessType.name());

    return cfg;
}

From source file:org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest.java

License:Apache License

/**
 * @param accessType Hibernate L2 cache access type.
 * @param gridName Grid name.//from  ww  w.  j a v  a 2s. co  m
 * @return Hibernate configuration.
 */
protected Configuration hibernateConfiguration(org.hibernate.cache.spi.access.AccessType accessType,
        String gridName) {
    Configuration cfg = new Configuration();

    cfg.addAnnotatedClass(Entity.class);
    cfg.addAnnotatedClass(Entity2.class);
    cfg.addAnnotatedClass(VersionedEntity.class);
    cfg.addAnnotatedClass(ChildEntity.class);
    cfg.addAnnotatedClass(ParentEntity.class);

    cfg.setCacheConcurrencyStrategy(ENTITY_NAME, accessType.getExternalName());
    cfg.setCacheConcurrencyStrategy(ENTITY2_NAME, accessType.getExternalName());
    cfg.setCacheConcurrencyStrategy(VERSIONED_ENTITY_NAME, accessType.getExternalName());
    cfg.setCacheConcurrencyStrategy(PARENT_ENTITY_NAME, accessType.getExternalName());
    cfg.setCollectionCacheConcurrencyStrategy(CHILD_COLLECTION_REGION, accessType.getExternalName());

    cfg.setProperty(HBM2DDL_AUTO, "create");

    cfg.setProperty(GENERATE_STATISTICS, "true");

    cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true");

    cfg.setProperty(USE_QUERY_CACHE, "true");

    cfg.setProperty(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());

    cfg.setProperty(RELEASE_CONNECTIONS, "on_close");

    cfg.setProperty(GRID_NAME_PROPERTY, gridName);

    // Use the same cache for Entity and Entity2.
    cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);

    cfg.setProperty(DFLT_ACCESS_TYPE_PROPERTY, accessType.name());

    return cfg;
}

From source file:org.apache.ignite.cache.hibernate.HibernateL2CacheStrategySelfTest.java

License:Apache License

/**
 * @param accessType Cache access typr./*from   w  w  w  . java  2  s .  c o m*/
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);

    for (Map.Entry<String, String> e : HibernateL2CacheSelfTest
            .hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    builder.applySetting(USE_STRUCTURED_CACHE, "true");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
    builder.applySetting(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
    builder.applySetting(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);

    MetadataSources metadataSources = new MetadataSources(builder.build());

    metadataSources.addAnnotatedClass(Entity1.class);
    metadataSources.addAnnotatedClass(Entity2.class);
    metadataSources.addAnnotatedClass(Entity3.class);
    metadataSources.addAnnotatedClass(Entity4.class);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    return metadata.buildSessionFactory();
}

From source file:org.infinispan.test.hibernate.cache.commons.stress.CorrectnessTestCase.java

License:LGPL

private Metadata buildMetadata(StandardServiceRegistry registry) {
    MetadataSources metadataSources = new MetadataSources(registry);
    for (Class entityClass : getAnnotatedClasses()) {
        metadataSources.addAnnotatedClass(entityClass);
    }/*from www  .ja v a2s . com*/

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited()) {
            ((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
        }
    }

    // Collections don't have integrated version, these piggyback on parent's owner version (for DB).
    // However, this version number isn't extractable and is not passed to cache methods.
    AccessType collectionAccessType = accessType == AccessType.NONSTRICT_READ_WRITE ? AccessType.READ_WRITE
            : accessType;
    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        collectionBinding.setCacheConcurrencyStrategy(collectionAccessType.getExternalName());
    }

    return metadata;
}