Package com.thinkaurelius.titan.graphdb.internal

Examples of com.thinkaurelius.titan.graphdb.internal.InternalType


                    TitanType type = relation.getType();

                    //Give special treatment to edge type definitions
                    if (SystemTypeManager.prepersistedSystemTypes.contains(type)) {
                        InternalType itype = (InternalType) relation.getVertex(0);
                        otherEdgeTypes.put(itype, relation);
                    } else { //STANDARD TitanRelation
                        for (int pos = 0; pos < relation.getLen(); pos++) {
                            InternalVertex vertex = relation.getVertex(pos);
                            if (pos == 0 || !relation.isLoop()) mutations.put(vertex, relation);
                            Direction dir = EdgeDirection.fromPosition(pos);
                            if (acquireLocks && relation.getType().isUnique(dir) && !vertex.isNew()
                                    && ((InternalType) relation.getType()).uniqueLock(dir)) {
                                Entry entry = edgeSerializer.writeRelation(relation, pos, tx);
                                mutator.acquireEdgeLock(IDHandler.getKey(vertex.getID()), entry.getColumn(), null);
                            }
                        }
                    }
                    //Update Indexes
                    if (relation.isProperty()) {
                        if (acquireLocks) indexSerializer.lockKeyedProperty((TitanProperty) relation, mutator);
                    }

                }

                //3. Persist
                List<StaticBuffer> mutatedVertexKeys = new ArrayList<StaticBuffer>();
                if (!otherEdgeTypes.isEmpty()) {
                    mutatedVertexKeys.addAll(persist(otherEdgeTypes, tx));
                    mutator.flush();
                    //Register new keys with indexprovider
                    for (InternalType itype : otherEdgeTypes.keySet()) {
                        if (itype.isPropertyKey() && itype.isNew())
                            indexSerializer.newPropertyKey((TitanKey) itype, mutator);
                    }
                }

                if (!mutations.isEmpty()) mutatedVertexKeys.addAll(persist(mutations, tx));
