本文来自:安卓航班网

        原理和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

posted on 2011-09-01 18:55  泉と緣  阅读(412)  评论(0编辑  收藏  举报