Java Code Examples for com.thinkaurelius.titan.core.PropertyKey#cardinality()

The following examples show how to use com.thinkaurelius.titan.core.PropertyKey#cardinality() . 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: Titan1Graph.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public Titan1Graph() {
    //determine multi-properties once at startup
    TitanManagement mgmt = null;
    try {
        mgmt = Titan1GraphDatabase.getGraphInstance().openManagement();
        Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class);
        multiProperties = new HashSet<>();
        for (PropertyKey key : keys) {
            if (key.cardinality() != Cardinality.SINGLE) {
                multiProperties.add(key.name());
            }
        }
    } finally {
        if (mgmt != null) {
            mgmt.rollback();
        }
    }
}
 
Example 2
Source File: StandardKeyInformation.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public StandardKeyInformation(PropertyKey key, Parameter... parameters) {
    Preconditions.checkNotNull(key);
    Preconditions.checkNotNull(parameters);
    this.dataType = key.dataType();
    this.parameters = parameters;
    this.cardinality = key.cardinality();
}
 
Example 3
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private TitanGraphIndex createCompositeIndex(String indexName, ElementCategory elementCategory, boolean unique, TitanSchemaType constraint, PropertyKey... keys) {
    checkIndexName(indexName);
    Preconditions.checkArgument(keys != null && keys.length > 0, "Need to provide keys to index [%s]", indexName);
    Preconditions.checkArgument(!unique || elementCategory == ElementCategory.VERTEX, "Unique indexes can only be created on vertices [%s]", indexName);
    boolean allSingleKeys = true;
    boolean oneNewKey = false;
    for (PropertyKey key : keys) {
        Preconditions.checkArgument(key != null && key instanceof PropertyKeyVertex, "Need to provide valid keys: %s", key);
        if (key.cardinality() != Cardinality.SINGLE) allSingleKeys = false;
        if (key.isNew()) oneNewKey = true;
        else updatedTypes.add((PropertyKeyVertex) key);
    }

    Cardinality indexCardinality;
    if (unique) indexCardinality = Cardinality.SINGLE;
    else indexCardinality = (allSingleKeys ? Cardinality.SET : Cardinality.LIST);

    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, true);
    def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
    def.setValue(TypeDefinitionCategory.BACKING_INDEX, Token.INTERNAL_INDEX_NAME);
    def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
    def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, indexCardinality);
    def.setValue(TypeDefinitionCategory.STATUS, oneNewKey ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
    TitanSchemaVertex indexVertex = transaction.makeSchemaVertex(TitanSchemaCategory.GRAPHINDEX, indexName, def);
    for (int i = 0; i < keys.length; i++) {
        Parameter[] paras = {ParameterType.INDEX_POSITION.getParameter(i)};
        addSchemaEdge(indexVertex, keys[i], TypeDefinitionCategory.INDEX_FIELD, paras);
    }

    Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof TitanSchemaVertex));
    if (constraint != null) {
        addSchemaEdge(indexVertex, (TitanSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
    }
    updateSchemaVertex(indexVertex);
    TitanGraphIndexWrapper index = new TitanGraphIndexWrapper(indexVertex.asIndexType());
    if (!oneNewKey) updateIndex(index, SchemaAction.REGISTER_INDEX);
    return index;
}
 
Example 4
Source File: HasStepFolder.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static boolean validTitanOrder(OrderGlobalStep ostep, Traversal rootTraversal,
                                      boolean isVertexOrder) {
    for (Comparator comp : (List<Comparator>) ostep.getComparators()) {
        if (!(comp instanceof ElementValueComparator)) return false;
        ElementValueComparator evc = (ElementValueComparator) comp;
        if (!(evc.getValueComparator() instanceof Order)) return false;

        TitanTransaction tx = TitanTraversalUtil.getTx(rootTraversal.asAdmin());
        String key = evc.getPropertyKey();
        PropertyKey pkey = tx.getPropertyKey(key);
        if (pkey == null || !(Comparable.class.isAssignableFrom(pkey.dataType()))) return false;
        if (isVertexOrder && pkey.cardinality() != Cardinality.SINGLE) return false;
    }
    return true;
}
 
Example 5
Source File: PropertyKeyDefinition.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public PropertyKeyDefinition(PropertyKey key) {
    this(key.name(),key.longId(),key.cardinality(),key.dataType());
}