use of java.sql.Array in project adempiere by adempiere.
the class CalculateReplenishPlan method getSqlArray.
/**
* @param data
* @param sqlTypeName
* @param conn
* @return
* @throws SQLException
*/
private Array getSqlArray(Object[] data, String sqlTypeName, Connection conn) throws SQLException {
Array array;
if (conn instanceof C3P0ProxyConnection) {
C3P0ProxyConnection proxy = (C3P0ProxyConnection) conn;
try {
Method m = Connection.class.getMethod("createArrayOf", String.class, Object[].class);
Object[] args = { sqlTypeName, data };
array = (Array) proxy.rawConnectionOperation(m, C3P0ProxyConnection.RAW_CONNECTION, args);
} catch (Exception e) {
throw new SQLException(e);
}
} else {
array = conn.createArrayOf(sqlTypeName, data);
}
return array;
}
use of java.sql.Array in project phoenix by apache.
the class StatsCollectorIT method testUpdateStats.
@Test
public void testUpdateStats() throws SQLException, IOException, InterruptedException {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
conn = getConnection();
conn.createStatement().execute("CREATE TABLE " + fullTableName + " ( k VARCHAR, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4] \n" + " CONSTRAINT pk PRIMARY KEY (k, b_string_array DESC))" + tableDDLOptions);
String[] s;
Array array;
conn = upsertValues(props, fullTableName);
// CAll the update statistics query here. If already major compaction has run this will not get executed.
stmt = conn.prepareStatement("UPDATE STATISTICS " + fullTableName);
stmt.execute();
stmt = upsertStmt(conn, fullTableName);
stmt.setString(1, "z");
s = new String[] { "xyz", "def", "ghi", "jkll", null, null, "xxx" };
array = conn.createArrayOf("VARCHAR", s);
stmt.setArray(2, array);
s = new String[] { "zya", "def", "ghi", "jkll", null, null, null, "xxx" };
array = conn.createArrayOf("VARCHAR", s);
stmt.setArray(3, array);
stmt.execute();
stmt = conn.prepareStatement("UPDATE STATISTICS " + fullTableName);
stmt.execute();
rs = conn.createStatement().executeQuery("SELECT k FROM " + fullTableName);
assertTrue(rs.next());
conn.close();
}
use of java.sql.Array in project phoenix by apache.
the class StringToArrayConverterTest method testToArray_SingleElement.
@Test
public void testToArray_SingleElement() throws SQLException {
Array singleElementArray = converter.toArray("value");
assertArrayEquals(new Object[] { "value" }, (Object[]) singleElementArray.getArray());
}
use of java.sql.Array in project phoenix by apache.
the class ArrayIT method testPKWithDescArray.
@Test
public void testPKWithDescArray() throws Exception {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
long ts = nextTimestamp();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute("CREATE TABLE t ( a VARCHAR ARRAY PRIMARY KEY DESC)\n");
conn.close();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO t VALUES(?)");
Array a1 = conn.createArrayOf("VARCHAR", new String[] { "a", "ba" });
stmt.setArray(1, a1);
stmt.execute();
Array a2 = conn.createArrayOf("VARCHAR", new String[] { "a", "c" });
stmt.setArray(1, a2);
stmt.execute();
conn.commit();
conn.close();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT a FROM t ORDER BY a DESC");
assertTrue(rs.next());
assertEquals(a2, rs.getArray(1));
assertTrue(rs.next());
assertEquals(a1, rs.getArray(1));
assertFalse(rs.next());
conn.close();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 50));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO t VALUES(?)");
Array a3 = conn.createArrayOf("VARCHAR", new String[] { "a", "b" });
stmt.setArray(1, a3);
stmt.execute();
conn.commit();
conn.close();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT a FROM t ORDER BY a DESC");
assertTrue(rs.next());
assertEquals(a2, rs.getArray(1));
assertTrue(rs.next());
assertEquals(a1, rs.getArray(1));
assertTrue(rs.next());
assertEquals(a3, rs.getArray(1));
assertFalse(rs.next());
conn.close();
}
use of java.sql.Array in project phoenix by apache.
the class ArrayIT method testVarLengthArrComparisonWithNulls.
@Test
public void testVarLengthArrComparisonWithNulls() throws Exception {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
long ts = nextTimestamp();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute("CREATE TABLE t ( k VARCHAR PRIMARY KEY, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4])");
conn.close();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO t VALUES(?,?,?)");
stmt.setString(1, "a");
String[] s = new String[] { "abc", "def", "ghi", "jkll", null, null, "xxx" };
Array array = conn.createArrayOf("VARCHAR", s);
stmt.setArray(2, array);
s = new String[] { "abc", "def", "ghi", "jkll", null, null, null, "xxx" };
array = conn.createArrayOf("VARCHAR", s);
stmt.setArray(3, array);
stmt.execute();
conn.commit();
conn.close();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT k, a_string_array[2] FROM t where a_string_array>b_string_array");
assertTrue(rs.next());
assertEquals("a", rs.getString(1));
assertEquals("def", rs.getString(2));
conn.close();
}
Aggregations