-
-
Save gakuzzzz/21c68758cba47c26e6791bbc1073fc83 to your computer and use it in GitHub Desktop.
Doma external embeddable
This file contains hidden or 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
@Entity | |
public class Era { | |
@Id | |
public Integer id; | |
public String name; | |
public Interval interval; | |
} |
This file contains hidden or 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
create table era { | |
id integer primary key, | |
name varchar(100), | |
start bigint, | |
end bigint, | |
} |
This file contains hidden or 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
@Embeddable(factoryMethod = "to", extractMethod = "from") | |
public class IntervalAdapter { | |
private final long start; | |
private final long end; | |
public IntervalAdapter(long start, long end) { | |
this.start = start; | |
this.end = end; | |
} | |
public Interval to() { | |
return new Interval(start, end); | |
} | |
public static IntervalAdapter from(Interval interval) { | |
return new IntervalAdapter(interval.getStartMillis(), interval.getEndMillis()); | |
} | |
// getter, setter | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment