/** * Retrieves an Index. * * @throws IndexNotFoundException if the index does not exist */ public Index getIndex(String name) throws IOException, IndexNotFoundException { HTableInterface table; try { table = new LocalHTable(hbaseConf, name); } catch (RuntimeException e) { if (e.getCause() != null && e.getCause() instanceof TableNotFoundException) { throw new IndexNotFoundException(name); } else { throw e; } } catch (TableNotFoundException e) { throw new IndexNotFoundException(name); } return instantiateIndex(name, table); }
private Index instantiateIndex(String name, HTableInterface table) throws IOException, IndexNotFoundException { byte[] jsonData; try { jsonData = table.getTableDescriptor().getValue(INDEX_META_KEY); } catch (RuntimeException e) { if (e.getCause() != null && e.getCause() instanceof TableNotFoundException) { throw new IndexNotFoundException(name); } else { throw e; } } catch (TableNotFoundException e) { throw new IndexNotFoundException(name); } if (jsonData == null) { throw new IOException("Not a valid index table: " + name); } IndexDefinition indexDef = deserialize(name, jsonData); return new Index(table, indexDef); }
} catch (RuntimeException e) { if (e.getCause() != null && e.getCause() instanceof TableNotFoundException) { throw new IndexNotFoundException(name); } else { throw e; throw new IndexNotFoundException(name);