Skip to content

Commit 5889ab6

Browse files
authored
Merge pull request #11 from bytefish/2.0-api
2 parents 2c90282 + 4cb0e42 commit 5889ab6

57 files changed

Lines changed: 691 additions & 285 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

JSqlServerBulkInsert/jsqlserverbulkinsert.iml

Lines changed: 0 additions & 2 deletions
This file was deleted.

JSqlServerBulkInsert/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>de.bytefish</groupId>
99
<artifactId>jsqlserverbulkinsert</artifactId>
10-
<version>1.5</version>
10+
<version>2.0</version>
1111
<name>jsqlserverbulkinsert</name>
1212
<description>JSqlServerBulkInsert is a Java library for Bulk Inserts to the SQL Server.</description>
1313
<url>http://www.github.com/bytefish/JSqlServerBulkInsert</url>
@@ -54,6 +54,11 @@
5454
</configuration>
5555
</plugin>
5656
</plugins>
57+
<testResources>
58+
<testResource>
59+
<directory>src/test/resources</directory>
60+
</testResource>
61+
</testResources>
5762
</build>
5863

5964
<properties>
@@ -155,7 +160,7 @@
155160
<dependency>
156161
<groupId>com.microsoft.sqlserver</groupId>
157162
<artifactId>mssql-jdbc</artifactId>
158-
<version>6.4.0.jre8</version>
163+
<version>7.2.2.jre8</version>
159164
</dependency>
160165

161166
<dependency>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Philipp Wagner. All rights reserved.
1+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
package de.bytefish.jsqlserverbulkinsert;

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Philipp Wagner. All rights reserved.
1+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
package de.bytefish.jsqlserverbulkinsert;
@@ -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
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
package de.bytefish.jsqlserverbulkinsert.converters;
5+
6+
public abstract class BaseConverter<TSourceType> implements IConverter<TSourceType> {
7+
8+
public Object convert(TSourceType value) {
9+
if(value == null) {
10+
return null;
11+
}
12+
13+
return internalConvert(value);
14+
}
15+
16+
public abstract Object internalConvert(TSourceType value);
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
package de.bytefish.jsqlserverbulkinsert.converters;
5+
6+
import java.math.BigDecimal;
7+
import java.math.RoundingMode;
8+
9+
public class BigDecimalConverter extends BaseConverter<BigDecimal> {
10+
11+
private final int scale;
12+
private final RoundingMode roundingMode;
13+
14+
public BigDecimalConverter(int scale, RoundingMode roundingMode) {
15+
this.roundingMode = roundingMode;
16+
this.scale = scale;
17+
}
18+
19+
@Override
20+
public Object internalConvert(BigDecimal value) {
21+
return value.setScale(scale, BigDecimal.ROUND_HALF_UP);
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
package de.bytefish.jsqlserverbulkinsert.converters;
5+
6+
import java.math.BigInteger;
7+
8+
public class BigIntegerConverter extends BaseConverter<BigInteger> {
9+
@Override
10+
public Object internalConvert(BigInteger value) {
11+
return value.longValueExact();
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
package de.bytefish.jsqlserverbulkinsert.converters;
5+
6+
public interface IConverter<TSourceType> {
7+
8+
Object convert(TSourceType value);
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package de.bytefish.jsqlserverbulkinsert.converters;
2+
3+
public class IdentityConverter<TPropertyType> extends BaseConverter<TPropertyType> {
4+
@Override
5+
public Object internalConvert(TPropertyType value) {
6+
return value;
7+
}
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Philipp Wagner and Victor Lee. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
package de.bytefish.jsqlserverbulkinsert.converters;
5+
6+
import java.sql.Timestamp;
7+
import java.time.Instant;
8+
9+
public class InstantConverter extends BaseConverter<Instant> {
10+
11+
@Override
12+
public Object internalConvert(Instant value) {
13+
Timestamp castedResult = new Timestamp(value.toEpochMilli());
14+
15+
// Round to the nearest 100 nanoseconds, the precision that SQL server can handle:
16+
castedResult.setNanos((value.getNano()/100)*100);
17+
18+
return castedResult;
19+
};
20+
21+
}

0 commit comments

Comments
 (0)