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

The following examples show how to use com.gs.fw.common.mithra.attribute.Attribute#valueOf() . 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: ReladomoDeserializer.java    From reladomo with Apache License 2.0 6 votes vote down vote up
protected void setAttributesAndMethods(MithraObject obj, PartialDeserialized partial, DeserializationClassMetaData metaData)
{
    List<Attribute> settableAttributes = metaData.getSettableAttributes();
    for(int i=0;i<settableAttributes.size();i++)
    {
        Attribute attr = settableAttributes.get(i);
        if (partial.isAttributeSet(attr, metaData))
        {
            Object newValue = attr.valueOf(partial.dataObject);
            if (newValue == null)
            {
                attr.setValueNull(obj);
            }
            else
            {
                attr.setValue(obj, newValue);
            }
        }
    }
    //todo: deserializable methods
}
 
Example 2
Source File: MithraTestResource.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void insertTestData(List<? extends MithraObject> testDataList)
{
    initializeRuntime();
    List<MithraDataObject> dataObjects = getDataObjectsFromDomainObjects(testDataList);
    MithraObjectPortal portal = dataObjects.get(0).zGetMithraObjectPortal();
    Attribute sourceAttribute = portal.getFinder().getSourceAttribute();
    if (sourceAttribute != null)
    {
        List segregated = this.segregateBySourceAttribute(dataObjects, sourceAttribute);
        int segregatedSize = segregated.size();
        for (int i = 0; i < segregatedSize; i++)
        {
            List segregatedList = (List) segregated.get(i);
            Object source = sourceAttribute.valueOf(segregatedList.get(0));
            this.insertTestData(segregatedList, source);
        }
    }
    else
    {
        this.insertTestData(dataObjects, null);
    }
    portal.reloadCache();
}
 
Example 3
Source File: AdhocFastList.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private Object getSourceAttributeValue(Attribute sourceAttribute, Object mithraObject)
{
    Object sourceAttributeValue = null;
    if (sourceAttribute != null)
    {
        sourceAttributeValue = sourceAttribute.valueOf(mithraObject);
    }
    return sourceAttributeValue;
}
 
Example 4
Source File: DbExtractor.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private Object getValueConvertIfNeeded(Attribute attribute, Object object)
{
    Object value = attribute.valueOf(object);
    if (attribute instanceof TimestampAttribute && value != null)
    {
        TimestampAttribute timestampAttribute = (TimestampAttribute) attribute;
        if (timestampAttribute.requiresConversionFromUtc() &&
                (timestampAttribute.getAsOfAttributeInfinity() == null || !timestampAttribute.getAsOfAttributeInfinity().equals(value)))
        {
            return MithraTimestamp.zConvertTimeForReadingWithUtcCalendar(new Timestamp(((Timestamp) value).getTime()), TimeZone.getDefault());
        }
    }
    return value;
}
 
Example 5
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 6
Source File: RemoteInsertResult.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void run()
{
    MithraObjectPortal mithraObjectPortal = this.mithraDataObject.zGetMithraObjectPortal(this.hierarchyDepth);
    boolean isDated = mithraObjectPortal.getFinder().getAsOfAttributes() != null;
    if (isDated)
    {
        Cache cache = mithraObjectPortal.getCache();
        TemporalContainer container = cache.getOrCreateContainer(this.mithraDataObject);
        InTransactionDatedTransactionalObject inTxObject = container.makeUninsertedDataActiveAndCreateObject(this.mithraDataObject);
        cache.putDatedData(this.mithraDataObject);
        mithraObjectPortal.getMithraObjectPersister().insert(this.mithraDataObject);
        inTxObject.zSetInserted();
        mithraObjectPortal.incrementClassUpdateCount();
    }
    else
    {
        MithraTransactionalObject txObject = (MithraTransactionalObject)
                mithraObjectPortal.getMithraObjectFactory().createObject(this.mithraDataObject);
        txObject.zPrepareForRemoteInsert();
        txObject.zInsertForRemote(this.hierarchyDepth);
    }
    Attribute sourceAttribute = mithraObjectPortal.getFinder().getSourceAttribute();
    Object sourceAttributeValue = null;
    if(sourceAttribute != null)
    {
        sourceAttributeValue = sourceAttribute.valueOf(this.mithraDataObject);
    }
    Set sourceAttributeValueSet = new UnifiedSet(1);
    sourceAttributeValueSet.add(sourceAttributeValue);
    this.databaseIdentifierMap = mithraObjectPortal.extractDatabaseIdentifiers(sourceAttributeValueSet);
}
 
Example 7
Source File: SyslogCheckerTest.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testStringSourceAttribute()
{
    SpecialAccount specialAccount = SpecialAccountFinder.findByPrimaryKey(1, 10, "A");
    CHECKER.checkAndWaitForSyslog(specialAccount);

    MithraObjectPortal mithraObjectPortal = specialAccount.zGetPortal();
    MithraDatabaseObject databaseObject = mithraObjectPortal.getDatabaseObject();

    Attribute sourceAttribute = mithraObjectPortal.getFinder().getSourceAttribute();
    Object sourceAttributeValue = sourceAttribute.valueOf(specialAccount);
    String schema = ((MithraCodeGeneratedDatabaseObject) databaseObject).getSchemaGenericSource(sourceAttributeValue);
    CHECKER.checkAndWaitForSyslogSynchronized(sourceAttributeValue, schema, databaseObject);
}
 
