OmniSciDB  c07336695a
com.mapd.utility.db_vendors.PostGis_types Class Reference
+ Inheritance diagram for com.mapd.utility.db_vendors.PostGis_types:
+ Collaboration diagram for com.mapd.utility.db_vendors.PostGis_types:

Public Member Functions

String get_wkt (ResultSet rs, int column_number, String gis_type_name) throws SQLException
 
String find_gis_type (Connection conn, String column_name, String column_type_name) throws SQLException
 
- Public Member Functions inherited from com.mapd.utility.db_vendors.Db_vendor_types
abstract String find_gis_type (Connection conn, String source_column_name, String source_column_type_name) throws SQLException
 
abstract String get_wkt (ResultSet rs, int column_number, String gis_type_name) throws SQLException
 

Protected Member Functions

 PostGis_types ()
 
- Protected Member Functions inherited from com.mapd.utility.db_vendors.Db_vendor_types
 Db_vendor_types ()
 

Private Member Functions

String wkt_point (PGpoint point)
 
String find_type_detail (Connection conn, String ref_table_name, String ref_column_name, String column_name) throws SQLException
 

Static Private Attributes

static Hashtable< String, String > extra_types
 

Additional Inherited Members

- Static Public Member Functions inherited from com.mapd.utility.db_vendors.Db_vendor_types
static com.mapd.utility.db_vendors.Db_vendor_types Db_vendor_factory (String connection_str)
 
- Static Protected Attributes inherited from com.mapd.utility.db_vendors.Db_vendor_types
static HashSet< Integer > valid_srid
 

Detailed Description

Definition at line 35 of file Db_vendor_types.java.

Constructor & Destructor Documentation

◆ PostGis_types()

com.mapd.utility.db_vendors.PostGis_types.PostGis_types ( )
inlineprotected

Definition at line 36 of file Db_vendor_types.java.

36 {}

Member Function Documentation

◆ find_gis_type()

String com.mapd.utility.db_vendors.PostGis_types.find_gis_type ( Connection  conn,
String  column_name,
String  column_type_name 
) throws SQLException
inline

Definition at line 91 of file Db_vendor_types.java.

93  {
94  if (column_type_name.equalsIgnoreCase("geography"))
95  return find_type_detail(
96  conn, "geography_columns", "f_geography_column", column_name);
97  else if (column_type_name.equalsIgnoreCase("geometry"))
98  return find_type_detail(conn, "geometry_columns", "f_geometry_column", column_name);
99  if (!extra_types.containsKey(column_type_name))
100  throw new SQLException("type not supported");
101  return extra_types.get(column_type_name);
102  }
String find_type_detail(Connection conn, String ref_table_name, String ref_column_name, String column_name)
static Hashtable< String, String > extra_types

◆ find_type_detail()

String com.mapd.utility.db_vendors.PostGis_types.find_type_detail ( Connection  conn,
String  ref_table_name,
String  ref_column_name,
String  column_name 
) throws SQLException
inlineprivate

Definition at line 104 of file Db_vendor_types.java.

References Integer, Experimental.String, run-benchmark-import.type, and com.mapd.utility.db_vendors.Db_vendor_types.valid_srid.

