using System;
using System.Collections;
using System.Collections.Generic;
using Zhaizj.Framework.ORM;
namespace Zhaizj.Framework.Data {
///
/// 缓存对象,常驻内存,同时以json格式存储在磁盘中
///
[Serializable]
public class CacheObject {
private int _id;
private String _name;
///
/// 对象的 id
///
public int Id {
get { return _id; }
set { _id = value; }
}
///
/// 对象名称
///
public String Name {
get { return _name; }
set { _name = value; }
}
///
/// 根据 id 检索对象
///
///
///
public CacheObject findById( int id ) {
return MemoryDB.FindById( this.GetType(), id );
}
///
/// 检索出所有对象
///
///
public IList findAll() {
return MemoryDB.FindAll( this.GetType() );
}
///
/// 根据名称检索出对象列表
///
///
///
public IList findByName( String name ) {
return this.findBy( "Name", name );
}
///
/// 根据属性名,检索出对象
///
///
///
///
public IList findBy( String propertyName, Object val ) {
findAll();
return MemoryDB.FindBy( this.GetType(), propertyName, val );
}
///
/// 插入数据:并对所有属性做索引,速度较慢
///
public void insert() {
MemoryDB.Insert( this );
}
///
/// 插入数据:只针对特定属性做索引,提高速度
///
///
///
public void insertByIndex( String propertyName, Object pValue ) {
MemoryDB.InsertByIndex( this, propertyName, pValue );
}
///
/// 插入数据:针对若干属性做索引
///
///
public void insertByIndex( Dictionary dic ) {
MemoryDB.InsertByIndex( this, dic );
}
///
/// 更新数据
///
///
public Result update() {
return MemoryDB.Update( this );
}
///
/// 更新数据:只针对特性数据做索引
///
///
public void updateByIndex( Dictionary dic ) {
MemoryDB.updateByIndex( this, dic );
}
///
/// 不持久化,也不做索引
///
///
public Result updateNoIndex() {
return new Result();
}
///
/// 删除数据
///
public void delete() {
MemoryDB.Delete( this );
}
}
}