Skip to content

Commit

Permalink
Project code reformat.
Browse files Browse the repository at this point in the history
2 space indentation, 4 space continuous edit.
Probably a couple of side effects.
  • Loading branch information
kalle committed Aug 11, 2014
1 parent cbaa772 commit b09b08a
Show file tree
Hide file tree
Showing 218 changed files with 9,671 additions and 9,381 deletions.
3 changes: 2 additions & 1 deletion core/pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down
14 changes: 9 additions & 5 deletions core/src/main/java/org/prevayler/Clock.java
Expand Up @@ -4,14 +4,18 @@

package org.prevayler;

/** Tells the time.
/**
* Tells the time.
*
* @see Prevayler
*/
public interface Clock {

/** Tells the time.
* @return A Date greater or equal to the one returned by the last call to this method. If the time is the same as the last call, the SAME Date object is returned rather than a new, equal one.
*/
public java.util.Date time();
/**
* Tells the time.
*
* @return A Date greater or equal to the one returned by the last call to this method. If the time is the same as the last call, the SAME Date object is returned rather than a new, equal one.
*/
public java.util.Date time();

}
98 changes: 57 additions & 41 deletions core/src/main/java/org/prevayler/Prevayler.java
Expand Up @@ -8,58 +8,74 @@
import java.io.IOException;


