/// <inheritdoc /> public virtual TEntity Copy <TEntity>(TEntity entity, Iri newIri = null) where TEntity : IEntity { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (entity.Context == this) { return(entity); } var proxy = entity.Unwrap() as Entity; if (proxy == null) { throw new ArgumentOutOfRangeException(nameof(entity)); } lock (proxy) { proxy.EntityContextOverride = this; proxy.IriOverride = newIri; var result = (Entity)proxy.Clone(true); proxy.EntityContextOverride = null; proxy.IriOverride = null; result.IsInitialized = true; return(result.ActLike <TEntity>()); } }
internal static void SetList(this Entity entity, Iri head, ICollectionMapping collectionMapping, EntityInitializationContext context) { Iri previousHead = null; while (true) { ISet <Statement> statements; if ((previousHead == head) || (!context.EntityStatements.TryGetValue(head, out statements))) { break; } context.EntityStatements.Remove(previousHead = head); foreach (var statement in statements) { if (statement.Predicate == rdf.first) { entity.SetProperty(statement, collectionMapping, context); } else if (statement.Predicate == rdf.rest) { head = statement.Object; } } } }
/// <summary>Initializes a new instance of the <see cref="Statement"/> class.</summary> /// <param name="subject">Subject of the statement.</param> /// <param name="predicate">Predicate of the statement..</param> /// <param name="value">Literal value of the statement.</param> /// <param name="language">Language of the literal value.</param> /// <param name="graph">Optional graph.</param> public Statement(Iri subject, Iri predicate, string value, string language, Iri graph = null) { if (subject == null) { throw new ArgumentNullException(nameof(subject)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } if (language == null) { throw new ArgumentNullException(nameof(language)); } Graph = graph; Subject = subject; Predicate = predicate; Value = value; Language = language; }
/// <summary>Initializes a new instance of the <see cref="Entity"/> class.</summary> /// <param name="id">The identifier.</param> /// <param name="context">The entity context.</param> internal Entity(Iri id, DefaultEntityContext context) { Iri = id; _isInitialized = false; _context = context; OriginalValues = new HashSet <MulticastPropertyValue>(); }
/// <inheritdoc /> public virtual TEntity Create <TEntity>(Iri iri) where TEntity : IEntity { if (iri == null) { throw new ArgumentNullException(nameof(iri)); } return(CreateInternal <TEntity>(iri)); }
/// <inheritdoc /> public void Delete(Iri iri) { if (iri == null) { throw new ArgumentNullException(nameof(iri)); } var existingEntity = Entities.Where(entity => entity.Key.Iri == iri).Select(entity => entity.Key).FirstOrDefault(); if (existingEntity != null) { Entities.Remove(existingEntity); } }
internal virtual Entity CreateInternal(Iri iri, bool isInitialized = true) { Entity result; if (_entityCache.TryGetValue(iri, out result)) { return(result); } var inMemoryEntitySource = _entitySource as IInMemoryEntitySource; if (inMemoryEntitySource != null) { return(_entityCache[iri] = inMemoryEntitySource.Create(iri) as Entity); } return(CreateInternal(new Entity(iri, this) { IsInitialized = isInitialized })); }
/// <inheritdoc /> public IEntity Create(Iri iri) { if (iri == null) { throw new ArgumentNullException(nameof(iri)); } lock (_sync) { var result = Entities.Where(entity => entity.Key.Iri == iri).Select(entity => entity.Key).FirstOrDefault(); if (result == null) { Entities[result = new Entity(iri, _entityContext()) { IsInitialized = true }] = new HashSet <Statement>(); } return(result); } }
/// <summary>Initializes a new instance of the <see cref="Statement"/> class.</summary> /// <param name="subject">Subject of the statement.</param> /// <param name="predicate">Predicate of the statement..</param> /// <param name="object">Related object.</param> /// <param name="graph">Optional graph.</param> public Statement(Iri subject, Iri predicate, Iri @object, Iri graph = null) { if (subject == null) { throw new ArgumentNullException(nameof(subject)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } if (@object == null) { throw new ArgumentNullException(nameof(@object)); } Graph = graph; Subject = subject; Predicate = predicate; Object = @object; }
/// <summary>Initializes a new instance of the <see cref="Statement"/> class.</summary> /// <param name="subject">Subject of the statement.</param> /// <param name="predicate">Predicate of the statement..</param> /// <param name="value">Literal value of the statement.</param> /// <param name="dataType">Type of the literal value.</param> /// <param name="graph">Optional graph.</param> public Statement(Iri subject, Iri predicate, string value, Iri dataType = null, Iri graph = null) { if (subject == null) { throw new ArgumentNullException(nameof(subject)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } Graph = graph; Subject = subject; Predicate = predicate; Value = value; DataType = dataType; }
private static void AddStatements(ISet <Statement> entityStatements, ICollectionMapping collectionMapping, IEntity entity, IEnumerable values) { if (collectionMapping.StoreAs == CollectionStorageModel.Simple) { AddStatements(entityStatements, collectionMapping, entity.Iri, values); return; } var iri = entity.Iri; var term = collectionMapping.Term; foreach (var value in values) { var auxIri = new Iri(); entityStatements.Add(iri != entity.Iri ? new Statement(iri, rdf.rest, auxIri) : new Statement(iri, term, auxIri)); var entityValue = value as IEntity; entityStatements.Add(entityValue != null ? new Statement(auxIri, rdf.first, entityValue.Iri) : collectionMapping.ValueConverter.ConvertTo(auxIri, rdf.first, value, collectionMapping.Graph)); iri = auxIri; } entityStatements.Add(new Statement(iri, rdf.rest, rdf.nil)); }
/// <inheritdoc /> public virtual void Delete(Iri iri) { if (iri == null) { throw new ArgumentNullException(nameof(iri)); } if (iri.IsBlank) { throw new ArgumentOutOfRangeException(nameof(iri)); } lock (_sync) { Entity result; if (_entityCache.TryGetValue(iri, out result)) { _entityCache.Remove(iri); _deletedEntities.Add(iri); } } (_entitySource as IInMemoryEntitySource)?.Delete(iri); }
/// <inheritdoc /> public override bool Equals(object obj) { Iri anotherIri = obj as Iri; return(anotherIri != null && _iri.Equals(anotherIri._iri)); }
/// <inheritdoc /> public override int GetHashCode() { return(Iri.GetHashCode()); }
private static void AddStatements(ISet <Statement> entityStatements, ICollectionMapping collectionMapping, Iri iri, IEnumerable values) { foreach (var value in values) { var entityValue = value as IEntity; entityStatements.Add(entityValue != null ? new Statement(iri, collectionMapping.Term, entityValue.Iri) : collectionMapping.ValueConverter.ConvertTo(iri, collectionMapping.Term, value, collectionMapping.Graph)); } }
/// <summary>Checks whether a given <paramref name="entity" /> is of the given <paramref name="class" />.</summary> /// <param name="entity">Entity to check.</param> /// <param name="class">Class to search for.</param> /// <returns><b>true</b> if a given <paramref name="entity" /> is mapped to the <paramref name="class" />; otherwise <b>false</b>.</returns> public static bool Is(this IEntity entity, Iri @class) { return(entity.GetTypes().Contains(@class)); }
/// <inheritdoc /> public IEnumerable <Statement> Load(Iri iri) { throw new NotSupportedException("In-Memory entity source doesn't support entity loading."); }
/// <inheritdoc /> public IEntityContextFactory WithQIri(string prefix, Iri iri) { _container.Register(new QIriMapping(prefix, iri), prefix); return(this); }
/// <inheritdoc /> public TEntity Create <TEntity>(Iri iri) where TEntity : IEntity { return(Create(iri).ActLike <TEntity>()); }
private TEntity CreateInternal <TEntity>(Iri iri, bool isInitialized = true) where TEntity : IEntity { return(CreateInternal(iri, isInitialized).ActLike <TEntity>()); }
internal static bool Matches(this Statement statement, Iri graph) { return((graph == null) || (graph == statement.Graph)); }