Back to project page on-the-hook.
The source code is released under:
MIT License
If you think the Android project on-the-hook listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.yoandinkov.onthehook.db; /*w w w.jav a 2 s.com*/ import java.util.ArrayList; import java.util.List; import android.content.Context; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.util.Log; import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; import com.j256.ormlite.dao.Dao; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import com.yoandinkov.onthehook.db.models.FishDbModel; public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static final String DATABASE_NAME = "Fishes.sqlite"; private static final int DATABASE_VERSION = 1; private Dao<FishDbModel, Integer> fishDao = null; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { try { TableUtils.createTable(connectionSource, FishDbModel.class); } catch (SQLException e) { Log.e(DatabaseHelper.class.getName(), "Can't create database", e); throw new RuntimeException(e); } catch (java.sql.SQLException e) { e.printStackTrace(); } } @Override public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) { try { List<String> allSql = new ArrayList<String>(); switch (oldVersion) { case 1: // allSql.add("alter table AdData add column `new_col` VARCHAR"); // allSql.add("alter table AdData add column `new_col2` VARCHAR"); } for (String sql : allSql) { db.execSQL(sql); } } catch (SQLException e) { Log.e(DatabaseHelper.class.getName(), "exception during onUpgrade", e); throw new RuntimeException(e); } } public Dao<FishDbModel, Integer> getFishesListDao() { if (null == fishDao) { try { fishDao = getDao(FishDbModel.class); } catch (java.sql.SQLException e) { e.printStackTrace(); } } return fishDao; } public void dropFishesTable() { try { TableUtils.dropTable(getConnectionSource(), FishDbModel.class, false); } catch (java.sql.SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }