/** * 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); }
/** * Factory method to create an ordered set specifying the list and set to use. * <p> * The list and set must both be empty. * * @param <E> the element type * @param set the set to decorate, must be empty and not null * @param list the list to decorate, must be empty and not null * @return a new ordered set * @throws NullPointerException if set or list is null * @throws IllegalArgumentException if either the set or list is not empty * @since 4.0 */ public static <E> ListOrderedSet<E> listOrderedSet(final Set<E> set, final List<E> list) { if (set == null) { throw new NullPointerException("Set must not be null"); } if (list == null) { throw new NullPointerException("List must not be null"); } if (set.size() > 0 || list.size() > 0) { throw new IllegalArgumentException("Set and List must be empty"); } return new ListOrderedSet<>(set, list); }
/** * Factory method to create an ordered set using the supplied list to retain order. * <p> * A <code>HashSet</code> is used for the set behaviour. * <p> * NOTE: If the list contains duplicates, the duplicates are removed, * altering the specified list. * * @param <E> the element type * @param list the list to decorate, must not be null * @return a new ordered set * @throws NullPointerException if list is null * @since 4.0 */ public static <E> ListOrderedSet<E> listOrderedSet(final List<E> list) { if (list == null) { throw new NullPointerException("List must not be null"); } CollectionUtils.filter(list, UniquePredicate.uniquePredicate()); final Set<E> set = new HashSet<>(list); return new ListOrderedSet<>(set, list); }
static EdgeLabel loadSqlgSchemaEdgeLabel( String edgeLabelName, VertexLabel outVertexLabel, VertexLabel inVertexLabel, Map<String, PropertyType> properties) { //edges are created in the out vertex's schema. return new EdgeLabel(true, edgeLabelName, outVertexLabel, inVertexLabel, properties, new ListOrderedSet<>()); }
static EdgeLabel loadSqlgSchemaEdgeLabel( String edgeLabelName, VertexLabel outVertexLabel, VertexLabel inVertexLabel, Map<String, PropertyType> properties) { //edges are created in the out vertex's schema. return new EdgeLabel(true, edgeLabelName, outVertexLabel, inVertexLabel, properties, new ListOrderedSet<>()); }
EdgeLabel(Topology topology, String edgeLabelName) { super(topology.getSqlgGraph(), edgeLabelName, Collections.emptyMap(), new ListOrderedSet<>()); this.topology = topology; }
EdgeLabel(Topology topology, String edgeLabelName) { super(topology.getSqlgGraph(), edgeLabelName, Collections.emptyMap(), new ListOrderedSet<>()); this.topology = topology; }
/** * Ensures that the edge table with out and in {@link VertexLabel}s and property columns exists. * The edge table will reside in the out vertex's schema. * If a table, a foreign key or a column needs to be created a lock is first obtained. * * @param edgeLabelName The label of the edge for which a table will be created. * @param outVertexLabel The edge's out {@link VertexLabel} * @param inVertexLabel The edge's in {@link VertexLabel} * @param properties The edge's properties with their type. * @return The {@link EdgeLabel} */ public EdgeLabel ensureEdgeLabelExist(final String edgeLabelName, final VertexLabel outVertexLabel, final VertexLabel inVertexLabel, Map<String, PropertyType> properties) { return ensureEdgeLabelExist(edgeLabelName, outVertexLabel, inVertexLabel, properties, new ListOrderedSet<>()); }
public VertexLabel ensureVertexLabelExist(final String label, final Map<String, PropertyType> columns) { return ensureVertexLabelExist(label, columns, new ListOrderedSet<>()); }
/** * Ensures that the edge table with out and in {@link VertexLabel}s and property columns exists. * The edge table will reside in the out vertex's schema. * If a table, a foreign key or a column needs to be created a lock is first obtained. * * @param edgeLabelName The label of the edge for which a table will be created. * @param outVertexLabel The edge's out {@link VertexLabel} * @param inVertexLabel The edge's in {@link VertexLabel} * @param properties The edge's properties with their type. * @return The {@link EdgeLabel} */ public EdgeLabel ensureEdgeLabelExist(final String edgeLabelName, final VertexLabel outVertexLabel, final VertexLabel inVertexLabel, Map<String, PropertyType> properties) { return ensureEdgeLabelExist(edgeLabelName, outVertexLabel, inVertexLabel, properties, new ListOrderedSet<>()); }
/** * Called via {@link Schema#ensureEdgeLabelExist(String, VertexLabel, VertexLabel, Map)} * This is called when the {@link EdgeLabel} does not exist and needs to be created. * * @param edgeLabelName The edge's label. * @param inVertexLabel The edge's in vertex. * @param properties The edge's properties. * @return The new EdgeLabel. */ EdgeLabel addEdgeLabel( String edgeLabelName, VertexLabel inVertexLabel, Map<String, PropertyType> properties) { return addEdgeLabel(edgeLabelName, inVertexLabel, properties, new ListOrderedSet<>()); }
public VertexLabel ensureVertexLabelExist(final String label, final Map<String, PropertyType> columns) { return ensureVertexLabelExist(label, columns, new ListOrderedSet<>()); }
/** * Called via {@link Schema#ensureEdgeLabelExist(String, VertexLabel, VertexLabel, Map)} * This is called when the {@link EdgeLabel} does not exist and needs to be created. * * @param edgeLabelName The edge's label. * @param inVertexLabel The edge's in vertex. * @param properties The edge's properties. * @return The new EdgeLabel. */ EdgeLabel addEdgeLabel( String edgeLabelName, VertexLabel inVertexLabel, Map<String, PropertyType> properties) { return addEdgeLabel(edgeLabelName, inVertexLabel, properties, new ListOrderedSet<>()); }
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; }
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; }
static EdgeLabel createEdgeLabel( String edgeLabelName, VertexLabel outVertexLabel, VertexLabel inVertexLabel, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers) { Preconditions.checkState(!inVertexLabel.getSchema().isSqlgSchema(), "You may not create an edge to %s", Topology.SQLG_SCHEMA); //edges are created in the out vertex's schema. EdgeLabel edgeLabel = new EdgeLabel(false, edgeLabelName, outVertexLabel, inVertexLabel, properties, identifiers); edgeLabel.createEdgeTableOnDb(outVertexLabel, inVertexLabel, properties, identifiers); edgeLabel.committed = false; return edgeLabel; }
static EdgeLabel createEdgeLabel( String edgeLabelName, VertexLabel outVertexLabel, VertexLabel inVertexLabel, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers) { Preconditions.checkState(!inVertexLabel.getSchema().isSqlgSchema(), "You may not create an edge to %s", Topology.SQLG_SCHEMA); //edges are created in the out vertex's schema. EdgeLabel edgeLabel = new EdgeLabel(false, edgeLabelName, outVertexLabel, inVertexLabel, properties, identifiers); edgeLabel.createEdgeTableOnDb(outVertexLabel, inVertexLabel, properties, identifiers); edgeLabel.committed = false; return edgeLabel; }
public void ensurePropertiesExist(Map<String, PropertyType> columns) { for (Map.Entry<String, PropertyType> column : columns.entrySet()) { if (!this.properties.containsKey(column.getKey())) { Preconditions.checkState(!this.getSchema().isSqlgSchema(), "schema may not be %s", SQLG_SCHEMA); if (!this.uncommittedProperties.containsKey(column.getKey())) { this.getSchema().getTopology().lock(); if (!getProperty(column.getKey()).isPresent()) { TopologyManager.addEdgeColumn(this.sqlgGraph, this.getSchema().getName(), EDGE_PREFIX + getLabel(), column, new ListOrderedSet<>()); addColumn(this.getSchema().getName(), EDGE_PREFIX + getLabel(), ImmutablePair.of(column.getKey(), column.getValue())); PropertyColumn propertyColumn = new PropertyColumn(this, column.getKey(), column.getValue()); propertyColumn.setCommitted(false); this.uncommittedProperties.put(column.getKey(), propertyColumn); this.getSchema().getTopology().fire(propertyColumn, "", TopologyChangeAction.CREATE); } } } } }
@Override public void read(Kryo kryo, Input input) { this.schemaTable = SchemaTable.of(input.readString(), input.readString()); String s = input.readString(); if (s.equals("s")) { //sequence this.id = ID.from(input.readLong()); } else { int size = input.readInt(); ListOrderedSet<Comparable> identifiers = new ListOrderedSet<>(); for (int i = 0; i < size; i++) { String identifier = input.readString(); identifiers.add(identifier); } this.id = ID.from(identifiers); } }
@Override public void read(Kryo kryo, Input input) { this.schemaTable = SchemaTable.of(input.readString(), input.readString()); String s = input.readString(); if (s.equals("s")) { //sequence this.id = ID.from(input.readLong()); } else { int size = input.readInt(); ListOrderedSet<Comparable> identifiers = new ListOrderedSet<>(); for (int i = 0; i < size; i++) { String identifier = input.readString(); identifiers.add(identifier); } this.id = ID.from(identifiers); } }