group persistence modules (#2890)
* move security content from spring-security-rest-full * swagger update * move query language to new module * rename spring-security-rest-full to spring-rest-full * group persistence modules
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
dbeb5f8ba4
commit
26c50909be
+45
@@ -0,0 +1,45 @@
|
||||
package org.baeldung.spring.data.cassandra.config;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.cassandra.config.CassandraClusterFactoryBean;
|
||||
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
|
||||
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
|
||||
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
|
||||
@Configuration
|
||||
@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;
|
||||
|
||||
@Override
|
||||
protected String getKeyspaceName() {
|
||||
return environment.getProperty("cassandra.keyspace");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public CassandraClusterFactoryBean cluster() {
|
||||
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();
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
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;
|
||||
|
||||
@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<String> tags = new HashSet<>();
|
||||
|
||||
public Book(final UUID id, final String title, final String publisher, final Set<String> tags) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.publisher = publisher;
|
||||
this.tags.addAll(tags);
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getPublisher() {
|
||||
return publisher;
|
||||
}
|
||||
|
||||
public Set getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setId(final UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setTitle(final String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setPublisher(final String publisher) {
|
||||
this.publisher = publisher;
|
||||
}
|
||||
|
||||
public void setTags(final Set<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package org.baeldung.spring.data.cassandra.repository;
|
||||
|
||||
import org.baeldung.spring.data.cassandra.model.Book;
|
||||
import org.springframework.data.cassandra.repository.CassandraRepository;
|
||||
import org.springframework.data.cassandra.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface BookRepository extends CassandraRepository<Book> {
|
||||
|
||||
@Query("select * from book where title = ?0 and publisher=?1")
|
||||
Iterable<Book> findByTitleAndPublisher(String title, String publisher);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
cassandra.contactpoints=127.0.0.1
|
||||
cassandra.port=9142
|
||||
cassandra.keyspace=testKeySpace
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework" level="WARN" />
|
||||
<logger name="org.springframework.transaction" level="WARN" />
|
||||
|
||||
<!-- in order to debug some marshalling issues, this needs to be TRACE -->
|
||||
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 855 B |
Reference in New Issue
Block a user