File tree Expand file tree Collapse file tree 2 files changed +92
-0
lines changed
tests/DaoTestEntityAnnotation/src
androidTest/Java/org/greenrobot/greendao/test/entityannotation
main/java/org/greenrobot/greendao/test/entityannotation Expand file tree Collapse file tree 2 files changed +92
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .greenrobot .greendao .test .entityannotation ;
2+
3+ import org .greenrobot .greendao .test .AbstractDaoTestLongPk ;
4+ import org .greenrobot .greendao .test .entityannotation .TypesInInnerClass .MyInnerType ;
5+
6+ public class TypesInInnerClassTest extends AbstractDaoTestLongPk <TypesInInnerClassDao , TypesInInnerClass > {
7+
8+ public TypesInInnerClassTest () {
9+ super (TypesInInnerClassDao .class );
10+ }
11+
12+ @ Override
13+ protected TypesInInnerClass createEntity (Long key ) {
14+ TypesInInnerClass entity = new TypesInInnerClass ();
15+ entity .setId (key );
16+ entity .setType (new MyInnerType ("cafe" ));
17+ return entity ;
18+ }
19+
20+ public void testType () {
21+ TypesInInnerClass entity = createEntity (1L );
22+ dao .insert (entity );
23+ TypesInInnerClass entity2 = dao .load (1L );
24+ assertNotSame (entity , entity2 );
25+ assertEquals ("cafe" , entity2 .getType ().value );
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ package org .greenrobot .greendao .test .entityannotation ;
2+
3+ import org .greenrobot .greendao .annotation .Convert ;
4+ import org .greenrobot .greendao .annotation .Entity ;
5+ import org .greenrobot .greendao .annotation .Generated ;
6+ import org .greenrobot .greendao .annotation .Id ;
7+ import org .greenrobot .greendao .converter .PropertyConverter ;
8+
9+ @ Entity
10+ public class TypesInInnerClass {
11+ static class MyInnerType {
12+
13+ public MyInnerType (String value ) {
14+ this .value = value ;
15+ }
16+
17+ String value ;
18+ }
19+
20+ static class MyInnerTypeConverter implements PropertyConverter <MyInnerType , Long > {
21+
22+ @ Override
23+ public MyInnerType convertToEntityProperty (Long databaseValue ) {
24+ return databaseValue !=null ? new MyInnerType (Long .toHexString (databaseValue )): null ;
25+ }
26+
27+ @ Override
28+ public Long convertToDatabaseValue (MyInnerType entityProperty ) {
29+ return entityProperty != null ? Long .parseLong (entityProperty .value , 16 ): null ;
30+ }
31+ }
32+
33+ @ Id
34+ Long id ;
35+
36+ @ Convert (converter = MyInnerTypeConverter .class , columnType = Long .class )
37+ MyInnerType type ;
38+
39+ public MyInnerType getType () {
40+ return this .type ;
41+ }
42+
43+ public void setType (MyInnerType type ) {
44+ this .type = type ;
45+ }
46+
47+ public Long getId () {
48+ return this .id ;
49+ }
50+
51+ public void setId (Long id ) {
52+ this .id = id ;
53+ }
54+
55+ @ Generated (hash = 1322981681 )
56+ public TypesInInnerClass (Long id , MyInnerType type ) {
57+ this .id = id ;
58+ this .type = type ;
59+ }
60+
61+ @ Generated (hash = 1754325029 )
62+ public TypesInInnerClass () {
63+ }
64+
65+ }
You can’t perform that action at this time.
0 commit comments