@Test public void getTableMetadataOnUnexistentTable() { final Session session = mock(Session.class); final Cluster cluster = mock(Cluster.class); final Metadata metadata = mock(Metadata.class); final KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class); when(session.getCluster()).thenReturn(cluster); when(cluster.getMetadata()).thenReturn(metadata); when(metadata.getKeyspace("keyspace")).thenReturn(keyspaceMetadata); when(keyspaceMetadata.getTable("table")).thenReturn(null); thrown.expect(IllegalStateException.class); thrown.expectMessage("Table keyspace.table does not exist"); CassandraUtils.getTableMetadata(session, "keyspace", "table"); }
public static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table) { Preconditions.checkNotNull(session); Preconditions.checkNotNull(keyspace); Preconditions.checkNotNull(table); final KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new IllegalStateException(String.format("Keyspace %s does not exist", keyspace)); } final TableMetadata tableMetadata = keyspaceMetadata.getTable(table); if (tableMetadata == null) { throw new IllegalStateException(String.format("Table %s.%s does not exist", keyspace, table)); } return tableMetadata; }
CassandraUtils { public static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table) { Preconditions.checkNotNull(session); Preconditions.checkNotNull(keyspace); Preconditions.checkNotNull(table); final KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new IllegalStateException(String.format("Keyspace %s does not exist", keyspace)); } final TableMetadata tableMetadata = keyspaceMetadata.getTable(table); if (tableMetadata == null) { throw new IllegalStateException(String.format("Table %s.%s does not exist", keyspace, table)); } return tableMetadata; } }
CassandraUtils { public static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table) { Preconditions.checkNotNull(session); Preconditions.checkNotNull(keyspace); Preconditions.checkNotNull(table); final KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new IllegalStateException(String.format("Keyspace %s does not exist", keyspace)); } final TableMetadata tableMetadata = keyspaceMetadata.getTable(table); if (tableMetadata == null) { throw new IllegalStateException(String.format("Table %s.%s does not exist", keyspace, table)); } return tableMetadata; } private  CassandraUtils(); }
CassandraUtils { public static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table) { Preconditions.checkNotNull(session); Preconditions.checkNotNull(keyspace); Preconditions.checkNotNull(table); final KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new IllegalStateException(String.format("Keyspace %s does not exist", keyspace)); } final TableMetadata tableMetadata = keyspaceMetadata.getTable(table); if (tableMetadata == null) { throw new IllegalStateException(String.format("Table %s.%s does not exist", keyspace, table)); } return tableMetadata; } private  CassandraUtils(); static void executeCqlScript(final Session session, final String script); static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table); static Object parseValue(final DataType type, final String value); }
CassandraUtils { public static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table) { Preconditions.checkNotNull(session); Preconditions.checkNotNull(keyspace); Preconditions.checkNotNull(table); final KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new IllegalStateException(String.format("Keyspace %s does not exist", keyspace)); } final TableMetadata tableMetadata = keyspaceMetadata.getTable(table); if (tableMetadata == null) { throw new IllegalStateException(String.format("Table %s.%s does not exist", keyspace, table)); } return tableMetadata; } private  CassandraUtils(); static void executeCqlScript(final Session session, final String script); static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table); static Object parseValue(final DataType type, final String value);  }