@Test public void testExecute() throws Exception { session.execute(createTestTableStatement); RegularStatement statement = QueryBuilder.select() .from(keyspace, "test") .where(QueryBuilder.eq("id", QueryBuilder.bindMarker())); PreparedStatement prepared = session.prepare(statement); BoundStatement bound = prepared.bind("123"); ResultSet rs = session.execute(bound); assertNotNull(rs); testComplete(); }
if (keyspaceMetadata != null) { for (TableMetadata tableMetadata : keyspaceMetadata.getTables()) { session.execute(TableBuilder.drop(keyspace, tableMetadata.getName()).ifExists());
.primaryKey("col1"); session.execute(statement); session.execute(statement); fail("Table already exists, create should have throw AlreadyExistsException"); } catch (QueryValidationException e) { .primaryKey("col1"); session.execute(statement); session.execute(alterTable); session.execute(statement); session.execute(statement); session.execute(statement); fail("Table should not exist, drop should have throw InvalidQueryException"); } catch (QueryValidationException e) {
private void createKeyspace(Metadata metadata) { Statement createKeyspaceStatement = null; // Find out which node is closest and use that for the networktopologystrategy LoadBalancingPolicy lbPolicy = session.getCluster().getConfiguration().getPolicies().getLoadBalancingPolicy(); for (Host host : metadata.getAllHosts()) { if (lbPolicy.distance(host) == HostDistance.LOCAL) { createKeyspaceStatement = KeyspaceBuilder.create(keyspace) .ifNotExists() .networkTopologyStrategy() .dc(host.getDatacenter(), 1); break; } } if (createKeyspaceStatement == null) { fail("Could not find a local host for the test"); return; } session.execute(createKeyspaceStatement); }