KeyAccess 是一个轻量级的对象关系映射框架(ORM),利用现有数据库生成对象模型。
示例代码:
// All artists List artists = Artist.queryObjects(conn);
// Artists with a good rating List newArtists = Artist.queryObjects(conn, “rating > 4”);
// Get the number of classical albums int numClassicalAlbums = Album.queryCount(conn, “type = ‘CLASSICAL’ “);
// Load single object by one or more primary keys (vararg) Artist artist = Artist.queryObjectByKey(conn, 294);
// Load all objects, but not into a list: call a callback function for each object instead. // This can dramatically reduce memory requirements if you need to process // thousands of objects. There is also a version available where you can // supply a where clause. Artist.queryObjects(conn, new IObjectLoadHandler() { public void onLoad(Object obj) { System.out.println(“Artist: “+ ((Artist)obj).getName()); } });