private void MakeCollectionPersistent(INakedObjectAdapter collection) { if (collection.ResolveState.IsPersistent() || collection.Spec.Persistable == PersistableType.Transient) { return; } if (collection.ResolveState.IsTransient()) { collection.ResolveState.Handle(Events.StartResolvingEvent); collection.ResolveState.Handle(Events.EndResolvingEvent); } manager.MadePersistent(collection); collection.GetAsEnumerable(manager).ForEach(MakePersistent); }
private void Persist(INakedObjectAdapter nakedObjectAdapter) { if (nakedObjectAdapter.ResolveState.IsAggregated() || nakedObjectAdapter.ResolveState.IsTransient() && nakedObjectAdapter.Spec.Persistable != PersistableType.Transient) { var fields = ((IObjectSpec)nakedObjectAdapter.Spec).Properties; if (!nakedObjectAdapter.Spec.IsEncodeable && fields.Length > 0) { nakedObjectAdapter.Persisting(); if (!nakedObjectAdapter.Spec.ContainsFacet(typeof(IComplexTypeFacet))) { manager.MadePersistent(nakedObjectAdapter); } foreach (var field in fields) { if (!field.IsPersisted) { continue; } if (field is IOneToManyAssociationSpec) { var collection = field.GetNakedObject(nakedObjectAdapter); if (collection == null) { throw new NotPersistableException(logger.LogAndReturn($"Collection {field.Name} does not exist in {nakedObjectAdapter.Spec.FullName}")); } MakePersistent(collection); } else { var fieldValue = field.GetNakedObject(nakedObjectAdapter); if (fieldValue == null) { continue; } Persist(fieldValue); } } persistor.AddPersistedObject(nakedObjectAdapter); } } }
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); } } }