Skip to content
This repository was archived by the owner on Oct 18, 2025. It is now read-only.

Commit 62cff1f

Browse files
committed
Optimize number data types
Simple change, certain fields of entities and composite key classes did not need to be 32-bit integers and could work with smaller data types. I looked at the MySQL database table and column structure, then changed some Java data types accordingly. int = int (4 bytes) smallint = short (2 bytes) tinyint = byte (1 byte)
1 parent ccd9669 commit 62cff1f

File tree

8 files changed

+22
-22
lines changed

8 files changed

+22
-22
lines changed

src/main/java/com/carpi/carpibackend/dto/CourseDto.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CourseDto {
1515
private String department;
1616

1717
@Min(0)
18-
private int code;
18+
private short code;
1919

2020
@NotNull
2121
private String title;
@@ -24,10 +24,10 @@ public class CourseDto {
2424
private String description;
2525

2626
@Min(0)
27-
private short creditMin;
27+
private byte creditMin;
2828

2929
@Min(0)
30-
private short creditMax;
30+
private byte creditMax;
3131

3232
@NotNull
3333
private String[] semesterList;

src/main/java/com/carpi/carpibackend/entity/Course.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Course {
2323
private String department;
2424

2525
@Column(name = "code_num", nullable = false)
26-
private int code;
26+
private short code;
2727

2828
@Column(name = "title", nullable = false)
2929
private String title;
@@ -32,8 +32,8 @@ public class Course {
3232
private String description;
3333

3434
@Column(name = "credit_min", nullable = false)
35-
private short creditMin;
35+
private byte creditMin;
3636

3737
@Column(name = "credit_max", nullable = false)
38-
private short creditMax;
38+
private byte creditMax;
3939
}

src/main/java/com/carpi/carpibackend/entity/CourseAttribute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class CourseAttribute {
2323
private String department;
2424

2525
@Column(name = "code_num", nullable = false)
26-
private int code;
26+
private short code;
2727

2828
@Column(name = "attr", nullable = false)
2929
private String attribute;

src/main/java/com/carpi/carpibackend/entity/CourseSearchResult.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
public class CourseSearchResult {
1616

1717
@EmbeddedId
18-
private CourseKey pkCourses;
18+
private CourseKey coursePk;
1919

2020
@Column(name = "dept", nullable = false)
2121
private String department;
2222

2323
@Column(name = "code_num", nullable = false)
24-
private int code;
24+
private short code;
2525

2626
@Column(name = "title", nullable = false)
2727
private String title;
@@ -30,10 +30,10 @@ public class CourseSearchResult {
3030
private String description;
3131

3232
@Column(name = "credit_min", nullable = false)
33-
private short creditMin;
33+
private byte creditMin;
3434

3535
@Column(name = "credit_max", nullable = false)
36-
private short creditMax;
36+
private byte creditMax;
3737

3838
@Column(name = "sem_list", nullable = false)
3939
private String semesterList;

src/main/java/com/carpi/carpibackend/entity/CourseSeats.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class CourseSeats {
1515
private CourseSeatsKey courseSeatsPk;
1616

1717
@Column(name = "sem_year", nullable = false)
18-
private int semesterYear;
18+
private short semesterYear;
1919

2020
@Column(name = "semester", nullable = false)
2121
private String semester;
@@ -24,11 +24,11 @@ public class CourseSeats {
2424
private String department;
2525

2626
@Column(name = "code_num", nullable = false)
27-
private int code;
27+
private short code;
2828

2929
@Column(name = "seats_filled", nullable = false)
30-
private int seatsFilled;
30+
private short seatsFilled;
3131

3232
@Column(name = "seats_total", nullable = false)
33-
private int seatsTotal;
33+
private short seatsTotal;
3434
}

src/main/java/com/carpi/carpibackend/keys/CourseAttributeKey.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CourseAttributeKey implements Serializable {
1212
private String department;
1313

1414
@Column(name = "code_num", insertable = false, updatable = false, nullable = false)
15-
private int code;
15+
private short code;
1616

1717
@Column(name = "attr", insertable = false, updatable = false, nullable = false)
1818
private String attr;
@@ -33,9 +33,9 @@ public boolean equals(Object obj) {
3333

3434
@Override
3535
public int hashCode() {
36-
int result = department != null ? department.hashCode() : 0;
36+
int result = (department != null ? department.hashCode() : 0);
3737
result = 31 * result + Integer.hashCode(code);
38-
result = 31 * result + attr != null ? attr.hashCode() : 0;
38+
result = 31 * result + (attr != null ? attr.hashCode() : 0);
3939
return result;
4040
}
4141

src/main/java/com/carpi/carpibackend/keys/CourseKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class CourseKey implements Serializable {
1717
private String department;
1818

1919
@Column(name = "code_num", insertable = false, updatable = false, nullable = false)
20-
private int code;
20+
private short code;
2121

2222
@Override
2323
public boolean equals(Object obj) {
@@ -33,7 +33,7 @@ public boolean equals(Object obj) {
3333

3434
@Override
3535
public int hashCode() {
36-
int result = department != null ? department.hashCode() : 0;
36+
int result = (department != null ? department.hashCode() : 0);
3737
result = 31 * result + Integer.hashCode(code);
3838
return result;
3939
}

src/main/java/com/carpi/carpibackend/keys/CourseSeatsKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public class CourseSeatsKey implements Serializable {
1010

1111
@Column(name = "sem_year", insertable = false, updatable = false, nullable = false)
12-
private int semesterYear;
12+
private short semesterYear;
1313

1414
@Column(name = "semester", insertable = false, updatable = false, nullable = false)
1515
private String semester;
@@ -18,7 +18,7 @@ public class CourseSeatsKey implements Serializable {
1818
private String department;
1919

2020
@Column(name = "code_num", insertable = false, updatable = false, nullable = false)
21-
private int code;
21+
private short code;
2222

2323
@Override
2424
public boolean equals(Object obj) {

0 commit comments

Comments
 (0)