Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
 internal virtual void SafeClose(TxDataHolder data)
 {
     if (data != null)
     {
         data.Dispose();
     }
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 internal virtual TxDataHolder Removed(bool createIfNotExists)
 {
     if (this.Remove == null && createIfNotExists)
     {
         this.Remove = new TxDataHolder(Index, Index.type.newTxData(Index));
     }
     return(this.Remove);
 }
Ejemplo n.º 5
0
 internal virtual TxDataHolder Added(bool createIfNotExists)
 {
     if (this.Add == null && createIfNotExists)
     {
         this.Add = new TxDataHolder(Index, Index.type.newTxData(Index));
     }
     return(this.Add);
 }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        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());
        }
Ejemplo n.º 10
0
        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());
        }
Ejemplo n.º 11
0
        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));
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
        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);
                }
            }
        }
Ejemplo n.º 14
0
 internal override ICollection <EntityId> Get(TxDataHolder holder, string key, object value)
 {
     return(InternalQuery(Index.type.get(key, value), null));
 }
Ejemplo n.º 15
0
        internal override IndexSearcher AsSearcher(TxDataHolder holder, QueryContext context)
        {
            bool refresh = context == null || !context.TradeCorrectnessForSpeed;

            return(Searcher(refresh));
        }
Ejemplo n.º 16
0
 internal override ICollection <EntityId> Query(TxDataHolder holder, Query query, QueryContext contextOrNull)
 {
     return(InternalQuery(query, contextOrNull));
 }
Ejemplo n.º 17
0
 internal override void Add(TxDataHolder holder, EntityId entityId, string key, object value)
 {
     IdCollection(key, value, true).Add(entityId);
 }
Ejemplo n.º 18
0
 internal abstract void Remove(TxDataHolder holder, EntityId entityId, string key, object value);
Ejemplo n.º 19
0
        internal virtual IndexSearcher GetAdditionsAsSearcher(LuceneExplicitIndex index, QueryContext context)
        {
            TxDataHolder data = AddedTxDataOrNull(index);

            return(data != null?data.AsSearcher(context) : null);
        }
Ejemplo n.º 20
0
 internal abstract ICollection <EntityId> Query(TxDataHolder holder, Query query, QueryContext contextOrNull);
Ejemplo n.º 21
0
 internal abstract ICollection <EntityId> Get(TxDataHolder holder, string key, object value);
Ejemplo n.º 22
0
 internal abstract IndexSearcher AsSearcher(TxDataHolder holder, QueryContext context);