private static VertexLabel ensureVertexLabelExist(Topology topology, String label, Map<String, PropertyType> columns, List<String> nonUniqueIndexNames) { VertexLabel vertexLabel = topology.ensureVertexLabelExist(label, columns); nonUniqueIndexNames.stream() .flatMap(fromOptional(vertexLabel::getProperty)) .map(Collections::singletonList) .forEach(properties -> vertexLabel.ensureIndexExists(NON_UNIQUE, properties)); return vertexLabel; }
@SuppressWarnings("OptionalGetWithoutIsPresent") static GlobalUniqueIndex createGlobalUniqueIndex(SqlgGraph sqlgGraph, Topology topology, String globalUniqueIndexName, Set<PropertyColumn> properties) { //all PropertyColumns must be for the same PropertyType PropertyType propertyType = properties.iterator().next().getPropertyType(); Map<String, PropertyType> valueColumn = new HashMap<>(); valueColumn.put(GLOBAL_UNIQUE_INDEX_RECORD_ID, PropertyType.STRING); valueColumn.put(GLOBAL_UNIQUE_INDEX_PROPERTY_NAME, PropertyType.STRING); valueColumn.put(GLOBAL_UNIQUE_INDEX_VALUE, propertyType); VertexLabel vertexLabel = topology.getGlobalUniqueIndexSchema().ensureVertexLabelExist(globalUniqueIndexName, valueColumn); PropertyColumn valuePropertyColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_VALUE).get(); PropertyColumn recordIdColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_RECORD_ID).get(); PropertyColumn propertyColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_PROPERTY_NAME).get(); vertexLabel.ensureIndexExists(IndexType.UNIQUE, Collections.singletonList(valuePropertyColumn)); vertexLabel.ensureIndexExists(IndexType.UNIQUE, Arrays.asList(recordIdColumn, propertyColumn)); GlobalUniqueIndex globalUniqueIndex = new GlobalUniqueIndex(topology, globalUniqueIndexName, properties); topology.getGlobalUniqueIndexSchema().globalUniqueIndexes.put(globalUniqueIndex.getName(),globalUniqueIndex); TopologyManager.addGlobalUniqueIndex(sqlgGraph, globalUniqueIndexName, properties); globalUniqueIndex.committed = false; return globalUniqueIndex; }
@SuppressWarnings("OptionalGetWithoutIsPresent") static GlobalUniqueIndex createGlobalUniqueIndex(SqlgGraph sqlgGraph, Topology topology, String globalUniqueIndexName, Set<PropertyColumn> properties) { //all PropertyColumns must be for the same PropertyType PropertyType propertyType = properties.iterator().next().getPropertyType(); Map<String, PropertyType> valueColumn = new HashMap<>(); valueColumn.put(GLOBAL_UNIQUE_INDEX_RECORD_ID, PropertyType.STRING); valueColumn.put(GLOBAL_UNIQUE_INDEX_PROPERTY_NAME, PropertyType.STRING); valueColumn.put(GLOBAL_UNIQUE_INDEX_VALUE, propertyType); VertexLabel vertexLabel = topology.getGlobalUniqueIndexSchema().ensureVertexLabelExist(globalUniqueIndexName, valueColumn); PropertyColumn valuePropertyColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_VALUE).get(); PropertyColumn recordIdColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_RECORD_ID).get(); PropertyColumn propertyColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_PROPERTY_NAME).get(); vertexLabel.ensureIndexExists(IndexType.UNIQUE, Collections.singletonList(valuePropertyColumn)); vertexLabel.ensureIndexExists(IndexType.UNIQUE, Arrays.asList(recordIdColumn, propertyColumn)); GlobalUniqueIndex globalUniqueIndex = new GlobalUniqueIndex(topology, globalUniqueIndexName, properties); topology.getGlobalUniqueIndexSchema().globalUniqueIndexes.put(globalUniqueIndex.getName(),globalUniqueIndex); TopologyManager.addGlobalUniqueIndex(sqlgGraph, globalUniqueIndexName, properties); globalUniqueIndex.committed = false; return globalUniqueIndex; }
/** * @deprecated Please use {@link Topology#ensureVertexLabelExist(String, Map)} and {@link VertexLabel#ensureIndexExists(IndexType, List)}. */ @Deprecated public void createVertexLabeledIndex(String label, Object... dummykeyValues) { Map<String, PropertyType> columns = SqlgUtil.transformToColumnDefinitionMap(dummykeyValues); SchemaTable schemaTablePair = SchemaTable.from(this, label); VertexLabel vertexLabel = this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); List<PropertyColumn> properties = new ArrayList<>(); List<String> keys = SqlgUtil.transformToKeyList(dummykeyValues); for (String key : keys) { properties.add(vertexLabel.getProperty(key).get()); } vertexLabel.ensureIndexExists(IndexType.NON_UNIQUE, properties); }
/** * @deprecated Please use {@link Topology#ensureVertexLabelExist(String, Map)} and {@link VertexLabel#ensureIndexExists(IndexType, List)}. */ @Deprecated public void createVertexLabeledIndex(String label, Object... dummykeyValues) { Map<String, PropertyType> columns = SqlgUtil.transformToColumnDefinitionMap(dummykeyValues); SchemaTable schemaTablePair = SchemaTable.from(this, label); VertexLabel vertexLabel = this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); List<PropertyColumn> properties = new ArrayList<>(); List<String> keys = SqlgUtil.transformToKeyList(dummykeyValues); for (String key : keys) { properties.add(vertexLabel.getProperty(key).get()); } vertexLabel.ensureIndexExists(IndexType.NON_UNIQUE, properties); }