private Schema removeSchemaFromCaches(String schema) { Preconditions.checkState(isSqlWriteLockHeldByCurrentThread() || isTopologyMapWriteLockHeldByCurrentThread()); Schema s = this.schemas.remove(schema); this.allTableCache.keySet().removeIf(schemaTable -> schemaTable.startsWith(schema + ".")); this.edgeForeignKeyCache.keySet().removeIf(schemaTable -> schemaTable.startsWith(schema + ".")); this.schemaTableForeignKeyCache.keySet().removeIf(schemaTable -> schemaTable.getSchema().equals(schema)); return s; }
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); }
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()); } }
/** * 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 mappedAliasVertexForeignKeyColumnEnd(SchemaTableTree previousSchemaTableTree, Direction direction, String rawFromLabel, String identifier) { 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 + "." + identifier + (direction == Direction.IN ? Topology.IN_VERTEX_COLUMN_END : Topology.OUT_VERTEX_COLUMN_END); return this.getColumnNameAliasMap().get(result); }
private String mappedAliasVertexForeignKeyColumnEnd(SchemaTableTree previousSchemaTableTree, Direction direction, String rawFromLabel, String identifier) { 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 + "." + identifier + (direction == Direction.IN ? Topology.IN_VERTEX_COLUMN_END : Topology.OUT_VERTEX_COLUMN_END); return this.getColumnNameAliasMap().get(result); }
private SchemaTable getHasContainerSchemaTable(SchemaTableTree schemaTableTree, SchemaTable predicateSchemaTable) { SchemaTable hasContainerLabelSchemaTable; //Check if we are on a vertex or edge if (schemaTableTree.getSchemaTable().getTable().startsWith(VERTEX_PREFIX)) { hasContainerLabelSchemaTable = SchemaTable.of(predicateSchemaTable.getSchema(), VERTEX_PREFIX + predicateSchemaTable.getTable()); } else { hasContainerLabelSchemaTable = SchemaTable.of(predicateSchemaTable.getSchema(), EDGE_PREFIX + predicateSchemaTable.getTable()); } return hasContainerLabelSchemaTable; }
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 String calculatedAliasId() { String result = this.stepDepth + 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 void calculateLabeledAliasPropertyName(String propertyName, String alias) { String reducedLabels = reducedLabels(); String result = this.stepDepth + ALIAS_SEPARATOR + reducedLabels + ALIAS_SEPARATOR + getSchemaTable().getSchema() + ALIAS_SEPARATOR + getSchemaTable().getTable() + ALIAS_SEPARATOR + propertyName; this.getColumnNameAliasMap().put(result, alias); this.getAliasColumnNameMap().put(alias, result); }
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; }
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() ); }
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() ); }
public void loadOutVertex(ResultSet resultSet, List<ColumnList.Column> outForeignKeyColumns) { List<Comparable> identifiers = SqlgUtil.getValue(resultSet, outForeignKeyColumns); ColumnList.Column column = outForeignKeyColumns.get(0); this.outVertex = SqlgVertex.of( this.sqlgGraph, ListOrderedSet.listOrderedSet(identifiers), column.getForeignSchemaTable().getSchema(), column.getForeignSchemaTable().getTable() ); }
public void addTemporaryVertex(Object... keyValues) { if (this.tx().isInStreamingBatchMode()) { throw SqlgExceptions.invalidMode(String.format("Transaction is in %s, use streamVertex(Object ... keyValues)", this.tx().getBatchModeType().toString())); } Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label, true); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); this.getTopology().ensureTemporaryVertexTableExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); new SqlgVertex(this, true, false, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); }