use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.
the class AbstractJcrBackedRoleBindingDaoTest method testDao.
@Test
public void testDao() throws Exception {
ICacheManager cm = mock(ICacheManager.class);
PentahoSystem.registerObject(cm, IPentahoRegistrableObjectFactory.Types.INTERFACES);
when(cm.cacheEnabled("roleBindingCache")).thenReturn(false);
new AbstractJcrBackedRoleBindingDaoImpl();
verify(cm, times(1)).addCacheRegion("roleBindingCache");
}
use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.
the class MondrianCatalogHelper method init.
// ~ Methods =========================================================================================================
protected synchronized void init(final IPentahoSession pentahoSession) {
// First check if the catalogs are initialized for the current locale
final ICacheManager cacheMgr = PentahoSystem.getCacheManager(pentahoSession);
if (cacheMgr.cacheEnabled(MONDRIAN_CATALOG_CACHE_REGION) && cacheMgr.getFromRegionCache(MONDRIAN_CATALOG_CACHE_REGION, getLocale().toString()) != null) {
return;
}
if (MondrianCatalogHelper.logger.isDebugEnabled()) {
// $NON-NLS-1$
MondrianCatalogHelper.logger.debug("init");
}
// By default, we will use the system to load all schemas into the cache.
// access to these schemas is controlled later via the hasAccess() method
loadCatalogsIntoCache(makeDataSources(), PentahoSessionHolder.getSession());
}
use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.
the class MondrianCatalogHelper method loadCatalogsIntoCache.
protected void loadCatalogsIntoCache(final DataSourcesConfig.DataSources dataSources, final IPentahoSession pentahoSession) {
// Create the cache region if necessary.
ICacheManager cacheMgr = PentahoSystem.getCacheManager(pentahoSession);
if (!cacheMgr.cacheEnabled(MONDRIAN_CATALOG_CACHE_REGION)) {
// Create the region
cacheMgr.addCacheRegion(MONDRIAN_CATALOG_CACHE_REGION);
}
Map<String, MondrianCatalog> catalogs = (Map<String, MondrianCatalog>) cacheMgr.getFromRegionCache(MONDRIAN_CATALOG_CACHE_REGION, getLocale().toString());
if (catalogs == null) {
catalogs = new HashMap<String, MondrianCatalog>();
} else {
return;
}
for (DataSourcesConfig.DataSource dataSource : dataSources.dataSources) {
List<String> catalogNames = new ArrayList<String>();
for (DataSourcesConfig.Catalog catalog : dataSource.catalogs.catalogs) {
catalogNames.add(catalog.name);
}
for (DataSourcesConfig.Catalog catalog : dataSource.catalogs.catalogs) {
if (catalog.definition.startsWith("mondrian:") || catalog.definition.startsWith("solution:")) {
// $NON-NLS-1$
// try catch here so the whole thing doesn't blow up if one datasource is configured incorrectly.
MondrianSchema schema = null;
try {
schema = makeSchema(getCatalogAsString(pentahoSession, catalog));
} catch (Exception e) {
MondrianCatalogHelper.logger.error(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0013_FAILED_TO_LOAD_SCHEMA", catalog.definition), // $NON-NLS-1$
e);
if (e instanceof MondrianException) {
throw (MondrianException) e;
}
}
MondrianCatalog mondrianCatalog = null;
if (schema == null) {
mondrianCatalog = new MondrianCatalog(catalog.name, catalog.dataSourceInfo, catalog.definition, schema);
} else {
mondrianCatalog = new MondrianCatalog(useSchemaNameAsCatalogName ? schema.getName() : catalog.name, catalog.dataSourceInfo, catalog.definition, schema);
}
catalogs.put(mondrianCatalog.getName(), mondrianCatalog);
catalogs.put(mondrianCatalog.getDefinition(), mondrianCatalog);
} else {
MondrianCatalogHelper.logger.warn(Messages.getInstance().getString("MondrianCatalogHelper.WARN_SKIPPING_DATASOURCE_DEF", // $NON-NLS-1$
catalog.definition));
}
}
}
cacheMgr.putInRegionCache(MONDRIAN_CATALOG_CACHE_REGION, getLocale().toString(), catalogs);
}
use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.
the class MondrianCatalogHelper method reInit.
@Override
public synchronized void reInit(final IPentahoSession pentahoSession) {
final ICacheManager cacheMgr = PentahoSystem.getCacheManager(pentahoSession);
if (cacheMgr.cacheEnabled(MONDRIAN_CATALOG_CACHE_REGION)) {
cacheMgr.clearRegionCache(MONDRIAN_CATALOG_CACHE_REGION);
}
init(pentahoSession);
}
use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.
the class OlapServiceImpl method resetCache.
/**
* Clears all caches for all locales.
*/
protected void resetCache(IPentahoSession session) {
final Lock writeLock = cacheLock.writeLock();
try {
writeLock.lock();
final ICacheManager cacheMgr = PentahoSystem.getCacheManager(session);
cacheMgr.clearRegionCache(CATALOG_CACHE_REGION);
} finally {
writeLock.unlock();
}
}
Aggregations