com.gs.fw.common.mithra.attribute.Attribute Java Examples

The following examples show how to use com.gs.fw.common.mithra.attribute.Attribute. 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: ColumnarInStream.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public BitsInBytes decodeColumnarNull(SingleColumnAttribute attr, List data) throws IOException
{
    int hasNulls = in.read();
    if (hasNulls == 0)
    {
        return null;
    }
    BitsInBytes result = BitsInBytes.readFromInputStream(in, data.size());
    Attribute nullableAttribute = (Attribute) attr;
    for(int i=0;i<data.size();i++)
    {
        if (result.get(i))
        {
            nullableAttribute.setValueNull(data.get(i));
        }
    }
    return result;
}
 
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: BatchUpdateOperation.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public List<UpdateOperation> getUpdateOperations()
{
    if (isIncrement())
    {
        return this.updateOperations;
    }
    MithraFastList<Attribute> allAttribute = computeKeyAttributes();
    Extractor[] keyExtractors = new Extractor[allAttribute.size()];
    allAttribute.toArray(keyExtractors);
    FullUniqueIndex updatedObjects = new FullUniqueIndex(keyExtractors, this.updateOperations.size());
    for(int i=updateOperations.size() - 1; i >= 0; i--)
    {
        UpdateOperation updateOperation = updateOperations.get(i);
        if (updatedObjects.put(getDataWithKey(updateOperation)) != null)
        {
            updateOperations.set(i, null);
        }
    }
    if (updatedObjects.size() != updateOperations.size())
    {
        updateOperations.removeNullItems();
    }
    return updateOperations;
}
 
Example #4
Source File: MsSqlDatabaseType.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public void setMultiUpdateViaJoinQuery(
        Object source,
        List updates,
        Attribute[] prototypeArray,
        MithraFastList<Attribute> nullAttributes,
        int pkAttributeCount,
        TupleTempContext tempContext,
        MithraObjectPortal mithraObjectPortal,
        String fullyQualifiedTableNameGenericSource,
        StringBuilder builder)
{
    this.startUpdateViaJoinQuery(fullyQualifiedTableNameGenericSource, builder);
    builder.append(" set ");
    for (int i = 0; i < updates.size(); i++)
    {
        AttributeUpdateWrapper wrapper = (AttributeUpdateWrapper) updates.get(i);
        if (i > 0)
        {
            builder.append(", ");
        }
        builder.append(wrapper.getSetAttributeSql());
    }
    this.appendTempTableJoin(source, prototypeArray, nullAttributes, pkAttributeCount, tempContext, mithraObjectPortal, fullyQualifiedTableNameGenericSource, builder);
}
 
Example #5
Source File: UpdateOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
public TransactionOperation combineUpdate(TransactionOperation op)
{
    if (op instanceof UpdateOperation && this.getPortal() == op.getPortal())
    {
        UpdateOperation incoming = (UpdateOperation) op;
        if (op.getMithraObject() == this.getMithraObject())
        {
            for(int i=0;i<incoming.updates.size();i++)
            {
                this.addOperation(incoming.updates.get(i));
            }
            return this;
        }
        if (this.canBeBatched(incoming))
        {
            if (this.getMithraObject() == op.getMithraObject()) return op;
            Attribute diffPk = this.canBeMultiUpdated(incoming);
            if (diffPk != null)
            {
                return new MultiUpdateOperation(this, incoming, diffPk);
            }
            return new BatchUpdateOperation(this, incoming);
        }
    }
    return null;
}
 
Example #6
Source File: CustomerAccountDatabaseObjectAbstract.java    From reladomo-scala with Apache License 2.0 5 votes vote down vote up
public List getSimulatedSequenceInitValues()
{
	ArrayList simulatedSequenceInitValues = new ArrayList(1);
	Attribute[] primaryKeyAttributes = CustomerAccountFinder.getPrimaryKeyAttributes();
	SimulatedSequenceInitValues initValues = null;
	return simulatedSequenceInitValues;
}
 
Example #7
Source File: ReladomoDeserializer.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected Operation constructMultiPkOp(List<MithraDataObject> listToRefresh, Attribute[] pkAttributes)
{
    TupleAttribute ta = pkAttributes[0].tupleWith(pkAttributes[1]);
    for(int i=2;i<pkAttributes.length;i++)
    {
        ta = ta.tupleWith(pkAttributes[i]);
    }
    return ta.in(listToRefresh, pkAttributes);
}
 
