Java 类org.hibernate.cache.spi.access.AccessType 实例源码

项目:hazelcast-hibernate5    文件:HazelcastNaturalIdRegion.java   
@Override
public NaturalIdRegionAccessStrategy buildAccessStrategy(final AccessType accessType) throws CacheException {
    if (AccessType.READ_ONLY.equals(accessType)) {
        return new NaturalIdRegionAccessStrategyAdapter(
                new ReadOnlyAccessDelegate<HazelcastNaturalIdRegion>(this, props));
    }
    if (AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new NaturalIdRegionAccessStrategyAdapter(
                new NonStrictReadWriteAccessDelegate<HazelcastNaturalIdRegion>(this, props));
    }
    if (AccessType.READ_WRITE.equals(accessType)) {
        return new NaturalIdRegionAccessStrategyAdapter(
                new ReadWriteAccessDelegate<HazelcastNaturalIdRegion>(this, props));
    }
    throw new CacheException("AccessType \"" + accessType + "\" is not currently supported by Hazelcast.");
}
项目:hazelcast-hibernate5    文件:HazelcastEntityRegion.java   
@Override
public EntityRegionAccessStrategy buildAccessStrategy(final AccessType accessType) throws CacheException {
    if (AccessType.READ_ONLY.equals(accessType)) {
        return new EntityRegionAccessStrategyAdapter(
                new ReadOnlyAccessDelegate<HazelcastEntityRegion>(this, props));
    }
    if (AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new EntityRegionAccessStrategyAdapter(
                new NonStrictReadWriteAccessDelegate<HazelcastEntityRegion>(this, props));
    }
    if (AccessType.READ_WRITE.equals(accessType)) {
        return new EntityRegionAccessStrategyAdapter(
                new ReadWriteAccessDelegate<HazelcastEntityRegion>(this, props));
    }
    throw new CacheException("AccessType \"" + accessType + "\" is not currently supported by Hazelcast.");
}
项目:hazelcast-hibernate5    文件:HazelcastCollectionRegion.java   
@Override
public CollectionRegionAccessStrategy buildAccessStrategy(final AccessType accessType) throws CacheException {
    if (AccessType.READ_ONLY.equals(accessType)) {
        return new CollectionRegionAccessStrategyAdapter(
                new ReadOnlyAccessDelegate<HazelcastCollectionRegion>(this, props));
    }
    if (AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new CollectionRegionAccessStrategyAdapter(
                new NonStrictReadWriteAccessDelegate<HazelcastCollectionRegion>(this, props));
    }
    if (AccessType.READ_WRITE.equals(accessType)) {
        return new CollectionRegionAccessStrategyAdapter(
                new ReadWriteAccessDelegate<HazelcastCollectionRegion>(this, props));
    }
    throw new CacheException("AccessType \"" + accessType + "\" is not currently supported by Hazelcast.");
}
项目:hazelcast-hibernate5    文件:NaturalIdTest.java   
@Test
public void testNaturalIdCacheEvictsEntityOnUpdate() {
    Assume.assumeTrue(defaultAccessType == AccessType.READ_WRITE);

    insertAnnotatedEntities(1);

    Session session = sf.openSession();
    Transaction tx = session.beginTransaction();

    //1 cache hit since dummy:0 just inserted and still in the cache
    AnnotatedEntity toBeUpdated = session.byNaturalId(AnnotatedEntity.class).using("title", "dummy:0").getReference();
    toBeUpdated.setTitle("dummy101");
    tx.commit();
    session.close();

    assertEquals(1, sf.getStatistics().getNaturalIdCacheHitCount());

    //dummy:0 should be evicted and this leads to a cache miss
    session = sf.openSession();
    Criteria criteria = session.createCriteria(AnnotatedEntity.class).add(Restrictions.naturalId().set("title","dummy:0"))
                               .setCacheable(true);
    criteria.uniqueResult();

    assertEquals(1, sf.getStatistics().getNaturalIdCacheMissCount());
}
项目:hazelcast-hibernate5    文件:NaturalIdTest.java   
@Test
public void testNaturalIdCacheStillHitsAfterIrrelevantNaturalIdUpdate() {
    Assume.assumeTrue(defaultAccessType == AccessType.READ_WRITE);

    insertAnnotatedEntities(2);

    Session session = sf.openSession();
    Transaction tx = session.beginTransaction();

    //1 cache hit since dummy:1 just inserted and still in the cache
    AnnotatedEntity toBeUpdated = session.byNaturalId(AnnotatedEntity.class).using("title", "dummy:1").getReference();
    toBeUpdated.setTitle("dummy101");
    tx.commit();
    session.close();

    assertEquals(1, sf.getStatistics().getNaturalIdCacheHitCount());

    //only dummy:1 should be evicted from cache on contrary to behavior of hibernate query cache without natural ids
    session = sf.openSession();
    Criteria criteria = session.createCriteria(AnnotatedEntity.class).add(Restrictions.naturalId().set("title","dummy:0"))
                               .setCacheable(true);
    criteria.uniqueResult();

    //cache hit dummy:0 + previous hit
    assertEquals(2, sf.getStatistics().getNaturalIdCacheHitCount());
}
项目:hazelcast-hibernate    文件:NaturalIdTest.java   
@Test
public void testNaturalIdCacheEvictsEntityOnUpdate() {
    Assume.assumeTrue(defaultAccessType == AccessType.READ_WRITE);

    insertAnnotatedEntities(1);

    Session session = sf.openSession();
    Transaction tx = session.beginTransaction();

    //1 cache hit since dummy:0 just inserted and still in the cache
    AnnotatedEntity toBeUpdated = (AnnotatedEntity)session.byNaturalId(AnnotatedEntity.class).using("title", "dummy:0").getReference();
    toBeUpdated.setTitle("dummy101");
    tx.commit();
    session.close();

    assertEquals(1, sf.getStatistics().getNaturalIdCacheHitCount());

    //dummy:0 should be evicted and this leads to a cache miss
    session = sf.openSession();
    Criteria criteria = session.createCriteria(AnnotatedEntity.class).add(Restrictions.naturalId().set("title","dummy:0"))
                               .setCacheable(true);
    criteria.uniqueResult();

    assertEquals(1, sf.getStatistics().getNaturalIdCacheMissCount());
}
项目:hazelcast-hibernate    文件:NaturalIdTest.java   
@Test
public void testNaturalIdCacheStillHitsAfterIrrelevantNaturalIdUpdate() {
    Assume.assumeTrue(defaultAccessType == AccessType.READ_WRITE);

    insertAnnotatedEntities(2);

    Session session = sf.openSession();
    Transaction tx = session.beginTransaction();

    //1 cache hit since dummy:1 just inserted and still in the cache
    AnnotatedEntity toBeUpdated = (AnnotatedEntity)session.byNaturalId(AnnotatedEntity.class).using("title", "dummy:1").getReference();
    toBeUpdated.setTitle("dummy101");
    tx.commit();
    session.close();

    assertEquals(1, sf.getStatistics().getNaturalIdCacheHitCount());

    //only dummy:1 should be evicted from cache on contrary to behavior of hibernate query cache without natural ids
    session = sf.openSession();
    Criteria criteria = session.createCriteria(AnnotatedEntity.class).add(Restrictions.naturalId().set("title","dummy:0"))
                               .setCacheable(true);
    criteria.uniqueResult();

    //cache hit dummy:0 + previous hit
    assertEquals(2, sf.getStatistics().getNaturalIdCacheHitCount());
}
项目:ignite    文件:HibernateTransactionalDataRegion.java   
/**
 * @param accessType Hibernate L2 cache access type.
 * @return Access strategy for given access type.
 */
