Java Code Examples for org.hibernate.mapping.RootClass#setCacheRegionName()

The following examples show how to use org.hibernate.mapping.RootClass#setCacheRegionName() . 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: Configuration.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String region, boolean includeLazy)
		throws MappingException {
	RootClass rootClass = getRootClassMapping( clazz );
	if ( rootClass == null ) {
		throw new MappingException( "Cannot cache an unknown entity: " + clazz );
	}
	rootClass.setCacheConcurrencyStrategy( concurrencyStrategy );
	rootClass.setCacheRegionName( region );
	rootClass.setLazyPropertiesCacheable( includeLazy );
}
 
Example 2
Source File: ModelBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void applyCaching(MappingDocument mappingDocument, Caching caching, RootClass rootEntityDescriptor) {
	if ( caching == null || caching.getRequested() == TruthValue.UNKNOWN ) {
		// see if JPA's SharedCacheMode indicates we should implicitly apply caching
		//
		// here we only really look for ALL.  Ideally we could look at NONE too as a means
		// to selectively disable all caching, but historically hbm.xml mappings were processed
		// outside this concept and whether to cache or not was defined wholly by what
		// is defined in the mapping document.  So for backwards compatibility we
		// do not consider ENABLE_SELECTIVE nor DISABLE_SELECTIVE here.
		//
		// Granted, ALL was not historically considered either, but I have a practical
		// reason for wanting to support this... our legacy tests built using
		// Configuration applied a similar logic but that capability is no longer
		// accessible from Configuration
		switch ( mappingDocument.getBuildingOptions().getSharedCacheMode() ) {
			case ALL: {
				caching = new Caching(
						null,
						mappingDocument.getBuildingOptions().getImplicitCacheAccessType(),
						false,
						TruthValue.UNKNOWN
				);
				break;
			}
			case NONE: {
				// Ideally we'd disable all caching...
				break;
			}
			case ENABLE_SELECTIVE: {
				// this is default behavior for hbm.xml
				break;
			}
			case DISABLE_SELECTIVE: {
				// really makes no sense for hbm.xml
				break;
			}
			default: {
				// null or UNSPECIFIED, nothing to do.  IMO for hbm.xml this is equivalent
				// to ENABLE_SELECTIVE
				break;
			}
		}
	}

	if ( caching == null || caching.getRequested() == TruthValue.FALSE ) {
		return;
	}

	if ( caching.getAccessType() != null ) {
		rootEntityDescriptor.setCacheConcurrencyStrategy( caching.getAccessType().getExternalName() );
	}
	else {
		rootEntityDescriptor.setCacheConcurrencyStrategy( mappingDocument.getBuildingOptions().getImplicitCacheAccessType().getExternalName() );
	}
	rootEntityDescriptor.setCacheRegionName( caching.getRegion() );
	rootEntityDescriptor.setLazyPropertiesCacheable( caching.isCacheLazyProperties() );
	rootEntityDescriptor.setCached( caching.getRequested() != TruthValue.UNKNOWN );
}
 
Example 3
Source File: HbmBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void bindRootPersistentClassCommonValues(Element node,
		java.util.Map inheritedMetas, Mappings mappings, RootClass entity)
		throws MappingException {

	// DB-OBJECTNAME

	Attribute schemaNode = node.attribute( "schema" );
	String schema = schemaNode == null ?
			mappings.getSchemaName() : schemaNode.getValue();

	Attribute catalogNode = node.attribute( "catalog" );
	String catalog = catalogNode == null ?
			mappings.getCatalogName() : catalogNode.getValue();

	Table table = mappings.addTable(
			schema,
			catalog,
			getClassTableName( entity, node, schema, catalog, null, mappings ),
			getSubselect( node ),
	        entity.isAbstract() != null && entity.isAbstract().booleanValue()
		);
	entity.setTable( table );
	bindComment(table, node);

	log.info(
			"Mapping class: " + entity.getEntityName() +
			" -> " + entity.getTable().getName()
		);

	// MUTABLE
	Attribute mutableNode = node.attribute( "mutable" );
	entity.setMutable( ( mutableNode == null ) || mutableNode.getValue().equals( "true" ) );

	// WHERE
	Attribute whereNode = node.attribute( "where" );
	if ( whereNode != null ) entity.setWhere( whereNode.getValue() );

	// CHECK
	Attribute chNode = node.attribute( "check" );
	if ( chNode != null ) table.addCheckConstraint( chNode.getValue() );

	// POLYMORPHISM
	Attribute polyNode = node.attribute( "polymorphism" );
	entity.setExplicitPolymorphism( ( polyNode != null )
		&& polyNode.getValue().equals( "explicit" ) );

	// ROW ID
	Attribute rowidNode = node.attribute( "rowid" );
	if ( rowidNode != null ) table.setRowId( rowidNode.getValue() );

	Iterator subnodes = node.elementIterator();
	while ( subnodes.hasNext() ) {

		Element subnode = (Element) subnodes.next();
		String name = subnode.getName();

		if ( "id".equals( name ) ) {
			// ID
			bindSimpleId( subnode, entity, mappings, inheritedMetas );
		}
		else if ( "composite-id".equals( name ) ) {
			// COMPOSITE-ID
			bindCompositeId( subnode, entity, mappings, inheritedMetas );
		}
		else if ( "version".equals( name ) || "timestamp".equals( name ) ) {
			// VERSION / TIMESTAMP
			bindVersioningProperty( table, subnode, mappings, name, entity, inheritedMetas );
		}
		else if ( "discriminator".equals( name ) ) {
			// DISCRIMINATOR
			bindDiscriminatorProperty( table, entity, subnode, mappings );
		}
		else if ( "cache".equals( name ) ) {
			entity.setCacheConcurrencyStrategy( subnode.attributeValue( "usage" ) );
			entity.setCacheRegionName( subnode.attributeValue( "region" ) );
			entity.setLazyPropertiesCacheable( !"non-lazy".equals( subnode.attributeValue( "include" ) ) );
		}

	}

	// Primary key constraint
	entity.createPrimaryKey();

	createClassProperties( node, entity, mappings, inheritedMetas );
}