Return scope store

@param scope
Scope
@param persistent
Persistent store or not?
@return Scope's store
166976
private IPersistenceStore getStore(IScope scope, boolean persistent) {
        IPersistenceStore store;
        if (!persistent) {
            // Use special store for non-persistent shared objects
            if (!scope.hasAttribute(SO_TRANSIENT_STORE)) {
                store = new RamPersistence(scope);
                scope.setAttribute(SO_TRANSIENT_STORE, store);
                return store;
            }
            return (IPersistenceStore) scope.getAttribute(SO_TRANSIENT_STORE);
        }
        // Evaluate configuration for persistent shared objects
        if (!scope.hasAttribute(SO_PERSISTENCE_STORE)) {
            try {
                store = PersistenceUtils.getPersistenceStore(scope, persistenceClassName);
                log.info("Created persistence store {} for shared objects", store);
            } catch (Exception err) {
                log.warn("Could not create persistence store ({}) for shared objects, falling back to Ram persistence", persistenceClassName, err);
                store = new RamPersistence(scope);
            }
            scope.setAttribute(SO_PERSISTENCE_STORE, store);
            return store;
        }
        return (IPersistenceStore) scope.getAttribute(SO_PERSISTENCE_STORE);
    }
188260
public CMAPersonalAccessToken addScope(Scope scope) {
    if (scopes == null) {
      scopes = new ArrayList<Scope>();
    }

    scopes.add(scope);
    return this;
  }
2204
public synchronized T get(Scope scope) {
    if (instance != null) {
      return instance;
    }

    if (providerInstance != null) {
      if (isProvidingSingletonInScope) {
        instance = providerInstance.get();
        //gc
        providerInstance = null;
        return instance;
      }

      return providerInstance.get();
    }

    if (factoryClass != null && factory == null) {
      factory = FactoryLocator.getFactory(factoryClass);
      //gc
      factoryClass = null;
    }

    if (factory != null) {
      if (!factory.hasScopeAnnotation() && !isCreatingSingletonInScope) {
        return factory.createInstance(scope);
      }
      instance = factory.createInstance(scope);
      //gc
      factory = null;
      return instance;
    }

    if (providerFactoryClass != null && providerFactory == null) {
      providerFactory = FactoryLocator.getFactory(providerFactoryClass);
      //gc
      providerFactoryClass = null;
    }

    if (providerFactory != null) {
      if (providerFactory.hasProvidesSingletonInScopeAnnotation() || isProvidingSingletonInScope) {
        instance = providerFactory.createInstance(scope).get();
        //gc
        providerFactory = null;
        return instance;
      }
      if (providerFactory.hasScopeAnnotation() || isCreatingSingletonInScope) {
        providerInstance = providerFactory.createInstance(scope);
        //gc
        providerFactory = null;
        return providerInstance.get();
      }

      return providerFactory.createInstance(scope).get();
    }

    throw new IllegalStateException("A provider can only be used with an instance, a provider, a factory or a provider factory. Should not happen.");
  }
1192469
public AbstractScope<?, ?> getAbstractScope() {
    AbstractScope<?, ?> scope = scopes.peek();

    // NOTE(dylandavidson): Use for-each loop to avoid slow ArrayList#get performance.
    for (Node scopeRoot : scopeRoots) {
      scope = scopeCreator.createScope(scopeRoot, scope);
      scopes.push(scope);
    }
    scopeRoots.clear();
    return scope;
  }
798139
@Override
    public CompletableFuture<DeleteScopeStatus> deleteScope(final String scopeName) {
        return getScope(scopeName).deleteScope().handle((result, e) -> {
            Throwable ex = Exceptions.unwrap(e);
            if (ex == null) {
                return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SUCCESS).build();
            }
            if (ex instanceof StoreException.DataNotFoundException) {
                return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_FOUND).build();
            } else if (ex instanceof StoreException.DataNotEmptyException) {
                return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.SCOPE_NOT_EMPTY).build();
            } else {
                log.debug("DeleteScope failed due to {} ", ex);
                return DeleteScopeStatus.newBuilder().setStatus(DeleteScopeStatus.Status.FAILURE).build();
            }
        });
    }
72459
public function setScopeStorage(ScopeInterface $storage)
    {
        $storage->setServer($this);
        $this->scopeStorage = $storage;

        return $this;
    }
307608
function getCurrentScope(statementType) {
            let currentScope;

            if (statementType === "var") {
                currentScope = functionStack[functionStack.length - 1];
            } else if (statementType === "let") {
                currentScope = blockStack[blockStack.length - 1].let;
            } else if (statementType === "const") {
                currentScope = blockStack[blockStack.length - 1].const;
            }
            return currentScope;
        }
770573
public function getScope($key)
    {
        $scope = ('application' === $key) ? 'APPLICATION_CONFIG' : 'BUNDLE_CONFIG';

        if ($this->application->getContainer()->has('config.configurator')) {
            $scope = $this
                    ->application
                    ->getContainer()
                    ->get('config.configurator')
                    ->getRegistryScope($scope, $this->persistPerContext, $this->persistPerEnvironment)
            ;
        }

        return $scope;
    }
1128279
public Scope getEnclosingScope(Scope scope) {
        for (Scope s = this; s != null; s = s.getParent()) {
            if (s.isEnclosing(scope)) {
                return s;
            }
        }
        return null;
    }
299816
private void sawStore(int seen, int pc) {
        int reg = RegisterUtils.getStoreReg(this, seen);

        if (catchHandlers.get(pc)) {
            ignoreRegs.set(reg);
            ScopeBlock catchSB = findScopeBlock(rootScopeBlock, pc + 1);
            if ((catchSB != null) && (catchSB.getStart() < pc)) {
                ScopeBlock sb = new ScopeBlock(pc, catchSB.getFinish());
                catchSB.setFinish(getPC() - 1);
                rootScopeBlock.addChild(sb);
            }
        } else if (!monitorSyncPCs.isEmpty()) {
            ignoreRegs.set(reg);
        } else if (sawNull) {
            ignoreRegs.set(reg);
        } else if (isRiskyStoreClass(reg)) {
            ignoreRegs.set(reg);
        }

        if (!ignoreRegs.get(reg)) {
            ScopeBlock sb = findScopeBlock(rootScopeBlock, pc);
            if (sb != null) {
                UserObject assoc = null;
                if (stack.getStackDepth() > 0) {
                    OpcodeStack.Item srcItm = stack.getStackItem(0);
                    assoc = (UserObject) srcItm.getUserValue();
                    if (assoc == null) {
                        if (srcItm.getRegisterNumber() >= 0) {
                            assoc = new UserObject(srcItm.getRegisterNumber());
                        }
                    }
                }

                if ((assoc != null) && assoc.isRisky) {
                    ignoreRegs.set(reg);
                } else {
                    sb.addStore(reg, pc, assoc);
                    if (sawDup) {
                        sb.addLoad(reg, pc);
                    }
                }
            } else {
                ignoreRegs.set(reg);
            }
        }

        ScopeBlock sb = findScopeBlock(rootScopeBlock, pc);
        if (sb != null) {
            sb.markFieldAssociatedWrites(reg);
        }
    }
168471
public static MortarScope getScope(Context context) {
    //noinspection ResourceType
    Object scope = context.getSystemService(MORTAR_SERVICE);
    if (scope == null) {
      // Essentially a workaround for the lifecycle interval where an Activity's
      // base context is not yet set to the Application, but the Application
      // context is available and contains a MortarScope that provides needed
      // services. Thanks, Android!

      //noinspection ResourceType
      scope = context.getApplicationContext().getSystemService(MORTAR_SERVICE);
    }
    return (MortarScope) scope;
  }
231408
public final PersistenceServiceUnit getPersistenceServiceUnit() throws Exception {
        lock.readLock().lock();
        try {
            if (destroyed)
                throw new IllegalStateException();
            if (persistenceServiceUnit == null) {
                // Switch to write lock for lazy initialization
                lock.readLock().unlock();
                lock.writeLock().lock();
                try {
                    if (destroyed)
                        throw new IllegalStateException();
                    if (persistenceServiceUnit == null)
                        persistenceServiceUnit = dbStore.createPersistenceServiceUnit(priv.getClassLoader(Task.class),
                                                                                      Partition.class.getName(),
                                                                                      Property.class.getName(),
                                                                                      Task.class.getName());
                } finally {
                    // Downgrade to read lock for rest of method
                    lock.readLock().lock();
                    lock.writeLock().unlock();
                }
            }
            return persistenceServiceUnit;
        } finally {
            lock.readLock().unlock();
        }
    }
973985
private Store getStore(MavenProject rootModule) throws MojoExecutionException {
        StoreConfiguration configuration = getStoreConfiguration(rootModule);
        List<Class<?>> descriptorTypes;
        try {
            descriptorTypes = pluginRepositoryProvider.getPluginRepository().getModelPluginRepository().getDescriptorTypes();
        } catch (PluginRepositoryException e) {
            throw new MojoExecutionException("Cannot determine model types.", e);
        }
        Object existingStore = cachingStoreProvider.getStore(configuration, descriptorTypes);
        if (!Store.class.isAssignableFrom(existingStore.getClass())) {
            throw new MojoExecutionException(
                    "Cannot re-use store instance from reactor. Either declare the plugin as extension or execute Maven using the property -D"
                            + PROPERTY_STORE_LIFECYCLE + "=" + StoreLifecycle.MODULE + " on the command line.");
        }
        return (Store) existingStore;
    }