Example #8
Source File: TwoExtractorHashStrategy.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public TwoExtractorHashStrategy(Extractor first, Extractor second)
{
    this.first = first;
    this.second = second;
    if (first instanceof Attribute && second instanceof Attribute)
    {
        extractors = new Attribute[] { (Attribute) first, (Attribute) second};
    }
    else
    {
        extractors = new Extractor[] { first, second };
    }
}
 
Example #9
Source File: OrOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public Operation zSubstituteForTempJoin(Map<Attribute, Attribute> attributeMap, Object prototypeObject)
{
    InternalList newOps = new InternalList(operations.length);
    for (int i = 0; i < operations.length; i++)
    {
        Operation newOp = operations[i].zSubstituteForTempJoin(attributeMap, prototypeObject);
        if (newOp != null) newOps.add(newOp);
    }
    if (newOps.size() == 0) return null;
    if (newOps.size() == 1) return (Operation) newOps.get(0);
    Operation[] newOpArray = new Operation[newOps.size()];
    newOps.toArray(newOpArray);
    return new OrOperation(newOpArray);
}
 
Example #10
Source File: SerializationConfig.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public SerializationConfig withoutTheseAttributes(Attribute... attributes)
{
    SerializationConfig config = new SerializationConfig();
    config.rootNode = this.rootNode.withoutTheseAttributes(attributes);
    config.annotatedContextNames = this.annotatedContextNames;
    config.excludedMethods = this.excludedMethods;
    config.serializeMetaData = this.serializeMetaData;
    return config;
}
 
Example #11
Source File: TransitivePropagator.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private UnifiedMap<MapperStack, InternalList> createOperationsToInsert()
{
    UnifiedMap<MapperStack, InternalList> operationsWithMapperStackToInsert = new UnifiedMap<MapperStack, InternalList>();

    for(Iterator<ObjectWithMapperStack<Attribute>> it = equalityMap.keySet().iterator(); it.hasNext();)
    {
        ObjectWithMapperStack<Attribute> attributeWithStack = it.next();
        if (existingOperationsWithMapperStack.get(attributeWithStack) == null)
        {
            for(Iterator<ObjectWithMapperStack<Attribute>> candidateIt = equalityMap.get(attributeWithStack).iterator(); candidateIt.hasNext();)
            {
                AtomicOperation otherOp = existingOperationsWithMapperStack.get(candidateIt.next());
                if (otherOp != null)
                {
                    Operation toInsert = otherOp.susbtituteOtherAttribute(attributeWithStack.getObject());
                    if (toInsert != null)
                    {
                        InternalList insertList = operationsWithMapperStackToInsert.get(attributeWithStack.getMapperStack());
                        if (insertList == null)
                        {
                            insertList = new InternalList(2);
                            operationsWithMapperStackToInsert.put(attributeWithStack.getMapperStack(), insertList);
                        }
                        insertList.add(toInsert);
                        //todo: instead of breaking here, we could pick the best operation out of several possible
                        break;
                    }
                }
            }
        }
    }
    return operationsWithMapperStackToInsert;
}
 
Example #12
Source File: NonUniqueOffHeapIndex.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
public void reportSpaceUsage(Logger logger, String className)
{
    String msg = className+ " index on ";
    for(Extractor e: onHeapIndexExtractors)
    {
        msg += ((Attribute) e).getAttributeName()+", ";
    }
    this.storage.reportSpaceUsage(logger, msg);
}
 
Example #13
Source File: MultiEqualityOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public Operation getSusbstitutedEquality(Attribute original, Attribute newAttribute)
{
    for (int i = 0; i < this.atomicOperations.length; i++)
    {
        AtomicOperation aeo = atomicOperations[i];
        if (aeo instanceof AtomicEqualityOperation && aeo.getAttribute().equals(original))
        {
            return aeo.susbtituteOtherAttribute(newAttribute);
        }
    }
    return null;
}
 
Example #14
Source File: AbstractAtomicOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public Operation zSubstituteForTempJoin(Map<Attribute, Attribute> attributeMap, Object prototypeObject)
{
    Attribute newAttribute = attributeMap.get(this.attribute);
    if (newAttribute != null)
    {
        return susbtituteOtherAttribute(newAttribute);
    }
    return null;
}
 
