Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] PR for Document Spring Data YB in Ecosystem (Doc8339) #9618

Merged
merged 5 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/latest/integrations/_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
</div>

<div class="col-12 col-md-6 col-lg-12 col-xl-6">
<a class="section-link icon-offset" href="spring/">
<a class="section-link icon-offset" href="spring-framework/">
<div class="head">
<img class="icon" src="/images/section_icons/develop/ecosystem/spring.png" aria-hidden="true" />
<div class="title">Spring Framework</div>
Expand Down
43 changes: 43 additions & 0 deletions docs/content/latest/integrations/spring-framework/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Spring Framework
headerTitle: Spring Framework
linkTitle: Spring Framework
description: Using Spring Framework with YugabyteDB
headcontent: Using Spring Framework with YugabyteDB
aliases:
image: /images/section_icons/develop/ecosystem/spring.png
menu:
latest:
parent: integrations
identifier: spring-framework
weight: 645
---


<div class="row">

<div class="col-12 col-md-6 col-lg-12 col-xl-6">
<a class="section-link icon-offset" href="sdyb/">
<div class="head">
<img class="icon" src="/images/section_icons/develop/ecosystem/spring.png" aria-hidden="true"/>
<div class="title">Spring Data YugabyteDB</div>
</div>
<div class="body">
Use Spring Data YugabyteDB with YSQL APIs to build cloud-native applications.
</div>
</a>
</div>

<div class="col-12 col-md-6 col-lg-12 col-xl-6">
<a class="section-link icon-offset" href="spring-cassandra/">
<div class="head">
<img class="icon" src="/images/section_icons/develop/ecosystem/spring.png" aria-hidden="true"/>
<div class="title">Spring Data Cassandra and YCQL</div>
</div>
<div class="body">
Use YCQL integrated with the Spring Data Cassandra project.
</div>
</a>
</div>

</div>
141 changes: 141 additions & 0 deletions docs/content/latest/integrations/spring-framework/sdyb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
title: Spring Data YugabyteDB
linkTitle: Spring Data YugabyteDB
description: Spring Data YugabyteDB
aliases:
menu:
latest:
identifier: sdyb
parent: spring-framework
weight: 578
isTocNested: true
showAsideToc: true
---

Spring Data modules are used for accessing databases and performing various tasks via Java APIs, therefore eliminating the need to learn a database-specific query language.

Spring Data YugabyteDB (SDYB) modules provide support for YSQL APIs and enable you to build cloud-native applications.

## Overview

The following are some of the features included in SDYB YSQL:

- Spring Data `YsqlTemplate` and `YsqlRepository` for querying YugabyteDB
- `@EnableYsqlRepostiory` annotation for enabling `YsqlRepository`
- Yugabyte Distributed SQL transaction manager
- Spring Boot starter support for YugabyteDB
- Cluster awareness achieved via elimination of load balancer from SQL
- Topology awareness necessary for developing geographically-distributed applications
- Partition awareness for achieving row-level geo-partitioning

