Skip to content

Commit

Permalink
R-05 Adding repo support - still not running
Browse files Browse the repository at this point in the history
  • Loading branch information
predragstefanovic committed Jan 26, 2022
1 parent 75e629a commit 8916f45
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/com/ps/reactive/config/CassandraConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ps.reactive.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories;

@Configuration
@EnableReactiveCassandraRepositories(
basePackages = {
"com.ps.db.cassandra"
})
public class CassandraConfig extends AbstractCassandraConfiguration {

protected String getKeyspaceName() {
return "keyspace";
}

public String[] getEntityBasePackages() {
return new String[]{"com.ps.db.cassandra"};
}
}

36 changes: 36 additions & 0 deletions src/main/java/com/ps/reactive/config/PostgresR2DBCConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.ps.reactive.config;

import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories;
import org.springframework.data.r2dbc.core.DefaultReactiveDataAccessStrategy;
import org.springframework.data.r2dbc.core.R2dbcEntityOperations;
import org.springframework.r2dbc.core.DatabaseClient;

import static io.r2dbc.spi.ConnectionFactoryOptions.*;

@Configuration
@EnableReactiveCassandraRepositories(
basePackages = {
"com.ps.db.postgres"
})
public class PostgresR2DBCConfig {

@Bean
@Qualifier("postgres")
public ConnectionFactory connectionFactory() {
return ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(DRIVER, "postgresql")
.option(HOST, "localhost")
.option(PORT, 5432)
.option(USER, "postgres")
.option(PASSWORD, "postgres")
.option(DATABASE, "postgres")
.build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ps.reactive.db.cassandra;

import org.springframework.data.repository.reactive.ReactiveSortingRepository;

public interface CassandraReactiveRepository extends ReactiveSortingRepository<Person, PersonKey> {
}
17 changes: 17 additions & 0 deletions src/main/java/com/ps/reactive/db/cassandra/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ps.reactive.db.cassandra;

import lombok.Data;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;

@Data
@Table(value="people")
public class Person {

@PrimaryKey
private PersonKey key;

@Column(value="employment")
private String employment;
}
25 changes: 25 additions & 0 deletions src/main/java/com/ps/reactive/db/cassandra/PersonKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.ps.reactive.db.cassandra;

import lombok.Data;
import org.springframework.data.cassandra.core.cql.Ordering;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyClass;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;

import java.io.Serializable;

@Data
@PrimaryKeyClass
public class PersonKey implements Serializable {
@PrimaryKeyColumn(name = "city", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private String city;

@PrimaryKeyColumn(name = "lastname", ordinal = 1, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.ASCENDING)
private String lastName;

@PrimaryKeyColumn(name = "firstname", ordinal = 2, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.ASCENDING)
private String firstName;

@PrimaryKeyColumn(name = "email", ordinal = 3, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.ASCENDING)
private String email;
}

0 comments on commit 8916f45

Please sign in to comment.