Facade to User and Auction

../../_images/example-facade-solo.png

Facade for User and Auction

Installation

Prerequisites

Installing Baratine

Download Baratine from http://baratine.io/download and extract it to any directory.

Source Code for the Example

Maven repository

Add the following maven dependency:

<dependencies>
  <dependency>
    <groupId>io.baratine</groupId>
    <artifactId>baratine</artifactId>
    <version>0.10.0</version>
  </dependency>
</dependencies>

FacadeServiceImpl.java

Create the class FacadeServiceImpl.java:

package example;

import javax.inject.Inject;
import io.baratine.core.Lookup;
import io.baratine.core.Modify;
import io.baratine.core.Result;
import io.baratine.core.Service;
import io.baratine.store.Store;
import java.util.*;

@Service("public:///facade")
public class FacadeServiceImpl extends FacadeService
{
  @Inject @Lookup("pod://user/user")
  UserService _user;

  @Inject @Lookup("pod://auction/auction")
  AuctionService _auction;

  public void bid(String userName,
                  String auctionId,
                  long bid,
                  Result<String> result)
  {
    _user.get(userName,
              result.from((userName,r)->afterUser(user,auctionId,bid,r));
  }

  private void afterUser(User user,
                         String auctionId,
                         long bid,
                         Result<String> result)
  {
    _auction.bid(user, auctionId, bid, result.from(v->afterBid(v)));
  }

  private String afterBid(Bid bid)
  {
    return bid.toString();
  }
}

UserService.java

Create the class UserService.java:

package example;

import io.baratine.core.Result;

public interface UserService
{
  void get(String userName, Result<User> result);
}

AuctionService.java

Create the class AuctionService.java:

package example;

import io.baratine.core.Result;

public interface AuctionService
{
  void bid(User user, String auctionId, long bid, Result<Bid> result);
}