@Test public void testGeospatialTypes() { assertEquals(PGUtil.PG_TYPE_GEOMETRY, PGUtil.convertType(Types.BLOB, "geometry")); assertEquals(PGUtil.PG_TYPE_GEOGRAPHY, PGUtil.convertType(Types.LONGVARBINARY, "geography")); }
public static int convertType(final int type, final String typeName) { switch (type) { case Types.BIT: case Types.BOOLEAN: return PG_TYPE_BOOL; case Types.VARCHAR: return PG_TYPE_VARCHAR; case Types.CHAR: return PG_TYPE_BPCHAR; case Types.TINYINT: case Types.SMALLINT: return PG_TYPE_INT2; case Types.INTEGER: return PG_TYPE_INT4; case Types.BIGINT: return PG_TYPE_INT8; case Types.NUMERIC: case Types.DECIMAL: return PG_TYPE_NUMERIC; case Types.FLOAT: case Types.REAL: return PG_TYPE_FLOAT4; case Types.DOUBLE: return PG_TYPE_FLOAT8; case Types.TIME: return PG_TYPE_TIME; case Types.DATE: return PG_TYPE_DATE; case Types.TIMESTAMP: return PG_TYPE_TIMESTAMP_NO_TMZONE; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (typeName.equalsIgnoreCase("geometry")) { return PG_TYPE_GEOMETRY; } if (typeName.equalsIgnoreCase("geography")) { return PG_TYPE_GEOGRAPHY; } return PG_TYPE_BYTEA; case Types.SQLXML: return PG_TYPE_XML; case Types.LONGVARCHAR: case Types.CLOB: if (typeName.equalsIgnoreCase("json")) { return PG_TYPE_JSON; } return PG_TYPE_TEXT; case Types.ARRAY: switch (typeName) { case "boolean[]": return PG_TYPE_BOOLARRAY; case "byte[]": case "short[]": return PG_TYPE_INT2ARRAY; case "integer[]": return PG_TYPE_INT4ARRAY; case "long[]": return PG_TYPE_INT8ARRAY; case "float[]": return PG_TYPE_FLOAT4ARRAY; case "double[]": return PG_TYPE_FLOAT8ARRAY; case "biginiteger[]": case "bigdecimal[]": return PG_TYPE_NUMERICARRAY; case "date[]": return PG_TYPE_DATEARRAY; case "time[]": return PG_TYPE_TIMEARRAY; case "timestamp[]": return PG_TYPE_TIMESTAMP_NO_TMZONEARRAY; case "geometry[]": return PG_TYPE_GEOMETRYARRAY; case "geography[]": return PG_TYPE_GEOGRAPHYARRAY; case "xml[]": return PG_TYPE_XMLARRAY; case "json[]": return PG_TYPE_JSONARRAY; default: return PG_TYPE_TEXTARRAY; } default: return PG_TYPE_UNKNOWN; } }
PGUtil { public static int convertType(final int type, final String typeName) { switch (type) { case Types.BIT: case Types.BOOLEAN: return PG_TYPE_BOOL; case Types.VARCHAR: return PG_TYPE_VARCHAR; case Types.CHAR: return PG_TYPE_BPCHAR; case Types.TINYINT: case Types.SMALLINT: return PG_TYPE_INT2; case Types.INTEGER: return PG_TYPE_INT4; case Types.BIGINT: return PG_TYPE_INT8; case Types.NUMERIC: case Types.DECIMAL: return PG_TYPE_NUMERIC; case Types.FLOAT: case Types.REAL: return PG_TYPE_FLOAT4; case Types.DOUBLE: return PG_TYPE_FLOAT8; case Types.TIME: return PG_TYPE_TIME; case Types.DATE: return PG_TYPE_DATE; case Types.TIMESTAMP: return PG_TYPE_TIMESTAMP_NO_TMZONE; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (typeName.equalsIgnoreCase("geometry")) { return PG_TYPE_GEOMETRY; } if (typeName.equalsIgnoreCase("geography")) { return PG_TYPE_GEOGRAPHY; } return PG_TYPE_BYTEA; case Types.SQLXML: return PG_TYPE_XML; case Types.LONGVARCHAR: case Types.CLOB: if (typeName.equalsIgnoreCase("json")) { return PG_TYPE_JSON; } return PG_TYPE_TEXT; case Types.ARRAY: switch (typeName) { case "boolean[]": return PG_TYPE_BOOLARRAY; case "byte[]": case "short[]": return PG_TYPE_INT2ARRAY; case "integer[]": return PG_TYPE_INT4ARRAY; case "long[]": return PG_TYPE_INT8ARRAY; case "float[]": return PG_TYPE_FLOAT4ARRAY; case "double[]": return PG_TYPE_FLOAT8ARRAY; case "biginiteger[]": case "bigdecimal[]": return PG_TYPE_NUMERICARRAY; case "date[]": return PG_TYPE_DATEARRAY; case "time[]": return PG_TYPE_TIMEARRAY; case "timestamp[]": return PG_TYPE_TIMESTAMP_NO_TMZONEARRAY; case "geometry[]": return PG_TYPE_GEOMETRYARRAY; case "geography[]": return PG_TYPE_GEOGRAPHYARRAY; case "xml[]": return PG_TYPE_XMLARRAY; case "json[]": return PG_TYPE_JSONARRAY; default: return PG_TYPE_TEXTARRAY; } default: return PG_TYPE_UNKNOWN; } } }
PGUtil { public static int convertType(final int type, final String typeName) { switch (type) { case Types.BIT: case Types.BOOLEAN: return PG_TYPE_BOOL; case Types.VARCHAR: return PG_TYPE_VARCHAR; case Types.CHAR: return PG_TYPE_BPCHAR; case Types.TINYINT: case Types.SMALLINT: return PG_TYPE_INT2; case Types.INTEGER: return PG_TYPE_INT4; case Types.BIGINT: return PG_TYPE_INT8; case Types.NUMERIC: case Types.DECIMAL: return PG_TYPE_NUMERIC; case Types.FLOAT: case Types.REAL: return PG_TYPE_FLOAT4; case Types.DOUBLE: return PG_TYPE_FLOAT8; case Types.TIME: return PG_TYPE_TIME; case Types.DATE: return PG_TYPE_DATE; case Types.TIMESTAMP: return PG_TYPE_TIMESTAMP_NO_TMZONE; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (typeName.equalsIgnoreCase("geometry")) { return PG_TYPE_GEOMETRY; } if (typeName.equalsIgnoreCase("geography")) { return PG_TYPE_GEOGRAPHY; } return PG_TYPE_BYTEA; case Types.SQLXML: return PG_TYPE_XML; case Types.LONGVARCHAR: case Types.CLOB: if (typeName.equalsIgnoreCase("json")) { return PG_TYPE_JSON; } return PG_TYPE_TEXT; case Types.ARRAY: switch (typeName) { case "boolean[]": return PG_TYPE_BOOLARRAY; case "byte[]": case "short[]": return PG_TYPE_INT2ARRAY; case "integer[]": return PG_TYPE_INT4ARRAY; case "long[]": return PG_TYPE_INT8ARRAY; case "float[]": return PG_TYPE_FLOAT4ARRAY; case "double[]": return PG_TYPE_FLOAT8ARRAY; case "biginiteger[]": case "bigdecimal[]": return PG_TYPE_NUMERICARRAY; case "date[]": return PG_TYPE_DATEARRAY; case "time[]": return PG_TYPE_TIMEARRAY; case "timestamp[]": return PG_TYPE_TIMESTAMP_NO_TMZONEARRAY; case "geometry[]": return PG_TYPE_GEOMETRYARRAY; case "geography[]": return PG_TYPE_GEOGRAPHYARRAY; case "xml[]": return PG_TYPE_XMLARRAY; case "json[]": return PG_TYPE_JSONARRAY; default: return PG_TYPE_TEXTARRAY; } default: return PG_TYPE_UNKNOWN; } }  }
PGUtil { public static int convertType(final int type, final String typeName) { switch (type) { case Types.BIT: case Types.BOOLEAN: return PG_TYPE_BOOL; case Types.VARCHAR: return PG_TYPE_VARCHAR; case Types.CHAR: return PG_TYPE_BPCHAR; case Types.TINYINT: case Types.SMALLINT: return PG_TYPE_INT2; case Types.INTEGER: return PG_TYPE_INT4; case Types.BIGINT: return PG_TYPE_INT8; case Types.NUMERIC: case Types.DECIMAL: return PG_TYPE_NUMERIC; case Types.FLOAT: case Types.REAL: return PG_TYPE_FLOAT4; case Types.DOUBLE: return PG_TYPE_FLOAT8; case Types.TIME: return PG_TYPE_TIME; case Types.DATE: return PG_TYPE_DATE; case Types.TIMESTAMP: return PG_TYPE_TIMESTAMP_NO_TMZONE; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (typeName.equalsIgnoreCase("geometry")) { return PG_TYPE_GEOMETRY; } if (typeName.equalsIgnoreCase("geography")) { return PG_TYPE_GEOGRAPHY; } return PG_TYPE_BYTEA; case Types.SQLXML: return PG_TYPE_XML; case Types.LONGVARCHAR: case Types.CLOB: if (typeName.equalsIgnoreCase("json")) { return PG_TYPE_JSON; } return PG_TYPE_TEXT; case Types.ARRAY: switch (typeName) { case "boolean[]": return PG_TYPE_BOOLARRAY; case "byte[]": case "short[]": return PG_TYPE_INT2ARRAY; case "integer[]": return PG_TYPE_INT4ARRAY; case "long[]": return PG_TYPE_INT8ARRAY; case "float[]": return PG_TYPE_FLOAT4ARRAY; case "double[]": return PG_TYPE_FLOAT8ARRAY; case "biginiteger[]": case "bigdecimal[]": return PG_TYPE_NUMERICARRAY; case "date[]": return PG_TYPE_DATEARRAY; case "time[]": return PG_TYPE_TIMEARRAY; case "timestamp[]": return PG_TYPE_TIMESTAMP_NO_TMZONEARRAY; case "geometry[]": return PG_TYPE_GEOMETRYARRAY; case "geography[]": return PG_TYPE_GEOGRAPHYARRAY; case "xml[]": return PG_TYPE_XMLARRAY; case "json[]": return PG_TYPE_JSONARRAY; default: return PG_TYPE_TEXTARRAY; } default: return PG_TYPE_UNKNOWN; } }  static int convertType(final int type, final String typeName); }
PGUtil { public static int convertType(final int type, final String typeName) { switch (type) { case Types.BIT: case Types.BOOLEAN: return PG_TYPE_BOOL; case Types.VARCHAR: return PG_TYPE_VARCHAR; case Types.CHAR: return PG_TYPE_BPCHAR; case Types.TINYINT: case Types.SMALLINT: return PG_TYPE_INT2; case Types.INTEGER: return PG_TYPE_INT4; case Types.BIGINT: return PG_TYPE_INT8; case Types.NUMERIC: case Types.DECIMAL: return PG_TYPE_NUMERIC; case Types.FLOAT: case Types.REAL: return PG_TYPE_FLOAT4; case Types.DOUBLE: return PG_TYPE_FLOAT8; case Types.TIME: return PG_TYPE_TIME; case Types.DATE: return PG_TYPE_DATE; case Types.TIMESTAMP: return PG_TYPE_TIMESTAMP_NO_TMZONE; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: if (typeName.equalsIgnoreCase("geometry")) { return PG_TYPE_GEOMETRY; } if (typeName.equalsIgnoreCase("geography")) { return PG_TYPE_GEOGRAPHY; } return PG_TYPE_BYTEA; case Types.SQLXML: return PG_TYPE_XML; case Types.LONGVARCHAR: case Types.CLOB: if (typeName.equalsIgnoreCase("json")) { return PG_TYPE_JSON; } return PG_TYPE_TEXT; case Types.ARRAY: switch (typeName) { case "boolean[]": return PG_TYPE_BOOLARRAY; case "byte[]": case "short[]": return PG_TYPE_INT2ARRAY; case "integer[]": return PG_TYPE_INT4ARRAY; case "long[]": return PG_TYPE_INT8ARRAY; case "float[]": return PG_TYPE_FLOAT4ARRAY; case "double[]": return PG_TYPE_FLOAT8ARRAY; case "biginiteger[]": case "bigdecimal[]": return PG_TYPE_NUMERICARRAY; case "date[]": return PG_TYPE_DATEARRAY; case "time[]": return PG_TYPE_TIMEARRAY; case "timestamp[]": return PG_TYPE_TIMESTAMP_NO_TMZONEARRAY; case "geometry[]": return PG_TYPE_GEOMETRYARRAY; case "geography[]": return PG_TYPE_GEOGRAPHYARRAY; case "xml[]": return PG_TYPE_XMLARRAY; case "json[]": return PG_TYPE_JSONARRAY; default: return PG_TYPE_TEXTARRAY; } default: return PG_TYPE_UNKNOWN; } }  static int convertType(final int type, final String typeName); static final int PG_TYPE_UNSPECIFIED; static final int PG_TYPE_VARCHAR; static final int PG_TYPE_BOOL; static final int PG_TYPE_BYTEA; static final int PG_TYPE_CHAR; static final int PG_TYPE_BPCHAR; static final int PG_TYPE_INT8; static final int PG_TYPE_INT2; static final int PG_TYPE_INT4; static final int PG_TYPE_TEXT; static final int PG_TYPE_XML; static final int PG_TYPE_FLOAT4; static final int PG_TYPE_FLOAT8; static final int PG_TYPE_UNKNOWN; static final int PG_TYPE_GEOMETRY; static final int PG_TYPE_GEOMETRYARRAY; static final int PG_TYPE_GEOGRAPHY; static final int PG_TYPE_GEOGRAPHYARRAY; static final int PG_TYPE_JSON; static final int PG_TYPE_JSONARRAY; static final int PG_TYPE_OIDVECTOR; static final int PG_TYPE_INT2VECTOR; static final int PG_TYPE_OIDARRAY; static final int PG_TYPE_CHARARRAY; static final int PG_TYPE_TEXTARRAY; static final int PG_TYPE_DATE; static final int PG_TYPE_TIME; static final int PG_TYPE_TIMESTAMP_NO_TMZONE; static final int PG_TYPE_NUMERIC; static final int PG_TYPE_BOOLARRAY; static final int PG_TYPE_BYTEAARRAY; static final int PG_TYPE_INT8ARRAY; static final int PG_TYPE_INT2ARRAY; static final int PG_TYPE_INT4ARRAY; static final int PG_TYPE_FLOAT4ARRAY; static final int PG_TYPE_FLOAT8ARRAY; static final int PG_TYPE_DATEARRAY; static final int PG_TYPE_TIMEARRAY; static final int PG_TYPE_TIMESTAMP_NO_TMZONEARRAY; static final int PG_TYPE_NUMERICARRAY; static final int PG_TYPE_XMLARRAY; }