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

The following examples show how to use com.gs.fw.common.mithra.finder.RelatedFinder#getPrimaryKeyAttributes() . 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: MithraAbstractObjectPortal.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void appendJoinToSuper(StringBuilder buffer, String defaultDatabaseAlias)
{
    RelatedFinder superFinder = superClassFinders[0];
    Attribute[] superPkAttributes = superFinder.getPrimaryKeyAttributes();
    Attribute[] pkAttributes = ((PrivateReladomoClassMetaData)this.getClassMetaData()).getCachedPrimaryKeyAttributes();
    MithraObjectPortal[] superPortals = getSuperClassPortals();
    String superAlias = superPortals[0].getUniqueAlias();
    if (superAlias == null) superAlias = "";
    buffer.append(defaultDatabaseAlias).append(superAlias).append('.').append(superPkAttributes[0].getColumnName()).append("=");
    buffer.append(defaultDatabaseAlias).append(this.uniqueAlias).append('.').append(pkAttributes[0].getColumnName());
    for (int i = 1; i < pkAttributes.length; i++)
    {
        buffer.append(" AND ");
        buffer.append(defaultDatabaseAlias).append(superAlias).append('.').append(superPkAttributes[i].getColumnName()).append("=");
        buffer.append(defaultDatabaseAlias).append(this.uniqueAlias).append('.').append(pkAttributes[i].getColumnName());
    }
}
 
Example 2
Source File: DbExtractor.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private static Attribute[] getPrimaryKeyAttributesWithNoSource(RelatedFinder finder)
{
    Attribute sourceAttribute = finder.getSourceAttribute();
    Attribute[] primaryKeyAttributes = finder.getPrimaryKeyAttributes();
    if (sourceAttribute == null)
    {
        return primaryKeyAttributes;
    }
    int sourceLength = sourceAttribute == null ? 0 : 1;
    Attribute[] attributes = new Attribute[primaryKeyAttributes.length - sourceLength];
    int index = 0;
    for (Attribute pkAttr : primaryKeyAttributes)
    {
        if (!pkAttr.equals(sourceAttribute))
        {
            attributes[index++] = pkAttr;
        }
    }
    return attributes;
}
 
Example 3
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 4
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 5
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 6
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 7
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 8
Source File: MithraObjectGraphExtractor.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private FullUniqueIndex createDatelessIndex(MithraList mithraList)
{
    MithraObject mithraObject = (MithraObject) mithraList.get(0);
    RelatedFinder finder = mithraObject.zGetCurrentData().zGetMithraObjectPortal().getFinder();
    FullUniqueIndex pkIndex = new FullUniqueIndex(finder.getPrimaryKeyAttributes(), mithraList.size());
    pkIndex.addAll(mithraList);
    return pkIndex;
}
 
Example 9
Source File: SmallInstrumentIdsOnlyBeforeMilestoneDateAdditionalOperationBuilder.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
public Operation buildOperation(Timestamp businessDate, RelatedFinder relatedFinder)
{
    if (businessDate.before(CUT_OFF_DATE))
    {
        IntegerAttribute instrumentId = (IntegerAttribute) relatedFinder.getAttributeByName("instrumentId");
        return instrumentId.lessThan(3);
    }
    else
    {
        return new None(relatedFinder.getPrimaryKeyAttributes()[0]);
    }
}
 
Example 10
Source File: TestPerformance.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public Operation getPkOperation(List adhocList, RelatedFinder finder)
{
    Attribute[] pkAttributes = finder.getPrimaryKeyAttributes();
    if (pkAttributes.length == 1)
    {
        return pkAttributes[0].in(adhocList, pkAttributes[0]);
    }
    TupleAttribute pkTuple = pkAttributes[0].tupleWith(pkAttributes[1]);
    for(int i=2;i<pkAttributes.length;i++)
    {
        pkTuple = pkTuple.tupleWith(pkAttributes[i]);
    }
    return pkTuple.in(adhocList, pkAttributes);
}
 
Example 11
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);
        }
    }
}