Пример #1
0
        protected virtual IEntityGraphNode CreateNode(IEntityGraphNode parent, IRelationConfig relation, IEntityMapper mapper)
        {
            var node = (EntityGraphNode)this.Members.Invoke(this, "CreateNode", new[] { this.GetMapping(parent.Table).EntityType, relation.RelationType }, parent, relation);

            node.Children = GetChildren(this, node, mapper);
            return(node);
        }
Пример #2
0
        protected virtual void VisitAny(MethodCallExpression node, IRelationConfig relation)
        {
            var target = default(IFragmentTarget);

            if (!this.TryPeek(out target))
            {
                target = this.Query.Filter;
            }
            target.Write(target.CreateFunction(QueryFunction.Exists).With(function =>
            {
                var builder = this.Database.QueryFactory.Build();
                builder.Output.AddOperator(QueryOperator.Star);
                builder.Source.AddTable(relation.LeftTable.Extern());
                builder.Source.AddTable(relation.RightTable);
                builder.RelationManager.AddRelation(relation);
                function.AddArgument(function.CreateSubQuery(builder));
                this.Push(builder.Filter);
            }));
            try
            {
                for (var a = 1; a < node.Arguments.Count; a++)
                {
                    this.Visit(node.Arguments[a]);
                }
            }
            finally
            {
                this.Pop();
            }
        }
Пример #3
0
 public void AddRelationConfig(IRelationConfig relationConfig)
 {
     if (!relationConfigs.Add(relationConfig))
     {
         throw new ArgumentException("Duplicate relation configuration for '" + EntityType.Name + "'.'" + relationConfig.Name + "'");
     }
 }
Пример #4
0
        public IRelationBuilder AddRelation(IRelationConfig relation)
        {
            var builder = this.CreateRelation(relation);

            this.Expressions.Add(builder);
            return(builder);
        }
Пример #5
0
 protected virtual void Configure(IRelationConfig relation)
 {
     if (relation.Flags.HasFlag(RelationFlags.AutoExpression))
     {
         relation.AutoExpression();
     }
 }
Пример #6
0
        protected virtual DatabaseParameterHandler GetParameters(Frame frame, IRelationConfig relation)
        {
            var handlers = new List <DatabaseParameterHandler>();

            if (relation != null)
            {
                if (frame.Parent != null)
                {
                    handlers.Add(new ForeignKeysParameterHandlerStrategy(frame.Parent.Updated ?? frame.Parent.Persisted, frame.Updated ?? frame.Persisted, relation).Handler);
                }
                if (frame.Updated != null || frame.Persisted != null)
                {
                    handlers.Add(new ParameterHandlerStrategy(relation.RightTable, frame.Updated ?? frame.Persisted).Handler);
                }
            }
            switch (handlers.Count)
            {
            case 0:
                return(null);

            case 1:
                return(handlers[0]);

            default:
                return(Delegate.Combine(handlers.ToArray()) as DatabaseParameterHandler);
            }
        }
Пример #7
0
 public IRelationBuilder CreateRelation(IRelationConfig relation)
 {
     if (relation == null)
     {
         throw new NotImplementedException();
     }
     return(this.Fragment <IRelationBuilder>().With(builder => builder.Relation = relation));
 }
Пример #8
0
        public virtual IQueryGraphBuilder Lookup(IRelationConfig relation)
        {
            var builder = this.Build();

            builder.Output.AddColumns(relation.RightTable.Columns);
            builder.Source.AddTable(relation.RightTable);
            builder.RelationManager.AddRelation(relation);
            builder.Filter.AddColumn(relation.LeftTable.PrimaryKey);
            builder.Sort.AddColumns(relation.RightTable.PrimaryKeys);
            return(builder);
        }
Пример #9
0
 public override bool Equals(Object obj)
 {
     if (obj is RelationConfig20)
     {
         IRelationConfig other = (IRelationConfig)obj;
         return(Name.Equals(other.Name));
     }
     else
     {
         return(false);
     }
 }
Пример #10
0
        protected virtual void VisitContains(MethodCallExpression node, IRelationConfig relation, object element)
        {
            var target = default(IFragmentTarget);

            if (!this.TryPeek(out target))
            {
                target = this.Query.Filter;
            }
            target.Write(target.CreateFunction(QueryFunction.Exists).With(function =>
            {
                var builder = this.Database.QueryFactory.Build();
                builder.Output.AddOperator(QueryOperator.Star);
                builder.Source.AddTable(relation.LeftTable.Extern());
                builder.Source.AddTable(relation.RightTable);
                builder.RelationManager.AddRelation(relation);
                function.AddArgument(function.CreateSubQuery(builder));
                this.Push(builder.Filter);
            }));
            try
            {
                this.Peek.Write(
                    this.Push(this.Peek.CreateBinary(
                                  this.Peek.CreateColumn(relation.RightTable.PrimaryKey),
                                  QueryOperator.Equal,
                                  //Leave the right expression null, we will write to this later.
                                  null
                                  )).With(binary =>
                {
                    try
                    {
                        this.VisitParameter(relation.RightTable.PrimaryKey.ColumnType.Type, relation.RightTable.PrimaryKey.Getter(element));
                    }
                    finally
                    {
                        this.Pop();
                    }
                })
                    );
            }
            finally
            {
                this.Pop();
            }
        }
Пример #11
0
 public bool Equals(IRelationConfig other)
 {
     if (other == null)
     {
         return(false);
     }
     if ((TableConfig)this.LeftTable != (TableConfig)other.LeftTable)
     {
         return(false);
     }
     if ((TableConfig)this.MappingTable != (TableConfig)other.MappingTable)
     {
         return(false);
     }
     if ((TableConfig)this.RightTable != (TableConfig)other.RightTable)
     {
         return(false);
     }
     return(true);
 }
Пример #12
0
        protected Member HandleRelationConfig(Type realType, IRelationConfig relationConfig, IMap <String, Member> relationConfigToInfoItem)
        {
            if (relationConfig == null)
            {
                return(null);
            }
            Member member = relationConfigToInfoItem.Get(relationConfig.Name);

            if (member != null)
            {
                return(member);
            }
            member = IntermediateMemberTypeProvider.GetIntermediateRelationMember(realType, relationConfig.Name);
            if (member == null)
            {
                throw new Exception("No member with name '" + relationConfig.Name + "' found on entity type '" + realType.Name + "'");
            }
            relationConfigToInfoItem.Put(relationConfig.Name, member);
            return(member);
        }
Пример #13
0
        public IEntityDifference <T, TRelation> GetDifference <T, TRelation>(IRelationConfig <T, TRelation> relation, T persisted, T updated)
        {
            var persistedChild = persisted != null?relation.Accessor.Get(persisted) : default(TRelation);

            var updatedChild = updated != null?relation.Accessor.Get(updated) : default(TRelation);

            return(new EntityDifference <T, TRelation>().With(difference =>
            {
                if (persistedChild != null && updatedChild != null)
                {
                    difference.Updated.Add(new EntityDifference <TRelation>(persistedChild, updatedChild));
                }
                else if (updatedChild != null)
                {
                    difference.Added.Add(new EntityDifference <TRelation>(default(TRelation), updatedChild));
                }
                else if (persistedChild != null)
                {
                    difference.Deleted.Add(new EntityDifference <TRelation>(persistedChild, default(TRelation)));
                }
            }));
        }
        public void SetUp()
        {
            _statementAssembler   = new T();
            _mockInputSource      = Mock.Of <IInputSource>();
            _mockStatementsConfig = Mock.Of <IStatementsConfig>();

            Mock.Get(_mockInputSource).Setup(f => f.GetEntityRecords(It.IsAny <string>()))
            .Returns(
                new List <IDictionary <string, string> >()
            {
                { new Dictionary <string, string>()
                  {
                      { "EMPNO", "7369" },
                      { "ENAME", "SMITH" },
                      { "JOB", "CLERK" },
                      { "DEPTNO", "10" },
                  } }
            }
                );

            _fakeNamespaceMap = new Dictionary <string, string>()
            {
                { "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" },
                { "ex", "http://www.example.org/ns#" }
            };

            IRelationConfig relationConfigMock = Mock.Of <IRelationConfig>();

            Mock.Get(relationConfigMock).Setup(f => f.GetRelationName()).Returns("ex:name");
            IObjectsConfig objectsConfigMock = Mock.Of <IObjectsConfig>();

            Mock.Get(objectsConfigMock).Setup(f => f.GetSourceName()).Returns("ENAME");
            Mock.Get(_mockStatementsConfig).Setup(f => f.GetClassName()).Returns("ex:Employee");
            Mock.Get(_mockStatementsConfig).Setup(f => f.GetRelationObjectConfigs()).Returns(new Dictionary <IRelationConfig, IObjectsConfig>()
            {
                { relationConfigMock, objectsConfigMock }
            });
            Mock.Get(_mockStatementsConfig).Setup(f => f.GetTemplate()).Returns("http://www.example.org/employee/{EMPNO}");
        }
Пример #15
0
 public EntityGraphNode(Type entityType, IEntityGraphNode parent, ITableConfig table, IRelationConfig relation)
 {
     this.EntityType = entityType;
     this.Parent     = parent;
     this.Table      = table;
     this.Relation   = relation;
 }
Пример #16
0
 public EntityRelationGraphNode(IEntityGraphNode parent, IRelationConfig <T, TRelation> relation) : base(parent, relation.RightTable, relation)
 {
 }
Пример #17
0
 public ForeignKeysParameterHandlerStrategy(object parent, object child, IRelationConfig relation)
 {
     this.Parent   = parent;
     this.Child    = child;
     this.Relation = relation;
 }
Пример #18
0
 protected virtual IRelationBuilder VisitRelation(IRelationConfig relation)
 {
     return(this.Peek.Write(this.Peek.CreateRelation(relation)));
 }
Пример #19
0
        protected virtual bool TryGetRelation(MemberInfo member, Expression expression, out IRelationConfig result)
        {
            var type = this.GetMemberType(member);

            if (type.IsGenericType)
            {
                type = type.GetGenericArguments()[0];
            }
            var table = this.Database.Config.GetTable(TableConfig.By(expression.Type));

            if (table != null)
            {
                foreach (var relation in table.Relations)
                {
                    if (relation.RelationType == type)
                    {
                        result = relation;
                        return(true);
                    }
                }
            }
            result = default(IRelationConfig);
            return(false);
        }
Пример #20
0
 protected virtual IEntityGraphNode <TRelation> CreateNode <T, TRelation>(IEntityGraphNode <T> parent, IRelationConfig <T, TRelation> relation)
     where T : class
     where TRelation : class
 {
     return(new EntityRelationGraphNode <T, TRelation>(parent, relation));
 }
Пример #21
0
 public DatabaseQueryRelationCacheKey(IRelationConfig relation, string id)
     : base(id)
 {
     this.Relation = relation;
 }
Пример #22
0
 public void AddRelation(IRelationConfig relation)
 {
     this.Relations.Add(relation);
     this.CalculatedRelations = null;
 }
Пример #23
0
 public IDatabaseQuery Lookup(IRelationConfig relation)
 {
     return(this.GetOrAdd(new DatabaseQueryRelationCacheKey(relation, LOOKUP_BY_RELATION), () => this.Database.QueryFactory.Lookup(relation).Build()));
 }
Пример #24
0
 public void AddRelation(IRelationConfig relation)
 {
     this.Calculator.AddRelation(relation);
 }
Пример #25
0
 public IRelationBuilder GetRelation(IRelationConfig relation)
 {
     return(this.GetExpression <IRelationBuilder>(builder => builder.Relation == relation));
 }
Пример #26
0
 public static bool Validate(IDatabase database, bool strict, IRelationConfig relation, ITransactionSource transaction = null)
 {
     return(Validate(database, strict, new[] { relation }, transaction));
 }
Пример #27
0
 public PendingEntityRelation(IRelationConfig relation, IBinaryExpressionBuilder expression)
 {
     this.Relation   = relation;
     this.Expression = expression;
 }
Пример #28
0
 public void SetUp()
 {
     _relationConfig = new T();
 }
Пример #29
0
 protected virtual void Initialize <TEntity, TRelation>(TEntity item, IRelationConfig <TEntity, TRelation> relation)
 {
     //Nothing to do.
 }
Пример #30
0
 public EntityRelation(IRelationConfig relation, ITableConfig table, IBinaryExpressionBuilder expression)
 {
     this.Relation   = relation;
     this.Table      = table;
     this.Expression = expression;
 }