Example #15
Source File: MultiEqualityOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected int getOperationPosition(Attribute a)
{
    for (int i = 0; i < atomicOperations.length; i++)
    {
        AtomicOperation op = atomicOperations[i];
        if (op.getAttribute().equals(a))
        {
            return i;
        }
    }
    return -1;
}
 
Example #16
Source File: DependentLoaderFactoryImpl.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void addRelationshipAttribute(List<Pair<Extractor, Attribute>> list, Mapper mapper)
{
    this.relationshipAttributeMap.put(mapper.getAnyLeftAttribute(), mapper.getAnyRightAttribute());

    if (!mapper.getAnyRightAttribute().isAsOfAttribute() && !mapper.getAnyRightAttribute().isSourceAttribute())
    {
        list.add(new Pair(mapper.getAnyLeftAttribute(), mapper.getAnyRightAttribute()));
    }
}
 
Example #17
Source File: DbExtractor.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void addClass(List data, RelatedFinder finder, BufferedWriter out) throws IOException
{
    if (!data.isEmpty())
    {
        Attribute[] attributes = finder.getPersistentAttributes();
        this.addHeader(out, finder.getClass(), attributes);
        this.addData(out, attributes, data);
        out.newLine();
    }
}
 
Example #18
Source File: CustomerDatabaseObjectAbstract.java    From reladomo-scala with Apache License 2.0 5 votes vote down vote up
public List getSimulatedSequenceInitValues()
{
	ArrayList simulatedSequenceInitValues = new ArrayList(1);
	Attribute[] primaryKeyAttributes = CustomerFinder.getPrimaryKeyAttributes();
	SimulatedSequenceInitValues initValues = null;
	return simulatedSequenceInitValues;
}
 
Example #19
Source File: TestIndexReference.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testSerializatioon() throws Exception
{
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bytes);
    out.writeObject(new IndexReference(new FullNonDatedCache(new Attribute[0], null), 0));
    assertNull(new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())).readObject());
}
 
Example #20
Source File: MultiUpdateOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private StringBuffer createFirstPartSingleKeySql(String fullyQualifiedTableName)
{
    StringBuffer buf = new StringBuffer(30 + this.updates.size()*20 + singleValuedPrimaryKeys.size() * 20);
    buf.append("update ");
    buf.append(fullyQualifiedTableName);
    buf.append(" set ");
    for(int i=0;i<updates.size();i++)
    {
        AttributeUpdateWrapper upd = updates.get(i);
        if (i > 0) buf.append(", ");
        buf.append(upd.getSetAttributeSql());
    }
    buf.append(" where ");
    if (this.versionAttribute != null)
    {
        buf.append((this.versionAttribute).getColumnName());
        buf.append(" = ? ");
        buf.append(" and ");
    }
    for(int i=0;i<this.singleValuedPrimaryKeys.size();)
    {
        Attribute attr = (Attribute) singleValuedPrimaryKeys.get(i);
        buf.append(attr.getColumnName());
        if (attr.isAttributeNull(this.dataObjects[0]))
        {
            buf.append(" IS NULL ");
            this.singleValuedPrimaryKeys.remove(i);
        }
        else
        {
            buf.append(" = ? ");
            i++;
        }
        buf.append(" and ");
    }
    return buf;
}
 
Example #21
Source File: MithraAbstractObjectPortal.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private boolean hasNoToManyGroupBys(List<MithraGroupByAttribute> groupByAttributes)
{
    for (int i = 0; i < groupByAttributes.size(); i++)
    {
        Attribute attr = groupByAttributes.get(i).getAttribute();
        if (attr instanceof MappedAttribute)
        {
            if (((MappedAttribute) attr).getMapper().isToMany()) return false;
        }
    }
    return true;
}
 
Example #22
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 #23
Source File: ConstDivisionCalculatorDouble.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void appendToString(ToStringContext toStringContext)
{
    toStringContext.append("(");
    ((Attribute)this.attribute).zAppendToString(toStringContext);
    toStringContext.append("/");
    toStringContext.append(""+divisor);
    toStringContext.append(")");
}
 
Example #24
Source File: AttributeBasedOrderBy.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void addDepenedentAttributesToSet(Set set)
{
    Attribute a = this.attribute;
    while (a instanceof MappedAttribute)
    {
        a = ((MappedAttribute) a).getWrappedAttribute();
    }
    set.add(a);
}
 
