Skip to content

Database

Oliver Pennery edited this page Apr 22, 2021 · 6 revisions

Database

  1. Building
  2. Room
  3. Sensor
  4. Reading

Building

Syntax Data Type Description
ID Long Primary Key
Name String Name of building

Room

Syntax Data Type Description
ID Long Primary Key
Name String Name of building
BuildingId Long Foreign key of building

Sensor

Syntax Data Type Description
ID Long Primary Key[IOT ID]
Description String Description of Device
RoomId Long Foreign key of Room

Reading

Syntax Data Type Description
ID Long Primary Key
Date Date Date and time of reading
CO2 Int CO2 reading
SensorId Long Foreign key of Sensor

Note

Foreign keys are one to many in a tree stuct building ->> room ->> device ->> reading

example code for Sensor entity

how the parent is defined in code

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JsonBackReference
@Getter
@Setter
private Room room;

how the child is defined in code

@OneToMany(mappedBy = "sensor", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JsonManagedReference
@Setter
private Set<Reading> readings;

Clone this wiki locally