Java Code Examples for com.microsoft.sqlserver.jdbc.SQLServerBulkCopy

The following examples show how to use com.microsoft.sqlserver.jdbc.SQLServerBulkCopy. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sqlg   Source File: MSSqlServerDialect.java    License: MIT License 6 votes vote down vote up
@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);
                }
            }
        }
    }
}
 
Example 2
Source Project: sqlg   Source File: SQLServerVertexGlobalUniqueIndexBulkRecord.java    License: MIT License 5 votes vote down vote up
SQLServerVertexGlobalUniqueIndexBulkRecord(SQLServerBulkCopy bulkCopy,
                                           SqlgGraph sqlgGraph,
                                           Pair<SortedSet<String>,
                                             Map<SqlgVertex, Map<String, Object>>> vertices,
                                           PropertyColumn propertyColumn
) throws SQLServerException {
    this.rowIter = vertices.getRight().entrySet().iterator();
    this.propertyColumn = propertyColumn;

    bulkCopy.addColumnMapping(1, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_VALUE);
    this.columnMetadata.put(1, new ColumnMetadata(
            GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_VALUE,
            sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.STRING)[0],
            0,
            0,
            null,
            PropertyType.STRING
    ));
    bulkCopy.addColumnMapping(2, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_RECORD_ID);
    this.columnMetadata.put(2, new ColumnMetadata(
            GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_RECORD_ID,
            sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.STRING)[0],
            0,
            0,
            null,
            PropertyType.STRING
    ));
    bulkCopy.addColumnMapping(3, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_PROPERTY_NAME);
    this.columnMetadata.put(3, new ColumnMetadata(
            GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_PROPERTY_NAME,
            sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.STRING)[0],
            0,
            0,
            null,
            PropertyType.STRING
    ));
}
 
Example 3
Source Project: sqlg   Source File: SQLServerEdgeGlobalUniqueIndexBulkRecord.java    License: MIT License 5 votes vote down vote up
SQLServerEdgeGlobalUniqueIndexBulkRecord(SQLServerBulkCopy bulkCopy,
                                         SqlgGraph sqlgGraph,
                                         Map<SqlgEdge, Triple<SqlgVertex, SqlgVertex, Map<String, Object>>> edgeMap,
                                         PropertyColumn propertyColumn
) throws SQLServerException {

    this.rowIter = edgeMap.entrySet().iterator();
    this.propertyColumn = propertyColumn;

    bulkCopy.addColumnMapping(1, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_VALUE);
    this.columnMetadata.put(1, new ColumnMetadata(
            GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_VALUE,
            sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.STRING)[0],
            0,
            0,
            null,
            PropertyType.STRING
    ));
    bulkCopy.addColumnMapping(2, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_RECORD_ID);
    this.columnMetadata.put(2, new ColumnMetadata(
            GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_RECORD_ID,
            sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.STRING)[0],
            0,
            0,
            null,
            PropertyType.STRING
    ));
    bulkCopy.addColumnMapping(3, GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_PROPERTY_NAME);
    this.columnMetadata.put(3, new ColumnMetadata(
            GlobalUniqueIndex.GLOBAL_UNIQUE_INDEX_PROPERTY_NAME,
            sqlgGraph.getSqlDialect().propertyTypeToJavaSqlType(PropertyType.STRING)[0],
            0,
            0,
            null,
            PropertyType.STRING
    ));
}
 
Example 4
Source Project: sqlg   Source File: MSSqlServerDialect.java    License: MIT License 5 votes vote down vote up
@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);
                }
            }
        }
    }
}
 
Example 5
Source Project: sqlg   Source File: SQLServerVertexCacheBulkRecord.java    License: MIT License 5 votes vote down vote up
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);
    }
}