use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyTestUtil method performBulkCopy.
/**
* @param bulkWrapper
* @param srcData
* @param dstTable
*/
static void performBulkCopy(BulkCopyTestWrapper bulkWrapper, ISQLServerBulkRecord srcData, DBTable dstTable) {
try (DBConnection con = new DBConnection(bulkWrapper.getConnectionString());
DBStatement stmt = con.createStatement();
SQLServerBulkCopy bc = new SQLServerBulkCopy(bulkWrapper.getConnectionString())) {
bc.setDestinationTableName(dstTable.getEscapedTableName());
bc.writeToServer(srcData);
validateValues(con, srcData, dstTable);
} catch (Exception e) {
fail(e.getMessage());
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project sqlg by pietermartin.
the class MSSqlServerDialect method flushEdgeGlobalUniqueIndexes.
@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);
}
}
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project sqlg by pietermartin.
the class MSSqlServerDialect method flushVertexCache.
@Override
public void flushVertexCache(SqlgGraph sqlgGraph, Map<SchemaTable, Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>>> vertexCache) {
Connection connection = sqlgGraph.tx().getConnection();
for (Map.Entry<SchemaTable, Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>>> entry : vertexCache.entrySet()) {
SchemaTable schemaTable = entry.getKey();
Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>> vertices = entry.getValue();
if (vertices.getLeft().isEmpty()) {
Map<String, PropertyType> columns = new HashMap<>();
columns.put("dummy", PropertyType.from(0));
sqlgGraph.getTopology().ensureVertexLabelPropertiesExist(schemaTable.getSchema(), schemaTable.getTable(), columns);
}
try {
SQLServerConnection sqlServerConnection = connection.unwrap(SQLServerConnection.class);
try (SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(sqlServerConnection)) {
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));
}
int numberInserted = vertices.getRight().size();
if (!schemaTable.isTemporary() && numberInserted > 0) {
long endHigh;
// If multiple threads are bulk writing to the same label then the indexes might no be in sequence.
try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT IDENT_CURRENT('" + schemaTable.getSchema() + "." + VERTEX_PREFIX + schemaTable.getTable() + "')")) {
ResultSet resultSet = preparedStatement.executeQuery();
resultSet.next();
endHigh = resultSet.getLong(1);
resultSet.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
// set the id on the vertex
long id = endHigh - numberInserted + 1;
for (SqlgVertex sqlgVertex : vertices.getRight().keySet()) {
sqlgVertex.setInternalPrimaryKey(RecordId.from(schemaTable, id++));
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
Aggregations