long timeStamp = QueryConstants.UNSET_TIMESTAMP;
String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
PName tenantId = connection.getTenantId();
PTable theTable = null;
if (updateCacheImmediately || connection.getAutoCommit()) {
MetaDataMutationResult result = client.updateCache(schemaName, tableName);
timeStamp = result.getMutationTime();
theTable = result.getTable();
if (theTable == null) {
throw new TableNotFoundException(schemaName, tableName, timeStamp);
}
} else {
try {
theTable = connection.getMetaDataCache().getTable(new PTableKey(tenantId, fullTableName));
} catch (TableNotFoundException e1) {
if (tenantId != null) { // Check with null tenantId next
try {
theTable = connection.getMetaDataCache().getTable(new PTableKey(null, fullTableName));
} catch (TableNotFoundException e2) {
}
}
}
// We always attempt to update the cache in the event of a TableNotFoundException
if (theTable == null) {
MetaDataMutationResult result = client.updateCache(schemaName, tableName);
if (result.wasUpdated()) {
timeStamp = result.getMutationTime();
theTable = result.getTable();
}
}
if (theTable == null) {
throw new TableNotFoundException(schemaName, tableName, timeStamp);
}