public void InterceptorOnFlushDirtyTest() { var auditRepo = new Mock <IAuditLogRepository>(); PersonName editingPerson = new PersonName { LastName = "LN", FirstName = "FN", MiddleName = "MN" }; AuditInterceptor interceptor = new AuditInterceptor(editingPerson); interceptor.LogRepo = auditRepo.Object; object[] currentState = new object[1] { 1 }; object[] previousState = new object[1] { 0 }; string[] propertyNames = new string[1] { "testProperty" }; var iType = new Mock <NHibernate.Type.IType>(); NHibernate.Type.IType[] types = new NHibernate.Type.IType[1] { iType.Object }; Part p = new Part(); interceptor.OnFlushDirty(p, 1, currentState, previousState, propertyNames, types); auditRepo.Verify(_ => _.Save(It.IsAny <AuditLog>()), Times.Once()); }
public void InterceptorOnSaveTest() { var auditRepo = new Mock<IAuditLogRepository>(); User editingPerson = new User(); AuditInterceptor interceptor = new AuditInterceptor(editingPerson); interceptor.LogRepo = auditRepo.Object; object [] state = new object [1] {1}; string [] propertyNames = new string [1] {"testProperty"}; var iType = new Mock<NHibernate.Type.IType>(); NHibernate.Type.IType [] types = new NHibernate.Type.IType [1] {iType.Object}; Part p = new Part(); interceptor.OnSave (p, 1, state, propertyNames, types); auditRepo.Verify(_ => _.Save(It.IsAny<AuditLog>()), Times.Once()); }
public ICriterion <T> Like(string value) { var propertyName = NHibernate.Impl.ExpressionProcessor.FindMemberExpression(_expression.Body); string sql = string.Empty; if (typeof(TValue) == typeof(string)) { sql = $"{{alias}}.{propertyName} as LikeCompare"; } else { sql = $"convert(nvarchar(max), {{alias}}.{propertyName}) as LikeCompare"; } var columnAliases = new[] { "LikeCompare" }; var types = new NHibernate.Type.IType[] { NHibernateUtil.String }; var proj = Projections.SqlProjection(sql, columnAliases, types); return(new NHibernateCriterion <T>(Restrictions.Like(proj, value))); }
public void InterceptorOnSaveTest() { var auditRepo = new Mock <IAuditLogRepository>(); User editingPerson = new User(); AuditInterceptor interceptor = new AuditInterceptor(editingPerson); interceptor.LogRepo = auditRepo.Object; object [] state = new object [1] { 1 }; string [] propertyNames = new string [1] { "testProperty" }; var iType = new Mock <NHibernate.Type.IType>(); NHibernate.Type.IType [] types = new NHibernate.Type.IType [1] { iType.Object }; Part p = new Part(); interceptor.OnSave(p, 1, state, propertyNames, types); auditRepo.Verify(_ => _.Save(It.IsAny <AuditLog>()), Times.Once()); }
public int Delete(string query, object value, NHibernate.Type.IType type) { throw new NotImplementedException(); }
/// <summary> /// 根据Metadata得到属性类型(Path以:或者.分割,如果是Collection,则返回Collection的内部Type) /// </summary> /// <param name="sessionFactory"></param> /// <param name="type"></param> /// <param name="fullPropertyName"></param> /// <param name="hasCollection"></param> /// <returns></returns> public static Type GetPropertyType(ISessionFactory sessionFactory, Type type, string fullPropertyName, out bool hasCollection) { hasCollection = false; if (string.IsNullOrEmpty(fullPropertyName)) { return(null); } string dictKey = type.ToString() + "#" + fullPropertyName; lock (s_propertyTypesHasCollection) { if (!s_propertyTypes.ContainsKey(dictKey)) { NHibernate.Metadata.IClassMetadata classMetadata = sessionFactory.GetClassMetadata(type); if (classMetadata == null) { throw new NotSupportedException("There is no Metadata of type " + type.ToString()); } NHibernate.Type.IType destType = null; Type innerType = null; NHibernate.Type.ComponentType componentType = null; string[] ss = fullPropertyName.Split(new char[] { ':', '.' }); for (int i = 0; i < ss.Length; ++i) { TryRemoveJoinTypeChar(ref ss[i]); if (componentType == null) { destType = classMetadata.GetPropertyType(ss[i]); } else { for (int j = 0; j < componentType.PropertyNames.Length; ++j) { if (componentType.PropertyNames[j] == ss[i]) { destType = componentType.Subtypes[j]; break; } } } componentType = destType as NHibernate.Type.ComponentType; if (componentType == null) { if (destType.IsCollectionType) { //System.Collections.Generic.IList`1[[Hd.Model.Jk2.进口其他业务箱, Hd.Model.Jk2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] innerType = Feng.Utils.ReflectionHelper.GetGenericUnderlyingType(destType.ReturnedClass); classMetadata = sessionFactory.GetClassMetadata(innerType); hasCollection = true; } else { classMetadata = sessionFactory.GetClassMetadata(destType.ReturnedClass); } } } if (!destType.IsCollectionType) { s_propertyTypes[dictKey] = destType.ReturnedClass; } else { s_propertyTypes[dictKey] = innerType; } s_propertyTypesHasCollection[dictKey] = hasCollection; } hasCollection = s_propertyTypesHasCollection[dictKey]; return(s_propertyTypes[dictKey]); } }
private static FieldChange CreateChange(object valueNew, object valueOld, NHibernate.Persister.Entity.IEntityPersister persister, int i) { if (valueOld == null && valueNew == null) { return(null); } NHibernate.Type.IType propType = persister.PropertyTypes[i]; string propName = persister.PropertyNames[i]; var propInfo = persister.MappedClass.GetProperty(propName); if (propInfo.GetCustomAttributes(typeof(IgnoreHistoryTraceAttribute), true).Length > 0) { return(null); } FieldChange change = null; #region Обработка в зависимости от типа данных if (propType is NHibernate.Type.StringType && !StringCompare(ref change, (string)valueOld, (string)valueNew)) { return(null); } var link = propType as NHibernate.Type.ManyToOneType; if (link != null) { if (!EntityCompare(ref change, valueOld, valueNew)) { return(null); } } if ((propType is NHibernate.Type.DateTimeType || propType is NHibernate.Type.TimestampType) && !DateTimeCompare(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.DecimalType && !DecimalCompare(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.BooleanType && !BooleanCompare(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.Int16Type && !IntCompare <Int16>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.Int32Type && !IntCompare <Int32>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.Int64Type && !IntCompare <Int64>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.UInt16Type && !IntCompare <UInt16>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.UInt32Type && !IntCompare <UInt32>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.UInt64Type && !IntCompare <UInt64>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.EnumStringType && !EnumCompare(ref change, propInfo, valueOld, valueNew)) { return(null); } #endregion if (change != null) { change.Path = propName; change.UpdateType(); return(change); } logger.Warn("Трекер не умеет сравнивать изменения в полях типа {0}. Поле {1} пропущено.", propType, propName); return(null); }
public System.Collections.IList Find(string query, object value, NHibernate.Type.IType type) { throw new NotWrappedException(); }
public System.Collections.ICollection Filter(object collection, string filter, object value, NHibernate.Type.IType type) { throw new NotWrappedException(); }
public bool NeedsUpdating(object entry, int i, NHibernate.Type.IType elemType) { throw new NotImplementedException(); }
public string GetType(NHibernate.Type.IType type) { if (type is NHibernate.Type.Int32Type) { return("int"); } if (type is NHibernate.Type.StringType) { var sqlType = ((NHibernate.Type.StringType)type).SqlType; return(string.Format("nvarchar({0})", sqlType.Length > 4000?"max":sqlType.Length.ToString())); } if (type is NHibernate.Type.BooleanType) { return("bit"); } if (type is NHibernate.Type.DateTimeType) { return("datetime"); } if (type is NHibernate.Type.DecimalType) { return("decimal"); } if (type is NHibernate.Type.DoubleType) { return("double"); } if (type is NHibernate.Type.Int64Type) { return("bitint"); } if (type is NHibernate.Type.CharType) { return("char"); } if (type is NHibernate.Type.TimestampType) { return("timestamp"); } if (type is NHibernate.Type.Int16Type) { return("tinyint"); } if (type is NHibernate.Type.XmlDocType) { return("xml"); } if (type is NHibernate.Type.BinaryType) { var sqlType = ((NHibernate.Type.StringType)type).SqlType; return(string.Format("varbinary({0})", sqlType.Length > 4000 ? "max" : sqlType.Length.ToString())); } if (type is NHibernate.Type.PersistentEnumType) { var enumType = (NHibernate.Type.PersistentEnumType)type; return(enumType.SqlType.DbType.ToString() == "Int32" ? "int" : "nvarchar(255)"); } return("未知"); }
public override void Configure(NHibernate.Type.IType type, IDictionary <string, string> parms, NHibernate.Dialect.Dialect dialect) { base.Configure(type, parms, dialect); }
public ISQLQuery AddScalar(string columnAlias, NHibernate.Type.IType type) { ApplyActionToShards(q => ((ISQLQuery)q).AddScalar(columnAlias, type)); return(this); }