Skip to content

Commit 1678111

Browse files
committed
Fixed error when custom database type inherited from enum converts to VARCHAR
1 parent a385e6b commit 1678111

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
package de.zalando.sprocwrapper.proxy;
22

33
import java.lang.reflect.Method;
4-
54
import java.sql.Connection;
65
import java.sql.SQLException;
76
import java.util.UUID;
87

98
import org.postgresql.util.PGobject;
10-
119
import org.slf4j.Logger;
1210
import org.slf4j.LoggerFactory;
1311

12+
1413
import de.zalando.typemapper.postgres.PgTypeHelper;
1514

1615
/**
17-
* @author jmussler
16+
* @author jmussler
1817
*/
1918
class OtherStoredProcedureParameter extends StoredProcedureParameter {
2019
private static final Logger LOG = LoggerFactory.getLogger(OtherStoredProcedureParameter.class);
2120

2221
public OtherStoredProcedureParameter(final Class<?> clazz, final Method m, final String typeName, final int sqlType,
23-
final int javaPosition, final boolean sensitive) {
22+
final int javaPosition, final boolean sensitive) {
2423
super(clazz, m, typeName, sqlType, javaPosition, sensitive);
2524
}
2625

2726
@Override
2827
public Object mapParam(final Object value, final Connection connection) {
2928
if (value == null) {
29+
if (clazz.isEnum()) {
30+
/*
31+
* In situation when there is null value passed as an argument and
32+
* argument type maps to custom database type which inherited from ENUM
33+
* sql type "OTHER" will fallback to sql type "VARCHAR" what will cause an exception
34+
* "No function matches the given name and argument types. You might need to add explicit type casts."
35+
* That happens because SP expects custom type but not VARCHAR
36+
*
37+
*/
38+
final PGobject pgobj = new PGobject();
39+
pgobj.setType(typeName);
40+
return pgobj;
41+
}
3042
return null;
3143
}
3244

src/test/java/de/zalando/sprocwrapper/SimpleIT.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,39 @@
11
package de.zalando.sprocwrapper;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertFalse;
5-
import static org.junit.Assert.assertNotNull;
6-
import static org.junit.Assert.assertNull;
7-
import static org.junit.Assert.assertTrue;
8-
93
import java.math.BigDecimal;
10-
114
import java.sql.Connection;
125
import java.sql.ResultSet;
136
import java.sql.SQLException;
147
import java.sql.Statement;
158
import java.sql.Timestamp;
16-
179
import java.text.SimpleDateFormat;
18-
1910
import java.util.ArrayList;
2011
import java.util.Arrays;
2112
import java.util.Collections;
2213
import java.util.Date;
2314
import java.util.HashMap;
2415
import java.util.List;
25-
2616
import javax.sql.DataSource;
27-
2817
import javax.validation.ConstraintViolationException;
2918

19+
import com.google.common.collect.Lists;
20+
import com.google.common.collect.Sets;
3021
import org.joda.time.DateTime;
31-
3222
import org.junit.Assert;
3323
import org.junit.Ignore;
3424
import org.junit.Test;
35-
3625
import org.junit.runner.RunWith;
37-
3826
import org.springframework.beans.factory.annotation.Autowired;
3927
import org.springframework.beans.factory.annotation.Qualifier;
40-
4128
import org.springframework.jdbc.core.JdbcTemplate;
42-
4329
import org.springframework.test.context.ContextConfiguration;
4430
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31+
import static org.junit.Assert.assertEquals;
32+
import static org.junit.Assert.assertFalse;
33+
import static org.junit.Assert.assertNotNull;
34+
import static org.junit.Assert.assertNull;
35+
import static org.junit.Assert.assertTrue;
4536

46-
import com.google.common.collect.Lists;
47-
import com.google.common.collect.Sets;
4837

4938
import de.zalando.sprocwrapper.example.AddressPojo;
5039
import de.zalando.sprocwrapper.example.Example1DomainObject1;
@@ -77,7 +66,6 @@
7766
import de.zalando.sprocwrapper.example.TestInheritanceChild;
7867
import de.zalando.sprocwrapper.example.WrapperLookupSchema;
7968
import de.zalando.sprocwrapper.example.WrapperOptionalLookupType;
80-
8169
import de.zalando.typemapper.parser.DateTimeUtil;
8270

8371
@RunWith(SpringJUnit4ClassRunner.class)
@@ -1088,4 +1076,14 @@ public void testSQLUpdate() {
10881076
assertTrue(l1.size() == 1);
10891077
assertTrue(l2.size() == 0);
10901078
}
1079+
1080+
@Test
1081+
public void testNullComplexParam() throws Exception {
1082+
exampleSProcService.createOrder(null);
1083+
}
1084+
1085+
@Test
1086+
public void testNullEnumParam() {
1087+
exampleSProcService.useEnumParam(null);
1088+
}
10911089
}

0 commit comments

Comments
 (0)