Created
May 27, 2016 21:19
-
-
Save nakamura-to/91b6da40aa5ae13f8fa522a13a690e67 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 | |
public class IntervalAdapter { | |
private final long start; | |
private final long end; | |
public IntervalAdapter(long start, long end) { | |
this.start = start; | |
this.end = end; | |
} | |
// getter, setter | |
} |
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
@ExternalEmbeddable | |
public class IntervalConverter implements EmbeddableConverter<Interval, IntervalAdapter> { | |
public IntervalAdapter fromEmbeddableToAdapter(Interval interval) { | |
return new IntervalAdapter(interval.getStartMillis(), interval.getEndMillis()); | |
} | |
public Interval fromAdapterToEmbeddable(IntervalAdapter adapter) { | |
return new Interval(adapter.getStart(), adapter.getEnd()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment