Created
October 1, 2013 15:52
-
-
Save gastaldi/6780684 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Copyright 2013 Red Hat, Inc. and/or its affiliates. | |
| * | |
| * Licensed under the Eclipse Public License version 1.0, available at | |
| * http://www.eclipse.org/legal/epl-v10.html | |
| */ | |
| package org.jboss.forge.addon.resource.transaction; | |
| import org.jboss.forge.addon.resource.Resource; | |
| import org.jboss.forge.addon.resource.events.ResourceEvent; | |
| /** | |
| * A {@link Change} object contains references to the original and the modified resource enlisted in a | |
| * {@link ResourceTransaction} | |
| * | |
| * @author <a href="ggastald@redhat.com">George Gastaldi</a> | |
| */ | |
| public interface Change | |
| { | |
| /** | |
| * The description of this change (if any) | |
| */ | |
| String getDescription(); | |
| /** | |
| * @return The original {@link Resource} | |
| */ | |
| Resource<?> getOriginalResource(); | |
| /** | |
| * @return The modified {@link Resource} | |
| */ | |
| Resource<?> getModifiedResource(); | |
| /** | |
| * @return The {@link ResourceEvent} that originated this {@link Change} | |
| */ | |
| ResourceEvent getEvent(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Copyright 2013 Red Hat, Inc. and/or its affiliates. | |
| * | |
| * Licensed under the Eclipse Public License version 1.0, available at | |
| * http://www.eclipse.org/legal/epl-v10.html | |
| */ | |
| package org.jboss.forge.addon.resource.transaction; | |
| import javax.annotation.Priority; | |
| import javax.decorator.Decorator; | |
| import javax.decorator.Delegate; | |
| import javax.inject.Inject; | |
| import org.jboss.forge.addon.resource.Resource; | |
| import org.jboss.forge.addon.resource.ResourceFactory; | |
| /** | |
| * Adds orthogonal transaction features to the {@link ResourceFactory} | |
| * | |
| * @author <a href="ggastald@redhat.com">George Gastaldi</a> | |
| */ | |
| @Priority(0) | |
| @Decorator | |
| public abstract class ResourceFactoryTransactionDecorator implements ResourceFactory | |
| { | |
| @Inject | |
| @Delegate | |
| ResourceFactory delegate; | |
| private volatile boolean enabled; | |
| @Override | |
| public <E, T extends Resource<E>> T create(Class<T> type, E underlyingResource) | |
| { | |
| T result = delegate.create(type, underlyingResource); | |
| if (enabled) | |
| { | |
| // Wrap the resource | |
| } | |
| return result; | |
| } | |
| void setEnabled(boolean enabled) | |
| { | |
| this.enabled = enabled; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Copyright 2013 Red Hat, Inc. and/or its affiliates. | |
| * | |
| * Licensed under the Eclipse Public License version 1.0, available at | |
| * http://www.eclipse.org/legal/epl-v10.html | |
| */ | |
| package org.jboss.forge.addon.resource.transaction; | |
| import java.io.Closeable; | |
| import java.util.Set; | |
| /** | |
| * A {@link ResourceTransaction} manages changes to a group of resources | |
| * | |
| * @author <a href="ggastald@redhat.com">George Gastaldi</a> | |
| */ | |
| public interface ResourceTransaction extends Closeable | |
| { | |
| /** | |
| * Starts a transaction. It does nothing if the transaction was already started. It throws an | |
| * {@link IllegalStateException} if the transaction was closed | |
| */ | |
| public void start(); | |
| /** | |
| * Applies every change in the {@link Set} returned by {@link ResourceTransaction#getChangeSet()} | |
| */ | |
| public void commit(); | |
| /** | |
| * Discards this transaction and the associated changes with it | |
| */ | |
| public void rollback(); | |
| /** | |
| * The changes associated with this transaction. | |
| * | |
| * @return a mutable {@link Set} with the changes that were introduced so far | |
| */ | |
| public Set<Change> getChangeSet(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment