Java Code Examples for com.gs.fw.common.mithra.finder.RelatedFinder#getAsOfAttributes()

The following examples show how to use com.gs.fw.common.mithra.finder.RelatedFinder#getAsOfAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionOperation.java    From reladomo with Apache License 2.0 6 votes vote down vote up
protected FullUniqueIndex createFullUniqueIndex(List objects)
{
    RelatedFinder finder = this.getPortal().getFinder();
    Extractor[] extractors = IdentityExtractor.getArrayInstance();
    UnderlyingObjectGetter getter = null;
    if (finder.getAsOfAttributes() != null)
    {
        extractors = getObjectSamenessKeyAttributes(finder);
        getter = new TransactionalUnderlyingObjectGetter();
    }
    FullUniqueIndex index = new FullUniqueIndex(extractors, objects.size());
    if (getter != null)
    {
        index.setUnderlyingObjectGetter(getter);
    }
    for(int i=0;i<objects.size();i++)
    {
        index.put(objects.get(i));
    }
    return index;
}
 
Example 2
Source File: MilestoneRectangle.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public static List<MithraDatedObject> toMithraObjects(RelatedFinder finder, List<MilestoneRectangle> rectangles)
 {
     List<MithraDataObject> mithraDataObjects = toMithraData(finder, rectangles);

     AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
     Timestamp[] asOfValues = new Timestamp[asOfAttributes.length];
     List<MithraDatedObject> mithraObjects = FastList.newList(mithraDataObjects.size());
     for (MithraDataObject data : mithraDataObjects)
     {
for(int i=0;i<asOfAttributes.length;i++)
         {
             asOfValues[i] = asOfAttributes[i].getInfinityDate();
         }

MithraDatedObject object = finder.getMithraObjectPortal().getMithraDatedObjectFactory()
        .createObject(data, asOfValues);
         mithraObjects.add(object);
     }
     return mithraObjects;
 }
 
Example 3
Source File: OverlapFixer.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private static OrderBy getOrderOfPrecedence(RelatedFinder finder)
{
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    OrderBy orderBy = null;
    Set<String> asOfFromToAttributes = UnifiedSet.newSet(asOfAttributes.length * 2);
    for (int i = asOfAttributes.length - 1; i >= 0; i--)
    {
        OrderBy descendingFrom = asOfAttributes[i].getFromAttribute().descendingOrderBy();
        orderBy = orderBy == null ? descendingFrom : orderBy.and(descendingFrom);
        orderBy = orderBy.and(asOfAttributes[i].getToAttribute().ascendingOrderBy());

        asOfFromToAttributes.add(asOfAttributes[i].getFromAttribute().getAttributeName());
        asOfFromToAttributes.add(asOfAttributes[i].getToAttribute().getAttributeName());
    }

    for (Attribute attr : finder.getPersistentAttributes())
    {
        if (!asOfFromToAttributes.contains(attr.getAttributeName()))
        {
            OrderBy asc = attr.ascendingOrderBy();
            orderBy = orderBy == null ? asc : orderBy.and(asc);
        }
    }

    return orderBy;
}
 
Example 4
Source File: MilestoneRectangle.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private static List<MilestoneRectangle> fromMithraObjects(RelatedFinder finder, List<? extends MithraDatedObject> mithraObjects)
{
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    List<MilestoneRectangle> rectangles = FastList.newList();
    for (MithraDatedObject object : mithraObjects)
    {
        rectangles.add(new MilestoneRectangle(object.zGetCurrentData(), asOfAttributes));

    }
    if (MilestoneRectangle.merge(rectangles).size() != rectangles.size())
    {
        MithraDataObject dataObject = (MithraDataObject) rectangles.get(0).data;
        LOGGER.warn("Invalid milestoning of " + dataObject.getClass().getSimpleName() + '[' + dataObject.zGetPrintablePrimaryKey() + ']');
    }
    return rectangles;
}
 
Example 5
Source File: DefaultLoadOperationProvider.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public List<Operation> getOperationsForFullCacheLoad(RelatedFinder finder)
{
    if (finder.getSourceAttribute() != null)
    {
        throw new RuntimeException("for full cache load of objects with source attribute, configure a loadOperationProvider in the runtime xml");
    }
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    if (asOfAttributes != null)
    {
        Operation op = asOfAttributes[0].equalsEdgePoint();
        if (asOfAttributes.length > 1)
        {
            op = op.and(asOfAttributes[1].equalsEdgePoint());
        }
        return ListFactory.create(op);
    }
    else
    {
        return ListFactory.create(finder.all());
    }
}
 
