diff --git a/spring-data-cassandra/.classpath b/spring-data-cassandra/.classpath new file mode 100644 index 000000000000..698778fef337 --- /dev/null +++ b/spring-data-cassandra/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-data-cassandra/.project b/spring-data-cassandra/.project new file mode 100644 index 000000000000..239fa4f00275 --- /dev/null +++ b/spring-data-cassandra/.project @@ -0,0 +1,29 @@ + + + spring-data-cassandra + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/config/CassandraConfig.java b/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/config/CassandraConfig.java index 5f2c4c6d477d..2edd5551a5a7 100644 --- a/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/config/CassandraConfig.java +++ b/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/config/CassandraConfig.java @@ -17,8 +17,8 @@ @PropertySource(value = { "classpath:cassandra.properties" }) @EnableCassandraRepositories(basePackages = "org.baeldung.spring.data.cassandra.repository") public class CassandraConfig extends AbstractCassandraConfiguration { - private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class); + @Autowired private Environment environment; @@ -27,15 +27,17 @@ protected String getKeyspaceName() { return environment.getProperty("cassandra.keyspace"); } + @Override @Bean public CassandraClusterFactoryBean cluster() { - CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); + final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); cluster.setContactPoints(environment.getProperty("cassandra.contactpoints")); cluster.setPort(Integer.parseInt(environment.getProperty("cassandra.port"))); LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "& port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "]."); return cluster; } + @Override @Bean public CassandraMappingContext cassandraMapping() throws ClassNotFoundException { return new BasicCassandraMappingContext(); diff --git a/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/model/Book.java b/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/model/Book.java index 6c099d99bc7b..a8ec81d6b583 100644 --- a/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/model/Book.java +++ b/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/model/Book.java @@ -1,28 +1,31 @@ package org.baeldung.spring.data.cassandra.model; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + import org.springframework.cassandra.core.Ordering; import org.springframework.cassandra.core.PrimaryKeyType; import org.springframework.data.cassandra.mapping.Column; import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; import org.springframework.data.cassandra.mapping.Table; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - @Table public class Book { + @PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING) private UUID id; + @PrimaryKeyColumn(name = "title", ordinal = 1, type = PrimaryKeyType.PARTITIONED) private String title; @PrimaryKeyColumn(name = "publisher", ordinal = 2, type = PrimaryKeyType.PARTITIONED) private String publisher; + @Column private Set tags = new HashSet<>(); - public Book(UUID id, String title, String publisher, Set tags) { + public Book(final UUID id, final String title, final String publisher, final Set tags) { this.id = id; this.title = title; this.publisher = publisher; @@ -45,19 +48,20 @@ public Set getTags() { return tags; } - public void setId(UUID id) { + public void setId(final UUID id) { this.id = id; } - public void setTitle(String title) { + public void setTitle(final String title) { this.title = title; } - public void setPublisher(String publisher) { + public void setPublisher(final String publisher) { this.publisher = publisher; } - public void setTags(Set tags) { + public void setTags(final Set tags) { this.tags = tags; } + } diff --git a/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/repository/BookRepository.java b/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/repository/BookRepository.java index e37ae78b595b..66d656ac3a0f 100644 --- a/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/repository/BookRepository.java +++ b/spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/repository/BookRepository.java @@ -7,6 +7,8 @@ @Repository public interface BookRepository extends CassandraRepository { + @Query("select * from book where title = ?0 and publisher=?1") Iterable findByTitleAndPublisher(String title, String publisher); + } diff --git a/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/BookRepositoryIntegrationTest.java b/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/BookRepositoryIntegrationTest.java index e5a723714531..8cbcdc3195ac 100644 --- a/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/BookRepositoryIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/BookRepositoryIntegrationTest.java @@ -1,9 +1,11 @@ package org.baeldung.spring.data.cassandra.repository; -import com.datastax.driver.core.Cluster; -import com.datastax.driver.core.Session; -import com.datastax.driver.core.utils.UUIDs; -import com.google.common.collect.ImmutableSet; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.io.IOException; +import java.util.HashMap; + import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -11,7 +13,11 @@ import org.baeldung.spring.data.cassandra.config.CassandraConfig; import org.baeldung.spring.data.cassandra.model.Book; import org.cassandraunit.utils.EmbeddedCassandraServerHelper; -import org.junit.*; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cassandra.core.cql.CqlIdentifier; @@ -19,16 +25,14 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.io.IOException; -import java.util.HashMap; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.utils.UUIDs; +import com.google.common.collect.ImmutableSet; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = CassandraConfig.class) public class BookRepositoryIntegrationTest { - private static final Log LOGGER = LogFactory.getLog(BookRepositoryIntegrationTest.class); public static final String KEYSPACE_CREATION_QUERY = "CREATE KEYSPACE IF NOT EXISTS testKeySpace WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' };"; @@ -43,13 +47,14 @@ public class BookRepositoryIntegrationTest { @Autowired private CassandraAdminOperations adminTemplate; + // + @BeforeClass public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException { EmbeddedCassandraServerHelper.startEmbeddedCassandra(); - Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1") - .withPort(9142).build(); + final Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build(); LOGGER.info("Server Started at 127.0.0.1:9142... "); - Session session = cluster.connect(); + final Session session = cluster.connect(); session.execute(KEYSPACE_CREATION_QUERY); session.execute(KEYSPACE_ACTIVATE_QUERY); LOGGER.info("KeySpace created and activated."); @@ -63,54 +68,54 @@ public void createTable() throws InterruptedException, TTransportException, Conf @Test public void whenSavingBook_thenAvailableOnRetrieval() { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", - "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); bookRepository.save(ImmutableSet.of(javaBook)); - Iterable books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media"); + final Iterable books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media"); assertEquals(javaBook.getId(), books.iterator().next().getId()); } @Test public void whenUpdatingBooks_thenAvailableOnRetrieval() { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); bookRepository.save(ImmutableSet.of(javaBook)); - Iterable books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media"); + final Iterable books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media"); javaBook.setTitle("Head First Java Second Edition"); bookRepository.save(ImmutableSet.of(javaBook)); - Iterable updateBooks = bookRepository.findByTitleAndPublisher("Head First Java Second Edition", "O'Reilly Media"); + final Iterable updateBooks = bookRepository.findByTitleAndPublisher("Head First Java Second Edition", "O'Reilly Media"); assertEquals(javaBook.getTitle(), updateBooks.iterator().next().getTitle()); } @Test(expected = java.util.NoSuchElementException.class) public void whenDeletingExistingBooks_thenNotAvailableOnRetrieval() { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); bookRepository.save(ImmutableSet.of(javaBook)); bookRepository.delete(javaBook); - Iterable books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media"); + final Iterable books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media"); assertNotEquals(javaBook.getId(), books.iterator().next().getId()); } @Test public void whenSavingBooks_thenAllShouldAvailableOnRetrieval() { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", - "O'Reilly Media", ImmutableSet.of("Computer", "Software")); - Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", - "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); bookRepository.save(ImmutableSet.of(javaBook)); bookRepository.save(ImmutableSet.of(dPatternBook)); - Iterable books = bookRepository.findAll(); + final Iterable books = bookRepository.findAll(); int bookCount = 0; - for (Book book : books) bookCount++; + for (final Book book : books) { + bookCount++; + } assertEquals(bookCount, 2); } @After public void dropTable() { - adminTemplate.dropTable(CqlIdentifier.cqlId(DATA_TABLE_NAME)); + adminTemplate.dropTable(CqlIdentifier.cqlId(DATA_TABLE_NAME)); } @AfterClass public static void stopCassandraEmbedded() { EmbeddedCassandraServerHelper.cleanEmbeddedCassandra(); } + } diff --git a/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/CQLQueriesIntegrationTest.java b/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/CQLQueriesIntegrationTest.java index 031b5c0b6f1b..584d5f868b5c 100644 --- a/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/CQLQueriesIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/CQLQueriesIntegrationTest.java @@ -1,12 +1,13 @@ package org.baeldung.spring.data.cassandra.repository; -import com.datastax.driver.core.Cluster; -import com.datastax.driver.core.Session; -import com.datastax.driver.core.querybuilder.Insert; -import com.datastax.driver.core.querybuilder.QueryBuilder; -import com.datastax.driver.core.querybuilder.Select; -import com.datastax.driver.core.utils.UUIDs; -import com.google.common.collect.ImmutableSet; +import static junit.framework.TestCase.assertEquals; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -14,7 +15,11 @@ import org.baeldung.spring.data.cassandra.config.CassandraConfig; import org.baeldung.spring.data.cassandra.model.Book; import org.cassandraunit.utils.EmbeddedCassandraServerHelper; -import org.junit.*; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cassandra.core.cql.CqlIdentifier; @@ -23,18 +28,17 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; - -import static junit.framework.TestCase.assertEquals; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.querybuilder.Insert; +import com.datastax.driver.core.querybuilder.QueryBuilder; +import com.datastax.driver.core.querybuilder.Select; +import com.datastax.driver.core.utils.UUIDs; +import com.google.common.collect.ImmutableSet; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = CassandraConfig.class) public class CQLQueriesIntegrationTest { - private static final Log LOGGER = LogFactory.getLog(CQLQueriesIntegrationTest.class); public static final String KEYSPACE_CREATION_QUERY = "CREATE KEYSPACE IF NOT EXISTS testKeySpace " + "WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' };"; @@ -49,12 +53,14 @@ public class CQLQueriesIntegrationTest { @Autowired private CassandraOperations cassandraTemplate; + // + @BeforeClass public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException { EmbeddedCassandraServerHelper.startEmbeddedCassandra(25000); - Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build(); + final Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build(); LOGGER.info("Server Started at 127.0.0.1:9142... "); - Session session = cluster.connect(); + final Session session = cluster.connect(); session.execute(KEYSPACE_CREATION_QUERY); session.execute(KEYSPACE_ACTIVATE_QUERY); LOGGER.info("KeySpace created and activated."); @@ -68,40 +74,40 @@ public void createTable() throws InterruptedException, TTransportException, Conf @Test public void whenSavingBook_thenAvailableOnRetrieval_usingQueryBuilder() { - UUID uuid = UUIDs.timeBased(); - Insert insert = QueryBuilder.insertInto(DATA_TABLE_NAME).value("id", uuid).value("title", "Head First Java").value("publisher", "OReilly Media").value("tags", ImmutableSet.of("Software")); + final UUID uuid = UUIDs.timeBased(); + final Insert insert = QueryBuilder.insertInto(DATA_TABLE_NAME).value("id", uuid).value("title", "Head First Java").value("publisher", "OReilly Media").value("tags", ImmutableSet.of("Software")); cassandraTemplate.execute(insert); - Select select = QueryBuilder.select().from("book").limit(10); - Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); + final Select select = QueryBuilder.select().from("book").limit(10); + final Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); assertEquals(uuid, retrievedBook.getId()); } @Test public void whenSavingBook_thenAvailableOnRetrieval_usingCQLStatements() { - UUID uuid = UUIDs.timeBased(); - String insertCql = "insert into book (id, title, publisher, tags) values " + "(" + uuid + ", 'Head First Java', 'OReilly Media', {'Software'})"; + final UUID uuid = UUIDs.timeBased(); + final String insertCql = "insert into book (id, title, publisher, tags) values " + "(" + uuid + ", 'Head First Java', 'OReilly Media', {'Software'})"; cassandraTemplate.execute(insertCql); - Select select = QueryBuilder.select().from("book").limit(10); - Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); + final Select select = QueryBuilder.select().from("book").limit(10); + final Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); assertEquals(uuid, retrievedBook.getId()); } @Test public void whenSavingBook_thenAvailableOnRetrieval_usingPreparedStatements() throws InterruptedException { - UUID uuid = UUIDs.timeBased(); - String insertPreparedCql = "insert into book (id, title, publisher, tags) values (?, ?, ?, ?)"; - List singleBookArgsList = new ArrayList<>(); - List> bookList = new ArrayList<>(); + final UUID uuid = UUIDs.timeBased(); + final String insertPreparedCql = "insert into book (id, title, publisher, tags) values (?, ?, ?, ?)"; + final List singleBookArgsList = new ArrayList<>(); + final List> bookList = new ArrayList<>(); singleBookArgsList.add(uuid); singleBookArgsList.add("Head First Java"); singleBookArgsList.add("OReilly Media"); singleBookArgsList.add(ImmutableSet.of("Software")); bookList.add(singleBookArgsList); cassandraTemplate.ingest(insertPreparedCql, bookList); - //This may not be required, just added to avoid any transient issues + // This may not be required, just added to avoid any transient issues Thread.sleep(5000); - Select select = QueryBuilder.select().from("book"); - Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); + final Select select = QueryBuilder.select().from("book"); + final Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); assertEquals(uuid, retrievedBook.getId()); } @@ -114,4 +120,5 @@ public void dropTable() { public static void stopCassandraEmbedded() { EmbeddedCassandraServerHelper.cleanEmbeddedCassandra(); } + } diff --git a/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/CassandraTemplateIntegrationTest.java b/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/CassandraTemplateIntegrationTest.java index 35de50864197..e331ac3cd409 100644 --- a/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/CassandraTemplateIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/baeldung/spring/data/cassandra/repository/CassandraTemplateIntegrationTest.java @@ -1,11 +1,15 @@ package org.baeldung.spring.data.cassandra.repository; -import com.datastax.driver.core.Cluster; -import com.datastax.driver.core.Session; -import com.datastax.driver.core.querybuilder.QueryBuilder; -import com.datastax.driver.core.querybuilder.Select; -import com.datastax.driver.core.utils.UUIDs; -import com.google.common.collect.ImmutableSet; +import static junit.framework.TestCase.assertNull; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -13,7 +17,11 @@ import org.baeldung.spring.data.cassandra.config.CassandraConfig; import org.baeldung.spring.data.cassandra.model.Book; import org.cassandraunit.utils.EmbeddedCassandraServerHelper; -import org.junit.*; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cassandra.core.cql.CqlIdentifier; @@ -22,20 +30,16 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import static junit.framework.TestCase.assertNull; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.querybuilder.QueryBuilder; +import com.datastax.driver.core.querybuilder.Select; +import com.datastax.driver.core.utils.UUIDs; +import com.google.common.collect.ImmutableSet; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = CassandraConfig.class) public class CassandraTemplateIntegrationTest { - private static final Log LOGGER = LogFactory.getLog(CassandraTemplateIntegrationTest.class); public static final String KEYSPACE_CREATION_QUERY = "CREATE KEYSPACE IF NOT EXISTS testKeySpace " + "WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' };"; @@ -50,12 +54,14 @@ public class CassandraTemplateIntegrationTest { @Autowired private CassandraOperations cassandraTemplate; + // + @BeforeClass public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException { EmbeddedCassandraServerHelper.startEmbeddedCassandra(); - Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build(); + final Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build(); LOGGER.info("Server Started at 127.0.0.1:9142... "); - Session session = cluster.connect(); + final Session session = cluster.connect(); session.execute(KEYSPACE_CREATION_QUERY); session.execute(KEYSPACE_ACTIVATE_QUERY); LOGGER.info("KeySpace created and activated."); @@ -69,24 +75,24 @@ public void createTable() throws InterruptedException, TTransportException, Conf @Test public void whenSavingBook_thenAvailableOnRetrieval() { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); cassandraTemplate.insert(javaBook); - Select select = QueryBuilder.select().from("book").where(QueryBuilder.eq("title", "Head First Java")).and(QueryBuilder.eq("publisher", "O'Reilly Media")).limit(10); - Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); + final Select select = QueryBuilder.select().from("book").where(QueryBuilder.eq("title", "Head First Java")).and(QueryBuilder.eq("publisher", "O'Reilly Media")).limit(10); + final Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); assertEquals(javaBook.getId(), retrievedBook.getId()); } @Test public void whenSavingBooks_thenAllAvailableOnRetrieval() { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); - Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); - List bookList = new ArrayList<>(); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final List bookList = new ArrayList<>(); bookList.add(javaBook); bookList.add(dPatternBook); cassandraTemplate.insert(bookList); - Select select = QueryBuilder.select().from("book").limit(10); - List retrievedBooks = cassandraTemplate.select(select, Book.class); + final Select select = QueryBuilder.select().from("book").limit(10); + final List retrievedBooks = cassandraTemplate.select(select, Book.class); assertThat(retrievedBooks.size(), is(2)); assertEquals(javaBook.getId(), retrievedBooks.get(0).getId()); assertEquals(dPatternBook.getId(), retrievedBooks.get(1).getId()); @@ -94,45 +100,45 @@ public void whenSavingBooks_thenAllAvailableOnRetrieval() { @Test public void whenUpdatingBook_thenShouldUpdatedOnRetrieval() { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); cassandraTemplate.insert(javaBook); - Select select = QueryBuilder.select().from("book").limit(10); - Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); + final Select select = QueryBuilder.select().from("book").limit(10); + final Book retrievedBook = cassandraTemplate.selectOne(select, Book.class); retrievedBook.setTags(ImmutableSet.of("Java", "Programming")); cassandraTemplate.update(retrievedBook); - Book retrievedUpdatedBook = cassandraTemplate.selectOne(select, Book.class); + final Book retrievedUpdatedBook = cassandraTemplate.selectOne(select, Book.class); assertEquals(retrievedBook.getTags(), retrievedUpdatedBook.getTags()); } @Test public void whenDeletingASelectedBook_thenNotAvailableOnRetrieval() throws InterruptedException { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "OReilly Media", ImmutableSet.of("Computer", "Software")); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "OReilly Media", ImmutableSet.of("Computer", "Software")); cassandraTemplate.insert(javaBook); cassandraTemplate.delete(javaBook); - Select select = QueryBuilder.select().from("book").limit(10); - Book retrievedUpdatedBook = cassandraTemplate.selectOne(select, Book.class); + final Select select = QueryBuilder.select().from("book").limit(10); + final Book retrievedUpdatedBook = cassandraTemplate.selectOne(select, Book.class); assertNull(retrievedUpdatedBook); } @Test public void whenDeletingAllBooks_thenNotAvailableOnRetrieval() { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); - Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); cassandraTemplate.insert(javaBook); cassandraTemplate.insert(dPatternBook); cassandraTemplate.deleteAll(Book.class); - Select select = QueryBuilder.select().from("book").limit(10); - Book retrievedUpdatedBook = cassandraTemplate.selectOne(select, Book.class); + final Select select = QueryBuilder.select().from("book").limit(10); + final Book retrievedUpdatedBook = cassandraTemplate.selectOne(select, Book.class); assertNull(retrievedUpdatedBook); } @Test public void whenAddingBooks_thenCountShouldBeCorrectOnRetrieval() { - Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); - Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); + final Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", "O'Reilly Media", ImmutableSet.of("Computer", "Software")); cassandraTemplate.insert(javaBook); cassandraTemplate.insert(dPatternBook); - long bookCount = cassandraTemplate.count(Book.class); + final long bookCount = cassandraTemplate.count(Book.class); assertEquals(2, bookCount); } diff --git a/spring-data-mongodb/.classpath b/spring-data-mongodb/.classpath new file mode 100644 index 000000000000..baf7c981310c --- /dev/null +++ b/spring-data-mongodb/.classpath @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-data-mongodb/.project b/spring-data-mongodb/.project new file mode 100644 index 000000000000..e3d768757313 --- /dev/null +++ b/spring-data-mongodb/.project @@ -0,0 +1,29 @@ + + + spring-data-mongodb + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml index ef6ac59dd4c8..d9a578cb8ca3 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-mvc-java/pom.xml @@ -169,6 +169,7 @@ + 4.2.4.RELEASE @@ -197,8 +198,9 @@ 2.6 2.18.1 2.7 - 1.4.15 + 1.4.17 1.8.7 + \ No newline at end of file