android SQLiteDatabase源码解析

本文详细探讨了Android中SQLiteClosable接口在SQLite数据库操作中的作用,通过源码分析,揭示了其在资源管理、关闭操作以及防止内存泄漏等方面的关键实现。通过对SQLiteCursor、SQLiteStatement等类的源码解析,理解数据库操作的底层机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

	源于包android.database.sqlite.SQLiteDatabase
	首先看一下继承和实现了那些基类和接口
			SQLiteDatabase extends SQLiteClosable  implements Closeable 
	Closeable extends AutoCloseable

interface   AutoCloseable //java. lang
void close() throws Exception;
Defines an interface for classes that can (or need to) be closed once they
* are not used any longer. Calling the {@code close} method releases resources
* that the object holds.
一旦不用回收释放资源,关闭资源
interface Closeable extends AutoCloseable   //java.io
void close() throws IOException;
Closeable 是可以关闭的数据源或目标。调用 close 方法可释放对象保存的资源(如打开文件)
关闭此流并释放与此流关联的所有系统资源。如果已经关闭该流,则调用此方法无效。
abstract class SQLiteClosable implements Closeable //  抽象类
abstract void onAllReferencesReleased();//
void onAllReferencesReleasedFromContainer()
void acquireReference()
void releaseReference()
void releaseReferenceFromContainer()
public void close() {
    releaseReference();//实现Closeable的方法
}


final class SQLiteDatabase 
public static SQLiteDatabase openDatabase(String path, CursorFactory factory, int flags) {
    return openDatabase(path, factory, flags, null);
}
public static SQLiteDatabase openDatabase(String path, CursorFactory factory, int flags,
        DatabaseErrorHandler errorHandler) {//路径    cuesor构造器,传null使用默认构造器 
    SQLiteDatabase db = new SQLiteDatabase(path, flags, factory, errorHandler);
    db.open();
    return db;
}
public static boolean deleteDatabase(File file) //删除数据库
public void reopenReadWrite()
public Cursor query(boolean distinct, String table, String[] columns,
        String selection, String[] selectionArgs, String groupBy,
        String having, String orderBy, String limit) {
    return queryWithFactory(null, distinct, table, columns, selection, selectionArgs,
            groupBy, having, orderBy, limit, null);
}








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值