protected override string GetParameterName(IPropertyMap propertyMap, string prefix) { string name = prefix; name = name + propertyMap.Name; name = ":" + name + GetNextParamNr().ToString() ; return name; }
public virtual void NotifyPropertyLoad(object obj, IPropertyMap propertyMap, object value) { if (propertyMap.NoInverseManagement) return; if (propertyMap.ReferenceType == ReferenceType.None) return; if (!(propertyMap.Inverse.Length > 0)) return; IPropertyMap invPropertyMap = propertyMap.MustGetInversePropertyMap(); if (invPropertyMap == null) return; if (propertyMap.ReferenceType == ReferenceType.ManyToMany) { HandleManyManyPropertyLoad(obj, propertyMap, invPropertyMap, (IList) value); } if (propertyMap.ReferenceType == ReferenceType.ManyToOne) { HandleManyOnePropertyLoad(obj, propertyMap, invPropertyMap, (IList) value); } if (propertyMap.ReferenceType == ReferenceType.OneToMany) { HandleOneManyPropertyLoad(obj, propertyMap, invPropertyMap, value); } if (propertyMap.ReferenceType == ReferenceType.OneToOne) { HandleOneOnePropertyLoad(obj, propertyMap, invPropertyMap, value); } }
public virtual IList CloneList(object obj, IPropertyMap propertyMap, IList orgList) { Type t = obj.GetType() ; Type listType = t.GetProperty(propertyMap.Name).PropertyType; IList newList = Context.ProxyFactory.CreateListProxy(listType,Context.ObjectFactory,new object[0] ) ; IInterceptableList mList; bool stackMute = false; mList = newList as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; mList.Interceptable = (IInterceptable) obj; mList.PropertyName = propertyMap.Name; } foreach (object item in orgList) { newList.Add(item); } if (mList != null) { mList.MuteNotify = stackMute; } return newList; }
public virtual SqlColumnAlias GetPropertyColumn(IPropertyMap propertyMap, object hash) { if (hash == null) { hash = propertyMap; } SqlTableAlias tbl = sqlEmitter.GetTableAlias(propertyMap.MustGetTableMap(), hash) ; IColumnMap columnMap = propertyMap.GetColumnMap(); return tbl.GetSqlColumnAlias(columnMap); }
public void ChangeOperator(Func<IDbConnection, IDbTransaction,object, object> action, IDbContext context, dynamic entity,IPropertyMap map=null) { OperatorInfo item = new OperatorInfo { func = action, Context = context, entity = entity, Map = map }; this.list.Add(item); }
public SqlEmitter(INPathEngine npathEngine, NPathSelectQuery query,NPathQueryType queryType, IClassMap rootClassMap,SqlSelectStatement parentQuery,IPropertyMap backReference,int subQueryLevel) { this.npathEngine = npathEngine; this.query = query; this.rootClassMap = rootClassMap; propertyPathTraverser = new PropertyPathTraverser(this); this.propertyColumnMap = new Hashtable() ; this.npathQueryType = queryType; this.parentQuery = parentQuery; this.backReference = backReference; this.subQueryLevel = subQueryLevel; }
public static void GenerateDLinqField(IClassMap classMap, IPropertyMap propertyMap, CodeTypeDeclaration classDecl) { switch (propertyMap.ReferenceType) { case ReferenceType.None : classDecl.Members.Add(GenerateDLinqPrimitiveField(classMap, propertyMap)); break; case ReferenceType.OneToMany : GenerateDLinqOneToManyFields(classMap, propertyMap, classDecl); break; } }
public ObjectTreeNode(IContext context, object obj, object referencedByObj, IPropertyMap referencedByPropertyMap) { this.context = context; this.obj = obj; this.ClassMap = context.DomainMap.MustGetClassMap(obj.GetType() ); this.referencedByObj = referencedByObj; this.referencedByClassMap = context.DomainMap.MustGetClassMap(ReferencedByObj.GetType() ); this.referencedByPropertyMap = referencedByPropertyMap; this.Nodes.Add(new TreeNode() ); SetText(); this.ImageIndex = 0; this.SelectedImageIndex = 0; }
/// <summary> /// Generates the property. /// </summary> /// <param name="file">The file.</param> /// <param name="property">The property.</param> /// <param name="isReadOnly">if set to <c>true</c> the readonly property is generated.</param> public static void GenerateProperty(StreamWriter file, IPropertyMap property, bool isReadOnly) { string fieldType = ConvertColumnTypeToCsType(property.GetColumnMap().DataType); string fieldName = GetFieldName(property); file.WriteLine("\t\tpublic " + fieldType + " " + property.Name); file.WriteLine("\t\t{"); file.WriteLine("\t\t\tget { return " + fieldName + "; }"); if (!isReadOnly) { file.WriteLine("\t\t\tset { " + fieldName + " = value; }"); } file.WriteLine("\t\t}"); }
private string BuildObjectIdentity(object obj, IPropertyMap newPropertyMap, object newValue) { string id = ""; IClassMap classMap = m_ObjectManager.Context.DomainMap.MustGetClassMap(obj.GetType()); string sep = classMap.IdentitySeparator; // bool gotObjectStatus = false; // ObjectStatus objStatus = ObjectStatus.Clean; if (sep == "") { sep = "|"; } object value; foreach (IPropertyMap propertyMap in classMap.GetIdentityPropertyMaps()) { if (propertyMap == newPropertyMap) { value = newValue; if (propertyMap.ReferenceType != ReferenceType.None) { value = m_ObjectManager.GetObjectIdentity(value); } } else { value = m_ObjectManager.GetPropertyValue(obj, propertyMap.Name); if (value == null || m_ObjectManager.GetNullValueStatus(obj, propertyMap.Name) == true) { if (!(m_hashTempIds.ContainsKey(obj))) { m_hashTempIds[obj] = Guid.NewGuid().ToString(); } return (string)m_hashTempIds[obj]; } else if (propertyMap.ReferenceType != ReferenceType.None) { //this ensures that a complete id can be created ahead in case of auto-in //m_ObjectManager.GetPropertyValue(obj, propertyMap.Name); value = m_ObjectManager.GetObjectIdentity(value); } } id += Convert.ToString(value) + sep; } if (id.Length > sep.Length) { id = id.Substring(0, id.Length - sep.Length); } return id; }
/* private System.Nullable<int> _ReportsTo; private EntityRef<Employee> _ReportsToEmployee; * */ public static void GenerateDLinqOneToManyFields(IClassMap classMap, IPropertyMap propertyMap, CodeTypeDeclaration classDecl) { foreach (IColumnMap columnMap in propertyMap.GetAllColumnMaps()) { string fieldName = propertyMap.GenerateMemberName(columnMap.Name); CodeMemberField fieldMember = new CodeMemberField() ; fieldMember.Name = fieldName; //Add code for adding Nullable generics when OM is ported to .NET 2.0 CodeTypeReference typeReference = new CodeTypeReference(columnMap.GetSystemType()); fieldMember.Type = typeReference; classDecl.Members.Add(fieldMember); } }
public void SetupJoin(IPropertyMap propertyMap, IPropertyMap parentMap, string propertyPath, JoinType joinType) { TableJoin tableJoin = GetTableJoinForPropertyPath(propertyPath); if (tableJoin == null) { tableJoin = new TableJoin(); tableJoin.PropertyMap = propertyMap; tableJoin.JoinType = joinType; if (parentMap == null) { tableJoin.JoinTree = this; this.propertyPathTraverser.SqlEmitter.GetTableAlias(propertyMap.MustGetTableMap(), propertyMap); } else { //make sure the table has an alias tableJoin.Parent = GetTableJoinForPropertyPath(propertyPath.Substring(0, propertyPath.Length - propertyMap.Name.Length - 1)); this.propertyPathTraverser.SqlEmitter.GetTableAlias(propertyMap.MustGetTableMap(), tableJoin.Parent); } } }
public virtual ValidationMode GetValidationMode(IClassMap classMap, IPropertyMap propertyMap) { ValidationMode validationMode = propertyMap.ValidationMode; if (validationMode == ValidationMode.Default) { validationMode = classMap.ValidationMode; if (validationMode == ValidationMode.Default) { validationMode = classMap.DomainMap.ValidationMode; if (validationMode == ValidationMode.Default) { validationMode = this.Context.ValidationMode; if (validationMode == ValidationMode.Default) { validationMode = ValidationMode.ValidateLoaded; } } } } return validationMode; }
public ObjectPropertyDescriptor(MemberDescriptor descr, IContext context, IPropertyMap propertyMap, object obj, Attribute[] attrs) : base(descr, attrs) { this.realPropertyDescriptor = (PropertyDescriptor) descr; this.name = propertyMap.Name; this.displayName = propertyMap.Name; Attribute[] attribs = new Attribute[descr.Attributes.Count + 4]; int i = 0; foreach (Attribute attrib in descr.Attributes) { attribs[i] = attrib; i++; } attribs[i] = new DescriptionAttribute(propertyMap.Name + " is a property."); attribs[i + 1] = new CategoryAttribute(""); attribs[i + 2] = new DefaultValueAttribute(context.ObjectManager.GetOriginalPropertyValue(obj, propertyMap.Name)); attribs[i + 3] = new ReadOnlyAttribute(propertyMap.IsReadOnly); attributes = new AttributeCollection(attribs); }
/// <summary> /// Fetches a FieldInfo for a specific property in a given type /// </summary> /// <param name="propertyMap"></param> /// <param name="type"></param> /// <param name="propertyName"></param> /// <returns></returns> //[DebuggerStepThrough()] public static FieldInfo GetFieldInfo(IPropertyMap propertyMap, Type type, string propertyName) { Hashtable fieldLookup = FieldLookup(type); if (fieldLookup != null) { if (!fieldLookup.ContainsKey(propertyName)) { FieldInfo fieldInfo = type.GetField(propertyMap.GetFieldName(), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); if (fieldInfo == null) //field was not found in this type fieldInfo = GetFieldInfo(propertyMap, type.BaseType, propertyName); //fetch the field from the base class lock(syncRoot) { if (!fieldLookup.ContainsKey(propertyName)) { fieldLookup.Add(propertyName, fieldInfo); //cache the field info with this type , even if the field was found in a super class } } } return fieldLookup[propertyName] as FieldInfo; } return null; }
protected virtual void HandleSlaveManyOnePropertySet(object obj, IPropertyMap propertyMap, IList newList, IList oldList) { this.Context.LogManager.Info(this, "Managing inverse many-one property relationship synchronization", "Writing to object of type: " + obj.GetType().ToString() + ", Property: " + propertyMap.Name); // do not localize IPropertyMap invPropertyMap = propertyMap.GetInversePropertyMap(); if (invPropertyMap == null) { return; } ArrayList added = GetListDiff(oldList, newList); ArrayList removed = GetListDiff(newList, oldList); IObjectManager om = this.Context.ObjectManager; IUnitOfWork uow = this.Context.UnitOfWork; IList list; IInterceptableList mList; object value; object oldObj; bool stackMute = false; foreach (object iValue in added) { value = iValue; om.EnsurePropertyIsLoaded(value, invPropertyMap); oldObj = om.GetPropertyValue(value, invPropertyMap.Name); if (!(oldObj == obj)) { om.SetPropertyValue(value, invPropertyMap.Name, obj); om.SetNullValueStatus(value, invPropertyMap.Name, obj == null); om.SetUpdatedStatus(value, invPropertyMap.Name, true); this.Context.LogManager.Debug(this, "Wrote back-reference in inverse property", "Wrote to object of type: " + value.GetType().ToString() + ", Inverse Property: " + invPropertyMap.Name); // do not localize uow.RegisterDirty(value); if (oldObj != null) { om.EnsurePropertyIsLoaded(oldObj, propertyMap); list = (IList)om.GetPropertyValue(oldObj, propertyMap.Name); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Remove(value); if (mList != null) { mList.MuteNotify = stackMute; } uow.RegisterDirty(oldObj); om.SetUpdatedStatus(oldObj, invPropertyMap.Name, true); this.Context.LogManager.Debug(this, "Removed back-reference in inverse property", "Wrote to object of type: " + oldObj.GetType().ToString() + ", Inverse Property: " + propertyMap.Name); // do not localize } } } foreach (object iValue in removed) { value = iValue; om.EnsurePropertyIsLoaded(value, invPropertyMap); oldObj = om.GetPropertyValue(value, invPropertyMap.Name); om.SetPropertyValue(value, invPropertyMap.Name, null); om.SetNullValueStatus(value, invPropertyMap.Name, true); om.SetUpdatedStatus(value, invPropertyMap.Name, true); uow.RegisterDirty(value); if (oldObj != null) { om.EnsurePropertyIsLoaded(oldObj, propertyMap); list = (IList)om.GetPropertyValue(oldObj, propertyMap.Name); mList = list as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } list.Remove(value); if (mList != null) { mList.MuteNotify = stackMute; } uow.RegisterDirty(oldObj); om.SetUpdatedStatus(oldObj, invPropertyMap.Name, true); } } }
public void AddModelReference(object objectToDeserialize, IPropertyMap propertyMap, string referenceValue) { _modelReferenceCache.Add(objectToDeserialize, propertyMap, referenceValue); }
protected virtual void CreateIDColumnForProperty(IPropertyMap propertyMap, IDomainMap targetDomainMap, bool generateMappings, IClassMap ownerClassMap) { IClassMap classMap = propertyMap.ClassMap; ITableMap tableMap = null; ISourceMap sourceMap = null; ISourceMap addToSourceMap = null; IClassMap classMapClone = null; IPropertyMap propertyMapClone = null; IColumnMap columnMap = null; string classTableName = ""; string ownerClassTableName = ""; string name = ""; string forColName = ""; string tableName = ""; string foreignKeyName = ""; bool isClassTableOrConcrete = false; sourceMap = classMap.GetSourceMap(); if (sourceMap == null) { sourceMap = classMap.DomainMap.GetSourceMap(); if (sourceMap == null) { throw new Exception("No default data source specified for domain model! Can't add table for class!"); } } addToSourceMap = targetDomainMap.GetSourceMap(sourceMap.Name); if (addToSourceMap == null) { addToSourceMap = (ISourceMap) sourceMap.Clone(); addToSourceMap.DomainMap = targetDomainMap; } if (propertyMap.ClassMap.Table.Length > 0) { classTableName = propertyMap.ClassMap.Table; } else { classTableName = GetTableNameForClass(propertyMap.ClassMap); } if (propertyMap.Table.Length > 0) { tableName = propertyMap.Table; } else if (propertyMap.IsCollection) { tableName = GetTableNameForProperty(propertyMap); } else { if (IsOutbrokenByInheritance(propertyMap, ownerClassMap)) { isClassTableOrConcrete = true; ownerClassTableName = GetTableNameForClass(ownerClassMap, true); tableName = ownerClassTableName; } else { tableName = classTableName; } } tableMap = addToSourceMap.GetTableMap(tableName); if (tableMap == null) { tableMap = new TableMap(); tableMap.Name = tableName; tableMap.SourceMap = addToSourceMap; } foreignKeyName = "FK_" + tableMap.Name; foreach (IPropertyMap idPropertyMap in propertyMap.ClassMap.GetIdentityPropertyMaps()) { if (idPropertyMap.Column.Length > 0) { forColName = idPropertyMap.Column; } else { forColName = GetColumnNameForProperty(idPropertyMap); } foreignKeyName += "_" + forColName; } if (!(classMap.InheritanceType == InheritanceType.None)) { if (classMap.TypeColumn.Length > 0) { foreignKeyName += "_" + classMap.TypeColumn; } else { foreignKeyName += "_" + GetTypeColumnNameForClass(classMap); } } foreach (IPropertyMap idPropertyMap in propertyMap.ClassMap.GetIdentityPropertyMaps()) { if (idPropertyMap.Column.Length > 0) { forColName = idPropertyMap.Column; } else { forColName = GetColumnNameForProperty(idPropertyMap); } if (propertyMap.IdColumn.Length > 0) { name = propertyMap.IdColumn; } else { name = forColName; } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = GetColumnTypeForProperty(idPropertyMap); columnMap.Length = GetColumnLengthForProperty(idPropertyMap); columnMap.Precision = GetColumnPrecisionForProperty(idPropertyMap); columnMap.Scale = GetColumnScaleForProperty(idPropertyMap); if (!(propertyMap.IsCollection)) { columnMap.IsPrimaryKey = true; columnMap.AllowNulls = false; } if (propertyMap.IsCollection || propertyMap.Table.Length > 0 || isClassTableOrConcrete) { columnMap.IsForeignKey = true; columnMap.PrimaryKeyTable = classTableName; columnMap.PrimaryKeyColumn = forColName; columnMap.ForeignKeyName = foreignKeyName; } if (generateMappings & propertyMap.IdColumn.Length < 1) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; } propertyMapClone.IdColumn = columnMap.Name; if (tableMap.Name != classTableName) { propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } } } if (classMap.InheritanceType != InheritanceType.None) { if (classMap.TypeColumn.Length > 0) { name = classMap.TypeColumn; } else { name = GetTypeColumnNameForClass(classMap); } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = DbType.AnsiStringFixedLength; columnMap.Length = 1; columnMap.Precision = 1; columnMap.Scale = 0; if (!(propertyMap.IsCollection)) { columnMap.IsPrimaryKey = true; columnMap.ForeignKeyName = foreignKeyName; columnMap.AllowNulls = false; } columnMap.IsForeignKey = true; columnMap.PrimaryKeyTable = classTableName; columnMap.PrimaryKeyColumn = name; if (generateMappings) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; } foreach (string iterName in propertyMapClone.AdditionalIdColumns) { if (iterName == columnMap.Name) { return; } } propertyMapClone.AdditionalIdColumns.Add(columnMap.Name); } } }
public ReplicationPropertyMap(IPropertyMap <TKey, TValue> master, IPropertyMap <TKey, TValue> slave, ISynchronizer <IPropertyMap <TKey, TValue> > synchronizer) : base(master, slave, synchronizer) { }
/// <summary> /// /// </summary> /// <param name="propertyMap"></param> /// <returns></returns> public static IPropertyMap Key(this IPropertyMap propertyMap) { propertyMap.Strategy = new KeyStrategy(); return(propertyMap); }
public virtual OptimisticConcurrencyBehaviorType GetDeleteOptimisticConcurrencyBehavior(OptimisticConcurrencyBehaviorType optimisticConcurrencyBehavior, IPropertyMap propertyMap) { IColumnMap columnMap = null; if (optimisticConcurrencyBehavior == OptimisticConcurrencyBehaviorType.DefaultBehavior) { if (this.Context.OptimisticConcurrencyMode == OptimisticConcurrencyMode.Disabled) { optimisticConcurrencyBehavior = OptimisticConcurrencyBehaviorType.Disabled; } else { optimisticConcurrencyBehavior = propertyMap.DeleteOptimisticConcurrencyBehavior; if (optimisticConcurrencyBehavior == OptimisticConcurrencyBehaviorType.DefaultBehavior) { optimisticConcurrencyBehavior = propertyMap.ClassMap.DeleteOptimisticConcurrencyBehavior; if (optimisticConcurrencyBehavior == OptimisticConcurrencyBehaviorType.DefaultBehavior) { optimisticConcurrencyBehavior = propertyMap.ClassMap.DomainMap.DeleteOptimisticConcurrencyBehavior; if (optimisticConcurrencyBehavior == OptimisticConcurrencyBehaviorType.DefaultBehavior) { optimisticConcurrencyBehavior = m_DeleteOptimisticConcurrencyBehavior; } } } } } if (optimisticConcurrencyBehavior == OptimisticConcurrencyBehaviorType.DefaultBehavior) { columnMap = propertyMap.GetColumnMap(); if (columnMap != null) { if (columnMap.DataType == DbType.AnsiString || columnMap.DataType == DbType.AnsiStringFixedLength || columnMap.DataType == DbType.String || columnMap.DataType == DbType.StringFixedLength) { if (columnMap.Precision == 0 || columnMap.Precision >= 4000) { optimisticConcurrencyBehavior = OptimisticConcurrencyBehaviorType.Disabled; } else { optimisticConcurrencyBehavior = OptimisticConcurrencyBehaviorType.IncludeWhenLoaded; } } else if (columnMap.DataType == DbType.Binary || columnMap.DataType == DbType.Object) { optimisticConcurrencyBehavior = OptimisticConcurrencyBehaviorType.Disabled; } else { optimisticConcurrencyBehavior = OptimisticConcurrencyBehaviorType.IncludeWhenLoaded; } } } else { if (!(optimisticConcurrencyBehavior == OptimisticConcurrencyBehaviorType.Disabled)) { if (propertyMap.DeleteOptimisticConcurrencyBehavior == OptimisticConcurrencyBehaviorType.DefaultBehavior) { columnMap = propertyMap.GetColumnMap(); if (columnMap != null) { if (columnMap.DataType == DbType.AnsiString || columnMap.DataType == DbType.AnsiStringFixedLength || columnMap.DataType == DbType.String || columnMap.DataType == DbType.StringFixedLength) { if (columnMap.Precision == 0 || columnMap.Precision >= 4000) { optimisticConcurrencyBehavior = OptimisticConcurrencyBehaviorType.Disabled; } } else if (columnMap.DataType == DbType.Binary || columnMap.DataType == DbType.Object) { optimisticConcurrencyBehavior = OptimisticConcurrencyBehaviorType.Disabled; } } } } } if (columnMap == null) { columnMap = propertyMap.GetColumnMap(); } if (columnMap != null) { if (columnMap.DataType == DbType.Binary || columnMap.DataType == DbType.Object) { optimisticConcurrencyBehavior = OptimisticConcurrencyBehaviorType.Disabled; } } return optimisticConcurrencyBehavior; }
protected virtual string GetEntityGraphTypeFieldDescription <TEntity>(IPropertyMap property) where TEntity : class => $"The {property.Name} of the {typeof(TEntity).Name}.";
public object LoadProperty(object obj, string propertyName, string domainKey) { if (useCompression && this.compressor != null) { obj = this.compressor.Decompress((string)obj); //propertyName = this.compressor.Decompress(propertyName); //domainKey = this.compressor.Decompress(domainKey); } IContext ctx = contextFactory.GetContext(domainKey); IObjectManager om = ctx.ObjectManager; IMarshalingTransformer transformer = new MarshalingTransformer(ctx); MarshalReference mr = (MarshalReference)formater.Deserialize(obj, typeof(MarshalReference)); string identity = transformer.GetIdentity(mr, mr.Value); IClassMap classMap = ctx.DomainMap.MustGetClassMap(mr.Type); IPropertyMap propertyMap = classMap.MustGetPropertyMap(propertyName); Type realType = ctx.AssemblyManager.MustGetTypeFromClassMap(classMap); //object realObj = ctx.GetObjectById(identity, realType); object realObj = ctx.GetObjectById(identity, realType, true); ctx.LoadProperty(realObj, propertyName); object serialized = null; if (propertyMap.IsCollection) { if (propertyMap.ReferenceType == ReferenceType.None) { // IList list = (IList) om.GetPropertyValue(realObj, propertyName); // MarshalList ml = transformer.FromList(list) ; // serialized = formater.Serialize(ml); } else { //TODO: fix transformer.FromReferenceList //Even better: Add MarshalProperty.Object, OriginalObject, List, OriginalList, ReferenceList and OriginalReferenceList! IList list = (IList)om.GetPropertyValue(realObj, propertyName); MarshalObjectList mol = transformer.FromObjectList(list); serialized = formater.Serialize(mol); } } else { if (propertyMap.ReferenceType == ReferenceType.None) { MarshalProperty mp = transformer.FromProperty(obj, propertyMap); serialized = formater.Serialize(mp); } else { object value = om.GetPropertyValue(realObj, propertyName); if (value != null) { ObjectStatus objectStatus = ctx.GetObjectStatus(value); if (objectStatus == ObjectStatus.NotLoaded) { ctx.PersistenceEngine.LoadObject(ref value); } if (value != null) { MarshalObject mo = transformer.FromObject(value); serialized = formater.Serialize(mo); } } } } if (serialized == null) { serialized = ""; } ctx.Dispose(); if (useCompression && this.compressor != null) { return(this.compressor.Compress((string)serialized)); } else { return(serialized); } }
public bool IsShadowingProperty(IPropertyMap propertyMap) { throw new Exception("The method or operation is not implemented."); }
public bool IsInheritedProperty(IPropertyMap propertyMap) { throw new Exception("The method or operation is not implemented."); }
protected override void AddPropertyMap(IPropertyMap propertyMap) { base.AddPropertyMap(propertyMap); deserializationPropertyMaps.Add(propertyMap.Definition.Content.SerializedName.LocalName, propertyMap); }
public virtual object ManageNullValue(object obj, IPropertyMap propertyMap, object value) { if (propertyMap != null) { if (Convert.IsDBNull(value)) { //The ManageLoadedValue method should be side-effect free....otherwise we //risk overwriting dirty objects with incorrect nullvalue statuses //this.Context.ObjectManager.SetNullValueStatus(obj, propertyMap.Name, true); if (!(propertyMap.ReferenceType == ReferenceType.None)) { return null; } else { if (propertyMap.NullSubstitute.Length > 0) { Type propType = obj.GetType().GetProperty(propertyMap.Name).PropertyType; if (propType.IsEnum) { return Enum.ToObject(propType, Convert.ToInt32(propertyMap.NullSubstitute)); } else if (propType == typeof(Boolean) || propType.IsSubclassOf(typeof(Boolean))) { return Convert.ToBoolean(propertyMap.NullSubstitute); } else if (propType == typeof(Byte) || propType.IsSubclassOf(typeof(Byte))) { return Convert.ToByte(propertyMap.NullSubstitute); } else if (propType == typeof(Char) || propType.IsSubclassOf(typeof(Char))) { return Convert.ToChar(propertyMap.NullSubstitute); } else if (propType == typeof(DateTime) || propType.IsSubclassOf(typeof(DateTime))) { return DateTime.Parse(propertyMap.NullSubstitute); } else if (propType == typeof(Decimal) || propType.IsSubclassOf(typeof(Decimal))) { return Convert.ToDecimal(propertyMap.NullSubstitute); } else if (propType == typeof(Double) || propType.IsSubclassOf(typeof(Double))) { return Convert.ToDouble(propertyMap.NullSubstitute); } else if (propType == typeof(Guid) || propType.IsSubclassOf(typeof(Guid))) { return new Guid(propertyMap.NullSubstitute); } else if (propType == typeof(Int16) || propType.IsSubclassOf(typeof(Int16))) { return Convert.ToInt16(propertyMap.NullSubstitute); } else if (propType == typeof(Int32) || propType.IsSubclassOf(typeof(Int32))) { return Convert.ToInt32(propertyMap.NullSubstitute); } else if (propType == typeof(Int64) || propType.IsSubclassOf(typeof(Int64))) { return Convert.ToInt64(propertyMap.NullSubstitute); } else if (propType == typeof(object) || propType.IsSubclassOf(typeof(object))) { return propertyMap.NullSubstitute; } else if (propType == typeof(SByte) || propType.IsSubclassOf(typeof(SByte))) { return Convert.ToByte(propertyMap.NullSubstitute); } else if (propType == typeof(Single) || propType.IsSubclassOf(typeof(Single))) { return Convert.ToSingle(propertyMap.NullSubstitute); } else if (propType == typeof(String) || propType.IsSubclassOf(typeof(String))) { return propertyMap.NullSubstitute; } else if (propType == typeof(ushort) || propType.IsSubclassOf(typeof(ushort))) { return Convert.ToUInt16(propertyMap.NullSubstitute); } else if (propType == typeof(uint) || propType.IsSubclassOf(typeof(uint))) { return Convert.ToUInt32(propertyMap.NullSubstitute); } else if (propType == typeof(ulong) || propType.IsSubclassOf(typeof(ulong))) { return Convert.ToUInt64(propertyMap.NullSubstitute); } return propertyMap.NullSubstitute; } else { Type propType = obj.GetType().GetProperty(propertyMap.Name).PropertyType; if (propType == typeof (Boolean) || propType.IsSubclassOf(typeof (Boolean))) { return false; } else if (propType == typeof (Byte) || propType.IsSubclassOf(typeof (Byte))) { return Convert.ToByte(0); } else if (propType == typeof (Char) || propType.IsSubclassOf(typeof (Char))) { return Convert.ToChar(""); } else if (propType == typeof (DateTime) || propType.IsSubclassOf(typeof (DateTime))) { return null; } else if (propType == typeof (Decimal) || propType.IsSubclassOf(typeof (Decimal))) { return Convert.ToDecimal(0); } else if (propType == typeof (Double) || propType.IsSubclassOf(typeof (Double))) { return Convert.ToDouble(0); } else if (propType == typeof (Guid) || propType.IsSubclassOf(typeof (Guid))) { return Guid.Empty; } else if (propType == typeof (Int16) || propType.IsSubclassOf(typeof (Int16))) { return Convert.ToInt16(0); } else if (propType == typeof (Int32) || propType.IsSubclassOf(typeof (Int32))) { return Convert.ToInt32(0); } else if (propType == typeof (Int64) || propType.IsSubclassOf(typeof (Int64))) { return Convert.ToInt64(0); } else if (propType == typeof (object) || propType.IsSubclassOf(typeof (object))) { return null; } else if (propType == typeof (SByte) || propType.IsSubclassOf(typeof (SByte))) { return Convert.ToByte(0); } else if (propType == typeof (Single) || propType.IsSubclassOf(typeof (Single))) { return Convert.ToSingle(0); } else if (propType == typeof (String) || propType.IsSubclassOf(typeof (String))) { return ""; } else if (propType == typeof (ushort) || propType.IsSubclassOf(typeof (ushort))) { return Convert.ToUInt16(0); } else if (propType == typeof (uint) || propType.IsSubclassOf(typeof (uint))) { return Convert.ToUInt32(0); } else if (propType == typeof (ulong) || propType.IsSubclassOf(typeof (ulong))) { return Convert.ToUInt64(0); } } } } // else // { // //The ManageLoadedValue method should be side-effect free....otherwise we // //risk overwriting dirty objects with incorrect nullvalue statuses // //this.Context.ObjectManager.SetNullValueStatus(obj, propertyMap.Name, false); // } } return value; }
public void SetInversePropertyMap(IPropertyMap value) { this.InversePropertyMap = value; }
public virtual MergeBehaviorType GetMergeBehavior(MergeBehaviorType mergeBehavior, IClassMap classMap, IPropertyMap propertyMap) { if (mergeBehavior == MergeBehaviorType.DefaultBehavior) { mergeBehavior = propertyMap.MergeBehavior; if (mergeBehavior == MergeBehaviorType.DefaultBehavior) { mergeBehavior = classMap.MergeBehavior; if (mergeBehavior == MergeBehaviorType.DefaultBehavior) { mergeBehavior = classMap.DomainMap.MergeBehavior; if (mergeBehavior == MergeBehaviorType.DefaultBehavior) { mergeBehavior = m_MergeBehavior; if (mergeBehavior == MergeBehaviorType.DefaultBehavior) { mergeBehavior = MergeBehaviorType.TryResolveConflicts; } } } } } return mergeBehavior; }
public DynamicNodeMapper(IXmlSerializerRepository <TContext> serializerRepository, IPropertyMap propertyMap) { _serializerRepository = serializerRepository; _propertyMap = propertyMap; }
public BackupPropertyMap(IPropertyMap <TKey, TValue> primary, IPropertyMap <TKey, TValue> backup, TimeSpan synchronizationTimeout) : this(primary, backup, new IntersectionMapSynchronizer <TKey, TValue>(synchronizationTimeout)) { }
public string Convert(IPropertyMap propertyMap) => "bool";
protected virtual bool IsOutbrokenByInheritance(IPropertyMap propertyMap, IClassMap classMap) { if (((classMap.InheritanceType == InheritanceType.ClassTableInheritance || classMap.InheritanceType == InheritanceType.ConcreteTableInheritance) && !(classMap.GetInheritedClassMap() == null && (classMap.InheritanceType == InheritanceType.ConcreteTableInheritance || classMap.IsInheritedProperty(propertyMap) == false)))) { return true; } return false; }
public Expression BuildPropertyComparisonExpression(ParameterExpression entityParameter, IPropertyMap property, object comparisonValue) { return(ComparisonExpressionBuilder.BuildPropertyComparisonExpression(entityParameter, property, comparisonValue, Expression.LessThanOrEqual)); }
public string Convert(IPropertyMap propertyMap) => "datetime";
public BackupPropertyMap(IPropertyMap <TKey, TValue> primary, IPropertyMap <TKey, TValue> backup, ISynchronizer <IMap <TKey, TValue> > synchronizer) : base(primary, backup, synchronizer) { }
protected override string GetParameterName(IPropertyMap propertyMap, IColumnMap columnMap) { return(GetParameterName(propertyMap, columnMap, "")); }
/// <summary> /// This assumes that mi will always be a PropertyInfo. /// </summary> /// <param name="mi"></param> /// <param name="sourceType"></param> /// <returns></returns> public ExtraMemberCallDetails GetGetterStrategy(MemberInfo mi, Expression destination, Type sourceType, IPropertyMap propertyMap) { Expression indexExp = Expression.Constant(new object[] { sourceType }); Expression[] parameters = new Expression[3] { Expression.Constant(mi), destination, indexExp }; return(new ExtraMemberCallDetails(ExtraMemberCallDirectionEnum.Get, mi, parameters)); }
public virtual void NotifyPropertyLoad(object obj, IPropertyMap propertyMap, object value) { }
// This assumes that mi will always be a PropertyInfo. public ExtraMemberCallDetails GetSetterStrategy(MemberInfo mi, Expression destination, Type sourceType, IPropertyMap propertyMap, ParameterExpression value) { Expression newValue; if (mi is PropertyInfo pi && pi.PropertyType.IsValueType()) { newValue = Expression.TypeAs((Expression)value, typeof(object)); }
public void Write(IPropertyMap map) { if (!string.IsNullOrEmpty(Enlist)) { map.SetValue(EnlistName, Enlist); } if (!string.IsNullOrEmpty(SvnUri)) { map.SetValue(UriName, SvnUri); } if (!string.IsNullOrEmpty(SvnSuffix)) { map.SetValue(ProjectSuffix, SvnSuffix); } if (!string.IsNullOrEmpty(Group)) { map.SetValue(GroupName, Group); } if (!string.IsNullOrEmpty(Relation)) { map.SetValue(RelationName, Relation); } StringBuilder sb = null; foreach (KeyValuePair <string, string> kv in _custom) { if (map.WrittenKey(kv.Key)) { continue; } if (InList(kv.Key, HandledProperties)) { continue; } map.SetValue(kv.Key, kv.Value); } foreach (string k in map.WrittenKeys) { if (!InList(k, InitialProperties)) { continue; } if (sb == null) { sb = new StringBuilder(); } else { sb.Append(','); } sb.Append(k); } if (sb != null) { map.SetValue(KeysName, sb.ToString()); } }
public void Load(IPropertyMap map) { string value; string properties; _custom.Clear(); if (map.TryGetValue(KeysName, out properties)) { foreach (string nm in properties.Split(',')) { string name = nm.Trim(); if (string.IsNullOrEmpty(name)) { continue; } if (InList(name, HandledProperties)) { continue; } if (map.TryGetValue(name, out value)) { _custom[name] = value; } } } if (map.TryGetValue(EnlistName, out value)) { Enlist = value; } else { Enlist = null; } if (map.TryGetValue(UriName, out value)) { SvnUri = value; } else { SvnUri = null; } if (map.TryGetValue(ProjectSuffix, out value)) { SvnSuffix = value; } else { SvnSuffix = null; } if (map.TryGetValue(GroupName, out value)) { Group = value; } else { Group = null; } if (map.TryGetValue(RelationName, out value)) { Relation = value; } else { Relation = null; } }
protected virtual void HandleSlavePropertySet(object obj, string propertyName, object value, object oldValue, bool hasOldValue) { IPropertyMap propertyMap = this.Context.DomainMap.MustGetClassMap(obj.GetType()).MustGetPropertyMap(propertyName); HandleSlavePropertySet(obj, propertyMap, value, oldValue, hasOldValue); }
protected override string GetParameterName(IPropertyMap propertyMap) { return("?"); }
//if value is a list, values in list come in the same order as columns are returned from propertymap.refClassMap.GetIdentityCols! garantueed order ! //type column value must have been extracted from list in advance and should be passed to discriminator param public virtual object ManageReferenceValue(object obj, IPropertyMap propertyMap, object value, object discriminator) { IClassMap refClassMap; IPropertyMap mapToId; bool isIdentity = false; if (!(propertyMap.ReferenceType == ReferenceType.None)) { if (value != null) { string identity = ""; refClassMap = propertyMap.MustGetReferencedClassMap(); if (discriminator != null) { try { discriminator = discriminator.ToString() ; } catch { discriminator = ""; } refClassMap = refClassMap.GetSubClassWithTypeValue((string) discriminator); if (refClassMap == null) throw new NPersistException("Could not find class map with type value '" + (string) discriminator + "'"); } mapToId = refClassMap.MustGetPropertyMapForColumnMap(propertyMap.GetColumnMap().MustGetPrimaryKeyColumnMap()); if (mapToId.IsIdentity) { isIdentity = true; IList valueAsList = value as IList; if (valueAsList == null) identity = Convert.ToString(value); else { string separator = refClassMap.GetIdentitySeparator(); if (separator == "") { separator = "|"; } StringBuilder identityBuilder = new StringBuilder() ; foreach (object valueItem in valueAsList) identityBuilder.Append(Convert.ToString(valueItem) + separator) ; identityBuilder.Length -= separator.Length; identity = identityBuilder.ToString(); } } if (isIdentity) { return this.Context.GetObjectById(identity, this.Context.AssemblyManager.MustGetTypeFromClassMap(refClassMap), true); } else return this.Context.GetObjectByKey(mapToId.Name, Convert.ToString(value), obj.GetType().GetProperty(propertyMap.Name).PropertyType); } } return value; }
protected override string GetParameterName(IPropertyMap propertyMap, IColumnMap columnMap, string prefix) { return("?"); }
protected virtual bool PropertyIsPartOfCompositeIdentityRelationship(IPropertyMap propertyMap) { if (propertyMap.ReferenceType != ReferenceType.None) if (propertyMap.GetAdditionalIdColumnMaps().Count > 0) return true; return false; }
private void MergePrimitivePropertyValues(object value, object extValue, PropertyStatus propStatus, PropertyStatus extPropStatus, IObjectManager om, object existing, IClassMap classMap, IPropertyMap propertyMap, object obj, bool forOrgValue, MergeBehaviorType mergeBehavior) { if (!value.Equals(extValue)) // May be to naive - possibly should use some advanced method like ComparePropertyValues.. { bool keepExisting = KeepExistingValue(value, extValue, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue); if (!keepExisting) { if (forOrgValue) { om.SetPropertyValue(existing, propertyMap.Name, value); om.SetNullValueStatus(existing, propertyMap.Name, om.GetNullValueStatus(obj, propertyMap.Name)); if (propStatus == PropertyStatus.Dirty) { this.Context.UnitOfWork.RegisterDirty(existing); om.SetUpdatedStatus(existing, propertyMap.Name, true); } } else { om.SetOriginalPropertyValue(existing, propertyMap.Name, value); } } } }
public virtual RefreshBehaviorType GetRefreshBehavior(RefreshBehaviorType refreshBehavior, IClassMap classMap, IPropertyMap propertyMap) { if (refreshBehavior == RefreshBehaviorType.DefaultBehavior) { if (this.Context.OptimisticConcurrencyMode == OptimisticConcurrencyMode.Early) { refreshBehavior = RefreshBehaviorType.ThrowConcurrencyException ; } else { refreshBehavior = propertyMap.RefreshBehavior; if (refreshBehavior == RefreshBehaviorType.DefaultBehavior) { refreshBehavior = classMap.RefreshBehavior; if (refreshBehavior == RefreshBehaviorType.DefaultBehavior) { refreshBehavior = classMap.DomainMap.RefreshBehavior; if (refreshBehavior == RefreshBehaviorType.DefaultBehavior) { refreshBehavior = m_RefreshBehavior; if (refreshBehavior == RefreshBehaviorType.DefaultBehavior) { refreshBehavior = RefreshBehaviorType.OverwriteNotLoaded; } } } } } } return refreshBehavior; }
private void MergeListRefProperty(IObjectManager om, object obj, IClassMap classMap, IPropertyMap propertyMap, object existing, PropertyStatus propStatus, PropertyStatus extPropStatus, bool forOrgValue, MergeBehaviorType mergeBehavior) { IList list = ((IList) om.GetPropertyValue(obj, propertyMap.Name)); IList orgList = ((IList) om.GetPropertyValue(existing, propertyMap.Name)); MergeReferenceLists(list, orgList, om, obj, mergeBehavior, classMap, propertyMap, existing, propStatus, extPropStatus, forOrgValue); }
private void MergePrimitiveProperty(IObjectManager om, object obj, IClassMap classMap, IPropertyMap propertyMap, object existing, bool forOrgValue, PropertyStatus propStatus, PropertyStatus extPropStatus, MergeBehaviorType mergeBehavior) { if (forOrgValue) { object value = om.GetPropertyValue(obj, propertyMap.Name); object extValue = om.GetPropertyValue(existing, propertyMap.Name); MergePrimitivePropertyValues(value, extValue, propStatus, extPropStatus, om, existing, classMap, propertyMap, obj, forOrgValue, mergeBehavior); } else { object orgValue = om.GetOriginalPropertyValue(obj, propertyMap.Name); object extOrgValue = om.GetOriginalPropertyValue(existing, propertyMap.Name); MergePrimitivePropertyValues(orgValue, extOrgValue, propStatus, extPropStatus, om, existing, classMap, propertyMap, obj, forOrgValue, mergeBehavior); } }
protected virtual void AddPropertyMap(IPropertyMap propertyMap) { propertyMaps.Add(propertyMap); }
private bool KeepExistingValue(object value, object extValue, MergeBehaviorType mergeBehavior, IClassMap classMap, IPropertyMap propertyMap, object existing, object obj, PropertyStatus propStatus, PropertyStatus extPropStatus, bool forOrgValue) { bool keepExisting = false; MergeBehaviorType useMergeBehavior = GetMergeBehavior(mergeBehavior, classMap, propertyMap); if (useMergeBehavior == MergeBehaviorType.ThrowConcurrencyException) throw new MergeException("Merge Conflict!", extValue, value, existing, obj, propertyMap.Name, forOrgValue); //First try: Dirty wins.. if (propStatus == PropertyStatus.Dirty && extPropStatus == PropertyStatus.Dirty) { if (useMergeBehavior == MergeBehaviorType.DefaultBehavior) throw new BothDirtyMergeException("Unresovable Merge Conflict! Both values are dirty!", extValue, value, existing, obj, propertyMap.Name, forOrgValue); else if (useMergeBehavior == MergeBehaviorType.IgnoreConflictsUsingMergeValue) keepExisting = false; else if (useMergeBehavior == MergeBehaviorType.IgnoreConflictsUsingCashedValue) keepExisting = true; else throw new NPersistException("This should be unreachable code...if it is not, that means I made a mistake!" ); } else if (propStatus == PropertyStatus.Dirty) keepExisting = false; else if (extPropStatus == PropertyStatus.Dirty) keepExisting = true; else { //Second try: Clean wins if (propStatus == PropertyStatus.Clean && extPropStatus == PropertyStatus.Clean) { if (useMergeBehavior == MergeBehaviorType.DefaultBehavior) throw new BothCleanMergeException("Unresovable Merge Conflict! Both values are clean!", extValue, value, existing, obj, propertyMap.Name, forOrgValue); else if (useMergeBehavior == MergeBehaviorType.IgnoreConflictsUsingMergeValue) keepExisting = false; else if (useMergeBehavior == MergeBehaviorType.IgnoreConflictsUsingCashedValue) keepExisting = true; else throw new NPersistException("This should be unreachable code...if it is not, that means I made a mistake!" ); } else if (propStatus == PropertyStatus.Clean) keepExisting = false; else if (extPropStatus == PropertyStatus.Clean) keepExisting = true; else { if (extPropStatus == PropertyStatus.NotLoaded) keepExisting = false; if (extPropStatus == PropertyStatus.Deleted) keepExisting = true; else throw new NPersistException("This should be unreachable code...if it is not, that means I made a mistake!" ); } } return keepExisting; }
public DuplicateMappingException(IPropertyMap map) : base($"Duplicate mapping detected. Property '{map.PropertyInfo.Name}' is already mapped.") { }
private void MergeReferenceLists(IList list, IList orgList, IObjectManager om, object obj, MergeBehaviorType mergeBehavior, IClassMap classMap, IPropertyMap propertyMap, object existing, PropertyStatus propStatus, PropertyStatus extPropStatus, bool forOrgValue) { IList objectsToRemove = new ArrayList(); IList objectsToAdd = new ArrayList(); IUnitOfWork uow = this.Context.UnitOfWork; foreach (object itemOrgObj in orgList) { string itemOrgObjId = om.GetObjectIdentity(itemOrgObj); bool found = false; foreach (object itemObj in list) { string itemObjId = om.GetObjectIdentity(itemObj); if (itemObjId == itemOrgObjId) { found = true; break; } } if (!found) objectsToRemove.Add(itemOrgObj); } foreach (object itemObj in list) { string itemObjId = om.GetObjectIdentity(itemObj); bool found = false; foreach (object itemOrgObj in orgList) { string itemOrgObjId = om.GetObjectIdentity(itemOrgObj); if (itemObjId == itemOrgObjId) { found = true; break; } } if (!found) { object itemOrgObj = this.Context.GetObjectById(itemObjId, obj.GetType()); objectsToAdd.Add(itemOrgObj); } } if (objectsToRemove.Count > 0 || objectsToAdd.Count > 0) { bool keepExisting = KeepExistingValue(list, orgList, mergeBehavior, classMap, propertyMap, existing, obj, propStatus, extPropStatus, forOrgValue); if (!keepExisting) { bool stackMute = false; IInterceptableList mList = orgList as IInterceptableList; if (mList != null) { stackMute = mList.MuteNotify; mList.MuteNotify = true; } foreach (object itemOrgObj in objectsToRemove) orgList.Remove(itemOrgObj); foreach (object itemOrgObj in objectsToAdd) orgList.Add(itemOrgObj); if (mList != null) { mList.MuteNotify = stackMute; } if (propStatus == PropertyStatus.Dirty) { uow.RegisterDirty(existing); om.SetUpdatedStatus(existing, propertyMap.Name, true); } } } }
public Field(IPropertyMap pm) : base(pm) { }
protected virtual void CreateTableForProperty(IPropertyMap propertyMap, IDomainMap targetDomainMap, bool generateMappings) { IClassMap classMap = propertyMap.ClassMap; ITableMap tableMap = null; ISourceMap sourceMap = null; ISourceMap addToSourceMap = null; IClassMap classMapClone = null; IPropertyMap propertyMapClone = null; string name = ""; sourceMap = classMap.GetSourceMap(); if (sourceMap == null) { sourceMap = classMap.DomainMap.GetSourceMap(); if (sourceMap == null) { throw new Exception("No default data source specified for domain model! Can't add table for class!"); } } addToSourceMap = targetDomainMap.GetSourceMap(sourceMap.Name); if (addToSourceMap == null) { addToSourceMap = (ISourceMap) sourceMap.Clone(); addToSourceMap.DomainMap = targetDomainMap; } if (propertyMap.Table.Length > 0) { name = propertyMap.Table; } else { name = GetTableNameForProperty(propertyMap); } tableMap = addToSourceMap.GetTableMap(name); if (tableMap == null) { tableMap = new TableMap(); tableMap.Name = name; tableMap.SourceMap = addToSourceMap; } if (generateMappings & propertyMap.Table.Length < 1) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); classMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == targetDomainMap.Source)) { classMapClone.Source = addToSourceMap.Name; } classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; } propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } }
public Field(IPropertyMap pm, string aliasName) : base(pm) { this.AliasName = aliasName; }
protected virtual void CreateColumnForProperty(IPropertyMap propertyMap, IDomainMap targetDomainMap, bool generateMappings, IClassMap ownerClassMap) { IClassMap classMap = propertyMap.ClassMap; ITableMap tableMap = null; ISourceMap sourceMap = null; ISourceMap addToSourceMap = null; IClassMap classMapClone = null; IPropertyMap propertyMapClone = null; IColumnMap columnMap = null; string classTableName = ""; string name = ""; string tableName = ""; bool allowNulls = false; IClassMap refClassMap = null; string forTableName = ""; string forColumnName = ""; int cnt = 0; bool found = false; string primColName = ""; string ownerClassTableName = ""; string foreignKeyName = ""; sourceMap = classMap.GetSourceMap(); if (sourceMap == null) { sourceMap = classMap.DomainMap.GetSourceMap(); if (sourceMap == null) { throw new Exception("No default data source specified for domain model! Can't add table for class!"); } } addToSourceMap = targetDomainMap.GetSourceMap(sourceMap.Name); if (addToSourceMap == null) { addToSourceMap = (ISourceMap) sourceMap.Clone(); addToSourceMap.DomainMap = targetDomainMap; } if (propertyMap.ClassMap.Table.Length > 0) { classTableName = propertyMap.ClassMap.Table; } else { classTableName = GetTableNameForClass(propertyMap.ClassMap); } if (propertyMap.Table.Length > 0) { tableName = propertyMap.Table; } else if (propertyMap.IsCollection) { tableName = GetTableNameForProperty(propertyMap); } else { if (IsOutbrokenByInheritance(propertyMap, ownerClassMap)) { ownerClassTableName = GetTableNameForClass(ownerClassMap, true); tableName = ownerClassTableName; } else { tableName = classTableName; } } tableMap = addToSourceMap.GetTableMap(tableName); if (tableMap == null) { tableMap = new TableMap(); tableMap.Name = tableName; tableMap.SourceMap = addToSourceMap; } if (propertyMap.Column.Length > 0) { name = propertyMap.Column; } else { name = GetColumnNameForProperty(propertyMap); } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = GetColumnTypeForProperty(propertyMap); columnMap.Length = GetColumnLengthForProperty(propertyMap); columnMap.Precision = GetColumnPrecisionForProperty(propertyMap); columnMap.Scale = GetColumnScaleForProperty(propertyMap); allowNulls = propertyMap.IsNullable; if (propertyMap.IsIdentity) { allowNulls = false; } columnMap.AllowNulls = allowNulls; if (propertyMap.IsIdentity) { columnMap.IsPrimaryKey = true; columnMap.AllowNulls = false; if (propertyMap.ReferenceType == ReferenceType.None) { if (columnMap.DataType == DbType.Int16 || columnMap.DataType == DbType.Int32 || columnMap.DataType == DbType.Int64) { if (propertyMap.ClassMap.GetIdentityPropertyMaps().Count == 1) { if (propertyMap.GetIsAssignedBySource()) { columnMap.IsAutoIncrease = true; columnMap.Seed = 1; columnMap.Increment = 1; } } } } } if (!(propertyMap.ReferenceType == ReferenceType.None)) { foreignKeyName = "FK_" + columnMap.TableMap.Name + "_" + columnMap.Name; refClassMap = propertyMap.GetReferencedClassMap(); if (!(refClassMap == null)) { foreach (IPropertyMap idProp in refClassMap.GetIdentityPropertyMaps()) { if (cnt > 0) { if (idProp.Column.Length > 0) { name = idProp.Column; } else { name = GetColumnNameForProperty(idProp); } foreignKeyName += "_" + name; } } } primColName = ""; if (refClassMap.TypeColumn.Length > 0) { primColName = refClassMap.TypeColumn; } else { if (!(refClassMap.InheritanceType == InheritanceType.None)) { primColName = GetTypeColumnNameForClass(refClassMap); } } if (primColName.Length > 0) { name = propertyMap.Name + "_" + primColName; foreignKeyName += "_" + name; } else { name = propertyMap.Name; } } if (!(propertyMap.ReferenceType == ReferenceType.None)) { columnMap.IsForeignKey = true; columnMap.ForeignKeyName = foreignKeyName; refClassMap = propertyMap.GetReferencedClassMap(); if (!(refClassMap == null)) { if (refClassMap.Table.Length > 0) { forTableName = refClassMap.Table; } else { forTableName = GetTableNameForClass(refClassMap); } columnMap.PrimaryKeyTable = forTableName; foreach (IPropertyMap idProp in refClassMap.GetIdentityPropertyMaps()) { if (idProp.Column.Length > 0) { forColumnName = idProp.Column; } else { forColumnName = GetColumnNameForProperty(idProp); } break; } columnMap.PrimaryKeyColumn = forColumnName; } } if (generateMappings & propertyMap.Column.Length < 1) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); if (tableMap.Name == classTableName) { classMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == targetDomainMap.Source)) { classMapClone.Source = addToSourceMap.Name; } } classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; } propertyMapClone.Column = columnMap.Name; if (!(tableMap.Name == classTableName)) { propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } } if (!(propertyMap.ReferenceType == ReferenceType.None)) { refClassMap = propertyMap.GetReferencedClassMap(); if (!(refClassMap == null)) { foreach (IPropertyMap idProp in refClassMap.GetIdentityPropertyMaps()) { if (cnt > 0) { if (idProp.Column.Length > 0) { name = idProp.Column; } else { name = GetColumnNameForProperty(idProp); } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = GetColumnTypeForProperty(idProp); columnMap.Length = GetColumnLengthForProperty(idProp); columnMap.Precision = GetColumnPrecisionForProperty(idProp); columnMap.Scale = GetColumnScaleForProperty(idProp); columnMap.IsForeignKey = true; columnMap.ForeignKeyName = foreignKeyName; columnMap.PrimaryKeyTable = forTableName; if (idProp.Column.Length > 0) { forColumnName = idProp.Column; } else { forColumnName = GetColumnNameForProperty(idProp); } columnMap.PrimaryKeyColumn = forColumnName; if (generateMappings) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); if (tableMap.Name == classTableName) { classMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == targetDomainMap.Source)) { classMapClone.Source = addToSourceMap.Name; } } classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; if (!(tableMap.Name == classTableName)) { propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } } found = false; foreach (string iterName in propertyMapClone.AdditionalColumns) { if (iterName == columnMap.Name) { found = true; } } if (!(found)) { propertyMapClone.AdditionalColumns.Add(columnMap.Name); } } } cnt += 1; } if (refClassMap.InheritanceType != InheritanceType.None) { if (refClassMap.TypeColumn.Length > 0) { primColName = refClassMap.TypeColumn; } else { primColName = GetTypeColumnNameForClass(refClassMap); } name = propertyMap.Name + "_" + primColName; columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = DbType.AnsiStringFixedLength; columnMap.Length = 1; columnMap.Precision = 1; columnMap.Scale = 0; columnMap.AllowNulls = true; if (propertyMap.IsIdentity) { columnMap.AllowNulls = false; } columnMap.IsForeignKey = true; columnMap.ForeignKeyName = foreignKeyName; columnMap.PrimaryKeyTable = forTableName; columnMap.PrimaryKeyColumn = primColName; if (generateMappings) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); if (tableMap.Name == classTableName) { classMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == targetDomainMap.Source)) { classMapClone.Source = addToSourceMap.Name; } } classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; if (!(tableMap.Name == classTableName)) { propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } } found = false; foreach (string iterName in propertyMapClone.AdditionalColumns) { if (iterName == columnMap.Name) { found = true; } } if (!(found)) { propertyMapClone.AdditionalColumns.Add(columnMap.Name); } } } } } }
public ReplicationPropertyMap(IPropertyMap <TKey, TValue> master, IPropertyMap <TKey, TValue> slave, TimeSpan synchronizationTimeout) : this(master, slave, new DifferentialMapSynchronizer <TKey, TValue>(synchronizationTimeout)) { }