Android Open Source - OBS-Translation-App Abstract D B Helper






From Project

Back to project page OBS-Translation-App.

License

The source code is released under:

MIT License

If you think the Android project OBS-Translation-App listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.door43.obs.mta.db;
//w  ww.j  ava2 s . c  o m
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import org.door43.obs.mta.model.IPersistenceObject;

import java.util.Date;

public abstract class AbstractDBHelper extends SQLiteOpenHelper {

  /* CONSTANTS */

    /* FIELDS */

    /* CONSTRUCTORS */

    public AbstractDBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public AbstractDBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
        super(context, name, factory, version, errorHandler);
    }

    /* METHODS */

    public void checkBeforeSave(IPersistenceObject object) {

        if (object == null) {
            return;
        }

        Date now = new Date();

        if (object.getCreated() == null) {
            object.setCreated(now);
        }

        object.setModified(now);

    }

    public void putDateValue(ContentValues contentValues, String paramName, Date date) {

        if (date == null) {
            contentValues.put(paramName, "null");
        } else {
            contentValues.put(paramName, date.getTime());
        }

    }

    public Date getDate(Cursor cur, String column) {

        if (cur == null || column == null) {
            return null;
        }

        int columnIndex = cur.getColumnIndex(column);

        if (columnIndex == -1) {
            return null;
        }

        return new Date(cur.getLong(columnIndex));
    }

    public boolean doesExists(String tableName, String column, Long id) {

        SQLiteDatabase db = getReadableDatabase();

        Cursor cur = db.query(tableName, new String[]{column},
                column + " = ?",
                new String[]{String.valueOf(id)},
                null, null, null);

        return (cur != null && cur.moveToFirst());

    }

    /* GETTERS AND SETTERS */

    /* OBJECT METHODS */

}




Java Source Code List

com.door43.obt.ata.MenuListActivity.java
com.door43.obt.ata.MenuListFragment.java
com.door43.obt.ata.RowAdapter.java
com.door43.obt.ata.SplashActivity.java
com.door43.obt.ata.TranslationDetailActivity.java
com.door43.obt.ata.TranslationFragment.java
org.door43.obs.mta.ConstApp.java
org.door43.obs.mta.db.AbstractDBHelper.java
org.door43.obs.mta.db.ConstTranslations.java
org.door43.obs.mta.db.TranslationDBHelper.java
org.door43.obs.mta.model.Frame.java
org.door43.obs.mta.model.IFrame.java
org.door43.obs.mta.model.IPersistenceObject.java
org.door43.obs.mta.model.ITerm.java
org.door43.obs.mta.model.IText.java
org.door43.obs.mta.model.ITranslationNotes.java
org.door43.obs.mta.model.ITranslation.java
org.door43.obs.mta.model.PersistenceObject.java
org.door43.obs.mta.model.Term.java
org.door43.obs.mta.model.Text.java
org.door43.obs.mta.model.TranslationNotes.java
org.door43.obs.mta.model.Translation.java
org.door43.obs.mta.service.FakeTranslationService.java
org.door43.obs.mta.service.ITranslationService.java
org.door43.obs.mta.service.TranslationService.java
org.door43.obs.mta.util.AssetsUtil.java
org.door43.obs.mta.util.StringUtils.java