Skip to content

Commit

Permalink
Modify article/answer content schema to TEXT and fix timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
gousaiyang committed Sep 13, 2017
1 parent 01d64cc commit 0b02d0c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/me/sjtumeow/meow/model/Answer.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package me.sjtumeow.meow.model;

import com.fasterxml.jackson.annotation.JsonBackReference;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.Formula;

import com.fasterxml.jackson.annotation.JsonBackReference;

@Entity
public class Answer extends Item {

private static final long serialVersionUID = 1L;

@Column(columnDefinition = "TEXT")
private String content;

@JsonBackReference
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/me/sjtumeow/meow/model/Article.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package me.sjtumeow.meow.model;

import javax.persistence.Column;
import javax.persistence.Entity;

@Entity
public class Article extends Item {

private static final long serialVersionUID = 1L;

String title, summary, content, cover;
String title, summary, cover;

@Column(columnDefinition = "TEXT")
String content;

public Article() {
type = Item.ITEM_TYPE_ARTICLE;
Expand Down
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());
}
}
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());
}
}

0 comments on commit 0b02d0c

Please sign in to comment.