use of org.apache.atlas.typesystem.types.EnumType in project incubator-atlas by apache.
the class GraphBackedSearchIndexerTest method verifyUserDefinedTypeIndex.
@Test
public void verifyUserDefinedTypeIndex() throws AtlasException {
AtlasGraph graph = TestUtils.getGraph();
AtlasGraphManagement managementSystem = graph.getManagementSystem();
try {
TypeSystem typeSystem = TypeSystem.getInstance();
String enumName = "randomEnum" + RandomStringUtils.randomAlphanumeric(10);
EnumType managedType = typeSystem.defineEnumType(enumName, new EnumValue("randomEnumValue", 0));
HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = createClassTypeDef("Database", "Database type description", null, TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("managedType", managedType));
ClassType databaseType = typeSystem.defineClassType(databaseTypeDefinition);
graphBackedSearchIndexer.onAdd(Arrays.asList(databaseType));
verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY, false);
verifyVertexIndexContains(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY);
verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.SUPER_TYPES_PROPERTY_KEY, false);
verifyVertexIndexContains(managementSystem, "Database.managedType");
} finally {
//search indexer uses its own titan management transaction
managementSystem.rollback();
}
}
use of org.apache.atlas.typesystem.types.EnumType in project incubator-atlas by apache.
the class StructInstance method setInt.
public void setInt(String attrName, int val) throws AtlasException {
AttributeInfo i = fieldMapping.fields.get(attrName);
if (i == null) {
throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
}
if (i.dataType() != DataTypes.INT_TYPE && !(i.dataType() instanceof EnumType)) {
throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.INT_TYPE.getName()));
}
int pos = fieldMapping.fieldPos.get(attrName);
int nullPos = fieldMapping.fieldNullPos.get(attrName);
nullFlags[nullPos] = false;
ints[pos] = val;
explicitSets[nullPos] = true;
}
use of org.apache.atlas.typesystem.types.EnumType in project incubator-atlas by apache.
the class StructInstance method getInt.
public int getInt(String attrName) throws AtlasException {
AttributeInfo i = fieldMapping.fields.get(attrName);
if (i == null) {
throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
}
if (i.dataType() != DataTypes.INT_TYPE && !(i.dataType() instanceof EnumType)) {
throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic get method", attrName, getTypeName(), DataTypes.INT_TYPE.getName()));
}
int pos = fieldMapping.fieldPos.get(attrName);
int nullPos = fieldMapping.fieldNullPos.get(attrName);
if (nullFlags[nullPos]) {
return DataTypes.INT_TYPE.nullValue();
}
return ints[pos];
}
Aggregations