diff --git a/CHANGELOG.md b/CHANGELOG.md index ce80892..31db425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/PgBulkInsert/pgbulkinsert-bulkprocessor/pom.xml b/PgBulkInsert/pgbulkinsert-bulkprocessor/pom.xml index 02991e6..92864c9 100644 --- a/PgBulkInsert/pgbulkinsert-bulkprocessor/pom.xml +++ b/PgBulkInsert/pgbulkinsert-bulkprocessor/pom.xml @@ -8,7 +8,7 @@ de.bytefish.pgbulkinsert pgbulkinsert-parent - 7.0.0 + 7.0.1 .. diff --git a/PgBulkInsert/pgbulkinsert-core/pom.xml b/PgBulkInsert/pgbulkinsert-core/pom.xml index e857172..8ce2d27 100644 --- a/PgBulkInsert/pgbulkinsert-core/pom.xml +++ b/PgBulkInsert/pgbulkinsert-core/pom.xml @@ -8,7 +8,7 @@ de.bytefish.pgbulkinsert pgbulkinsert-parent - 7.0.0 + 7.0.1 .. diff --git a/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/function/ToBooleanFunction.java b/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/function/ToBooleanFunction.java new file mode 100644 index 0000000..3b34c96 --- /dev/null +++ b/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/function/ToBooleanFunction.java @@ -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 { + + /** + * Applies this function to the given argument. + * + * @param value the function argument + * @return the function result + */ + boolean applyAsBoolean(T value); +} \ No newline at end of file diff --git a/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/function/ToFloatFunction.java b/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/function/ToFloatFunction.java new file mode 100644 index 0000000..b061dff --- /dev/null +++ b/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/function/ToFloatFunction.java @@ -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 { + + /** + * Applies this function to the given argument. + * + * @param value the function argument + * @return the function result + */ + float applyAsFloat(T value); +} \ No newline at end of file diff --git a/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/mapping/AbstractMapping.java b/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/mapping/AbstractMapping.java index 9e257e1..25692df 100644 --- a/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/mapping/AbstractMapping.java +++ b/PgBulkInsert/pgbulkinsert-core/src/main/java/de/bytefish/pgbulkinsert/mapping/AbstractMapping.java @@ -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; @@ -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 { @@ -81,11 +80,17 @@ protected void mapBoolean(String columnName, Function property map(columnName, DataType.Boolean, propertyGetter); } + protected void mapBooleanPrimitive(String columnName, ToBooleanFunction propertyGetter) { + addColumn(columnName, (binaryWriter, entity) -> { + binaryWriter.writeBoolean(propertyGetter.applyAsBoolean(entity)); + }); + } + protected void mapByte(String columnName, Function propertyGetter) { map(columnName, DataType.Char, propertyGetter); } - protected void mapByte(String columnName, ToIntFunction propertyGetter) { + protected void mapBytePrimitive(String columnName, ToIntFunction propertyGetter) { addColumn(columnName, (binaryWriter, entity) -> { binaryWriter.writeByte(propertyGetter.applyAsInt(entity)); }); @@ -95,7 +100,7 @@ protected void mapShort(String columnName, Function propertyGet map(columnName, DataType.Int2, propertyGetter); } - protected void mapShort(String columnName, ToIntFunction propertyGetter) { + protected void mapShortPrimitive(String columnName, ToIntFunction propertyGetter) { addColumn(columnName, (binaryWriter, entity) -> { binaryWriter.writeShort(propertyGetter.applyAsInt(entity)); }); @@ -105,7 +110,7 @@ protected void mapInteger(String columnName, Function propertyG map(columnName, DataType.Int4, propertyGetter); } - protected void mapInteger(String columnName, ToIntFunction propertyGetter) { + protected void mapIntegerPrimitive(String columnName, ToIntFunction propertyGetter) { addColumn(columnName, (binaryWriter, entity) -> { binaryWriter.writeInt(propertyGetter.applyAsInt(entity)); }); @@ -119,15 +124,27 @@ protected void mapLong(String columnName, Function propertyGett map(columnName, DataType.Int8, propertyGetter); } + protected void mapLongPrimitive(String columnName, ToLongFunction propertyGetter) { + addColumn(columnName, (binaryWriter, entity) -> { + binaryWriter.writeLong(propertyGetter.applyAsLong(entity)); + }); + } + protected void mapFloat(String columnName, Function propertyGetter) { map(columnName, DataType.SinglePrecision, propertyGetter); } + protected void mapFloatPrimitive(String columnName, ToFloatFunction propertyGetter) { + addColumn(columnName, (binaryWriter, entity) -> { + binaryWriter.writeFloat(propertyGetter.applyAsFloat(entity)); + }); + } + protected void mapDouble(String columnName, Function propertyGetter) { map(columnName, DataType.DoublePrecision, propertyGetter); } - protected void mapDouble(String columnName, ToDoubleFunction propertyGetter) { + protected void mapDoublePrimitive(String columnName, ToDoubleFunction propertyGetter) { addColumn(columnName, (binaryWriter, entity) -> { binaryWriter.writeDouble(propertyGetter.applyAsDouble(entity)); }); diff --git a/PgBulkInsert/pgbulkinsert-rowwriter/pom.xml b/PgBulkInsert/pgbulkinsert-rowwriter/pom.xml index 35eee92..ef8a82c 100644 --- a/PgBulkInsert/pgbulkinsert-rowwriter/pom.xml +++ b/PgBulkInsert/pgbulkinsert-rowwriter/pom.xml @@ -8,7 +8,7 @@ de.bytefish.pgbulkinsert pgbulkinsert-parent - 7.0.0 + 7.0.1 .. diff --git a/PgBulkInsert/pom.xml b/PgBulkInsert/pom.xml index bade0f1..ec0ca35 100644 --- a/PgBulkInsert/pom.xml +++ b/PgBulkInsert/pom.xml @@ -7,7 +7,7 @@ de.bytefish.pgbulkinsert pgbulkinsert-parent pom - 7.0.0 + 7.0.1 pgbulkinsert PgBulkInsert is a Java library for Bulk Inserts with PostgreSQL. http://www.github.com/bytefish/PgBulkInsert diff --git a/README.md b/README.md index a19bf92..4559877 100644 --- a/README.md +++ b/README.md @@ -30,13 +30,13 @@ You can add the following dependencies to your pom.xml to include [PgBulkInsert] de.bytefish.pgbulkinsert pgbulkinsert-core - 7.0.0 + 7.0.1 de.bytefish.pgbulkinsert pgbulkinsert-rowwriter - 7.0.0 + 7.0.1 ``` @@ -47,14 +47,14 @@ If you are working with Java8 you have to add a classifier ``jdk8`` to the depen de.bytefish.pgbulkinsert pgbulkinsert-core - 7.0.0 + 7.0.1 jdk8 de.bytefish.pgbulkinsert pgbulkinsert-rowwriter - 7.0.0 + 7.0.1 jdk8 ``` @@ -334,6 +334,19 @@ private List 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``.