44package de .bytefish .jsqlserverbulkinsert .mapping ;
55
66import de .bytefish .jsqlserverbulkinsert .converters .*;
7- import de .bytefish .jsqlserverbulkinsert .model .ColumnDefinition ;
8- import de .bytefish .jsqlserverbulkinsert .model .ColumnMetaData ;
9- import de .bytefish .jsqlserverbulkinsert .model .IColumnDefinition ;
10- import de .bytefish .jsqlserverbulkinsert .model .TableDefinition ;
7+ import de .bytefish .jsqlserverbulkinsert .functional .ToBooleanFunction ;
8+ import de .bytefish .jsqlserverbulkinsert .functional .ToFloatFunction ;
9+ import de .bytefish .jsqlserverbulkinsert .model .*;
1110
1211import java .math .BigDecimal ;
1312import java .math .BigInteger ;
2120import java .util .List ;
2221import java .util .Optional ;
2322import java .util .function .Function ;
23+ import java .util .function .ToDoubleFunction ;
2424import java .util .function .ToIntFunction ;
2525import java .util .function .ToLongFunction ;
2626
@@ -45,9 +45,9 @@ protected void mapBoolean(String columnName, Function<TEntity, Boolean> property
4545 mapProperty (columnName , Types .BIT , propertyGetter , new BooleanConverter ());
4646 }
4747
48- // protected void mapBoolean(String columnName, ToIntFunction <TEntity> propertyGetter) {
49- // mapProperty(columnName, Types.BIT, (entity) -> (byte) propertyGetter.applyAsInt (entity), );
50- // }
48+ protected void mapBoolean (String columnName , ToBooleanFunction <TEntity > propertyGetter ) {
49+ mapProperty (columnName , Types .BIT , (entity ) -> propertyGetter .applyAsBoolean (entity ), new BooleanConverter () );
50+ }
5151
5252 // region Text Functions
5353
@@ -92,10 +92,14 @@ protected void mapInteger(String columnName, Function<TEntity, Integer> property
9292 mapProperty (columnName , Types .INTEGER , 0 , 0 , isAutoIncrement , propertyGetter , new IntegerConverter ());
9393 }
9494
95- // protected void mapInteger(String columnName, ToIntFunction<TEntity> propertyGetter, boolean isAutoIncrement)
96- // {
97- // addColumn(columnName, Types.INTEGER, isAutoIncrement, (entity) -> propertyGetter.applyAsInt(entity));
98- // }
95+ protected void mapInteger (String columnName , ToIntFunction <TEntity > propertyGetter )
96+ {
97+ mapProperty (columnName , Types .INTEGER , (entity ) -> propertyGetter .applyAsInt (entity ), new IntegerConverter ());
98+ }
99+
100+ protected void mapInteger (String columnName , ToIntFunction <TEntity > propertyGetter , boolean isAutoIncrement ) {
101+ mapProperty (columnName , Types .INTEGER , (entity ) -> propertyGetter .applyAsInt (entity ), new IntegerConverter ());
102+ }
99103
100104 protected void mapLong (String columnName , Function <TEntity , Long > propertyGetter ) {
101105 mapProperty (columnName , Types .BIGINT , propertyGetter , new LongConverter ());
@@ -105,34 +109,42 @@ protected void mapLong(String columnName, Function<TEntity, Long> propertyGetter
105109 mapProperty (columnName , Types .BIGINT , 0 , 0 , isAutoIncrement , propertyGetter , new LongConverter ());
106110 }
107111
108- // protected void mapLong(String columnName, ToLongFunction<TEntity> propertyGetter, boolean isAutoIncrement) {
109- // addColumn(columnName, Types.BIGINT, isAutoIncrement, (entity) -> propertyGetter.applyAsLong(entity));
110- // }
112+ protected void mapLong (String columnName , ToLongFunction <TEntity > propertyGetter ) {
113+ mapProperty (columnName , Types .BIGINT , (entity ) -> propertyGetter .applyAsLong (entity ), new LongConverter ());
114+ }
115+
116+ protected void mapLong (String columnName , ToLongFunction <TEntity > propertyGetter , boolean isAutoIncrement ) {
117+ mapProperty (columnName , Types .BIGINT , 0 , 0 , isAutoIncrement , (entity ) -> propertyGetter .applyAsLong (entity ), new LongConverter ());
118+ }
111119
112120 protected void mapNumeric (String columnName , int precision , int scale , Function <TEntity , BigDecimal > propertyGetter ) {
113121 mapProperty (columnName , Types .NUMERIC , precision , scale , false , propertyGetter , new BigDecimalConverter (scale ));
114122 }
115123
116- protected void mapDecimal (String columnName , int precision , int scale , Function <TEntity , BigDecimal > propertyGetter )
117- {
124+ protected void mapDecimal (String columnName , int precision , int scale , Function <TEntity , BigDecimal > propertyGetter ) {
118125 mapProperty (columnName , Types .DECIMAL , precision , scale , false , propertyGetter , new BigDecimalConverter (scale ));
119126 }
120127
121- protected void mapReal (String columnName , Function <TEntity , Float > propertyGetter )
122- {
128+ protected void mapReal (String columnName , Function <TEntity , Float > propertyGetter ) {
123129 mapProperty (columnName , Types .REAL , propertyGetter , new FloatConverter ());
124130 }
125131
126- protected void mapBigInt (String columnName , Function <TEntity , BigInteger > propertyGetter ) {
132+ protected void mapReal (String columnName , ToFloatFunction <TEntity > propertyGetter ) {
133+ mapProperty (columnName , Types .REAL , (entity ) -> propertyGetter .applyAsFloat (entity ), new FloatConverter ());
134+ }
127135
136+ protected void mapBigInt (String columnName , Function <TEntity , BigInteger > propertyGetter ) {
128137 mapProperty (columnName , Types .BIGINT , propertyGetter , new BigIntegerConverter ());
129138 }
130139
131- protected void mapDouble (String columnName , Function <TEntity , Double > propertyGetter )
132- {
140+ protected void mapDouble (String columnName , Function <TEntity , Double > propertyGetter ) {
133141 mapProperty (columnName , Types .DOUBLE , propertyGetter , new DoubleConverter ());
134142 }
135143
144+ protected void mapDouble (String columnName , ToDoubleFunction <TEntity > propertyGetter ) {
145+ mapProperty (columnName , Types .DOUBLE , (entity ) -> propertyGetter .applyAsDouble (entity ), new DoubleConverter ());
146+ }
147+
136148 // endregion
137149
138150 // region Time Functions
@@ -153,6 +165,15 @@ protected void mapDateTime(String columnName, Function<TEntity, Timestamp> prope
153165 protected void mapLocalDateTime (String columnName , Function <TEntity , LocalDateTime > propertyGetter ) {
154166 mapProperty (columnName , Types .TIMESTAMP , propertyGetter , new LocalDateTimeConverter ());
155167 }
168+
169+ protected void mapTimeWithTimeZone (String columnName , Function <TEntity , OffsetTime > propertyGetter ) {
170+ mapProperty (columnName , SqlServerTypes .TimeWithTimeZone , propertyGetter , new OffsetTimeConverter ());
171+ }
172+
173+ protected void mapDateTimeWithTimeZone (String columnName , Function <TEntity , OffsetDateTime > propertyGetter ) {
174+ mapProperty (columnName , SqlServerTypes .DateTimeWithTimeZone , propertyGetter , new OffsetDateTimeConverter ());
175+ }
176+
156177//
157178// protected void mapUTCNano(String dateColumnName, String timeColumnName, Function<TEntity, Long> propertyGetter) {
158179//
@@ -208,14 +229,6 @@ protected void mapLocalDateTime(String columnName, Function<TEntity, LocalDateTi
208229// }
209230
210231
211- protected void mapTimeWithTimeZone (String columnName , Function <TEntity , OffsetTime > propertyGetter ) {
212- mapProperty (columnName , 2013 , propertyGetter , new OffsetTimeConverter ());
213- }
214-
215- protected void mapDateTimeWithTimeZone (String columnName , Function <TEntity , OffsetDateTime > propertyGetter ) {
216- mapProperty (columnName , 2014 , propertyGetter , new OffsetDateTimeConverter ());
217- }
218-
219232 // endregion
220233
221234 // region Binary
@@ -226,7 +239,7 @@ protected void mapVarBinary(String columnName, int maxLength, Function<TEntity,
226239
227240 // endregion
228241
229- protected <TProperty > void mapProperty (String name , int type , Function <TEntity , TProperty > propertyGetter , IConverter <TProperty > converter )
242+ public <TProperty > void mapProperty (String name , int type , Function <TEntity , TProperty > propertyGetter , IConverter <TProperty > converter )
230243 {
231244 // Create the current Column Meta Data:
232245 ColumnMetaData columnMetaData = new ColumnMetaData (name , type );
@@ -235,7 +248,7 @@ protected <TProperty> void mapProperty(String name, int type, Function<TEntity,
235248 addColumn (columnMetaData , propertyGetter , converter );
236249 }
237250
238- protected <TProperty > void mapProperty (String name , int type , int precision , int scale , boolean isAutoIncrement , Function <TEntity , TProperty > propertyGetter , IConverter <TProperty > converter )
251+ public <TProperty > void mapProperty (String name , int type , int precision , int scale , boolean isAutoIncrement , Function <TEntity , TProperty > propertyGetter , IConverter <TProperty > converter )
239252 {
240253 // Create the current Column Meta Data:
241254 ColumnMetaData columnMetaData = new ColumnMetaData (name , type , precision , scale , isAutoIncrement );
@@ -244,7 +257,7 @@ protected <TProperty> void mapProperty(String name, int type, int precision, int
244257 addColumn (columnMetaData , propertyGetter , converter );
245258 }
246259
247- private <TProperty > void addColumn (ColumnMetaData columnMetaData , Function <TEntity , TProperty > propertyGetter , IConverter <TProperty > converter )
260+ public <TProperty > void addColumn (ColumnMetaData columnMetaData , Function <TEntity , TProperty > propertyGetter , IConverter <TProperty > converter )
248261 {
249262 // Add a new Column with the Meta Data and Property Getter:
250263 ColumnDefinition <TEntity , TProperty > columnDefinition = new ColumnDefinition <>(columnMetaData , propertyGetter , converter );
0 commit comments