使用objectbox可以儲存一些具有複雜關係的資料,比如一對多關係,比如一對多關係和多對多關係.
比如我要儲存這樣關係的資料
subjectmanager對movielistsubject是一對多的關係
每乙個subject對rating和image都是一對一的關係
層次由高到低是這樣設計實體的
@entity
public class movielistcontent
@entity
public class movielistsubjectmanager
@entity
public class rating
@entity
public class image
final boxmovielistcontentbox = boxstore.boxfor(movielistcontent.class);
final boxmovielistsubjectbox = boxstore.boxfor(movielistsubject.class);
final boxratingbox = boxstore.boxfor(rating.class);
final boxmovielistsubjectmanagerbox = boxstore.boxfor(movielistsubjectmanager.class);
boximagebox = boxstore.boxfor(image.class);
movielistcontentbox.removeall();
movielistsubjectbox.removeall();
ratingbox.removeall();
imagebox.removeall();
movielistsubjectmanagerbox.removeall();
doubanapiservice service = apiservicesington.getservice();
observableobservable = service.getmoviesearcecontent("高圓圓", "0", "10");
observable.subscribeon(schedulers.io())
.observeon(androidschedulers.mainthread())
.subscribe(new consumer()
movielistsubjectmanager.getmovielistsubjecttomany().addall(movielistsubjects);
movielistcontent.getmovielistsubjectmanagertoone().settarget(movielistsubjectmanager);
movielistcontentbox.put(movielistcontent);
}});
boxmovielistcontentbox = boxstore.boxfor(movielistcontent.class);
movielistcontent movielistcontent = movielistcontentbox.get(20);
log.d("tinuv_movielistcontent", movielistcontent.gettitle());
movielistsubjectmanager manager = movielistcontent.getmovielistsubjectmanagertoone().gettarget();
for (int i = 0; i < 10; i++)
搞懂這些東西其實花了我很長時間(大概一天),因為英語不好,很多地方看文件看不懂,只能一遍一遍嘗試,在嘗試的過程中程式崩潰了很多次,我也崩潰了很多次,但是還是要感謝這個庫的開發者,因為真的很好用也很有用.
objectbox官方**:
??正文結束??
Redis無法儲存ef複雜物件
最近專案需要使用redis。然後我就滿懷激情開始處理資料層了。在原來查詢資料的基礎上,有封裝了乙個redis快取層。結果在redis儲存ef物件的時候,發現了乙個非常尷尬的問題。model public partial class sys user key public int userid pub...
複雜sql,還沒學儲存過程
複雜sql 涉及 行轉列,排名,差值,排名變化,left join select 排名 a0,concat 收聽份額 a1 concat 收聽份額 a2 收聽份額 增減值 排名變化 concat 收聽率 a1 concat 收聽率 a2 收聽率 增減值 from z 2019061010290876...
hive儲存複雜的json格式
1.hive復合資料型別 array data type map primitive type,data type struct col name data type comment col comment 2.json建構於兩種結構 名稱 值 對的集合 a collection of name v...