OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ai.heavy.jdbc.HeavyAIArrayTest Class Reference
+ Collaboration diagram for ai.heavy.jdbc.HeavyAIArrayTest:

Public Member Functions

void setUp () throws Exception
 
void tearDown () throws Exception
 
void create_and_read_array_test () throws Exception
 
void insert_select_test () throws Exception
 
void illegal_arguments_test () throws Exception
 

Static Package Attributes

static Properties PROPERTIES = new Property_loader("prepare_test.properties")
 
static final String url = PROPERTIES.getProperty("default_db_connection_url")
 
static final String user = PROPERTIES.getProperty("default_super_user")
 
static final String password = PROPERTIES.getProperty("default_user_password")
 
static final Integer[] ia = {100, null, 200, 300, 400, 500}
 
static final Float[] fa = {null, null, 1.0001f, 12.541f, null}
 
static final BigDecimal[] da
 
static final String[] sa = {"Hello", null, "World", "!"}
 
static final Timestamp[] ta
 

Private Attributes

Connection m_conn = null
 

Detailed Description

Definition at line 18 of file HeavyAIArrayTest.java.

Member Function Documentation

void ai.heavy.jdbc.HeavyAIArrayTest.create_and_read_array_test ( ) throws Exception
inline

Definition at line 54 of file HeavyAIArrayTest.java.

References ai.heavy.jdbc.HeavyAIArrayTest.da, ai.heavy.jdbc.HeavyAIArrayTest.fa, Float, ai.heavy.jdbc.HeavyAIArrayTest.ia, Integer, ai.heavy.jdbc.HeavyAIArrayTest.sa, and ai.heavy.jdbc.HeavyAIArrayTest.ta.

54  {
55  Array ints = m_conn.createArrayOf("INT", ia);
56  Array floats = m_conn.createArrayOf("FLOAT", fa);
57  Array decimals = m_conn.createArrayOf("DECIMAL", da);
58  Array strings = m_conn.createArrayOf("STR", sa);
59  Array timestamps = m_conn.createArrayOf("TIMESTAMP", ta);
60 
61  assertEquals(ints.getArray(), ia);
62  assertEquals(floats.getArray(), fa);
63  assertEquals(decimals.getArray(), da);
64  assertEquals(strings.getArray(), sa);
65  assertEquals(timestamps.getArray(), ta);
66 
67  ResultSet rs = ints.getResultSet();
68  while (rs.next()) {
69  Integer val = rs.getInt(2);
70  if (rs.wasNull()) val = null;
71  assertEquals(val, ia[rs.getInt(1) - 1]);
72  }
73  rs = floats.getResultSet();
74  while (rs.next()) {
75  Float val = rs.getFloat(2);
76  if (rs.wasNull()) val = null;
77  assertEquals(val, fa[rs.getInt(1) - 1]);
78  }
79  rs = decimals.getResultSet();
80  while (rs.next()) {
81  assertEquals(rs.getBigDecimal(2), da[rs.getInt(1) - 1]);
82  }
83  rs = strings.getResultSet();
84  while (rs.next()) {
85  assertEquals(rs.getString(2), sa[rs.getInt(1) - 1]);
86  }
87  rs = timestamps.getResultSet();
88  while (rs.next()) {
89  assertEquals(rs.getTimestamp(2), ta[rs.getInt(1) - 1]);
90  }
91  }
static final Timestamp[] ta
static final BigDecimal[] da
void ai.heavy.jdbc.HeavyAIArrayTest.illegal_arguments_test ( ) throws Exception
inline

Definition at line 129 of file HeavyAIArrayTest.java.

References ai.heavy.jdbc.HeavyAIArrayTest.ia.

129  {
130  try {
131  m_conn.createArrayOf("BIGINT", ia);
132  assertTrue("Should not be able to create BIGINT array from integers", false);
133  } catch (SQLException e) {
134  } catch (Exception ex) {
135  assertTrue("Expected an SQLException", false);
136  }
137 
138  try {
139  m_conn.createArrayOf("not_a_type", ia);
140  assertTrue("Should not be able to create an array without a valid type", false);
141  } catch (SQLException e) {
142  } catch (Exception ex) {
143  assertTrue("Expected an SQLException", false);
144  }
145 
146  try {
147  m_conn.createArrayOf("BIGINT", null);
148  assertTrue("Should not be able to create an array from null", false);
149  } catch (SQLException e) {
150  } catch (Exception ex) {
151  assertTrue("Expected an SQLException", false);
152  }
153 
154  Array ints = m_conn.createArrayOf("INT", ia);
155  int sz = ia.length;
156  try {
157  ints.getArray(sz / 2, sz / 2 + 2);
158  assertTrue("Should not be able to get array bigger than its initial size", false);
159  } catch (SQLException e) {
160  } catch (Exception ex) {
161  assertTrue("Expected an SQLException", false);
162  }
163  }
void ai.heavy.jdbc.HeavyAIArrayTest.insert_select_test ( ) throws Exception
inline

Definition at line 94 of file HeavyAIArrayTest.java.

References ai.heavy.jdbc.HeavyAIArrayTest.da, ai.heavy.jdbc.HeavyAIArrayTest.fa, Float, ai.heavy.jdbc.HeavyAIArrayTest.ia, Integer, ai.heavy.jdbc.HeavyAIArrayTest.sa, and ai.heavy.jdbc.HeavyAIArrayTest.ta.

