All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gs.fw.common.mithra.cache.TransactionalDatedNonUniqueIndex Maven / Gradle / Ivy

There is a newer version: 18.1.0
Show newest version
/*
 Copyright 2016 Goldman Sachs.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */

package com.gs.fw.common.mithra.cache;

import com.gs.collections.impl.list.mutable.FastList;
import com.gs.fw.common.mithra.MithraManagerProvider;
import com.gs.fw.common.mithra.MithraTransaction;
import com.gs.fw.common.mithra.extractor.Extractor;
import com.gs.fw.common.mithra.extractor.RelationshipHashStrategy;
import com.gs.fw.common.mithra.transaction.TransactionLocal;
import com.gs.fw.common.mithra.util.DoUntilProcedure;
import com.gs.fw.common.mithra.util.Filter2;
import org.slf4j.Logger;

import java.sql.Timestamp;
import java.util.List;



public class TransactionalDatedNonUniqueIndex implements IterableNonUniqueIndex, TransactionalIndex
{

    private ExtractorBasedHashStrategy hashStrategy;
    private ExtractorBasedHashStrategy pkHashStrategy;
    private Extractor[] pkExtractors;
    private Extractor[] indexExtractors;
    private Index mainIndex;
    private TransactionLocal perTransactionStorage = new TransactionLocal();

    public TransactionalDatedNonUniqueIndex(String indexName, Extractor[] pkExtractors, Extractor[] indexExtractors, Index mainIndex)
    {
        this.pkExtractors = pkExtractors;
        this.indexExtractors = indexExtractors;
        this.pkHashStrategy = ExtractorBasedHashStrategy.create(pkExtractors);
        this.hashStrategy = ExtractorBasedHashStrategy.create(indexExtractors);
        this.mainIndex = mainIndex;
    }

    @Override
    public boolean isInitialized()
    {
        return true;
    }

    @Override
    public Index getInitialized(IterableIndex iterableIndex)
    {
        return this;
    }

    protected Object removeDeletedFromMainResult(Object fromMain, TransactionLocalStorage txStorage)
    {
        if (fromMain == null)
        {
            return null;
        }
        List result = null;
        FullUniqueIndex deletedPerThread = getLocalStorageDeleted(txStorage);
        if (deletedPerThread == null)
        {
            if (fromMain instanceof FullUniqueIndex)
            {
                return fromMain;
            }
            else if (fromMain instanceof List)
            {
                result = (List) fromMain;
            }
            else
            {
                result = new FastList(1);
                result.add(fromMain);
            }
        }
        else
        {
            if (fromMain instanceof FullUniqueIndex)
            {
                result = new FastList();
                ((FullUniqueIndex)fromMain).forAll(new AddNonDeleted(result, deletedPerThread));
            }
            else if (fromMain instanceof List)
            {
                List fromMainList = (List) fromMain;
                result = new FastList(((List) fromMain).size());
                for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy