JDBM中提供了一个接口RecordManager,用于对记录进行操作:
public abstract long insert( Object obj )
throws IOException;
/**
* Inserts a new record using a custom serializer.
*/
public abstract long insert( Object obj, Serializer serializer )
throws IOException;
/**
* Deletes a record.
*/
public abstract void delete( long recid )
throws IOException;
/**
* Updates a record using standard java object serialization.
*/
public abstract void update( long recid, Object obj )
throws IOException;
/**
* Updates a record using a custom serializer.
*/
public abstract void update( long recid, Object obj, Serializer serializer )
throws IOException;
/**
* Fetches a record using standard java object serialization.
*/
public abstract Object fetch( long recid )
throws IOException;
/**
* Fetches a record using a custom serializer.
*/
public abstract Object fetch( long recid, Serializer serializer )
throws IOException;
/**
* Closes the record manager.
*/
public abstract void close()
throws IOException;
具体的实现类一共两个:BaseRecordManager和CacheRecordManager,后者是前者的Cache。BaseRecordManager用于将缓存对象序列化到文件系统中,即缓存对象管理主要是文件读取方面的操作,而CacheRecordManager
对读取的文件进行了缓存,较少IO的次数提高效率。
BaseRecordManager
BaseRecordManager有四个主要的变量
/**
* Underlying record file.
*/
private RecordFile _file;
/**
* Physical row identifier manager.
*/
private PhysicalRowIdManager _physMgr;
/**
* Logigal to Physical row identifier manager.
*/
private LogicalRowIdManager _logMgr;
/**
* Page manager.
*/
private PageManager _pageman;
没有看其实现代码,但是从其构造函数可以看出一些端倪:
public BaseRecordManager( String filename )
throws IOException
{
_file = new RecordFile( filename );
_pageman = new PageManager( _file );
_physMgr = new PhysicalRowIdManager( _file, _pageman );
_logMgr = new LogicalRowIdManager( _file, _pageman );
}
jdbm.recman主要都是关于Page,PhysicalRow和LogicalRow这些相关类。