protected void Persist(INakedObject nakedObject, IPersistedObjectAdder persistor) {
            if (nakedObject.ResolveState.IsAggregated() ||
                (nakedObject.ResolveState.IsTransient() &&
                 nakedObject.Specification.Persistable != Persistable.TRANSIENT)) {
                INakedObjectAssociation[] fields = nakedObject.Specification.Properties;
                if (!nakedObject.Specification.IsEncodeable && fields.Length > 0) {
                    Log.Info("make persistent " + nakedObject);
                    nakedObject.Persisting();
                    if (!nakedObject.Specification.ContainsFacet(typeof (IComplexTypeFacet))) {
                        persistor.MadePersistent(nakedObject);
                    }

                    foreach (INakedObjectAssociation field in fields) {
                        if (!field.IsPersisted) {
                            continue;
                        }
                        if (field is IOneToManyAssociation) {
                            INakedObject collection = field.GetNakedObject(nakedObject);
                            if (collection == null) {
                                throw new NotPersistableException("Collection " + field.Name + " does not exist in " + nakedObject.Specification.FullName);
                            }
                            MakePersistent(collection, persistor);
                        }
                        else {
                            INakedObject fieldValue = field.GetNakedObject(nakedObject);
                            if (fieldValue == null) {
                                continue;
                            }
                            Persist(fieldValue, persistor);
                        }
                    }
                    persistor.AddPersistedObject(nakedObject);
                }
            }
        }
Exemple #2
0
        private void Persist(INakedObject nakedObject)
        {
            if (nakedObject.ResolveState.IsAggregated() || (nakedObject.ResolveState.IsTransient() && nakedObject.Spec.Persistable != PersistableType.Transient))
            {
                IAssociationSpec[] fields = ((IObjectSpec)nakedObject.Spec).Properties;
                if (!nakedObject.Spec.IsEncodeable && fields.Length > 0)
                {
                    Log.Info("make persistent " + nakedObject);
                    nakedObject.Persisting();
                    if (!nakedObject.Spec.ContainsFacet(typeof(IComplexTypeFacet)))
                    {
                        manager.MadePersistent(nakedObject);
                    }

                    foreach (IAssociationSpec field in fields)
                    {
                        if (!field.IsPersisted)
                        {
                            continue;
                        }
                        if (field is IOneToManyAssociationSpec)
                        {
                            INakedObject collection = field.GetNakedObject(nakedObject);
                            if (collection == null)
                            {
                                throw new NotPersistableException("Collection " + field.Name + " does not exist in " + nakedObject.Spec.FullName);
                            }
                            MakePersistent(collection);
                        }
                        else
                        {
                            INakedObject fieldValue = field.GetNakedObject(nakedObject);
                            if (fieldValue == null)
                            {
                                continue;
                            }
                            Persist(fieldValue);
                        }
                    }
                    persistor.AddPersistedObject(nakedObject);
                }
            }
        }