Skip to content

Commit ff053d2

Browse files
eugenpdavidmorley
authored andcommitted
minor cleanup
1 parent 17d5f4a commit ff053d2

11 files changed

Lines changed: 269 additions & 115 deletions

File tree

‎spring-data-cassandra/.classpath‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="output" path="target/classes"/>
31+
</classpath>

‎spring-data-cassandra/.project‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>spring-data-cassandra</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.springframework.ide.eclipse.core.springbuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.springframework.ide.eclipse.core.springnature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
28+
</natures>
29+
</projectDescription>

‎spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/config/CassandraConfig.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
@PropertySource(value = { "classpath:cassandra.properties" })
1818
@EnableCassandraRepositories(basePackages = "org.baeldung.spring.data.cassandra.repository")
1919
public class CassandraConfig extends AbstractCassandraConfiguration {
20-
2120
private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class);
21+
2222
@Autowired
2323
private Environment environment;
2424

@@ -27,15 +27,17 @@ protected String getKeyspaceName() {
2727
return environment.getProperty("cassandra.keyspace");
2828
}
2929

30+
@Override
3031
@Bean
3132
public CassandraClusterFactoryBean cluster() {
32-
CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
33+
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
3334
cluster.setContactPoints(environment.getProperty("cassandra.contactpoints"));
3435
cluster.setPort(Integer.parseInt(environment.getProperty("cassandra.port")));
3536
LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "& port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "].");
3637
return cluster;
3738
}
3839

