-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify article/answer content schema to TEXT and fix timestamps
- Loading branch information
1 parent
01d64cc
commit 0b02d0c
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/me/sjtumeow/meow/util/LocalDateAttributeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package me.sjtumeow.meow.util; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
|
||
@Converter(autoApply = true) | ||
public class LocalDateAttributeConverter implements AttributeConverter<LocalDateTime, Timestamp> { | ||
|
||
@Override | ||
public Timestamp convertToDatabaseColumn(LocalDateTime localDateTime) { | ||
return (localDateTime == null ? null : Timestamp.valueOf(localDateTime)); | ||
} | ||
|
||
@Override | ||
public LocalDateTime convertToEntityAttribute(Timestamp timestamp) { | ||
return (timestamp == null ? null : timestamp.toLocalDateTime()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/me/sjtumeow/meow/util/LocalDateTimeAttributeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.sjtumeow.meow.util; | ||
|
||
import java.sql.Date; | ||
import java.time.LocalDate; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
|
||
/** | ||
* Custom converter class that enables usage of LocalDateTime with the DB | ||
*/ | ||
|
||
@Converter(autoApply = true) | ||
public class LocalDateTimeAttributeConverter implements AttributeConverter<LocalDate, Date> { | ||
|
||
@Override | ||
public Date convertToDatabaseColumn(LocalDate localDate) { | ||
return (localDate == null ? null : Date.valueOf(localDate)); | ||
} | ||
|
||
@Override | ||
public LocalDate convertToEntityAttribute(Date date) { | ||
return (date == null ? null : date.toLocalDate()); | ||
} | ||
} |