Java Code Examples for org.hibernate.cfg.Configuration#setCollectionCacheConcurrencyStrategy()

The following examples show how to use org.hibernate.cfg.Configuration#setCollectionCacheConcurrencyStrategy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateL2CacheSelfTest.java    From ignite with Apache License 2.0 7 votes vote down vote up
/**
 * @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;
}
 
Example 2
Source File: ExecutionEnvironment.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void applyCacheSettings(Configuration configuration) {
	if ( settings.getCacheConcurrencyStrategy() != null ) {
		Iterator iter = configuration.getClassMappings();
		while ( iter.hasNext() ) {
			PersistentClass clazz = (PersistentClass) iter.next();
			Iterator props = clazz.getPropertyClosureIterator();
			boolean hasLob = false;
			while ( props.hasNext() ) {
				Property prop = (Property) props.next();
				if ( prop.getValue().isSimpleValue() ) {
					String type = ( ( SimpleValue ) prop.getValue() ).getTypeName();
					if ( "blob".equals(type) || "clob".equals(type) ) {
						hasLob = true;
					}
					if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) {
						hasLob = true;
					}
				}
			}
			if ( !hasLob && !clazz.isInherited() && settings.overrideCacheStrategy() ) {
				configuration.setCacheConcurrencyStrategy( clazz.getEntityName(), settings.getCacheConcurrencyStrategy() );
			}
		}
		iter = configuration.getCollectionMappings();
		while ( iter.hasNext() ) {
			Collection coll = (Collection) iter.next();
			configuration.setCollectionCacheConcurrencyStrategy( coll.getRole(), settings.getCacheConcurrencyStrategy() );
		}
	}
}