MongoDB@ActFramework

Gelin Luo

About me

Agenda

  • A brief introduction to ActFramework
  • Using MongoDB in ActFramework
    • Adaptive Record model
    • Integrate with external storage

ActFramework and Why

  • Story with PlayFramework v1.x
  • Why not SpringFramwork

PlayFramework v1

Why not SpringFramework

  • Verbose programming style
  • No Hot Reload
  • Over complicated configuration model
  • SpringBoot is a rescure but we have a better solution

ActFramework

  • Everything nice in PlayFramework V1
    • Simple Expressive Programming
    • Hot Reload
    • Stateless architecture
    • Profile based configuration
    • Built in Database access
  • Plus
    • Maven drive project structure/build
    • Even better parameter bindings
    • Even better Job programming
    • JSR standard Dependency Injection
    • Much faster runtime performance
    • Multi-DB support
    • Event bus
    • Bulit in CLI 
    • Built in Metric

Deliver an expressive programming experience to Java Web Developer

public class HelloWorldApp {

    @GetAction
    public void home(@DefaultValue("World") @Output String who) {
    }

    public static void main(String[] args) throws Exception {
        Act.start();
    }

}

DEMO TIME

Using MongoDB in ActFramework

Configuration

db.uri=mongodb://localhost/test

Model

@Entity("todo")
public class TodoItem extends MorphiaModel<TodoItem> {

    public String desc;

    public TodoItem(String desc) {
        this.desc = desc;
    }
}

Controller

public class TodoController {

    @Inject
    private MorphiaDao<TodoItem> dao;

    @GetAction("/list")
    public Iterable<TodoItem> list() {
        return dao.findAll();
    }

    @PostAction("/list")
    public void add(String desc) {
        TodoItem item = new TodoItem(desc);
        dao.save(item);
    }

    @GetAction("/list/{item}")
    public TodoItem showItem(@DbBind TodoItem item) {
        return item;
    }

    @PutAction("/list/{item}")
    public void update(@DbBind @NotNull TodoItem item, String desc) {
        item.desc = desc;
        dao.save(item);
    }

    @DeleteAction("/list/{id}")
    public void delete(String id) {
        dao.deleteById(new ObjectId(id));
    }

}

Problem - Duplicate data at BE and FE

User Entity

export class Employee {
    id: string;
    name: string;
    employeeNum: string;
    department: string;
    preference: {
        theme: string,
        lang: string
    }
}
public class Employee {
    private String name;
    private String email;
    private String employeeNum;
    private String department;
}

Solution - Adaptive Record

User Entity

export class Employee {
    id: string;
    name: string;
    employeeNum: string;
    department: string;
    preference: {
        theme: string,
        lang: string
    }
}
@Entity
public class Employee 
extends MorphiaAdaptiveRecord<Employee> {
    public String name;
    public String email;
}

DEMO TIME

External storage integration

  • AWS S3
  • Azure Blob
  • Local Disk

DEMO TIME

Questions?

Using MongoDB in ActFramework

By Gelin Luo

Using MongoDB in ActFramework

Talks about using MongoDB in ActFramework

  • 450