OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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, ResultSetMetaData metadata, int column_number) 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 83 of file Db_vendor_types.java.

Constructor & Destructor Documentation

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

Definition at line 84 of file Db_vendor_types.java.

84 {}

Member Function Documentation

String com.mapd.utility.db_vendors.PostGis_types.find_gis_type ( Connection  conn,
ResultSetMetaData  metadata,
int  column_number 
) throws SQLException
inlinevirtual

Implements com.mapd.utility.db_vendors.Db_vendor_types.

Definition at line 139 of file Db_vendor_types.java.

References com.mapd.utility.db_vendors.PostGis_types.extra_types, com.mapd.utility.db_vendors.PostGis_types.find_type_detail(), and Experimental.String.

141  {
142  String column_name = metadata.getColumnName(column_number);
143  String column_type_name = metadata.getColumnTypeName(column_number);
144  if (column_type_name.equalsIgnoreCase("geography"))
145  return find_type_detail(
146  conn, "geography_columns", "f_geography_column", column_name);
147  else if (column_type_name.equalsIgnoreCase("geometry"))
148  return find_type_detail(conn, "geometry_columns", "f_geometry_column", column_name);
149  if (!extra_types.containsKey(column_type_name))
150  throw new SQLException(
151  "type not supported: " + column_type_name + " for column " + column_name);
152  return extra_types.get(column_type_name);
153  }
String find_type_detail(Connection conn, String ref_table_name, String ref_column_name, String column_name)
static Hashtable< String, String > extra_types

+ Here is the call graph for this function:

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 155 of file Db_vendor_types.java.

References com.mapd.utility.db_vendors.PostGis_types.extra_types, Integer, Experimental.String, run_benchmark_import.type, and com.mapd.utility.db_vendors.Db_vendor_types.valid_srid.

Referenced by com.mapd.utility.db_vendors.PostGis_types.find_gis_type().

158  {
159  String omnisci_type = null;
160  Statement detail_st = conn.createStatement();
161  // Select for a specific column name from the ref table.
162  String select = "select type, srid from " + ref_table_name + " where "
163  + ref_column_name + " = '" + column_name + "'";
164  ResultSet rs = detail_st.executeQuery(select);
165  String ps_column_type = null;
166  int ps_srid = 0;
167  // The select statment above, can return multiple values qualified by schema/table.
168  // Unfortunately at this stage only the original postgres column name is known. If
169  // get mulitple returns with the same column name, but different types we will not be
170  // able to separate which specific column is which type. This loop checks for this
171  // condition and thows when detected.
172  while (rs.next()) {
173  String type = rs.getString(1);
174  int srid = rs.getInt(2);
175  // If multiple rows are returned with different geo types for a single coulmn name
176  // then throw.
177  if (ps_column_type != null
178  && (ps_column_type.equalsIgnoreCase(type) || srid != ps_srid)) {
179  throw new SQLException("multiple column definitions [" + ps_column_type + ":"
180  + type + "] found for column_name [" + column_name + "]");
181  }
182  ps_column_type = type;
183  ps_srid = srid;
184  }
185  if (!extra_types.containsKey(ps_column_type.toLowerCase()))
186  throw new SQLException("type not supported");
187  omnisci_type = extra_types.get(ps_column_type.toLowerCase());
188  if (ps_srid != 0) {
189  if (!valid_srid.contains(new Integer(ps_srid)))
190  throw new SQLException("type not supported");
191  omnisci_type = omnisci_type + "," + ps_srid;
192  }
193  return new String("geometry(" + omnisci_type + ")");
194  }
static Hashtable< String, String > extra_types

+ Here is the caller graph for this function:

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

Implements com.mapd.utility.db_vendors.Db_vendor_types.

Definition at line 100 of file Db_vendor_types.java.

References Fragmenter_Namespace.indexOf(), and com.mapd.utility.db_vendors.PostGis_types.wkt_point().

101  {
102  if (gis_type_name.equalsIgnoreCase("geometry")
103  || gis_type_name.equalsIgnoreCase("geography")) {
104  Object gis_object = rs.getObject(column_number);
105  PGgeometry pGeometry = (PGgeometry) gis_object;
106  if (pGeometry == null) throw new SQLException("unknown type");
107  // Try and trim the front SRID=nnnn; value from the string returned from the db.
108  // If there isn't a SRID=nnnn; string (marked by the ';') then simply
109  // return the whole string
110  int semi_colon_indx = pGeometry.getValue().indexOf(';');
111  if (-1 != semi_colon_indx && semi_colon_indx < pGeometry.getValue().length()) {
112  return pGeometry.getValue().substring(semi_colon_indx + 1);
113  }
114  return pGeometry.getValue();
115  }
116  StringBuffer WKT_string = new StringBuffer();
117  if (gis_type_name.equalsIgnoreCase("point")) {
118  PGpoint point = (PGpoint) rs.getObject(column_number);
119  WKT_string.append(extra_types.get(gis_type_name) + "(" + wkt_point(point) + ")");
120 
121  } else if (gis_type_name.equalsIgnoreCase("polygon")) {
122  PGpolygon polygon = (PGpolygon) rs.getObject(column_number);
123  WKT_string.append(extra_types.get(gis_type_name) + "((");
124  for (PGpoint p : polygon.points) {
125  WKT_string.append(wkt_point(p) + ",");
126  }
127  WKT_string.replace(WKT_string.length() - 1, WKT_string.length(), "))");
128  } else if (gis_type_name.equalsIgnoreCase("lseg")) {
129  PGlseg lseg = (PGlseg) rs.getObject(column_number);
130  WKT_string.append(extra_types.get(gis_type_name) + "(");
131  for (PGpoint p : lseg.point) {
132  WKT_string.append(wkt_point(p) + ",");
133  }
134  WKT_string.replace(WKT_string.length() - 1, WKT_string.length(), ")");
135  }
136  return WKT_string.toString();
137  }
String wkt_point(PGpoint point)
size_t indexOf(std::vector< T > &vec, T val)

+ Here is the call graph for this function:

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

Definition at line 96 of file Db_vendor_types.java.

References Experimental.String.

Referenced by com.mapd.utility.db_vendors.PostGis_types.get_wkt().

96  {
97  return new String("" + point.x + " " + point.y);
98  }

+ Here is the caller graph for this function:

Member Data Documentation

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", "multipolygon");
}
}

Definition at line 87 of file Db_vendor_types.java.

Referenced by com.mapd.utility.db_vendors.PostGis_types.find_gis_type(), and com.mapd.utility.db_vendors.PostGis_types.find_type_detail().


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