// effects: Given a list of cells in the schema, generates the query and
        // update mapping views for OFTYPE(Extent, Type) combinations in this schema
        // container. Returns a list of generated query and update views.
        // If it is false and some columns in a table are unmapped, an
        // exception is raised
        private static ViewGenResults GenerateViewsFromCells(List<Cell> cells, ConfigViewGenerator config,
                                                                   CqlIdentifiers identifiers,
                                                                   StorageEntityContainerMapping containerMapping)
        {
            EntityUtil.CheckArgumentNull(cells, "cells");
            EntityUtil.CheckArgumentNull(config, "config");
            Debug.Assert(cells.Count > 0, "There must be at least one cell in the container mapping");


            // Go through each table and determine their foreign key constraints
            EntityContainer container = containerMapping.StorageEntityContainer;
            Debug.Assert(container != null);

            ViewGenResults viewGenResults = new ViewGenResults();
            ErrorLog tmpLog = EnsureAllCSpaceContainerSetsAreMapped(cells, config, containerMapping);
            if (tmpLog.Count > 0)
            {
                viewGenResults.AddErrors(tmpLog);
                Helpers.StringTraceLine(viewGenResults.ErrorsToString());
                return viewGenResults;
            }

            List<ForeignConstraint> foreignKeyConstraints = ForeignConstraint.GetForeignConstraints(container);

            CellPartitioner partitioner = new CellPartitioner(cells, foreignKeyConstraints);
            List<CellGroup> cellGroups = partitioner.GroupRelatedCells();
            foreach (CellGroup cellGroup in cellGroups)
            {
                ViewGenerator viewGenerator = null;
                ErrorLog groupErrorLog = new ErrorLog();
                try
                {
                    viewGenerator = new ViewGenerator(cellGroup, config, foreignKeyConstraints, containerMapping);
                }
                catch (InternalMappingException exception)
                {
                    // All exceptions have mapping errors in them
                    Debug.Assert(exception.ErrorLog.Count > 0, "Incorrectly created mapping exception");
                    groupErrorLog = exception.ErrorLog;
                }

                if (groupErrorLog.Count == 0)
                {
                    Debug.Assert(viewGenerator != null);
                    groupErrorLog = viewGenerator.GenerateAllBidirectionalViews(viewGenResults.Views, identifiers);
                }

                if (groupErrorLog.Count != 0)
                {
                    viewGenResults.AddErrors(groupErrorLog);
                }
            }
            // We used to print the errors here. Now we trace them as they are being thrown
            //if (viewGenResults.HasErrors && config.IsViewTracing) {
            //    Helpers.StringTraceLine(viewGenResults.ErrorsToString());
            //}
            return viewGenResults;
        }
        // effects: Given a list of cells in the schema, generates the query and
        // update mapping views for OFTYPE(Extent, Type) combinations in this schema
        // container. Returns a list of generated query and update views.
        // If it is false and some columns in a table are unmapped, an
        // exception is raised
        private static ViewGenResults GenerateViewsFromCells(List <Cell> cells, ConfigViewGenerator config,
                                                             CqlIdentifiers identifiers,
                                                             StorageEntityContainerMapping containerMapping)
        {
            EntityUtil.CheckArgumentNull(cells, "cells");
            EntityUtil.CheckArgumentNull(config, "config");
            Debug.Assert(cells.Count > 0, "There must be at least one cell in the container mapping");


            // Go through each table and determine their foreign key constraints
            EntityContainer container = containerMapping.StorageEntityContainer;

            Debug.Assert(container != null);

            ViewGenResults viewGenResults = new ViewGenResults();
            ErrorLog       tmpLog         = EnsureAllCSpaceContainerSetsAreMapped(cells, config, containerMapping);

            if (tmpLog.Count > 0)
            {
                viewGenResults.AddErrors(tmpLog);
                Helpers.StringTraceLine(viewGenResults.ErrorsToString());
                return(viewGenResults);
            }

            List <ForeignConstraint> foreignKeyConstraints = ForeignConstraint.GetForeignConstraints(container);

            CellPartitioner  partitioner = new CellPartitioner(cells, foreignKeyConstraints);
            List <CellGroup> cellGroups  = partitioner.GroupRelatedCells();

            foreach (CellGroup cellGroup in cellGroups)
            {
                ViewGenerator viewGenerator = null;
                ErrorLog      groupErrorLog = new ErrorLog();
                try
                {
                    viewGenerator = new ViewGenerator(cellGroup, config, foreignKeyConstraints, containerMapping);
                }
                catch (InternalMappingException exception)
                {
                    // All exceptions have mapping errors in them
                    Debug.Assert(exception.ErrorLog.Count > 0, "Incorrectly created mapping exception");
                    groupErrorLog = exception.ErrorLog;
                }

                if (groupErrorLog.Count == 0)
                {
                    Debug.Assert(viewGenerator != null);
                    groupErrorLog = viewGenerator.GenerateAllBidirectionalViews(viewGenResults.Views, identifiers);
                }

                if (groupErrorLog.Count != 0)
                {
                    viewGenResults.AddErrors(groupErrorLog);
                }
            }
            // We used to print the errors here. Now we trace them as they are being thrown
            //if (viewGenResults.HasErrors && config.IsViewTracing) {
            //    Helpers.StringTraceLine(viewGenResults.ErrorsToString());
            //}
            return(viewGenResults);
        }