null, -1, 0, false, Query.SEC_NONE, m_context).read().size());
}
public void testSchemaUnicodeValidation() throws Exception
{
RelationalSchema schema = (RelationalSchema)m_database.getSchema();
Table origVersionTable = schema.getVersionTable(); // note original
Table versionTable = schema.getTable("Version");
RelationalDatabase origDS = (RelationalDatabase)schema.getDataSource();
RelationalDatabase ds = (RelationalDatabase)origDS.clone();
try
{
schema.setDataSource(ds);
schema.setVersionTable(versionTable);
try
{
m_adapter.getVersion(schema); // one of getVersion() has to throw exception
ds.setUnicode(!ds.isUnicode()); // try the oposite Unicode flag
m_adapter.getVersion(schema); // one of getVersion() has to throw exception
fail("Unicode flag validation exception expected.");
}
catch (UncheckedException e)
{
// test online upgrade prevention
assertEquals("err.persistence.sql.unicodeMismatch", e.getErrorCode());
}
// ensure correct result was provided as per the created schema
SQLConnection con = m_adapter.getConnection();
Statement stmt = null;
ResultSet rs = null;
try
{
stmt = con.getConnection().createStatement();
rs = stmt.executeQuery(
"select namespace from " +
versionTable.getFullName(m_adapter.createSchemaManager().getOwner()));
// 1 == the namespace column
assertEquals(Boolean.valueOf(origDS.isUnicode()), m_adapter.isUnicode(schema, rs, 1));
}
finally
{
try
{
if (rs != null)
{
rs.close();
}
}
catch (Throwable t)
{}
try
{
if (stmt != null)
{
stmt.close();
}
}
catch (Throwable t)
{}
con.decRef();
}
StringWriter writer = new StringWriter();
SQLSchemaManager manager = m_adapter.createSchemaManager();
manager.setSQLAppender(manager.new SQLWriterAppender(writer));
manager.upgrade(schema);
// test offline upgrade script guard generation
assertTrue(writer.toString().contains(getUnicodeCheckGuard(ds.isUnicode())));
ds.setUnicode(!ds.isUnicode()); // try the oposite Unicode flag
writer = new StringWriter();
manager.setSQLAppender(manager.new SQLWriterAppender(writer));
manager.upgrade(schema);
// test offline upgrade script guard generation
assertTrue(writer.toString().contains(getUnicodeCheckGuard(ds.isUnicode())));
}
finally
{
schema.setVersionTable(origVersionTable); // reset so testUpgrade() will not fail
schema.setDataSource(origDS); // reset to original
}
}