Java Code Examples for javax.persistence.SharedCacheMode

The following examples show how to use javax.persistence.SharedCacheMode. These examples are extracted from open source projects. 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 Project: ignite   Source File: HibernateL2CacheSelfTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param igniteInstanceName Node name.
 * @param dfltAccessType Default cache access type.
 * @return Properties map.
 */
static Map<String, String> hibernateProperties(String igniteInstanceName, String dfltAccessType) {
    Map<String, String> map = new HashMap<>();

    map.put(HBM2DDL_AUTO, "create");
    map.put(JPA_SHARED_CACHE_MODE, SharedCacheMode.ALL.name());
    map.put(GENERATE_STATISTICS, "true");
    map.put(USE_SECOND_LEVEL_CACHE, "true");
    map.put(USE_QUERY_CACHE, "true");
    map.put(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
    map.put(RELEASE_CONNECTIONS, "on_close");
    map.put(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
    map.put(DFLT_ACCESS_TYPE_PROPERTY, dfltAccessType);

    return map;
}
 
Example 2
@Bean
@DependsOn(value = {"simpleApplicationContextHolder"})
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
    factoryBean.setDataSource(dataSource);
    factoryBean.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
    factoryBean.setValidationMode(ValidationMode.CALLBACK);
    factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
    factoryBean.setPackagesToScan("com.devicehive.model");

    final Properties props = new Properties();
    props.putAll(this.properties.getHibernateProperties(this.dataSource));
    if (useNativeClient) {
        props.put("hibernate.cache.hazelcast.native_client_group", groupName);
        props.put("hibernate.cache.hazelcast.native_client_password", groupPassword);
        if (!CollectionUtils.isEmpty(clusterMembers)) {
            props.put("hibernate.cache.hazelcast.native_client_address", clusterMembers.get(0));
        }
    }

    factoryBean.setJpaProperties(props);
    return factoryBean;
}
 
Example 3
Source Project: tomee   Source File: ReloadableEntityManagerFactory.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized void setSharedCacheMode(final SharedCacheMode mode) {
    final PersistenceUnitInfoImpl info = entityManagerFactoryCallable.getUnitInfo();
    info.setSharedCacheMode(mode);

    final Properties properties = entityManagerFactoryCallable.getUnitInfo().getProperties();
    if (properties.containsKey(JAVAX_PERSISTENCE_SHARED_CACHE_MODE)) {
        properties.setProperty(JAVAX_PERSISTENCE_SHARED_CACHE_MODE, mode.name());
    }
}
 
Example 4
Source Project: tomee   Source File: ReloadableEntityManagerFactory.java    License: Apache License 2.0 5 votes vote down vote up
@ManagedOperation
@Description("change the shared cache mode if possible (value is ok)")
public void setSharedCacheMode(final String value) {
    try {
        final String v = value.trim().toUpperCase();
        final SharedCacheMode mode = v.isEmpty() ? SharedCacheMode.UNSPECIFIED : SharedCacheMode.valueOf(v);
        reloadableEntityManagerFactory.setSharedCacheMode(mode);
    } catch (final Exception iae) {
        // ignored
    }
}
 
Example 5
Source Project: quickperf   Source File: PersistenceUnitInfoBuilder.java    License: Apache License 2.0 4 votes vote down vote up
public PersistenceUnitInfo build(final DataSource dataSource
                               , final Properties config
                               , final Class<?>... persistentClasses) {
    return new PersistenceUnitInfo(){

        @Override
        public String getPersistenceUnitName() {
            return "my pu";
        }

        @Override
        public String getPersistenceProviderClassName() {
            return "org.hibernate.jpa.HibernatePersistenceProvider";
        }

        @Override
        public PersistenceUnitTransactionType getTransactionType() {
            return PersistenceUnitTransactionType.RESOURCE_LOCAL;
        }

        @Override
        public DataSource getJtaDataSource() {
            return null;
        }

        @Override
        public DataSource getNonJtaDataSource() {
            return dataSource;
        }

        @Override
        public List<String> getMappingFileNames() {
            return emptyList();
        }

        @Override
        public List<URL> getJarFileUrls() {
            return emptyList();
        }

        @Override
        public URL getPersistenceUnitRootUrl() {
            return null;
        }

        @Override
        public List<String> getManagedClassNames() {
            return Arrays.stream(persistentClasses)
                                    .map(c -> c.getName())
                                    .collect(toList());
        }

        @Override
        public boolean excludeUnlistedClasses() {
            return false;
        }

        @Override
        public SharedCacheMode getSharedCacheMode() {
            return SharedCacheMode.NONE;
        }

        @Override
        public ValidationMode getValidationMode() {
            return ValidationMode.NONE;
        }

        @Override
        public Properties getProperties() {
            return config;
        }

        @Override
        public String getPersistenceXMLSchemaVersion() {
            return "2.1";
        }

        @Override
        public ClassLoader getClassLoader() {
            return this.getClass().getClassLoader();
        }

        @Override
        public void addTransformer(ClassTransformer transformer) {

        }

        @Override
        public ClassLoader getNewTempClassLoader() {
            return null;
        }

    };
}
 
Example 6
Source Project: we-cmdb   Source File: DynamicEntityUnitInfo.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SharedCacheMode getSharedCacheMode() {
    return SharedCacheMode.UNSPECIFIED;
}
 
Example 7
Source Project: spring-analysis-note   Source File: PersistenceUnitReader.java    License: MIT License 4 votes vote down vote up
/**
 * Parse the unit info DOM element.
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(
		Element persistenceUnit, String version, @Nullable URL rootUrl) throws IOException {

	SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();

	// set JPA version (1.0 or 2.0)
	unitInfo.setPersistenceXMLSchemaVersion(version);

	// set persistence unit root URL
	unitInfo.setPersistenceUnitRootUrl(rootUrl);

	// set unit name
	unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());

	// set transaction type
	String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim();
	if (StringUtils.hasText(txType)) {
		unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
	}

	// evaluate data sources
	String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
	if (StringUtils.hasText(jtaDataSource)) {
		unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
	}

	String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE);
	if (StringUtils.hasText(nonJtaDataSource)) {
		unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim()));
	}

	// provider
	String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER);
	if (StringUtils.hasText(provider)) {
		unitInfo.setPersistenceProviderClassName(provider.trim());
	}

	// exclude unlisted classes
	Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
	if (excludeUnlistedClasses != null) {
		String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
		unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText));
	}

	// set JPA 2.0 shared cache mode
	String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
	if (StringUtils.hasText(cacheMode)) {
		unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode));
	}

	// set JPA 2.0 validation mode
	String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
	if (StringUtils.hasText(validationMode)) {
		unitInfo.setValidationMode(ValidationMode.valueOf(validationMode));
	}

	parseProperties(persistenceUnit, unitInfo);
	parseManagedClasses(persistenceUnit, unitInfo);
	parseMappingFiles(persistenceUnit, unitInfo);
	parseJarFiles(persistenceUnit, unitInfo);

	return unitInfo;
}
 
Example 8
Source Project: spring-analysis-note   Source File: MutablePersistenceUnitInfo.java    License: MIT License 4 votes vote down vote up
public void setSharedCacheMode(SharedCacheMode sharedCacheMode) {
	this.sharedCacheMode = sharedCacheMode;
}
 
Example 9
Source Project: spring-analysis-note   Source File: MutablePersistenceUnitInfo.java    License: MIT License 4 votes vote down vote up
@Override
public SharedCacheMode getSharedCacheMode() {
	return this.sharedCacheMode;
}
 
Example 10
@Override
public SharedCacheMode getSharedCacheMode() {
    return SharedCacheMode.UNSPECIFIED;
}
 
Example 11
@Override
public SharedCacheMode getSharedCacheMode() {
  return null;
}
 
Example 12
protected void applyCacheSettings(Configuration configuration) {
  if ( getCacheConcurrencyStrategy() != null ) {
    configuration.setProperty( AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, getCacheConcurrencyStrategy() );
    configuration.setSharedCacheMode( SharedCacheMode.ALL );
  }
}
 
Example 13
Source Project: java-technology-stack   Source File: PersistenceUnitReader.java    License: MIT License 4 votes vote down vote up
/**
 * Parse the unit info DOM element.
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(
		Element persistenceUnit, String version, @Nullable URL rootUrl) throws IOException {

	SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();

	// set JPA version (1.0 or 2.0)
	unitInfo.setPersistenceXMLSchemaVersion(version);

	// set persistence unit root URL
	unitInfo.setPersistenceUnitRootUrl(rootUrl);

	// set unit name
	unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());

	// set transaction type
	String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim();
	if (StringUtils.hasText(txType)) {
		unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
	}

	// evaluate data sources
	String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
	if (StringUtils.hasText(jtaDataSource)) {
		unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
	}

	String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE);
	if (StringUtils.hasText(nonJtaDataSource)) {
		unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim()));
	}

	// provider
	String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER);
	if (StringUtils.hasText(provider)) {
		unitInfo.setPersistenceProviderClassName(provider.trim());
	}

	// exclude unlisted classes
	Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
	if (excludeUnlistedClasses != null) {
		String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
		unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText));
	}

	// set JPA 2.0 shared cache mode
	String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
	if (StringUtils.hasText(cacheMode)) {
		unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode));
	}

	// set JPA 2.0 validation mode
	String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
	if (StringUtils.hasText(validationMode)) {
		unitInfo.setValidationMode(ValidationMode.valueOf(validationMode));
	}

	parseProperties(persistenceUnit, unitInfo);
	parseManagedClasses(persistenceUnit, unitInfo);
	parseMappingFiles(persistenceUnit, unitInfo);
	parseJarFiles(persistenceUnit, unitInfo);

	return unitInfo;
}
 
Example 14
Source Project: java-technology-stack   Source File: MutablePersistenceUnitInfo.java    License: MIT License 4 votes vote down vote up
public void setSharedCacheMode(SharedCacheMode sharedCacheMode) {
	this.sharedCacheMode = sharedCacheMode;
}
 
Example 15
Source Project: java-technology-stack   Source File: MutablePersistenceUnitInfo.java    License: MIT License 4 votes vote down vote up
@Override
public SharedCacheMode getSharedCacheMode() {
	return this.sharedCacheMode;
}
 
Example 16
Source Project: quarkus   Source File: LightPersistenceXmlDescriptor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SharedCacheMode getSharedCacheMode() {
    return sharedCachemode;
}
 
Example 17
Source Project: jweb-cms   Source File: DatabaseImpl.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public SharedCacheMode getSharedCacheMode() {
    return null;
}
 
Example 18
Source Project: lams   Source File: PersistenceUnitReader.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse the unit info DOM element.
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, URL rootUrl)
		throws IOException {

	SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();

	// set JPA version (1.0 or 2.0)
	unitInfo.setPersistenceXMLSchemaVersion(version);

	// set persistence unit root URL
	unitInfo.setPersistenceUnitRootUrl(rootUrl);

	// set unit name
	unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());

	// set transaction type
	String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim();
	if (StringUtils.hasText(txType)) {
		unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
	}

	// evaluate data sources
	String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
	if (StringUtils.hasText(jtaDataSource)) {
		unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
	}

	String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE);
	if (StringUtils.hasText(nonJtaDataSource)) {
		unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim()));
	}

	// provider
	String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER);
	if (StringUtils.hasText(provider)) {
		unitInfo.setPersistenceProviderClassName(provider.trim());
	}

	// exclude unlisted classes
	Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
	if (excludeUnlistedClasses != null) {
		String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
		unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText));
	}

	// set JPA 2.0 shared cache mode
	String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
	if (StringUtils.hasText(cacheMode)) {
		unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode));
	}

	// set JPA 2.0 validation mode
	String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
	if (StringUtils.hasText(validationMode)) {
		unitInfo.setValidationMode(ValidationMode.valueOf(validationMode));
	}

	parseProperties(persistenceUnit, unitInfo);
	parseManagedClasses(persistenceUnit, unitInfo);
	parseMappingFiles(persistenceUnit, unitInfo);
	parseJarFiles(persistenceUnit, unitInfo);

	return unitInfo;
}
 
Example 19
public void setSharedCacheMode(SharedCacheMode sharedCacheMode) {
	this.sharedCacheMode = sharedCacheMode;
}
 
Example 20
@Override
public SharedCacheMode getSharedCacheMode() {
	return this.sharedCacheMode;
}
 
Example 21
Source Project: lams   Source File: AnnotationBinder.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static SharedCacheMode determineSharedCacheMode(MetadataBuildingContext context) {
	return context.getBuildingOptions().getSharedCacheMode();
}
 
Example 22
@Override
public SharedCacheMode getSharedCacheMode() {
	return sharedCacheMode;
}
 
Example 23
public void setSharedCacheMode(String sharedCacheMode) {
	this.sharedCacheMode = SharedCacheMode.valueOf( sharedCacheMode );
}
 
Example 24
@Override
public SharedCacheMode getSharedCacheMode() {
	return persistenceUnitInfo.getSharedCacheMode();
}
 
Example 25
@Override
public MetadataBuilder applySharedCacheMode(SharedCacheMode cacheMode) {
	delegate.applySharedCacheMode( cacheMode );
	return getThis();
}
 
Example 26
@Override
public SharedCacheMode getSharedCacheMode() {
	return delegate.getSharedCacheMode();
}
 
Example 27
Source Project: lams   Source File: MetadataBuilderImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applySharedCacheMode(SharedCacheMode sharedCacheMode) {
	this.options.sharedCacheMode = sharedCacheMode;
	return this;
}
 
Example 28
Source Project: lams   Source File: MetadataBuilderImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public SharedCacheMode getSharedCacheMode() {
	return sharedCacheMode;
}
 
Example 29
Source Project: hibernate-types   Source File: PersistenceUnitInfoImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SharedCacheMode getSharedCacheMode() {
    return SharedCacheMode.UNSPECIFIED;
}
 
Example 30
Source Project: hibernate-types   Source File: PersistenceUnitInfoImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SharedCacheMode getSharedCacheMode() {
    return SharedCacheMode.UNSPECIFIED;
}