Code example for SQLiteDatabase

Methods: closebeginTransactioncompileStatementendTransactionisOpen

0
	} 
 
	public DataManager(Context context, boolean useDebugDb) {
		this.context = context;
		this.useDebugDb = useDebugDb;
	} 
 
	private boolean isOpenDb() { 
		return (db != null && db.isOpen());
	} 
 
	private boolean closeDb() { 
		if (isOpenDb()) { 
			try { 
				db.close();
				 
				db = null;
				rpgCharacterDao = null;
				 
				return true; 
			} catch (SQLiteException e) {
				// Log.w("DataManager", e.getMessage()); 
			} 
		} 
 
		return false; 
	} 
 
	private boolean openDb() { 
		if (!isOpenDb()) { 
			db = new OpenHelper(context, useDebugDb).getWritableDatabase();
 
			// since we pass db into DAO, have to recreate DAO if db is 
			// re-opened 
			rpgCharacterDao = new RpgCharacterDAO(db);
 
			return true; 
		} 
 
		return false; 
	} 
 
	// Match operations 
 
	public Long saveRpgCharacter(RpgCharacter rpgCharacter) {
		long matchId = 0L;
 
		if (rpgCharacter == null) {
			return matchId;
		} 
 
		try { 
			openDb(); 
			db.beginTransaction();
			matchId = rpgCharacterDao.save(rpgCharacter);
			db.setTransactionSuccessful();
 
		} catch (SQLException e) {
			Log.e("ERROR", "DataManager - saveRpgCharacter - Error saving match (" + rpgCharacter.toString() + ")", e);
			matchId = 0L;
		} finally { 
			db.endTransaction();
			closeDb(); 
		} 
 
		return matchId;
	} 
Stop searching for code, let great code find you!  Add Codota to your java IDE