Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimal support for external extensions to pgjdbc datatypes #181

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,21 @@
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public abstract class BinaryDecoder implements Type.Codec.Decoder {

abstract Object decode(Type type, Short typeLength, Integer typeModifier, ByteBuf buffer, Context context) throws IOException;
protected abstract Object decode(Type type, Short typeLength, Integer typeModifier, ByteBuf buffer, Context context) throws IOException;

@Override
public Object decode(Type type, Short typeLength, Integer typeModifier, Object buffer, Context context) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

public abstract class BinaryEncoder implements Type.Codec.Encoder {

abstract void encode(Type type, ByteBuf buffer, Object val, Context context) throws IOException;
protected abstract void encode(Type type, ByteBuf buffer, Object val, Context context) throws IOException;

@Override
public void encode(Type type, Object buffer, Object value, Context context) throws IOException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/impossibl/postgres/system/procs/Dates.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public Class<?> getOutputType() {
}

@Override
Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {
protected Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {

Map<String, Object> pieces = new HashMap<>();

Expand All @@ -228,7 +228,7 @@ public Class<?> getInputType() {
}

@Override
void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {
protected void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {

String strVal = context.getDateFormatter().getPrinter().format((Instant) val);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public abstract class TextDecoder implements Type.Codec.Decoder {

abstract Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException;
protected abstract Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException;

@Override
public Object decode(Type type, Short typeLength, Integer typeModifier, Object buffer, Context context) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public abstract class TextEncoder implements Type.Codec.Encoder {

abstract void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException;
protected abstract void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException;

@Override
public void encode(Type type, Object buffer, Object value, Context context) throws IOException {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/impossibl/postgres/system/procs/Tids.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Class<?> getOutputType() {
}

@Override
Object decode(Type type, Short typeLength, Integer typeModifier, ByteBuf buffer, Context context) throws IOException {
protected Object decode(Type type, Short typeLength, Integer typeModifier, ByteBuf buffer, Context context) throws IOException {

int length = buffer.readInt();
if (length == -1) {
Expand Down Expand Up @@ -89,7 +89,7 @@ public Class<?> getInputType() {
}

@Override
void encode(Type type, ByteBuf buffer, Object val, Context context) throws IOException {
protected void encode(Type type, ByteBuf buffer, Object val, Context context) throws IOException {

if (val == null) {

Expand Down Expand Up @@ -126,7 +126,7 @@ public Class<?> getOutputType() {
}

@Override
Tid decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {
protected Tid decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {

String[] items = buffer.subSequence(1, buffer.length() - 1).toString().split(",");

Expand All @@ -151,7 +151,7 @@ public Class<?> getInputType() {
}

@Override
void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {
protected void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {

Tid tid = (Tid) val;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Class<?> getOutputType() {
}

@Override
Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {
protected Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {

Map<String, Object> pieces = new HashMap<>();

Expand All @@ -169,7 +169,7 @@ public Class<?> getInputType() {
}

@Override
void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {
protected void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {

String strVal = context.getTimeFormatter().getPrinter().format((Instant) val);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public Class<?> getOutputType() {
}

@Override
Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {
protected Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {

Map<String, Object> pieces = new HashMap<>();

Expand All @@ -159,7 +159,7 @@ public Class<?> getInputType() {
}

@Override
void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {
protected void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {

String strVal = context.getTimeFormatter().getPrinter().format((Instant) val);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Class<?> getOutputType() {
}

@Override
Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {
protected Object decode(Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Context context) throws IOException {

Map<String, Object> pieces = new HashMap<>();

Expand Down Expand Up @@ -220,7 +220,7 @@ public Class<?> getInputType() {
}

@Override
void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {
protected void encode(Type type, StringBuilder buffer, Object val, Context context) throws IOException {

String strVal = context.getTimestampFormatter().getPrinter().format((Instant) val);

Expand Down
14 changes: 9 additions & 5 deletions src/test/java/com/impossibl/postgres/jdbc/CodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
@RunWith(Parameterized.class)
public class CodecTest {

PGConnectionImpl conn;
String typeName;
Object value;
protected PGConnectionImpl conn;
protected String typeName;
protected Object value;

public CodecTest(String typeName, Object value) {
this.typeName = typeName;
Expand Down Expand Up @@ -340,7 +340,7 @@ private void assertStreamEquals(InputStream expected, InputStream actual) throws
assertArrayEquals(ByteStreams.toByteArray(expected), ByteStreams.toByteArray(actual));
}

interface Maker {
public interface Maker {
Object make(PGConnectionImpl conn) throws SQLException;
}

Expand Down Expand Up @@ -447,6 +447,10 @@ public Object make(PGConnectionImpl conn) throws SQLException {
{"tid", new PGRowId(new Tid(0, (short) 1))},
};

return expandDataTypesToStructsAndArrays(scalarTypesData);
}

public static Collection<Object[]> expandDataTypesToStructsAndArrays(Object[][] scalarTypesData) {
List<Object[]> data = new ArrayList<>();

//Combine entries with generated ones for array and composite testing
Expand Down Expand Up @@ -514,7 +518,7 @@ public Object make(PGConnectionImpl conn) throws SQLException {
return data;
}

static Map<String, String> typeCasts;
protected static Map<String, String> typeCasts;
static {
typeCasts = new HashMap<>();
typeCasts.put("bit", "bit(7)");
Expand Down