You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ka...@apache.org on 2019/01/29 21:37:52 UTC

[metamodel] branch master updated: As per #208: Fix PostgreSQL native type being null

This is an automated email from the ASF dual-hosted git repository.

kaspersor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metamodel.git


The following commit(s) were added to refs/heads/master by this push:
     new eea52ad  As per #208: Fix PostgreSQL native type being null
eea52ad is described below

commit eea52adfc39c00984d1ca47613a0b52acf65e752
Author: lixiaobao <li...@gmail.com>
AuthorDate: Tue Jan 29 13:37:29 2019 -0800

    As per #208: Fix PostgreSQL native type being null
---
 .../jdbc/dialects/PostgresqlQueryRewriter.java     | 44 ++++++++++++----------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
index 7fe03cb..b582930 100644
--- a/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
+++ b/jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/PostgresqlQueryRewriter.java
@@ -47,14 +47,16 @@ public class PostgresqlQueryRewriter extends LimitOffsetQueryRewriter {
 
     @Override
     public ColumnType getColumnType(int jdbcType, String nativeType, Integer columnSize) {
-        switch (nativeType) {
-        case "bool":
-            // override the normal behaviour of postgresql which maps "bool" to
-            // a BIT.
-            return ColumnType.BOOLEAN;
-        case "json":
-        case "jsonb":
-            return ColumnType.MAP;
+        if (nativeType != null) {
+            switch (nativeType) {
+            case "bool":
+                // override the normal behaviour of postgresql which maps "bool" to
+                // a BIT.
+                return ColumnType.BOOLEAN;
+            case "json":
+            case "jsonb":
+                return ColumnType.MAP;
+            }
         }
         return super.getColumnType(jdbcType, nativeType, columnSize);
     }
@@ -106,18 +108,20 @@ public class PostgresqlQueryRewriter extends LimitOffsetQueryRewriter {
 
     @Override
     public Object getResultSetValue(ResultSet resultSet, int columnIndex, Column column) throws SQLException {
-        switch (column.getNativeType()) {
-        case "json":
-        case "jsonb":
-            assert column.getType() == ColumnType.MAP;
-            final String stringValue = resultSet.getString(columnIndex);
-            if (stringValue == null) {
-                return null;
-            }
-            try {
-                return jsonObjectMapper.readValue(stringValue, Map.class);
-            } catch (Exception e) {
-                throw new IllegalArgumentException("Unable to read string as JSON: " + stringValue);
+        if (column.getNativeType() != null) {
+            switch (column.getNativeType()) {
+            case "json":
+            case "jsonb":
+                assert column.getType() == ColumnType.MAP;
+                final String stringValue = resultSet.getString(columnIndex);
+                if (stringValue == null) {
+                    return null;
+                }
+                try {
+                    return jsonObjectMapper.readValue(stringValue, Map.class);
+                } catch (Exception e) {
+                    throw new IllegalArgumentException("Unable to read string as JSON: " + stringValue);
+                }
             }
         }
         return super.getResultSetValue(resultSet, columnIndex, column);