Skip to content

Commit fa9a46a

Browse files
committed
Merge pull request #28 from akushsky/master
Add code for processing UUID as plain function parameter.
2 parents 062e244 + 267fa7b commit fa9a46a

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/main/java/de/zalando/sprocwrapper/proxy/OtherStoredProcedureParameter.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.sql.Connection;
66
import java.sql.SQLException;
7+
import java.util.UUID;
78

89
import org.postgresql.util.PGobject;
910

@@ -46,6 +47,18 @@ public Object mapParam(final Object value, final Connection connection) {
4647
}
4748

4849
result = pgobj;
50+
} else if (clazz.isAssignableFrom(UUID.class)) {
51+
final PGobject pgobj = new PGobject();
52+
pgobj.setType(typeName);
53+
try {
54+
pgobj.setValue(value.toString());
55+
} catch (SQLException ex) {
56+
if (sensitive) {
57+
LOG.error("Failed to set PG object value (sensitive parameter, stacktrace hidden)");
58+
} else {
59+
LOG.error("Failed to set PG object value", ex);
60+
}
61+
}
4962
} else {
5063
try {
5164
result = PgTypeHelper.asPGobject(value, typeName, connection);

src/main/java/de/zalando/typemapper/postgres/PgTypeHelper.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,7 @@
88
import java.sql.Timestamp;
99
import java.sql.Types;
1010

11-
import java.util.ArrayList;
12-
import java.util.Arrays;
13-
import java.util.Collection;
14-
import java.util.Collections;
15-
import java.util.Comparator;
16-
import java.util.Date;
17-
import java.util.HashMap;
18-
import java.util.List;
19-
import java.util.Locale;
20-
import java.util.Map;
21-
import java.util.TreeMap;
11+
import java.util.*;
2212

2313
import javax.persistence.Column;
2414

@@ -96,7 +86,7 @@ public class PgTypeHelper {
9686
m.put("double precision", "float8");
9787
m.put("boolean", "bool");
9888
m.put("decimal", "numeric");
99-
m.put("character verrying", "varchar");
89+
m.put("character varying", "varchar");
10090
m.put("char", "bpchar");
10191
m.put("character", "bpchar");
10292
pgGenericTypeNameAliasMap = Collections.unmodifiableMap(m);
@@ -149,6 +139,7 @@ public static final int getSQLType(final String typeName) {
149139
m.put(java.sql.Date.class, "timestamp");
150140
m.put(java.sql.Timestamp.class, "timestamp");
151141
m.put(java.sql.Time.class, "timestamp");
142+
m.put(java.util.UUID.class, "uuid");
152143
javaGenericClassToPgTypeNameMap = Collections.unmodifiableMap(m);
153144
}
154145

0 commit comments

Comments
 (0)