Commit 2edc14a6 authored by Mygod's avatar Mygod

Refine database package

parent bc94adef
...@@ -23,11 +23,11 @@ package com.github.shadowsocks.database ...@@ -23,11 +23,11 @@ package com.github.shadowsocks.database
import android.content.Context import android.content.Context
import android.content.pm.ApplicationInfo import android.content.pm.ApplicationInfo
import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteDatabase
import com.github.shadowsocks.ShadowsocksApplication.app
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
import com.j256.ormlite.dao.Dao import com.j256.ormlite.dao.Dao
import com.j256.ormlite.support.ConnectionSource import com.j256.ormlite.support.ConnectionSource
import com.j256.ormlite.table.TableUtils import com.j256.ormlite.table.TableUtils
import com.github.shadowsocks.ShadowsocksApplication.app
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
import scala.collection.mutable import scala.collection.mutable
...@@ -55,12 +55,16 @@ class DBHelper(val context: Context) ...@@ -55,12 +55,16 @@ class DBHelper(val context: Context)
TableUtils.createTable(connectionSource, classOf[Profile]) TableUtils.createTable(connectionSource, classOf[Profile])
} }
def recreate(database: SQLiteDatabase, connectionSource: ConnectionSource) {
TableUtils.dropTable(connectionSource, classOf[Profile], true)
onCreate(database, connectionSource)
}
def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int, def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int,
newVersion: Int) { newVersion: Int) {
if (oldVersion != newVersion) { if (oldVersion != newVersion) {
if (oldVersion < 7) { if (oldVersion < 7) {
profileDao.executeRawNoArgs("DROP TABLE IF EXISTS 'profile';") recreate(database, connectionSource)
onCreate(database, connectionSource)
return return
} }
...@@ -132,8 +136,7 @@ class DBHelper(val context: Context) ...@@ -132,8 +136,7 @@ class DBHelper(val context: Context)
} catch { } catch {
case ex: Exception => case ex: Exception =>
app.track(ex) app.track(ex)
profileDao.executeRawNoArgs("DROP TABLE IF EXISTS 'profile';") recreate(database, connectionSource)
onCreate(database, connectionSource)
return return
} }
} }
......
...@@ -31,7 +31,7 @@ import com.j256.ormlite.field.{DataType, DatabaseField} ...@@ -31,7 +31,7 @@ import com.j256.ormlite.field.{DataType, DatabaseField}
class Profile { class Profile {
@DatabaseField(generatedId = true) @DatabaseField(generatedId = true)
var id: Int = 0 var id: Int = _
@DatabaseField @DatabaseField
var name: String = "" var name: String = ""
...@@ -59,28 +59,28 @@ class Profile { ...@@ -59,28 +59,28 @@ class Profile {
var remoteDns: String = "8.8.8.8" var remoteDns: String = "8.8.8.8"
@DatabaseField @DatabaseField
var proxyApps: Boolean = false var proxyApps: Boolean = _
@DatabaseField @DatabaseField
var bypass: Boolean = false var bypass: Boolean = _
@DatabaseField @DatabaseField
var udpdns: Boolean = false var udpdns: Boolean = _
@DatabaseField @DatabaseField
var auth: Boolean = false var auth: Boolean = _
@DatabaseField @DatabaseField
var ipv6: Boolean = false var ipv6: Boolean = _
@DatabaseField(dataType = DataType.LONG_STRING) @DatabaseField(dataType = DataType.LONG_STRING)
var individual: String = "" var individual: String = ""
@DatabaseField @DatabaseField
var tx: Long = 0 var tx: Long = _
@DatabaseField @DatabaseField
var rx: Long = 0 var rx: Long = _
@DatabaseField @DatabaseField
val date: java.util.Date = new java.util.Date() val date: java.util.Date = new java.util.Date()
...@@ -89,7 +89,7 @@ class Profile { ...@@ -89,7 +89,7 @@ class Profile {
var userOrder: Long = _ var userOrder: Long = _
@DatabaseField @DatabaseField
var kcp: Boolean = false var kcp: Boolean = _
@DatabaseField @DatabaseField
var kcpPort: Int = 8399 var kcpPort: Int = 8399
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment