@Override public void flushVertexGlobalUniqueIndexes(SqlgGraph sqlgGraph, Map<SchemaTable, Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>>> vertexCache) { for (SchemaTable schemaTable : vertexCache.keySet()) { Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>> vertices = vertexCache.get(schemaTable); Map<String, PropertyColumn> propertyColumnMap = sqlgGraph.getTopology().getPropertiesFor(schemaTable.withPrefix(VERTEX_PREFIX)); for (Map.Entry<String, PropertyColumn> propertyColumnEntry : propertyColumnMap.entrySet()) { PropertyColumn propertyColumn = propertyColumnEntry.getValue(); for (GlobalUniqueIndex globalUniqueIndex : propertyColumn.getGlobalUniqueIndices()) { try { Connection connection = sqlgGraph.tx().getConnection(); SQLServerConnection sqlServerConnection = connection.unwrap(SQLServerConnection.class); try (SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(sqlServerConnection)) { bulkCopy.setDestinationTableName(sqlgGraph.getSqlDialect().maybeWrapInQoutes(Schema.GLOBAL_UNIQUE_INDEX_SCHEMA) + "." + sqlgGraph.getSqlDialect().maybeWrapInQoutes(VERTEX_PREFIX + globalUniqueIndex.getName()) ); bulkCopy.writeToServer(new SQLServerVertexGlobalUniqueIndexBulkRecord(bulkCopy, sqlgGraph, vertices, propertyColumn)); } } catch (SQLException e) { throw new RuntimeException(e); } } } } }
this.propertyColumn = propertyColumn; bulkCopy.addColumnMapping(1, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_VALUE); this.columnMetadata.put(1, new ColumnMetadata( GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_VALUE, PropertyType.STRING )); bulkCopy.addColumnMapping(2, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_RECORD_ID); this.columnMetadata.put(2, new ColumnMetadata( GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_RECORD_ID, PropertyType.STRING )); bulkCopy.addColumnMapping(3, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_PROPERTY_NAME); this.columnMetadata.put(3, new ColumnMetadata( GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_PROPERTY_NAME,
try { SQLServerConnection sqlServerConnection = connection.unwrap(SQLServerConnection.class); try (SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(sqlServerConnection)) { SQLServerBulkCopyOptions options = new SQLServerBulkCopyOptions(); bulkCopy.setBulkCopyOptions(options); bulkCopy.setDestinationTableName(sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getSchema()) + "." + sqlgGraph.getSqlDialect().maybeWrapInQoutes(EDGE_PREFIX + schemaTable.getTable()) ); bulkCopy.writeToServer(new SQLServerEdgeCacheBulkRecord(bulkCopy, sqlgGraph, metaEdge, schemaTable, triples));
try (SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(sqlServerConnection)) { SQLServerBulkCopyOptions options = new SQLServerBulkCopyOptions(); bulkCopy.setBulkCopyOptions(options); if (schemaTable.isTemporary()) { bulkCopy.setDestinationTableName( sqlgGraph.getSqlDialect().maybeWrapInQoutes(sqlgGraph.getSqlDialect().temporaryTablePrefix() + VERTEX_PREFIX + schemaTable.getTable()) ); } else { bulkCopy.setDestinationTableName(sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getSchema()) + "." + sqlgGraph.getSqlDialect().maybeWrapInQoutes(VERTEX_PREFIX + schemaTable.getTable()) ); bulkCopy.writeToServer(new SQLServerVertexCacheBulkRecord(bulkCopy, sqlgGraph, schemaTable, vertices));
@Override public void flushEdgeGlobalUniqueIndexes(SqlgGraph sqlgGraph, Map<MetaEdge, Pair<SortedSet<String>, Map<SqlgEdge, Triple<SqlgVertex, SqlgVertex, Map<String, Object>>>>> edgeCache) { for (MetaEdge metaEdge : edgeCache.keySet()) { Pair<SortedSet<String>, Map<SqlgEdge, Triple<SqlgVertex, SqlgVertex, Map<String, Object>>>> triples = edgeCache.get(metaEdge); Map<SqlgEdge, Triple<SqlgVertex, SqlgVertex, Map<String, Object>>> edgeMap = triples.getRight(); Map<String, PropertyColumn> propertyColumnMap = sqlgGraph.getTopology().getPropertiesFor(metaEdge.getSchemaTable().withPrefix(EDGE_PREFIX)); for (Map.Entry<String, PropertyColumn> propertyColumnEntry : propertyColumnMap.entrySet()) { PropertyColumn propertyColumn = propertyColumnEntry.getValue(); for (GlobalUniqueIndex globalUniqueIndex : propertyColumn.getGlobalUniqueIndices()) { try { Connection connection = sqlgGraph.tx().getConnection(); SQLServerConnection sqlServerConnection = connection.unwrap(SQLServerConnection.class); try (SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(sqlServerConnection)) { bulkCopy.setDestinationTableName(sqlgGraph.getSqlDialect().maybeWrapInQoutes(Schema.GLOBAL_UNIQUE_INDEX_SCHEMA) + "." + sqlgGraph.getSqlDialect().maybeWrapInQoutes(VERTEX_PREFIX + globalUniqueIndex.getName()) ); bulkCopy.writeToServer(new SQLServerEdgeGlobalUniqueIndexBulkRecord(bulkCopy, sqlgGraph, edgeMap, propertyColumn)); } } catch (SQLException e) { throw new RuntimeException(e); } } } } }
this.propertyColumn = propertyColumn; bulkCopy.addColumnMapping(1, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_VALUE); this.columnMetadata.put(1, new ColumnMetadata( GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_VALUE, PropertyType.STRING )); bulkCopy.addColumnMapping(2, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_RECORD_ID); this.columnMetadata.put(2, new ColumnMetadata( GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_RECORD_ID, PropertyType.STRING )); bulkCopy.addColumnMapping(3, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_PROPERTY_NAME); this.columnMetadata.put(3, new ColumnMetadata( GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_PROPERTY_NAME,
SQLServerVertexCacheBulkRecord(SQLServerBulkCopy bulkCopy, SqlgGraph sqlgGraph, SchemaTable schemaTable, Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>> vertices) throws SQLServerException { this.rowIter = vertices.getRight().entrySet().iterator(); if (!schemaTable.isTemporary()) { this.propertyColumns = sqlgGraph.getTopology() .getSchema(schemaTable.getSchema()).orElseThrow(() -> new IllegalStateException(String.format("Schema %s not found", schemaTable.getSchema()))) .getVertexLabel(schemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel %s not found", schemaTable.getTable()))) .getProperties(); } else { this.properties = sqlgGraph.getTopology().getPublicSchema().getTemporaryTable(VERTEX_PREFIX + schemaTable.getTable()); } int i = 1; this.columns = vertices.getLeft(); this.dummy = this.columns.isEmpty(); if (this.dummy) { bulkCopy.addColumnMapping(i, "dummy"); this.columnMetadata.put(i, new ColumnMetadata( "dummy", sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.INTEGER)[0], 0, 0, null, PropertyType.INTEGER )); } else { addMetaData(bulkCopy, sqlgGraph); } }
bulkCopy.addColumnMapping(i, metaEdge.getInLabel() + Topology.IN_VERTEX_COLUMN_END); this.columnMetadata.put(i++, new ColumnMetadata( metaEdge.getInLabel() + Topology.IN_VERTEX_COLUMN_END, } else { for (String identifier : inVertexLabel.getIdentifiers()) { bulkCopy.addColumnMapping(i, metaEdge.getInLabel() + "." + identifier + Topology.IN_VERTEX_COLUMN_END); PropertyType propertyType = inVertexLabel.getProperty(identifier).orElseThrow(() -> new IllegalStateException(String.format("BUG: Did not find the identifier property %s.", identifier))).getPropertyType(); this.columnMetadata.put(i++, new ColumnMetadata( bulkCopy.addColumnMapping(i, metaEdge.getOutLabel() + Topology.OUT_VERTEX_COLUMN_END); this.columnMetadata.put(i++, new ColumnMetadata( metaEdge.getOutLabel() + Topology.OUT_VERTEX_COLUMN_END, for (String identifier : outVertexLabel.getIdentifiers()) { PropertyType propertyType = outVertexLabel.getProperty(identifier).orElseThrow(() -> new IllegalStateException(String.format("BUG: Did not find the identifier property %s.", identifier))).getPropertyType(); bulkCopy.addColumnMapping(i, metaEdge.getOutLabel() + "." + identifier + Topology.OUT_VERTEX_COLUMN_END); this.columnMetadata.put(i++, new ColumnMetadata( metaEdge.getOutLabel() + "." + identifier + Topology.OUT_VERTEX_COLUMN_END,
bulkCopy.addColumnMapping(i, column); this.columnMetadata.put(i++, new ColumnMetadata( column, bulkCopy.addColumnMapping(i, column); this.columnMetadata.put(i++, new ColumnMetadata( column, bulkCopy.addColumnMapping(i, column); this.columnMetadata.put(i++, new ColumnMetadata( column, break; case LOCALDATE_ORDINAL: bulkCopy.addColumnMapping(i, column); this.columnMetadata.put(i++, new ColumnMetadata( column, break; case LOCALDATETIME_ORDINAL: bulkCopy.addColumnMapping(i, column); this.columnMetadata.put(i++, new ColumnMetadata( column, break; case LOCALTIME_ORDINAL: bulkCopy.addColumnMapping(i, column); this.columnMetadata.put(i++, new ColumnMetadata( column,