SchemaTableTree(SqlgGraph sqlgGraph, SchemaTable schemaTable, int stepDepth, int replacedStepDepth) { this.sqlgGraph = sqlgGraph; this.schemaTable = schemaTable; this.stepDepth = stepDepth; this.hasContainers = new ArrayList<>(); this.andOrHasContainers = new ArrayList<>(); this.dbComparators = new ArrayList<>(); this.labels = Collections.emptySet(); this.replacedStepDepth = replacedStepDepth; this.filteredAllTables = sqlgGraph.getTopology().getAllTables(Topology.SQLG_SCHEMA.equals(schemaTable.getSchema()), Schema.GLOBAL_UNIQUE_INDEX_SCHEMA.equals(schemaTable.getSchema())); setIdentifiersAndDistributionColumn(); this.hasIDPrimaryKey = this.identifiers.isEmpty(); }
SchemaTableTree(SqlgGraph sqlgGraph, SchemaTable schemaTable, int stepDepth, int replacedStepDepth) { this.sqlgGraph = sqlgGraph; this.schemaTable = schemaTable; this.stepDepth = stepDepth; this.hasContainers = new ArrayList<>(); this.andOrHasContainers = new ArrayList<>(); this.dbComparators = new ArrayList<>(); this.labels = Collections.emptySet(); this.replacedStepDepth = replacedStepDepth; this.filteredAllTables = sqlgGraph.getTopology().getAllTables(Topology.SQLG_SCHEMA.equals(schemaTable.getSchema()), Schema.GLOBAL_UNIQUE_INDEX_SCHEMA.equals(schemaTable.getSchema())); setIdentifiersAndDistributionColumn(); this.hasIDPrimaryKey = this.identifiers.isEmpty(); }
private void buildQuestionMark(StringBuilder sql, VertexLabel vertexLabel) { if (vertexLabel.getIdentifiers().isEmpty()) { sql.append("?"); } else { for (String identifier : vertexLabel.getIdentifiers()) { if (!vertexLabel.isDistributed() || !vertexLabel.getDistributionPropertyColumn().getName().equals(identifier)) { sql.append("?, "); } } //remove the extra comma sql.delete(sql.length() - 2, sql.length()); } }
private void buildQuestionMark(StringBuilder sql, VertexLabel vertexLabel) { if (vertexLabel.getIdentifiers().isEmpty()) { sql.append("?"); } else { for (String identifier : vertexLabel.getIdentifiers()) { if (!vertexLabel.isDistributed() || !vertexLabel.getDistributionPropertyColumn().getName().equals(identifier)) { sql.append("?, "); } } //remove the extra comma sql.delete(sql.length() - 2, sql.length()); } }
/** * Only called for a new partitioned vertex/edge label being added. * * @param label The vertex or edge's label. * @param properties The element's properties. * @param identifiers The element's identifiers. * @param partitionType The partition type. i.e. RANGE or LIST. * @param partitionExpression The sql fragment to express the partition column or expression. */ AbstractLabel(SqlgGraph sqlgGraph, String label, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers, PartitionType partitionType, String partitionExpression) { Preconditions.checkArgument(partitionType == PartitionType.RANGE || partitionType == PartitionType.LIST, "Only RANGE and LIST partitions are supported. Found %s", partitionType.name()); Preconditions.checkArgument(!partitionExpression.isEmpty(), "partitionExpression may not be an empty string."); Preconditions.checkArgument(!identifiers.isEmpty(), "Partitioned labels must have at least one identifier."); this.sqlgGraph = sqlgGraph; this.label = label; for (Map.Entry<String, PropertyType> propertyEntry : properties.entrySet()) { PropertyColumn property = new PropertyColumn(this, propertyEntry.getKey(), propertyEntry.getValue()); property.setCommitted(false); this.uncommittedProperties.put(propertyEntry.getKey(), property); } this.uncommittedIdentifiers.addAll(identifiers); this.partitionType = partitionType; this.partitionExpression = partitionExpression; }
/** * Only called for a new partitioned vertex/edge label being added. * * @param label The vertex or edge's label. * @param properties The element's properties. * @param identifiers The element's identifiers. * @param partitionType The partition type. i.e. RANGE or LIST. * @param partitionExpression The sql fragment to express the partition column or expression. */ AbstractLabel(SqlgGraph sqlgGraph, String label, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers, PartitionType partitionType, String partitionExpression) { Preconditions.checkArgument(partitionType == PartitionType.RANGE || partitionType == PartitionType.LIST, "Only RANGE and LIST partitions are supported. Found %s", partitionType.name()); Preconditions.checkArgument(!partitionExpression.isEmpty(), "partitionExpression may not be an empty string."); Preconditions.checkArgument(!identifiers.isEmpty(), "Partitioned labels must have at least one identifier."); this.sqlgGraph = sqlgGraph; this.label = label; for (Map.Entry<String, PropertyType> propertyEntry : properties.entrySet()) { PropertyColumn property = new PropertyColumn(this, propertyEntry.getKey(), propertyEntry.getValue()); property.setCommitted(false); this.uncommittedProperties.put(propertyEntry.getKey(), property); } this.uncommittedIdentifiers.addAll(identifiers); this.partitionType = partitionType; this.partitionExpression = partitionExpression; }
public enum STEP_TYPE { GRAPH_STEP, VERTEX_STEP, EDGE_VERTEX_STEP }
static VertexLabel createPartitionedVertexLabel( SqlgGraph sqlgGraph, Schema schema, String label, Map<String, PropertyType> columns, ListOrderedSet<String> identifiers, PartitionType partitionType, String partitionExpression) { Preconditions.checkArgument(!schema.isSqlgSchema(), "createVertexLabel may not be called for \"%s\"", SQLG_SCHEMA); Preconditions.checkArgument(partitionType != PartitionType.NONE, "PartitionType must be RANGE or LIST. Found NONE."); Preconditions.checkArgument(!StringUtils.isEmpty(partitionExpression), "partitionExpression may not be null or empty when creating a partitioned vertex label."); Preconditions.checkArgument(!identifiers.isEmpty(), "Partitioned label must have at least one identifier."); VertexLabel vertexLabel = new VertexLabel(schema, label, columns, identifiers, partitionType, partitionExpression); vertexLabel.createPartitionedVertexLabelOnDb(columns, identifiers); TopologyManager.addVertexLabel(sqlgGraph, schema.getName(), label, columns, identifiers, partitionType, partitionExpression); vertexLabel.committed = false; return vertexLabel; }
public enum STEP_TYPE { GRAPH_STEP, VERTEX_STEP, EDGE_VERTEX_STEP }
static VertexLabel createPartitionedVertexLabel( SqlgGraph sqlgGraph, Schema schema, String label, Map<String, PropertyType> columns, ListOrderedSet<String> identifiers, PartitionType partitionType, String partitionExpression) { Preconditions.checkArgument(!schema.isSqlgSchema(), "createVertexLabel may not be called for \"%s\"", SQLG_SCHEMA); Preconditions.checkArgument(partitionType != PartitionType.NONE, "PartitionType must be RANGE or LIST. Found NONE."); Preconditions.checkArgument(!StringUtils.isEmpty(partitionExpression), "partitionExpression may not be null or empty when creating a partitioned vertex label."); Preconditions.checkArgument(!identifiers.isEmpty(), "Partitioned label must have at least one identifier."); VertexLabel vertexLabel = new VertexLabel(schema, label, columns, identifiers, partitionType, partitionExpression); vertexLabel.createPartitionedVertexLabelOnDb(columns, identifiers); TopologyManager.addVertexLabel(sqlgGraph, schema.getName(), label, columns, identifiers, partitionType, partitionExpression); vertexLabel.committed = false; return vertexLabel; }
private void createPartitionedVertexLabelOnDb(Map<String, PropertyType> columns, ListOrderedSet<String> identifiers) { Preconditions.checkState(!identifiers.isEmpty(), "Partitioned table must have identifiers."); StringBuilder sql = new StringBuilder(this.sqlgGraph.getSqlDialect().createTableStatement()); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.schema.getName())); sql.append("."); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(VERTEX_PREFIX + getLabel())); sql.append(" ("); buildColumns(this.sqlgGraph, new ListOrderedSet<>(), columns, sql); //nothing to do with the identifiers as partitioned tables do not have primary keys. sql.append(") PARTITION BY "); sql.append(this.partitionType.name()); sql.append(" ("); sql.append(this.partitionExpression); sql.append(")"); if (this.sqlgGraph.getSqlDialect().needsSemicolon()) { sql.append(";"); } if (logger.isDebugEnabled()) { logger.debug(sql.toString()); } Connection conn = this.sqlgGraph.tx().getConnection(); try (Statement stmt = conn.createStatement()) { stmt.execute(sql.toString()); } catch (SQLException e) { throw new RuntimeException(e); } }
private void createPartitionedVertexLabelOnDb(Map<String, PropertyType> columns, ListOrderedSet<String> identifiers) { Preconditions.checkState(!identifiers.isEmpty(), "Partitioned table must have identifiers."); StringBuilder sql = new StringBuilder(this.sqlgGraph.getSqlDialect().createTableStatement()); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.schema.getName())); sql.append("."); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(VERTEX_PREFIX + getLabel())); sql.append(" ("); buildColumns(this.sqlgGraph, new ListOrderedSet<>(), columns, sql); //nothing to do with the identifiers as partitioned tables do not have primary keys. sql.append(") PARTITION BY "); sql.append(this.partitionType.name()); sql.append(" ("); sql.append(this.partitionExpression); sql.append(")"); if (this.sqlgGraph.getSqlDialect().needsSemicolon()) { sql.append(";"); } if (logger.isDebugEnabled()) { logger.debug(sql.toString()); } Connection conn = this.sqlgGraph.tx().getConnection(); try (Statement stmt = conn.createStatement()) { stmt.execute(sql.toString()); } catch (SQLException e) { throw new RuntimeException(e); } }
if (!identifiers.isEmpty() && columns.size() > identifiers.size()) { sql.append(", ");
if (!identifiers.isEmpty() && columns.size() > identifiers.size()) { sql.append(", ");
SqlgUtil.setKeyValuesAsParameterUsingPropertyColumn(this.sqlgGraph, i, preparedStatement, propertyTypeValueMap); preparedStatement.executeUpdate(); if (!temporary && !vertexLabel.getIdentifiers().isEmpty()) { ListOrderedSet<Comparable> identifiers = new ListOrderedSet<>(); for (String identifier : vertexLabel.getIdentifiers()) {
SqlgUtil.setKeyValuesAsParameterUsingPropertyColumn(this.sqlgGraph, i, preparedStatement, propertyTypeValueMap); preparedStatement.executeUpdate(); if (!temporary && !vertexLabel.getIdentifiers().isEmpty()) { ListOrderedSet<Comparable> identifiers = new ListOrderedSet<>(); for (String identifier : vertexLabel.getIdentifiers()) {