mercredi 2 août 2017

DAO pattern with Lists

I'm working on an application with two objects called Types and Tags.

Type.java

public class Type {
    private String name;
    private final UUID uuid;
    private final List<Tag> tags;
}

Tag.java

public class Tag {
    private String name;
    private final UUID uuid;
}

Tables.sql

CREATE TABLE tag (
  tag_uuid CHAR(36) PRIMARY KEY,
  name     VARCHAR(255) UNIQUE
);

CREATE TABLE type (
  type_uuid CHAR(36) PRIMARY KEY,
  name      VARCHAR(255) UNIQUE
);

CREATE TABLE type_tags (
  type_uuid CHAR(36),
  tag_uuid  CHAR(36),
  PRIMARY KEY (type_uuid, tag_uuid),
  FOREIGN KEY (type_uuid) REFERENCES type (type_uuid),
  FOREIGN KEY (tag_uuid) REFERENCES tag (tag_uuid)
);

I'm following the DAO design pattern, but I'm having trouble applying it here. Each Type can has a list of Tags, so what's the best approach to load a Type?

Aucun commentaire:

Enregistrer un commentaire