OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HeavyAIGeomTest.java
Go to the documentation of this file.
1 package ai.heavy.jdbc;
2 import static org.junit.Assert.*;
3 
4 import org.junit.Test;
5 
6 import java.sql.*;
7 import java.util.Properties;
8 
9 public class HeavyAIGeomTest {
10  static Properties PROPERTIES = new Property_loader("connection_test.properties");
11  static final String url = PROPERTIES.getProperty("default_db_connection_url");
12  static final String user = PROPERTIES.getProperty("default_super_user");
13  static final String password = PROPERTIES.getProperty("default_user_password");
14 
15  static String sql_drop_tbl_geom = "drop table if exists jdbc_geom";
16  static String sql_create_tbl_geom =
17  "create table jdbc_geom (m_point POINT, m_linestring LINESTRING, m_polygon POLYGON, m_multi_polygon MULTIPOLYGON)";
18 
19  static String sql_insert_geom =
20  "insert into jdbc_geom values ('POINT(0 0)', 'LINESTRING(0 1, 2 2)',"
21  + " 'POLYGON((0 0,4 0,4 4,0 0))',"
22  + " 'MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0)))')";
23 
24  static String sql_insert_geom_batch = "insert into jdbc_geom values (?, ?, ?, ?)";
25 
26  static String sql_select_geom = "select * from jdbc_geom";
27 
28  /* Test the basic connection and methods functionality */
29  @Test
30  public void tst1_geometry() throws Exception {
31  Connection conn = DriverManager.getConnection(url, user, password);
32  assertNotEquals(null, conn);
33  Statement statement = conn.createStatement();
34  statement.executeUpdate(sql_drop_tbl_geom);
35  statement.executeUpdate(sql_create_tbl_geom);
36  statement.executeUpdate(sql_insert_geom);
37 
38  ResultSet rs = statement.executeQuery(sql_select_geom);
39  while (rs.next()) {
40  Object m_point = rs.getObject("m_point");
41  Object m_linestring = rs.getObject("m_linestring");
42  Object m_polygon = rs.getObject("m_polygon");
43  Object m_multi_polygon = rs.getString("m_multi_polygon");
44  assertEquals("POLYGON ((0 0,4 0,4 4,0 0))", m_polygon);
45  assertEquals("LINESTRING (0 1,2 2)", m_linestring);
46  assertEquals("POINT (0 0)", m_point);
47  assertEquals("MULTIPOLYGON (((0 0,4 0,4 4,0 4,0 0)))", m_multi_polygon);
48  }
49  rs.close();
50  statement.executeUpdate(sql_drop_tbl_geom);
51  }
52 
53  /* Test geo batch functionality */
54  @Test
55  public void tst2_geometry() throws Exception {
56  Connection conn = DriverManager.getConnection(url, user, password);
57  assertNotEquals(null, conn);
58  Statement statement = conn.createStatement();
59  statement.executeUpdate(sql_drop_tbl_geom);
60  statement.executeUpdate(sql_create_tbl_geom);
61  PreparedStatement ps = conn.prepareStatement(sql_insert_geom_batch);
62  ps.setString(1, "POINT(0 0)");
63  ps.setString(2, "LINESTRING(0 1, 2 2)");
64  ps.setString(3, "POLYGON((0 0,4 0,4 4,0 0))");
65  ps.setString(4, "MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0)))");
66  ps.addBatch();
67  ps.executeBatch();
68 
69  ResultSet rs = statement.executeQuery(sql_select_geom);
70  while (rs.next()) {
71  // Test getString and getObject return on geo type
72  Object m_point = rs.getObject("m_point");
73  Object m_linestring = rs.getString("m_linestring");
74  Object m_polygon = rs.getObject("m_polygon");
75  String m_multi_polygon = rs.getString("m_multi_polygon");
76  assertEquals("POLYGON ((0 0,4 0,4 4,0 0))", m_polygon);
77  assertEquals("LINESTRING (0 1,2 2)", m_linestring);
78  assertEquals("POINT (0 0)", m_point);
79  assertEquals("MULTIPOLYGON (((0 0,4 0,4 4,0 4,0 0)))", m_multi_polygon);
80  }
81  rs.close();
82  statement.executeUpdate(sql_drop_tbl_geom);
83  }
84 }
tuple conn
Definition: report.py:41