@Override public Repository connect( String repositoryName ) throws KettleException { IPentahoSession session = PentahoSessionHolder.getSession(); if ( session == null ) { logger.debug( "No active Pentaho Session, attempting to load PDI repository unauthenticated." ); throw new KettleException( "Attempting to create PDI Repository with no Active PentahoSession. " + "This is not allowed." ); } ICacheManager cacheManager = PentahoSystem.getCacheManager( session ); String sessionName = session.getName(); Repository repository = (Repository) cacheManager.getFromRegionCache( REGION, sessionName ); if ( repository == null ) { logger.debug( "Repository not cached for user: " + sessionName + ". Creating new Repository." ); repository = delegate.connect( repositoryName ); if ( !cacheManager.cacheEnabled( REGION ) ) { cacheManager.addCacheRegion( REGION ); } cacheManager.putInRegionCache( REGION, sessionName, repository ); } else { logger.debug( "Repository was cached for user: " + sessionName ); } return repository; } }
public AbstractJcrBackedRoleBindingDao() { cacheManager = PentahoSystem.getCacheManager( null ); if ( !cacheManager.cacheEnabled( LOGICAL_ROLE_BINDINGS_REGION ) ) { cacheManager.addCacheRegion( LOGICAL_ROLE_BINDINGS_REGION ); } }
private void putInRegionCacheWasCalled( int wishedTimes ) { verify( ICacheManagerMock, times( wishedTimes ) ).putInRegionCache( eq( IDBDatasourceService.JDBC_DATASOURCE ), anyString(), anyObject() ); }
.getFromRegionCache( USER_CACHE_REGION, JcrTenantUtils.getTenantedUser( principalName ) ); final Principal user = new UserPrincipal( principalName ); if ( cacheManager != null ) { cacheManager.putInRegionCache( USER_CACHE_REGION, principalName, user ); .getFromRegionCache( ROLE_CACHE_REGION, JcrTenantUtils.getTenantedRole( principalName ) ); cacheManager.putInRegionCache( ROLE_CACHE_REGION, principalName, roleToCache );
public DataSource getDataSource( String dsName ) throws DBDatasourceServiceException { DataSource dataSource = null; if ( cacheManager != null ) { if ( !cacheManager.cacheEnabled( IDBDatasourceService.JDBC_DATASOURCE ) ) { cacheManager.addCacheRegion( IDBDatasourceService.JDBC_DATASOURCE ); } Object foundDs = cacheManager.getFromRegionCache( IDBDatasourceService.JDBC_DATASOURCE, dsName ); if ( foundDs != null ) { dataSource = (DataSource) foundDs; } else { dataSource = retrieve( dsName ); } } return dataSource; }
@Override public void onReload() { if ( !loaded ) { setAuthorizationActions( PentahoSystem.getAll( IAuthorizationAction.class ) ); updateImmutableRoleBindingNames(); // when immutableRoleBindingNames gets updated, we should ensure no stale logical roles remain cached if ( cacheManager.cacheEnabled( LOGICAL_ROLE_BINDINGS_REGION ) ) { cacheManager.removeRegionCache( LOGICAL_ROLE_BINDINGS_REGION ); } loaded = true; } } } );
private void performAgainstAllInCache( CacheCallable callable ) { Set allKeysFromRegionCache = cacheManager.getAllKeysFromRegionCache( ICacheManager.SESSION ); for ( Object compositeKey : allKeysFromRegionCache ) { Matcher matcher = SESSION_KEY_PATTERN.matcher( compositeKey.toString() ); if ( matcher.matches() ) { String key = matcher.toMatchResult().group( 1 ); if ( ENTRY_COLLECTOR.equals( key ) ) { Object fromRegionCache = cacheManager.getFromRegionCache( ICacheManager.SESSION, compositeKey ); if ( EntryCache.class.isAssignableFrom( fromRegionCache.getClass() ) ) { callable.call( (EntryCache) fromRegionCache ); } } } } }
@SuppressWarnings( "unchecked" ) public void shutdown() { ICacheManager cacheManager = PentahoSystem.getCacheManager( null ); List<ObjectPool> objectPools = null; objectPools = (List<ObjectPool>) cacheManager.getAllValuesFromRegionCache( IDBDatasourceService.JDBC_POOL ); Logger.debug( this, "DatasourceSystemListener: Called for shutdown ..." ); //$NON-NLS-1$ try { if ( objectPools != null ) { for ( ObjectPool objectPool : objectPools ) { if ( null != objectPool ) { objectPool.clear(); } } } } catch ( Throwable ignored ) { Logger.error( this, "Failed to clear connection pool: " + ignored.getMessage(), ignored ); //$NON-NLS-1$ } cacheManager.removeRegionCache( IDBDatasourceService.JDBC_POOL ); cacheManager.removeRegionCache( IDBDatasourceService.JDBC_DATASOURCE ); Logger.debug( this, "DatasourceSystemListener: Completed shutdown." ); //$NON-NLS-1$ }
fromCache = null; } else { fromCache = (Principal) cacheManager.getFromRegionCache( ROLE_CACHE_REGION, roleAuthority );
/** * This method clears the JNDI DS cache. The need exists because after a JNDI connection edit the old DS must be * removed from the cache. * */ public void clearCache() { cacheManager.removeRegionCache( IDBDatasourceService.JDBC_DATASOURCE ); }
public synchronized void clearCaches() { if ( cacheManager != null ) { cacheManager.clearRegionCache( ROLE_CACHE_REGION ); cacheManager.clearRegionCache( USER_CACHE_REGION ); } }
@Override protected ICacheManager addCacheRegions( ) { ICacheManager cacheManager = super.addCacheRegions(); if ( !cacheManager.cacheEnabled( IDBDatasourceService.JDBC_POOL ) ) { cacheManager.addCacheRegion( IDBDatasourceService.JDBC_POOL ); } return cacheManager; }
@Override protected DataSource retrieve( String dsName ) throws DBDatasourceServiceException { DataSource ds; try { ds = getJndiDataSource( dsName ); if ( ds != null ) { cacheManager.putInRegionCache( IDBDatasourceService.JDBC_DATASOURCE, dsName, ds ); } } catch ( DBDatasourceServiceException dse ) { throw new DBDatasourceServiceException( Messages.getInstance().getErrorString( "DatasourceService.ERROR_0003_UNABLE_TO_GET_JNDI_DATASOURCE" ), dse ); //$NON-NLS-1$ } return ds; }
final String tenatedRoleString = JcrTenantUtils.getTenantedRole( role ); if ( cacheManager != null ) { Object rolePrincipal = cacheManager.getFromRegionCache( ROLE_CACHE_REGION, role ); if ( rolePrincipal == null ) { final SpringSecurityRolePrincipal ssRolePrincipal = new SpringSecurityRolePrincipal( tenatedRoleString ); cacheManager.putInRegionCache( ROLE_CACHE_REGION, role, ssRolePrincipal );
public void shutdown() { ICacheManager cacheManager = PentahoSystem.getCacheManager( null ); Logger.debug( this, "DatasourceSystemListener: Called for shutdown ..." ); //$NON-NLS-1$ cacheManager.removeRegionCache( IDBDatasourceService.JDBC_DATASOURCE ); Logger.debug( this, "DatasourceSystemListener: Completed shutdown." ); //$NON-NLS-1$ }
protected ICacheManager addCacheRegions() { ICacheManager cacheManager = PentahoSystem.getCacheManager( null ); Logger.debug( this, "Adding caching regions ..." ); //$NON-NLS-1$ if ( !cacheManager.cacheEnabled( IDBDatasourceService.JDBC_DATASOURCE ) ) { cacheManager.addCacheRegion( IDBDatasourceService.JDBC_DATASOURCE ); } return cacheManager; }
@Test public void testRetrieveJNDIConnection_3() throws Exception { service = spy( getPreparedService( mgmtService, cacheManager, null, null ) ); when( mgmtService.getDatasourceByName( testName ) ).thenReturn( connection ); when( connection.getAccessType() ).thenReturn( DatabaseAccessType.JNDI ); service.retrieve( testName ); verify( service, times( 2 ) ).getJndiDataSource( anyString() ); verify( cacheManager, never() ).putInRegionCache( IDBDatasourceService.JDBC_DATASOURCE, testName, jndiDataSource ); }
String roleName = tenantedRoleNameUtils.getPrincipleName( runtimeRoleName ); String roleId = tenantedRoleNameUtils.getPrincipleId( tenant, runtimeRoleName ); Object fromRegionCache = cacheManager.getFromRegionCache( LOGICAL_ROLE_BINDINGS_REGION, roleId ); if ( fromRegionCache != null ) { cachedBoundLogicalRoleNames.addAll( (Collection<String>) fromRegionCache ); cacheManager.putInRegionCache( LOGICAL_ROLE_BINDINGS_REGION, stringCollectionEntry.getKey(), stringCollectionEntry.getValue() ); String roleId = tenantedRoleNameUtils.getPrincipleId( tenant, runtimeRoleName ); if ( cacheManager.getFromRegionCache( LOGICAL_ROLE_BINDINGS_REGION, roleId ) == null ) { cacheManager.putInRegionCache( LOGICAL_ROLE_BINDINGS_REGION, roleId, Collections.emptyList() );
if ( !cacheManager.cacheEnabled( USER_CACHE_REGION ) ) { cacheManager.addCacheRegion( USER_CACHE_REGION ); if ( !cacheManager.cacheEnabled( ROLE_CACHE_REGION ) ) { cacheManager.addCacheRegion( ROLE_CACHE_REGION );
@Test public void testRetrieveJNDIConnection_1() throws Exception { when( mgmtService.getDatasourceByName( testName ) ).thenReturn( connection ); when( connection.getAccessType() ).thenReturn( DatabaseAccessType.JNDI ); service.retrieve( testName ); verify( service ).getJndiDataSource( testName ); verify( cacheManager ).putInRegionCache( IDBDatasourceService.JDBC_DATASOURCE, testName, jndiDataSource ); }