Example 6
Source File: MultiQueueExecutor.java    From reladomo with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor.
 * @param numberOfQueues      Total number of queues. There is one thread  for every queue, so this is also the number of threads.
 * @param hashBucketExtractor Hashing algorithm for the object. You can use a Mithra attribute, for example ProductFinder.cusip()
 * @param batchSize           Number of objects to put in each batch.
 * @param finder              An instance of the finder class. For example, ProductFinder.getFinderInstance()
 *
 */
public MultiQueueExecutor(int numberOfQueues, HashableValueSelector hashBucketExtractor,
                          int batchSize, RelatedFinder finder)
{
    this.batchSize = batchSize;
    this.finder = finder;
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    isDated = asOfAttributes != null;
    hasOptimisticLocking = asOfAttributes != null && (asOfAttributes.length == 2 || asOfAttributes[0].isProcessingDate());
    this.numberOfQueues = numberOfQueues;
    executors = new ThreadPoolExecutor[numberOfQueues];
    for (int i = 0; i < numberOfQueues; i++)
    {
        executors[i] = createExecutor();
    }
    this.hashBucketExtractor = hashBucketExtractor;
    terminateLists = allocateLists();
    insertLists = allocateLists();
    dbUpdateLists = allocateLists();
    fileUpdateLists = allocateLists();
    lastLogTime = System.currentTimeMillis();
}
 
Example 7
Source File: InactivateForArchiveSingleQueueExecutor.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public InactivateForArchiveSingleQueueExecutor(int numberOfThreads, Comparator orderBy, int batchSize, RelatedFinder finder, int insertThreads)
{
    super(numberOfThreads, orderBy, batchSize, finder, insertThreads);
    AsOfAttribute[] finderAsOfAttributes = finder.getAsOfAttributes();
    if (finderAsOfAttributes.length == 2)
    {
        asOfAttributes[0] = finderAsOfAttributes[0].getToAttribute();
        asOfAttributes[1] = finderAsOfAttributes[1].getToAttribute();
    }
    if (finderAsOfAttributes.length == 1)
    {
        if (finderAsOfAttributes[0].isProcessingDate())
        {
            asOfAttributes[0] = null;
            asOfAttributes[1] = finderAsOfAttributes[0].getToAttribute();
        }
    }
}
 
Example 8
Source File: MithraConfigurationManager.java    From reladomo with Apache License 2.0 6 votes vote down vote up
protected void addToExportedConfigs(RelatedFinder relatedFinder, MithraConfigurationManager configManager)
{
    if (threeTierExport)
    {
        synchronized (configManager.threeTierConfigSet)
        {
            configManager.threeTierConfigSet.add(new RemoteMithraObjectConfig(relationshipCacheSize,
                    minQueriesToKeep, className, relatedFinder.getSerialVersionId(),
                    useMultiUpdate, relatedFinder.getHierarchyDepth(), pureNotificationId,
                    this.cacheTimeToLive, this.relationshipCacheTimeToLive, this.factoryParameter, persisterId));
        }
    }
    if (isOffHeapFullCache() && relatedFinder.getAsOfAttributes() != null)
    {
        synchronized (configManager.cacheReplicableConfigSet)
        {
            configManager.cacheReplicableConfigSet.add(new RemoteMithraObjectConfig(relationshipCacheSize,
                    minQueriesToKeep, className, relatedFinder.getSerialVersionId(),
                    useMultiUpdate, relatedFinder.getHierarchyDepth(), pureNotificationId,
                    this.cacheTimeToLive, this.relationshipCacheTimeToLive, this.factoryParameter, persisterId));
        }
    }
}
 
Example 9
Source File: MilestoneRectangle.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public MithraDataObject getMithraDataCopyWithNewMilestones(RelatedFinder finder)
{
    MithraDataObject data = ((MithraDataObject) this.data).copy();
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    if (asOfAttributes != null)
    {
        asOfAttributes[0].getFromAttribute().setValue(data, new Timestamp(this.from));
        asOfAttributes[0].getToAttribute().setValue(data, new Timestamp(this.thru));
        if (asOfAttributes.length > 1)
        {
            asOfAttributes[1].getFromAttribute().setValue(data, new Timestamp(this.in));
            asOfAttributes[1].getToAttribute().setValue(data, new Timestamp(this.out));
        }
    }
    return data;
}
 
Example 10
Source File: MilestoneRectangle.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public static List<MilestoneRectangle> fromMithraData(RelatedFinder finder, List mithraData)
{
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    List<MilestoneRectangle> rectangles = FastList.newList();
    for (Object data : mithraData)
    {
        rectangles.add(new MilestoneRectangle(data, asOfAttributes));
               
    }
    if (MilestoneRectangle.merge(rectangles).size() != rectangles.size())
    {
        MithraDataObject dataObject = (MithraDataObject) rectangles.get(0).data;
        LOGGER.warn("Invalid milestoning of " + dataObject.getClass().getSimpleName() + '[' + dataObject.zGetPrintablePrimaryKey() + ']');
    }
    return rectangles;
}
 
Example 11
Source File: StringSourceFullCacheLoader.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public List<Operation> getOperationsForFullCacheLoad(RelatedFinder finder)
{
    UnifiedSet<String> set = new UnifiedSet<String>();
    set.add("A");
    set.add("B");
    Operation op = ((StringAttribute) finder.getSourceAttribute()).in(set);
    if (finder.getAsOfAttributes() != null)
    {
        for(AsOfAttribute a: finder.getAsOfAttributes())
        {
            op = op.and(a.equalsEdgePoint());
        }
    }
    return ListFactory.create(op);
}
 
Example 12
Source File: DependentLoaderFactoryImpl.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void addDanglingAsOfAttributes(RelatedFinder ownerFinder)
{
    final AsOfAttribute[] asOfAttributes = ownerFinder.getAsOfAttributes();
    if (asOfAttributes == null)
    {
        return;
    }

    for (AsOfAttribute each : asOfAttributes)
    {
        this.relationshipAttributeMap.put(each, null);
    }
}
 
Example 13
Source File: DbExtractor.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private static Attribute[] getSourcelessPrimaryKeyWithFromAttributes(RelatedFinder finder)
{
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    Attribute sourceAttribute = finder.getSourceAttribute();
    Attribute[] primaryKeyAttributes = finder.getPrimaryKeyAttributes();
    if (asOfAttributes == null && sourceAttribute == null)
    {
        return primaryKeyAttributes;
    }
    int asOfLength = asOfAttributes == null ? 0 : asOfAttributes.length;
    int sourceLength = sourceAttribute == null ? 0 : 1;
    Attribute[] attributes = new Attribute[primaryKeyAttributes.length + asOfLength - sourceLength];
    int index = 0;
    for (Attribute pkAttr : primaryKeyAttributes)
    {
        if (!pkAttr.equals(sourceAttribute))
        {
            attributes[index++] = pkAttr;
        }
    }
    if (asOfAttributes != null)
    {
        for (AsOfAttribute asOfAttr : asOfAttributes)
        {
            attributes[index++] = asOfAttr.getFromAttribute();
        }
    }
    return attributes;
}
 
Example 14
Source File: InactivateForArchivingLoader.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public InactivateForArchivingLoader(Timestamp startTime, Timestamp endTime, RelatedFinder finder, Object sourceSourceAttribute, Object destinationSourceAttribute)
{
    this.startTime = startTime;
    this.endTime = endTime;
    this.finder = finder;
    this.sourceSourceAttribute = sourceSourceAttribute;
    this.destinationSourceAttribute = destinationSourceAttribute;
    this.lastLogTime = System.currentTimeMillis();

    AsOfAttribute[] finderAsOfAttributes = finder.getAsOfAttributes();
    if (finderAsOfAttributes.length == 2)
    {
        businessDate = finderAsOfAttributes[0];
        processingDate = finderAsOfAttributes[1];
    }
    if (finderAsOfAttributes.length == 1)
    {
        if (finderAsOfAttributes[0].isProcessingDate())
        {
            processingDate = finderAsOfAttributes[0];
        }
        else
        {
            throw new RuntimeException("Chained inactivation is only supported with processing date");
        }
    }

    Attribute[] primaryKeyAttributes = finder.getPrimaryKeyAttributes();
    indexExtractor = new Attribute[primaryKeyAttributes.length  + finderAsOfAttributes.length - 1];
    System.arraycopy(primaryKeyAttributes, 0, indexExtractor, 0, primaryKeyAttributes.length - 1); // don't copy the source attribute
    for(int i=0;i<finderAsOfAttributes.length;i++)
    {
        indexExtractor[primaryKeyAttributes.length + i - 1] = finderAsOfAttributes[i].getFromAttribute();
    }
}
 
