@Override public Result exec(final State state, final CancelIndicator cancelIndicator) throws Exception { if (state == null) { return defaultResult.get(); } return work.exec(state); } }
@Override public <Result extends Object> Result execute(final IUnitOfWork<Result, ? super JavaResource> unit) throws Exception { synchronized (this.getLock()) { return unit.exec(this); } }
/** * {@inheritDoc} * * @since 2.4 */ /* @Nullable */ @Override public <Result> Result execute(/* @NonNull */ IUnitOfWork<Result, ? super TypeResource> unit) throws Exception { synchronized (getLock()) { return unit.exec(this); } }
public R exec(XtextResource state) throws Exception { ResourceSet localContext = state.getResourceSet(); if (localContext != null) return work.exec(localContext); return null; } });
/** * {@inheritDoc} * * @since 2.4 */ /* @Nullable */ @Override public <Result> Result execute(/* @NonNull */ IUnitOfWork<Result, ? super BatchLinkableResource> unit) throws Exception { synchronized (getLock()) { return unit.exec(this); } }
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) { try { return work.exec(resourceSet); } catch(Exception exc) { throw new WrappedException(exc); } }
public T exec(XtextResource resource) throws Exception { if(resource != null && !resource.getContents().isEmpty()) { work.exec(resource.getContents().get(0)); } return null; } });
/** * {@inheritDoc} * * @since 2.4 */ @Nullable public <Result> Result execute(@NonNull IUnitOfWork<Result, ? super SynchronizedXtextResourceSet> unit) throws Exception { synchronized (getLock()) { return unit.exec(this); } }
/** * {@inheritDoc} * * @since 2.4 */ @Nullable public <Result> Result execute(@NonNull IUnitOfWork<Result, ? super TypeResource> unit) throws Exception { synchronized (getLock()) { return unit.exec(this); } }
/** * The transaction will be executed with caching enabled. However, all newly cached values will be discarded as soon * as the transaction is over. * @since 2.1 */ public <Result, Param extends Resource> Result execWithTemporaryCaching(Param resource, IUnitOfWork<Result, Param> transaction) throws WrappedException { CacheAdapter cacheAdapter = getOrCreate(resource); IgnoreValuesMemento memento = cacheAdapter.ignoreNewValues(); try { return transaction.exec(resource); } catch (Exception e) { throw new WrappedException(e); } finally { memento.done(); } }
/** * The transaction will be executed with caching enabled. However, all newly cached values will be discarded as soon * as the transaction is over. * @since 2.1 */ public <Result, Param extends Resource> Result execWithTemporaryCaching(Param resource, IUnitOfWork<Result, Param> transaction) throws WrappedException { CacheAdapter cacheAdapter = getOrCreate(resource); IgnoreValuesMemento memento = cacheAdapter.ignoreNewValues(); try { return transaction.exec(resource); } catch (Exception e) { throw new WrappedException(e); } finally { memento.done(); } }
protected <R extends Object> R readOnly(final URI objectURI, final IUnitOfWork<R, EObject> work) { final IUnitOfWork<R, ResourceSet> _function = (ResourceSet resourceSet) -> { final EObject targetObject = resourceSet.getEObject(objectURI, true); return work.exec(targetObject); }; return this.getResourceAccess().<R>readOnly(objectURI, _function); }
@Override public <R extends Object> R readOnly(final URI targetURI, final IUnitOfWork<R, ResourceSet> work) { final Function2<Document, XtextResource, R> _function = (Document document, XtextResource resource) -> { try { if ((resource == null)) { return null; } return work.exec(resource.getResourceSet()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; return this.workspaceManager.<R>doRead(targetURI, _function); }
/** * Tries to get a read-only copy of the State and execute {@code work} on it. * * @param work Work to execute on the State * @param defaultResult Supplies a result in case the State is null * * @return The result of executing {@code work}, or * the result of querying {@code defaultResult} if the State is null * @since 2.14 */ default <Result> Result tryReadOnly( IUnitOfWork<Result, State> work, Supplier<? extends Result> defaultResult ) { // Some implementations rely on the type of {@code work} if (work instanceof CancelableUnitOfWork<?, ?>) { return readOnly(new WrappingCancelableUnitOfWork<>(defaultResult, work)); } return readOnly((state) -> { if (state == null) { return defaultResult.get(); } return work.exec(state); }); }
/** * Tries to modify the State by executing {@code work} on it. * * @param work Work that modifies the State * @param defaultResult Supplies a result in case the State is null * * @return The result of executing {@code work}, or * the result of querying {@code defaultResult} if the State is null * @since 2.14 */ default <Result> Result tryModify( IUnitOfWork<Result, State> work, Supplier<? extends Result> defaultResult ) { // Some implementations rely on the type of {@code work} if (work instanceof CancelableUnitOfWork<?, ?>) { return modify(new WrappingCancelableUnitOfWork<>(defaultResult, work)); } return modify((state) -> { if (state == null) { return defaultResult.get(); } return work.exec(state); }); }
/** * Tries to get a read-only copy of the State and execute {@code work} on it. * Cancels all cancelable readers before executing the {@link IUnitOfWork}. * For interactive jobs that need fastest possible execution. * * @param work Work to execute on the State * @param defaultResult Supplies a result in case the State is null * * @return The result of executing {@code work}, or * the result of querying {@code defaultResult} if the State is null * @since 2.14 * @see CancelableUnitOfWork */ default <Result> Result tryPriorityReadOnly( IUnitOfWork<Result, State> work, Supplier<? extends Result> defaultResult ) { // Some implementations rely on the type of {@code work} if (work instanceof CancelableUnitOfWork<?, ?>) { return priorityReadOnly(new WrappingCancelableUnitOfWork<>(defaultResult, work)); } return priorityReadOnly((state) -> { if (state == null) { return defaultResult.get(); } return work.exec(state); }); }
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) { Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(targetURI.trimFragment()); Iterator<Pair<IStorage, IProject>> iterator = storages.iterator(); while(iterator.hasNext()) { Pair<IStorage, IProject> pair = iterator.next(); IProject project = pair.getSecond(); if (project != null) { ResourceSet resourceSet = resourceSetProvider.get(project); if(resourceSet != null) resourceSet.getResource(targetURI, true); try { return work.exec(resourceSet); } catch (Exception e) { throw new WrappedException(e); } } } return null; } }
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) { URI resourceURI = targetURI.trimFragment(); Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resourceURI); Iterator<Pair<IStorage, IProject>> iterator = storages.iterator(); ResourceSet resourceSet = fallBackResourceSet; while(iterator.hasNext()) { Pair<IStorage, IProject> pair = iterator.next(); IProject project = pair.getSecond(); if (project != null) { resourceSet = getResourceSet(project); break; } } if(resourceSet != null) { resourceSet.getResource(resourceURI, true); try { return work.exec(resourceSet); } catch (Exception e) { throw new WrappedException(e); } } return null; }
/** * The transaction will be executed. While it is running, any semantic state change * in the given resource will be ignored and the cache will not be cleared. */ public <Result, Param extends Resource> Result execWithoutCacheClear(Param resource, IUnitOfWork<Result, Param> transaction) throws WrappedException { CacheAdapter cacheAdapter = getOrCreate(resource); try { cacheAdapter.ignoreNotifications(); return transaction.exec(resource); } catch (Exception e) { throw new WrappedException(e); } finally { cacheAdapter.listenToNotifications(); } }
/** * The transaction will be executed. While it is running, any semantic state change * in the given resource will be ignored and the cache will not be cleared. */ public <Result, Param extends Resource> Result execWithoutCacheClear(Param resource, IUnitOfWork<Result, Param> transaction) throws WrappedException { CacheAdapter cacheAdapter = getOrCreate(resource); try { cacheAdapter.ignoreNotifications(); return transaction.exec(resource); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new WrappedException(e); } finally { cacheAdapter.listenToNotifications(); } }