示例#1
0
        private Object ExtractCurrentVersionValue(IReadOnlyEntity entity, IColumn versionColumn, Type type
                                                  , ITransaction tx)
        {
            Object versionValue = null;

            ITypeFieldValueList keyFieldValueList = OperationUtils.ExtractEntityTypeKeyValues(entity, type);
            IDbCommand          cmd    = null;
            IDataReader         reader = null;

            try
            {
                cmd    = CreateRetrievalPreparedStatement(keyFieldValueList, tx);
                reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    versionValue = DbLayer.DataManipulate().ReadFromResultSet(reader, versionColumn);
                }
            }
            catch (Exception ex)
            {
                String message = String.Format("SQL Exception while trying retrieve version information from {0}"
                                               , entity.GetType().FullName);
                throw new StatementExecutionException(message, ex);
            }
            finally
            {
                DbMgtUtility.Close(reader);
                DbMgtUtility.Close(cmd);
            }
            return(versionValue);
        }
示例#2
0
        private ICollection <EntityFieldValue> GetModifiedFieldValues(IReadOnlyEntity entity, Type type)
        {
            EntityInfo                     entityInfo      = CacheManager.GetEntityInfo(type);
            ICollection <IColumn>          typeColumns     = entityInfo.Columns;
            ITypeFieldValueList            currentValues   = OperationUtils.ExtractEntityTypeFieldValues(entity, type);
            ICollection <EntityFieldValue> modifiedColumns = new  List <EntityFieldValue>();

            foreach (IColumn typeColumn in typeColumns)
            {
                if (typeColumn.Key)
                {
                    continue;
                }

                EntityFieldValue classFieldValue    = currentValues.GetFieldValue(typeColumn.AttributeName);
                EntityFieldValue originalFieldValue = entity.Context != null?entity.Context.ChangeTracker.GetFieldValue(typeColumn.AttributeName) : null;

                bool matches = originalFieldValue != null && classFieldValue != null && classFieldValue.Value == originalFieldValue.Value ||
                               (originalFieldValue != null && classFieldValue != null && classFieldValue.Value != null && classFieldValue.Value.Equals(originalFieldValue.Value));
                if (!matches)
                {
                    modifiedColumns.Add(classFieldValue);
                }
            }
            return(modifiedColumns);
        }
示例#3
0
        private ITypeFieldValueList ExtractCurrentRowValues(IReadOnlyEntity entity, Type type, ITransaction tx)
        {
            ITypeFieldValueList fieldValueList = null;

            ITypeFieldValueList keyFieldValueList = OperationUtils.ExtractEntityTypeKeyValues(entity, type);
            IDbCommand          cmd    = null;
            IDataReader         reader = null;

            try
            {
                cmd    = CreateRetrievalPreparedStatement(keyFieldValueList, tx);
                reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    fieldValueList = ReadValues(type, reader);
                }
            }
            catch (Exception ex)
            {
                string message = String.Format("SQL Exception while trying retrieve current data row from {0}"
                                               , entity.GetType().FullName);
                throw new StatementExecutionException(message, ex);
            }
            finally
            {
                DbMgtUtility.Close(reader);
                DbMgtUtility.Close(cmd);
            }
            return(fieldValueList);
        }
示例#4
0
        private void FillChangeTrackerValues(IEntity entity, ITransaction tx, IEntityContext entityContext)
        {
            if (entity.Status == EntityStatus.New ||
                entity.Status == EntityStatus.Deleted)
            {
                return;
            }

            EntityInfo entityInfo = CacheManager.GetEntityInfo(entity);

            while (entityInfo != null)
            {
                ITypeFieldValueList values = ExtractCurrentRowValues(entity, entityInfo.EntityType, tx);
                entityContext.ChangeTracker.AddFields(values.FieldValues);

                ICollection <IRelation> dbRelations = entityInfo.Relations;
                foreach (IRelation relation in dbRelations)
                {
                    ICollection <IReadOnlyEntity> children = ReadRelationChildrenFromDb(entity, entityInfo.EntityType, tx, relation);
                    foreach (IReadOnlyEntity childEntity in children)
                    {
                        ITypeFieldValueList valueTypeList = OperationUtils.ExtractRelationKeyValues(childEntity, relation);
                        if (valueTypeList != null)
                        {
                            entityContext.ChangeTracker.AddChildEntityKey(valueTypeList);
                        }
                    }
                }
                entityInfo = entityInfo.SuperEntityInfo;
            }
        }
示例#5
0
        private static void SetParentRelationFieldsForNonIdentifyingRelations(IEntity parentEntity
                                                                              , IEnumerable <IEntity> childObjects, RelationColumnMapping mapping)
        {
            IReadOnlyEntity       firstObject     = null;
            IEnumerator <IEntity> childEnumerator = childObjects.GetEnumerator();

            if (childEnumerator.MoveNext())
            {
                firstObject = childEnumerator.Current;
            }
            if (firstObject == null)
            {
                return;
            }
            EntityInfo parentInfo = CacheManager.GetEntityInfo(parentEntity);
            EntityInfo childInfo  = CacheManager.GetEntityInfo(firstObject);

            PropertyInfo setter    = null;
            bool         foundOnce = false;

            while (parentInfo != null)
            {
                IColumn parentMatchedColumn = parentInfo.FindColumnByAttribute(mapping.FromField);
                if (parentMatchedColumn != null)
                {
                    foundOnce = true;
                    setter    = parentInfo.GetProperty(parentMatchedColumn);
                }
                parentInfo = parentInfo.SuperEntityInfo;
            }
            if (!foundOnce)
            {
                string message = String.Format("The field {0} does not have a matching field in the object {1}", mapping.ToField, firstObject.GetType().FullName);
                throw new NoMatchingColumnFoundException(message);
            }

            foundOnce = false;
            while (childInfo != null)
            {
                IColumn childMatchedColumn = childInfo.FindColumnByAttribute(mapping.ToField);

                if (childMatchedColumn != null)
                {
                    foundOnce = true;
                    foreach (IReadOnlyEntity dbObject in childObjects)
                    {
                        ITypeFieldValueList fieldValueList  = OperationUtils.ExtractEntityTypeFieldValues(dbObject, childInfo.EntityType);
                        EntityFieldValue    childFieldValue = fieldValueList.GetFieldValue(childMatchedColumn.AttributeName);
                        setter.SetValue(parentEntity, childFieldValue.Value, null);
                    }
                }
                childInfo = childInfo.SuperEntityInfo;
            }
            if (!foundOnce)
            {
                string message = String.Format("The field {0} does not have a matching field in the object {1}", mapping.ToField, firstObject.GetType().FullName);
                throw new NoMatchingColumnFoundException(message);
            }
        }
示例#6
0
        private void SaveForType(IEntity entity, Type type, ITransaction tx)
        {
            EntityInfo entityInfo = CacheManager.GetEntityInfo(type);

            if (entityInfo == null)
            {
                return;
            }

            ProcessNonIdentifyingRelations(entity, entityInfo);

            ITypeFieldValueList fieldValues = OperationUtils.ExtractEntityTypeFieldValues(entity, type);

            if (entity.Status == EntityStatus.Unmodified)
            {
                //do nothing
            }
            else if (entity.Status == EntityStatus.New)
            {
                Insert(entity, fieldValues, type, tx);
            }
            else if (entity.Status == EntityStatus.Modified)
            {
                if (entityInfo.TableInfo.VerifyOnWriteStrategy == VerifyOnWriteStrategy.Verify)
                {
                    if (!VersionValidated(entity, type, tx))
                    {
                        throw new DataUpdatedFromAnotherSourceException(String.Format("The type {0} updated from another transaction", type));
                    }
                    OperationUtils.IncrementVersion(fieldValues);
                    SetValues(entity, fieldValues);
                }
                Update(entity, fieldValues, type, tx);
            }
            else if (entity.Status == EntityStatus.Deleted)
            {
                Delete(fieldValues, type, tx);
            }
            else
            {
                string message = String.Format("In-corret status for class {0}", type.FullName);
                throw new IncorrectStatusException(message);
            }

            fieldValues = OperationUtils.ExtractEntityTypeFieldValues(entity, type);
            IEntityContext entityContext = entity.Context;

            if (entityContext != null)
            {
                entityContext.ChangeTracker.AddFields(fieldValues.FieldValues);
            }
            entity.Context.AddToCurrentObjectGraphIndex(entity);

            ProcessIdentifyingRelations(entity, type, tx, entityInfo, fieldValues);
        }
