Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story and example #1

Open
sormuras opened this issue Dec 20, 2016 · 0 comments
Open

Story and example #1

sormuras opened this issue Dec 20, 2016 · 0 comments

Comments

@sormuras
Copy link
Owner

sormuras commented Dec 20, 2016

story

Using Prevayler for persistence is easy. With Stash you can turn any Java interface into a Prevalent System. Stash generates Java source code that persists each method call on the interface for playing it back later.

example

@Stash.Interface
public interface Club extends AutoCloseable {

  Member create(String name);

  Member member(int number);

  void rename(int number, String newName);

  static void main(String[] args) throws Exception {
    ByteBuffer buffer = ByteBuffer.allocate(1000);
    try (Club club = Stash.create(Club.class, new Disco(), buffer)) {
      club.create("Aaron");
      club.create("Bert");
      club.create("Carla");
      club.rename(1, "Bartholomaeus");
    }
    try (Club club = Stash.proxy(Club.class, new Disco(), buffer)) {
      assert "Aaron".equals(club.member(0).name());
      assert "Bartholomaeus".equals(club.member(1).name());
      assert "Carla".equals(club.member(2).name());
      club.rename(2, "Ceera");
    }
    try (Club club = new ClubStash(Treasure.create(new Disco(), buffer))) {
      assert "Aaron".equals(club.member(0).name());
      assert "Bartholomaeus".equals(club.member(1).name());
      assert "Ceera".equals(club.member(2).name());
    }
  }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant