示例#1
0
        /// <summary>
        ///     Registers a column binding for the type specified.
        /// </summary>
        /// <param name="type">
        ///     The entity type.
        /// </param>
        /// <param name="columnBinding">
        ///     The column binding.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the column binding has been added, <c>false</c> if an existing column binding has been replaced.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="type" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="columnBinding" /> is null.
        /// </exception>
        public bool RegisterColumnBinding(Type type, IColumnBinding columnBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (columnBinding == null)
            {
                throw new ArgumentNullException(nameof(columnBinding));
            }

            lock (this.syncRoot)
            {
                this.Refresh();

                BindingSpec <IColumnBinding> existingColumnBinding;
                if (this.columnBindings.TryGetValue(type, out existingColumnBinding))
                {
                    this.RemovingColumnBinding(type, existingColumnBinding.Binding);
                }

                this.columnBindings.Remove(from kv in this.columnBindings
                                           where kv.Value.Derived && type.IsAssignableFrom(kv.Key)
                                           select kv.Key);
                return(this.columnBindings.AddOrUpdate(type, new BindingSpec <IColumnBinding>(columnBinding)));
            }
        }
示例#2
0
 /// <summary>
 ///     Removes all entity references affected by the column binding specified.
 /// </summary>
 /// <param name="type">
 ///     The entity type.
 /// </param>
 /// <param name="columnBinding">
 ///     The column binding.
 /// </param>
 protected override void RemovingColumnBinding(Type type, IColumnBinding columnBinding)
 {
     this.entityReferences.Remove(
         from kv in this.entityReferences
         where type.IsAssignableFrom(kv.Key) ||
         (kv.Value != null && object.ReferenceEquals(kv.Value.ColumnBinding, columnBinding))
         select kv.Key);
 }
示例#3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PartialKeyBinding" /> class.
        /// </summary>
        /// <param name="entityType">
        ///     The entity type.
        /// </param>
        /// <param name="columnBinding">
        ///     The column binding.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="entityType" /> is null.
        /// </exception>
        protected PartialKeyBinding(Type entityType, IColumnBinding columnBinding)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException(nameof(entityType));
            }

            this.entityType    = entityType;
            this.ColumnBinding = columnBinding;
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PartialKeyBinding"/> class.
        /// </summary>
        /// <param name="entityType">
        /// The entity type.
        /// </param>
        /// <param name="columnBinding">
        /// The column binding.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityType"/> is null.
        /// </exception>
        protected PartialKeyBinding(Type entityType, IColumnBinding columnBinding)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }

            this.entityType = entityType;
            this.ColumnBinding = columnBinding;
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyPropertyKeyBinding"/> class.
        /// </summary>
        /// <param name="inspectedProperty">
        /// The inspected property.
        /// </param>
        /// <param name="columnBinding">
        /// The column binding.
        /// </param>
        /// <exception cref="ArgumentException">
        /// If the <paramref name="inspectedProperty"/> does not have an entity key.
        /// </exception>
        internal KeyPropertyKeyBinding(InspectedProperty inspectedProperty, IColumnBinding columnBinding)
            : base(inspectedProperty, columnBinding)
        {
            if (!inspectedProperty.HasKey)
            {
                throw new ArgumentException("Invalid property, missing entity key", "inspectedProperty");
            }

            this.get = inspectedProperty.Getter;
            this.set = inspectedProperty.Setter;
        }
示例#6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="KeyPropertyKeyBinding" /> class.
        /// </summary>
        /// <param name="inspectedProperty">
        ///     The inspected property.
        /// </param>
        /// <param name="columnBinding">
        ///     The column binding.
        /// </param>
        /// <exception cref="ArgumentException">
        ///     If the <paramref name="inspectedProperty" /> does not have an entity key.
        /// </exception>
        internal KeyPropertyKeyBinding(InspectedProperty inspectedProperty, IColumnBinding columnBinding)
            : base(inspectedProperty, columnBinding)
        {
            if (!inspectedProperty.HasKey)
            {
                throw new ArgumentException("Invalid property, missing entity key", nameof(inspectedProperty));
            }

            this.get = inspectedProperty.Getter;
            this.set = inspectedProperty.Setter;
        }