/** Implementations of this interface can provide transparent persistence and replication to all Business Objects in a Prevalent System. ALL operations that alter the observable state of the Prevalent System must be implemented as Transaction or TransactionWithQuery objects and must be executed using the Prevayler.execute(...) methods.
/**
* Implementations of this interface can provide transparent persistence and replication to all Business Objects in a Prevalent System. ALL operations that alter the observable state of the Prevalent System must be implemented as Transaction or TransactionWithQuery objects and must be executed using the Prevayler.execute(...) methods.
* See the demo applications in org.prevayler.demos for examples.
*
* @param <P> The type of object you intend to persist as a Prevalent System. <br>
* @see org.prevayler.PrevaylerFactory
*/
public interface Prevayler<P>{
public interface Prevayler<P> {

/** Returns the object which holds direct or indirect references to all other Business Objects in the system.
*/
public P prevalentSystem();
/**
* Returns the object which holds direct or indirect references to all other Business Objects in the system.
*/
public P prevalentSystem();

/** Returns the Clock used to determine the execution time of all Transaction and Queries executed using this Prevayler. This Clock is useful only to Communication Objects and must NOT be used by Transactions, Queries or Business Objects, since that would make them become non-deterministic. Instead, Transactions, Queries and Business Objects must use the executionTime parameter which is passed on their execution.
*/
public Clock clock();
/**
* Returns the Clock used to determine the execution time of all Transaction and Queries executed using this Prevayler. This Clock is useful only to Communication Objects and must NOT be used by Transactions, Queries or Business Objects, since that would make them become non-deterministic. Instead, Transactions, Queries and Business Objects must use the executionTime parameter which is passed on their execution.
*/
public Clock clock();

/** Executes the given Transaction on the prevalentSystem(). ALL operations that alter the observable state of the prevalentSystem() must be implemented as Transaction or TransactionWithQuery objects and must be executed using the Prevayler.execute() methods. This method synchronizes on the prevalentSystem() to execute the Transaction. It is therefore guaranteed that only one Transaction is executed at a time. This means the prevalentSystem() does not have to worry about concurrency issues among Transactions.
* Implementations of this interface can log the given Transaction for crash or shutdown recovery, for example, or execute it remotely on replicas of the prevalentSystem() for fault-tolerance and load-balancing purposes.
* @see org.prevayler.PrevaylerFactory
*/
public void execute(Transaction<? super P> transaction);
/**
* Executes the given Transaction on the prevalentSystem(). ALL operations that alter the observable state of the prevalentSystem() must be implemented as Transaction or TransactionWithQuery objects and must be executed using the Prevayler.execute() methods. This method synchronizes on the prevalentSystem() to execute the Transaction. It is therefore guaranteed that only one Transaction is executed at a time. This means the prevalentSystem() does not have to worry about concurrency issues among Transactions.
* Implementations of this interface can log the given Transaction for crash or shutdown recovery, for example, or execute it remotely on replicas of the prevalentSystem() for fault-tolerance and load-balancing purposes.
*
* @see org.prevayler.PrevaylerFactory
*/
public void execute(Transaction<? super P> transaction);

/** Executes the given sensitiveQuery on the prevalentSystem(). A sensitiveQuery is a Query that would be affected by the concurrent execution of a Transaction or other sensitiveQuery. This method synchronizes on the prevalentSystem() to execute the sensitiveQuery. It is therefore guaranteed that no other Transaction or sensitiveQuery is executed at the same time.
* <br> Robust Queries (queries that do not affect other operations and that are not affected by them) can be executed directly as plain old method calls on the prevalentSystem() without the need of being implemented as Query objects. Examples of Robust Queries are queries that read the value of a single field or historical queries such as: "What was this account's balance at mid-night?".
* @return The result returned by the execution of the sensitiveQuery on the prevalentSystem().
* @throws Exception The Exception thrown by the execution of the sensitiveQuery on the prevalentSystem().
*/
public <R> R execute(Query<? super P,R> sensitiveQuery) throws Exception;
/**
* Executes the given sensitiveQuery on the prevalentSystem(). A sensitiveQuery is a Query that would be affected by the concurrent execution of a Transaction or other sensitiveQuery. This method synchronizes on the prevalentSystem() to execute the sensitiveQuery. It is therefore guaranteed that no other Transaction or sensitiveQuery is executed at the same time.
* <br> Robust Queries (queries that do not affect other operations and that are not affected by them) can be executed directly as plain old method calls on the prevalentSystem() without the need of being implemented as Query objects. Examples of Robust Queries are queries that read the value of a single field or historical queries such as: "What was this account's balance at mid-night?".
*
* @return The result returned by the execution of the sensitiveQuery on the prevalentSystem().
* @throws Exception The Exception thrown by the execution of the sensitiveQuery on the prevalentSystem().
*/
public <R> R execute(Query<? super P, R> sensitiveQuery) throws Exception;

/** Executes the given transactionWithQuery on the prevalentSystem().
* Implementations of this interface can log the given transaction for crash or shutdown recovery, for example, or execute it remotely on replicas of the prevalentSystem() for fault-tolerance and load-balancing purposes.
* @return The result returned by the execution of the transactionWithQuery on the prevalentSystem().
* @throws Exception The Exception thrown by the execution of the sensitiveQuery on the prevalentSystem().
* @see org.prevayler.PrevaylerFactory
*/
public <R> R execute(TransactionWithQuery<? super P,R> transactionWithQuery) throws Exception;
/**
* Executes the given transactionWithQuery on the prevalentSystem().
* Implementations of this interface can log the given transaction for crash or shutdown recovery, for example, or execute it remotely on replicas of the prevalentSystem() for fault-tolerance and load-balancing purposes.
*
* @return The result returned by the execution of the transactionWithQuery on the prevalentSystem().
* @throws Exception The Exception thrown by the execution of the sensitiveQuery on the prevalentSystem().
* @see org.prevayler.PrevaylerFactory
*/
public <R> R execute(TransactionWithQuery<? super P, R> transactionWithQuery) throws Exception;

/** The same as execute(TransactionWithQuery<P,R>) except no Exception is thrown.
* @return The result returned by the execution of the sureTransactionWithQuery on the prevalentSystem().
*/
public <R> R execute(SureTransactionWithQuery<? super P,R> sureTransactionWithQuery);
/**
* The same as execute(TransactionWithQuery<P,R>) except no Exception is thrown.
*
* @return The result returned by the execution of the sureTransactionWithQuery on the prevalentSystem().
*/
public <R> R execute(SureTransactionWithQuery<? super P, R> sureTransactionWithQuery);

/** Produces a complete serialized image of the underlying PrevalentSystem.
* This will accelerate future system startups. Taking a snapshot once a day is enough for most applications.
* This method synchronizes on the prevalentSystem() in order to take the snapshot. This means that transaction execution will be blocked while the snapshot is taken.
* @return The file to which the snapshot was written. This file should be left where it is, so that Prevayler can read it during startup. You can copy it to another location for backup purposes if desired.
* @throws Exception if there is trouble writing to the snapshot file or serializing the prevalent system.
*/
public File takeSnapshot() throws Exception;
/**
* Produces a complete serialized image of the underlying PrevalentSystem.
* This will accelerate future system startups. Taking a snapshot once a day is enough for most applications.
* This method synchronizes on the prevalentSystem() in order to take the snapshot. This means that transaction execution will be blocked while the snapshot is taken.
*
* @return The file to which the snapshot was written. This file should be left where it is, so that Prevayler can read it during startup. You can copy it to another location for backup purposes if desired.
* @throws Exception if there is trouble writing to the snapshot file or serializing the prevalent system.
*/
public File takeSnapshot() throws Exception;

/** Closes any files or other system resources opened by this Prevayler.
* @throws IOException if there is trouble closing a file or some other system resource.
*/
public void close() throws IOException;
/**
* Closes any files or other system resources opened by this Prevayler.
*
* @throws IOException if there is trouble closing a file or some other system resource.
*/
public void close() throws IOException;

}
22 changes: 12 additions & 10 deletions core/src/main/java/org/prevayler/Query.java
Expand Up @@ -7,19 +7,21 @@
import java.io.Serializable;
import java.util.Date;

/** Represents a query that can be executed on a Prevalent System.
/**
* Represents a query that can be executed on a Prevalent System.
*
* @param <P> The type or any supertype of the Prevalent System you intend to perform the query upon. <br>
* @param <R> The type of object which should be returned. <br>
* @see Prevayler#execute(Query)
*/
public interface Query<P,R> extends Serializable{
/**
* @param prevalentSystem The Prevalent System to be queried.
* @param executionTime The "current" time.
* @return The result of this Query.
* @throws Exception Any Exception encountered by this Query.
*/
public R query(P prevalentSystem, Date executionTime) throws Exception;
public interface Query<P, R> extends Serializable {

/**
* @param prevalentSystem The Prevalent System to be queried.
* @param executionTime The "current" time.
* @return The result of this Query.
* @throws Exception Any Exception encountered by this Query.
*/
public R query(P prevalentSystem, Date executionTime) throws Exception;

}
16 changes: 10 additions & 6 deletions core/src/main/java/org/prevayler/SureTransactionWithQuery.java
Expand Up @@ -6,16 +6,20 @@

import java.util.Date;

/** The same as TransactionWithQuery except it does not throw Exception when executed.
/**
* The same as TransactionWithQuery except it does not throw Exception when executed.
*
* @param <P> The type or any supertype of the Prevalent System you intend to perform the transaction and query upon. <br>
* @param <R> The type of object which should be returned. <br>
* @see TransactionWithQuery
*/
public interface SureTransactionWithQuery<P,R> extends TransactionWithQuery<P,R>{
public interface SureTransactionWithQuery<P, R> extends TransactionWithQuery<P, R> {

/** The same as TransactionWithQuery.executeAndQuery(P, Date) except it does not throw Exception when executed.
* @see TransactionWithQuery#executeAndQuery(Object, Date)
*/
public R executeAndQuery(P prevalentSystem, Date executionTime);
/**
* The same as TransactionWithQuery.executeAndQuery(P, Date) except it does not throw Exception when executed.
*
* @see TransactionWithQuery#executeAndQuery(Object, Date)
*/
public R executeAndQuery(P prevalentSystem, Date executionTime);

}
18 changes: 11 additions & 7 deletions core/src/main/java/org/prevayler/Transaction.java
Expand Up @@ -7,21 +7,25 @@
import java.io.Serializable;
import java.util.Date;

/** An atomic transaction to be executed on a Prevalent System.
/**
* An atomic transaction to be executed on a Prevalent System.
* <br>
* <br>To be recoverable, any changes to the observable state of a Prevalent System must be encapsulated in Transactions and performed via the given <code>prevalentSystem</code> in each Transaction.
* <br>
* <br>Upon recovery execution, anything outside <code>prevalentSystem</code> will be a freshly deserialized copy, so cannot reference anything in the Prevalent System.
* <br>
*
* @param <P> The type or any supertype of the Prevalent System you intend to perform the transaction upon. <br>
*/

public interface Transaction<P> extends Serializable{
public interface Transaction<P> extends Serializable {

/** This method is called by Prevayler.execute(Transaction) to execute this Transaction on the given Prevalent System. See org.prevayler.demos for usage examples.
* @param prevalentSystem The system on which this Transaction will execute.
* @param executionTime The time at which this Transaction is being executed. Every Transaction executes completely within a single moment in time. Logically, a Prevalent System's time does not pass during the execution of a Transaction.
*/
public void executeOn(P prevalentSystem, Date executionTime);
/**
* This method is called by Prevayler.execute(Transaction) to execute this Transaction on the given Prevalent System. See org.prevayler.demos for usage examples.
*
* @param prevalentSystem The system on which this Transaction will execute.
* @param executionTime The time at which this Transaction is being executed. Every Transaction executes completely within a single moment in time. Logically, a Prevalent System's time does not pass during the execution of a Transaction.
*/
public void executeOn(P prevalentSystem, Date executionTime);

}
24 changes: 14 additions & 10 deletions core/src/main/java/org/prevayler/TransactionWithQuery.java
Expand Up @@ -7,18 +7,22 @@
import java.io.Serializable;
import java.util.Date;

/** A Transaction that also returns a result or throws an Exception after executing. <br><br>A "PersonCreation" Transaction, for example, may return the Person it created. Without this, to retrieve the newly created Person, the caller would have to issue a Query like: "What was the last Person I created?". <br><br>Looking at the Prevayler demos is by far the best way to learn how to use this class.
/**
* A Transaction that also returns a result or throws an Exception after executing. <br><br>A "PersonCreation" Transaction, for example, may return the Person it created. Without this, to retrieve the newly created Person, the caller would have to issue a Query like: "What was the last Person I created?". <br><br>Looking at the Prevayler demos is by far the best way to learn how to use this class.
*
* @param <P> The type or any supertype of the Prevalent System you intend to perform the transaction and query upon. <br>
* @param <R> The type of object which should be returned. <br>
* @see Transaction
*/
public interface TransactionWithQuery<P,R> extends Serializable {

/** Performs the necessary modifications on the given prevalentSystem and also returns an object or throws an Exception.
* This method is called by Prevayler.execute(TransactionWithQuery<P,R>) to execute this TransactionWithQuery on the given Prevalent System. See org.prevayler.demos for usage examples.
* @param prevalentSystem The system on which this TransactionWithQuery will execute.
* @param executionTime The time at which this TransactionWithQuery is being executed. Every Transaction executes completely within a single moment in time. Logically, a Prevalent System's time does not pass during the execution of a Transaction.
*/
public R executeAndQuery(P prevalentSystem, Date executionTime) throws Exception;

public interface TransactionWithQuery<P, R> extends Serializable {

/**
* Performs the necessary modifications on the given prevalentSystem and also returns an object or throws an Exception.
* This method is called by Prevayler.execute(TransactionWithQuery<P,R>) to execute this TransactionWithQuery on the given Prevalent System. See org.prevayler.demos for usage examples.
*
* @param prevalentSystem The system on which this TransactionWithQuery will execute.
* @param executionTime The time at which this TransactionWithQuery is being executed. Every Transaction executes completely within a single moment in time. Logically, a Prevalent System's time does not pass during the execution of a Transaction.
*/
public R executeAndQuery(P prevalentSystem, Date executionTime) throws Exception;

}
42 changes: 21 additions & 21 deletions core/src/main/java/org/prevayler/foundation/Chunk.java
Expand Up @@ -5,32 +5,32 @@

public class Chunk {

private byte[] _bytes;
private Map _parameters;
private byte[] _bytes;
private Map _parameters;

public Chunk(byte[] bytes) {
this(bytes, new LinkedHashMap());
}
public Chunk(byte[] bytes) {
this(bytes, new LinkedHashMap());
}

public Chunk(byte[] bytes, Map parameters) {
_bytes = bytes;
_parameters = parameters;
}
public Chunk(byte[] bytes, Map parameters) {
_bytes = bytes;
_parameters = parameters;
}

public byte[] getBytes() {
return _bytes;
}
public byte[] getBytes() {
return _bytes;
}

public void setParameter(String name, String value) {
_parameters.put(name, value);
}
public void setParameter(String name, String value) {
_parameters.put(name, value);
}

public String getParameter(String name) {
return (String) _parameters.get(name);
}
public String getParameter(String name) {
return (String) _parameters.get(name);
}

public Map getParameters() {
return _parameters;
}
public Map getParameters() {
return _parameters;
}

}

0 comments on commit b09b08a

Please sign in to comment.