net.ecfirm.ec.ec1.model.EcModel.java Source code

Java tutorial

Introduction

Here is the source code for net.ecfirm.ec.ec1.model.EcModel.java

Source

/*
 * @package ecfirm.net
 * @copyright Copyright (C) kilmeny.net. All rights reserved.
 * @license GNU General Public License version 2 or later.
 */

package net.ecfirm.ec.ec1.model;

import android.content.Context;
import android.database.Cursor;

import net.ecfirm.ec.ec1.lib.EcApp;
import net.ecfirm.ec.ec1.lib.EcConf;
import net.ecfirm.ec.ec1.lib.EcFactory;
import net.ecfirm.ec.ec1.lib.EcFile;
import net.ecfirm.ec.ec1.net.EcNet;

import org.json.JSONArray;

import java.util.Observable;

public abstract class EcModel extends Observable implements EcModelBase {
    protected static EcApp app = null;
    protected static EcConf conf = null;
    protected static Context context = null;
    protected static EcFile file = null;
    protected String nameModel = "";
    protected static EcNet net = null;

    protected EcModel() {
        this.nameModel = this.getClass().getSimpleName().substring(7).toLowerCase();
        context = EcFactory.getContext();
        app = EcFactory.getEcApp();
        conf = EcFactory.getEcConf();
        file = EcFactory.getEcFile();
        net = EcFactory.getEcNet();
    }

    protected abstract void close();

    @Override
    public abstract long deleteColumn(String nameKey, long valueKey);

    @Override
    public abstract long deletes();

    protected abstract Cursor getColumns(String nameKey, long valueKey, String cols[]);

    /**
     * @deprecated not yet used */
    public int getModified(long value) {
        String[] cols = { "modified" };
        Cursor cursor = this.getColumns(this.nameModel, value, cols);
        try {
            return cursor.getInt(0);
        } catch (Exception e) {
            app.log(e);
            return 0;
        }
    }

    @Override
    public abstract Cursor getItemsCursor();

    @Override
    public String getName() {
        return this.nameModel;
    }

    protected void inform() {
        this.setChanged();
        this.notifyObservers();
    }

    @Override
    public abstract long setColumn(String nameKey, String valueKey, String nameCol, String valueCol);

    @Override
    public abstract boolean setItems(JSONArray items);
}