@Override public Object execute(Statement statement, Class<?> type) { return operations.select(statement, type); } }
@Override @SuppressWarnings("unchecked") public Object execute(Statement statement, Class<?> type) { List<Object> objects = operations.select(statement, (Class) type); if (objects.isEmpty()) { return null; } if (objects.size() == 1 || limiting) { return objects.get(0); } throw new IncorrectResultSizeDataAccessException(1, objects.size()); } }
@Override public List<T> findAllById(Iterable<ID> ids) { Assert.notNull(ids, "The given Iterable of id's must not be null"); List<ID> idCollection = Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()); return operations.select(Query.query(where(entityInformation.getIdAttribute()).in(idCollection)), entityInformation.getJavaType()); }
@Override public List<T> findAll() { Select select = QueryBuilder.select().all().from(entityInformation.getTableName().toCql()); return operations.select(select, entityInformation.getJavaType()); }
@Test public void testCassandraBatchIngest() { List<Book> books = BookSampler.getBookList(5); List<List<?>> ingestBooks = new ArrayList<>(); for (Book b : books) { List<Object> l = new ArrayList<>(); l.add(b.getIsbn()); l.add(b.getTitle()); l.add(b.getAuthor()); l.add(b.getPages()); l.add(b.getSaleDate()); l.add(b.isInStock()); ingestBooks.add(l); } Message<List<List<?>>> message = MessageBuilder.withPayload(ingestBooks).build(); this.cassandraMessageHandler3.handleMessage(message); Select select = QueryBuilder.select().all().from("book"); books = this.template.select(select, Book.class); assertThat(books).hasSize(5); this.template.batchOps().delete(books); }
@Test public void testBasicCassandraInsert() { Book b1 = new Book(); b1.setIsbn("123456-1"); b1.setTitle("Spring Integration Cassandra"); b1.setAuthor("Cassandra Guru"); b1.setPages(521); b1.setSaleDate(new Date()); b1.setInStock(true); Message<Book> message = MessageBuilder.withPayload(b1).build(); this.cassandraMessageHandler1.handleMessage(message); Select select = QueryBuilder.select().all().from("book"); List<Book> books = this.template.select(select, Book.class); assertThat(books).hasSize(1); this.template.delete(b1); }