Search in sources :

Example 16 with ICacheManager

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");
}
Also used : ICacheManager(org.pentaho.platform.api.engine.ICacheManager) Test(org.junit.Test)

Example 17 with ICacheManager

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());
}
Also used : ICacheManager(org.pentaho.platform.api.engine.ICacheManager)

Example 18 with ICacheManager

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);
}
Also used : DataSourcesConfig(mondrian.xmla.DataSourcesConfig) ArrayList(java.util.ArrayList) XOMException(org.eigenbase.xom.XOMException) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) SAXException(org.xml.sax.SAXException) MondrianException(mondrian.olap.MondrianException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) MondrianException(mondrian.olap.MondrianException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 19 with ICacheManager

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);
}
Also used : ICacheManager(org.pentaho.platform.api.engine.ICacheManager)

Example 20 with ICacheManager

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();
    }
}
Also used : ICacheManager(org.pentaho.platform.api.engine.ICacheManager) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

ICacheManager (org.pentaho.platform.api.engine.ICacheManager)24 Test (org.junit.Test)6 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 DataSource (javax.sql.DataSource)2 DataSourcesConfig (mondrian.xmla.DataSourcesConfig)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 Domain (org.pentaho.metadata.model.Domain)2 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)2 MockSessionAwareMetadataDomainRepository (org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1