/** * Factory method to create an ordered set. * <p> * An <code>ArrayList</code> is used to retain order. * * @param <E> the element type * @param set the set to decorate, must not be null * @return a new ordered set * @throws NullPointerException if set is null * @since 4.0 */ public static <E> ListOrderedSet<E> listOrderedSet(final Set<E> set) { return new ListOrderedSet<>(set); }
@Override public boolean addAll(final Collection<? extends E> coll) { boolean result = false; for (final E e : coll) { result |= add(e); } return result; }
/** * Inserts the specified element at the specified position if it is not yet * contained in this ordered set (optional operation). Shifts the element * currently at this position and any subsequent elements to the right. * * @param index the index at which the element is to be inserted * @param object the element to be inserted * @see List#add(int, Object) */ public void add(final int index, final E object) { if (!contains(object)) { decorated().add(object); setOrder.add(index, object); } }
public ListOrderedSet<Comparable> loadIdentifierObjects(Map<String, Integer> idColumnCountMap, ResultSet resultSet) throws SQLException { ListOrderedSet<Comparable> identifierObjects = new ListOrderedSet<>(); for (String identifier : this.identifiers) { String labelledAliasIdentifier = labeledAliasIdentifier(identifier); int count = idColumnCountMap.get(labelledAliasIdentifier); identifierObjects.add((Comparable) resultSet.getObject(count)); } return identifierObjects; }
if (inVertexLabel.getIdentifiers().isEmpty()) { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.inVertex.schema + "." + this.inVertex.table + Topology.IN_VERTEX_COLUMN_END)); } else { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.inVertex.schema + "." + this.inVertex.table + "." + identifier + Topology.IN_VERTEX_COLUMN_END)); if (outVertexLabel.isDistributed()) { if (i++ < inVertexLabel.getIdentifiers().size() - 1) { sql.append(", "); if (i++ < inVertexLabel.getIdentifiers().size()) { sql.append(", "); if (outVertexLabel.getIdentifiers().isEmpty()) { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.outVertex.schema + "." + this.outVertex.table + Topology.OUT_VERTEX_COLUMN_END)); } else { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.outVertex.schema + "." + this.outVertex.table + "." + identifier + Topology.OUT_VERTEX_COLUMN_END)); if (outVertexLabel.isDistributed()) { if (i++ < inVertexLabel.getIdentifiers().size() - 1) { sql.append(", "); if (i++ < inVertexLabel.getIdentifiers().size()) { sql.append(", "); if (inVertexLabel.getIdentifiers().isEmpty()) { preparedStatement.setLong(i++, this.inVertex.recordId.sequenceId()); } else { ListOrderedSet<Comparable> identifiers = new ListOrderedSet<>();
abstractLabel = vertexLabel.get(); Preconditions.checkArgument(abstractLabel.getIdentifiers().size() == identifiers.length, "%d identifiers expected in the RecordId. Found %d. given id = %s", abstractLabel.getIdentifiers().size(), identifiers.length, label + id); ListOrderedSet<Comparable> identifierValues = new ListOrderedSet<>(); int count = 0; for (String identifier : abstractLabel.getIdentifiers()) { PropertyType propertyType = propertyColumn.get().getPropertyType(); Comparable value = (Comparable) SqlgUtil.stringValueToType(propertyType, identifiers[count++].trim()); identifierValues.add(value); } else { throw new IllegalStateException(String.format("identifier %s for %s not found", identifier, schemaTable.toString()));
List<String> primaryKeys = this.sqlDialect.getPrimaryKeys(metadata, tblCat, schema, table); if (primaryKeys.size() == 1 && primaryKeys.get(0).equals(Topology.ID)) { TopologyManager.addVertexLabel(this.sqlgGraph, schema, label, columns, new ListOrderedSet<>()); } else { ListOrderedSet<String> identifiers = new ListOrderedSet<>(); for (String s : columns.keySet()) { if (s.equalsIgnoreCase("ID") || s.equalsIgnoreCase("uid") || s.equalsIgnoreCase("uuid")) { identifiers.add(s); TopologyManager.addVertexLabel(this.sqlgGraph, schema, label, columns, ListOrderedSet.listOrderedSet(primaryKeys)); Vertex edgeVertex; if (hasIDPrimaryKey(primaryKeys)) { edgeVertex = TopologyManager.addEdgeLabel(this.sqlgGraph, table, Collections.emptyMap(), new ListOrderedSet<>(), PartitionType.NONE, null); } else { ListOrderedSet<String> identifiers = new ListOrderedSet<>(); for (Triple<String, Integer, String> s : edgeColumns) { if (s.getLeft().equalsIgnoreCase("ID") || s.getLeft().equalsIgnoreCase("uid") || s.getLeft().equalsIgnoreCase("uuid")) { identifiers.add(s.getLeft()); edgeVertex = TopologyManager.addEdgeLabel(this.sqlgGraph, table, Collections.emptyMap(), ListOrderedSet.listOrderedSet(primaryKeys), PartitionType.NONE, null); TopologyManager.addEdgeColumn(this.sqlgGraph, schema, table, columns, ListOrderedSet.listOrderedSet(primaryKeys)); String label = table.substring(Topology.EDGE_PREFIX.length()); if (indices != null) {
SqlgUtil.setKeyValuesAsParameterUsingPropertyColumn(this.sqlgGraph, i, preparedStatement, propertyTypeValueMap); preparedStatement.executeUpdate(); if (!temporary && !vertexLabel.getIdentifiers().isEmpty()) { ListOrderedSet<Comparable> identifiers = new ListOrderedSet<>(); for (String identifier : vertexLabel.getIdentifiers()) { identifiers.add((Comparable) propertyTypeValueMap.get(identifier).getRight());
for (String identifier : edgeLabel.getIdentifiers()) { sql.append(maybeWrapInQoutes(identifier)); if (cnt++ < edgeLabel.getIdentifiers().size()) { sql.append(","); for (Comparable identifierValue : id.getIdentifiers()) { sql.append(toRDBSStringLiteral(identifierValue)); if (cnt++ < id.getIdentifiers().size()) { sql.append(",");
/** * Returns a set that maintains the order of elements that are added * backed by the given set. * <p> * If an element is added twice, the order is determined by the first add. * The order is observed through the iterator or toArray. * * @param <E> the element type * @param set the set to order, must not be null * @return an ordered set backed by the given set * @throws NullPointerException if the set is null */ public static <E> Set<E> orderedSet(final Set<E> set) { return ListOrderedSet.listOrderedSet(set); }
private void distribute(int shard_count, PropertyColumn distributionPropertyColumn, AbstractLabel colocate) { Preconditions.checkArgument(getIdentifiers().contains(distributionPropertyColumn.getName()), "The distribution column must be part of the primary key"); Connection conn = sqlgGraph.tx().getConnection(); if (shard_count > -1) { try (Statement stmt = conn.createStatement()) { String sql = "SET citus.shard_count = " + shard_count + ";"; logger.debug(sql); stmt.execute(sql); } catch (SQLException e) { throw new RuntimeException(e); } } distribute(conn, distributionPropertyColumn, colocate); }
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); } }
public ListOrderedSet<String> getIdentifiers() { ListOrderedSet<String> result = ListOrderedSet.listOrderedSet(this.identifiers); if (this.getSchema().getTopology().isSqlWriteLockHeldByCurrentThread()) { result.addAll(this.uncommittedIdentifiers); } return result; }
/** * 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; }
@Override public void clear() { decorated().clear(); setOrder.clear(); }
/** * Only called for a new vertex/edge label being added. * * @param label The vertex or edge's label. * @param properties The vertex's properties. * @param identifiers The vertex or edge's identifiers */ AbstractLabel(SqlgGraph sqlgGraph, String label, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers) { 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); }
@Override public boolean equals(Object other) { if (!(other instanceof ID)) { return false; } ID otherID = (ID) other; if (this.sequenceId != null) { return this.sequenceId.equals(otherID.sequenceId); } else { return this.identifiers.equals(otherID.identifiers); } }
this.uncommittedIdentifiers.clear(); this.uncommittedGlobalUniqueIndexProperties.clear(); for (Iterator<Map.Entry<String, Index>> it = this.uncommittedIndexes.entrySet().iterator(); it.hasNext(); ) {