From d0a0736b7f2e56a1529a94811e05bfcc8ffc41a6 Mon Sep 17 00:00:00 2001 From: lado Date: Tue, 27 Nov 2012 11:28:56 +0100 Subject: debian files updated --- .../vdrmanager/data/db/OrmDatabaseHelper.java | 194 --------------------- 1 file changed, 194 deletions(-) delete mode 100644 vdrmanager/src/de/bjusystems/vdrmanager/data/db/OrmDatabaseHelper.java (limited to 'vdrmanager/src/de/bjusystems') diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/OrmDatabaseHelper.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/db/OrmDatabaseHelper.java deleted file mode 100644 index 3feb8b0..0000000 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/OrmDatabaseHelper.java +++ /dev/null @@ -1,194 +0,0 @@ -package de.bjusystems.vdrmanager.data.db; - -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.util.Log; - -import com.j256.ormlite.android.AndroidCompiledStatement; -import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; -import com.j256.ormlite.dao.RuntimeExceptionDao; -import com.j256.ormlite.stmt.PreparedQuery; -import com.j256.ormlite.stmt.QueryBuilder; -import com.j256.ormlite.stmt.StatementBuilder.StatementType; -import com.j256.ormlite.support.ConnectionSource; -import com.j256.ormlite.table.TableUtils; - -import de.bjusystems.vdrmanager.data.Vdr; - -/** - * Database helper class used to manage the creation and upgrading of your - * database. This class also usually provides the DAOs used by the other - * classes. - */ -public class OrmDatabaseHelper extends OrmLiteSqliteOpenHelper { - - public static final String TAG = OrmDatabaseHelper.class.getName(); - // name of the database file for your application -- change to something - // appropriate for your app - public static final String DATABASE_NAME = "vdrmanager.db"; - // any time you make changes to your database objects, you may have to - // increase the database version - private static final int DATABASE_VERSION = 2; - - private RuntimeExceptionDao vdrDAO = null; - - public OrmDatabaseHelper(Context context) { - super(context, DATABASE_NAME, null, DATABASE_VERSION); - } - - - public static String getDataBaseFile(){ - return "/data/data/de.bjusystems.vdrmanager/databases/" + DATABASE_NAME; - } - /** - * This is called when the database is first created. Usually you should - * call createTable statements here to create the tables that will store - * your data. - */ - @Override - public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { - try { - Log.i(OrmDatabaseHelper.class.getName(), "onCreate"); - TableUtils.createTable(connectionSource, Vdr.class); - } catch (SQLException e) { - Log.e(OrmDatabaseHelper.class.getName(), "Can't create database", e); - throw new RuntimeException(e); - } - - // // here we try inserting data in the on-create as a test - // RuntimeExceptionDao dao = getSimpleDataDao(); - // long millis = System.currentTimeMillis(); - // // create some entries in the onCreate - // Note simple = new Note(); - // dao.create(simple); - // simple = new SimpleData(millis + 1); - // dao.create(simple); - // Log.i(DatabaseHelper.class.getName(), - // "created new entries in onCreate: " + millis); - } - - private List backup() throws SQLException { - List values = new ArrayList(); - Cursor c = getVdrCursor(); - try { - if (c != null && c.getCount() == 0) { - return values; - } - - c.move(-1); - - while (c.moveToNext()) { - ContentValues cv = new ContentValues(); - for (int i = 0; i < c.getColumnCount(); ++i) { - cv.put(c.getColumnName(i), c.getString(i)); - } - values.add(cv); - } - return values; - } finally { - if (c != null && c.isClosed() == false) { - c.close(); - } - } - - } - - /** - * This is called when your application is upgraded and it has a higher - * version number. This allows you to adjust the various data to match the - * new version number. - */ - @Override - public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, - int oldVersion, int newVersion) { - // try { - Log.i(TAG, "onUpgrade to " + newVersion + " from " + oldVersion); - // List b = backup(); - // Log.i(OrmDatabaseHelper.class.getName(), "backup"); - // Dao dao = getDao(Vdr.class); - // List backup = dao.queryForAll(); - // if (backup != null) { - // Log.i(OrmDatabaseHelper.class.getName(), - // "backuped " + backup.size() + " instances"); - // } - // TableUtils.dropTable(connectionSource, Vdr.class, true); - // after we drop the old databases, we create the new ones - // onCreate(db, connectionSource); - if (oldVersion == 1) { - - String alter = "ALTER TABLE vdr add livePort INTEGER"; - Log.i(TAG, "exec: " + alter); - int count = getVdrDAO().executeRaw(alter); - Log.i(TAG, "alterd " + count + " rows"); - - alter = "ALTER TABLE vdr add enableRecStreaming SMALLINT"; - Log.i(TAG, "exec: " + alter); - count = getVdrDAO().executeRaw(alter); - Log.i(TAG, "alterd " + count + " rows"); - - alter = "ALTER TABLE vdr add recStreamMethod VARCHAR"; - Log.i(TAG, "exec: " + alter); - count = getVdrDAO().executeRaw(alter); - Log.i(TAG, "alterd " + count + " rows"); - - - String update = "Update vdr set livePort = 8008, enableRecStreaming = 0, recStreamMethod = 'vdr-live'"; - Log.i(TAG, "exec: " + update); - count = getVdrDAO().executeRaw(update); - Log.i(TAG, "alterd " + count + " rows"); - } - - // if (backup != null) { - // for (Vdr v : backup) { - // dao.create(v); - // Log.i(OrmDatabaseHelper.class.getName(), - // "recovered " + v.getName()); - // } - // } - - // getVdrDAO().updateRaw(statement, arguments) - - // } catch (SQLException e) { - // Log.e(OrmDatabaseHelper.class.getName(), "Can't drop databases", e); - // throw new RuntimeException(e); - // } - } - - /** - * Returns the Database Access Object (DAO) for our Label class. It will - * create it or just give the cached value. - */ - public RuntimeExceptionDao getVdrDAO() { - if (vdrDAO == null) { - vdrDAO = getRuntimeExceptionDao(Vdr.class); - } - return vdrDAO; - } - - /** - * Close the database connections and clear any cached DAOs. - */ - @Override - public void close() { - super.close(); - vdrDAO = null; - } - - public Cursor getVdrCursor() throws SQLException { - QueryBuilder qb = getVdrDAO().queryBuilder(); - - PreparedQuery preparedQuery = qb.prepare(); - - AndroidCompiledStatement compiledStatement = (AndroidCompiledStatement) preparedQuery - .compile(getConnectionSource().getReadOnlyConnection(), - StatementType.SELECT); - - return compiledStatement.getCursor(); - } -} \ No newline at end of file -- cgit v1.2.3