Skip to content

Commit 731c53d

Browse files
committed
Update the README and add a saveAll method for Collections
1 parent 0bf7e7e commit 731c53d

2 files changed

Lines changed: 52 additions & 9 deletions

File tree

JSqlServerBulkInsert/src/main/java/de/bytefish/jsqlserverbulkinsert/SqlServerBulkInsert.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.sql.Connection;
1414
import java.sql.SQLException;
15+
import java.util.Collection;
1516
import java.util.stream.Stream;
1617

1718
public class SqlServerBulkInsert<TEntity> implements ISqlServerBulkInsert<TEntity> {
@@ -44,4 +45,12 @@ public void saveAll(Connection connection, SQLServerBulkCopyOptions options, Str
4445
throw new RuntimeException(e);
4546
}
4647
}
48+
49+
public void saveAll(Connection connection, Collection<TEntity> entities) throws SQLException {
50+
if(entities == null) {
51+
throw new IllegalArgumentException("entities");
52+
}
53+
54+
saveAll(connection, entities.stream());
55+
}
4756
}

README.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,44 @@ You can obtain [JSqlServerBulkInsert] from Maven by adding the following:
1414
<dependency>
1515
<groupId>de.bytefish</groupId>
1616
<artifactId>jsqlserverbulkinsert</artifactId>
17-
<version>1.5</version>
17+
<version>2.0</version>
1818
</dependency>
1919
```
2020

21+
22+
## Supported Types ##
23+
24+
Please read up the Microsoft Documentation for understanding the mapping between SQL Server Types and JDBC Data Types:
25+
26+
* (Understanding the JDBC Driver Data Types)[https://docs.microsoft.com/en-us/sql/connect/jdbc/understanding-the-jdbc-driver-data-types]
27+
28+
The following JDBC Types are supported by the library:
29+
30+
* [Numeric Types](http://www.postgresql.org/docs/current/static/datatype-numeric.html)
31+
* TINYINT
32+
* SMALLINT
33+
* INTEGER
34+
* BIGINT
35+
* NUMERIC
36+
* REAL
37+
* DOUBLE
38+
* Date/Time Types
39+
* DATE
40+
* TIMESTAMP
41+
* TIMESTAMP with Timezone
42+
* Boolean Type
43+
* BIT
44+
* Character / Text Types
45+
* CHAR
46+
* NCHAR
47+
* CLOB
48+
* VARCHAR
49+
* NVARCHAR
50+
* LONGVARCHAR
51+
* NLONGVARCHAR
52+
* Binary Data Types
53+
* VARBINARY
54+
2155
## Getting Started ##
2256

2357
Imagine ``1,000,000`` Persons should be inserted into an SQL Server database.
@@ -35,7 +69,7 @@ Bulk Inserting ``1,000,000``entities to a SQL Server 2016 database took ``5`` Se
3569
The domain model could be the ``Person`` class with a First Name, Last Name and a birth date.
3670

3771
```java
38-
// Copyright (c) Philipp Wagner. All rights reserved.
72+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
3973
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4074

4175
package de.bytefish.jsqlserverbulkinsert.test.model;
@@ -85,7 +119,7 @@ To bulk insert the ``Person`` data to a SQL Server database it is important to k
85119
between the Java Object and the Database Columns:
86120

87121
```java
88-
// Copyright (c) Philipp Wagner. All rights reserved.
122+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
89123
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
90124

91125
package de.bytefish.jsqlserverbulkinsert.test.integration;
@@ -98,16 +132,17 @@ public class PersonMapping extends AbstractMapping<Person> {
98132
public PersonMapping() {
99133
super("dbo", "UnitTest");
100134

101-
mapString("FirstName", Person::getFirstName);
102-
mapString("LastName", Person::getLastName);
135+
mapNvarchar("FirstName", Person::getFirstName);
136+
mapNvarchar("LastName", Person::getLastName);
103137
mapDate("BirthDate", Person::getBirthDate);
104138
}
105139
}
106140
```
107141

108142
### Construct and use the SqlServerBulkInsert ###
109143

110-
The ``AbstractMapping`` is used to instantiate a ``SqlServerBulkInsert``, which provides a ``saveAll`` method to store a given stream of data.
144+
The ``AbstractMapping`` is used to instantiate a ``SqlServerBulkInsert``, which provides
145+
a ``saveAll`` method to store a given stream of data.
111146

112147
```java
113148
// Instantiate the SqlServerBulkInsert class:
@@ -119,15 +154,14 @@ bulkInsert.saveAll(connection, persons.stream());
119154
And the full Integration Test:
120155

121156
```java
122-
// Copyright (c) Philipp Wagner. All rights reserved.
157+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
123158
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
124159

125160
package de.bytefish.jsqlserverbulkinsert.test.integration;
126161

127-
import de.bytefish.jsqlserverbulkinsert.mapping.AbstractMapping;
128-
import de.bytefish.jsqlserverbulkinsert.test.model.Person;
129162
import de.bytefish.jsqlserverbulkinsert.SqlServerBulkInsert;
130163
import de.bytefish.jsqlserverbulkinsert.test.base.TransactionalTestBase;
164+
import de.bytefish.jsqlserverbulkinsert.test.model.Person;
131165
import de.bytefish.jsqlserverbulkinsert.test.utils.MeasurementUtils;
132166
import org.junit.Assert;
133167
import org.junit.Test;

0 commit comments

Comments
 (0)