-
Notifications
You must be signed in to change notification settings - Fork 11
Storage Manager
It is component for working with the system database. On client device system database it is H2. On the server it is PostgreSQL. In this database saving all persistence data (users, hashed passwords, limits, user setting, vufs metainfo and etc). Exchange with Storage Manager component use serializable DTO classes.
Storage Manager have next stack architecture:

On this image you can view next layers from area Storage Manager:
- Storage Interface Layer - contain data service and repository interfaces for each persistence entity type.
- Transformation Layer - contain utils for convert DTO to entity classes and vice versa (use library MapStruck).
- Entity Layer - contain entity classes use Spring JPA annotation.
This architecture helping have clear business objects in other services without persistent API dependencies. Also as DTO object is serializable, we can run some services on different servers use communication bus for transport objects.


Base packet com.stnetix.ariaddna.persistence for Storage manager should be contain next sub package:
- entity - POJO classes for represent domain model for persist in DB.
- repository - interfaces for all entity objects.
- services - interfaces and implementation service for get, find and persist entity object.
- dto - serializable JavaBeans classes for represent domain model and contain bulder for simple constract.
- transformers - service classes use MapStruct library for convert DTO to Entity and vice versa
- utils - classes for helping connect to DB and read JPA configuration files (persist.xml)
DTO classes it is serializable POJO class with inner builder.
package com.stnetix.ariaddna.persistence.dto;
import java.io.Serializable;
import java.util.UUID;
public class UserDto implements Serializable {
private static final long serialVersionUID = -7064669949678106858L;
private UUID uuid;
private String firstName;
private String lastName;
private UserDto() {
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
return "UserDto{" +
"uuid=" + uuid +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
'}';
}
public static final class UserDtoBuilder {
private UserDtoBuilder() {
}
public static UserDtoBuilder anUserDto() {
return new UserDtoBuilder();
}
public UserDtoBuilder withUuid(UUID uuid) {
this.uuid = uuid;
return this;
}
public UserDtoBuilder withFirstName(String firstName) {
this.firstName = firstName;
return this;
}
public UserDtoBuilder withLastName(String lastName) {
this.lastName = lastName;
return this;
}
public UserDtoBuilder but() {
return anUserDto().withUuid(uuid).withFirstName(firstName).withLastName(lastName);
}
public UserDto build() {
UserDto userDto = new UserDto();
userDto.setUuid(uuid);
userDto.setFirstName(firstName);
userDto.setLastName(lastName);
return userDto;
}
private UUID uuid;
private String firstName;
private String lastName;
}
}Builder can be generate use "Builder Generator" plugin for IDEA. Notice: now DTO design is not immutable.
Entity class is standard POJO class.
See simple example for UserEntity.class:
package com.stnetix.ariaddna.persistence.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.UUID;
@Entity
@Table(name = "User")
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private long id;
@Column(name = "UUID")
private UUID uuid;
@Column(name = "FIRST_NAME")
private String firstName;
@Column(name = "LAST_NAME")
private String lastName;
protected UserEntity() {
}
public UserEntity(UUID uuid, String firstName, String lastName) {
this.uuid = uuid;
this.firstName = firstName;
this.lastName = lastName;
}
@Override
public String toString() {
return String.format(
"UserEntity[id=%d, firstName='%s', lastName='%s']",
id, firstName, lastName);
}
}See simple example Spring JPA (in this example Application implementing service functionality)
See MapStruct documentation and quick guide
© 2018, ariADDna project