Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/middleware/NextGenDB.java
Show All 13 Lines | BusTO (middleware) | ||||
You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | ||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
package it.reyboz.bustorino.middleware; | package it.reyboz.bustorino.middleware; | ||||
import android.content.ContentValues; | import android.content.ContentValues; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.content.SharedPreferences; | |||||
import android.database.Cursor; | import android.database.Cursor; | ||||
import android.database.sqlite.SQLiteConstraintException; | import android.database.sqlite.SQLiteConstraintException; | ||||
import android.database.sqlite.SQLiteDatabase; | import android.database.sqlite.SQLiteDatabase; | ||||
import android.database.sqlite.SQLiteException; | import android.database.sqlite.SQLiteException; | ||||
import android.database.sqlite.SQLiteOpenHelper; | import android.database.sqlite.SQLiteOpenHelper; | ||||
import android.provider.BaseColumns; | import android.provider.BaseColumns; | ||||
import android.support.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import android.util.Log; | import android.util.Log; | ||||
import it.reyboz.bustorino.R; | |||||
import it.reyboz.bustorino.backend.Fetcher; | |||||
import it.reyboz.bustorino.backend.FiveTAPIFetcher; | |||||
import it.reyboz.bustorino.backend.Route; | import it.reyboz.bustorino.backend.Route; | ||||
import it.reyboz.bustorino.backend.Stop; | import it.reyboz.bustorino.backend.Stop; | ||||
import org.json.JSONException; | |||||
import org.json.JSONObject; | |||||
import java.util.*; | import java.util.*; | ||||
import java.util.concurrent.atomic.AtomicInteger; | import java.util.concurrent.atomic.AtomicReference; | ||||
import static it.reyboz.bustorino.middleware.NextGenDB.Contract.*; | import static it.reyboz.bustorino.middleware.NextGenDB.Contract.*; | ||||
public class NextGenDB extends SQLiteOpenHelper{ | public class NextGenDB extends SQLiteOpenHelper{ | ||||
public static final String DATABASE_NAME = "bustodatabase.db"; | public static final String DATABASE_NAME = "bustodatabase.db"; | ||||
public static final int DATABASE_VERSION = 2; | public static final int DATABASE_VERSION = 2; | ||||
public static final String DEBUG_TAG = "NextGenDB-BusTO"; | public static final String DEBUG_TAG = "NextGenDB-BusTO"; | ||||
//NO Singleton instance | //NO Singleton instance | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | public class NextGenDB extends SQLiteOpenHelper{ | ||||
private Context appContext; | private Context appContext; | ||||
public NextGenDB(Context context) { | public NextGenDB(Context context) { | ||||
super(context, DATABASE_NAME, null, DATABASE_VERSION); | super(context, DATABASE_NAME, null, DATABASE_VERSION); | ||||
appContext = context.getApplicationContext(); | appContext = context.getApplicationContext(); | ||||
} | } | ||||
/** | |||||
* Lazy initialization singleton getter, thread-safe with double checked locking | |||||
* from https://en.wikipedia.org/wiki/Singleton_pattern | |||||
* @return the instance | |||||
*/ | |||||
/* | |||||
public static NextGenDB getInstance(Context context){ | |||||
if(instance==null){ | |||||
synchronized (NextGenDB.class){ | |||||
if(instance==null){ | |||||
instance = new NextGenDB(context); | |||||
} | |||||
} | |||||
} | |||||
return instance; | |||||
}*/ | |||||
@Override | @Override | ||||
public void onCreate(SQLiteDatabase db) { | public void onCreate(SQLiteDatabase db) { | ||||
Log.d("BusTO-AppDB","Lines creating database:\n"+SQL_CREATE_LINES_TABLE+"\n"+ | Log.d("BusTO-AppDB","Lines creating database:\n"+SQL_CREATE_LINES_TABLE+"\n"+ | ||||
SQL_CREATE_STOPS_TABLE+"\n"+SQL_CREATE_BRANCH_TABLE+"\n"+SQL_CREATE_CONNECTIONS_TABLE); | SQL_CREATE_STOPS_TABLE+"\n"+SQL_CREATE_BRANCH_TABLE+"\n"+SQL_CREATE_CONNECTIONS_TABLE); | ||||
db.execSQL(SQL_CREATE_LINES_TABLE); | db.execSQL(SQL_CREATE_LINES_TABLE); | ||||
db.execSQL(SQL_CREATE_STOPS_TABLE); | db.execSQL(SQL_CREATE_STOPS_TABLE); | ||||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | public static final class Contract{ | ||||
} | } | ||||
} | } | ||||
public static final class DBUpdatingException extends Exception{ | public static final class DBUpdatingException extends Exception{ | ||||
public DBUpdatingException(String message) { | public DBUpdatingException(String message) { | ||||
super(message); | super(message); | ||||
} | } | ||||
} | } | ||||
} | } |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register