com.gs.fw.common.mithra.MithraObject Java Examples

The following examples show how to use com.gs.fw.common.mithra.MithraObject. 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: AbstractTransactionalOperationBasedList.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean retainAll(DelegatingList<E> delegatingList, Collection<?> c)
{
    List list = resolveOperationAndCopy(delegatingList);
    FastList newList = FastList.newList(list.size());
    for(int i=0;i<list.size();i++)
    {
        Object item = list.get(i);
        if (c.contains(item))
        {
            newList.add(item);
        }
        else
        {
            this.removeHandler.removeRelatedObject((MithraObject) item);
        }
    }
    if (newList.size() < list.size())
    {
        getResolved(delegatingList).setResult(newList);
        return true;
    }
    return false;
}
 
Example #2
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 #3
Source File: AbstractDatedTransactionalCache.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public Object put(MithraObject object)
{
    try
    {
        this.getCacheLock().acquireWriteLock();
        // put the data first:
        MithraTransactionalObject transactionalObject = (MithraTransactionalObject) object;
        MithraDataObject data = transactionalObject.zGetTxDataForRead();
        int nonPkHashCode = this.getNonDatedPkHashCode(data);
        this.addToIndiciesWithoutCopyInTransaction(data, nonPkHashCode);
        return this.getUniqueConcurrentDatedObjectIndex().put(object, nonPkHashCode, true);
    }
    finally
    {
        this.getCacheLock().release();
    }
}
 
Example #4
Source File: ReladomoDeserializer.java    From reladomo with Apache License 2.0 6 votes vote down vote up
protected void handleNotFoundObject(PartialDeserialized partial, DeserializationClassMetaData metaData) throws DeserializationException
{
    MithraObject inMemory;
    switch (partial.state)
    {
        case 0: // not set
            inMemory = constructObjectAndSetAttributes(partial, metaData);
            partial.setDeserialized(inMemory, ReladomoSerializationContext.IN_MEMORY_STATE);
            break;
        case ReladomoSerializationContext.READ_ONLY_STATE:
        case ReladomoSerializationContext.DETACHED_STATE:
            throw new DeserializationException("Object "+partial.dataObject.zGetPrintablePrimaryKey()+" doesn't exist in the db");
        case ReladomoSerializationContext.DELETED_OR_TERMINATED_STATE:
            inMemory = constructObjectAndSetAttributes(partial, metaData);
            inMemory.zSetNonTxPersistenceState(PersistedState.DELETED);
            partial.setDeserialized(inMemory, ReladomoSerializationContext.DELETED_OR_TERMINATED_STATE);
            break;
        default:
            throw new DeserializationException("should not get here!");
    }
}
 
Example #5
Source File: AbstractNonDatedTransactionalCache.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateCacheForNewObjects(List newDataList, List updatedDataList, FastList checkToReindexList)
{
    NonNullMutableBoolean isDirty = new NonNullMutableBoolean();
    for (int i = 0; i < newDataList.size(); i++)
    {
        MithraDataObject data = (MithraDataObject) newDataList.get(i);
        MithraObject newObject = this.getFromDataByPrimaryKeyForCreation(data, isDirty);
        if (newObject == null)
        {
            newObject = this.getFactory().createObject(data);
            addToIndicesUnderLockAfterCreate(newObject, false);
        }
        else
        {
            if (isDirty.value)
            {
                addToIndicesUnderLockAfterCreate(newObject, false);
            }
            updatedDataList.add(data);
            checkToReindexList.add(newObject);
        }
    }
}
 
Example #6
Source File: AbstractNonDatedTransactionalCache.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public void removeIgnoringTransaction(MithraObject object)
{
    try
    {
        this.getCacheLock().acquireWriteLock();
        Index[] indices = this.getIndices();
        for(int i=0;i<indices.length;i++)
        {
            TransactionalIndex index = (TransactionalIndex) indices[i];
            index.removeIgnoringTransaction(object);
        }
    }
    finally
    {
        this.getCacheLock().release();
    }
}
 
Example #7
Source File: LoadingTaskImpl.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void putOnDependentQueues(MithraObject keyHolder)
{
    this.newOrChangedCount++;

    if (this.dependentKeyIndices.isEmpty() || !this.needDependentLoaders)
    {
        return;
    }

    this.stripe.add(keyHolder.zGetCurrentData());

    this.dependentKeyIndices.get(0).getCacheLoaderEngine().changeStripedCount(this.dependentKeyIndices.size());

    if (this.stripe.size() == QUEUE_STRIPE_SIZE)
    {
        for (int i = 0; i < this.dependentKeyIndices.size(); i++)
        {
            this.dependentKeyIndices.get(i).putStripeOnQueue(this.stripe);
        }
        this.stripe = FastList.newList(QUEUE_STRIPE_SIZE);
    }
}
 
Example #8
Source File: VerboseSerializer.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void writeObjects(List objects, ObjectOutput out) throws IOException
{
    this.writeHeader(out);
    Attribute[] persistentAttributes = this.finder.getPersistentAttributes();
    Attribute sourceAttribute = this.finder.getSourceAttribute();
    out.writeInt(objects.size());
    for (Object o : objects)
    {
        if (o instanceof MithraObject)
        {
            o = ((MithraObject) o).zGetCurrentData();
        }
        if (sourceAttribute != null)
        {
            sourceAttribute.serializeValue(o, out);
        }
        for (Attribute persistentAttribute : persistentAttributes)
        {
            persistentAttribute.serializeValue(o, out);
        }
    }
}
 
Example #9
Source File: DbExtractor.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private void addClassToMap(List data, RelatedFinder finder, Map<RelatedFinder, List<MithraDataObject>> map)
{
    if (!data.isEmpty())
    {
        List<MithraDataObject> existing = map.get(finder);
        if (existing == null)
        {
            existing = FastList.newList(data.size());
            map.put(finder, existing);
        }
        for (int i = 0; i < data.size(); i++)
        {
            existing.add(MithraObject.class.cast(data.get(i)).zGetCurrentData());
        }
    }
}
 
Example #10
Source File: MergeBuffer.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private void considerInsert(E e, List<E> ownerList, Object ownerObject, boolean fixForeignKeys)
{
    if (mergeOptions.getMergeHook().beforeInsertOfNew(e) == MergeHook.InsertInstruction.INSERT)
    {
        if (fixForeignKeys)
        {
            MithraObject nonPersistentCopy = ((MithraObject) ownerObject).getNonPersistentCopy();
            setValueOnRelationship(nonPersistentCopy, e); // fix the FK
        }
        this.addForInsert(e, ownerList, ownerObject);
        if (!detached)
        {
            navigateChildrenForInsert(e);
        }
    }
}
 
Example #11
Source File: AbstractNonDatedTransactionalCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
public Object preparePut(MithraObject obj)
{
    try
    {
        this.getCacheLock().acquireWriteLock();
        return ((TransactionalIndex)this.getPrimaryKeyIndex()).preparePut(obj);
    }
    finally
    {
        this.getCacheLock().release();
    }
}
 
Example #12
Source File: AbstractNonDatedTransactionalCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected Object addToIndiciesIgnoringTransaction(MithraObject result, boolean weak)
{
    TransactionalIndex primaryKeyIndex = ((TransactionalIndex) this.getPrimaryKeyIndex());
    Object old = primaryKeyIndex.putIgnoringTransaction(result, result.zGetCurrentData(), weak);
    Index[] indices = this.getIndices();
    for(int i=1;i<indices.length;i++)
    {
        TransactionalIndex index = (TransactionalIndex) indices[i];
        index.putIgnoringTransaction(result, result.zGetCurrentData(), weak);
    }
    return old;
}
 
Example #13
Source File: EvoTypesNested.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public static EvoTypesNested managedInstance(MithraObject ref, EvoTypesNestedExtractors attributes)
{
    if (attributes.charAttribute().charValueOf(ref) == 'A')
    {
        return new EvoTypesNestedA(ref, attributes);
    }
    else if (attributes.charAttribute().charValueOf(ref) == 'B')
    {
        return new EvoTypesNestedB(ref, attributes);
    }
    else
    {
        return new EvoTypesNested(ref, attributes);
    }
}
 
Example #14
Source File: AbstractNonDatedCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected Object addToIndicies(MithraObject result, boolean weak)
{
    Object old = weak ? this.primaryKeyIndex.putWeak(result) : this.primaryKeyIndex.put(result);
    for (int i = 1; i < this.indices.length; i++)
    {
        indices[i].put(result);
    }
    return old;
}
 
Example #15
Source File: AbstractNonDatedCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void archiveCacheWithFilter(final ObjectOutput out, final Filter filterOfDatesToKeep)
{
    try
    {
        this.readWriteLock.acquireReadLock();
        final List<MithraObject> list = FastList.newList(zLIST_CHUNK_SIZE);
        this.primaryKeyIndex.forAll(new DoUntilProcedure()
        {
            public boolean execute(Object object)
            {
                if (filterOfDatesToKeep.matches(object))
                {
                    return false;
                }
                list.add((MithraObject) object);
                if (list.size() > zLIST_CHUNK_SIZE)
                {
                    archiveList(list, out);
                    list.clear();
                }
                return false;
            }
        });

        archiveList(list, out);
    }
    finally
    {
        this.readWriteLock.release();
    }
}
 
