com.thinkaurelius.titan.graphdb.internal.InternalRelationType Java Examples

The following examples show how to use com.thinkaurelius.titan.graphdb.internal.InternalRelationType. 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: MizoTitanRelationType.java    From mizo with Apache License 2.0 6 votes vote down vote up
public MizoTitanRelationType(InternalRelationType relationType) {
    status = relationType.getStatus();
    sortKey = relationType.getSortKey();
    name = relationType.name();
    id = relationType.longId();
    isInvisibleType = relationType.isInvisibleType();
    signature = relationType.getSignature();
    sortOrder = relationType.getSortOrder();
    multiplicity = relationType.multiplicity();
    consistencyModifier = relationType.getConsistencyModifier();
    ttl = relationType.getTTL();
    isPropertyKey = relationType.isPropertyKey();
    isEdgeLabel = relationType.isEdgeLabel();

    if (relationType instanceof PropertyKey) {
        dataType = ((PropertyKey)relationType).dataType();
        cardinality = ((PropertyKey)relationType).cardinality();
    } else {
        dataType = null;
        cardinality = null;
    }
}
 
Example #2
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public <T extends RelationType> Iterable<T> getRelationTypes(Class<T> clazz) {
    Preconditions.checkNotNull(clazz);
    Iterable<? extends TitanVertex> types = null;
    if (PropertyKey.class.equals(clazz)) {
        types = QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.PROPERTYKEY);
    } else if (EdgeLabel.class.equals(clazz)) {
        types = QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.EDGELABEL);
    } else if (RelationType.class.equals(clazz)) {
        types = Iterables.concat(getRelationTypes(EdgeLabel.class), getRelationTypes(PropertyKey.class));
    } else throw new IllegalArgumentException("Unknown type class: " + clazz);
    return Iterables.filter(Iterables.filter(types, clazz), new Predicate<T>() {
        @Override
        public boolean apply(@Nullable T t) {
            //Filter out all relation type indexes
            return ((InternalRelationType) t).getBaseType() == null;
        }
    });
}
 
Example #3
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<RelationTypeIndex> getRelationIndexes(final RelationType type) {
    Preconditions.checkArgument(type != null && type instanceof InternalRelationType, "Invalid relation type provided: %s", type);
    return Iterables.transform(Iterables.filter(((InternalRelationType) type).getRelationIndexes(), new Predicate<InternalRelationType>() {
        @Override
        public boolean apply(@Nullable InternalRelationType internalRelationType) {
            return !type.equals(internalRelationType);
        }
    }), new Function<InternalRelationType, RelationTypeIndex>() {
        @Nullable
        @Override
        public RelationTypeIndex apply(@Nullable InternalRelationType internalType) {
            return new RelationTypeIndexWrapper(internalType);
        }
    });
}
 
Example #4
Source File: MizoRDD.java    From mizo with Apache License 2.0 6 votes vote down vote up
/**
 * Given a path for Titan config file, connects and gets the internal Titan types,
 * converting them to MizoTitanRelationTypes mapped by type-ids
 * @param titanConfigPath Path to Titan's config path
 * @return Mapping between relation type-ids to InternalRelationType instances
 */
protected static HashMap<Long, MizoTitanRelationType> loadRelationTypes(String titanConfigPath) {
    TitanGraph g = TitanFactory.open(titanConfigPath);
    StandardTitanTx tx = (StandardTitanTx)g.buildTransaction().readOnly().start();

    HashMap<Long, MizoTitanRelationType> relations = Maps.newHashMap();

    tx.query()
            .has(BaseKey.SchemaCategory, Contain.IN, Lists.newArrayList(TitanSchemaCategory.values()))
            .vertices()
            .forEach(v -> {
                if (v instanceof InternalRelationType)
                    relations.put(v.longId(), new MizoTitanRelationType((InternalRelationType)v));
            });

    tx.close();

    try {
        ((StandardTitanGraph)g).getBackend().close();
    } catch (BackendException e) {
        e.printStackTrace();
    }

    return relations;
}
 
