Refine database package
This commit is contained in:
@@ -23,11 +23,11 @@ package com.github.shadowsocks.database
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
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.github.shadowsocks.ShadowsocksApplication.app
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.collection.mutable
|
||||
@@ -55,12 +55,16 @@ class DBHelper(val context: Context)
|
||||
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,
|
||||
newVersion: Int) {
|
||||
if (oldVersion != newVersion) {
|
||||
if (oldVersion < 7) {
|
||||
profileDao.executeRawNoArgs("DROP TABLE IF EXISTS 'profile';")
|
||||
onCreate(database, connectionSource)
|
||||
recreate(database, connectionSource)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -132,8 +136,7 @@ class DBHelper(val context: Context)
|
||||
} catch {
|
||||
case ex: Exception =>
|
||||
app.track(ex)
|
||||
profileDao.executeRawNoArgs("DROP TABLE IF EXISTS 'profile';")
|
||||
onCreate(database, connectionSource)
|
||||
recreate(database, connectionSource)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.j256.ormlite.field.{DataType, DatabaseField}
|
||||
|
||||
class Profile {
|
||||
@DatabaseField(generatedId = true)
|
||||
var id: Int = 0
|
||||
var id: Int = _
|
||||
|
||||
@DatabaseField
|
||||
var name: String = ""
|
||||
@@ -59,28 +59,28 @@ class Profile {
|
||||
var remoteDns: String = "8.8.8.8"
|
||||
|
||||
@DatabaseField
|
||||
var proxyApps: Boolean = false
|
||||
var proxyApps: Boolean = _
|
||||
|
||||
@DatabaseField
|
||||
var bypass: Boolean = false
|
||||
var bypass: Boolean = _
|
||||
|
||||
@DatabaseField
|
||||
var udpdns: Boolean = false
|
||||
var udpdns: Boolean = _
|
||||
|
||||
@DatabaseField
|
||||
var auth: Boolean = false
|
||||
var auth: Boolean = _
|
||||
|
||||
@DatabaseField
|
||||
var ipv6: Boolean = false
|
||||
var ipv6: Boolean = _
|
||||
|
||||
@DatabaseField(dataType = DataType.LONG_STRING)
|
||||
var individual: String = ""
|
||||
|
||||
@DatabaseField
|
||||
var tx: Long = 0
|
||||
var tx: Long = _
|
||||
|
||||
@DatabaseField
|
||||
var rx: Long = 0
|
||||
var rx: Long = _
|
||||
|
||||
@DatabaseField
|
||||
val date: java.util.Date = new java.util.Date()
|
||||
@@ -89,7 +89,7 @@ class Profile {
|
||||
var userOrder: Long = _
|
||||
|
||||
@DatabaseField
|
||||
var kcp: Boolean = false
|
||||
var kcp: Boolean = _
|
||||
|
||||
@DatabaseField
|
||||
var kcpPort: Int = 8399
|
||||
|
||||
Reference in New Issue
Block a user