コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the ObjectFactory class.
        /// </summary>
        /// <param name="currentUnit">The current unit.</param>
        /// <param name="entity">The associative entity.</param>
        public ObjectRelationsFactory(CslaGeneratorUnit currentUnit, AssociativeEntity entity)
        {
            _currentUnit               = currentUnit;
            _cslaObjects               = _currentUnit.CslaObjects;
            _entity                    = entity;
            MainObjectInfo             = _cslaObjects.Find(_entity.MainObject);
            MainRootCriteriaProperties = GetCriteriaProperties(MainObjectInfo);

            if (entity.RelationType == ObjectRelationType.ManyToMany)
            {
                SecondaryObjectInfo             = _cslaObjects.Find(_entity.SecondaryObject);
                SecondaryRootCriteriaProperties = GetCriteriaProperties(SecondaryObjectInfo);

                _associativeTable = FindAssociativeTable(MainObjectInfo, SecondaryObjectInfo);

                _resultSet = new TableResultSet(
                    _associativeTable.ResultIndex,
                    _associativeTable.Columns,
                    _associativeTable.Type);

                _dbObject = new TableDataBaseObject(
                    _associativeTable.ObjectCatalog,
                    _associativeTable.ObjectName,
                    _associativeTable.ObjectSchema,
                    _associativeTable.Catalog);
            }
            else
            {
                var mainItemObjectInfo = _cslaObjects.Find(_entity.MainItemTypeName);

                _associatedTable = FindAssociatedTable(MainObjectInfo, mainItemObjectInfo);

                _resultSet = new TableResultSet(
                    _associatedTable.ResultIndex,
                    _associatedTable.Columns,
                    _associatedTable.Type);

                _dbObject = new TableDataBaseObject(
                    _associatedTable.ObjectCatalog,
                    _associatedTable.ObjectName,
                    _associatedTable.ObjectSchema,
                    _associatedTable.Catalog);
            }
        }
コード例 #2
0
        public static bool IsItemCorrect(CslaObjectInfoCollection cslaObjects, string collectionName, string itemName)
        {
            var collectionCandidate = cslaObjects.Find(collectionName);

            if (itemName == collectionCandidate.ItemType)
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
        public static bool IsChildCorrect(CslaObjectInfoCollection cslaObjects, string parentName, string childName)
        {
            var childCandidate = cslaObjects.Find(childName);

            if (parentName == childCandidate.ParentType)
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
        public void BuildRelationObjects(AssociativeEntity.EntityFacade entity)
        {
            StringBuilder sb;
            var           isManyToMany = (_entity.RelationType == ObjectRelationType.ManyToMany);

            // make property if needed
            ChildProperty child;

            if (FacadeObjectInfo.ChildCollectionProperties.Contains(entity.PropertyName))
            {
                child = FacadeObjectInfo.ChildCollectionProperties.Find(entity.PropertyName);
            }
            else
            {
                child = new ChildProperty {
                    Name = entity.PropertyName
                };
                FacadeObjectInfo.ChildCollectionProperties.Add(child);

                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Successfully added ChildProperty {0} to {1} object.",
                                entity.PropertyName,
                                FacadeObjectInfo.ObjectName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }
            child.ParameterName   = entity.PropertyName;
            child.TypeName        = entity.CollectionTypeName;
            child.DeclarationMode = PropertyDeclaration.Managed;
            child.ReadOnly        = FacadeObjectInfo.IsReadOnlyObject();
            child.Nullable        = false;
            child.LazyLoad        = entity.LazyLoad;
            child.LoadingScheme   = entity.LoadingScheme;

            // LoadParameters might be re-filled by BuildCollectionCriteriaGet
            child.LoadParameters = entity.LoadParameters;
            child.Access         = PropertyAccess.IsPublic;
            child.Undoable       = true;

            // make collection if needed
            var coll = _cslaObjects.Find(entity.CollectionTypeName);

            if (coll == null)
            {
                coll = new CslaObjectInfo(_currentUnit)
                {
                    ObjectType = CslaObjectType.EditableChildCollection,
                    ObjectName = entity.CollectionTypeName
                };
                _currentUnit.CslaObjects.InsertAtTop(coll);

                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Successfully added {0} collection object.", entity.CollectionTypeName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }

            // populate collection
            coll.ParentType       = entity.ObjectName;
            coll.ParentProperties = BuildParentProperties(coll);
            coll.ItemType         = entity.ItemTypeName;

            // handle collection criteria
            BuildCollectionCriteriaGet(coll, entity, child);

            /* handle item */
            var item = _cslaObjects.Find(entity.ItemTypeName);

            if (item == null)
            {
                item = new CslaObjectInfo(_currentUnit)
                {
                    ObjectType = CslaObjectType.EditableChild,
                    ObjectName = entity.ItemTypeName
                };
                _currentUnit.CslaObjects.InsertAtTop(item);

                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Successfully added {0} collection item object.", entity.ItemTypeName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }

            // populate collection item
            if (!isManyToMany)
            {
                item.ParentInsertOnly = true;
            }
            else
            {
                item.ParentInsertOnly = false;
            }
            item.ParentType       = entity.CollectionTypeName;
            item.ParentProperties = BuildParentProperties(item);
            var suffix     = string.Empty;
            var objectName = entity.ItemTypeName;

            if (isManyToMany &&
                !_entity.MainLazyLoad &&
                !_entity.SecondaryLazyLoad &&
                _entity.Parent.Params.ORBItemsUseSingleSP)
            {
                suffix     = _entity.Parent.Params.ORBSingleSPSuffix;
                objectName = _entity.MainItemTypeName;
            }
            if (item.IsNotReadOnlyObject())
            {
                if (item.GenerateDataPortalInsert)
                {
                    item.InsertProcedureName = _entity.Parent.Params.GetAddProcName(objectName) + suffix;
                }
                if (item.GenerateDataPortalUpdate)
                {
                    item.UpdateProcedureName = _entity.Parent.Params.GetUpdateProcName(objectName) + suffix;
                }
            }
            else
            {
                item.InsertProcedureName = string.Empty;
                item.UpdateProcedureName = string.Empty;
            }

            // prepare for deprecate
            item.DeleteProcedureName = string.Empty;

            // handle collection item CriteriaNew
            if (!isManyToMany)
            {
                BuildCollectionItemCriteriaNew(item, null, null, false);
            }
            else
            {
                if (FacadeObjectInfo == MainObjectInfo)
                {
                    BuildCollectionItemCriteriaNew(item, null, SecondaryObjectInfo, true);
                }
                else
                {
                    BuildCollectionItemCriteriaNew(item, null, MainObjectInfo, true);
                }
            }

            // handle collection item Criteria
            if (!isManyToMany)
            {
                BuildCollectionItemCriteriaDelete(item, null, null, false);
            }
            else
            {
                if (FacadeObjectInfo == MainObjectInfo)
                {
                    BuildCollectionItemCriteriaDelete(item, MainObjectInfo, SecondaryObjectInfo, true);
                }
                else
                {
                    BuildCollectionItemCriteriaDelete(item, SecondaryObjectInfo, MainObjectInfo, true);
                }
            }
        }