using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Script.Serialization;
using System.Xml.Serialization;
using NewLife;
using NewLife.Data;
using NewLife.Log;
using NewLife.Model;
using NewLife.Reflection;
using NewLife.Threading;
using NewLife.Web;
using XCode;
using XCode.Cache;
using XCode.Configuration;
using XCode.DataAccessLayer;
namespace XCode.Sharding
{
/// <summary>分片</summary>
public partial class Shard : Entity<Shard>
{
#region 对象æ“作
static Shard()
{
// ç´¯åŠ å—å…¸
//Meta.Factory.AdditionalFields.Add(__.Logins);
// 过滤器
//Meta.Modules.Add<UserModule>();
//Meta.Modules.Add<TimeModule>();
//Meta.Modules.Add<IPModule>();
}
/// <summary>验è¯æ•°æ®ï¼Œé€šè¿‡æŠ›å‡ºå¼‚常的方å¼æ示验è¯å¤±è´¥ã€‚</summary>
/// <param name="isNew">是å¦æ’å…¥</param>
public override void Valid(Boolean isNew)
{
// 如果没有è„æ•°æ®ï¼Œåˆ™ä¸éœ€è¦è¿›è¡Œä»»ä½•å¤„ç†
if (!HasDirty) return;
// 这里验è¯å‚数范围,建议抛出å‚数异常,指定å‚æ•°å,å‰ç«¯ç”¨æˆ·ç•Œé¢å¯ä»¥æ•èŽ·å‚数异常并èšç„¦åˆ°å¯¹åº”çš„å‚数输入框
if (String.IsNullOrEmpty(Name)) throw new ArgumentNullException(nameof(Name), "å称ä¸èƒ½ä¸ºç©ºï¼");
// 建议先调用基类方法,基类方法会对唯一索引的数æ®è¿›è¡ŒéªŒè¯
base.Valid(isNew);
// 在新æ’入数æ®æˆ–者修改了指定å—段时进行修æ£
// 处ç†å½“å‰å·²ç™»å½•ç”¨æˆ·ä¿¡æ¯
//var user = ManageProvider.User;
//if (user != null)
{
//if (isNew && !Dirtys[nameof(CreateUserID)) CreateUserID = user.ID;
//if (!Dirtys[nameof(UpdateUserID)]) UpdateUserID = user.ID;
}
//if (isNew && !Dirtys[nameof(CreateTime)]) CreateTime = DateTime.Now;
//if (!Dirtys[nameof(UpdateTime)]) UpdateTime = DateTime.Now;
//if (isNew && !Dirtys[nameof(CreateIP)]) CreateIP = WebHelper.UserHost;
//if (!Dirtys[nameof(UpdateIP)]) UpdateIP = WebHelper.UserHost;
}
///// <summary>首次连接数æ®åº“æ—¶åˆå§‹åŒ–æ•°æ®ï¼Œä»…用于实体类é‡è½½ï¼Œç”¨æˆ·ä¸åº”该调用该方法</summary>
//[EditorBrowsable(EditorBrowsableState.Never)]
//protected override void InitData()
//{
// // InitData一般用于当数æ®è¡¨æ²¡æœ‰æ•°æ®æ—¶æ·»åŠ 一些默认数æ®ï¼Œè¯¥å®žä½“类的任何第一次数æ®åº“æ“作都会触å‘该方法,默认异æ¥è°ƒç”¨
// if (Meta.Count > 0) return;
// if (XTrace.Debug) XTrace.WriteLine("开始åˆå§‹åŒ–Shard[分片]æ•°æ®â€¦â€¦");
// var entity = new Shard();
// entity.ID = 0;
// entity.Name = "abc";
// entity.EntityType = "abc";
// entity.ConnName = "abc";
// entity.TableName = "abc";
// entity.CreateUserID = 0;
// entity.CreateIP = "abc";
// entity.CreateTime = DateTime.Now;
// entity.UpdateUserID = 0;
// entity.UpdateIP = "abc";
// entity.UpdateTime = DateTime.Now;
// entity.Remark = "abc";
// entity.Insert();
// if (XTrace.Debug) XTrace.WriteLine("完æˆåˆå§‹åŒ–Shard[分片]æ•°æ®ï¼"
//}
///// <summary>å·²é‡è½½ã€‚基类先调用Valid(true)验è¯æ•°æ®ï¼Œç„¶åŽåœ¨äº‹åŠ¡ä¿æŠ¤å†…调用OnInsert</summary>
///// <returns></returns>
//public override Int32 Insert()
//{
// return base.Insert();
//}
///// <summary>å·²é‡è½½ã€‚在事务ä¿æŠ¤èŒƒå›´å†…处ç†ä¸šåŠ¡ï¼Œä½äºŽValid之åŽ</summary>
///// <returns></returns>
//protected override Int32 OnDelete()
//{
// return base.OnDelete();
//}
#endregion
#region 扩展属性
#endregion
#region 扩展查询
/// <summary>æ ¹æ®ç¼–å·æŸ¥æ‰¾</summary>
/// <param name="id">ç¼–å·</param>
/// <returns>实体对象</returns>
public static Shard FindByID(Int32 id)
{
if (id <= 0) return null;
if (Meta.Count >= 1000)
return Find(__.ID, id);
else // 实体缓å˜
return Meta.Cache.Entities.Find(__.ID, id);
// 实体缓å˜
//return Meta.SingleCache[id];
}
/// <summary>æ ¹æ®å称查找</summary>
/// <param name="name">å称</param>
/// <returns>实体对象</returns>
public static EntityList<Shard> FindByName(String name)
{
if (Meta.Count >= 1000)
return FindAll(__.Name, name);
else // 实体缓å˜
return Meta.Cache.Entities.FindAll(__.Name, name);
}
/// <summary>æ ¹æ®å®žä½“类查找</summary>
/// <param name="entitytype">实体类</param>
/// <returns>实体对象</returns>
public static EntityList<Shard> FindByEntityType(String entitytype)
{
if (Meta.Count >= 1000)
return FindAll(__.EntityType, entitytype);
else // 实体缓å˜
return Meta.Cache.Entities.FindAll(__.EntityType, entitytype);
}
#endregion
#region 高级查询
#endregion
#region 业务æ“作
#endregion
}
}
|