107  {
108  String omnisci_type = null;
109  Statement detail_st = conn.createStatement();
110  // Select for a specific column name from the ref table.
111  String select = "select type, srid from " + ref_table_name + " where "
112  + ref_column_name + " = '" + column_name + "'";
113  ResultSet rs = detail_st.executeQuery(select);
114  String ps_column_type = null;
115  int ps_srid = 0;
116  // The select statment above, can return multiple values qualified by schema/table.
117  // Unfortunately at this stage only the original postgres column name is known. If
118  // get mulitple returns with the same column name, but different types we will not be
119  // able to separate which specific column is which type. This loop checks for this
120  // condition and thows when detected.
121  while (rs.next()) {
122  String type = rs.getString(1);
123  int srid = rs.getInt(2);
124  // If multiple rows are returned with different geo types for a single coulmn name
125  // then throw.
126  if (ps_column_type != null
127  && (ps_column_type.equalsIgnoreCase(type) || srid != ps_srid)) {
128  throw new SQLException("multiple column definitions [" + ps_column_type + ":"
129  + type + "] found for column_name [" + column_name + "]");
130  }
131  ps_column_type = type;
132  ps_srid = srid;
133  }
134  if (!extra_types.containsKey(ps_column_type.toLowerCase()))
135  throw new SQLException("type not supported");
136  omnisci_type = extra_types.get(ps_column_type.toLowerCase());
137  if (ps_srid != 0) {
138  if (!valid_srid.contains(new Integer(ps_srid)))
139  throw new SQLException("type not supported");
140  omnisci_type = omnisci_type + "," + ps_srid;
141  }
142  return new String("geometry(" + omnisci_type + ")");
143  }
static Hashtable< String, String > extra_types

◆ get_wkt()

String com.mapd.utility.db_vendors.PostGis_types.get_wkt ( ResultSet  rs,
int  column_number,
String  gis_type_name 
) throws SQLException
inline

Definition at line 52 of file Db_vendor_types.java.

53  {
54  if (gis_type_name.equalsIgnoreCase("geometry")
55  || gis_type_name.equalsIgnoreCase("geography")) {
56  Object gis_object = rs.getObject(column_number);
57  PGgeometry pGeometry = (PGgeometry) gis_object;
58  if (pGeometry == null) throw new SQLException("unknown type");
59  // Try and trim the front SRID=nnnn; value from the string returned from the db.
60  // If there isn't a SRID=nnnn; string (marked by the ';') then simply
61  // return the whole string
62  int semi_colon_indx = pGeometry.getValue().indexOf(';');
63  if (-1 != semi_colon_indx && semi_colon_indx < pGeometry.getValue().length()) {
64  return pGeometry.getValue().substring(semi_colon_indx + 1);
65  }
66  return pGeometry.getValue();
67  }
68  StringBuffer WKT_string = new StringBuffer();
69  if (gis_type_name.equalsIgnoreCase("point")) {
70  PGpoint point = (PGpoint) rs.getObject(column_number);
71  WKT_string.append(extra_types.get(gis_type_name) + "(" + wkt_point(point) + ")");
72 
73  } else if (gis_type_name.equalsIgnoreCase("polygon")) {
74  PGpolygon polygon = (PGpolygon) rs.getObject(column_number);
75  WKT_string.append(extra_types.get(gis_type_name) + "((");
76  for (PGpoint p : polygon.points) {
77  WKT_string.append(wkt_point(p) + ",");
78  }
79  WKT_string.replace(WKT_string.length() - 1, WKT_string.length(), "))");
80  } else if (gis_type_name.equalsIgnoreCase("lseg")) {
81  PGlseg lseg = (PGlseg) rs.getObject(column_number);
82  WKT_string.append(extra_types.get(gis_type_name) + "(");
83  for (PGpoint p : lseg.point) {
84  WKT_string.append(wkt_point(p) + ",");
85  }
86  WKT_string.replace(WKT_string.length() - 1, WKT_string.length(), ")");
87  }
88  return WKT_string.toString();
89  }
String wkt_point(PGpoint point)
static Hashtable< String, String > extra_types

◆ wkt_point()

String com.mapd.utility.db_vendors.PostGis_types.wkt_point ( PGpoint  point)
inlineprivate

Definition at line 48 of file Db_vendor_types.java.

References Experimental.String.

48  {
49  return new String("" + point.x + " " + point.y);
50  }

Member Data Documentation

◆ extra_types

Hashtable<String, String> com.mapd.utility.db_vendors.PostGis_types.extra_types
staticprivate
Initial value:
= new Hashtable() {
{
put("point", "POINT");
put("lseg", "linestring");
put("linestring", "linestring");
put("polygon", "polygon");
put("multipolygon", "multipolyon");
}
}

Definition at line 39 of file Db_vendor_types.java.


The documentation for this class was generated from the following file: