if (!isCompatible(con, db))
{
String sDBName = con.getMetaData().getDatabaseProductName();
String sDBVersion = con.getMetaData().getDatabaseProductVersion();
throw new PersistenceException("err.persistence.adapterMismatch",
new Object[]{db.getName(), db.getAdapter().getName(),
(sDBVersion.contains(sDBName)) ? sDBVersion : (sDBName + " " + sDBVersion)});
}
stmt = con.prepareStatement(sSQL);
ResultSet rs = executeQuery(stmt);
if (!rs.next())
{
throw new PersistenceException("err.persistence.noStorageVersion",
new Object[]{db.getName()});
}
SchemaVersion version = new SchemaVersion();
version.setNamespace(Primitive.toString(getBind(namespaceColumn).getValue(rs, 0, this)));
version.setVersion(Primitive.toString(getBind(versionColumn).getValue(rs, 1, this)));
Integer step = Primitive.toInteger(getBind(stepColumn).getValue(rs, 2, this));
version.setStep((step == null) ? -1 : step.intValue());
Boolean upgradable = Primitive.toBoolean(getBind(upgradableColumn).getValue(rs, 3, this));
version.setUpgradable((upgradable == null) ? false : upgradable.booleanValue());
Boolean test = Primitive.toBoolean(getBind(testColumn).getValue(rs, 4, this));
version.setTest((test == null) ? false : test.booleanValue());
// has to be done while still have data in ResultSet on DB2
Boolean unicode = isUnicode((RelationalSchema)schema, rs, 1); // 1 == "namespace" column
boolean bUnicode = db.isUnicode();
if (unicode == null)
{
throw new PersistenceException(
"err.persistence.sql.unicodeUnknown",
new Object[]{db.getName(), Boolean.valueOf(bUnicode)});
}
if (unicode.booleanValue() != bUnicode)
{
throw new PersistenceException(
"err.persistence.sql.unicodeMismatch",
new Object[]{db.getName(), Boolean.valueOf(bUnicode)});
}
if (rs.next())
{
throw new PersistenceException("err.persistence.ambiguousStorageVersion",
new Object[]{db.getName()});
}
return version;
}
catch (SQLException e)
{
throw new PersistenceException("err.persistence.checkVersion",
new Object[]{db.getName()}, e);
}
finally
{
close(stmt);