Example #25
Source File: AbstractDatedCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected void populateIndexAttributes(Index index, int indexRef)
{
    Extractor[] rawAttributes = (Extractor[]) index.getExtractors();
    Attribute[] attributes = new Attribute[rawAttributes.length + this.asOfAttributes.length];
    System.arraycopy(rawAttributes, 0, attributes, 0, rawAttributes.length);
    System.arraycopy(this.asOfAttributes, 0, attributes, rawAttributes.length, this.asOfAttributes.length);
    if (indexRef != this.indexToAttributesMap.size())
    {
        throw new RuntimeException("wacky index references");
    }
    this.indexToAttributesMap.add(attributes);
}
 
Example #26
Source File: TestCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void runFullCachePerformance()
{
    UserDatabaseObject udo = new UserDatabaseObject();
    FullNonDatedCache fullCache = new FullNonDatedCache(UserFinder.getPrimaryKeyAttributes(), udo);
    fullCache.addUniqueIndex(USER_ID_INDEX, new Attribute[] { UserFinder.userId() } );

    UserData userData0 = createUserData(0, "moh");
    User user0 = (User) fullCache.getObjectFromData(userData0);
    fullCache.getObjectFromData(createUserData(1, "moh"));
    fullCache.getObjectFromData(createUserData(2, "moh"));
    fullCache.getObjectFromData(createUserData(3, "doh"));
    fullCache.getObjectFromData(createUserData(4, "poh"));
    fullCache.getObjectFromData(createUserData(5, "joh"));
    fullCache.getObjectFromData(createUserData(6, null));
    fullCache.getObjectFromData(createUserData(7, null));

    int max = 200000;
    int loop = 1;
    for (int i=100;i< max;i++)
    {
        fullCache.getObjectFromData(createUserData(i, "name "+i%10));
    }

    Attribute[] pkArray = UserFinder.getPrimaryKeyAttributes();
    UserData tempData = createUserData(0, "moh");
    for(int j=0;j<loop;j++)
    {
        for(int i=100;i< max;i++)
        {
            tempData.setId(i);
            User user = (User) fullCache.getAsOne(tempData, pkArray);
            assertEquals(i, user.getId());
        }
    }
}
 
Example #27
Source File: TestIndexCreation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testLewPosition()
{
    TestCache cache = new TestCache();
    TxMonkeyFinder.initializeIndicies(cache);
    Index[] indices = cache.getIndices();
    assertEquals(2, indices.length);
    assertTrue(indices[0].isUnique());
    assertEquals(1, indices[1].getExtractors().length);
    assertEquals("animalGroupId", ((Attribute) indices[1].getExtractors()[0]).getAttributeName());
}
 
Example #28
Source File: TransitivePropagator.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void processEqualities()
{
    final UnifiedMap<ObjectWithMapperStack<Attribute>, UnifiedSet<ObjectWithMapperStack<Attribute>>> equalityMap = this.getEqualityMap();
    final boolean[] anyChanged = new boolean[1];
    do
    {
        anyChanged[0] = false;
        equalityMap.forEachKeyValue(new Procedure2<ObjectWithMapperStack<Attribute>, UnifiedSet<ObjectWithMapperStack<Attribute>>>()
        {
            public void value(ObjectWithMapperStack<Attribute> attribute, UnifiedSet<ObjectWithMapperStack<Attribute>> equalities)
            {
                InternalList equalityList = new InternalList(equalities);
                for (int i = 0; i < equalityList.size(); i++)
                {
                    UnifiedSet<ObjectWithMapperStack<Attribute>> setToAdd = equalityMap.get(equalityList.get(i));
                    for (Iterator<ObjectWithMapperStack<Attribute>> setIterator = setToAdd.iterator(); setIterator.hasNext(); )
                    {
                        ObjectWithMapperStack<Attribute> possibleNewEquality = setIterator.next();
                        if (!possibleNewEquality.equals(attribute) && equalities.add(possibleNewEquality))
                        {
                            anyChanged[0] = true;
                            equalityList.add(possibleNewEquality); // growing the collection that we're looping over.
                            equalities.add(possibleNewEquality);
                        }
                    }
                }
            }
        });
    } while(anyChanged[0]);
}
 
Example #29
Source File: MultiEqualityMapper.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public Set<Attribute> getAllLeftAttributes()
{
    fixLeftAttributes();
    UnifiedSet result = new UnifiedSet(this.leftAttributes.length);
    for(int i=0;i<this.leftAttributes.length;i++) result.add(this.leftAttributes[i]);
    return result;
}
 
Example #30
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);
}