Example #16
Source File: ExtractResult.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(MithraObject mithraObject, MithraObject mithraObject2)
{
    if (finder(mithraObject).equals(finder(mithraObject2)))
    {
        Object source = source(mithraObject);
        Object source2 = source(mithraObject2);
        return source == null ? source2 == null : source.equals(source2);
    }
    return false;
}
 
Example #17
Source File: ExtractResult.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public synchronized void addMithraObjects(List mithraList, List notExtracted)
{
    for (Object object : mithraList)
    {
        final MithraObject mithraObject = MithraObject.class.cast(object);
        final RelatedFinder finder = mithraObject.zGetCurrentData().zGetMithraObjectPortal().getFinder();
        FullUniqueIndex existing = this.dataObjectsByFinder.getIfAbsentPut(mithraObject, new Function0<FullUniqueIndex>()
        {
            @Override
            public FullUniqueIndex value()
            {
                Attribute[] primaryKeyAttributes = finder.getPrimaryKeyAttributes();
                AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
                Extractor[] extractors = new Extractor[primaryKeyAttributes.length + (asOfAttributes == null ? 0 : asOfAttributes.length)];
                System.arraycopy(primaryKeyAttributes, 0, extractors, 0, primaryKeyAttributes.length);
                if (asOfAttributes != null)
                {
                    for (int i = 0; i < asOfAttributes.length; i++)
                    {
                        extractors[primaryKeyAttributes.length + i] = asOfAttributes[i].getFromAttribute();
                    }
                }
                return new FullUniqueIndex(extractors, 100);
            }
        });
        if (existing.put(mithraObject) == null && notExtracted != null)
        {
            notExtracted.add(mithraObject);
        }
    }
}
 
Example #18
Source File: AbstractDatedTransactionalCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(MithraObject object)
{
    MithraTransactionalObject transactionalObject = (MithraTransactionalObject) object;
    MithraDataObject data = transactionalObject.zGetTxDataForRead();
    data.zSetDataVersion(REMOVED_VERSION);
    this.removeDatedData(data);
    // we purposely don't remove this from the dated object cache, because this method
    // is only called during in-place updates, which should not affect the dated object.
}
 