HibernateAccessStrategyAdapter createAccessStrategy(AccessType accessType) {
    switch (accessType) {
        case READ_ONLY:
            return factory.accessStrategyFactory().createReadOnlyStrategy(cache);

        case NONSTRICT_READ_WRITE:
            return factory.accessStrategyFactory().createNonStrictReadWriteStrategy(cache);

        case READ_WRITE:
            return factory.accessStrategyFactory().createReadWriteStrategy(cache);

        case TRANSACTIONAL:
            return factory.accessStrategyFactory().createTransactionalStrategy(cache);

        default:
            throw new IllegalArgumentException("Unknown Hibernate access type: " + accessType);
    }
}
项目:ignite    文件:HibernateTransactionalDataRegion.java   
/**
 * @param accessType Hibernate L2 cache access type.
 * @return Access strategy for given access type.
 */
HibernateAccessStrategyAdapter createAccessStrategy(AccessType accessType) {
    switch (accessType) {
        case READ_ONLY:
            return factory.accessStrategyFactory().createReadOnlyStrategy(cache);

        case NONSTRICT_READ_WRITE:
            return factory.accessStrategyFactory().createNonStrictReadWriteStrategy(cache);

        case READ_WRITE:
            return factory.accessStrategyFactory().createReadWriteStrategy(cache);

        case TRANSACTIONAL:
            return factory.accessStrategyFactory().createTransactionalStrategy(cache);

        default:
            throw new IllegalArgumentException("Unknown Hibernate access type: " + accessType);
    }
}
项目:ignite    文件:HibernateL2CacheSelfTest.java   
/**
 * @param accessType Hibernate L2 cache access type.
 * @param igniteInstanceName Ignite instance name.
 * @return Hibernate configuration.
 */