40+
@Override
3941
@Bean
4042
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException {
4143
return new BasicCassandraMappingContext();

‎spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/model/Book.java‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
package org.baeldung.spring.data.cassandra.model;
22

3+
import java.util.HashSet;
4+
import java.util.Set;
5+
import java.util.UUID;
6+
37
import org.springframework.cassandra.core.Ordering;
48
import org.springframework.cassandra.core.PrimaryKeyType;
59
import org.springframework.data.cassandra.mapping.Column;
610
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
711
import org.springframework.data.cassandra.mapping.Table;
812

9-
import java.util.HashSet;
10-
import java.util.Set;
11-
import java.util.UUID;
12-
1313
@Table
1414
public class Book {
15+
1516
@PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING)
1617
private UUID id;
18+
1719
@PrimaryKeyColumn(name = "title", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
1820
private String title;
1921

2022
@PrimaryKeyColumn(name = "publisher", ordinal = 2, type = PrimaryKeyType.PARTITIONED)
2123
private String publisher;
24+
2225
@Column
2326
private Set<String> tags = new HashSet<>();
2427

25-
public Book(UUID id, String title, String publisher, Set<String> tags) {
28+
public Book(final UUID id, final String title, final String publisher, final Set<String> tags) {
2629
this.id = id;
2730
this.title = title;
2831
this.publisher = publisher;
@@ -45,19 +48,20 @@ public Set getTags() {
4548
return tags;
4649
}
4750

48-
public void setId(UUID id) {
51+
public void setId(final UUID id) {
4952
this.id = id;
5053
}
5154

52-
public void setTitle(String title) {
55+
public void setTitle(final String title) {
5356
this.title = title;
5457
}
5558

56-
public void setPublisher(String publisher) {
59+
public void setPublisher(final String publisher) {
5760
this.publisher = publisher;
5861
}
5962

60-
public void setTags(Set<String> tags) {
63+
public void setTags(final Set<String> tags) {
6164
this.tags = tags;
6265
}
66+
6367
}

‎spring-data-cassandra/src/main/java/org/baeldung/spring/data/cassandra/repository/BookRepository.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
@Repository
99
public interface BookRepository extends CassandraRepository<Book> {
10+
1011
@Query("select * from book where title = ?0 and publisher=?1")
1112
Iterable<Book> findByTitleAndPublisher(String title, String publisher);
13+
1214
}
Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
package org.baeldung.spring.data.cassandra.repository;
22

3-
import com.datastax.driver.core.Cluster;
4-
import com.datastax.driver.core.Session;
5-
import com.datastax.driver.core.utils.UUIDs;
6-
import com.google.common.collect.ImmutableSet;
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotEquals;
5+
6+
import java.io.IOException;
7+
import java.util.HashMap;
8+
79
import org.apache.cassandra.exceptions.ConfigurationException;
810
import org.apache.commons.logging.Log;
911
import org.apache.commons.logging.LogFactory;
1012
import org.apache.thrift.transport.TTransportException;
1113
import org.baeldung.spring.data.cassandra.config.CassandraConfig;
1214
import org.baeldung.spring.data.cassandra.model.Book;
1315
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
14-
import org.junit.*;
16+
import org.junit.After;
17+
import org.junit.AfterClass;
18+
import org.junit.Before;
19+
import org.junit.BeforeClass;
20+
import org.junit.Test;
1521
import org.junit.runner.RunWith;
1622
import org.springframework.beans.factory.annotation.Autowired;
1723
import org.springframework.cassandra.core.cql.CqlIdentifier;
1824
import org.springframework.data.cassandra.core.CassandraAdminOperations;
1925
import org.springframework.test.context.ContextConfiguration;
2026
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2127

22-
import java.io.IOException;
23-
import java.util.HashMap;
24-
25-
import static org.junit.Assert.assertEquals;
26-
import static org.junit.Assert.assertNotEquals;
28+
import com.datastax.driver.core.Cluster;
29+
import com.datastax.driver.core.Session;
30+
import com.datastax.driver.core.utils.UUIDs;
31+
import com.google.common.collect.ImmutableSet;
2732

2833
@RunWith(SpringJUnit4ClassRunner.class)
2934
@ContextConfiguration(classes = CassandraConfig.class)
3035
public class BookRepositoryIntegrationTest {
31-
3236
private static final Log LOGGER = LogFactory.getLog(BookRepositoryIntegrationTest.class);
3337

3438
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 {
4347
@Autowired
4448
private CassandraAdminOperations adminTemplate;
4549

50+
//
51+
4652
@BeforeClass
4753
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
4854
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
49-
Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1")
50-
.withPort(9142).build();
55+
final Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
5156
LOGGER.info("Server Started at 127.0.0.1:9142... ");
52-
Session session = cluster.connect();
57+
final Session session = cluster.connect();
5358
session.execute(KEYSPACE_CREATION_QUERY);
5459
session.execute(KEYSPACE_ACTIVATE_QUERY);
5560
LOGGER.info("KeySpace created and activated.");
@@ -63,54 +68,54 @@ public void createTable() throws InterruptedException, TTransportException, Conf
6368

6469
@Test
6570
public void whenSavingBook_thenAvailableOnRetrieval() {
66-
Book javaBook = new Book(UUIDs.timeBased(), "Head First Java",
67-
"O'Reilly Media", ImmutableSet.of("Computer", "Software"));
71+
final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
6872
bookRepository.save(ImmutableSet.of(javaBook));
69-
Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
73+
final Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
7074
assertEquals(javaBook.getId(), books.iterator().next().getId());
7175
}
7276

7377
@Test
7478
public void whenUpdatingBooks_thenAvailableOnRetrieval() {
75-
Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
79+
final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
7680
bookRepository.save(ImmutableSet.of(javaBook));
77-
Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
81+
final Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
7882
javaBook.setTitle("Head First Java Second Edition");
7983
bookRepository.save(ImmutableSet.of(javaBook));
80-
Iterable<Book> updateBooks = bookRepository.findByTitleAndPublisher("Head First Java Second Edition", "O'Reilly Media");
84+
final Iterable<Book> updateBooks = bookRepository.findByTitleAndPublisher("Head First Java Second Edition", "O'Reilly Media");
8185
assertEquals(javaBook.getTitle(), updateBooks.iterator().next().getTitle());
8286
}
8387

8488
@Test(expected = java.util.NoSuchElementException.class)
8589
public void whenDeletingExistingBooks_thenNotAvailableOnRetrieval() {
86-
Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
90+
final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
8791
bookRepository.save(ImmutableSet.of(javaBook));
8892
bookRepository.delete(javaBook);
89-
Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
93+
final Iterable<Book> books = bookRepository.findByTitleAndPublisher("Head First Java", "O'Reilly Media");
9094
assertNotEquals(javaBook.getId(), books.iterator().next().getId());
9195
}
9296

9397
@Test
9498
public void whenSavingBooks_thenAllShouldAvailableOnRetrieval() {
95-
Book javaBook = new Book(UUIDs.timeBased(), "Head First Java",
96-
"O'Reilly Media", ImmutableSet.of("Computer", "Software"));
97-
Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns",
98-
"O'Reilly Media", ImmutableSet.of("Computer", "Software"));
99+
final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
100+
final Book dPatternBook = new Book(UUIDs.timeBased(), "Head Design Patterns", "O'Reilly Media", ImmutableSet.of("Computer", "Software"));
99101
bookRepository.save(ImmutableSet.of(javaBook));
100102
bookRepository.save(ImmutableSet.of(dPatternBook));
101-
Iterable<Book> books = bookRepository.findAll();
103+
final Iterable<Book> books = bookRepository.findAll();
102104
int bookCount = 0;
103-
for (Book book : books) bookCount++;
105+
for (final Book book : books) {
106+
bookCount++;
107+
}
104108
assertEquals(bookCount, 2);
105109
}
106110

107111
@After
108112
public void dropTable() {
109-
adminTemplate.dropTable(CqlIdentifier.cqlId(DATA_TABLE_NAME));
113+
adminTemplate.dropTable(CqlIdentifier.cqlId(DATA_TABLE_NAME));
110114
}
111115

112116
@AfterClass
113117
public static void stopCassandraEmbedded() {
114118
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
115119
}
120+
116121
}

0 commit comments

Comments
 (0)