package com.raizlabs.android.dbflow.structure.provider;

import android.database.Cursor;

import com.raizlabs.android.dbflow.config.FlowManager;
import com.raizlabs.android.dbflow.sql.language.ConditionGroup;
import com.raizlabs.android.dbflow.structure.BaseModel;

/**
 * Description: Provides a base implementation of a {@link com.raizlabs.android.dbflow.structure.Model} backed
 * by a content provider. All operations sync with the content provider in this app from a {@link android.content.ContentProvider}
 */
public abstract class BaseSyncableProviderModel<TableClass extends BaseSyncableProviderModel> extends BaseModel implements ModelProvider<TableClass> {

    @Override
    public void insert() {
        super.insert();
        ContentUtils.insert(getInsertUri(), this);
    }

    @Override
    public void save() {
        super.save();

        if (exists()) {
            update();
        } else {
            insert();
        }
    }

    @Override
    public void delete() {
        super.delete();
        ContentUtils.delete(getDeleteUri(), this);
    }

    @Override
    public void update() {
        super.update();
        ContentUtils.update(getUpdateUri(), this);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void load(ConditionGroup whereConditionGroup,
                     String orderBy, String... columns) {
        Cursor cursor = ContentUtils.query(FlowManager.getContext().getContentResolver(), getQueryUri(), whereConditionGroup, orderBy, columns);
        if(cursor != null && cursor.moveToFirst()) {
            getModelAdapter().loadFromCursor(cursor, this);
            cursor.close();
        }
    }

    @Override
    @SuppressWarnings("unchecked")
    public void load() {
        load(getModelAdapter().getPrimaryConditionClause(this), "");
    }
}

@@ -886,54 +886,120 @@
     
-update();%0A        %7D else %7B%0A            insert(
+ContentUtils.update(getUpdateUri(), this);%0A        %7D else %7B%0A            ContentUtils.insert(getInsertUri(), this
 );%0A 

fix duplicate calling for insert and update methods