OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
com.omnisci.jdbc.OmniSciArrayTest Class Reference
+ Collaboration diagram for com.omnisci.jdbc.OmniSciArrayTest:

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 OmniSciArrayTest.java.

Member Function Documentation

void com.omnisci.jdbc.OmniSciArrayTest.create_and_read_array_test ( ) throws Exception
inline

Definition at line 54 of file OmniSciArrayTest.java.

References com.omnisci.jdbc.OmniSciArrayTest.da, com.omnisci.jdbc.OmniSciArrayTest.fa, com.omnisci.jdbc.OmniSciArrayTest.ia, com.omnisci.jdbc.OmniSciArrayTest.sa, and com.omnisci.jdbc.OmniSciArrayTest.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 BigDecimal[] da
void com.omnisci.jdbc.OmniSciArrayTest.illegal_arguments_test ( ) throws Exception
inline

Definition at line 129 of file OmniSciArrayTest.java.

References com.omnisci.jdbc.OmniSciArrayTest.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 com.omnisci.jdbc.OmniSciArrayTest.insert_select_test ( ) throws Exception
inline

Definition at line 94 of file OmniSciArrayTest.java.

References com.omnisci.jdbc.OmniSciArrayTest.da, com.omnisci.jdbc.OmniSciArrayTest.fa, com.omnisci.jdbc.OmniSciArrayTest.ia, com.omnisci.jdbc.OmniSciArrayTest.sa, com.omnisci.jdbc.OmniSciArrayTest.ta, and omnisci.dtypes.Timestamp.

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 BigDecimal[] da
void com.omnisci.jdbc.OmniSciArrayTest.setUp ( ) throws Exception
inline

Definition at line 38 of file OmniSciArrayTest.java.

References com.omnisci.jdbc.OmniSciArrayTest.password, com.omnisci.jdbc.OmniSciArrayTest.url, and com.omnisci.jdbc.OmniSciArrayTest.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 com.omnisci.jdbc.OmniSciArrayTest.tearDown ( ) throws Exception
inline

Definition at line 47 of file OmniSciArrayTest.java.

47  {
48  m_conn.close();
49  }

Member Data Documentation

final BigDecimal [] com.omnisci.jdbc.OmniSciArrayTest.da
staticpackage
Initial value:
= {BigDecimal.valueOf(1.100),
null,
BigDecimal.valueOf(2.15),
BigDecimal.valueOf(3.5)}

Definition at line 26 of file OmniSciArrayTest.java.

Referenced by com.omnisci.jdbc.OmniSciArrayTest.create_and_read_array_test(), and com.omnisci.jdbc.OmniSciArrayTest.insert_select_test().

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

Definition at line 35 of file OmniSciArrayTest.java.

final String com.omnisci.jdbc.OmniSciArrayTest.password = PROPERTIES.getProperty("default_user_password")
staticpackage

Definition at line 22 of file OmniSciArrayTest.java.

Referenced by com.omnisci.jdbc.OmniSciArrayTest.setUp().

Properties com.omnisci.jdbc.OmniSciArrayTest.PROPERTIES = new Property_loader("prepare_test.properties")
staticpackage

Definition at line 19 of file OmniSciArrayTest.java.

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

Definition at line 31 of file OmniSciArrayTest.java.

Referenced by com.omnisci.jdbc.OmniSciArrayTest.create_and_read_array_test(), and com.omnisci.jdbc.OmniSciArrayTest.insert_select_test().

final String com.omnisci.jdbc.OmniSciArrayTest.url = PROPERTIES.getProperty("default_db_connection_url")
staticpackage

Definition at line 20 of file OmniSciArrayTest.java.

Referenced by com.omnisci.jdbc.OmniSciArrayTest.setUp().

final String com.omnisci.jdbc.OmniSciArrayTest.user = PROPERTIES.getProperty("default_super_user")
staticpackage

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