return null; //throw new SQLException(L.l("table {0} does not exist", name));
}
String version = null;
ReadStream is = path.openRead();
try {
// skip allocation table and fragment table
is.skip(DATA_START + ROOT_DATA_OFFSET);
StringBuilder sb = new StringBuilder();
int ch;
while ((ch = is.read()) > 0) {
sb.append((char) ch);
}
version = sb.toString();
if (! version.startsWith("Resin-DB")) {
throw new SQLException(L.l("table {0} is not a Resin DB. Version '{1}'",
name, version));
}
else if (version.compareTo(MIN_VERSION) < 0 ||
DB_VERSION.compareTo(version) < 0) {
throw new SQLException(L.l("table {0} is out of date. Old version {1}.",
name, version));
}
} finally {
is.close();
}
is = path.openRead();
try {
// skip allocation table and fragment table
is.skip(DATA_START + ROOT_DATA_END);
StringBuilder cb = new StringBuilder();
int ch;
while ((ch = is.read()) > 0) {
cb.append((char) ch);
}
String sql = cb.toString();
if (log.isLoggable(Level.FINER))
log.finer("Table[" + name + "] " + version + " loading\n" + sql);
try {
CreateQuery query = (CreateQuery) Parser.parse(db, sql);
TableFactory factory = query.getFactory();
if (! factory.getName().equalsIgnoreCase(name))
throw new IOException(L.l("factory {0} does not match", name));
Table table = new Table(db, factory.getName(), factory.getRow(),
factory.getConstraints());
table.init();
//if (! table.validateIndexesSafe()) {
table.clearIndexes();
table.initIndexes();
table.rebuildIndexes();
//}
return table;
} catch (Exception e) {
log.log(Level.WARNING, e.toString(), e);
throw new SQLException(L.l("can't load table {0} in {1}.\n{2}",
name, path.getNativePath(), e.toString()));
}
} finally {
is.close();
}
}