예제 #1
0
        /// <summary>
        /// Change the URI identifier for this data object.
        /// </summary>
        /// <remarks>This change will update all triples where the data object identity
        /// is the subject or object. It will not change predicates.</remarks>
        /// <param name="newIdentity">The new URI identifier</param>
        /// <param name="enforceClassUniqueConstraint">Add an update precondition to ensure that the update will fail if the store already
        /// contains an RDF resource with the same rdf:type(s) as this data object.</param>
        public IDataObject UpdateIdentity(string newIdentity, bool enforceClassUniqueConstraint)
        {
            if (newIdentity == null)
            {
                throw new ArgumentNullException("newIdentity", "DataObject Identity must not be null");
            }
            if (String.IsNullOrWhiteSpace(newIdentity))
            {
                throw new ArgumentException("DataObject Identity must not be an empty string or whitespace.", "newIdentity");
            }
            if (newIdentity.Equals(Identity))
            {
                // No change
                return(this);
            }

            if (IsNew)
            {
                // Simple case - we only have to change the uncommitted triples locally.
                CheckLoaded();
                var ret = new DataObject(_store, newIdentity, true);
                ret.BindTriples(_triples.Select(t => ReplaceIdentity(t, newIdentity)), true, enforceClassUniqueConstraint);
                Delete();
                return(ret);
            }
            else
            {
                CheckLoaded();
                var ret = new DataObject(_store, newIdentity, true);
                ret.BindTriples(_triples.Union(_store.GetReferencingTriples(this)).Select(t => ReplaceIdentity(t, newIdentity)), true, enforceClassUniqueConstraint);
                Delete();
                return(ret);
            }
        }