@Override public String toString() { return "["+key.name()+"]"; }
@Override public default String key() { return propertyKey().name(); }
public GraphCentricQueryBuilder has(PropertyKey key, TitanPredicate predicate, Object condition) { Preconditions.checkNotNull(key); return has(key.name(),predicate,condition); }
public static TitanVertex getVertex(TitanTransaction tx, PropertyKey key, Object value) { return getVertex(tx, key.name(), value); }
private Parameter getFieldMap(PropertyKey key) { return ParameterType.MAPPED_NAME.getParameter(key.name()); }
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; }
public static Set<String> getPropertyKeys(TitanVertex v) { final Set<String> s = new HashSet<>(); v.query().properties().forEach( p -> s.add(p.propertyKey().name())); return s; }
@Override public void setPropertyDirect(PropertyKey key, Object value) { Preconditions.checkArgument(!(key instanceof ImplicitKey), "Cannot use implicit type [%s] when setting property", key.name()); if (properties == EMPTY_PROPERTIES) { if (tx().getConfiguration().isSingleThreaded()) { properties = new HashMap<PropertyKey, Object>(5); } else { synchronized (this) { if (properties == EMPTY_PROPERTIES) { properties = Collections.synchronizedMap(new HashMap<PropertyKey, Object>(5)); } } } } properties.put(key, value); }
@Override public void setPropertyDirect(PropertyKey key, Object value) { Preconditions.checkArgument(!(key instanceof ImplicitKey), "Cannot use implicit type [%s] when setting property", key.name()); if (properties == EMPTY_PROPERTIES) { if (tx().getConfiguration().isSingleThreaded()) { properties = new HashMap<PropertyKey, Object>(5); } else { synchronized (this) { if (properties == EMPTY_PROPERTIES) { properties = Collections.synchronizedMap(new HashMap<PropertyKey, Object>(5)); } } } } properties.put(key, value); }
@Override public <O> O valueOrNull(PropertyKey key) { return (O)property(key.name()).orElse(null); }
@Override public <V> V valueOrNull(PropertyKey key) { return (V)property(key.name()).orElse(null); }
@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; }
@Override public Q orderBy(String keyName, org.apache.tinkerpop.gremlin.process.traversal.Order order) { Preconditions.checkArgument(schemaInspector.containsPropertyKey(keyName), "Provided key does not exist: %s", keyName); PropertyKey key = schemaInspector.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(!(key instanceof SystemRelationType), "Cannot use system types in ordering: %s", key); Preconditions.checkArgument(!orders.containsKey(key)); Preconditions.checkArgument(orders.isEmpty(), "Only a single sort order is supported on vertex queries"); orders.add(key, Order.convert(order)); return getThis(); }
public String getDefaultFieldName(final PropertyKey key, final Parameter[] parameters, final String indexName) { Preconditions.checkArgument(!ParameterType.MAPPED_NAME.hasParameter(parameters),"A field name mapping has been specified for key: %s",key); Preconditions.checkArgument(containsIndex(indexName),"Unknown backing index: %s",indexName); String fieldname = configuration.get(INDEX_NAME_MAPPING,indexName)?key.name():keyID2Name(key); return mixedIndexes.get(indexName).mapKey2Field(fieldname, new StandardKeyInformation(key,parameters)); }
public static Iterable<Object> getValues(TitanElement element, PropertyKey key) { if (element instanceof TitanRelation) { Object value = element.valueOrNull(key); if (value==null) return Collections.EMPTY_LIST; else return ImmutableList.of(value); } else { assert element instanceof TitanVertex; return Iterables.transform((((TitanVertex) element).query()).keys(key.name()).properties(), new Function<TitanVertexProperty, Object>() { @Nullable @Override public Object apply(@Nullable TitanVertexProperty titanProperty) { return titanProperty.value(); } }); } }
public void reindexElement(TitanElement element, MixedIndexType index, Map<String,Map<String,List<IndexEntry>>> documentsPerStore) { if (!indexAppliesTo(index,element)) return; List<IndexEntry> entries = Lists.newArrayList(); for (ParameterIndexField field: index.getFieldKeys()) { PropertyKey key = field.getFieldKey(); if (field.getStatus()==SchemaStatus.DISABLED) continue; if (element.properties(key.name()).hasNext()) { element.values(key.name()).forEachRemaining(value->entries.add(new IndexEntry(key2Field(field), value))); } } Map<String,List<IndexEntry>> documents = documentsPerStore.get(index.getStoreName()); if (documents==null) { documents = Maps.newHashMap(); documentsPerStore.put(index.getStoreName(),documents); } getDocuments(documentsPerStore,index).put(element2String(element),entries); }
public PropertyKeyDefinition(PropertyKey key) { this(key.name(),key.longId(),key.cardinality(),key.dataType()); }
public final Object verifyAttribute(PropertyKey key, Object attribute) { if (attribute==null) throw new SchemaViolationException("Property value cannot be null"); Class<?> datatype = key.dataType(); if (datatype.equals(Object.class)) { if (!attributeHandler.validDataType(attribute.getClass())) { throw Property.Exceptions.dataTypeOfPropertyValueNotSupported(attribute); } 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.name(), datatype, attribute.getClass()); attribute = converted; } assert (attribute.getClass().equals(datatype)); attributeHandler.verifyAttribute(datatype, attribute); return attribute; } }
/** * Insert an extremely simple graph and start * TASK_COUNT simultaneous readers in an executor with * THREAD_COUNT threads. * * @throws Exception */ @Test public void concurrentReadsOnSingleTransaction() throws Exception { initializeGraph(); PropertyKey id = tx.getPropertyKey("uid"); // Tail many concurrent readers on a single transaction CountDownLatch startLatch = new CountDownLatch(TASK_COUNT); CountDownLatch stopLatch = new CountDownLatch(TASK_COUNT); for (int i = 0; i < TASK_COUNT; i++) { int vertexid = RandomGenerator.randomInt(0, VERTEX_COUNT); EdgeLabel elabel = tx.getEdgeLabel("rel" + RandomGenerator.randomInt(0, REL_COUNT)); executor.execute(new SimpleReader(tx, startLatch, stopLatch, vertexid, elabel.name(), EDGE_COUNT * 2, id.name())); startLatch.countDown(); } stopLatch.await(); }
/** * Very simple graph operation to ensure minimal functionality and cleanup */ @Test public void testBasic() { PropertyKey uid = makeVertexIndexedUniqueKey("name", String.class); finishSchema(); TitanVertex n1 = tx.addVertex(); uid = tx.getPropertyKey("name"); n1.property(uid.name(), "abcd"); clopen(); long nid = n1.longId(); uid = tx.getPropertyKey("name"); assertTrue(getV(tx, nid) != null); assertTrue(getV(tx, uid.longId()) != null); assertMissing(tx, nid + 64); uid = tx.getPropertyKey(uid.name()); n1 = getV(tx, nid); assertEquals(n1, getOnlyVertex(tx.query().has(uid.name(), "abcd"))); assertEquals(1, Iterables.size(n1.query().relations())); //TODO: how to expose relations? assertEquals("abcd", n1.value(uid.name())); assertCount(1, tx.query().vertices()); close(); TitanCleanup.clear(graph); open(config); assertEmpty(tx.query().vertices()); }