internal override void Remove(TxDataHolder holder, EntityId entityId, string key, object value) { try { EnsureLuceneDataInstantiated(); long id = entityId.Id(); Document document = FindDocument(id); if (document != null) { Index.type.removeFromDocument(document, key, value); if (LuceneDataSource.DocumentIsEmpty(document)) { _writer.deleteDocuments(Index.type.idTerm(id)); } else { _writer.updateDocument(Index.type.idTerm(id), document); } } InvalidateSearcher(); } catch (IOException e) { throw new Exception(e); } }
internal virtual void SafeClose(TxDataHolder data) { if (data != null) { data.Dispose(); } }
private void Insert(EntityId entity, string key, object value, TxDataHolder insertInto, TxDataHolder removeFrom) { if (removeFrom != null) { removeFrom.Remove(entity, key, value); } insertInto.Add(entity, key, value); }
internal virtual TxDataHolder Removed(bool createIfNotExists) { if (this.Remove == null && createIfNotExists) { this.Remove = new TxDataHolder(Index, Index.type.newTxData(Index)); } return(this.Remove); }
internal virtual TxDataHolder Added(bool createIfNotExists) { if (this.Add == null && createIfNotExists) { this.Add = new TxDataHolder(Index, Index.type.newTxData(Index)); } return(this.Add); }
internal override IndexSearcher AsSearcher(TxDataHolder holder, QueryContext context) { if (context != null && context.TradeCorrectnessForSpeed) { return(null); } TxData fullTxData = ToFullTxData(); holder.Set(fullTxData); return(fullTxData.AsSearcher(holder, context)); }
internal override ICollection <EntityId> Get(TxDataHolder holder, string key, object value) { value = value is ValueContext ? (( ValueContext )value).CorrectValue : value.ToString(); ISet <EntityId> ids = IdCollection(key, value, false); if (ids == null || ids.Count == 0) { return(Collections.emptySet()); } return(ids); }
internal override ICollection <EntityId> Query(TxDataHolder holder, Query query, QueryContext contextOrNull) { if (contextOrNull != null && contextOrNull.TradeCorrectnessForSpeed) { return(Collections.emptyList()); } TxData fullTxData = ToFullTxData(); holder.Set(fullTxData); return(fullTxData.Query(holder, query, contextOrNull)); }
internal virtual ICollection <EntityId> GetAddedIds(LuceneExplicitIndex index, string key, object value) { TxDataHolder added = AddedTxDataOrNull(index); if (added == null) { return(Collections.emptySet()); } ICollection <EntityId> ids = added.Get(key, value); return(ids != null ? ids : Collections.emptySet()); }
internal virtual ICollection <EntityId> GetRemovedIds(LuceneExplicitIndex index, Query query) { TxDataHolder removed = RemovedTxDataOrNull(index); if (removed == null) { return(Collections.emptySet()); } ICollection <EntityId> ids = removed.Query(query, null); return(ids != null ? ids : Collections.emptySet()); }
internal virtual ICollection <EntityId> GetRemovedIds(LuceneExplicitIndex index, string key, object value) { TxDataHolder removed = RemovedTxDataOrNull(index); if (removed == null) { return(Collections.emptySet()); } ICollection <EntityId> ids = removed.Get(key, value); ICollection <EntityId> orphanIds = removed.GetOrphans(key); return(Merge(ids, orphanIds)); }
internal override void Add(TxDataHolder holder, EntityId entityId, string key, object value) { try { EnsureLuceneDataInstantiated(); long id = entityId.Id(); Document document = FindDocument(id); bool add = false; if (document == null) { document = IndexType.NewDocument(entityId); document.add(new StoredField(TX_STATE_KEY, _txStateValue)); _cachedDocuments.put(id, document); add = true; } if (string.ReferenceEquals(key, null) && value == null) { // Set a special "always hit" flag document.add(new StringField(ORPHANS_KEY, ORPHANS_VALUE, Store.NO)); AddOrphan(null); } else if (value == null) { // Set a special "always hit" flag document.add(new StringField(ORPHANS_KEY, key, Store.NO)); AddOrphan(key); } else { Index.type.addToDocument(document, key, value); } if (add) { _writer.addDocument(document); } else { _writer.updateDocument(Index.type.idTerm(id), document); } InvalidateSearcher(); } catch (IOException e) { throw new Exception(e); } }
internal override void Remove(TxDataHolder holder, EntityId entityId, string key, object value) { if (_data == null) { return; } if (string.ReferenceEquals(key, null) || value == null) { TxData fullData = ToFullTxData(); fullData.Remove(holder, entityId, key, value); holder.Set(fullData); } else { ICollection <EntityId> ids = IdCollection(key, value, false); if (ids != null) { ids.remove(entityId); } } }
internal override ICollection <EntityId> Get(TxDataHolder holder, string key, object value) { return(InternalQuery(Index.type.get(key, value), null)); }
internal override IndexSearcher AsSearcher(TxDataHolder holder, QueryContext context) { bool refresh = context == null || !context.TradeCorrectnessForSpeed; return(Searcher(refresh)); }
internal override ICollection <EntityId> Query(TxDataHolder holder, Query query, QueryContext contextOrNull) { return(InternalQuery(query, contextOrNull)); }
internal override void Add(TxDataHolder holder, EntityId entityId, string key, object value) { IdCollection(key, value, true).Add(entityId); }
internal abstract void Remove(TxDataHolder holder, EntityId entityId, string key, object value);
internal virtual IndexSearcher GetAdditionsAsSearcher(LuceneExplicitIndex index, QueryContext context) { TxDataHolder data = AddedTxDataOrNull(index); return(data != null?data.AsSearcher(context) : null); }
internal abstract ICollection <EntityId> Query(TxDataHolder holder, Query query, QueryContext contextOrNull);
internal abstract ICollection <EntityId> Get(TxDataHolder holder, string key, object value);
internal abstract IndexSearcher AsSearcher(TxDataHolder holder, QueryContext context);