List of usage examples for org.hibernate.mapping Collection setCacheConcurrencyStrategy
public void setCacheConcurrencyStrategy(String cacheConcurrencyStrategy)
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindCollectionSecondPass(GrailsDomainClassProperty property, Mappings mappings, Map<?, ?> persistentClasses, Collection collection, String sessionFactoryBeanName) { PersistentClass associatedClass = null; if (LOG.isDebugEnabled()) LOG.debug("Mapping collection: " + collection.getRole() + " -> " + collection.getCollectionTable().getName()); PropertyConfig propConfig = getPropertyConfig(property); if (propConfig != null && StringUtils.hasText(propConfig.getSort())) { if (!property.isBidirectional() && property.isOneToMany()) { throw new GrailsDomainException("Default sort for associations [" + property.getDomainClass().getName() + "->" + property.getName() + "] are not supported with unidirectional one to many relationships."); }// w ww .ja v a2s . c o m GrailsDomainClass referenced = property.getReferencedDomainClass(); if (referenced != null) { GrailsDomainClassProperty propertyToSortBy = referenced.getPropertyByName(propConfig.getSort()); String associatedClassName = property.getReferencedDomainClass().getFullName(); associatedClass = (PersistentClass) persistentClasses.get(associatedClassName); if (associatedClass != null) { collection.setOrderBy(buildOrderByClause(propertyToSortBy.getName(), associatedClass, collection.getRole(), propConfig.getOrder() != null ? propConfig.getOrder() : "asc")); } } } // Configure one-to-many if (collection.isOneToMany()) { GrailsDomainClass referenced = property.getReferencedDomainClass(); Mapping m = getRootMapping(referenced); boolean tablePerSubclass = m != null && !m.getTablePerHierarchy(); if (referenced != null && !referenced.isRoot() && !tablePerSubclass) { Mapping rootMapping = getRootMapping(referenced); String discriminatorColumnName = RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME; if (rootMapping != null) { final ColumnConfig discriminatorColumn = rootMapping.getDiscriminatorColumn(); if (discriminatorColumn != null) { discriminatorColumnName = discriminatorColumn.getName(); } if (rootMapping.getDiscriminatorMap().get("formula") != null) { discriminatorColumnName = (String) m.getDiscriminatorMap().get("formula"); } } //NOTE: this will build the set for the in clause if it has sublcasses Set<String> discSet = buildDiscriminatorSet(referenced); String inclause = DefaultGroovyMethods.join(discSet, ","); collection.setWhere(discriminatorColumnName + " in (" + inclause + ")"); } OneToMany oneToMany = (OneToMany) collection.getElement(); String associatedClassName = oneToMany.getReferencedEntityName(); associatedClass = (PersistentClass) persistentClasses.get(associatedClassName); // if there is no persistent class for the association throw exception if (associatedClass == null) { throw new MappingException( "Association references unmapped class: " + oneToMany.getReferencedEntityName()); } oneToMany.setAssociatedClass(associatedClass); if (shouldBindCollectionWithForeignKey(property)) { collection.setCollectionTable(associatedClass.getTable()); } bindCollectionForPropertyConfig(collection, propConfig); } if (isSorted(property)) { collection.setSorted(true); } // setup the primary key references DependantValue key = createPrimaryKeyValue(mappings, property, collection, persistentClasses); // link a bidirectional relationship if (property.isBidirectional()) { GrailsDomainClassProperty otherSide = property.getOtherSide(); if (otherSide.isManyToOne() && shouldBindCollectionWithForeignKey(property)) { linkBidirectionalOneToMany(collection, associatedClass, key, otherSide); } else if (property.isManyToMany() || Map.class.isAssignableFrom(property.getType())) { bindDependentKeyValue(property, key, mappings, sessionFactoryBeanName); } } else { if (hasJoinKeyMapping(propConfig)) { bindSimpleValue("long", key, false, propConfig.getJoinTable().getKey().getName(), mappings); } else { bindDependentKeyValue(property, key, mappings, sessionFactoryBeanName); } } collection.setKey(key); // get cache config if (propConfig != null) { CacheConfig cacheConfig = propConfig.getCache(); if (cacheConfig != null) { collection.setCacheConcurrencyStrategy(cacheConfig.getUsage()); } } // if we have a many-to-many if (property.isManyToMany() || isBidirectionalOneToManyMap(property)) { GrailsDomainClassProperty otherSide = property.getOtherSide(); if (property.isBidirectional()) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Mapping other side " + otherSide.getDomainClass().getName() + "." + otherSide.getName() + " -> " + collection.getCollectionTable().getName() + " as ManyToOne"); ManyToOne element = new ManyToOne(mappings, collection.getCollectionTable()); bindManyToMany(otherSide, element, mappings, sessionFactoryBeanName); collection.setElement(element); bindCollectionForPropertyConfig(collection, propConfig); if (property.isCircular()) { collection.setInverse(false); } } else { // TODO support unidirectional many-to-many } } else if (shouldCollectionBindWithJoinColumn(property)) { bindCollectionWithJoinTable(property, mappings, collection, propConfig, sessionFactoryBeanName); } else if (isUnidirectionalOneToMany(property)) { // for non-inverse one-to-many, with a not-null fk, add a backref! // there are problems with list and map mappings and join columns relating to duplicate key constraints // TODO change this when HHH-1268 is resolved bindUnidirectionalOneToMany(property, mappings, collection); } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
private static void bindCollectionSecondPass(GrailsDomainClassProperty property, Mappings mappings, Map<?, ?> persistentClasses, Collection collection, String sessionFactoryBeanName) { PersistentClass associatedClass = null; if (LOG.isDebugEnabled()) LOG.debug("Mapping collection: " + collection.getRole() + " -> " + collection.getCollectionTable().getName()); PropertyConfig propConfig = getPropertyConfig(property); if (propConfig != null && !StringUtils.isBlank(propConfig.getSort())) { if (!property.isBidirectional() && property.isOneToMany()) { throw new GrailsDomainException("Default sort for associations [" + property.getDomainClass().getName() + "->" + property.getName() + "] are not supported with unidirectional one to many relationships."); }/*from www. j a v a2s .co m*/ GrailsDomainClass referenced = property.getReferencedDomainClass(); if (referenced != null) { GrailsDomainClassProperty propertyToSortBy = referenced.getPropertyByName(propConfig.getSort()); String associatedClassName = property.getReferencedDomainClass().getFullName(); associatedClass = (PersistentClass) persistentClasses.get(associatedClassName); if (associatedClass != null) { collection.setOrderBy(buildOrderByClause(propertyToSortBy.getName(), associatedClass, collection.getRole(), propConfig.getOrder() != null ? propConfig.getOrder() : "asc")); } } } // Configure one-to-many if (collection.isOneToMany()) { GrailsDomainClass referenced = property.getReferencedDomainClass(); Mapping m = getRootMapping(referenced); boolean tablePerSubclass = m != null && !m.getTablePerHierarchy(); if (referenced != null && !referenced.isRoot() && !tablePerSubclass) { Mapping rootMapping = getRootMapping(referenced); String discriminatorColumnName = RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME; if (rootMapping != null) { final ColumnConfig discriminatorColumn = rootMapping.getDiscriminatorColumn(); if (discriminatorColumn != null) { discriminatorColumnName = discriminatorColumn.getName(); } if (rootMapping.getDiscriminatorMap().get("formula") != null) { discriminatorColumnName = (String) m.getDiscriminatorMap().get("formula"); } } //NOTE: this will build the set for the in clause if it has sublcasses Set<String> discSet = buildDiscriminatorSet(referenced); String inclause = StringUtils.join(discSet, ','); collection.setWhere(discriminatorColumnName + " in (" + inclause + ")"); } OneToMany oneToMany = (OneToMany) collection.getElement(); String associatedClassName = oneToMany.getReferencedEntityName(); associatedClass = (PersistentClass) persistentClasses.get(associatedClassName); // if there is no persistent class for the association throw exception if (associatedClass == null) { throw new MappingException( "Association references unmapped class: " + oneToMany.getReferencedEntityName()); } oneToMany.setAssociatedClass(associatedClass); if (shouldBindCollectionWithForeignKey(property)) { collection.setCollectionTable(associatedClass.getTable()); } bindCollectionForPropertyConfig(collection, propConfig); } if (isSorted(property)) { collection.setSorted(true); } // setup the primary key references DependantValue key = createPrimaryKeyValue(mappings, property, collection, persistentClasses); // link a bidirectional relationship if (property.isBidirectional()) { GrailsDomainClassProperty otherSide = property.getOtherSide(); if (otherSide.isManyToOne() && shouldBindCollectionWithForeignKey(property)) { linkBidirectionalOneToMany(collection, associatedClass, key, otherSide); } else if (property.isManyToMany() || Map.class.isAssignableFrom(property.getType())) { bindDependentKeyValue(property, key, mappings, sessionFactoryBeanName); } } else { if (hasJoinKeyMapping(propConfig)) { bindSimpleValue("long", key, false, propConfig.getJoinTable().getKey().getName(), mappings); } else { bindDependentKeyValue(property, key, mappings, sessionFactoryBeanName); } } collection.setKey(key); // get cache config if (propConfig != null) { CacheConfig cacheConfig = propConfig.getCache(); if (cacheConfig != null) { collection.setCacheConcurrencyStrategy(cacheConfig.getUsage()); } } // if we have a many-to-many if (property.isManyToMany() || isBidirectionalOneToManyMap(property)) { GrailsDomainClassProperty otherSide = property.getOtherSide(); if (property.isBidirectional()) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Mapping other side " + otherSide.getDomainClass().getName() + "." + otherSide.getName() + " -> " + collection.getCollectionTable().getName() + " as ManyToOne"); ManyToOne element = new ManyToOne(mappings, collection.getCollectionTable()); bindManyToMany(otherSide, element, mappings, sessionFactoryBeanName); collection.setElement(element); bindCollectionForPropertyConfig(collection, propConfig); if (property.isCircular()) { collection.setInverse(false); } } else { // TODO support unidirectional many-to-many } } else if (shouldCollectionBindWithJoinColumn(property)) { bindCollectionWithJoinTable(property, mappings, collection, propConfig, sessionFactoryBeanName); } else if (isUnidirectionalOneToMany(property)) { // for non-inverse one-to-many, with a not-null fk, add a backref! // there are problems with list and map mappings and join columns relating to duplicate key constraints // TODO change this when HHH-1268 is resolved bindUnidirectionalOneToMany(property, mappings, collection); } }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
protected void bindCollectionSecondPass(ToMany property, Mappings mappings, Map<?, ?> persistentClasses, Collection collection, String sessionFactoryBeanName) { PersistentClass associatedClass = null; if (LOG.isDebugEnabled()) LOG.debug("Mapping collection: " + collection.getRole() + " -> " + collection.getCollectionTable().getName()); PropertyConfig propConfig = getPropertyConfig(property); if (propConfig != null && StringUtils.hasText(propConfig.getSort())) { if (!property.isBidirectional() && (property instanceof org.grails.datastore.mapping.model.types.OneToMany)) { throw new DatastoreConfigurationException("Default sort for associations [" + property.getOwner().getName() + "->" + property.getName() + "] are not supported with unidirectional one to many relationships."); }/*w w w .j a v a2 s . c o m*/ PersistentEntity referenced = property.getAssociatedEntity(); if (referenced != null) { PersistentProperty propertyToSortBy = referenced.getPropertyByName(propConfig.getSort()); String associatedClassName = property.getAssociatedEntity().getName(); associatedClass = (PersistentClass) persistentClasses.get(associatedClassName); if (associatedClass != null) { collection.setOrderBy(buildOrderByClause(propertyToSortBy.getName(), associatedClass, collection.getRole(), propConfig.getOrder() != null ? propConfig.getOrder() : "asc")); } } } // Configure one-to-many if (collection.isOneToMany()) { PersistentEntity referenced = property.getAssociatedEntity(); Mapping m = getRootMapping(referenced); boolean tablePerSubclass = m != null && !m.getTablePerHierarchy(); if (referenced != null && !referenced.isRoot() && !tablePerSubclass) { Mapping rootMapping = getRootMapping(referenced); String discriminatorColumnName = RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME; if (rootMapping != null) { final ColumnConfig discriminatorColumn = rootMapping.getDiscriminatorColumn(); if (discriminatorColumn != null) { discriminatorColumnName = discriminatorColumn.getName(); } if (rootMapping.getDiscriminatorMap().get("formula") != null) { discriminatorColumnName = (String) m.getDiscriminatorMap().get("formula"); } } //NOTE: this will build the set for the in clause if it has sublcasses Set<String> discSet = buildDiscriminatorSet((HibernatePersistentEntity) referenced); String inclause = DefaultGroovyMethods.join(discSet, ","); collection.setWhere(discriminatorColumnName + " in (" + inclause + ")"); } OneToMany oneToMany = (OneToMany) collection.getElement(); String associatedClassName = oneToMany.getReferencedEntityName(); associatedClass = (PersistentClass) persistentClasses.get(associatedClassName); // if there is no persistent class for the association throw exception if (associatedClass == null) { throw new MappingException( "Association references unmapped class: " + oneToMany.getReferencedEntityName()); } oneToMany.setAssociatedClass(associatedClass); if (shouldBindCollectionWithForeignKey(property)) { collection.setCollectionTable(associatedClass.getTable()); } bindCollectionForPropertyConfig(collection, propConfig); } if (isSorted(property)) { collection.setSorted(true); } // setup the primary key references DependantValue key = createPrimaryKeyValue(mappings, property, collection, persistentClasses); // link a bidirectional relationship if (property.isBidirectional()) { Association otherSide = property.getInverseSide(); if ((otherSide instanceof org.grails.datastore.mapping.model.types.ToOne) && shouldBindCollectionWithForeignKey(property)) { linkBidirectionalOneToMany(collection, associatedClass, key, otherSide); } else if ((otherSide instanceof ManyToMany) || Map.class.isAssignableFrom(property.getType())) { bindDependentKeyValue(property, key, mappings, sessionFactoryBeanName); } } else { if (hasJoinKeyMapping(propConfig)) { bindSimpleValue("long", key, false, propConfig.getJoinTable().getKey().getName(), mappings); } else { bindDependentKeyValue(property, key, mappings, sessionFactoryBeanName); } } collection.setKey(key); // get cache config if (propConfig != null) { CacheConfig cacheConfig = propConfig.getCache(); if (cacheConfig != null) { collection.setCacheConcurrencyStrategy(cacheConfig.getUsage()); } } // if we have a many-to-many final boolean isManyToMany = property instanceof ManyToMany; if (isManyToMany || isBidirectionalOneToManyMap(property)) { PersistentProperty otherSide = property.getInverseSide(); if (property.isBidirectional()) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Mapping other side " + otherSide.getOwner().getName() + "." + otherSide.getName() + " -> " + collection.getCollectionTable().getName() + " as ManyToOne"); ManyToOne element = new ManyToOne(mappings, collection.getCollectionTable()); bindManyToMany((Association) otherSide, element, mappings, sessionFactoryBeanName); collection.setElement(element); bindCollectionForPropertyConfig(collection, propConfig); if (property.isCircular()) { collection.setInverse(false); } } else { // TODO support unidirectional many-to-many } } else if (shouldCollectionBindWithJoinColumn(property)) { bindCollectionWithJoinTable(property, mappings, collection, propConfig, sessionFactoryBeanName); } else if (isUnidirectionalOneToMany(property)) { // for non-inverse one-to-many, with a not-null fk, add a backref! // there are problems with list and map mappings and join columns relating to duplicate key constraints // TODO change this when HHH-1268 is resolved bindUnidirectionalOneToMany((org.grails.datastore.mapping.model.types.OneToMany) property, mappings, collection); } }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
protected void bindCollectionSecondPass(ToMany property, InFlightMetadataCollector mappings, Map<?, ?> persistentClasses, Collection collection, String sessionFactoryBeanName) { PersistentClass associatedClass = null; if (LOG.isDebugEnabled()) LOG.debug("Mapping collection: " + collection.getRole() + " -> " + collection.getCollectionTable().getName()); PropertyConfig propConfig = getPropertyConfig(property); PersistentEntity referenced = property.getAssociatedEntity(); if (propConfig != null && StringUtils.hasText(propConfig.getSort())) { if (!property.isBidirectional() && (property instanceof org.grails.datastore.mapping.model.types.OneToMany)) { throw new DatastoreConfigurationException("Default sort for associations [" + property.getOwner().getName() + "->" + property.getName() + "] are not supported with unidirectional one to many relationships."); }/*from w w w . ja va 2s .c o m*/ if (referenced != null) { PersistentProperty propertyToSortBy = referenced.getPropertyByName(propConfig.getSort()); String associatedClassName = property.getAssociatedEntity().getName(); associatedClass = (PersistentClass) persistentClasses.get(associatedClassName); if (associatedClass != null) { collection.setOrderBy(buildOrderByClause(propertyToSortBy.getName(), associatedClass, collection.getRole(), propConfig.getOrder() != null ? propConfig.getOrder() : "asc")); } } } // Configure one-to-many if (collection.isOneToMany()) { Mapping m = getRootMapping(referenced); boolean tablePerSubclass = m != null && !m.getTablePerHierarchy(); if (referenced != null && !referenced.isRoot() && !tablePerSubclass) { Mapping rootMapping = getRootMapping(referenced); String discriminatorColumnName = RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME; if (rootMapping != null) { DiscriminatorConfig discriminatorConfig = rootMapping.getDiscriminator(); if (discriminatorConfig != null) { final ColumnConfig discriminatorColumn = discriminatorConfig.getColumn(); if (discriminatorColumn != null) { discriminatorColumnName = discriminatorColumn.getName(); } if (discriminatorConfig.getFormula() != null) { discriminatorColumnName = discriminatorConfig.getFormula(); } } } //NOTE: this will build the set for the in clause if it has sublcasses Set<String> discSet = buildDiscriminatorSet((HibernatePersistentEntity) referenced); String inclause = DefaultGroovyMethods.join(discSet, ","); collection.setWhere(discriminatorColumnName + " in (" + inclause + ")"); } OneToMany oneToMany = (OneToMany) collection.getElement(); String associatedClassName = oneToMany.getReferencedEntityName(); associatedClass = (PersistentClass) persistentClasses.get(associatedClassName); // if there is no persistent class for the association throw exception if (associatedClass == null) { throw new MappingException( "Association references unmapped class: " + oneToMany.getReferencedEntityName()); } oneToMany.setAssociatedClass(associatedClass); if (shouldBindCollectionWithForeignKey(property)) { collection.setCollectionTable(associatedClass.getTable()); } bindCollectionForPropertyConfig(collection, propConfig); } if (referenced != null && referenced.isMultiTenant()) { String filterCondition = getMultiTenantFilterCondition(sessionFactoryBeanName, referenced); if (filterCondition != null) { collection.addFilter(GormProperties.TENANT_IDENTITY, filterCondition, true, Collections.<String, String>emptyMap(), Collections.<String, String>emptyMap()); } } if (isSorted(property)) { collection.setSorted(true); } // setup the primary key references DependantValue key = createPrimaryKeyValue(mappings, property, collection, persistentClasses); // link a bidirectional relationship if (property.isBidirectional()) { Association otherSide = property.getInverseSide(); if ((otherSide instanceof org.grails.datastore.mapping.model.types.ToOne) && shouldBindCollectionWithForeignKey(property)) { linkBidirectionalOneToMany(collection, associatedClass, key, otherSide); } else if ((otherSide instanceof ManyToMany) || Map.class.isAssignableFrom(property.getType())) { bindDependentKeyValue(property, key, mappings, sessionFactoryBeanName); } } else { if (hasJoinKeyMapping(propConfig)) { bindSimpleValue("long", key, false, propConfig.getJoinTable().getKey().getName(), mappings); } else { bindDependentKeyValue(property, key, mappings, sessionFactoryBeanName); } } collection.setKey(key); // get cache config if (propConfig != null) { CacheConfig cacheConfig = propConfig.getCache(); if (cacheConfig != null) { collection.setCacheConcurrencyStrategy(cacheConfig.getUsage()); } } // if we have a many-to-many final boolean isManyToMany = property instanceof ManyToMany; if (isManyToMany || isBidirectionalOneToManyMap(property)) { PersistentProperty otherSide = property.getInverseSide(); if (property.isBidirectional()) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Mapping other side " + otherSide.getOwner().getName() + "." + otherSide.getName() + " -> " + collection.getCollectionTable().getName() + " as ManyToOne"); ManyToOne element = new ManyToOne(mappings, collection.getCollectionTable()); bindManyToMany((Association) otherSide, element, mappings, sessionFactoryBeanName); collection.setElement(element); bindCollectionForPropertyConfig(collection, propConfig); if (property.isCircular()) { collection.setInverse(false); } } else { // TODO support unidirectional many-to-many } } else if (shouldCollectionBindWithJoinColumn(property)) { bindCollectionWithJoinTable(property, mappings, collection, propConfig, sessionFactoryBeanName); } else if (isUnidirectionalOneToMany(property)) { // for non-inverse one-to-many, with a not-null fk, add a backref! // there are problems with list and map mappings and join columns relating to duplicate key constraints // TODO change this when HHH-1268 is resolved bindUnidirectionalOneToMany((org.grails.datastore.mapping.model.types.OneToMany) property, mappings, collection); } }
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 a 2 s .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; }
From source file:org.infinispan.test.hibernate.cache.commons.stress.PutFromLoadStressTestCase.java
License:LGPL
@BeforeClass public static void beforeClass() { // Extra options located in src/test/resources/hibernate.properties StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true") .applySetting(Environment.USE_QUERY_CACHE, "true") // TODO: Tweak to have a fully local region factory (no transport, cache mode = local, no marshalling, ...etc) .applySetting(Environment.CACHE_REGION_FACTORY, "org.infinispan.hibernate.cache.InfinispanRegionFactory") .applySetting(Environment.JTA_PLATFORM, new NarayanaStandaloneJtaPlatform()) // Force minimal puts off to simplify stressing putFromLoad logic .applySetting(Environment.USE_MINIMAL_PUTS, "false") .applySetting(Environment.HBM2DDL_AUTO, "create-drop"); StandardServiceRegistry serviceRegistry = ssrb.build(); MetadataSources metadataSources = new MetadataSources(serviceRegistry) .addResource("cache/infinispan/functional/Item.hbm.xml") .addResource("cache/infinispan/functional/Customer.hbm.xml") .addResource("cache/infinispan/functional/Contact.hbm.xml").addAnnotatedClass(Age.class); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (entityBinding instanceof RootClass) { ((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional"); }/* w w w.j a v a2 s.c o m*/ } for (Collection collectionBinding : metadata.getCollectionBindings()) { collectionBinding.setCacheConcurrencyStrategy("transactional"); } sessionFactory = metadata.buildSessionFactory(); tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); }
From source file:org.infinispan.test.hibernate.cache.commons.stress.SecondLevelCacheStressTestCase.java
License:LGPL
private static Metadata buildMetadata(StandardServiceRegistry registry) { final String cacheStrategy = "transactional"; MetadataSources metadataSources = new MetadataSources(registry); for (Class entityClass : getAnnotatedClasses()) { metadataSources.addAnnotatedClass(entityClass); }/*w ww.j ava 2 s . c o m*/ Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (!entityBinding.isInherited()) { ((RootClass) entityBinding).setCacheConcurrencyStrategy(cacheStrategy); } } for (Collection collectionBinding : metadata.getCollectionBindings()) { collectionBinding.setCacheConcurrencyStrategy(cacheStrategy); } return metadata; }
From source file:org.infinispan.test.hibernate.cache.commons.tm.JBossStandaloneJtaExampleTest.java
License:LGPL
private SessionFactory buildSessionFactory() { // Extra options located in src/test/resources/hibernate.properties StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySetting(Environment.DIALECT, "HSQL").applySetting(Environment.HBM2DDL_AUTO, "create-drop") .applySetting(Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName()) .applySetting(Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory") .applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()) .applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta") .applySetting(Environment.RELEASE_CONNECTIONS, "auto") .applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true") .applySetting(Environment.USE_QUERY_CACHE, "true") .applySetting(Environment.JTA_PLATFORM, new NarayanaStandaloneJtaPlatform()) .applySetting(Environment.CACHE_REGION_FACTORY, TestRegionFactoryProvider.load().getRegionFactoryClass().getName()); StandardServiceRegistry serviceRegistry = ssrb.build(); MetadataSources metadataSources = new MetadataSources(serviceRegistry); metadataSources.addResource("org/infinispan/test/hibernate/cache/commons/functional/entities/Item.hbm.xml"); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (entityBinding instanceof RootClass) { RootClass rootClass = (RootClass) entityBinding; rootClass.setCacheConcurrencyStrategy("transactional"); rootClass.setCachingExplicitlyRequested(true); }// w ww.j a v a 2 s. co m } for (Collection collectionBinding : metadata.getCollectionBindings()) { collectionBinding.setCacheConcurrencyStrategy("transactional"); } return metadata.buildSessionFactory(); }
From source file:org.infinispan.test.hibernate.cache.stress.PutFromLoadStressTestCase.java
License:LGPL
@BeforeClass public static void beforeClass() { // Extra options located in src/test/resources/hibernate.properties StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true") .applySetting(Environment.USE_QUERY_CACHE, "true") // TODO: Tweak to have a fully local region factory (no transport, cache mode = local, no marshalling, ...etc) .applySetting(Environment.CACHE_REGION_FACTORY, "org.infinispan.hibernate.cache.InfinispanRegionFactory") .applySetting(Environment.JTA_PLATFORM, "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform") // Force minimal puts off to simplify stressing putFromLoad logic .applySetting(Environment.USE_MINIMAL_PUTS, "false") .applySetting(Environment.HBM2DDL_AUTO, "create-drop"); StandardServiceRegistry serviceRegistry = ssrb.build(); MetadataSources metadataSources = new MetadataSources(serviceRegistry) .addResource("cache/infinispan/functional/Item.hbm.xml") .addResource("cache/infinispan/functional/Customer.hbm.xml") .addResource("cache/infinispan/functional/Contact.hbm.xml").addAnnotatedClass(Age.class); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (entityBinding instanceof RootClass) { ((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional"); }/*from w ww. ja v a2 s.c om*/ } for (Collection collectionBinding : metadata.getCollectionBindings()) { collectionBinding.setCacheConcurrencyStrategy("transactional"); } sessionFactory = metadata.buildSessionFactory(); tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); }
From source file:org.infinispan.test.hibernate.cache.tm.JBossStandaloneJtaExampleTest.java
License:LGPL
private SessionFactory buildSessionFactory() { // Extra options located in src/test/resources/hibernate.properties StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySetting(Environment.DIALECT, "HSQL").applySetting(Environment.HBM2DDL_AUTO, "create-drop") .applySetting(Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName()) .applySetting(Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory") .applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()) .applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta") .applySetting(Environment.RELEASE_CONNECTIONS, "auto") .applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true") .applySetting(Environment.USE_QUERY_CACHE, "true") .applySetting(Environment.JTA_PLATFORM, new JBossStandAloneJtaPlatform()) .applySetting(Environment.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName()); StandardServiceRegistry serviceRegistry = ssrb.build(); MetadataSources metadataSources = new MetadataSources(serviceRegistry); metadataSources.addResource("org/infinispan/test/hibernate/cache/functional/entities/Item.hbm.xml"); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (entityBinding instanceof RootClass) { ((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional"); }/*from w w w . j a va2s . c o m*/ } for (Collection collectionBinding : metadata.getCollectionBindings()) { collectionBinding.setCacheConcurrencyStrategy("transactional"); } return metadata.buildSessionFactory(); }