View Full Code Here


                throw new IllegalArgumentException("Invalid dirID read from disk: " + dirID);
        }

        TitanType titanType = tx.getExistingType(typeId);

        InternalType def = (InternalType) titanType;
        long[] keysig = def.getSortKey();
        if (!parseHeaderOnly && !titanType.isUnique(dir)) {
            ReadBuffer sortKeyReader = def.getSortOrder()==Order.DESC?column.invert():column;
            readInlineTypes(keysig, properties, sortKeyReader, tx);
        }

        long relationIdDiff, vertexIdDiff = 0;
        if (titanType.isUnique(dir)) {
            if (rtype == RelationType.EDGE)
                vertexIdDiff = VariableLong.read(value);
            relationIdDiff = VariableLong.read(value);
        } else {
            //Move position to end to read backwards
            column.movePosition(column.length() - column.getPosition() - 1);

            relationIdDiff = VariableLong.readBackward(column);
            if (rtype == RelationType.EDGE)
                vertexIdDiff = VariableLong.readBackward(column);
        }

        assert relationIdDiff + vertexid > 0;
        long relationId = relationIdDiff + vertexid;

        Object other;
        switch (rtype) {
            case EDGE:
                Preconditions.checkArgument(titanType.isEdgeLabel());
                other = vertexid + vertexIdDiff;
                break;

            case PROPERTY:
                Preconditions.checkArgument(titanType.isPropertyKey());
                TitanKey key = ((TitanKey) titanType);
                other = hasGenericDataType(key)
                        ? serializer.readClassAndObject(value)
                        : serializer.readObjectNotNull(value, key.getDataType());
                break;

            default:
                throw new AssertionError();
        }
        assert other != null;

        if (!parseHeaderOnly) {
            //value signature & sort key if unique
            if (titanType.isUnique(dir)) {
                readInlineTypes(keysig, properties, value, tx);
            }

            readInlineTypes(def.getSignature(), properties, value, tx);

            //Third: read rest
            while (value.hasRemaining()) {
                TitanType type = tx.getExistingType(IDHandler.readInlineEdgeType(value));
                Object pvalue = readInline(value, type);
View Full Code Here

        int dirID = getDirID(dir, relation.isProperty() ? RelationType.PROPERTY : RelationType.EDGE);

        DataOutput colOut = serializer.getDataOutput(DEFAULT_COLUMN_CAPACITY, true);
        IDHandler.writeEdgeType(colOut, typeid, dirID);

        InternalType definition = (InternalType) type;
        long[] sortKey = definition.getSortKey();
        int startPosition = colOut.getPosition();
        if (!type.isUnique(dir)) {
            writeInlineTypes(sortKey, relation, colOut, tx);
        }
        int endPosition = colOut.getPosition();

        DataOutput writer = colOut;
        long vertexIdDiff = 0;
        long relationIdDiff = relation.getID() - relation.getVertex(position).getID();
        if (relation.isEdge())
            vertexIdDiff = relation.getVertex((position + 1) % 2).getID() - relation.getVertex(position).getID();

        if (type.isUnique(dir)) {
            writer = serializer.getDataOutput(DEFAULT_VALUE_CAPACITY, true);
            if (relation.isEdge()) VariableLong.write(writer, vertexIdDiff);
            VariableLong.write(writer, relationIdDiff);
        } else {
            if (relation.isEdge()) VariableLong.writeBackward(writer, vertexIdDiff);
            VariableLong.writeBackward(writer, relationIdDiff);
        }

        if (!type.isUnique(dir)) {
            writer = serializer.getDataOutput(DEFAULT_VALUE_CAPACITY, true);
        }

        if (relation.isProperty()) {
            Preconditions.checkArgument(relation.isProperty());
            Object value = ((TitanProperty) relation).getValue();
            Preconditions.checkNotNull(value);
            TitanKey key = (TitanKey) type;
            assert key.getDataType().isInstance(value);
            if (hasGenericDataType(key)) {
                writer.writeClassAndObject(value);
            } else {
                writer.writeObjectNotNull(value);
            }
        }

        //Write signature & sort key if unique
        if (type.isUnique(dir)) {
            writeInlineTypes(sortKey, relation, writer, tx);
        }
        long[] signature = definition.getSignature();
        writeInlineTypes(signature, relation, writer, tx);


        //Write remaining properties
        LongSet writtenTypes = new LongOpenHashSet(sortKey.length + signature.length);
View Full Code Here

        } else {
            Set<TitanType> ts = new HashSet<TitanType>(types.length);
            queries = new ArrayList<BackendQueryHolder<SliceQuery>>(types.length + 4);

            for (String typeName : types) {
                InternalType type = getType(typeName);
                if (type != null && (includeHidden || !type.isHidden())) {
                    ts.add(type);
                    if (type.isPropertyKey()) {
                        if (returnType == RelationType.EDGE)
                            throw new IllegalArgumentException("Querying for edges but including a property key: " + type.getName());
                        returnType = RelationType.PROPERTY;
                    }
                    if (type.isEdgeLabel()) {
                        if (returnType == RelationType.PROPERTY)
                            throw new IllegalArgumentException("Querying for properties but including an edge label: " + type.getName());
                        returnType = RelationType.EDGE;
                    }
                    //Construct sort key constraints (if any, and if not direction==Both)
                    EdgeSerializer.TypedInterval[] sortKeyConstraints = new EdgeSerializer.TypedInterval[type.getSortKey().length];
                    And<TitanRelation> remainingConditions = conditions;
                    boolean vertexConstraintApplies = type.getSortKey().length == 0 || conditions.hasChildren();
                    if (type.getSortKey().length > 0 && conditions.hasChildren()) {
                        remainingConditions = conditions.clone();
                        sortKeyConstraints = compileSortKeyConstraints(type,tx,remainingConditions);
                        if (sortKeyConstraints==null) continue; //Constraints cannot be matched

                        Interval interval;
                        if (sortKeyConstraints[sortKeyConstraints.length-1] == null ||
                                (interval=sortKeyConstraints[sortKeyConstraints.length-1].interval) == null || !interval.isPoint()) {
                            vertexConstraintApplies = false;

                        }
                    }
                    Direction[] dirs = {dir};
                    EdgeSerializer.VertexConstraint vertexConstraint = getVertexConstraint();
                    if (dir == Direction.BOTH &&
                            (hasSortKeyConstraints(sortKeyConstraints) || (vertexConstraintApplies && vertexConstraint != null))) {
                        //Split on direction in the presence of effective sort key constraints
                        dirs = new Direction[]{Direction.OUT, Direction.IN};
                    }
                    for (Direction dir : dirs) {
                        EdgeSerializer.VertexConstraint vertexCon = vertexConstraint;
                        if (vertexCon == null || !vertexConstraintApplies || type.isUnique(dir)) vertexCon = null;
                        EdgeSerializer.TypedInterval[] sortConstraints = sortKeyConstraints;
                        if (hasSortKeyConstraints(sortKeyConstraints) && type.isUnique(dir)) {
                            sortConstraints = new EdgeSerializer.TypedInterval[type.getSortKey().length];
                        }

                        boolean isFitted = !remainingConditions.hasChildren()
                                && vertexConstraint == vertexCon && sortConstraints == sortKeyConstraints;
                        SliceQuery q = serializer.getQuery(type, dir, sortConstraints, vertexCon);
View Full Code Here

    private static EdgeSerializer.TypedInterval[] compileSortKeyConstraints(InternalType type, StandardTitanTx tx, And<TitanRelation> conditions) {
        long[] sortKeys = type.getSortKey();
        EdgeSerializer.TypedInterval[] sortKeyConstraints = new EdgeSerializer.TypedInterval[type.getSortKey().length];

        for (int i = 0; i < sortKeys.length; i++) {
            InternalType pktype = (InternalType) tx.getExistingType(sortKeys[i]);
            Interval interval = null;
            //First check for equality constraints, since those are the most constraining
            for (Iterator<Condition<TitanRelation>> iter = conditions.iterator(); iter.hasNext(); ) {
                Condition<TitanRelation> cond = iter.next();
                if (cond instanceof PredicateCondition) {
                    PredicateCondition<TitanType, TitanRelation> atom = (PredicateCondition) cond;
                    if (atom.getKey().equals(pktype) && atom.getPredicate() == Cmp.EQUAL && interval == null) {
                        interval = new PointInterval(atom.getValue());
                        iter.remove();
                    }
                }
            }

            //If there are no equality constraints, check if the sort key's datatype allows comparison
            //and if so, find a bounding interval from the remaining constraints
            if (interval == null && pktype.isPropertyKey()
                    && Comparable.class.isAssignableFrom(((TitanKey) pktype).getDataType())) {
                ProperInterval pint = new ProperInterval();
                for (Iterator<Condition<TitanRelation>> iter = conditions.iterator(); iter.hasNext(); ) {
                    Condition<TitanRelation> cond = iter.next();
                    if (cond instanceof PredicateCondition) {
View Full Code Here

        //0) RelationType
        int reltypecompare = (r1.isProperty()?1:2) - (r2.isProperty()?1:2);
        if (reltypecompare != 0) return reltypecompare;

        //1) TitanType
        InternalType t1 = (InternalType) r1.getType(), t2 = (InternalType) r2.getType();
        int typecompare = t1.compareTo(t2);
        if (typecompare != 0) return typecompare;
        assert t1.equals(t2);

        //2) Direction
        Direction dir1 = null, dir2 = null;
        for (int i = 0; i < r1.getLen(); i++)
            if (r1.getVertex(i).equals(vertex)) {
                dir1 = EdgeDirection.fromPosition(i);
                break;
            }
        for (int i = 0; i < r2.getLen(); i++)
            if (r2.getVertex(i).equals(vertex)) {
                dir2 = EdgeDirection.fromPosition(i);
                break;
            }
        assert dir1 != null && dir2 != null; // ("Either relation is not incident on vertex [%s]", vertex);
        int dirCompare = EdgeDirection.position(dir1) - EdgeDirection.position(dir2);
        if (dirCompare != 0) return dirCompare;

        // Breakout: If type&direction are the same and the type is unique in the direction it follows that the relations are the same
        if (t1.isUnique(dir1)) return 0;

        // 3) Compare sort key values
        for (long typeid : t1.getSortKey()) {
            int keycompare = compareOnKey(r1, r2, typeid, t1.getSortOrder());
            if (keycompare != 0) return keycompare;
        }
        // 4) Compare property objects or other vertices
        if (r1.isProperty()) {
            Object o1 = ((TitanProperty) r1).getValue();
View Full Code Here

TOP

Related Classes of com.thinkaurelius.titan.graphdb.internal.InternalType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.