94  {
95  Statement stmt = m_conn.createStatement();
96  stmt.executeUpdate("DROP TABLE IF EXISTS arrays_tbl");
97  stmt.executeUpdate("CREATE TABLE arrays_tbl ("
98  + "i integer,"
99  + "ia INTEGER[],"
100  + "fa FLOAT[],"
101  + "da DECIMAL(4,3)[],"
102  + "sa TEXT[] ENCODING DICT,"
103  + "ta TIMESTAMP(3)[])");
104  PreparedStatement ps =
105  m_conn.prepareStatement("INSERT INTO arrays_tbl VALUES(?, ?, ?, ?, ?, ?)");
106  ps.setInt(1, 1);
107  ps.setArray(2, m_conn.createArrayOf("INT", ia));
108  ps.setArray(3, m_conn.createArrayOf("FLOAT", fa));
109  ps.setArray(4, m_conn.createArrayOf("DECIMAL", da));
110  ps.setArray(5, m_conn.createArrayOf("STR", sa));
111  ps.setArray(6, m_conn.createArrayOf("TIMESTAMP", ta));
112  ps.executeUpdate();
113 
114  ResultSet rs = stmt.executeQuery("SELECT i, ia, fa, da, sa, ta FROM arrays_tbl");
115  assertTrue(rs.next());
116  assertEquals(rs.getInt("i"), 1);
117  assertArrayEquals((Integer[]) rs.getArray("ia").getArray(), ia);
118  assertArrayEquals((Float[]) rs.getArray("fa").getArray(), fa);
119  assertArrayEquals((BigDecimal[]) rs.getArray("da").getArray(), da);
120  assertArrayEquals((String[]) rs.getArray("sa").getArray(), sa);
121  assertArrayEquals((Timestamp[]) rs.getArray("ta").getArray(), ta);
122 
123  ps.close();
124  stmt.executeUpdate("DROP TABLE arrays_tbl");
125  stmt.close();
126  }
static final Timestamp[] ta
static final BigDecimal[] da
void ai.heavy.jdbc.HeavyAIArrayTest.setUp ( ) throws Exception
inline

Definition at line 38 of file HeavyAIArrayTest.java.

References ai.heavy.jdbc.HeavyAIArrayTest.password, ai.heavy.jdbc.HeavyAIArrayTest.url, and ai.heavy.jdbc.HeavyAIArrayTest.user.

38  {
39  Properties pt = new Properties();
40  pt.setProperty("user", user);
41  pt.setProperty("password", password);
42  m_conn = DriverManager.getConnection(url, pt);
43  TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
44  }
void ai.heavy.jdbc.HeavyAIArrayTest.tearDown ( ) throws Exception
inline

Definition at line 47 of file HeavyAIArrayTest.java.

47  {
48  m_conn.close();
49  }

Member Data Documentation

final BigDecimal [] ai.heavy.jdbc.HeavyAIArrayTest.da
staticpackage
Initial value:
= {BigDecimal.valueOf(1.100),
null,
BigDecimal.valueOf(2.15),
BigDecimal.valueOf(3.5)}

Definition at line 26 of file HeavyAIArrayTest.java.

Referenced by ai.heavy.jdbc.HeavyAIArrayTest.create_and_read_array_test(), and ai.heavy.jdbc.HeavyAIArrayTest.insert_select_test().

final Float [] ai.heavy.jdbc.HeavyAIArrayTest.fa = {null, null, 1.0001f, 12.541f, null}
staticpackage
final Integer [] ai.heavy.jdbc.HeavyAIArrayTest.ia = {100, null, 200, 300, 400, 500}
staticpackage
Connection ai.heavy.jdbc.HeavyAIArrayTest.m_conn = null
private

Definition at line 35 of file HeavyAIArrayTest.java.

final String ai.heavy.jdbc.HeavyAIArrayTest.password = PROPERTIES.getProperty("default_user_password")
staticpackage

Definition at line 22 of file HeavyAIArrayTest.java.

Referenced by ai.heavy.jdbc.HeavyAIArrayTest.setUp().

Properties ai.heavy.jdbc.HeavyAIArrayTest.PROPERTIES = new Property_loader("prepare_test.properties")
staticpackage

Definition at line 19 of file HeavyAIArrayTest.java.

final String [] ai.heavy.jdbc.HeavyAIArrayTest.sa = {"Hello", null, "World", "!"}
staticpackage
final Timestamp [] ai.heavy.jdbc.HeavyAIArrayTest.ta
staticpackage
Initial value:
= {new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis() + 1000000),
null}

Definition at line 31 of file HeavyAIArrayTest.java.

Referenced by ai.heavy.jdbc.HeavyAIArrayTest.create_and_read_array_test(), and ai.heavy.jdbc.HeavyAIArrayTest.insert_select_test().

final String ai.heavy.jdbc.HeavyAIArrayTest.url = PROPERTIES.getProperty("default_db_connection_url")
staticpackage

Definition at line 20 of file HeavyAIArrayTest.java.

Referenced by ai.heavy.jdbc.HeavyAIArrayTest.setUp().

final String ai.heavy.jdbc.HeavyAIArrayTest.user = PROPERTIES.getProperty("default_super_user")
staticpackage

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