示例#7
0
        public void AddChildEntityKey(ITypeFieldValueList list)
        {
            lock (this)
            {
                var tmpList = new List <ITypeFieldValueList>();
                tmpList.AddRange(_childEntityRelationKeys);
                tmpList.Add(list);

                _childEntityRelationKeys = new ReadOnlyCollection <ITypeFieldValueList>(tmpList);
            }
        }
示例#8
0
 public IReadOnlyEntity GetFromCurrentObjectGraph(ITypeFieldValueList keys)
 {
     foreach (IEntityFieldValueList existingEntity in _entityFieldValueList)
     {
         if (OperationUtils.IsTypeKeyEquals(keys, existingEntity))
         {
             return(existingEntity.Entity);
         }
     }
     return(null);
 }
示例#9
0
        private void Insert(IEntity entity, ITypeFieldValueList valueTypeList, Type entityType, ITransaction tx)
        {
            EntityInfo entityInfo = CacheManager.GetEntityInfo(entityType);

            StringBuilder logSb = new StringBuilder();
            string        query = entityInfo.GetInsertQuery(DbLayer);
            IDbCommand    cmd   = tx.CreateCommand();

            cmd.CommandText = query;

            bool showQuery = Config.ShowQueries;

            if (showQuery)
            {
                logSb.Append(query);
            }
            int i = 0;

            foreach (EntityFieldValue fieldValue in valueTypeList.FieldValues)
            {
                IColumn column = fieldValue.Column;
                Object  columnValue;

                if (column.ReadFromSequence &&
                    column.SequenceGenerator != null)
                {
                    columnValue = column.SequenceGenerator.GetNextSequenceValue(tx);
                    PropertyInfo setter = entityType.GetProperty(column.AttributeName);
                    ReflectionUtils.SetValue(setter, entity, columnValue);
                }
                else
                {
                    columnValue = fieldValue.Value;
                }
                if (showQuery)
                {
                    logSb.Append(" ,").Append(column.ColumnName).Append("=").Append(columnValue);
                }
                DbLayer.DataManipulate().SetToPreparedStatement(cmd, columnValue, i + 1, column);
                i++;
            }
            if (showQuery)
            {
                Logger.GetLogger(Config.LoggerName).Debug(logSb.ToString());
            }
            if (Config.EnableStatistics)
            {
                Statistics.RegisterInsert(entityType);
            }
            cmd.ExecuteNonQuery();
            DbMgtUtility.Close(cmd);
        }
示例#10
0
 public static void IncrementVersion(ITypeFieldValueList fieldValues)
 {
     foreach (EntityFieldValue fieldValue in fieldValues.FieldValues)
     {
         if (fieldValue.Column.ColumnType == ColumnType.Version)
         {
             int version = int.Parse(fieldValue.Value.ToString());
             version++;
             fieldValue.Value = version;
             break;
         }
     }
 }
示例#11
0
        protected static void SetValues(IReadOnlyEntity roEntity, ITypeFieldValueList values)
        {
            EntityInfo entityInfo = CacheManager.GetEntityInfo(roEntity);

            foreach (EntityFieldValue fieldValue in values.FieldValues)
            {
                if (entityInfo.FindRelationColumnInfo(fieldValue.Column.AttributeName) == null)
                {
                    PropertyInfo setter = entityInfo.GetProperty(fieldValue.Column.AttributeName);
                    ReflectionUtils.SetValue(setter, roEntity, fieldValue.Value);
                }
            }
        }
示例#12
0
        protected IDbCommand CreateRetrievalPreparedStatement(ITypeFieldValueList keyValueList, ITransaction tx)
        {
            Type       targetType = keyValueList.Type;
            EntityInfo entityInfo = CacheManager.GetEntityInfo(targetType);
            string     query      = entityInfo.GetLoadQuery(DbLayer);

            IDbCommand cmd;

            try
            {
                cmd             = tx.CreateCommand();
                cmd.CommandText = query;
            }
            catch (Exception ex)
            {
                string message = String.Format("SQL Exception while trying create command for sql {0}", query);
                throw new CommandCreationException(message, ex);
            }

            ICollection <IColumn> keys = entityInfo.GetKeys();

            StringBuilder logSb     = new StringBuilder();
            bool          showQuery = Config.ShowQueries;

            if (showQuery)
            {
                logSb.Append(query);
            }
            int i = 0;

            foreach (IColumn key in keys)
            {
                Object fieldValue = keyValueList.GetFieldValue(key.AttributeName).Value;
                if (showQuery)
                {
                    logSb.Append(" ,").Append(key.ColumnName).Append("=").Append(fieldValue);
                }
                DbLayer.DataManipulate().SetToPreparedStatement(cmd, fieldValue, ++i, key);
            }
            if (showQuery)
            {
                Logger.GetLogger(Config.LoggerName).Debug(logSb.ToString());
            }
            if (Config.EnableStatistics)
            {
                Statistics.RegisterSelect(targetType);
            }
            return(cmd);
        }
示例#13
0
        private void LoadFromDb(IReadOnlyEntity roEntity, IDataReader reader, ITransaction tx)
        {
            EntityInfo entityInfo = CacheManager.GetEntityInfo(roEntity);

            while (entityInfo != null)
            {
                string tableName = entityInfo.TableInfo.TableName;
                if (entityInfo.EntityType == roEntity.GetType() || tableName == null) //if i==0 that means it's base class and can use existing result set
                {
                    LoadForType(roEntity, entityInfo.EntityType, reader, tx);
                }
                else
                {
                    IDbCommand  superCmd    = null;
                    IDataReader superReader = null;
                    try
                    {
                        ITypeFieldValueList keyValueList = OperationUtils.ExtractEntityTypeKeyValues(roEntity, entityInfo.EntityType);
                        superCmd    = CreateRetrievalPreparedStatement(keyValueList, tx);
                        superReader = superCmd.ExecuteReader();
                        if (superReader.Read())
                        {
                            LoadForType(roEntity, entityInfo.EntityType, superReader, tx);
                        }
                        else
                        {
                            string message =
                                String.Format(
                                    "Super class {0} does not contains a matching record for the base class {1}",
                                    entityInfo.EntityType.FullName, roEntity.GetType().FullName);
                            throw new NoMatchingRecordFoundForSuperClassException(message);
                        }
                    }
                    catch (Exception ex)
                    {
                        String message = String.Format("SQL Exception while trying to read from table {0}", tableName);
                        throw new ReadFromResultSetException(message, ex);
                    }
                    finally
                    {
                        DbMgtUtility.Close(superReader);
                        DbMgtUtility.Close(superCmd);
                    }
                }
                entityInfo = entityInfo.SuperEntityInfo;
            }
        }
示例#14
0
        private bool VersionValidated(IReadOnlyEntity entity, Type type, ITransaction tx)
        {
            EntityInfo            entityInfo  = CacheManager.GetEntityInfo(type);
            ICollection <IColumn> typeColumns = entityInfo.Columns;

            foreach (IColumn typeColumn in typeColumns)
            {
                if (typeColumn.ColumnType == ColumnType.Version)
                {
                    Object           classValue         = ExtractCurrentVersionValue(entity, typeColumn, type, tx);
                    EntityFieldValue originalFieldValue = entity.Context.ChangeTracker.GetFieldValue(typeColumn.AttributeName);
                    return(originalFieldValue != null && classValue == originalFieldValue.Value ||
                           (originalFieldValue != null && classValue != null && classValue.Equals(originalFieldValue.Value)));
                }
            }

            if (entityInfo.TableInfo.UpdateStrategy == UpdateStrategy.ChangedColumns)
            {
                ICollection <EntityFieldValue> modified = GetModifiedFieldValues(entity, type);
                typeColumns = new List <IColumn>();
                foreach (EntityFieldValue fieldValue in modified)
                {
                    typeColumns.Add(fieldValue.Column);
                }
            }

            ITypeFieldValueList fieldValueList = ExtractCurrentRowValues(entity, type, tx);

            if (fieldValueList == null)
            {
                return(false);
            }
            foreach (IColumn typeColumn in typeColumns)
            {
                EntityFieldValue classFieldValue    = fieldValueList.GetFieldValue(typeColumn.AttributeName);
                EntityFieldValue originalFieldValue = entity.Context != null?entity.Context.ChangeTracker.GetFieldValue(typeColumn.AttributeName) : null;

                bool matches = originalFieldValue != null && classFieldValue != null && classFieldValue.Value == originalFieldValue.Value ||
                               (originalFieldValue != null && classFieldValue != null && classFieldValue.Value != null && classFieldValue.Value.Equals(originalFieldValue.Value));
                if (!matches)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#15
0
        private void Delete(ITypeFieldValueList valueTypeList, Type type, ITransaction tx)
        {
            EntityInfo               entityInfo = CacheManager.GetEntityInfo(type);
            StringBuilder            logSb      = new StringBuilder();
            string                   query      = entityInfo.GetDeleteQuery(DbLayer);
            IList <EntityFieldValue> keys       = new List <EntityFieldValue>();

            foreach (EntityFieldValue fieldValue in valueTypeList.FieldValues)
            {
                if (fieldValue.Column.Key)
                {
                    keys.Add(fieldValue);
                }
            }

            bool showQuery = Config.ShowQueries;

            if (showQuery)
            {
                logSb.Append(query);
            }
            IDbCommand ps = tx.CreateCommand();

            ps.CommandText = query;
            for (int i = 0; i < keys.Count; i++)
            {
                EntityFieldValue fieldValue = keys[i];

                if (showQuery)
                {
                    logSb.Append(" ,").Append(fieldValue.Column.ColumnName).Append("=").Append(fieldValue.Value);
                }
                DbLayer.DataManipulate().SetToPreparedStatement(ps, fieldValue.Value, i + 1, fieldValue.Column);
            }
            if (showQuery)
            {
                Logger.GetLogger(Config.LoggerName).Debug(logSb.ToString());
            }
            if (Config.EnableStatistics)
            {
                Statistics.RegisterDelete(type);
            }
            ps.ExecuteNonQuery();
            DbMgtUtility.Close(ps);
        }
示例#16
0
        protected static ICollection <ITypeFieldValueList> GetChildEntityValueList(IEntity parentEntity, bool takeDeleted)
        {
            EntityInfo entityInfo = CacheManager.GetEntityInfo(parentEntity);
            ICollection <ITypeFieldValueList> existingEntityChildRelations = new List <ITypeFieldValueList>();

            while (entityInfo != null)
            {
                ICollection <IRelation> typeRelations = entityInfo.Relations;
                foreach (IRelation typeRelation in typeRelations)
                {
                    if (typeRelation.ReverseRelationship)
                    {
                        continue;
                    }
                    if (IsProxyObject(parentEntity, typeRelation))
                    {
                        continue;
                    }

                    ICollection <IEntity> childEntities = OperationUtils.GetRelationEntities(parentEntity, typeRelation);
                    foreach (IEntity childEntity in childEntities)
                    {
                        if (parentEntity.Status == EntityStatus.Deleted &&
                            typeRelation.DeleteRule == ReferentialRuleType.Cascade)
                        {
                            childEntity.Status = EntityStatus.Deleted;
                        }
                        if (childEntity.Status == EntityStatus.Deleted && !takeDeleted)
                        {
                            continue;
                        }
                        ITypeFieldValueList childKeyValueList = OperationUtils.ExtractRelationKeyValues(childEntity, typeRelation);
                        if (childKeyValueList != null)
                        {
                            existingEntityChildRelations.Add(childKeyValueList);
                        }
                    }
                }
                entityInfo = entityInfo.SuperEntityInfo;
            }
            return(existingEntityChildRelations);
        }
示例#17
0
        private void LoadForType(IReadOnlyEntity entity, Type type, IDataReader reader, ITransaction tx)
        {
            EntityInfo          entityInfo    = CacheManager.GetEntityInfo(type);
            IEntityContext      entityContext = entity.Context;
            ITypeFieldValueList valueTypeList = ReadValues(type, reader);

            SetValues(entity, valueTypeList);
            entity.Context.AddToCurrentObjectGraphIndex(entity);

            if (entityContext != null)
            {
                entityContext.ChangeTracker.AddFields(valueTypeList.FieldValues);
            }

            ICollection <IRelation> dbRelations = entityInfo.Relations;

            foreach (IRelation relation in dbRelations)
            {
                LoadChildrenFromRelation(entity, type, tx, relation, false);
            }
        }
示例#18
0
        private static void SetRelationObjectKeyValues(ITypeFieldValueList valueTypeList, Type entityType, Type childEntityType
                                                       , IEnumerable <IEntity> childObjects, IRelation relation)
        {
            EntityInfo            entityInfo = CacheManager.GetEntityInfo(entityType);
            ICollection <IColumn> columns    = entityInfo.Columns;

            foreach (RelationColumnMapping mapping in relation.TableColumnMappings)
            {
                IColumn          matchColumn = entityInfo.FindColumnByAttribute(mapping.FromField);
                EntityFieldValue fieldValue  = valueTypeList.GetFieldValue(matchColumn.AttributeName);

                if (fieldValue != null)
                {
                    SetChildPrimaryKeys(fieldValue, childEntityType, childObjects, mapping);
                }
                else
                {
                    string message = String.Format("The column {0} does not have a matching column in the object {1}", matchColumn.ColumnName, valueTypeList.Type.FullName);
                    throw new NoMatchingColumnFoundException(message);
                }
            }
        }
示例#19
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);
                        }
                    }
                }
            }
        }