Example #19
Source File: JacksonWrappedSerializer.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(T t, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException
{
    MithraObject mithraObject = t.getWrapped();
    SerializationConfig serializationConfig = t.getConfig();
    JacksonReladomoSerialContext jacksonReladomoSerialContext = new JacksonReladomoSerialContext(serializationConfig, new JacksonReladomoSerialWriter(), jsonGenerator, serializerProvider);
    jacksonReladomoSerialContext.serializeReladomoObject(mithraObject);
}
 
Example #20
Source File: ReladomoSerializationContext.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void serializeReladomoObject(MithraObject reladomoObject)
{
    try
    {
        writer.startReladomoObject(reladomoObject, this);
        Object previousObject = this.currentObjectBeingSerialized;
        this.currentObjectBeingSerialized = reladomoObject;

        if (this.serializationConfig.serializeMetaData())
        {
            writer.startMetadata(reladomoObject, this);
            serializeClassMetadata(reladomoObject);
            writer.writeMetadataEnd(reladomoObject, this);
        }

        writer.startAttributes(this, this.currentNode.getAttributes().size());
        serializeAttributes(reladomoObject);
        writer.endAttributes(this);

        writer.startRelationships(this, this.currentNode.getChildren().size());
        serializeRelationships(reladomoObject);
        writer.endRelationships(this);

        writer.startLinks(this, this.currentNode.getLinks().size());
        serializeLinks(reladomoObject);
        writer.endLinks(this);

        List<Method> annotatedMethods = getAnnotatedMethods(reladomoObject);
        writer.startAnnotatedMethod(reladomoObject, this, annotatedMethods.size());
        serializeAnnotatedMethods(reladomoObject, annotatedMethods);
        writer.endAnnotatedMethod(reladomoObject, this);

        writer.endReladomoObject(reladomoObject, this);
        this.currentObjectBeingSerialized = previousObject;
    }
    catch (Exception e)
    {
        throw new RuntimeException("Could not serialize object", e);
    }
}
 
Example #21
Source File: MergeBuffer.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void setValueOnRelationship(Object ownerObject, Object o)
{
    AbstractRelatedFinder relatedFinder = ((NavigatedMergeOption) this.mergeOptions).getRelatedFinder();
    Method relationshipSetter = ReladomoClassMetaData.fromObjectInstance((MithraObject)ownerObject).getRelationshipSetter(relatedFinder.getRelationshipName());

    try
    {
        relationshipSetter.invoke(ownerObject, o);
    }
    catch (Exception e)
    {
        throw new RuntimeException("Could not set relationship "+relatedFinder.getRelationshipName()+" on object "+((MithraObject)ownerObject).zGetCurrentData().zGetPrintablePrimaryKey(), e);
    }
}
 
Example #22
Source File: ReladomoSerializationContext.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected void serializeLinks(MithraObject reladomoObject) throws Exception
{
    List<SerializationNode> links = this.currentNode.getLinks();
    for(int i=0;i<links.size();i++)
    {
        SerializationNode linkNode = links.get(i);
        writer.writeLink(this, linkNode.getRelatedFinder().getRelationshipName(), linkNode.getLinkAttributes());
    }
}
 
Example #23
Source File: EvoTypesRoot.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public static EvoTypesRoot managedInstance(MithraObject ref, EvoTypesRootExtractors attributes)
{
    if (attributes.charAttribute().charValueOf(ref) == 'A')
    {
        return new EvoTypesRootA(ref, attributes);
    }
    else if (attributes.charAttribute().charValueOf(ref) == 'B')
    {
        return new EvoTypesRootB(ref, attributes);
    }
    else
    {
        return new EvoTypesRoot(ref, attributes);
    }
}
 
Example #24
Source File: MithraAbstractObjectPortal.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private Object checkRelatedValues(Object from, Object related, Extractor[] fromExtractors, Extractor[] relatedExtractors)
{
    if (related != null)
    {
        if (((MithraObject) related).isDeletedOrMarkForDeletion()) return null;
        if (fromExtractors != null)
        {
            for (int i = 0; i < fromExtractors.length; i++)
            {
                if (!fromExtractors[i].valueEquals(from, related, relatedExtractors[i])) return null;
            }
        }
    }
    return related;
}
 
Example #25
Source File: RemoteContinuedCursorResult.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void writeExternal(ObjectOutput out) throws IOException
{
    out.writeObject(op);
    out.writeInt(order);
    //todo: we seem to ignore reachedMaxRetrieveCount in forEachWithCursor
    //out.writeBoolean(this.reachedMaxRetrieveCount);
    out.writeInt(result.size());
    for(int i=0;i<result.size();i++)
    {
        MithraObject mithraObject = (MithraObject) result.get(i);
        serverContext.serializeFullData(mithraObject, out);
    }
    out.writeBoolean(finished);
    out.writeInt(remoteQueueSize);
}
 
Example #26
Source File: LoadingTaskImpl.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public int load()
{
    Operation loadOperation = this.loadOperationBuilder.build(this.sourceAttribute);
    BooleanFilter postLoadFilter = this.postLoadFilterBuilder.build();
    this.loadOperationBuilder = null;
    this.postLoadFilterBuilder = null;

    if (loadOperation instanceof None || FalseFilter.instance().equals(postLoadFilter))
    {
        return 0;
    }

    this.checkAndWaitForSyslog();

    Cursor cursor = buildCursor(loadOperation, postLoadFilter);
    try
    {
        while (cursor.hasNext())
        {
            this.putOnDependentQueues((MithraObject) cursor.next());
        }
    }
    finally
    {
        cursor.close();
        this.finishDependentQueues();
    }

    this.dereference();

    return newOrChangedCount;
}
 
Example #27
Source File: AbstractSybaseBulkLoader.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void bindObjectsAndExecute(List mithraObjects, Connection con) throws BulkLoaderException, SQLException
{
    for (Iterator it = mithraObjects.iterator(); it.hasNext();)
    {
        bindObject((MithraObject) it.next());
    }
    execute(con);
}
 
Example #28
Source File: TrivialJsonSerialWriter.java    From reladomo with Apache License 2.0 4 votes vote down vote up
@Override
public void endReladomoObject(MithraObject reladomoObject, AppendableSerialContext context) throws IOException
{
    context.getAppendable().append('}');
    context.endObject();
}
 
Example #29
Source File: AbstractNonDatedCache.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void reindex(MithraObject object, AttributeUpdateWrapper updateWrapper)
{
    throw new RuntimeException("should not get here");
}
 
Example #30
Source File: AbstractDatedCache.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void remove(MithraObject object)
{
    // todo: rezaem: implement not implemented method
    throw new RuntimeException("not implemented");
}