private Configuration hibernateConfiguration(AccessType accessType,
    String igniteInstanceName) {
    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());

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

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

    return cfg;
}
项目:hibernate-l2-memcached    文件:MemcachedEntityRegion.java   
public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {

        switch (accessType) {
            case READ_ONLY:
                if (metadata.isMutable()) {
                    log.warn("read-only cache configured for mutable entity [" + getName() + "]");
                }
                return new ReadOnlyMemcachedEntityRegionAccessStrategy(this, settings);
            case READ_WRITE:
                return new ReadWriteMemcachedEntityRegionAccessStrategy(this, settings);
            case NONSTRICT_READ_WRITE:
                return new NonStrictReadWriteMemcachedEntityRegionAccessStrategy(this, settings);
            case TRANSACTIONAL:
                return new TransactionalMemcachedEntityRegionAccessStrategy(this, cache, settings);
            default:
                throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]");
        }
    }
项目:hibernate-l2-memcached    文件:MemcachedNaturalIdRegion.java   
public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {

        switch (accessType) {

            case READ_ONLY:
                if (metadata.isMutable()) {
                    log.warn("read-only cache configured for mutable entity ["
                            + getName() + "]");
                }
                return new ReadOnlyMemcachedNaturalIdRegionAccessStrategy(this, settings);
            case READ_WRITE:
                return new ReadWriteMemcachedNaturalIdRegionAccessStrategy(this, settings, metadata);
            case NONSTRICT_READ_WRITE:
                return new NonStrictReadWriteMemcachedNaturalIdRegionAccessStrategy(this, settings);
            case TRANSACTIONAL:
                return new TransactionalMemcachedNaturalIdRegionAccessStrategy(this, settings);
            default:
                throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]");
        }
    }
项目:hibernate-l2-memcached    文件:MemcachedCollectionRegion.java   
public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {

        switch (accessType) {
            case READ_ONLY:
                if (metadata.isMutable()) {
                    log.warn("read-only cache configured for mutable entity [" + getName() + "]");
                }
                return new ReadOnlyMemcachedCollectionRegionAccessStrategy(this, settings);
            case READ_WRITE:
                return new ReadWriteMemcachedCollectionRegionAccessStrategy(this, settings);
            case NONSTRICT_READ_WRITE:
                return new NonStrictReadWriteMemcachedCollectionRegionAccessStrategy(this, settings);
            case TRANSACTIONAL:
                return new TransactionalMemcachedCollectionRegionAccessStrategy(this, settings);
            default:
                throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]");
        }
    }
项目:hibernate4-memcached    文件:NaturalIdRegionImpl.java   
@Override
    public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
        switch ( accessType ) {
            case READ_ONLY:
                if ( getCacheDataDescription().isMutable() ) {
                    LOG.warnf( "read-only cache configured for mutable collection [ %s ]", getName() );
                }
                return new ReadOnlyNaturalIdRegionAccessStrategy( this );
            case READ_WRITE:
                 return new ReadWriteNaturalIdRegionAccessStrategy( this );
            case NONSTRICT_READ_WRITE:
                return new NonstrictReadWriteNaturalIdRegionAccessStrategy( this );
            case TRANSACTIONAL:
                return new TransactionalNaturalIdRegionAccessStrategy( this );
//              throw new UnsupportedOperationException( "doesn't support this access strategy" );
            default:
                throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
        }
    }
项目:hibernate4-memcached    文件:CollectionRegionImpl.java   
@Override
    public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
        switch ( accessType ) {
            case READ_ONLY:
                if ( getCacheDataDescription().isMutable() ) {
                    LOG.warnf( "read-only cache configured for mutable collection [ %s ]", getName() );
                }
                return new ReadOnlyCollectionRegionAccessStrategy( this );
            case READ_WRITE:
                 return new ReadWriteCollectionRegionAccessStrategy( this );
            case NONSTRICT_READ_WRITE:
                return new NonstrictReadWriteCollectionRegionAccessStrategy( this );
            case TRANSACTIONAL:
                return new TransactionalCollectionRegionAccessStrategy( this );
//              throw new UnsupportedOperationException( "doesn't support this access strategy" );
            default:
                throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
        }
    }
项目:hibernate4-memcached    文件:EntityRegionImpl.java   
@Override
    public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
        switch ( accessType ) {
            case READ_ONLY:
                if ( getCacheDataDescription().isMutable() ) {
                    LOG.warnf( "read-only cache configured for mutable entity [ %s ]", getName() );
                }
                return new ReadOnlyEntityRegionAccessStrategy( this );
            case READ_WRITE:
                return new ReadWriteEntityRegionAccessStrategy( this );
            case NONSTRICT_READ_WRITE:
                return new NonstrictReadWriteEntityRegionAccessStrategy( this );
            case TRANSACTIONAL:
//              throw new UnsupportedOperationException( "doesn't support this access strategy" );
                return new TransactionalEntityRegionAccessStrategy( this );

            default:
                throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
        }

    }
