Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG #

## 7.0.1 ##

* Re-added support for primtive data types, but used method names:
* ``AbstractMapping#mapBooleanPrimitive``
* ``AbstractMapping#mapBytePrimitive``
* ``AbstractMapping#mapShortPrimtive``
* ``AbstractMapping#mapIntegerPrimitive``
* ``AbstractMapping#mapFloatPrimitive``
* ``AbstractMapping#mapDoublePrimitive``

## 7.0.0 ##

* The ``JpaMapping<>`` has been dropped from the library.
Expand Down
2 changes: 1 addition & 1 deletion PgBulkInsert/pgbulkinsert-bulkprocessor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>de.bytefish.pgbulkinsert</groupId>
<artifactId>pgbulkinsert-parent</artifactId>
<version>7.0.0</version>
<version>7.0.1</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion PgBulkInsert/pgbulkinsert-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>de.bytefish.pgbulkinsert</groupId>
<artifactId>pgbulkinsert-parent</artifactId>
<version>7.0.0</version>
<version>7.0.1</version>
<relativePath>..</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package de.bytefish.pgbulkinsert.function;

@FunctionalInterface
public interface ToBooleanFunction<T> {

/**
* Applies this function to the given argument.
*
* @param value the function argument
* @return the function result
*/
boolean applyAsBoolean(T value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package de.bytefish.pgbulkinsert.function;

@FunctionalInterface
public interface ToFloatFunction<T> {

/**
* Applies this function to the given argument.
*
* @param value the function argument
* @return the function result
*/
float applyAsFloat(T value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package de.bytefish.pgbulkinsert.mapping;

import de.bytefish.pgbulkinsert.function.ToBooleanFunction;
import de.bytefish.pgbulkinsert.function.ToFloatFunction;
import de.bytefish.pgbulkinsert.model.ColumnDefinition;
import de.bytefish.pgbulkinsert.model.TableDefinition;
import de.bytefish.pgbulkinsert.pgsql.PgBinaryWriter;
Expand All @@ -20,10 +22,7 @@
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.*;
import java.util.stream.Collectors;

public abstract class AbstractMapping<TEntity> {
Expand Down Expand Up @@ -81,11 +80,17 @@ protected void mapBoolean(String columnName, Function<TEntity, Boolean> property
map(columnName, DataType.Boolean, propertyGetter);
}

protected void mapBooleanPrimitive(String columnName, ToBooleanFunction<TEntity> propertyGetter) {
addColumn(columnName, (binaryWriter, entity) -> {
binaryWriter.writeBoolean(propertyGetter.applyAsBoolean(entity));
});
}

protected void mapByte(String columnName, Function<TEntity, Number> propertyGetter) {
map(columnName, DataType.Char, propertyGetter);
}

protected void mapByte(String columnName, ToIntFunction<TEntity> propertyGetter) {
protected void mapBytePrimitive(String columnName, ToIntFunction<TEntity> propertyGetter) {
addColumn(columnName, (binaryWriter, entity) -> {
binaryWriter.writeByte(propertyGetter.applyAsInt(entity));
});
Expand All @@ -95,7 +100,7 @@ protected void mapShort(String columnName, Function<TEntity, Number> propertyGet
map(columnName, DataType.Int2, propertyGetter);
}

protected void mapShort(String columnName, ToIntFunction<TEntity> propertyGetter) {
protected void mapShortPrimitive(String columnName, ToIntFunction<TEntity> propertyGetter) {
addColumn(columnName, (binaryWriter, entity) -> {
binaryWriter.writeShort(propertyGetter.applyAsInt(entity));
});
Expand All @@ -105,7 +110,7 @@ protected void mapInteger(String columnName, Function<TEntity, Number> propertyG
map(columnName, DataType.Int4, propertyGetter);
}

protected void mapInteger(String columnName, ToIntFunction<TEntity> propertyGetter) {
protected void mapIntegerPrimitive(String columnName, ToIntFunction<TEntity> propertyGetter) {
addColumn(columnName, (binaryWriter, entity) -> {
binaryWriter.writeInt(propertyGetter.applyAsInt(entity));
});
Expand All @@ -119,15 +124,27 @@ protected void mapLong(String columnName, Function<TEntity, Number> propertyGett
map(columnName, DataType.Int8, propertyGetter);
}

protected void mapLongPrimitive(String columnName, ToLongFunction<TEntity> propertyGetter) {
addColumn(columnName, (binaryWriter, entity) -> {
binaryWriter.writeLong(propertyGetter.applyAsLong(entity));
});
}

protected void mapFloat(String columnName, Function<TEntity, Number> propertyGetter) {
map(columnName, DataType.SinglePrecision, propertyGetter);
}

protected void mapFloatPrimitive(String columnName, ToFloatFunction<TEntity> propertyGetter) {
addColumn(columnName, (binaryWriter, entity) -> {
binaryWriter.writeFloat(propertyGetter.applyAsFloat(entity));
});
}

protected void mapDouble(String columnName, Function<TEntity, Number> propertyGetter) {
map(columnName, DataType.DoublePrecision, propertyGetter);
}

protected void mapDouble(String columnName, ToDoubleFunction<TEntity> propertyGetter) {
protected void mapDoublePrimitive(String columnName, ToDoubleFunction<TEntity> propertyGetter) {
addColumn(columnName, (binaryWriter, entity) -> {
binaryWriter.writeDouble(propertyGetter.applyAsDouble(entity));
});
Expand Down
2 changes: 1 addition & 1 deletion PgBulkInsert/pgbulkinsert-rowwriter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>de.bytefish.pgbulkinsert</groupId>
<artifactId>pgbulkinsert-parent</artifactId>
<version>7.0.0</version>
<version>7.0.1</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion PgBulkInsert/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>de.bytefish.pgbulkinsert</groupId>
<artifactId>pgbulkinsert-parent</artifactId>
<packaging>pom</packaging>
<version>7.0.0</version>
<version>7.0.1</version>
<name>pgbulkinsert</name>
<description>PgBulkInsert is a Java library for Bulk Inserts with PostgreSQL.</description>
<url>http://www.github.com/bytefish/PgBulkInsert</url>
Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ You can add the following dependencies to your pom.xml to include [PgBulkInsert]
<dependency>
<groupId>de.bytefish.pgbulkinsert</groupId>
<artifactId>pgbulkinsert-core</artifactId>
<version>7.0.0</version>
<version>7.0.1</version>
</dependency>

<dependency>
<groupId>de.bytefish.pgbulkinsert</groupId>
<artifactId>pgbulkinsert-rowwriter</artifactId>
<version>7.0.0</version>
<version>7.0.1</version>
</dependency>
```

Expand All @@ -47,14 +47,14 @@ If you are working with Java8 you have to add a classifier ``jdk8`` to the depen
<dependency>
<groupId>de.bytefish.pgbulkinsert</groupId>
<artifactId>pgbulkinsert-core</artifactId>
<version>7.0.0</version>
<version>7.0.1</version>
<classifier>jdk8</classifier>
</dependency>

<dependency>
<groupId>de.bytefish.pgbulkinsert</groupId>
<artifactId>pgbulkinsert-rowwriter</artifactId>
<version>7.0.0</version>
<version>7.0.1</version>
<classifier>jdk8</classifier>
</dependency>
```
Expand Down Expand Up @@ -334,6 +334,19 @@ private List<Person> getPersonList(int num) {

## FAQ ##

### How can I write Primitive Types (``boolean``, ``float``, ``double``)? ###

By default methods like ``mapBoolean`` map the boxed type ``Boolean``, ``Integer``, ``Long``. This might be problematic
if you need to squeeze out the last seconds when doing bulk inserts, see Issue:

* [https://github.com/PgBulkInsert/PgBulkInsert/issues/93](https://github.com/PgBulkInsert/PgBulkInsert/issues/93)

So for every data type that also has a primitive type, you can add a "Primitive" suffix to the method name like:

* ```mapBooleanPrimitive``

This will use the primitive type and prevent boxing and unboxing of values.

### How can I write a ``java.sql.Timestamp``? ###

You probably have Java classes with a ``java.sql.Timestamp`` in your application. Now if you use the ``AbstractMapping`` or a ``SimpleRowWriter`` it expects a ``LocalDateTime``. Here is how to map a ``java.sql.Timestamp``.
Expand Down