Example 8
Source File: DelegatingList.java    From reladomo with Apache License 2.0 4 votes vote down vote up
private void forceRefreshWithMultiplePk(List listToRefresh, Attribute[] pkAttributes, Operation extraOp, MithraTransaction tx, boolean oldEvaluationMode)
{
    List<? extends List> lists;
    try
    {
        if (tx != null) tx.zSetOperationEvaluationMode(true);
        lists = segregateBySourceAttribute(listToRefresh);
    }
    finally
    {
        if (tx != null) tx.zSetOperationEvaluationMode(oldEvaluationMode);
    }
    MithraObjectPortal portal = this.getMithraObjectPortal();
    Attribute sourceAttribute = portal.getFinder().getSourceAttribute();
    for (int i = 0; i < lists.size(); i++)
    {
        TupleTempContext tempContext = new TupleTempContext(pkAttributes, true);
        tempContext.enableRetryHook();
        try
        {
            List segregatedList = lists.get(i);
            Object source;
            try
            {
                if (tx != null) tx.zSetOperationEvaluationMode(true);
                source = sourceAttribute != null ? sourceAttribute.valueOf(segregatedList.get(0)) : null;
                tempContext.insert(segregatedList, portal, REFRESH_BULK_INSERT_THRESHOLD, false);
            }
            finally
            {
                if (tx != null) tx.zSetOperationEvaluationMode(oldEvaluationMode);
            }
            Operation op = tempContext.exists(source);
            if (extraOp != null) op = op.and(extraOp);
            portal.findAsCachedQuery(op, null, true, false, 0, false);
        }
        finally
        {
            tempContext.destroy();
        }
    }
}
 
Example 9
Source File: ExtractResult.java    From reladomo with Apache License 2.0 4 votes vote down vote up
private static Object source(MithraObject mithraObject)
{
    Attribute sourceAttribute = finder(mithraObject).getSourceAttribute();
    return sourceAttribute == null ? null : sourceAttribute.valueOf(mithraObject);
}
 
Example 10
Source File: RemoteBatchInsertResult.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void run()
{
    MithraDataObject mithraDataObject = (MithraDataObject) mithraDataObjects.get(0);
    MithraObjectPortal mithraObjectPortal = mithraDataObject.zGetMithraObjectPortal(this.hierarchyDepth);
    Cache cache = mithraObjectPortal.getCache();
    boolean isDated = mithraObjectPortal.getFinder().getAsOfAttributes() != null;
    List txObjects = new ArrayList(mithraDataObjects.size());
    MithraTransactionalObject[] objectsToSetInserted = new MithraTransactionalObject[mithraDataObjects.size()];
    if (isDated)
    {
        for(int i=0;i<mithraDataObjects.size();i++)
        {
            mithraDataObject = (MithraDataObject) mithraDataObjects.get(i);
            TemporalContainer container = cache.getOrCreateContainer(mithraDataObject);
            InTransactionDatedTransactionalObject inTxObject = container.makeUninsertedDataActiveAndCreateObject(mithraDataObject);
            cache.putDatedData(mithraDataObject);
            txObjects.add(inTxObject);
            objectsToSetInserted[i] = inTxObject;
        }
    }
    else
    {
        for(int i=0;i<mithraDataObjects.size();i++)
        {
            mithraDataObject = (MithraDataObject) mithraDataObjects.get(i);
            MithraTransactionalObject txObject = (MithraTransactionalObject)
                    mithraObjectPortal.getMithraObjectFactory().createObject(mithraDataObject);
            txObject.zPrepareForRemoteInsert();
            txObject.zSetTxPersistenceState(PersistedState.PERSISTED);
            cache.put(txObject);
            txObjects.add(txObject);
            objectsToSetInserted[i] = txObject;
        }
    }
    mithraObjectPortal.incrementClassUpdateCount();
    mithraObjectPortal.getMithraObjectPersister().batchInsert(txObjects, this.bulkInsertThreshold);

    Attribute sourceAttribute = mithraObjectPortal.getFinder().getSourceAttribute();
    Set sourceAttributeValueSet = new UnifiedSet();
    Object sourceAttributeValue = null;
    if(sourceAttribute == null)
    {
        sourceAttributeValueSet.add(sourceAttributeValue);
    }
    for(int i=0;i<objectsToSetInserted.length;i++)
    {
        objectsToSetInserted[i].zSetInserted();
        if(sourceAttribute != null)
        {
            sourceAttributeValue = sourceAttribute.valueOf(mithraDataObjects.get(i));
            sourceAttributeValueSet.add(sourceAttributeValue);
        }
    }
    databaseIdentifierMap = mithraObjectPortal.extractDatabaseIdentifiers(sourceAttributeValueSet);
}