Android Contact数据模型之EntityDelta(二)
本文來自:安卓航班網
????????原理和getPrimaryEntry(String mimeType)相似。但是只有forceSelection為true的情況下,才在沒有找到SuperPrimaryEntry的情況下返回PrimaryEntry,如果PrimaryEntry也沒找到,才返回MIME類型為mimeType的ValuesDelta的ArrayList<ValuesDelta>的第一的ValuesDelta,如果ArrayList<ValuesDelta>為空則返回null。
? ?? ???private ArrayList<ValuesDelta> getMimeEntries(String mimeType, boolean lazyCreate)
? ?? ???得到指定MIME類型mimeType的ArrayList<ValuesDelta>,如果lazyCreate為true,在IME類型mimeType的ArrayList<ValuesDelta>沒被創建的情況下,會創建它并放入HashMap<String, ArrayList<ValuesDelta>> mEntrie中。
? ?? ???public ArrayList<ValuesDelta> getMimeEntries(String mimeType)
? ?? ???直接調用getMimeEntries(mimeType, false)。
? ?? ? public int getMimeEntriesCount(String mimeType, boolean onlyVisible)
? ?? ? 得到指定MIME類型mimeType的ValuesDelta數量。如果onlyVisible是true,則ValuesDelta還必須是isVisible()的。
? ?? ? public boolean hasMimeEntries(String mimeType)
? ?? ? 返回HashMap<String, ArrayList<ValuesDelta>>中是否有MIME類型mimeType的ArrayList<ValuesDelta>。
? ?? ? public ValuesDelta addEntry(ValuesDelta entry)
? ?? ? 加入一個ValuesDelta entry。
? ?? ? public ValuesDelta getEntry(Long childId)
? ?? ? 得到id為Long childId的ValuesDelta
? ?? ???public int getEntryCount(boolean onlyVisible)
? ?? ???得到ValuesDelta的數量,如果onlyVisible是true,則ValuesDelta還必須是isVisible()的。
? ?? ???public boolean equals(Object object)
? ?? ???返回兩個EntityDelta是否相當。只有他們所包括的ValuesDelta一樣才相等。
? ?? ???注:這里的"一樣"是指ValuesDelta的equals(Object object)返回true.
? ?? ???private boolean containsEntry(ValuesDelta entry)
? ?? ???返回ValuesDelta entry是否已經在了HashMap<String, ArrayList<ValuesDelta>>中。
? ?? ???public void markDeleted()
? ?? ???對包含的所有ValuesDelta進行markDeleted()操作。(這里包括主數據ValuesDelta mValues和子數據 HashMap<String, ArrayList<ValuesDelta>>)
? ?? ???public String toString()
? ?? ???把所有ValuesDelta進行轉化為String.
? ?? ???private void possibleAdd(ArrayList<ContentProviderOperation> diff,ContentProviderOperation.Builder builder)
? ?? ???在builder不為空的情況下,把builder生成的ContentProviderOperation加入到ArrayList<ContentProviderOperation> diff中。
? ?? ?? ?注1:該方法其實應該是static的才對。不知道為什么google沒把它寫成靜態的。也許是google的失誤吧。
? ?? ?? ?public void buildAssert(ArrayList<ContentProviderOperation> buildInto)
java代碼:
* Build a list of {@link ContentProviderOperation} that will assert any
* "before" state hasn't changed. This is maintained separately so that all
* asserts can take place before any updates occur.
*/
?????用主數據mValues的Id和RawContacts.VERSION生產一個RawContacts.CONTENT_URI上的AssertQuery形builder,并加入ArrayList<ContentProviderOperation> buildInto)。
? ?? ? 注:該函數的真正意義應該是在對數據庫操作時(Provide中)進行數據庫更新時確保數據的一致性。即數據在我們讀到EntityDelta并沒有改變過。
? ?? ? public void buildDiff(ArrayList<ContentProviderOperation> buildInto)
? ?? ? 該函數負責把該EntityDelta轉化為ArrayList<ContentProviderOperation>,以便進行數據庫操作。它主要是調用ValuesDelta的buildDiff來進行ContentProviderOperation,然后把他們整合起來。
? ?? ? 注1:對于全新的插入操作,需要在操作前把主表mValues的RawContacts.AGGREGATION_MODE設置為RawContacts.AGGREGATION_MODE_SUSPENDED,等子數據都插入完了才設置為RawContacts.AGGREGATION_MODE_DEFAULT。
? ?? ? 注2:對于更新操作,但是子數據有插入操作的同上。
? ?? ? 注3:如果主數據時插入操作,那么子數據也必須是插入操作,否則會拋異常。
? ?? ? 注4:對于全EntityDelta的刪除操作,只需要主表的信息就可以了,因為它的每個子表都存有主表的Id(即Data.RAW_CONTACT_ID).
? ?? ? 注5:創建AssertQuery形的builder,可用這樣的形式:final ContentProviderOperation.Builder builder = ContentProviderOperation.newAssertQuery(RawContacts.CONTENT_URI)
? ?? ? protected Builder buildSetAggregationMode(Long beforeId, int mode)
? ?? ? 用Long beforeId, int mode生成update的Builder。
? ?? ? public int describeContents()
? ?? ? 返回0.// Nothing special about this parcel
? ?? ? 注:該方法來自Parcelable。
? ?? ? public void writeToParcel(Parcel dest, int flags)
? ?? ? 把主表和子表數據都寫到Parcel。
? ?? ? 注:該方法來自Parcelable。
? ?? ? public void readFromParcel(Parcel source)
? ?? ? 從Parcel source中讀取主表和子表數據。
原文地址:http://www.apkway.com/forum.php?mod=viewthread&tid=3196&extra=page%3D1
轉載于:https://www.cnblogs.com/yyq-quan/archive/2011/09/01/2162343.html
總結
以上是生活随笔為你收集整理的Android Contact数据模型之EntityDelta(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 超声检查预测一年后RA病人的MRI侵蚀进
- 下一篇: 【转】谈谈三层架构中MODEL的作用