public SchemaTable withPrefix(String prefix) { Preconditions.checkArgument(prefix.equals(VERTEX_PREFIX) || prefix.equals(EDGE_PREFIX), "Prefix must be either " + VERTEX_PREFIX + " or " + EDGE_PREFIX + " for " + prefix); Preconditions.checkState(!this.table.startsWith(VERTEX_PREFIX) && !this.table.startsWith(EDGE_PREFIX), "SchemaTable is already prefixed."); return SchemaTable.of(this.getSchema(), prefix + this.getTable()); }
public SchemaTable withOutPrefix() { Preconditions.checkState(this.table.startsWith(VERTEX_PREFIX) || this.table.startsWith(EDGE_PREFIX)); if (this.table.startsWith(VERTEX_PREFIX)) return SchemaTable.of(this.getSchema(), this.getTable().substring(VERTEX_PREFIX.length())); else return SchemaTable.of(this.getSchema(), this.getTable().substring(EDGE_PREFIX.length())); }
@Override public void serialize(final SchemaTable schemaTable, 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. final Map<String, Object> m = new LinkedHashMap<>(); m.put("schema", schemaTable.getSchema()); m.put("table", schemaTable.getTable()); jsonGenerator.writeObject(m); }
void addToAllTables(String tableName, Map<String, PropertyType> propertyTypeMap) { Preconditions.checkState(isSqlWriteLockHeldByCurrentThread() || isTopologyMapWriteLockHeldByCurrentThread()); this.allTableCache.put(tableName, propertyTypeMap); SchemaTable schemaTable = SchemaTable.from(this.sqlgGraph, tableName); if (schemaTable.getTable().startsWith(VERTEX_PREFIX) && !this.schemaTableForeignKeyCache.containsKey(schemaTable)) { //This happens for VertexLabel that have no edges, //else the addOutForeignKeysToVertexLabel or addInForeignKeysToVertexLabel would have already added it to the cache. this.schemaTableForeignKeyCache.put(schemaTable, Pair.of(new HashSet<>(), new HashSet<>())); } }
public void loadInVertex(ResultSet resultSet, SchemaTable inVertexSchemaTable, int columnIdx) throws SQLException { Long inId = resultSet.getLong(columnIdx); if (!resultSet.wasNull()) { this.inVertex = SqlgVertex.of(this.sqlgGraph, inId, inVertexSchemaTable.getSchema(), inVertexSchemaTable.getTable()); } }
public void loadOutVertex(ResultSet resultSet, SchemaTable outVertexSchemaTable, int columnIdx) throws SQLException { Long outId = resultSet.getLong(columnIdx); if (!resultSet.wasNull()) { this.outVertex = SqlgVertex.of(this.sqlgGraph, outId, outVertexSchemaTable.getSchema(), outVertexSchemaTable.getTable()); } }
/** * add a new column * * @param st * @param column * @param stepDepth * @param alias */ public void add(SchemaTable st, String column, int stepDepth, String alias) { add(st.getSchema(), st.getTable(), column, stepDepth, alias); }
/** * get an alias if the column is already in the list * * @param st * @param column * @param stepDepth * @return */ public String getAlias(SchemaTable st, String column, int stepDepth) { return getAlias(st.getSchema(), st.getTable(), column, stepDepth); }
private String calculatedAliasVertexForeignKeyColumnEnd(SchemaTableTree previousSchemaTableTree, Direction direction, String identifier) { String previousRawLabel = previousSchemaTableTree.getSchemaTable().getTable().substring(VERTEX_PREFIX.length()); String result = this.stepDepth + ALIAS_SEPARATOR + getSchemaTable().getSchema() + ALIAS_SEPARATOR + getSchemaTable().getTable() + ALIAS_SEPARATOR + previousSchemaTableTree.getSchemaTable().getSchema() + //This must be a dot as its the foreign key column, i.e. blah__I "." + previousRawLabel + "." + identifier + (direction == Direction.IN ? Topology.IN_VERTEX_COLUMN_END : Topology.OUT_VERTEX_COLUMN_END); String alias = rootAliasAndIncrement(); this.getColumnNameAliasMap().put(result, alias); this.getAliasColumnNameMap().put(alias, result); return alias; }
default List<Triple<SqlgSqlExecutor.DROP_QUERY, String, SchemaTable>> sqlTruncate(SqlgGraph sqlgGraph, SchemaTable schemaTable) { Preconditions.checkState(schemaTable.isWithPrefix(), "SqlDialect.sqlTruncate' schemaTable must start with a prefix %s or %s", Topology.VERTEX_PREFIX, Topology.EDGE_PREFIX); return Collections.singletonList( Triple.of( SqlgSqlExecutor.DROP_QUERY.TRUNCATE, "TRUNCATE TABLE " + maybeWrapInQoutes(schemaTable.getSchema()) + "." + maybeWrapInQoutes(schemaTable.getTable()), schemaTable ) ); }
public void addForeignKey(SchemaTableTree stt, String column, String alias) { String[] foreignKeyParts = column.split("\\."); Preconditions.checkState(foreignKeyParts.length == 2 || foreignKeyParts.length == 3, "Edge table foreign must be schema.table__I\\O or schema.table.property__I\\O. Found %s", column); addForeignKey(stt.getSchemaTable().getSchema(), stt.getSchemaTable().getTable(), column, stt.getStepDepth(), alias, foreignKeyParts); }
public void addForeignKey(SchemaTableTree stt, String column, String alias) { String[] foreignKeyParts = column.split("\\."); Preconditions.checkState(foreignKeyParts.length == 2 || foreignKeyParts.length == 3, "Edge table foreign must be schema.table__I\\O or schema.table.property__I\\O. Found %s", column); addForeignKey(stt.getSchemaTable().getSchema(), stt.getSchemaTable().getTable(), column, stt.getStepDepth(), alias, foreignKeyParts); }
private String calculateAliasPropertyName(String propertyName) { String result = this.stepDepth + ALIAS_SEPARATOR + getSchemaTable().getSchema() + ALIAS_SEPARATOR + getSchemaTable().getTable() + ALIAS_SEPARATOR + propertyName; String alias = rootAliasAndIncrement(); this.getColumnNameAliasMap().put(result, alias); this.getAliasColumnNameMap().put(alias, result); return alias; }
private void calculateLabeledAliasId(String alias) { String reducedLabels = reducedLabels(); String result = this.stepDepth + ALIAS_SEPARATOR + reducedLabels + ALIAS_SEPARATOR + getSchemaTable().getSchema() + ALIAS_SEPARATOR + getSchemaTable().getTable() + ALIAS_SEPARATOR + Topology.ID; this.getColumnNameAliasMap().put(result, alias); this.getAliasColumnNameMap().put(alias, result); }
private String calculateAliasPropertyName(String propertyName) { String result = this.stepDepth + ALIAS_SEPARATOR + getSchemaTable().getSchema() + ALIAS_SEPARATOR + getSchemaTable().getTable() + ALIAS_SEPARATOR + propertyName; String alias = rootAliasAndIncrement(); this.getColumnNameAliasMap().put(result, alias); this.getAliasColumnNameMap().put(alias, result); return alias; }
private String calculateLabeledAliasId() { String reducedLabels = reducedLabels(); String result = this.stepDepth + ALIAS_SEPARATOR + reducedLabels + ALIAS_SEPARATOR + getSchemaTable().getSchema() + ALIAS_SEPARATOR + getSchemaTable().getTable() + ALIAS_SEPARATOR + Topology.ID; String alias = rootAliasAndIncrement(); this.getColumnNameAliasMap().put(result, alias); this.getAliasColumnNameMap().put(alias, result); return alias; }
private String calculateLabeledAliasPropertyName(String propertyName) { String reducedLabels = reducedLabels(); String result = this.stepDepth + ALIAS_SEPARATOR + reducedLabels + ALIAS_SEPARATOR + getSchemaTable().getSchema() + ALIAS_SEPARATOR + getSchemaTable().getTable() + ALIAS_SEPARATOR + propertyName; String alias = rootAliasAndIncrement(); this.getColumnNameAliasMap().put(result, alias); this.getAliasColumnNameMap().put(alias, result); return alias; }
public void loadInVertex(ResultSet resultSet, List<ColumnList.Column> inForeignKeyColumns) { List<Comparable> identifiers = SqlgUtil.getValue(resultSet, inForeignKeyColumns); ColumnList.Column column = inForeignKeyColumns.get(0); this.inVertex = SqlgVertex.of( this.sqlgGraph, ListOrderedSet.listOrderedSet(identifiers), column.getForeignSchemaTable().getSchema(), column.getForeignSchemaTable().getTable() ); }
private String mappedAliasVertexForeignKeyColumnEnd(SchemaTableTree previousSchemaTableTree, Direction direction, String rawFromLabel) { String result = this.stepDepth + ALIAS_SEPARATOR + getSchemaTable().getSchema() + ALIAS_SEPARATOR + getSchemaTable().getTable() + ALIAS_SEPARATOR + previousSchemaTableTree.getSchemaTable().getSchema() + //This must be a dot as its the foreign key column, i.e. blah__I "." + rawFromLabel + (direction == Direction.IN ? Topology.IN_VERTEX_COLUMN_END : Topology.OUT_VERTEX_COLUMN_END); return this.getColumnNameAliasMap().get(result); }
@Override public Edge addEdge(String label, Vertex inVertex, Object... keyValues) { this.sqlgGraph.tx().readWrite(); boolean streaming = this.sqlgGraph.getSqlDialect().supportsBatchMode() && (this.sqlgGraph.tx().isInStreamingBatchMode() || this.sqlgGraph.tx().isInStreamingWithLockBatchMode()); if (streaming) { SchemaTable streamingBatchModeEdgeLabel = this.sqlgGraph.tx().getBatchManager().getStreamingBatchModeEdgeSchemaTable(); if (streamingBatchModeEdgeLabel != null && !streamingBatchModeEdgeLabel.getTable().substring(EDGE_PREFIX.length()).equals(label)) { throw new IllegalStateException("Streaming batch mode must occur for one label at a time. Expected \"" + streamingBatchModeEdgeLabel + "\" found \"" + label + "\". First commit the transaction or call SqlgGraph.flush() before streaming a different label"); } } return addEdgeInternal(streaming, label, inVertex, keyValues); }