示例#20
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);
        }
示例#21
0
 public bool AlreadyInCurrentObjectGraph(ITypeFieldValueList keys)
 {
     return(GetFromCurrentObjectGraph(keys) != null);
 }
示例#22
0
 public IReadOnlyEntity GetFromCurrentObjectGraph(ITypeFieldValueList keys)
 {
     InitReferenceStore();
     return(_referenceStore.GetFromCurrentObjectGraph(keys));
 }
示例#23
0
 public bool AlreadyInCurrentObjectGraph(ITypeFieldValueList keys)
 {
     InitReferenceStore();
     return(_referenceStore.AlreadyInCurrentObjectGraph(keys));
 }
示例#24
0
        public void LoadChildrenFromRelation(IReadOnlyEntity parentRoEntity, Type entityType, ITransaction tx
                                             , IRelation relation, bool lazy)
        {
            EntityInfo     entityInfo    = CacheManager.GetEntityInfo(entityType);
            IEntityContext entityContext = parentRoEntity.Context;

            PropertyInfo property = entityInfo.GetProperty(relation.AttributeName);
            Object       value    = ReflectionUtils.GetValue(property, parentRoEntity);

            if (!lazy && relation.FetchStrategy == FetchStrategy.Lazy)
            {
                CreateProxy(parentRoEntity, entityType, tx, relation, value, property);
                return;
            }

            ICollection <IReadOnlyEntity> children = ReadRelationChildrenFromDb(parentRoEntity, entityType, tx, relation);

            if (entityContext != null &&
                !relation.ReverseRelationship)
            {
                foreach (IReadOnlyEntity childEntity in children)
                {
                    ITypeFieldValueList valueTypeList = OperationUtils.ExtractRelationKeyValues(childEntity, relation);
                    if (valueTypeList != null)
                    {
                        entityContext.ChangeTracker.AddChildEntityKey(valueTypeList);
                    }
                }
            }

            if ((value == null || ProxyUtil.IsProxyType(value.GetType())) &&
                ReflectionUtils.IsImplementInterface(property.PropertyType, typeof(ICollection <>)))
            {
                Type propertyType = property.PropertyType;
                if (propertyType.IsInterface)
                {
                    Type generic = propertyType.GetGenericArguments()[0];
                    propertyType = typeof(List <>).MakeGenericType(new Type[] { generic });
                }
                value = Activator.CreateInstance(propertyType);

                IList genCollection = (IList)value;
                foreach (IReadOnlyEntity serverRoDbClass in children)
                {
                    genCollection.Add(serverRoDbClass);
                }
                ReflectionUtils.SetValue(property, parentRoEntity, genCollection);
            }
            else if (value != null &&
                     ReflectionUtils.IsImplementInterface(property.PropertyType, typeof(ICollection <>)))
            {
                IList genCollection = (IList)value;
                foreach (IReadOnlyEntity serverRoDbClass in children)
                {
                    genCollection.Add(serverRoDbClass);
                }
            }
            else
            {
                IEnumerator <IReadOnlyEntity> childEnumarator = children.GetEnumerator();
                if (childEnumarator.MoveNext())
                {
                    IReadOnlyEntity singleRoDbClass = childEnumarator.Current;
                    if (property.PropertyType.IsAssignableFrom(singleRoDbClass.GetType()))
                    {
                        ReflectionUtils.SetValue(property, parentRoEntity, singleRoDbClass);
                    }
                    else
                    {
                        string message = singleRoDbClass.GetType().FullName + " is not matching the getter " + property.Name;
                        Logger.GetLogger(Config.LoggerName).Fatal(message);
                        throw new NoSetterFoundToSetChildObjectListException(message);
                    }
                }
            }
        }
示例#25
0
 public static bool IsTypeKeyEquals(ITypeFieldValueList item1, ITypeFieldValueList item2)
 {
     return(item1.Type == item2.Type && IsValueKeyEquals(item1, item2));
 }