DatabaseHelper.java :  » UnTagged » petdb » uk » org » aspellclark » petsdb » db » Android Open Source

Android Open Source » UnTagged » petdb 
petdb » uk » org » aspellclark » petsdb » db » DatabaseHelper.java
package uk.org.aspellclark.petsdb.db;

import uk.org.aspellclark.common.db.AbstractDatabaseHelper;
import uk.org.aspellclark.common.db.AbstractDbConstants;
import uk.org.aspellclark.petsdb.model.Animal;
import uk.org.aspellclark.petsdb.model.Event;
import uk.org.aspellclark.petsdb.model.Insurance;
import uk.org.aspellclark.petsdb.model.Vet;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

/**
 * a simple class used to determine whether the application needs to execute
 * in debug mode or not.
 *
 * @author andy
 */
/**
 * This class helps open, create, and upgrade the database file.
 */
public class DatabaseHelper extends AbstractDatabaseHelper {

  public DatabaseHelper(Context context, AbstractDbConstants dbConstants) {
    super(context, dbConstants);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
    super.onCreate(db);
    db.execSQL(new Animal().getSqlCreate());
    db.execSQL(new Event().getSqlCreate());
    db.execSQL(new Vet().getSqlCreate());
    db.execSQL(new Insurance().getSqlCreate());
  }

  @Override
  public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    super.onUpgrade(db, oldVersion, newVersion);
    db.execSQL("DROP TABLE IF EXISTS " + new Animal().getTableName());
    db.execSQL("DROP TABLE IF EXISTS " + new Event().getTableName());
    db.execSQL("DROP TABLE IF EXISTS " + new Vet().getTableName());
    db.execSQL("DROP TABLE IF EXISTS " + new Insurance().getTableName());
    this.onCreate(db);
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.