项目:lams    文件:AbstractPluralAttributeSourceImpl.java   
@Override
public Caching getCaching() {
    final JaxbCacheElement cache = pluralAttributeElement.getCache();
    if ( cache == null ) {
        return null;
    }
    final String region = cache.getRegion() != null
            ? cache.getRegion()
            : StringHelper.qualify( container().getPath(), getName() );
    final AccessType accessType = Enum.valueOf( AccessType.class, cache.getUsage() );
    final boolean cacheLazyProps = !"non-lazy".equals( cache.getInclude() );
    return new Caching( region, accessType, cacheLazyProps );
}
项目:lams    文件:RootEntitySourceImpl.java   
@Override
public Caching getCaching() {
    final JaxbCacheElement cache = entityElement().getCache();
    if ( cache == null ) {
        return null;
    }
    final String region = cache.getRegion() != null ? cache.getRegion() : getEntityName();
    final AccessType accessType = Enum.valueOf( AccessType.class, cache.getUsage() );
    final boolean cacheLazyProps = !"non-lazy".equals( cache.getInclude() );
    return new Caching( region, accessType, cacheLazyProps );
}
项目:hazelcast-hibernate5    文件:NaturalIdTest.java   
@Parameterized.Parameters(name = "Executing: {0}")
public static Collection<Object[]> parameters() {
    return Arrays.asList(new Object[]{AccessType.READ_WRITE},
            new Object[]{AccessType.READ_ONLY},
            new Object[]{AccessType.NONSTRICT_READ_WRITE}
    );
}
项目:hazelcast-hibernate    文件:HazelcastNaturalIdRegion.java   
public NaturalIdRegionAccessStrategy buildAccessStrategy(final AccessType accessType) throws CacheException {
    if (AccessType.READ_ONLY.equals(accessType)) {
        return new NaturalIdRegionAccessStrategyAdapter(
                new ReadOnlyAccessDelegate<HazelcastNaturalIdRegion>(this, props));
    }
    if (AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new NaturalIdRegionAccessStrategyAdapter(
                new NonStrictReadWriteAccessDelegate<HazelcastNaturalIdRegion>(this, props));
    }
    if (AccessType.READ_WRITE.equals(accessType)) {
        return new NaturalIdRegionAccessStrategyAdapter(
                new ReadWriteAccessDelegate<HazelcastNaturalIdRegion>(this, props));
    }
    throw new CacheException("AccessType \"" + accessType + "\" is not currently supported by Hazelcast.");
}
项目:hazelcast-hibernate    文件:HazelcastEntityRegion.java   
public EntityRegionAccessStrategy buildAccessStrategy(final AccessType accessType) throws CacheException {
    if (AccessType.READ_ONLY.equals(accessType)) {
        return new EntityRegionAccessStrategyAdapter(
                new ReadOnlyAccessDelegate<HazelcastEntityRegion>(this, props));
    }
    if (AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new EntityRegionAccessStrategyAdapter(
                new NonStrictReadWriteAccessDelegate<HazelcastEntityRegion>(this, props));
    }
    if (AccessType.READ_WRITE.equals(accessType)) {
        return new EntityRegionAccessStrategyAdapter(
                new ReadWriteAccessDelegate<HazelcastEntityRegion>(this, props));
    }
    throw new CacheException("AccessType \"" + accessType + "\" is not currently supported by Hazelcast.");
}
项目:hazelcast-hibernate    文件:HazelcastCollectionRegion.java   
public CollectionRegionAccessStrategy buildAccessStrategy(final AccessType accessType) throws CacheException {
    if (AccessType.READ_ONLY.equals(accessType)) {
        return new CollectionRegionAccessStrategyAdapter(
                new ReadOnlyAccessDelegate<HazelcastCollectionRegion>(this, props));
    }
    if (AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new CollectionRegionAccessStrategyAdapter(
                new NonStrictReadWriteAccessDelegate<HazelcastCollectionRegion>(this, props));
    }
    if (AccessType.READ_WRITE.equals(accessType)) {
        return new CollectionRegionAccessStrategyAdapter(
                new ReadWriteAccessDelegate<HazelcastCollectionRegion>(this, props));
    }
    throw new CacheException("AccessType \"" + accessType + "\" is not currently supported by Hazelcast.");
}
项目:hazelcast-hibernate    文件:NaturalIdTest.java   
@Parameterized.Parameters(name = "Executing: {0}")
public static Collection<Object[]> parameters() {
    return Arrays.asList(new Object[]{AccessType.READ_WRITE},
            new Object[]{AccessType.READ_ONLY},
            new Object[]{AccessType.NONSTRICT_READ_WRITE}
    );
}
项目:TayzGrid    文件:TayzGridStrategyBuilder.java   
public static CollectionRegionAccessStrategy buildCollectionRegionAccessStrategy(TayzGridCollectionRegion region, AccessType accessType) {
    switch (accessType) {
        case READ_ONLY:
            return new ReadOnlyTayzGridCollectionRegionAccessStrategy(region);
        case NONSTRICT_READ_WRITE:
            return new NonStrictReadWriteTayzGridCollectionRegionAccessStrategy(region);
        case READ_WRITE:
            return new ReadWriteTayzGridCollectionRegionAccessStrategy(region);
        case TRANSACTIONAL:
            throw new IllegalArgumentException(accessType + " access strategy not supported.");
        default:
            throw new IllegalArgumentException(accessType + " is not recognized as valid access type.");
    }
}
项目:TayzGrid    文件:TayzGridStrategyBuilder.java   
public static EntityRegionAccessStrategy buildEntityRegionAccessStrategy(TayzGridEntityRegion region, AccessType accessType) {
    switch (accessType) {
        case READ_ONLY:
            return new ReadOnlyTayzGridEntityRegionAccessStrategy(region);
        case NONSTRICT_READ_WRITE:
            return new NonStrictReadWriteTayzGridEntityRegionAccessStrategy(region);
        case READ_WRITE:
            return new ReadWriteTayzGridEntityRegionAccessStrategy(region);
        case TRANSACTIONAL:
            throw new IllegalArgumentException(accessType + " access strategy not supported.");
        default:
            throw new IllegalArgumentException(accessType + " is not recognized as valid access type.");
    }
}
项目:TayzGrid    文件:TayzGridStrategyBuilder.java   
public static NaturalIdRegionAccessStrategy buildNaturalIdRegionAccessStrategy(TayzGridNaturalIdRegion region, AccessType accessType) {
    switch (accessType) {
        case READ_ONLY:
            return new ReadOnlyTayzGridNaturalIdRegionAccessStrategy(region);
        case NONSTRICT_READ_WRITE:
            return  new NonStrictReadWriteTayzGridNaturalIdRegionAccessStrategy(region);
        case READ_WRITE:
            return new ReadWriteTayzGridNaturalIdRegionAccessStraegy(region);
        case TRANSACTIONAL:
            throw new IllegalArgumentException(accessType + " access strategy not supported.");
        default:
            throw new IllegalArgumentException(accessType + " is not recognized as valid access type.");
    }
}
项目:ignite    文件:HibernateRegionFactory.java   
/** {@inheritDoc} */
@Override public void start(SessionFactoryOptions settings, Properties props) throws CacheException {
    String accessType = props.getProperty(DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name());

    dfltAccessType = AccessType.valueOf(accessType);

    accessStgyFactory.start(props);
}
项目:ignite    文件:HibernateL2CacheStrategySelfTest.java   
/**
 * @param accessType Cache access typr.
 * @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();
}
项目:ignite    文件:HibernateL2CacheSelfTest.java   
/**
 * 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();
}
项目:ignite    文件:HibernateRegionFactory.java   
/** {@inheritDoc} */
@Override public void start(Settings settings, Properties props) throws CacheException {
    String accessType = props.getProperty(DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name());

    dfltAccessType = AccessType.valueOf(accessType);

    accessStgyFactory.start(props);
}
项目:ignite    文件:HibernateL2CacheStrategySelfTest.java   
/**
 * @param accessType Cache access typr.
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    Configuration cfg = hibernateConfiguration(accessType, igniteInstanceName);

    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();

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

    return cfg.buildSessionFactory(builder.buildServiceRegistry());
}
项目:hibernate-memcached    文件:MemcachedEntityRegion.java   
public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    if(AccessType.READ_ONLY.equals(accessType)) {
        return new ReadOnlyMemcachedEntityRegionAccessStrategy(this, settings);
    } else if(AccessType.READ_WRITE.equals(accessType)) {
        return new ReadWriteMemcachedEntityRegionAccessStrategy(this, settings);
    } else if(AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new NonStrictReadWriteMemcachedEntityRegionAccessStrategy(this, settings);
    } else if(AccessType.TRANSACTIONAL.equals(accessType)) {
        throw new CacheException("Transactional access is not supported by Memcached region factory");
    } else {
        throw new IllegalArgumentException("Unknown access strategy type - " + accessType);
    }
}
项目:hibernate-memcached    文件:MemcachedCollectionRegion.java   
public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    if(AccessType.READ_ONLY.equals(accessType)) {
        return new ReadOnlyMemcachedCollectionRegionAccessStrategy(this, settings);
    } else if(AccessType.READ_WRITE.equals(accessType)) {
        return new ReadWriteMemcachedCollectionRegionAccessStrategy(this, settings);
    } else if(AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new NonStrictReadWriteMemcachedCollectionRegionAccessStrategy(this, settings);
    } else if(AccessType.TRANSACTIONAL.equals(accessType)) {
        throw new CacheException("Transactional access is not supported by Memcached region factory");
    } else {
        throw new UnsupportedOperationException("Uknown access strategy type - " + accessType);
    }
}
项目:hibernate4-memcached    文件:CachingRegionFactory.java   
@Override
public AccessType getDefaultAccessType() {
    if (properties != null && properties.get(DEFAULT_ACCESSTYPE) != null) {
        return AccessType.fromExternalName(properties.getProperty(DEFAULT_ACCESSTYPE));
    }
    return AccessType.READ_WRITE;
}
项目:hibernate4-memcached    文件:NaturalIdMemcachedRegion.java   
@Override
public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    switch (accessType) {
        case READ_ONLY:
            return new ReadOnlyNaturalIdRegionAccessStrategy(this);
        case NONSTRICT_READ_WRITE:
            return new NonstrictReadWriteNaturalIdRegionAccessStrategy(this);
        default:
            throw new CacheException("Unsupported access strategy : " + accessType + ".");
    }
}
项目:hibernate4-memcached    文件:EntityMemcachedRegion.java   
@Override
public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    switch (accessType) {
        case READ_ONLY:
            return new ReadOnlyEntityRegionAccessStrategy(this);
        case NONSTRICT_READ_WRITE:
            return new NonstrictReadWriteEntityRegionAccessStrategy(this);
        default:
            throw new CacheException("Unsupported access strategy : " + accessType + ".");
    }
}
项目:hibernate4-memcached    文件:CollectionMemcachedRegion.java   
@Override
public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    switch (accessType) {
        case READ_ONLY:
            return new ReadOnlyCollectionRegionAccessStrategy(this);
        case NONSTRICT_READ_WRITE:
            return new NonstrictReadWriteCollectionRegionAccessStrategy(this);
        default:
            throw new CacheException("Unsupported access strategy : " + accessType + ".");
    }
}
项目:lams    文件:Caching.java   
public Caching(String region, AccessType accessType, boolean cacheLazyProperties) {
    this.region = region;
    this.accessType = accessType;
    this.cacheLazyProperties = cacheLazyProperties;
}
项目:lams    文件:Caching.java   
public AccessType getAccessType() {
    return accessType;
}
项目:lams    文件:Caching.java   
public void setAccessType(AccessType accessType) {
    this.accessType = accessType;
}