Example 15
Source File: SerializationNode.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private static void fillDefaultAttributes(RelatedFinder finder, SerializationNode result)
{
    FastList<Attribute> attributes = unwrapAttributes(finder.getPersistentAttributes());
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    if (asOfAttributes != null)
    {
        for(AsOfAttribute a: asOfAttributes)
        {
            attributes.add(unwrapAttribute(a));
        }
    }
    result.attributes = attributes;
}
 
Example 16
Source File: MultiUpdateOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void findAllPkAttributes(RelatedFinder finder, MithraTransactionalObject obj, MithraDataObject[] data)
{
    Attribute[] primaryKeyAttributes = finder.getPrimaryKeyAttributes();
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    this.singleValuedPrimaryKeys = new MithraFastList(primaryKeyAttributes.length + 3);
    for(int i=0;i < primaryKeyAttributes.length; i++)
    {
        if (!primaryKeyAttributes[i].isSourceAttribute())
        {
            singleValuedPrimaryKeys.add(primaryKeyAttributes[i]);
        }
    }
    if (asOfAttributes != null)
    {
        for(int i=0;i < asOfAttributes.length; i++)
        {
            singleValuedPrimaryKeys.add(asOfAttributes[i].getToAttribute());
        }
    }
    if (obj.zGetPortal().getTxParticipationMode().isOptimisticLocking())
    {
        if (asOfAttributes != null)
        {
            Attribute optimisticAttribute = getOptimisticKey(data);
            if (optimisticAttribute != null) singleValuedPrimaryKeys.add(optimisticAttribute);
        }
    }
    for(int i=0;i<singleValuedPrimaryKeys.size();i++)
    {
        if (diffPk == singleValuedPrimaryKeys.get(i))
        {
            singleValuedPrimaryKeys.remove(i);
            break;
        }
    }
}
 
Example 17
Source File: TransactionOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private Extractor[] getObjectSamenessKeyAttributes(RelatedFinder finder) {
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    Extractor nonProcessingDateAttribute = null;
    if(asOfAttributes != null)
    {
        for (int i = 0; i < asOfAttributes.length; i++)
        {
            if(!asOfAttributes[i].isProcessingDate())
            {
                nonProcessingDateAttribute = asOfAttributes[i].getFromAttribute();
                break;
            }
        }
    }
    Extractor[] primaryKeyAttributes = finder.getPrimaryKeyAttributes();
    if(nonProcessingDateAttribute == null)
    {
        return primaryKeyAttributes;
    }
    else
    {
        Extractor[] fullKey = new Extractor[primaryKeyAttributes.length + 1];
        System.arraycopy(primaryKeyAttributes, 0, fullKey, 0, primaryKeyAttributes.length);
        fullKey[primaryKeyAttributes.length] = nonProcessingDateAttribute;
        return fullKey;
    }
}
 
Example 18
Source File: TransactionOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private boolean touchesSameObjectUsingIndex(TransactionOperation otherOp)
{
    int otherSize = otherOp.getAllObjects().size();
    int localSize = this.getAllObjects().size();
    TransactionOperation biggerOp;
    TransactionOperation smallerOp;
    if(localSize > otherSize)
    {
        biggerOp = this;
        smallerOp = otherOp;
    }
    else
    {
        biggerOp = otherOp;
        smallerOp = this;
    }
    RelatedFinder finder = this.getPortal().getFinder();
    if (finder.getAsOfAttributes() == null)
    {
        return indexCompare(smallerOp.getIndexedObjects(), biggerOp.getAllObjects());
    }
    //for temporal objects can't use the unique index with as-of attributes
    Extractor[] extractors = finder.getPrimaryKeyAttributes();
    List objectsFromSmallerOp = smallerOp.getAllObjects();
    FullUniqueIndex index = new FullUniqueIndex(extractors, objectsFromSmallerOp.size());
    index.setUnderlyingObjectGetter(new TransactionalUnderlyingObjectGetter());
    for (int i =0 ; i < objectsFromSmallerOp.size(); i++)
    {
        index.put(objectsFromSmallerOp.get(i));
    }
    return indexCompare(index, biggerOp.getAllObjects());
}
 
Example 19
Source File: ReladomoDeserializer.java    From reladomo with Apache License 2.0 4 votes vote down vote up
protected void resolveList(DeserializationClassMetaData metaData, List<PartialDeserialized> listToResolve) throws DeserializationException
{
    List<PartialDeserialized> dbLookUp = FastList.newList(listToResolve.size());
    for(PartialDeserialized partDes: listToResolve)
    {
        switch (partDes.state)
        {
            case 0: // not set
            case ReladomoSerializationContext.READ_ONLY_STATE:
            case ReladomoSerializationContext.DETACHED_STATE:
            case ReladomoSerializationContext.DELETED_OR_TERMINATED_STATE:
                dbLookUp.add(partDes);
                break;
            case ReladomoSerializationContext.IN_MEMORY_STATE:
                handleInMemoryObject(partDes, metaData);
                break;
        }
    }

    if (!dbLookUp.isEmpty())
    {
        RelatedFinder finder = metaData.getRelatedFinder();
        Attribute[] pkAttributesNoSource = metaData.getPrimaryKeyAttributesWithoutSource();
        Attribute sourceAttribute = metaData.getSourceAttribute();
        AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
        if (asOfAttributes != null || sourceAttribute != null)
        {
            List<List<PartialDeserialized>> segregated = segregateByAsOfAndSourceAttribute(metaData, dbLookUp);
            for (int i = 0; i < segregated.size(); i++)
            {
                List<PartialDeserialized> list = segregated.get(i);
                Operation segOp = NoOperation.instance();
                PartialDeserialized first = list.get(0);
                if (sourceAttribute != null)
                {
                    if (!first.isAttributeSet(sourceAttribute, metaData))
                    {
                        handleUnresolvableObjects(list, metaData);
                        break; // can't be resolved.
                    }
                    segOp = segOp.and(sourceAttribute.nonPrimitiveEq(sourceAttribute.valueOf(first.dataObject)));
                }
                if (metaData.getBusinessDateAttribute() != null && first.businessDate != null)
                {
                    segOp = segOp.and(metaData.getBusinessDateAttribute().eq(first.businessDate));
                }
                if (metaData.getProcessingDateAttribute() != null && first.processingDate != null)
                {
                    segOp = segOp.and(metaData.getProcessingDateAttribute().eq(first.processingDate));
                }
                forceRefresh(metaData, list, pkAttributesNoSource, segOp);
            }
        }
        else
        {
            forceRefresh(metaData, dbLookUp, pkAttributesNoSource, NoOperation.instance());
        }
    }
}
 
Example 20
Source File: DelegatingList.java    From reladomo with Apache License 2.0 4 votes vote down vote up
protected void forceRefreshForSimpleList()
{
    if (this.size() == 0)
    {
        return;
    }
    RelatedFinder finder = this.getMithraObjectPortal().getFinder();
    Attribute[] pkAttributes = finder.getPrimaryKeyAttributes();
    Attribute sourceAttribute = finder.getSourceAttribute();
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    MithraTransaction tx = MithraManagerProvider.getMithraManager().getCurrentTransaction();
    boolean oldEvaluationMode = tx != null && tx.zIsInOperationEvaluationMode();
    if (asOfAttributes != null)
    {
        List<? extends List> segregatedByDate;
        try
        {
            if (tx != null) tx.zSetOperationEvaluationMode(true);
            segregatedByDate = segregateByAsOfAttribute(asOfAttributes);
        }
        finally
        {
            if (tx != null) tx.zSetOperationEvaluationMode(oldEvaluationMode);
        }
        for (int i = 0; i < segregatedByDate.size(); i++)
        {
            List list = segregatedByDate.get(i);
            Operation dateOp;
            try
            {
                if (tx != null) tx.zSetOperationEvaluationMode(true);
                dateOp = asOfAttributes[0].nonPrimitiveEq(asOfAttributes[0].valueOf(list.get(0)));
                if (asOfAttributes.length == 2)
                {
                    dateOp = dateOp.and(asOfAttributes[1].nonPrimitiveEq(asOfAttributes[1].valueOf(list.get(0))));
                }
            }
            finally
            {
                if (tx != null)
                {
                    tx.zSetOperationEvaluationMode(oldEvaluationMode);
                }
            }
            if (pkAttributes.length == 1 || (pkAttributes.length == 2 && sourceAttribute != null))
            {
                forceRefreshWithOnePk(list, pkAttributes, dateOp, tx, oldEvaluationMode);
            }
            else
            {
                forceRefreshWithMultiplePk(list, pkAttributes, dateOp, tx, oldEvaluationMode);
            }
        }
    }
    else
    {
        if (pkAttributes.length == 1 || (pkAttributes.length == 2 && sourceAttribute != null))
        {
            forceRefreshWithOnePk(this, pkAttributes, null, tx, oldEvaluationMode);
        }
        else
        {
            forceRefreshWithMultiplePk(this, pkAttributes, null, tx, oldEvaluationMode);
        }
    }
}