1251604
public CompletableFuture<DeleteScopeStatus> deleteScope(final String scope) {
        Exceptions.checkNotNullOrEmpty(scope, "scope");
        return streamStore.deleteScope(scope);
    }
850593
public function usePersistence(PersistenceDefinition $definition, StorageType $storageType = null)
    {
        $enabledPersistences = $this->settings->tryGet(KnownSettingsEnum::ENABLED_PERSISTENCES) ?: [];

        $enabledPersistences[] = new EnabledPersistence($definition, $storageType);

        $this->settings->set(KnownSettingsEnum::ENABLED_PERSISTENCES, $enabledPersistences);

        return $definition->createConfigurator($this->settings);
    }
440830
boolean setLocalScope(TransactionScope<Txn> scope, boolean detached) {
        TransactionScope<Txn> existing = mLocalScope.get();
        if (((existing == null || existing.isInactive()) && detached) || existing == scope) {
            attachNotification(scope.getActiveTxn());
            mLocalScope.set(scope);
            return true;
        }
        return false;
    }
19303
private Session getCFSessionScope(PageContext pc, RefBoolean isNew) throws PageException {

	ApplicationContext appContext = pc.getApplicationContext();
	// get Context
	Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());

	// get Session
	boolean isMemory = false;
	String storage = appContext.getSessionstorage();
	if (StringUtil.isEmpty(storage, true)) {
	    storage = ConfigImpl.DEFAULT_STORAGE_SESSION;
	    isMemory = true;
	}
	else if ("ram".equalsIgnoreCase(storage)) {
	    storage = "memory";
	    isMemory = true;
	}
	else if ("registry".equalsIgnoreCase(storage)) {
	    storage = "file";
	}
	else {
	    storage = storage.toLowerCase();
	    if ("memory".equals(storage)) isMemory = true;
	}

	Session existing = (Session) context.get(pc.getCFID());
	if (existing != null && (existing.isExpired() || !(existing instanceof StorageScope))) existing = null; // second should not happen

	Session session = appContext.getSessionCluster() ? null : existing;

	if (session == null || !(session instanceof StorageScope) || !((StorageScope) session).getStorage().equalsIgnoreCase(storage)) {
	    // not necessary to check session in the same way, because it is overwritten anyway
	    if (isMemory) {
		if (existing != null) session = existing;
		else session = SessionMemory.getInstance(pc, isNew, getLog());
	    }
	    else if ("file".equals(storage)) {
		session = SessionFile.getInstance(appContext.getName(), pc, getLog());
	    }
	    else if ("cookie".equals(storage)) session = SessionCookie.getInstance(appContext.getName(), pc, getLog());
	    else {
		DataSource ds = pc.getDataSource(storage, null);
		if (ds != null && ds.isStorage()) {
		    if (INVIDUAL_STORAGE_KEYS) {
			try {
			    session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerDatasource(), appContext.getName(), storage, pc, existing,
				    getLog());
			}
			catch (PageException pe) {
			    session = SessionDatasource.getInstance(storage, pc, getLog(), null);
			}
		    }
		    else session = SessionDatasource.getInstance(storage, pc, getLog(), null);
		}
		else {
		    if (INVIDUAL_STORAGE_KEYS) {
			try {
			    session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerCache(), appContext.getName(), storage, pc, existing, getLog());
			}
			catch (PageException pe) {
			    session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
			}
		    }
		    else session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
		}

		if (session == null) {
		    // datasource not enabled for storage
		    if (ds != null) {
			if (!ds.isStorage()) throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session storage, "
				+ "you have to enable it in the Lucee administrator or define key \"storage=true\" for datasources defined in the application event handler.");
			throw new ApplicationException("datasource [" + storage
				+ "] could not be reached for session storage. Please make sure the datasource settings are correct, and the datasource is available.");
		    }
		    CacheConnection cc = CacheUtil.getCacheConnection(pc, storage, null);
		    if (cc != null) throw new ApplicationException(
			    "cache [" + storage + "] is not enabled to be used  as a session/client storage, you have to enable it in the Lucee administrator.");

		    throw new ApplicationException("there is no cache or datasource with name [" + storage + "] defined.");
		}
	    }
	    if (session instanceof StorageScope) ((StorageScope) session).setStorage(storage);
	    context.put(pc.getCFID(), session);
	    isNew.setValue(true);
	}
	else {
	    getLog().log(Log.LEVEL_INFO, "scope-context", "use existing session scope for " + appContext.getName() + "/" + pc.getCFID() + " from storage " + storage);
	}
	session.touchBeforeRequest(pc);
	return session;
    }