use of org.apache.atlas.typesystem.types.IDataType in project incubator-atlas by apache.
the class VertexLookupContext method findReferencedInstancesToPreLoad.
private void findReferencedInstancesToPreLoad(ITypedReferenceableInstance newInstance) throws AtlasException {
//pre-load vertices for reference fields
for (AttributeInfo info : newInstance.fieldMapping().fields.values()) {
if (info.dataType().getTypeCategory() == TypeCategory.CLASS) {
ITypedReferenceableInstance newAttributeValue = (ITypedReferenceableInstance) newInstance.get(info.name);
addAdditionalInstance(newAttributeValue);
}
if (info.dataType().getTypeCategory() == TypeCategory.ARRAY) {
IDataType elementType = ((DataTypes.ArrayType) info.dataType()).getElemType();
if (elementType.getTypeCategory() == TypeCategory.CLASS) {
List<ITypedReferenceableInstance> newElements = (List) newInstance.get(info.name);
addAdditionalInstances(newElements);
}
}
if (info.dataType().getTypeCategory() == TypeCategory.MAP) {
IDataType elementType = ((DataTypes.MapType) info.dataType()).getValueType();
if (elementType.getTypeCategory() == TypeCategory.CLASS) {
Map<Object, ITypedReferenceableInstance> newAttribute = (Map<Object, ITypedReferenceableInstance>) newInstance.get(info.name);
if (newAttribute != null) {
addAdditionalInstances(newAttribute.values());
}
}
}
}
}
use of org.apache.atlas.typesystem.types.IDataType in project incubator-atlas by apache.
the class StoreBackedTypeCache method onTypeFault.
/**
* Check the type store for the requested type.
* If found in the type store, the type and any required super and attribute types
* are loaded from the type store, and added to the cache.
*/
@Override
public IDataType onTypeFault(String typeName) throws AtlasException {
// Type is not cached - check the type store.
// Any super and attribute types needed by the requested type
// which are not cached will also be loaded from the store.
Context context = new Context();
TypesDef typesDef = getTypeFromStore(typeName, context);
if (typesDef.isEmpty()) {
// Type not found in the type store.
return null;
}
// Add all types that were loaded from the store to the cache.
TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(context.getTypesDef(), false);
Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded();
putAll(typesAdded.values());
return typesAdded.get(typeName);
}
use of org.apache.atlas.typesystem.types.IDataType in project incubator-atlas by apache.
the class DefaultTypeCache method putAll.
/*
* (non-Javadoc)
* @see
* org.apache.atlas.typesystem.types.cache.TypeCache#putAll(java
* .util.Collection)
*/
@Override
public void putAll(Collection<IDataType> types) throws AtlasException {
for (IDataType type : types) {
assertValidType(type);
types_.put(type.getName(), type);
}
}
use of org.apache.atlas.typesystem.types.IDataType in project incubator-atlas by apache.
the class Gremlin3ExpressionFactory method generateFieldExpression.
@Override
public GroovyExpression generateFieldExpression(GroovyExpression parent, FieldInfo fInfo, String propertyName, boolean inSelect) {
AttributeInfo attrInfo = fInfo.attrInfo();
IDataType attrType = attrInfo.dataType();
GroovyExpression propertyNameExpr = new LiteralExpression(propertyName);
//Whether it is the user or shared graph does not matter here, since we're
//just getting the conversion expression. Ideally that would be moved someplace else.
AtlasGraph graph = AtlasGraphProvider.getGraphInstance();
if (inSelect) {
GroovyExpression expr = new FunctionCallExpression(parent, PROPERTY_METHOD, propertyNameExpr);
expr = new FunctionCallExpression(expr, OR_ELSE_METHOD, LiteralExpression.NULL);
return graph.generatePersisentToLogicalConversionExpression(expr, attrType);
} else {
GroovyExpression unmapped = new FunctionCallExpression(TraversalStepType.FLAT_MAP_TO_VALUES, parent, VALUES_METHOD, propertyNameExpr);
if (graph.isPropertyValueConversionNeeded(attrType)) {
GroovyExpression toConvert = new FunctionCallExpression(getItVariable(), GET_METHOD);
GroovyExpression conversionFunction = graph.generatePersisentToLogicalConversionExpression(toConvert, attrType);
return new FunctionCallExpression(TraversalStepType.MAP_TO_VALUE, unmapped, MAP_METHOD, new ClosureExpression(conversionFunction));
} else {
return unmapped;
}
}
}
use of org.apache.atlas.typesystem.types.IDataType in project incubator-atlas by apache.
the class GraphBackedMetadataRepository method getEntityDefinition.
@Override
@GraphTransaction
public ITypedReferenceableInstance getEntityDefinition(String entityType, String attribute, Object value) throws AtlasException {
if (LOG.isDebugEnabled()) {
LOG.debug("Retrieving entity with type={} and {}={}", entityType, attribute, value);
}
IDataType type = typeSystem.getDataType(IDataType.class, entityType);
String propertyKey = getFieldNameInVertex(type, attribute);
AtlasVertex instanceVertex = graphHelper.findVertex(propertyKey, value, Constants.ENTITY_TYPE_PROPERTY_KEY, entityType, Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name());
String guid = GraphHelper.getGuid(instanceVertex);
ITypedReferenceableInstance cached = RequestContext.get().getInstanceV1(guid);
if (cached != null) {
return cached;
}
return graphToInstanceMapper.mapGraphToTypedInstance(guid, instanceVertex);
}
Aggregations