This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.arch.persistence.room.Database; | |
import android.arch.persistence.room.RoomDatabase; | |
@Database(version = 3, entities = { | |
TokenEntity.class | |
}) | |
public abstract class MyDatabsae extends RoomDatabase { | |
public abstract TokenDao tokenDao(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.arch.persistence.room.Dao; | |
import android.arch.persistence.room.Insert; | |
import android.arch.persistence.room.OnConflictStrategy; | |
import android.arch.persistence.room.Query; | |
@Dao | |
public interface ApiTokenDao { | |
@Query("SELECT * FROM token LIMIT 1") | |
TokenEntity getToken(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.arch.persistence.room.ColumnInfo; | |
import android.arch.persistence.room.Entity; | |
import android.arch.persistence.room.PrimaryKey; | |
@Entity(tableName = "token") | |
public class TokenEntity { | |
@PrimaryKey(autoGenerate = true) | |
public int id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.database.sqlite.SQLiteDatabase; | |
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 java.sql.SQLException; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface TokenDao { | |
TokenEntity get(); | |
void save(TokenEntity token); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
public final class TokenDaoImpl implements TokenDao { | |
private MyDatabase db; | |
@Inject public TokenDaoImpl(MyDatabase database) { | |
this.db = database; | |
} | |
@Override public synchronized TokenEntity get() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.j256.ormlite.field.DatabaseField; | |
import com.j256.ormlite.table.DatabaseTable; | |
@DatabaseTable(tableName = "token") | |
public final class TokenEntity { | |
@DatabaseField(id = true) public String id; | |
@DatabaseField public String apiToken; | |
public TokenEntity() { |