Search in sources :

Example 1 with StructInstance

use of org.apache.atlas.typesystem.persistence.StructInstance in project incubator-atlas by apache.

the class ClassType method createInstanceWithTraits.

public ITypedReferenceableInstance createInstanceWithTraits(Id id, AtlasSystemAttributes systemAttributes, Referenceable r, String... traitNames) throws AtlasException {
    ImmutableMap.Builder<String, ITypedStruct> b = new ImmutableBiMap.Builder<>();
    if (traitNames != null) {
        for (String t : traitNames) {
            TraitType tType = typeSystem.getDataType(TraitType.class, t);
            IStruct iTraitObject = r == null ? null : r.getTrait(t);
            ITypedStruct trait = iTraitObject == null ? tType.createInstance() : tType.convert(iTraitObject, Multiplicity.REQUIRED);
            b.put(t, trait);
        }
    }
    return new ReferenceableInstance(id == null ? new Id(getName()) : id, getName(), systemAttributes, fieldMapping, new boolean[fieldMapping.fields.size()], new boolean[fieldMapping.fields.size()], fieldMapping.numBools == 0 ? null : new boolean[fieldMapping.numBools], fieldMapping.numBytes == 0 ? null : new byte[fieldMapping.numBytes], fieldMapping.numShorts == 0 ? null : new short[fieldMapping.numShorts], fieldMapping.numInts == 0 ? null : new int[fieldMapping.numInts], fieldMapping.numLongs == 0 ? null : new long[fieldMapping.numLongs], fieldMapping.numFloats == 0 ? null : new float[fieldMapping.numFloats], fieldMapping.numDoubles == 0 ? null : new double[fieldMapping.numDoubles], fieldMapping.numBigDecimals == 0 ? null : new BigDecimal[fieldMapping.numBigDecimals], fieldMapping.numBigInts == 0 ? null : new BigInteger[fieldMapping.numBigInts], fieldMapping.numDates == 0 ? null : new Date[fieldMapping.numDates], fieldMapping.numStrings == 0 ? null : new String[fieldMapping.numStrings], fieldMapping.numArrays == 0 ? null : new ImmutableList[fieldMapping.numArrays], fieldMapping.numMaps == 0 ? null : new ImmutableMap[fieldMapping.numMaps], fieldMapping.numStructs == 0 ? null : new StructInstance[fieldMapping.numStructs], fieldMapping.numReferenceables == 0 ? null : new ReferenceableInstance[fieldMapping.numReferenceables], fieldMapping.numReferenceables == 0 ? null : new Id[fieldMapping.numReferenceables], b.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) StructInstance(org.apache.atlas.typesystem.persistence.StructInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ImmutableMap(com.google.common.collect.ImmutableMap) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) IStruct(org.apache.atlas.typesystem.IStruct)

Example 2 with StructInstance

use of org.apache.atlas.typesystem.persistence.StructInstance in project incubator-atlas by apache.

the class StructStore method load.

@Override
protected void load(StructInstance instance, int colPos, int pos) throws RepositoryException {
    StructInstance s = (StructInstance) structType.createInstance();
    instance.structs[colPos] = s;
    for (Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) {
        IAttributeStore attributeStore = e.getValue();
        attributeStore.load(pos, structType, s);
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) StructInstance(org.apache.atlas.typesystem.persistence.StructInstance) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 3 with StructInstance

use of org.apache.atlas.typesystem.persistence.StructInstance in project incubator-atlas by apache.

the class AtlasObjectIdConverter method hasAnyAssignedAttribute.

private boolean hasAnyAssignedAttribute(IReferenceableInstance rInstance) {
    boolean ret = false;
    if (rInstance instanceof StructInstance) {
        StructInstance sInstance = (StructInstance) rInstance;
        Map<String, Object> attributes = null;
        try {
            attributes = sInstance.getValuesMap();
        } catch (AtlasException e) {
        // ignore
        }
        if (MapUtils.isNotEmpty(attributes)) {
            for (String attrName : attributes.keySet()) {
                try {
                    if (sInstance.isValueSet(attrName)) {
                        ret = true;
                        break;
                    }
                } catch (AtlasException e) {
                // ignore
                }
            }
        }
    } else if (rInstance instanceof Referenceable) {
        Referenceable referenceable = (Referenceable) rInstance;
        ret = MapUtils.isNotEmpty(referenceable.getValuesMap());
    }
    return ret;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) StructInstance(org.apache.atlas.typesystem.persistence.StructInstance) AtlasException(org.apache.atlas.AtlasException)

Example 4 with StructInstance

use of org.apache.atlas.typesystem.persistence.StructInstance in project incubator-atlas by apache.

the class TraitStore method store.

void store(ReferenceableInstance i) throws RepositoryException {
    int pos = idPosMap.get(i.getId());
    StructInstance s = (StructInstance) i.getTrait(hierarchicalType.getName());
    super.storeFields(pos, s);
    classNameStore.set(pos, i.getTypeName());
}
Also used : StructInstance(org.apache.atlas.typesystem.persistence.StructInstance)

Example 5 with StructInstance

use of org.apache.atlas.typesystem.persistence.StructInstance in project incubator-atlas by apache.

the class TraitStore method load.

void load(ReferenceableInstance i) throws RepositoryException {
    int pos = idPosMap.get(i.getId());
    StructInstance s = (StructInstance) i.getTrait(hierarchicalType.getName());
    super.loadFields(pos, s);
}
Also used : StructInstance(org.apache.atlas.typesystem.persistence.StructInstance)

Aggregations

StructInstance (org.apache.atlas.typesystem.persistence.StructInstance)6 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)2 Map (java.util.Map)2 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)2 ImmutableList (com.google.common.collect.ImmutableList)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 AtlasException (org.apache.atlas.AtlasException)1 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)1 IStruct (org.apache.atlas.typesystem.IStruct)1 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)1 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)1 Referenceable (org.apache.atlas.typesystem.Referenceable)1 Id (org.apache.atlas.typesystem.persistence.Id)1 ReferenceableInstance (org.apache.atlas.typesystem.persistence.ReferenceableInstance)1