데이터베이스에서 트랜잭션이란?
트랜잭션(Transaction)이란?
트랜잭션이란? 트랜잭션(Transaction 이하 트랜잭션)이란, 데이터베이스의 상태를 변화시키기 해서 수행하는 작업의 단위를 뜻한다. 데이터베이스의 상태를 변화시킨다는 것은 무얼 의미하는 것일
mommoo.tistory.com
코드
순수 SQLite
private SQLiteDatabase db;
...
try {
db.beginTransaction();
[SELECT, INSERT, UPDATE, DELETE 등 다양한 query 활동]
// 중요!! 호출해주지 않으면 데이터베이스에 반영이 되지 않음
db.setTransactionSuccessful();
} catch (Exception e) {
e.printStackTrace();
} finally {
db.endTransaction();
}
Room 라이브러리
@Dao
public abstract class ProductDao {
@Insert
public abstract void insert(Product product);
@Delete
public abstract void delete(Product product);
@Transaction
public void insertAndDeleteInTransaction(Product newProduct, Product oldProduct) {
// Anything inside this method runs in a single transaction.
insert(newProduct);
delete(oldProduct);
}
}
'Android' 카테고리의 다른 글
| [Android] Collapse와 Expand 상태에서 힌트 문자가 다른 TextInputLayout (0) | 2021.02.18 |
|---|---|
| [Android] OPEN_DOCUMENT로 가져온 Uri를 Multipart.Part로 만들기(Retrofit2 파일 업로드) (2) | 2020.10.14 |
| [Android] 개발, 디자인 및 보안 관련 사이트 북마크 (0) | 2020.09.11 |
| [Android] 삼성 파일 브라우저에서 파일 오픈시 intent-filter가 동작하지 않을 때 (0) | 2020.09.08 |
| [Android] AppCompatDelegate.setDefaultNightMode Not Working (0) | 2020.08.31 |