예제 #1
0
        private void DeleteOrphanChildren(ITransaction tx, IEnumerable <ITypeFieldValueList> childrenToDelete)
        {
            foreach (ITypeFieldValueList relationKeyValueList in childrenToDelete)
            {
                EntityInfo entityInfo = CacheManager.GetEntityInfo(relationKeyValueList.Type);
                if (entityInfo == null)
                {
                    continue;
                }

                if (relationKeyValueList is EntityRelationFieldValueList)
                {
                    EntityRelationFieldValueList entityRelationFieldValueList = (EntityRelationFieldValueList)relationKeyValueList;
                    if (entityRelationFieldValueList.Relation.ReverseRelationship ||
                        entityRelationFieldValueList.Relation.NonIdentifyingRelation)
                    {
                        continue;
                    }
                }

                bool        recordExists = false;
                IDbCommand  cmd          = null;
                IDataReader reader       = null;
                try
                {
                    cmd    = CreateRetrievalPreparedStatement(relationKeyValueList, tx);
                    reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        recordExists = true;
                    }
                }
                catch (Exception ex)
                {
                    string message =
                        String.Format(
                            "SQL Exception while trying determine if orphan child entities are available for type {0}",
                            relationKeyValueList.Type.FullName);
                    throw new StatementExecutionException(message, ex);
                }
                finally
                {
                    DbMgtUtility.Close(reader);
                    DbMgtUtility.Close(cmd);
                }

                if (recordExists)
                {
                    Delete(relationKeyValueList, relationKeyValueList.Type, tx);
                }
            }
        }
예제 #2
0
 private static void ValidateForChildDeletion(IEntity currentEntity, IEnumerable <ITypeFieldValueList> currentChildren)
 {
     foreach (ITypeFieldValueList keyValueList in currentChildren)
     {
         EntityRelationFieldValueList entityRelationKeyValueList = (EntityRelationFieldValueList)keyValueList;
         if (entityRelationKeyValueList.Relation.DeleteRule == ReferentialRuleType.Restrict &&
             !entityRelationKeyValueList.Relation.ReverseRelationship &&
             currentEntity.Status == EntityStatus.Deleted)
         {
             throw new IntegrityConstraintViolationException(String.Format("Cannot delete child object {0} as restrict constraint in place", keyValueList.Type.FullName));
         }
     }
 }
예제 #3
0
        public static ITypeFieldValueList ExtractRelationKeyValues(IReadOnlyEntity child, IRelation relation)
        {
            EntityRelationFieldValueList valueList = null;

            if (child is IEntity)
            {
                valueList = new EntityRelationFieldValueList(relation);
                IEntity childDbClass = (IEntity)child;
                ICollection <EntityFieldValue> extractedValues = ExtractValues(childDbClass, true, null);
                foreach (EntityFieldValue entityFieldValue in extractedValues)
                {
                    valueList.FieldValues.Add(entityFieldValue);
                }
            }
            return(valueList);
        }