@Override public GraphCentricQueryBuilder orderBy(String keyName, org.apache.tinkerpop.gremlin.process.traversal.Order order) { Preconditions.checkArgument(tx.containsPropertyKey(keyName),"Provided key does not exist: %s",keyName); PropertyKey key = tx.getPropertyKey(keyName); Preconditions.checkArgument(key!=null && order!=null,"Need to specify and key and an order"); Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.dataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.name(), key.dataType()); Preconditions.checkArgument(key.cardinality()== Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.name()); Preconditions.checkArgument(!orders.containsKey(key)); orders.add(key, Order.convert(order)); return this; }
Preconditions.checkArgument(!field.getFieldKey().equals(key), "Key [%s] has already been added to index %s", key.name(), index.name()); if (addMappingParameter) extendedParas[arrPosition++] = ParameterType.MAPPED_NAME.getParameter( graph.getIndexSerializer().getDefaultFieldName(key, parameters, indexType.getBackingIndexName())); extendedParas[arrPosition++] = ParameterType.STATUS.getParameter(key.isNew() ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED); throw new TitanException("Could not register new index field '" + key.name() + "' with index backend as the data type, cardinality or parameter combination is not supported."); if (!key.isNew()) updateIndex(index, SchemaAction.REGISTER_INDEX);
public PropertyKeyDefinition(PropertyKey key) { this(key.name(),key.longId(),key.cardinality(),key.dataType()); }
public StandardKeyInformation(PropertyKey key, Parameter... parameters) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(parameters); this.dataType = key.dataType(); this.parameters = parameters; this.cardinality = key.cardinality(); }
private static long[] checkSignature(List<PropertyKey> sig) { Preconditions.checkArgument(sig.size() == (Sets.newHashSet(sig)).size(), "Signature and sort key cannot contain duplicate types"); long[] signature = new long[sig.size()]; for (int i = 0; i < sig.size(); i++) { PropertyKey key = sig.get(i); Preconditions.checkNotNull(key); Preconditions.checkArgument(!((PropertyKey) key).dataType().equals(Object.class), "Signature and sort keys must have a proper declared datatype: %s", key.name()); signature[i] = key.longId(); } return signature; }
@Override public GraphCentricQueryBuilder orderBy(PropertyKey key, Order order) { Preconditions.checkArgument(key!=null && order!=null,"Need to specify and key and an order"); Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.getDataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.getName(), key.getDataType()); Preconditions.checkArgument(key.getCardinality()== Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.getName()); Preconditions.checkArgument(!orders.containsKey(key)); orders.add(key, order); return this; }
assertNotNull(mgmt.getPropertyKey("weight")); assertNotNull(mgmt.getEdgeLabel("connect")); assertTrue(weight.isPropertyKey()); assertFalse(weight.isEdgeLabel()); assertEquals(Cardinality.SINGLE,weight.getCardinality()); assertEquals(Cardinality.SINGLE,someid.getCardinality()); assertEquals(Cardinality.SET,name.getCardinality()); assertEquals(Cardinality.LIST,value.getCardinality()); assertEquals(Object.class,someid.getDataType()); assertEquals(Decimal.class,weight.getDataType()); sig = ((InternalRelationType)value).getSignature(); assertEquals(1,sig.length); assertEquals(weight.getLongId(),sig[0]); assertTrue(mgmt.getGraphIndex(id.getName()).isUnique()); assertFalse(mgmt.getGraphIndex(someid.getName()).isUnique()); sig = ((InternalRelationType)connect).getSignature(); assertEquals(2,sig.length); assertEquals(id.getLongId(),sig[0]); assertEquals(link.getLongId(),sig[1]); assertEquals(0,((InternalRelationType) friend).getSortKey().length); assertNotNull(mgmt.getPropertyKey("weight")); assertNotNull(mgmt.getEdgeLabel("connect")); assertTrue(weight.isPropertyKey()); assertFalse(weight.isEdgeLabel()); assertEquals(Cardinality.SINGLE,weight.getCardinality()); assertEquals(Cardinality.SINGLE,someid.getCardinality()); assertEquals(Cardinality.SET,name.getCardinality());
assertNotNull(mgmt.getPropertyKey("weight")); assertNotNull(mgmt.getEdgeLabel("connect")); assertTrue(weight.isPropertyKey()); assertFalse(weight.isEdgeLabel()); assertEquals(Cardinality.SINGLE, weight.cardinality()); assertEquals(Cardinality.SINGLE, someid.cardinality()); assertEquals(Cardinality.SET, name.cardinality()); assertEquals(Cardinality.LIST, value.cardinality()); assertEquals(Object.class, someid.dataType()); assertEquals(Float.class, weight.dataType()); sig = ((InternalRelationType) value).getSignature(); assertEquals(1, sig.length); assertEquals(weight.longId(), sig[0]); assertTrue(mgmt.getGraphIndex(uid.name()).isUnique()); assertFalse(mgmt.getGraphIndex(someid.name()).isUnique()); sig = ((InternalRelationType) connect).getSignature(); assertEquals(1, sig.length); assertEquals(uid.longId(), sig[0]); assertEquals(0, ((InternalRelationType) friend).getSortKey().length); assertEquals(Order.DEFAULT, ((InternalRelationType) friend).getSortOrder()); assertNotNull(mgmt.getPropertyKey("weight")); assertNotNull(mgmt.getEdgeLabel("connect")); assertTrue(weight.isPropertyKey()); assertFalse(weight.isEdgeLabel()); assertEquals(Cardinality.SINGLE, weight.cardinality()); assertEquals(Cardinality.SINGLE, someid.cardinality()); assertEquals(Cardinality.SET, name.cardinality());
public static boolean hasGenericDataType(PropertyKey key) { return key.getDataType().equals(Object.class); } }
@Override public String toString() { return "["+key.getName()+"]"; }
public PropertyKeyDefinition(PropertyKey key) { this(key.getName(),key.getLongId(),key.getCardinality(),key.getDataType()); }
public Titan0Graph() { //determine multi-properties once at startup TitanManagement mgmt = null; try { mgmt = Titan0GraphDatabase.getGraphInstance().getManagementSystem(); Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class); multiProperties = Collections.synchronizedSet(new HashSet<String>()); for(PropertyKey key : keys) { if (key.getCardinality() != Cardinality.SINGLE) { multiProperties.add(key.getName()); } } } finally { if (mgmt != null) { mgmt.rollback(); } } }
private VertexProperty.Cardinality getPropertyKeyCardinality(String name) { RelationType rt = typeManager.getRelationType(name); if (null == rt || !rt.isPropertyKey()) return VertexProperty.Cardinality.single; PropertyKey pk = typeManager.getExistingPropertyKey(rt.longId()); switch (pk.cardinality()) { case SINGLE: return VertexProperty.Cardinality.single; case LIST: return VertexProperty.Cardinality.list; case SET: return VertexProperty.Cardinality.set; default: throw new IllegalStateException("Unknown cardinality " + pk.cardinality()); } }
assert skey!=ImplicitKey.ADJACENT_ID || (i==sortKeyIDs.length); assert skey!=ImplicitKey.TITANID || (!type.multiplicity().isConstrained() && (i==sortKeyIDs.length && skey.isPropertyKey() || i==sortKeyIDs.length+1 && skey.isEdgeLabel() )); assert colStart.getPosition()==colEnd.getPosition(); assert interval==null || interval.isPoints(); assert skey.longId() == sortKeyIDs[i];
public final Object verifyAttribute(PropertyKey key, Object attribute) { if (attribute==null) throw new SchemaViolationException("Property value cannot be null"); Class<?> datatype = key.getDataType(); if (datatype.equals(Object.class)) { return attribute; } else { if (!attribute.getClass().equals(datatype)) { Object converted = null; try { converted = attributeHandler.convert(datatype, attribute); } catch (IllegalArgumentException e) { //Just means that data could not be converted } if (converted == null) throw new SchemaViolationException( "Value [%s] is not an instance of the expected data type for property key [%s] and cannot be converted. Expected: %s, found: %s", attribute, key.getName(), datatype, attribute.getClass()); attribute = converted; } Preconditions.checkState(attribute.getClass().equals(datatype)); attributeHandler.verifyAttribute(datatype, attribute); return attribute; } }
@Override public String toString() { return "["+key.name()+"]"; }
Preconditions.checkArgument(indexType instanceof IndexTypeWrapper && key instanceof TitanSchemaVertex && ((IndexTypeWrapper)indexType).getSchemaBase() instanceof TitanSchemaVertex); Preconditions.checkArgument(key.getCardinality()==Cardinality.SINGLE || indexType.getElement()!=ElementCategory.VERTEX, "Can only index single-valued property keys on vertices [%s]",key); TitanSchemaVertex indexVertex = (TitanSchemaVertex)((IndexTypeWrapper)indexType).getSchemaBase(); Preconditions.checkArgument(!field.getFieldKey().equals(key),"Key [%s] has already been added to index %s",key.getName(),index.getName()); if (addMappingParameter) extendedParas[arrPosition++] = ParameterType.MAPPED_NAME.getParameter( graph.getIndexSerializer().getDefaultFieldName(key,parameters,indexType.getBackingIndexName())); extendedParas[arrPosition++] = ParameterType.STATUS.getParameter(key.isNew()?SchemaStatus.ENABLED:SchemaStatus.INSTALLED); if (!key.isNew()) updateIndex(index, SchemaAction.REGISTER_INDEX);
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);
@Override public AtlasCardinality getCardinality() { return GraphDbObjectFactory.createCardinality(wrappedPropertyKey.getCardinality()); }
public TitanVertexProperty addProperty(VertexProperty.Cardinality cardi, TitanVertex vertex, PropertyKey key, Object value) { if (key.cardinality().convert()!=cardi && cardi!=VertexProperty.Cardinality.single) throw new SchemaViolationException(String.format("Key is defined for %s cardinality which conflicts with specified: %s",key.cardinality(),cardi)); verifyWriteAccess(vertex); Preconditions.checkArgument(!(key instanceof ImplicitKey),"Cannot create a property of implicit type: %s",key.name()); vertex = ((InternalVertex) vertex).it(); Preconditions.checkNotNull(key); final Object normalizedValue = verifyAttribute(key, value); Cardinality cardinality = key.cardinality(); throw new SchemaViolationException("Adding this property for key [%s] and value [%s] violates a uniqueness constraint [%s]", key.name(), normalizedValue, lockTuple.getIndex());