void add(SqlgVertex sqlgVertex) { RecordId vertexRecordId = (RecordId) sqlgVertex.id(); if (this.vertexCache.containsKey(vertexRecordId)) { throw new IllegalStateException("The vertex cache should never already contain a new vertex!"); } else { SchemaTable schemaTable = vertexRecordId.getSchemaTable(); RecordId recordId; if (vertexRecordId.hasSequenceId()) { recordId = RecordId.from(SchemaTable.of(schemaTable.getSchema(), schemaTable.getTable()), vertexRecordId.sequenceId()); } else { recordId = RecordId.from(SchemaTable.of(schemaTable.getSchema(), schemaTable.getTable()), vertexRecordId.getIdentifiers()); } this.vertexCache.put(recordId, sqlgVertex); } }
@Override public void serialize(final RecordId recordId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException, JsonGenerationException { // when types are not embedded, stringify or resort to JSON primitive representations of the // type so that non-jvm languages can better interoperate with the TinkerPop stack. jsonGenerator.writeString(recordId.toString()); }
public static RecordId from(SchemaTable schemaTable, Long id) { return new RecordId(schemaTable, id); }
@Override public void serialize(final RecordId recordId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { final Map<String, Object> m = new HashMap<>(); m.put("schemaTable", recordId.getSchemaTable()); if (recordId.hasSequenceId()) { m.put("id", recordId.sequenceId()); } else { m.put("id", recordId.getIdentifiers()); } jsonGenerator.writeObject(m); }
@Override public int compareTo(Object o) { if (!(o instanceof RecordId)) { return -1; } RecordId other = (RecordId) o; int first = this.getSchemaTable().compareTo(other.getSchemaTable()); if (first != 0) { return first; } return this.getID().compareTo(other.getID()); }
private SchemaTable getIDContainerSchemaTable(SchemaTableTree schemaTableTree, Object value) { RecordId id; if (value instanceof Long) { return schemaTableTree.getSchemaTable(); } else if (!(value instanceof RecordId)) { id = RecordId.from(String.valueOf(value)); } else { id = (RecordId) value; } return getHasContainerSchemaTable(schemaTableTree, id.getSchemaTable()); }
sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes((this instanceof Vertex ? VERTEX_PREFIX : EDGE_PREFIX) + this.table)); sql.append(" WHERE "); if (this.recordId.hasSequenceId()) { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("ID")); sql.append(" = ?"); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(identifier)); sql.append(" = ?"); if (count++ < this.recordId.getIdentifiers().size()) { sql.append(" AND "); if (this.recordId.hasSequenceId()) { preparedStatement.setLong(1, this.recordId.sequenceId()); } else { int count = 1; for (Comparable identifier : this.recordId.getIdentifiers()) { preparedStatement.setObject(count++, identifier);
public static List<RecordId> from(SqlgGraph sqlgGraph, Object... elementId) { List<RecordId> result = new ArrayList<>(elementId.length); for (Object o : elementId) { if (o instanceof RecordId) { result.add((RecordId) o); } else { result.add(RecordId.from(sqlgGraph, o)); } } return result; }
private static List<ImmutablePair<PropertyType, Object>> transformToTypeAndValue(Multimap<String, Object> keyValues) { List<ImmutablePair<PropertyType, Object>> result = new ArrayList<>(); for (Map.Entry<String, Object> entry : keyValues.entries()) { Object value = entry.getValue(); String key = entry.getKey(); //value //skip the label as that is not a property but the table // skip column references that don't have values if (key.equals(label.getAccessor()) || value instanceof PropertyReference) { continue; } // we transform id in ID if (key.equals(T.id.getAccessor()) || "ID".equals(key)) { if (value instanceof Long) { result.add(ImmutablePair.of(PropertyType.LONG, value)); } else { RecordId id; if (!(value instanceof RecordId)) { id = RecordId.from(value); } else { id = (RecordId) value; } result.add(ImmutablePair.of(PropertyType.LONG, id.sequenceId())); } } else { result.add(ImmutablePair.of(PropertyType.from(value), value)); } } return result; }
@Override public Object[] getRowData() { List<Object> values = new ArrayList<>(); addValues(values); if (this.inVertexLabel.hasIDPrimaryKey()) { values.add(((RecordId) this.currentRow.getMiddle().id()).sequenceId()); } else { for (Object identifier : ((RecordId) this.currentRow.getMiddle().id()).getIdentifiers()) { values.add(identifier); } } if (this.outVertexLabel.hasIDPrimaryKey()) { values.add(((RecordId) this.currentRow.getLeft().id()).sequenceId()); } else { for (Object identifier : ((RecordId) this.currentRow.getLeft().id()).getIdentifiers()) { values.add(identifier); } } return values.toArray(); }
@Override public void write(Kryo kryo, Output output) { output.writeString(this.getSchemaTable().getSchema()); output.writeString(this.getSchemaTable().getTable()); if (hasSequenceId()) { output.writeString("s"); output.writeLong(this.getID().sequenceId); } else { output.writeString("i"); output.writeInt(getIdentifiers().size()); for (Comparable identifier : getIdentifiers()) { output.writeString((CharSequence) identifier); } } }
preparedStatement.setLong(1, this.recordId.sequenceId()); } else { int count = 1; for (Comparable identifierValue : this.recordId.getIdentifiers()) { preparedStatement.setObject(count++, identifierValue); loadResultSet(resultSet); } else { throw new IllegalStateException(String.format("Vertex with label %s and id %s does not exist.", this.schema + "." + this.table, this.recordId.getID().toString()));
@Override public <T extends PersistentObject> T getEntity(Object id) { RecordId recordId; try { if (!(id instanceof RecordId)) { recordId = RecordId.from(id); } else { recordId = (RecordId) id; } GraphTraversal<Vertex, Vertex> traversal = this.V(recordId); if (!traversal.hasNext()) { throw new RuntimeException(String.format("No vertex found for id %s", recordId.toString())); } return instantiateClassifier(traversal.next()); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void serializeWithType(final RecordId recordId, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider, final TypeSerializer typeSerializer) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(GraphSONTokens.CLASS, RecordId.class.getName()); jsonGenerator.writeObjectField("schemaTable", recordId.getSchemaTable()); jsonGenerator.writeNumberField("id", recordId.sequenceId()); jsonGenerator.writeEndObject(); } }
for (Object value : values) { if (hasContainer.getKey().equals(T.id.getAccessor())) { keyValueMap.put(identifier, ((RecordId) value).getIdentifiers().get(i)); } else { keyValueMap.put(hasContainer.getKey(), value); !((RecordId)hasContainer.getValue()).hasSequenceId()) { for (Object identifier : recordId.getIdentifiers()) { keyValueMap.put(schemaTableTree.getIdentifiers().get(i++), identifier);
String id = splittedId[1]; if (id.startsWith("[") && id.endsWith("]")) { return recordIdFromIdentifiers(sqlgGraph, label, id); } else { try { Long labelId = Long.valueOf(id); return new RecordId(label, labelId); } catch (NumberFormatException e) { throw SqlgExceptions.invalidId(vertexId.toString()); String id = splittedId[1]; if (id.startsWith("[") && id.endsWith("]")) { return recordIdFromIdentifiers(sqlgGraph, label, id); } else { throw SqlgExceptions.invalidId(vertexId.toString());
preparedStatement.setLong(idx, ((RecordId) this.id()).sequenceId()); } else { for (String identifier : abstractLabel.getIdentifiers()) {
private void barrierTheHeads() { //these collections are only used for the current starts. this.heads.clear(); this.schemaTableParentIds.clear(); while (this.starts.hasNext()) { @SuppressWarnings("unchecked") Traverser.Admin<E> h = this.starts.next(); E value = h.get(); SchemaTable schemaTable = value.getSchemaTablePrefixed(); List<Traverser.Admin<E>> traverserList = this.heads.get(schemaTable); //noinspection Java8MapApi if (traverserList == null) { traverserList = new ArrayList<>(); this.heads.put(schemaTable, traverserList); } traverserList.add(h); List<Pair<RecordId.ID, Long>> parentIdList = this.schemaTableParentIds.get(schemaTable); //noinspection Java8MapApi if (parentIdList == null) { parentIdList = new ArrayList<>(); this.schemaTableParentIds.put(schemaTable, parentIdList); } parentIdList.add(Pair.of(((RecordId) value.id()).getID(), this.startIndex)); this.startIndexTraverserAdminMap.put(this.startIndex++, h); } }
sql.append(" WHERE "); AbstractLabel abstractLabel; if (this.recordId.hasSequenceId()) { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.schema + "." + this.table + (direction == Direction.OUT ? Topology.OUT_VERTEX_COLUMN_END : Topology.IN_VERTEX_COLUMN_END))); sql.append(" = ?"); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.schema + "." + this.table + "." + identifier + (direction == Direction.OUT ? Topology.OUT_VERTEX_COLUMN_END : Topology.IN_VERTEX_COLUMN_END))); sql.append(" = ?"); if (count++ < this.recordId.getIdentifiers().size()) { sql.append(" AND "); if (this.recordId.hasSequenceId()) { preparedStatement.setLong(1, this.recordId.sequenceId()); } else { int count = 1; for (Comparable identifierValue : this.recordId.getIdentifiers()) { preparedStatement.setObject(count++, identifierValue);
public static List<RecordId> from(Object... elementId) { List<RecordId> result = new ArrayList<>(elementId.length); for (Object o : elementId) { if (o instanceof RecordId) { result.add((RecordId) o); } else { result.add(RecordId.from(o)); } } return result; }