示例#7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityReference" /> class.
        /// </summary>
        /// <param name="entityReference">
        ///     The entity reference.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="entityReference" /> is null.
        /// </exception>
        internal EntityReference(EntityReference entityReference)
        {
            if (entityReference == null)
            {
                throw new ArgumentNullException(nameof(entityReference));
            }

            this.entityType    = entityReference.entityType;
            this.tableBinding  = entityReference.tableBinding;
            this.columnBinding = entityReference.columnBinding;
            this.keyBinding    = entityReference.keyBinding;
        }
示例#8
0
        /// <summary>
        ///     Gets the key binding for the type specified.
        /// </summary>
        /// <param name="type">
        ///     The entity type.
        /// </param>
        /// <param name="columnBinding">
        ///     The column binding.
        /// </param>
        /// <returns>
        ///     The kay binding.
        /// </returns>
        private IKeyBinding GetKeyBindingForType(Type type, IColumnBinding columnBinding)
        {
            var keyBinding        = this.keyBindings.GetValue(type);
            var partialKeyBinding = keyBinding as PartialKeyBinding;

            if (partialKeyBinding != null && partialKeyBinding.ColumnBinding == null)
            {
                partialKeyBinding.ColumnBinding = columnBinding;
            }

            return(keyBinding);
        }
示例#9
0
        /// <summary>
        ///     Gets the column binding associated with the specified type.
        /// </summary>
        /// <param name="type">
        ///     The type.
        /// </param>
        /// <param name="columnBinding">
        ///     When this method returns, contains the column binding associated with the specified type, if the type is found;
        ///     otherwise null.
        /// </param>
        /// <returns>
        ///     <c>true</c> if a column binding exists for the type specified; otherwise, <c>false</c>.
        /// </returns>
        public bool TryGetColumnBinding(Type type, out IColumnBinding columnBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            lock (this.syncRoot)
            {
                columnBinding = this.GetColumnBindingForType(type);
            }

            return(columnBinding != null);
        }
示例#10
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="KeyBinding{T}" /> class.
        /// </summary>
        /// <param name="get">
        ///     The getter function.
        /// </param>
        /// <param name="set">
        ///     The setter method.
        /// </param>
        /// <param name="columnBinding">
        ///     The column binding.
        /// </param>
        /// <param name="generateKey">
        ///     Indicating whether this key binding should generate new keys or not.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="get" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="set" /> is null.
        /// </exception>
        public KeyBinding(Func <T, string> get, Action <T, string> set, IColumnBinding columnBinding, bool generateKey)
            : base(typeof(T), columnBinding)
        {
            if (get == null)
            {
                throw new ArgumentNullException(nameof(get));
            }

            if (set == null)
            {
                throw new ArgumentNullException(nameof(set));
            }

            this.get = get;
            this.set = set;

            this.generateKey = generateKey;
        }
示例#11
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityReference" /> class.
        /// </summary>
        /// <param name="entityType">
        ///     The entity type.
        /// </param>
        /// <param name="tableBinding">
        ///     The table binding.
        /// </param>
        /// <param name="columnBinding">
        ///     The column binding.
        /// </param>
        /// <param name="keyBinding">
        ///     The key binding.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="entityType" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="tableBinding" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="keyBinding" /> is null.
        /// </exception>
        internal EntityReference(Type entityType, ITableBinding tableBinding, IColumnBinding columnBinding,
                                 IKeyBinding keyBinding)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException(nameof(entityType));
            }

            if (tableBinding == null)
            {
                throw new ArgumentNullException(nameof(tableBinding));
            }

            if (keyBinding == null)
            {
                throw new ArgumentNullException(nameof(keyBinding));
            }

            this.entityType    = entityType;
            this.tableBinding  = tableBinding;
            this.columnBinding = columnBinding;
            this.keyBinding    = keyBinding;
        }
示例#12
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KeyBinding{T}" /> class.
 /// </summary>
 /// <param name="get">
 ///     The getter function.
 /// </param>
 /// <param name="set">
 ///     The setter method.
 /// </param>
 /// <param name="columnBinding">
 ///     The column binding.
 /// </param>
 /// <exception cref="ArgumentNullException">
 ///     If <paramref name="get" /> is null.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 ///     If <paramref name="set" /> is null.
 /// </exception>
 public KeyBinding(Func <T, string> get, Action <T, string> set, IColumnBinding columnBinding)
     : this(get, set, columnBinding, false)
 {
 }
示例#13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KeyBinding{T}" /> class.
 /// </summary>
 /// <param name="propertyLambda">
 ///     The property lambda.
 /// </param>
 /// <param name="columnBinding">
 ///     The column binding.
 /// </param>
 /// <param name="generateKey">
 ///     Indicating whether this key binding should generate new keys or not.
 /// </param>
 public KeyBinding(Expression <Func <T, string> > propertyLambda, IColumnBinding columnBinding, bool generateKey)
     : base(typeof(T), columnBinding)
 {
     FromExpression(propertyLambda, out this.get, out this.set);
     this.generateKey = generateKey;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InspectedPropertyKeyBinding"/> class.
 /// </summary>
 /// <param name="inspectedProperty">
 /// The inspected property.
 /// </param>
 /// <param name="columnBinding">
 /// The column binding.
 /// </param>
 protected InspectedPropertyKeyBinding(InspectedProperty inspectedProperty, IColumnBinding columnBinding)
     : base(inspectedProperty.InspectedType, columnBinding)
 {
 }
示例#15
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="GuidPropertyKeyBinding" /> class.
 /// </summary>
 /// <param name="inspectedProperty">
 ///     The inspected property.
 /// </param>
 /// <param name="columnBinding">
 ///     The column binding.
 /// </param>
 internal GuidPropertyKeyBinding(InspectedProperty inspectedProperty, IColumnBinding columnBinding)
     : base(inspectedProperty, columnBinding)
 {
     this.get = inspectedProperty.Getter;
     this.set = inspectedProperty.Setter;
 }
示例#16
0
 /// <summary>
 ///     Gets the fully qualified column name for the column binding specified.
 /// </summary>
 /// <param name="columnBinding">
 ///     The column binding.
 /// </param>
 /// <returns>
 ///     The fully qualified column name.
 /// </returns>
 private static string ColumnName(IColumnBinding columnBinding)
 {
     return(columnBinding.ColumnQualifier == null
         ? columnBinding.ColumnFamily
         : columnBinding.ColumnFamily + ":" + columnBinding.ColumnQualifier);
 }
示例#17
0
        /// <summary>
        ///     Gets the key binding for the inspected property specified.
        /// </summary>
        /// <param name="property">
        ///     The inspected property.
        /// </param>
        /// <param name="columnBinding">
        ///     The column binding.
        /// </param>
        /// <returns>
        ///     The key binding.
        /// </returns>
        private static IKeyBinding GetKeyBindingForProperty(InspectedProperty property, IColumnBinding columnBinding)
        {
            if (property.PropertyType == typeof(Key))
            {
                return(new KeyPropertyKeyBinding(property, columnBinding));
            }

            if (property.PropertyType == typeof(string))
            {
                return(new StringPropertyKeyBinding(property, columnBinding));
            }

            if (property.PropertyType == typeof(Guid))
            {
                return(new GuidPropertyKeyBinding(property, columnBinding));
            }

            throw new PersistenceException(String.Format(CultureInfo.InvariantCulture,
                                                         @"Unsupported id property type {0}", property.PropertyType));
        }
示例#18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityReference"/> class.
        /// </summary>
        /// <param name="entityReference">
        /// The entity reference.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityReference"/> is null.
        /// </exception>
        internal EntityReference(EntityReference entityReference)
        {
            if (entityReference == null)
            {
                throw new ArgumentNullException("entityReference");
            }

            this.entityType = entityReference.entityType;
            this.tableBinding = entityReference.tableBinding;
            this.columnBinding = entityReference.columnBinding;
            this.keyBinding = entityReference.keyBinding;
        }
示例#19
0
 /// <summary>
 /// Removes all entity references affected by the column binding specified.
 /// </summary>
 /// <param name="type">
 /// The entity type.
 /// </param>
 /// <param name="columnBinding">
 /// The column binding.
 /// </param>
 protected override void RemovingColumnBinding(Type type, IColumnBinding columnBinding)
 {
     this.entityReferences.Remove(
         from kv in this.entityReferences where type.IsAssignableFrom(kv.Key) || (kv.Value != null && object.ReferenceEquals(kv.Value.ColumnBinding, columnBinding)) select kv.Key);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StringPropertyKeyBinding"/> class.
 /// </summary>
 /// <param name="inspectedProperty">
 /// The inspected property.
 /// </param>
 /// <param name="columnBinding">
 /// The column binding.
 /// </param>
 internal StringPropertyKeyBinding(InspectedProperty inspectedProperty, IColumnBinding columnBinding)
     : base(inspectedProperty, columnBinding)
 {
     this.get = inspectedProperty.Getter;
     this.set = inspectedProperty.Setter;
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="InspectedPropertyKeyBinding" /> class.
 /// </summary>
 /// <param name="inspectedProperty">
 ///     The inspected property.
 /// </param>
 /// <param name="columnBinding">
 ///     The column binding.
 /// </param>
 protected InspectedPropertyKeyBinding(InspectedProperty inspectedProperty, IColumnBinding columnBinding)
     : base(inspectedProperty.InspectedType, columnBinding)
 {
 }
示例#22
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="KeyBinding{T}" /> class.
 /// </summary>
 /// <param name="propertyLambda">
 ///     The property lambda.
 /// </param>
 /// <param name="columnBinding">
 ///     The column binding.
 /// </param>
 public KeyBinding(Expression <Func <T, string> > propertyLambda, IColumnBinding columnBinding)
     : this(propertyLambda, columnBinding, false)
 {
 }
示例#23
0
 /// <summary>
 ///     The removing column binding callback.
 /// </summary>
 /// <param name="type">
 ///     The entity type.
 /// </param>
 /// <param name="columnBinding">
 ///     The column binding.
 /// </param>
 protected virtual void RemovingColumnBinding(Type type, IColumnBinding columnBinding)
 {
 }
示例#24
0
 /// <summary>
 /// Gets the fully qualified column name for the column binding specified.
 /// </summary>
 /// <param name="columnBinding">
 /// The column binding.
 /// </param>
 /// <returns>
 /// The fully qualified column name.
 /// </returns>
 private static string ColumnName(IColumnBinding columnBinding)
 {
     return columnBinding.ColumnQualifier == null ? columnBinding.ColumnFamily : columnBinding.ColumnFamily + ":" + columnBinding.ColumnQualifier;
 }
示例#25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityReference"/> class.
        /// </summary>
        /// <param name="entityType">
        /// The entity type.
        /// </param>
        /// <param name="tableBinding">
        /// The table binding.
        /// </param>
        /// <param name="columnBinding">
        /// The column binding.
        /// </param>
        /// <param name="keyBinding">
        /// The key binding.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityType"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="tableBinding"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="keyBinding"/> is null.
        /// </exception>
        internal EntityReference(Type entityType, ITableBinding tableBinding, IColumnBinding columnBinding, IKeyBinding keyBinding)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }

            if (tableBinding == null)
            {
                throw new ArgumentNullException("tableBinding");
            }

            if (keyBinding == null)
            {
                throw new ArgumentNullException("keyBinding");
            }

            this.entityType = entityType;
            this.tableBinding = tableBinding;
            this.columnBinding = columnBinding;
            this.keyBinding = keyBinding;
        }