forked from pgjdbc/r2dbc-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding codecs for multiple java 8 data types - pgjdbcgh-591
- Loading branch information
1 parent
543f5cc
commit af5e770
Showing
16 changed files
with
1,056 additions
and
143 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/io/r2dbc/postgresql/codec/DayOfWeekCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.r2dbc.postgresql.codec; | ||
|
||
import io.netty.buffer.ByteBufAllocator; | ||
|
||
import java.time.DayOfWeek; | ||
|
||
final class DayOfWeekCodec extends IntegerCodecDelegate<DayOfWeek> { | ||
|
||
DayOfWeekCodec(ByteBufAllocator byteBufAllocator) { | ||
super(DayOfWeek.class, byteBufAllocator, DayOfWeek::getValue, DayOfWeek::of); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/io/r2dbc/postgresql/codec/IntegerCodecDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.r2dbc.postgresql.codec; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.ByteBufAllocator; | ||
import io.r2dbc.postgresql.client.EncodedParameter; | ||
import io.r2dbc.postgresql.message.Format; | ||
import io.r2dbc.postgresql.util.Assert; | ||
|
||
import java.util.function.Function; | ||
|
||
class IntegerCodecDelegate<T> extends AbstractCodec<T> { | ||
|
||
private final IntegerCodec delegate; | ||
private final Function<T, Integer> toIntegerConverter; | ||
private final Function<Integer, T> fromIntegerConverter; | ||
|
||
IntegerCodecDelegate(Class<T> type, ByteBufAllocator byteBufAllocator, Function<T,Integer> toIntegerConverter, Function<Integer, T> fromIntegerConverter) { | ||
super(type); | ||
this.delegate = new IntegerCodec(byteBufAllocator); | ||
this.toIntegerConverter = toIntegerConverter; | ||
this.fromIntegerConverter = fromIntegerConverter; | ||
} | ||
|
||
@Override | ||
boolean doCanDecode(PostgresqlObjectId type, Format format) { | ||
return delegate.doCanDecode(type, format); | ||
} | ||
|
||
@Override | ||
T doDecode(ByteBuf buffer, PostgresTypeIdentifier dataType, Format format, Class<? extends T> type) { | ||
final Integer number = delegate.doDecode(buffer, dataType, format, Integer.TYPE); | ||
return fromIntegerConverter.apply(number); | ||
} | ||
|
||
@Override | ||
EncodedParameter doEncode(T value) { | ||
Assert.requireNonNull(value, "value must not be null"); | ||
return delegate.doEncode(toIntegerConverter.apply(value)); | ||
} | ||
|
||
@Override | ||
EncodedParameter doEncode(T value, PostgresTypeIdentifier dataType) { | ||
Assert.requireNonNull(value, "value must not be null"); | ||
Assert.requireNonNull(dataType, "dataType must not be null"); | ||
return delegate.doEncode(toIntegerConverter.apply(value), dataType); | ||
} | ||
|
||
@Override | ||
public Iterable<? extends PostgresTypeIdentifier> getDataTypes() { | ||
return delegate.getDataTypes(); | ||
} | ||
|
||
@Override | ||
public EncodedParameter encodeNull() { | ||
return delegate.encodeNull(); | ||
} | ||
} |
Oops, something went wrong.