st.setString(3, "prova");
st.setString(4, "test");
st.setLong(5, 1L); // loop only once
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
rs.close();
st.close();
log.fine("The return value of the query '" + sql + "' is '" + new String(buf) + "'");
assertEquals(sql, "<col name=\"test\"><![CDATA[prova]]></col>", new String(buf));
}
{
// col2xml_base64(?, ?)
sql = "{? = call " + this.replPrefix + "test_blob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "COL2XML_BASE64");
st.setBytes(3, "prova".getBytes());
st.setString(4, "test");
st.setLong(5, 1L); // loop only once
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
rs.close();
st.close();
log.fine("The return value of the query '" + sql + "' is '" + new String(buf) + "'");
assertEquals(sql, "<col name=\"test\" encoding=\"base64\">cHJvdmE=</col>", new String(buf));
String tmp = extractBase64Part(new String(buf));
byte[] ret = org.xmlBlaster.util.Base64.decode(tmp);
String returnName = new String(ret);
assertEquals("The returned (decoded) String is checked", "prova", returnName);
}
{
// col2xml_base64(?, ?) CONTENTS BIGGER THAN 4 kB
sql = "{? = call " + this.replPrefix + "test_blob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "COL2XML_BASE64");
int nmax = 256;
byte[] blob = new byte[nmax];
for (int i=0; i < nmax; i++)
blob[i] = (byte)i;
st.setBytes(3, blob);
st.setString(4, "test");
st.setLong(5, (long)nmax); // loop multiple times to simulate big contents
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
rs.close();
st.close();
String tmp = extractBase64Part(new String(buf));
byte[] ret = org.xmlBlaster.util.Base64.decode(tmp);
assertEquals("Comparison of lenght of input blob with output blob", nmax * nmax, ret.length);
log.fine("success");
}
// now testing the " + this.replPrefix + "needs_prot for the three cases ...
{ // needs no protection needs_prot(?)
sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "NEEDS_PROT");
st.setString(3, "prova");
st.setString(4, "unused");
st.setLong(5, 1L);
// st.registerOutParameter(1, Types.INTEGER);
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
// int ret = st.getInt(1);
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
String txt = new String(buf);
log.fine("The return value of the query '" + sql + "' is '" + txt + "'");
int ret = -1000;
try {
ret = Integer.parseInt(txt);
}
catch (Throwable e) {
assertTrue("Conversion exception should not occur on '" + sql + "' where ret is '" + txt + "'", false);
}
rs.close();
st.close();
assertEquals(sql, 0, ret);
}
{ // needs BASE64 needs_prot(?)
sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "NEEDS_PROT");
st.setString(3, "<![[CDATAsome text]]>");
st.setString(4, "unused");
st.setLong(5, 1L);
// st.registerOutParameter(1, Types.INTEGER);
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
// int ret = st.getInt(1);
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
String txt = new String(buf);
log.fine("The return value of the query '" + sql + "' is '" + txt + "'");
int ret = -1000;
try {
ret = Integer.parseInt(txt);
}
catch (Throwable e) {
assertTrue("Conversion exception should not occur on '" + sql + "' where ret is '" + txt + "'", false);
}
rs.close();
st.close();
assertEquals(sql, 2, ret);
}
{ // needs CDATA needs_prot(?)
sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "NEEDS_PROT");
st.setString(3, "this is a <a");
st.setString(4, "unused");
st.setLong(5, 1L);
// st.registerOutParameter(1, Types.INTEGER);
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
// int ret = st.getInt(1);
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
String txt = new String(buf);
log.fine("The return value of the query '" + sql + "' is '" + txt + "'");
int ret = -1000;
try {
ret = Integer.parseInt(txt);
}
catch (Throwable e) {
assertTrue("Conversion exception should not occur on '" + sql + "' where ret is '" + txt + "'", false);
}
rs.close();
st.close();
assertEquals(sql, 1, ret);
}
{ // needs CDATA needs_prot(?)
sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "NEEDS_PROT");
st.setString(3, "<this is a");
st.setString(4, "unused");
st.setLong(5, 1L);
// st.registerOutParameter(1, Types.INTEGER);
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
// int ret = st.getInt(1);
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
String txt = new String(buf);
log.fine("The return value of the query '" + sql + "' is '" + txt + "'");
int ret = -1000;
try {
ret = Integer.parseInt(txt);
}
catch (Throwable e) {
assertTrue("Conversion exception should not occur on '" + sql + "' where ret is '" + txt + "'", false);
}
rs.close();
st.close();
assertEquals(sql, 1, ret);
}
{ // needs CDATA needs_prot(?)
sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "NEEDS_PROT");
st.setString(3, "a<this is a");
st.setString(4, "unused");
st.setLong(5, 1L);
// st.registerOutParameter(1, Types.INTEGER);
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
// int ret = st.getInt(1);
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
String txt = new String(buf);
log.fine("The return value of the query '" + sql + "' is '" + txt + "'");
int ret = -1000;
try {
ret = Integer.parseInt(txt);
}
catch (Throwable e) {
assertTrue("Conversion exception should not occur on '" + sql + "' where ret is '" + txt + "'", false);
}
rs.close();
st.close();
assertEquals(sql, 1, ret);
}
// now testing the " + this.replPrefix + "needs_prot for the three cases ...
{ // needs no protection
// col2xml(?, ?)
sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "COL2XML");
st.setString(3, "colValue");
st.setString(4, "colName");
st.setLong(5, 1L);
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
rs.close();
st.close();
log.fine("The return value of the query '" + sql + "' is '" + new String(buf) + "'");
assertEquals(sql, "<col name=\"colName\">colValue</col>", new String(buf));
}
{ // col2xml(?, ?)
sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "COL2XML");
st.setString(3, "prova");
st.setString(4, "test");
st.setLong(5, 1L);
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
rs.close();
st.close();
log.fine("The return value of the query '" + sql + "' is '" + new String(buf) + "'");
assertEquals(sql, "<col name=\"test\">prova</col>", new String(buf));
}
{ // needs BASE64 col2xml(?, ?)
sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "COL2XML");
st.setString(3, "<![CDATA[colValue]]>");
st.setString(4, "colName");
st.setLong(5, 1L);
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
rs.close();
st.close();
log.fine("The return value of the query '" + sql + "' is '" + new String(buf) + "'");
assertEquals(sql, "<col name=\"colName\" encoding=\"base64\">PCFbQ0RBVEFbY29sVmFsdWVdXT4=</col>", new String(buf));
}
{ // needs CDATA col2xml(?, ?)
sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
CallableStatement st = conn.prepareCall(sql);
st.setString(2, "COL2XML");
st.setString(3, "c<olValue");
st.setString(4, "colName");
st.setLong(5, 1L);
st.registerOutParameter(1, Types.CLOB);
ResultSet rs = st.executeQuery();
Clob clob = st.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
rs.close();
st.close();
log.fine("The return value of the query '" + sql + "' is '" + new String(buf) + "'");
assertEquals(sql, "<col name=\"colName\"><![CDATA[c<olValue]]></col>", new String(buf));
}
// now test the counter ... (this invocation is used in SpecificDefault.incrementReplKey
{
long oldVal = 0;
for (int i=0; i < 2; i++) {
// sql = "{? = call nextval('repl_seq')}";
sql = "{? = call " + this.replPrefix + "increment()}";
CallableStatement st = conn.prepareCall(sql);
// st.registerOutParameter(1, Types.BIGINT);
st.registerOutParameter(1, Types.INTEGER);
ResultSet rs = st.executeQuery();
// long ret = st.getLong(1);
long ret = st.getLong(1);
rs.close();
st.close();
log.fine("The return value of the query '" + sql + "' is '" + ret + "'. The maximum integer value is '" + Integer.MAX_VALUE + "'");
if (i == 0)
oldVal = ret;
else
assertEquals(sql, oldVal + i , ret);
}
}
{ // tests that by broadcast statements they are written in the ITEMS table
// make sure there is nothing in the ITEMS table
sql = "DELETE FROM " + this.dbHelper.getIdentifier(this.replPrefix + "ITEMS");
this.pool.update(sql);
sql = "SELECT * FROM " + this.dbHelper.getIdentifier(this.replPrefix + "ITEMS");
long maxResponseEntries = 10L;
boolean isHighPrio = true;
boolean isMaster = false;
String sqlTopic = null;
String statementId = "1";
this.dbSpecific.broadcastStatement(sql, maxResponseEntries, isHighPrio, isMaster, sqlTopic, statementId);
Statement st = conn.createStatement();
try {
ResultSet rs = st.executeQuery("SELECT content FROM " + this.dbHelper.getIdentifier(this.replPrefix + "ITEMS"));
if (rs.next()) {
Clob clob = rs.getClob(1);
long len = clob.length();
byte[] buf = new byte[(int)len];
clob.getAsciiStream().read(buf);
String txt = new String(buf);
log.info("The statement to broadcast is '" + txt + "'");
assertFalse("There must not be any results after a SELECT statement to broadcast", rs.next());
}
else