Java Code Examples for com.gs.fw.common.mithra.attribute.Attribute#valueEquals()

The following examples show how to use com.gs.fw.common.mithra.attribute.Attribute#valueEquals() . 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: UpdateOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public static Attribute findDifferentPk(MithraObjectPortal portal, Object first, Object second)
{
    first = portal.zChooseDataForMultiupdate((MithraTransactionalObject)first);
    second = portal.zChooseDataForMultiupdate((MithraTransactionalObject)second);
    Attribute sourceAttribute = portal.getFinder().getSourceAttribute();
    if (sourceAttribute != null)
    {
        if (!sourceAttribute.valueEquals(first, second))
        {
            return null;
        }
    }
    Attribute[] primaryKeyAttributes = portal.zGetAddressingAttributes();
    Attribute differentPk = primaryKeyAttributes[0];
    if (primaryKeyAttributes.length > 1)
    {
        int count = 0;
        for(int i=0;i<primaryKeyAttributes.length;i++)
        {
            if (!primaryKeyAttributes[i].valueEquals(first, second))
            {
                differentPk = primaryKeyAttributes[i];
                count++;
                if (count > 1)
                {
                    return null;
                }
            }
        }
        if (count == 0)
        {
            return null;
        }
    }
    return differentPk;
}
 
Example 2
Source File: DeepFetchNode.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private List<List> segregateBySource(List resolvedList)
{
    Attribute sourceAttribute = this.relatedFinder.getSourceAttribute();
    if (sourceAttribute == null || resolvedList.size() == 1) return ListFactory.create(resolvedList);
    MultiHashMap map = null;
    Object first = resolvedList.get(0);
    for(int i=0;i < resolvedList.size(); i++)
    {
        Object current = resolvedList.get(i);
        if (map != null)
        {
            map.put(sourceAttribute.valueOf(current), current);
        }
        else if (!sourceAttribute.valueEquals(first, current))
        {
            map = new MultiHashMap();
            Object firstSource = sourceAttribute.valueOf(first);
            for(int j=0;j<i;j++)
            {
                map.put(firstSource, resolvedList.get(j));
            }
            map.put(sourceAttribute.valueOf(current), current);
        }
    }

    if (map != null)
    {
        return map.valuesAsList();
    }
    else
    {
        return ListFactory.create(resolvedList);
    }
}
 
Example 3
Source File: DeepFetchNode.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void removeConstants(Set<Attribute> leftAttributeSet, List resolvedBySourceList, Set<Attribute> constantSet, Set<Attribute> nonConstantSet)
{
    if (resolvedBySourceList.size() == 1)
    {
        leftAttributeSet.clear(); // everything is constant anyway
        return;
    }
    for(Iterator<Attribute> attributeIterator = leftAttributeSet.iterator(); attributeIterator.hasNext(); )
    {
        Attribute a = attributeIterator.next();
        if (constantSet.contains(a))
        {
            attributeIterator.remove();
        }
        else if (!nonConstantSet.contains(a))
        {
            boolean constant = true;
            Object first = resolvedBySourceList.get(0);
            for(int i=1;i<resolvedBySourceList.size();i++)
            {
                if (!a.valueEquals(first, resolvedBySourceList.get(i)))
                {
                    constant = false;
                    break;
                }
            }
            if (constant)
            {
                constantSet.add(a);
                attributeIterator.remove();
            }
            else
            {
                nonConstantSet.add(a);
            }
        }
    }
}
 
Example 4
Source File: MultiEqualityMapper.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public Operation getSimplifiedJoinOp(List parentList, int maxInClause, DeepFetchNode node, boolean useTuple)
{
    Operation constants = NoOperation.instance();
    boolean[] needsInClause = new boolean[leftAttributes.length];
    Object firstParent = parentList.get(0);
    int inClauseCount = 0;
    TupleAttribute tupleAttribute = null;
    Attribute firstNonConstantAttribute = null;
    for(int leftIndex = 0; leftIndex < leftAttributes.length; leftIndex++)
    {
        Attribute right = ((EqualityMapper) this.equalityMappers.get(leftIndex)).getRight();
        boolean isConstant = true;
        Attribute left = leftAttributes[leftIndex];
        for(int i=1;i<parentList.size();i++)
        {
            Object parent = parentList.get(i);
            if (!left.valueEquals(firstParent, parent))
            {
                isConstant = false;
                break;
            }
        }
        if (isConstant)
        {
            constants = constants.and(right.nonPrimitiveEq(left.valueOf(firstParent)));
        }
        else
        {
            inClauseCount++;
            if (!useTuple && inClauseCount > 1)
            {
                return null;
            }
            needsInClause[leftIndex] = true;
            if (firstNonConstantAttribute == null)
            {
                firstNonConstantAttribute = right;
            }
            else if (tupleAttribute == null)
            {
                tupleAttribute = firstNonConstantAttribute.tupleWith(right);
            }
            else
            {
                tupleAttribute = tupleAttribute.tupleWith(right);
            }
        }
    }
    if (inClauseCount == 0) return constants;
    if (tupleAttribute != null)
    {
        Extractor[] extractors = new Extractor[inClauseCount];
        int count = 0;
        for(int i=0;i<equalityMappers.size();i++)
        {
            if (needsInClause[i])
            {
                extractors[count] = leftAttributes[i];
                count++;
            }
        }
        return constants.and(tupleAttribute.inIgnoreNulls(parentList, extractors));
    }
    else
    {
        Operation op = constants;
        for(int i=0;i<needsInClause.length;i++)
        {
            if (needsInClause[i])
            {
                EqualityMapper mapper = (EqualityMapper) this.equalityMappers.get(i);
                Operation localOp = mapper.getSimplifiedJoinOp(parentList, maxInClause, node, useTuple);
                if (localOp == null) return null;
                op = op.and(localOp);
                break;
            }
        }
        return op;
    }
}