init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
using Zhaizj.Framework;
|
||||
using Zhaizj.Framework.Data;
|
||||
using Zhaizj.Framework.Reflection;
|
||||
using Zhaizj.Framework.ORM.Caching;
|
||||
|
||||
namespace Zhaizj.Framework.ORM {
|
||||
|
||||
internal class CacheUtil {
|
||||
|
||||
private static readonly ILog logger = LogManager.GetLogger( typeof( CacheUtil ) );
|
||||
|
||||
public static void CheckCountCache( String action, IEntity obj, EntityInfo entityInfo ) {
|
||||
|
||||
for (int i = 0; i < entityInfo.SavedPropertyList.Count; i++) {
|
||||
IEntity container = null;
|
||||
String propertyName = null;
|
||||
EntityPropertyInfo info = entityInfo.SavedPropertyList[i];
|
||||
if ((info.Name != "Id") && !(info.Name == "OID")) {
|
||||
ICacheAttribute attribute = ReflectionUtil.GetAttribute( info.Property, typeof( CacheCountAttribute ) ) as ICacheAttribute;
|
||||
if (attribute != null) {
|
||||
container = ReflectionUtil.GetPropertyValue( obj, info.Name ) as IEntity;
|
||||
propertyName = attribute.TargetPropertyName.Replace( " ", "" );
|
||||
}
|
||||
if (container != null) {
|
||||
String columnName = Entity.GetInfo( container ).GetColumnName( propertyName );
|
||||
setCountCacheBySql( container, columnName, action );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCountCacheBySql( IEntity container, String columName, String action ) {
|
||||
|
||||
EntityInfo et = Entity.GetInfo( container );
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append( "update " );
|
||||
builder.Append( et.TableName );
|
||||
builder.Append( " set " );
|
||||
builder.Append( columName );
|
||||
builder.Append( "=" );
|
||||
builder.Append( columName );
|
||||
if (action.ToLower() == "insert") {
|
||||
builder.Append( "+1" );
|
||||
}
|
||||
else {
|
||||
builder.Append( "-1" );
|
||||
}
|
||||
builder.AppendFormat( " where id={0}", container.Id );
|
||||
DataFactory.GetCommand( builder.ToString(), DbContext.getConnection( et ) ).ExecuteNonQuery();
|
||||
logger.Debug( "set counter cache : " + builder.ToString() );
|
||||
|
||||
CacheTime.updateTable( et.Type );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user