task/3382: Harmonisera tabellnamn #6

Merged
ansv7779 merged 104 commits from task/3382 into develop 2024-11-12 13:33:44 +01:00
2 changed files with 88 additions and 59 deletions
Showing only changes of commit 83ae6491f8 - Show all commits

View File

@ -1,42 +1,87 @@
package se.su.dsv.scipro.activityplan;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import jakarta.persistence.Cacheable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderColumn;
import jakarta.persistence.Table;
import se.su.dsv.scipro.system.DomainObject;
import se.su.dsv.scipro.system.User;
import jakarta.persistence.*;
import java.util.*;
@Entity
@Cacheable(true)
@Table(name = "activity_plan_template")
public class ActivityPlanTemplate extends DomainObject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OrderColumn(name = "numberInOrder")
@OneToMany(mappedBy="activityPlanTemplate", orphanRemoval=true, cascade=CascadeType.ALL)
private List<ActivityTemplate> activityTemplates = new ArrayList<>();
public List<ActivityTemplate> getActivityTemplates(){
return Collections.unmodifiableList(activityTemplates);
}
public void setActivityTemplates(List<ActivityTemplate> activityTemplates){
this.activityTemplates = new ArrayList<>(activityTemplates);
}
@ManyToOne(optional=false)
private User creator;
@Column(name = "is_sys_admin_template", nullable=false)
private boolean isSysAdminTemplate = false;
@Column(nullable=false)
private String title;
@Lob
private String description;
@Column(nullable=false)
private boolean isSysAdminTemplate = false;
@OrderColumn(name = "number_in_order")
@OneToMany(mappedBy="activityPlanTemplate", orphanRemoval=true, cascade=CascadeType.ALL)
private List<ActivityTemplate> activityTemplates = new ArrayList<>();
@ManyToOne(optional=false)
@JoinColumn(name = "user_id")
private User creator;
@Override
tozh4728 marked this conversation as resolved Outdated

Again less self describing column name. creator_id tells you it is the user who created the template rather than just a generic user_id. The referenced table/type is visible from the foreign key/class.

Again less self describing column name. `creator_id` tells you it is the user who created the template rather than just a generic `user_id`. The referenced table/type is visible from the foreign key/class.
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public boolean isSysAdminTemplate() {
return this.isSysAdminTemplate;
}
public void setSysAdminTemplate(boolean isSysAdminTemplate) {
this.isSysAdminTemplate = isSysAdminTemplate;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public void addActivity(ActivityTemplate activity){
activity.setActivityPlanTemplate(this);
@ -52,47 +97,22 @@ public class ActivityPlanTemplate extends DomainObject {
activityTemplates.addAll(activities);
}
@Override
public Long getId() {
return this.id;
public List<ActivityTemplate> getActivityTemplates(){
return Collections.unmodifiableList(activityTemplates);
}
public void setActivityTemplates(List<ActivityTemplate> activityTemplates){
this.activityTemplates = new ArrayList<>(activityTemplates);
}
public User getCreator() {
return this.creator;
}
public String getTitle() {
return this.title;
}
public String getDescription() {
return this.description;
}
public boolean isSysAdminTemplate() {
return this.isSysAdminTemplate;
}
public void setId(Long id) {
this.id = id;
}
public void setCreator(User creator) {
this.creator = creator;
}
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
public void setSysAdminTemplate(boolean isSysAdminTemplate) {
this.isSysAdminTemplate = isSysAdminTemplate;
}
@Override
public boolean equals(final Object o) {
if (o == this) return true;

View File

@ -1004,7 +1004,7 @@ alter table `application_period_project_type` rename column `activityPlanTemplat
alter table `application_period_project_type` add primary key (application_period_id, project_type_id);
-- >>> STACK PUSH: 2nd table group: target, ActivityPlanTemplate and ActivityTemplate
-- >>> STACK PUSH: 2nd table group: ActivityPlanTemplate and ActivityTemplate
-- table: ActivityTemplate, except foreign key to coming table activity_plan_template
@ -1028,15 +1028,21 @@ alter table `activity_template`
-- table: ActivityPlanTemplate (at this stage, no any foreign key is are referenced to ActivityPlanTemplate)
alter table `ActivityPlanTemplate` drop foreign key `FK_rgwf80yvcy2msbb6g80bae10p`;
alter table `ActivityPlanTemplate` drop key `FK_rgwf80yvcy2msbb6g80bae10p`;
alter table `ActivityPlanTemplate` drop key `FKACCF6522E44F4DBE`;
rename table `ActivityPlanTemplate` to `activity_plan_template`;
alter table `activity_plan_template` rename column `isSysAdminTemplate` to `is_sys_admin_template`;
alter table `activity_plan_template` rename column `creator_id` to `user_id`;
alter table `activity_plan_template`
add constraint fk_activity_plan_template_user_id
foreign key (user_id) references user (id)
on delete cascade on update cascade;
/* Activate following later
-- **********************************************************************************
-- TODO: -- Add back all foreign key references to activity_plan_template
-- **********************************************************************************
-- Add back all foreign key references to activity_plan_template
-- add foreign key reference from activity_template to activity_plan_template
alter table `activity_template`
@ -1044,15 +1050,18 @@ alter table `activity_template`
foreign key (activity_plan_template_id) references activity_plan_template (id)
on delete cascade on update cascade;
-- add foreign key reference from application_period_project_type to activity_plan_template
alter table `application_period_project_type`
add constraint fk_ap_pt_activity_plan_template_id
foreign key (activity_plan_template_id) references activity_plan_template (id)
on delete cascade on update cascade;
-- >>> STACK POP: 2nd table group (ActivityPlanTemplate and ActivityTemplate) is done!!!
/* Activate following later
-- **********************************************************************************
-- TODO: fix table ApplicationPeriod, verify no foreign keys are referenced to ApplicationPeriod before fix it
-- **********************************************************************************