-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
353 additions
and
4 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
resources/api/src/main/java/org/jboss/forge/resource/transaction/ChangeSet.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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.resource.transaction; | ||
|
||
import java.util.Set; | ||
|
||
import org.jboss.forge.resource.Resource; | ||
|
||
/** | ||
* A {@link ChangeSet} object contains the modified resources of a specific transaction | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
* | ||
*/ | ||
public interface ChangeSet | ||
{ | ||
/** | ||
* @return a set of the modified resources | ||
*/ | ||
Set<Resource<?>> getModifiedResources(); | ||
} |
41 changes: 41 additions & 0 deletions
41
resources/api/src/main/java/org/jboss/forge/resource/transaction/ResourceTransaction.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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.resource.transaction; | ||
|
||
import org.jboss.forge.resource.ResourceException; | ||
|
||
/** | ||
* The ResourceTransaction interface allows operations to be performed on transactions | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
* | ||
*/ | ||
public interface ResourceTransaction | ||
{ | ||
/** | ||
* Attempt to commit this transaction, discarding the current {@link ChangeSet}. | ||
* | ||
* @throws ResourceException if any operation fails | ||
*/ | ||
void commit() throws ResourceException; | ||
|
||
/** | ||
* Rolls back this transaction. This transaction should not be used again | ||
* | ||
* This also discards the current {@link ChangeSet} | ||
* | ||
* @throws ResourceException | ||
*/ | ||
void rollback() throws ResourceException; | ||
|
||
/** | ||
* @return A {@link ChangeSet} object containing which resources were modified during this transaction | ||
*/ | ||
ChangeSet getChangeSet(); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...es/api/src/main/java/org/jboss/forge/resource/transaction/ResourceTransactionManager.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.resource.transaction; | ||
|
||
import org.jboss.forge.container.services.Exported; | ||
import org.jboss.forge.resource.ResourceException; | ||
|
||
/** | ||
* The ResourceTransactionManager interface allows | ||
* | ||
* <ul> | ||
* <li>Starting a {@link ResourceTransaction}</li> | ||
* <li>Getting the current {@link ResourceTransaction}</li> | ||
* </ul> | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
* | ||
*/ | ||
@Exported | ||
public interface ResourceTransactionManager | ||
{ | ||
/** | ||
* Start a new transaction. | ||
* | ||
* If a transaction was already started, a {@link ResourceException} will be thrown | ||
* | ||
* @return a new {@link ResourceTransaction} instance | ||
* @throws ResourceException if a transaction was already started | ||
*/ | ||
ResourceTransaction startTransaction() throws ResourceException; | ||
|
||
/** | ||
* @return The current transaction or null if {@link ResourceTransactionManager#startTransaction()} was not | ||
* previously called | ||
*/ | ||
ResourceTransaction getCurrentTransaction(); | ||
} |
39 changes: 39 additions & 0 deletions
39
resources/impl/src/main/java/org/jboss/forge/resource/ChangeSetImpl.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.resource; | ||
|
||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
import org.jboss.forge.resource.transaction.ChangeSet; | ||
|
||
public class ChangeSetImpl implements ChangeSet | ||
{ | ||
private Set<Resource<?>> changeSet = new TreeSet<Resource<?>>(); | ||
|
||
public ChangeSetImpl() | ||
{ | ||
} | ||
|
||
public void addResource(Resource<?> resource) | ||
{ | ||
changeSet.add(resource); | ||
} | ||
|
||
public void removeResource(Resource<?> resource) | ||
{ | ||
changeSet.remove(resource); | ||
} | ||
|
||
@Override | ||
public Set<Resource<?>> getModifiedResources() | ||
{ | ||
return changeSet; | ||
} | ||
|
||
} |
This file contains 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
69 changes: 69 additions & 0 deletions
69
resources/impl/src/main/java/org/jboss/forge/resource/ResourceTransactionImpl.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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.resource; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.jboss.forge.resource.transaction.ChangeSet; | ||
import org.jboss.forge.resource.transaction.ResourceTransaction; | ||
|
||
public class ResourceTransactionImpl implements ResourceTransaction | ||
{ | ||
private File tempWorkspace; | ||
|
||
private ChangeSetImpl changeSet = new ChangeSetImpl(); | ||
private ResourceFactoryImpl factoryImpl; | ||
|
||
public ResourceTransactionImpl(ResourceFactoryImpl factoryImpl) throws ResourceException | ||
{ | ||
try | ||
{ | ||
tempWorkspace = File.createTempFile("Forge_RT", null); | ||
} | ||
catch (IOException io) | ||
{ | ||
throw new ResourceException(io); | ||
} | ||
tempWorkspace.delete(); | ||
tempWorkspace.mkdir(); | ||
this.factoryImpl = factoryImpl; | ||
} | ||
|
||
@Override | ||
public void commit() throws ResourceException | ||
{ | ||
factoryImpl.unsetTransaction(); | ||
} | ||
|
||
@Override | ||
public void rollback() throws ResourceException | ||
{ | ||
factoryImpl.unsetTransaction(); | ||
} | ||
|
||
/** | ||
* Decorates a Resource | ||
* | ||
* @param resource | ||
* @return | ||
*/ | ||
public <TYPE> Resource<TYPE> decorateResource(Resource<TYPE> resource) | ||
{ | ||
changeSet.addResource(resource); | ||
// TODO: Create a proxy to the FileResource | ||
return resource; | ||
} | ||
|
||
@Override | ||
public ChangeSet getChangeSet() | ||
{ | ||
return changeSet; | ||
} | ||
|
||
} |
Oops, something went wrong.