Esempio n. 1
0
        public void AddToCurrentObjectGraphIndex(IReadOnlyEntity refEntity)
        {
            IEntityFieldValueList refKeyList = OperationUtils.ExtractEntityKeyValues(refEntity);

            if (!AlreadyInCurrentObjectGraph(refKeyList))
            {
                _entityFieldValueList.Add(refKeyList);
            }
        }
Esempio n. 2
0
        private static void ProcessIdentifyingRelations(IEntity entity, Type type, ITransaction tx
                                                        , EntityInfo entityInfo, ITypeFieldValueList fieldValues)
        {
            ICollection <IRelation> dbRelations = entityInfo.Relations;

            foreach (IRelation relation in dbRelations)
            {
                if (relation.ReverseRelationship ||
                    relation.NonIdentifyingRelation)
                {
                    continue;
                }
                if (IsProxyObject(entity, relation))
                {
                    continue;
                }

                ICollection <IEntity> childObjects = OperationUtils.GetRelationEntities(entity, relation);
                if (childObjects != null)
                {
                    SetRelationObjectKeyValues(fieldValues, type, relation.RelatedObjectType, childObjects, relation);
                    foreach (IEntity fieldObject in childObjects)
                    {
                        IEntityFieldValueList childEntityKeyList = OperationUtils.ExtractEntityKeyValues(fieldObject);
                        if (entity.Context.AlreadyInCurrentObjectGraph(childEntityKeyList))
                        {
                            continue;
                        }
                        fieldObject.Context.CopyReferenceStoreFrom(entity);
                        if (fieldObject.Status != EntityStatus.Deleted) //deleted items are already deleted
                        {
                            fieldObject.Persist(tx);
                            entity.Context.AddToCurrentObjectGraphIndex(fieldObject);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void Update(IEntity entity, ITypeFieldValueList valueTypeList, Type type, ITransaction tx)
        {
            EntityInfo entityInfo = CacheManager.GetEntityInfo(type);
            ICollection <EntityFieldValue> keys   = new List <EntityFieldValue>();
            ICollection <EntityFieldValue> values = new List <EntityFieldValue>();
            StringBuilder logSb = new StringBuilder();
            string        query;


            if (entityInfo.TableInfo.UpdateStrategy == UpdateStrategy.ChangedColumns)
            {
                values = GetModifiedFieldValues(entity, type);
                if (values.Count == 0)
                {
                    return;
                }

                keys = OperationUtils.ExtractEntityKeyValues(entity).FieldValues;
                ICollection <IColumn> keysAndModified = new List <IColumn>();
                foreach (EntityFieldValue fieldValue in values)
                {
                    keysAndModified.Add(fieldValue.Column);
                }
                foreach (EntityFieldValue fieldValue in keys)
                {
                    keysAndModified.Add(fieldValue.Column);
                }
                query = DbLayer.DataManipulate().CreateUpdateQuery(entityInfo.TableInfo.TableName, keysAndModified);
            }
            else
            {
                query = entityInfo.GetUpdateQuery(DbLayer);
                foreach (EntityFieldValue fieldValue in valueTypeList.FieldValues)
                {
                    if (fieldValue.Column.Key)
                    {
                        keys.Add(fieldValue);
                    }
                    else
                    {
                        values.Add(fieldValue);
                    }
                }
            }

            bool showQuery = Config.ShowQueries;

            if (showQuery)
            {
                logSb.Append(query);
            }

            IDbCommand cmd = tx.CreateCommand();

            cmd.CommandText = query;
            int count = 0;

            foreach (EntityFieldValue fieldValue in values)
            {
                if (showQuery)
                {
                    logSb.Append(" ,").Append(fieldValue.Column.ColumnName).Append("=").Append(fieldValue.Value);
                }
                DbLayer.DataManipulate().SetToPreparedStatement(cmd, fieldValue.Value, ++count, fieldValue.Column);
            }

            foreach (EntityFieldValue fieldValue in keys)
            {
                if (showQuery)
                {
                    logSb.Append(" ,").Append(fieldValue.Column.ColumnName).Append("=").Append(fieldValue.Value);
                }
                DbLayer.DataManipulate().SetToPreparedStatement(cmd, fieldValue.Value, ++count, fieldValue.Column);
            }
            if (showQuery)
            {
                Logger.GetLogger(Config.LoggerName).Debug(logSb.ToString());
            }
            if (Config.EnableStatistics)
            {
                Statistics.RegisterUpdate(type);
            }
            cmd.ExecuteNonQuery();
            DbMgtUtility.Close(cmd);
        }