For more information, demonstrations, and contribution guidelines, see [Spring Data YugabyteDB GitHub project.](https://github.com/yugabyte/spring-data-yugabytedb/)

## Project Dependencies

The project definition includes the following dependencies:

```properties
<dependency>
<groupId>com.yugabyte</groupId>
<artifactId>spring-data-yugabytedb-ysql</artifactId>
<version>2.3.0</version>
lizayugabyte marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>com.yugabyte</groupId>
<artifactId>jdbc-yugabytedb</artifactId>
<version>42.2.7-yb-5.beta.1</version>
</dependency>
```

## Examples


The following example demonstrates how to create a basic shopping cart using SDYB:

```java
public interface ShoppingCartRepository extends YsqlRepository<ShoppingCart, String> {

ShoppingCart findById(String id);
List<ShoppingCart> findByUserId(String userId);

}

@Service
public class CartService {

private final ShoppingCartRepository repository;

public CartService(CartService repository) {
this.repository = repository;
}

public void doWork() {
repository.deleteAll();

ShoppingCart myShoppingCart = new ShoppingCart();
myShoppingCart.set("cart1")
myShoppingCart.setUserId("u1001");
myShoppingCart.setProductId("asin1001");
myShoppingCart.setQuantity(1);

repository.save(myShoppingCart);

ShoppingCart savedCart = repository.findById("cart1");

List<ShoppingCart> productsInCart = repository.findByUserId("u1001");
repository.count();
}

}

@Configuration
@EnableYsqlRepositories
public class YsqlConfig extends AbstractYugabyteJdbcConfiguration {

@Bean
DataSource dataSource() {
String hostName = "127.0.0.1";
String port = "5433";

Properties poolProperties = new Properties();
poolProperties.setProperty("dataSourceClassName",
"com.yugabyte.ysql.YBClusterAwareDataSource");
poolProperties.setProperty("dataSource.serverName", hostName);
poolProperties.setProperty("dataSource.portNumber", port);
poolProperties.setProperty("dataSource.user", "yugabyte");
poolProperties.setProperty("dataSource.password", "");
poolProperties.setProperty("dataSource.loadBalance", "true");
poolProperties.setProperty("dataSource.additionalEndpoints",
"127.0.0.2:5433,127.0.0.3:5433");

HikariConfig hikariConfig = new HikariConfig(poolProperties);
DataSource ybClusterAwareDataSource = new HikariDataSource(hikariConfig);
return ybClusterAwareDataSource;
}

@Bean
JdbcTemplate jdbcTemplate(@Autowired DataSource dataSource) {

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
return jdbcTemplate;
}

@Bean
NamedParameterJdbcOperations namedParameterJdbcOperations(DataSource dataSource) {
return new NamedParameterJdbcTemplate(dataSource);
}

@Bean
TransactionManager transactionManager(DataSource dataSource) {
return new YugabyteTransactionManager(dataSource);
}

}
```

## Compatibility Matrix

| **SDYB** | **YugabyteDB Smart Driver** | **Postgres JDBC Driver** |
| -------- | --------------------------- | ------------------------ |
| 2.3.0 | 42.2.7-yb-5.beta.1 | 42.2.7 or later |

lizayugabyte marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: Spring Support for YugabyteDB
linkTitle: Spring Framework
description: Spring Support for YugabyteDB
title: Spring Data Cassandra
linkTitle: Spring Data Cassandra
description: Spring Data Cassandra
aliases:
menu:
latest:
identifier: spring
parent: integrations
weight: 578
identifier: spring-cassandra
parent: spring-framework
weight: 579
isTocNested: true
showAsideToc: true
---

This document describes the Spring Framework support for YugabyteDB.
This document describes how to use Spring Data Cassandra and reactive Spring Data Cassandra with YCQL.

## Spring Data Cassandra and YCQL

Expand All @@ -25,7 +25,7 @@ The following is a non-exhaustive list of supported features:
- Build repositories based on common Spring Data interfaces.
- Synchronous, reactive, and asynchronous YCQL operations.

### Spring Data Cassandra Dependencies
### Project Dependencies

Spring Data Cassandra projects are bundled with the Apache Cassandra Java driver. To enhance performance, it is recommended to replace this driver with the Yugabyte Java driver for YCQL.

Expand Down Expand Up @@ -101,7 +101,7 @@ Yugabyte Java driver for YCQL provides support for single hop fetch which enable

### Sample Spring Boot Project

A sample Spring boot project is available at <https://github.com/yugabyte/spring-ycql-demo>. The following steps show how to incrementally build a Spring boot application using Spring Data Cassandra and YCQL.
A sample Spring boot project is available at <https://github.com/yugabyte/spring-ycql-demo>. The following steps demonstrate how to incrementally build a Spring boot application using Spring Data Cassandra and YCQL.

#### Use Spring Initializer

Expand Down Expand Up @@ -299,9 +299,9 @@ YCQL API is compatible with Spring Data reactive repositories for Apache Cassand

Using Spring WebFlux and Spring Data reactive repositories, you can implement fully reactive Spring Microservices with YCQL API.

### Spring Data Reactive Cassandra Dependencies
### Project Dependencies

Spring Data Reactive Cassandra projects are bundled with the Apache Cassandra Java driver. To enhance performance, it is recommended to replace this driver with Yugabyte Java driver for YCQL, as follows:
Reactive Spring Data Cassandra projects are bundled with the Apache Cassandra Java driver. To enhance performance, it is recommended to replace this driver with Yugabyte Java driver for YCQL, as follows:

```xml
<dependency>
Expand Down Expand Up @@ -383,8 +383,8 @@ public class Customer {
@Override
public String toString() {
return String.format(
"Customer[id=%d, firstName='%s', lastName='%s']",
id, firstName, lastName);
"Customer[id=%d, firstName='%s', lastName='%s']",
id, firstName, lastName);
}

// define getters and setters
Expand Down Expand Up @@ -440,12 +440,12 @@ public class YcqlReactiveDataAccessApplication implements CommandLineRunner {
CqlSession ycqlSession;

public static void main(String[] args) {
SpringApplication.run(YcqlReactiveDataAccessApplication.class, args);
SpringApplication.run(YcqlReactiveDataAccessApplication.class, args);
}

@Override
public void run(String... args) throws Exception {
log.info("Creating table");
log.info("Creating table");
ycqlSession.execute("CREATE TABLE IF NOT EXISTS demo.customer (\n" +
" id INT PRIMARY KEY,\n"+ " firstName text,\n" +
" lastName text\n" + ") WITH default_time_to_live = 0\n" +
Expand Down