Example #5
Source File: PredicateCondition.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean evaluate(E element) {
    RelationType type;
    if (key instanceof String) {
        type = ((InternalElement) element).tx().getRelationType((String) key);
        if (type == null)
            return satisfiesCondition(null);
    } else {
        type = (RelationType) key;
    }

    Preconditions.checkNotNull(type);

    if (type.isPropertyKey()) {
        Iterator<Object> iter = ElementHelper.getValues(element,(PropertyKey)type).iterator();
        if (iter.hasNext()) {
            while (iter.hasNext()) {
                if (satisfiesCondition(iter.next()))
                    return true;
            }
            return false;
        }
        return satisfiesCondition(null);
    } else {
        assert ((InternalRelationType)type).multiplicity().isUnique(Direction.OUT);
        return satisfiesCondition((TitanVertex)element.value(type.name()));
    }
}
 
Example #6
Source File: QueryUtil.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static InternalRelationType getType(StandardTitanTx tx, String typeName) {
    RelationType t = tx.getRelationType(typeName);
    if (t == null && !tx.getConfiguration().getAutoSchemaMaker().ignoreUndefinedQueryTypes()) {
        throw new IllegalArgumentException("Undefined type used in query: " + typeName);
    }
    return (InternalRelationType) t;
}
 
Example #7
Source File: RelationTypeVertex.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public Iterable<InternalRelationType> getRelationIndexes() {
    return Iterables.concat(ImmutableList.of(this),Iterables.transform(getRelated(TypeDefinitionCategory.RELATIONTYPE_INDEX,Direction.OUT),new Function<Entry, InternalRelationType>() {
        @Nullable
        @Override
        public InternalRelationType apply(@Nullable Entry entry) {
            assert entry.getSchemaType() instanceof InternalRelationType;
            return (InternalRelationType)entry.getSchemaType();
        }
    }));
}
 
Example #8
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public TitanSchemaElement getSchemaElement(long id) {
    TitanVertex v = transaction.getVertex(id);
    if (v == null) return null;
    if (v instanceof RelationType) {
        if (((InternalRelationType) v).getBaseType() == null) return (RelationType) v;
        return new RelationTypeIndexWrapper((InternalRelationType) v);
    }
    if (v instanceof TitanSchemaVertex) {
        TitanSchemaVertex sv = (TitanSchemaVertex) v;
        if (sv.getDefinition().containsKey(TypeDefinitionCategory.INTERNAL_INDEX)) {
            return new TitanGraphIndexWrapper(sv.asIndexType());
        }
    }
    throw new IllegalArgumentException("Not a valid schema element vertex: " + id);
}
 
Example #9
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the consistency level for a schema element (types and internal indexes)
 *
 * @param element
 * @return
 */
@Override
public ConsistencyModifier getConsistency(TitanSchemaElement element) {
    Preconditions.checkArgument(element != null);
    if (element instanceof RelationType) return ((InternalRelationType) element).getConsistencyModifier();
    else if (element instanceof TitanGraphIndex) {
        IndexType index = ((TitanGraphIndexWrapper) element).getBaseIndex();
        if (index.isMixedIndex()) return ConsistencyModifier.DEFAULT;
        return ((CompositeIndexType) index).getConsistencyModifier();
    } else return ConsistencyModifier.DEFAULT;
}
 
Example #10
Source File: RelationQueryCache.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public SliceQuery getQuery(final InternalRelationType type, Direction dir) {
    CacheEntry ce;
    try {
        ce = cache.get(type.longId(),new Callable<CacheEntry>() {
            @Override
            public CacheEntry call() throws Exception {
                return new CacheEntry(edgeSerializer,type);
            }
        });
    } catch (ExecutionException e) {
        throw new AssertionError("Should not happen: " + e.getMessage());
    }
    assert ce!=null;
    return ce.get(dir);
}
 
Example #11
Source File: RelationQueryCache.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public CacheEntry(EdgeSerializer edgeSerializer, InternalRelationType t) {
    if (t.isPropertyKey()) {
        out = edgeSerializer.getQuery(t, Direction.OUT,new EdgeSerializer.TypedInterval[t.getSortKey().length]);
        in = out;
        both = out;
    } else {
        out = edgeSerializer.getQuery(t,Direction.OUT,
                    new EdgeSerializer.TypedInterval[t.getSortKey().length]);
        in = edgeSerializer.getQuery(t,Direction.IN,
                new EdgeSerializer.TypedInterval[t.getSortKey().length]);
        both = edgeSerializer.getQuery(t,Direction.BOTH,
                new EdgeSerializer.TypedInterval[t.getSortKey().length]);
    }
}
 
Example #12
Source File: TypeUtil.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static boolean hasSimpleInternalVertexKeyIndex(PropertyKey key) {
        InternalRelationType type = (InternalRelationType)key;
        for (IndexType index : type.getKeyIndexes()) {
            if (index.getElement()== ElementCategory.VERTEX && index.isCompositeIndex()) {
                if (index.indexesKey(key)) return true;
//                InternalIndexType iIndex = (InternalIndexType)index;
//                if (iIndex.getFieldKeys().length==1) {
//                    assert iIndex.getFieldKeys()[0].getFieldKey().equals(key);
//                    return true;
//                }
            }
        }
        return false;
    }
 
Example #13
Source File: EmptyRelationType.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public InternalRelationType getBaseType() {
    return null;
}
 
Example #14
Source File: EmptyRelationType.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<InternalRelationType> getRelationIndexes() {
    return ImmutableSet.of((InternalRelationType)this);
}
 
Example #15
Source File: RelationTypeVertex.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public InternalRelationType getBaseType() {
    Entry entry = Iterables.getOnlyElement(getRelated(TypeDefinitionCategory.RELATIONTYPE_INDEX,Direction.IN),null);
    if (entry==null) return null;
    assert entry.getSchemaType() instanceof InternalRelationType;
    return (InternalRelationType)entry.getSchemaType();
}
 
Example #16
Source File: TypeUtil.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static boolean hasAnyIndex(PropertyKey key) {
    InternalRelationType type = (InternalRelationType) key;
    return !Iterables.isEmpty(type.getKeyIndexes()) ||
            Iterables.size(type.getRelationIndexes())>1; //The type itself is also returned as an index
}
 
Example #17
Source File: TypeUtil.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static InternalRelationType getBaseType(InternalRelationType type) {
    InternalRelationType baseType = type.getBaseType();
    if (baseType == null) return type;
    else return baseType;
}
 
Example #18
Source File: StandardTransactionLogProcessor.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
private static Iterable<MixedIndexType> getMixedIndexes(RelationType type) {
    if (!type.isPropertyKey()) return Collections.EMPTY_LIST;
    return Iterables.filter(Iterables.filter(((InternalRelationType)type).getKeyIndexes(),MIXED_INDEX_FILTER),MixedIndexType.class);
}
 
Example #19
Source File: RelationTypeIndexWrapper.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public InternalRelationType getWrappedType() {
    return type;
}
 
Example #20
Source File: RelationTypeIndexWrapper.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public RelationTypeIndexWrapper(InternalRelationType type) {
    Preconditions.checkArgument(type != null && type.getBaseType() != null);
    this.type = type;
}
 
Example #21
Source File: StandardTitanGraph.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static boolean acquireLock(InternalRelation relation, int pos, boolean acquireLocksConfig) {
    InternalRelationType type = (InternalRelationType)relation.getType();
    return acquireLocksConfig && type.getConsistencyModifier()== ConsistencyModifier.LOCK &&
            ( type.multiplicity().isUnique(EdgeDirection.fromPosition(pos))
                    || pos==0 && type.multiplicity()== Multiplicity.SIMPLE);
}
 
Example #22
Source File: MizoTitanRelationType.java    From mizo with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<InternalRelationType> getRelationIndexes() {
    return null;
}
 
Example #23
Source File: MizoTitanRelationType.java    From mizo with Apache License 2.0 4 votes vote down vote up
@Override
public InternalRelationType getBaseType() {
    return null;
}