- 浏览: 2560882 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Spring Boot and RESTful API(4)Cassandra Spring Data
Possible Data Structure
>CREATE KEYSPACE jobsmonitor WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
>use jobsmonitor;
>CREATE TABLE jobcounthistory(
source_id text,
record_date TIMESTAMP,
new_active_count int,
new_admin_count int,
old_active_count int,
old_admin_count int,
PRIMARY KEY ( source_id, record_date )
) WITH CLUSTERING ORDER BY (record_date DESC);
Possible query is as follow:
select * from jobcounthistory where source_id = 'asdfasf';
select * from jobcounthistory where source_id = 'asdf' and record_date > '2017-06-11';
>CREATE TABLE jobcountdiff(
date text,
diff int,
record_date TIMESTAMP,
source_id text,
PRIMARY KEY ( date, diff, record_date )
) WITH CLUSTERING ORDER BY (diff ASC, record_date DESC);
Possible Query is as follow:
select * from jobcountdiff where date = '2017-06-15';
select * from jobcountdiff where date = '2017-06-15' and diff > 10;
Code and Setup
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
Configuration in application.yaml
logging:
level:
debug
spring:
profiles:
active:
dev
data:
solr:
host:
http://localhost:8983/solr/
cassandra:
keyspace-name:jobsmonitor
contact-points: localhost
Domain Class
package com.sillycat.jobsmonitorapi.domain;
import java.util.Date;
import org.apache.commons.lang3.builder.ToStringBuilder;
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("jobcounthistory")
public class JobCountHistory {
@PrimaryKeyColumn(name = "source_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private String sourceID;
@PrimaryKeyColumn(name = "record_date", ordinal = 1, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING)
private Date recordDate;
@Column("new_active_count")
private Integer newActiveCount;
@Column("new_admin_count")
private Integer newAdminCount;
@Column("old_active_count")
private Integer oldActiveCount;
@Column("old_admin_count")
private Integer oldAdminCount;
public JobCountHistory() {
}
public String getSourceID() {
return sourceID;
}
public void setSourceID(String sourceID) {
this.sourceID = sourceID;
}
public Date getRecordDate() {
return recordDate;
}
public void setRecordDate(Date recordDate) {
this.recordDate = recordDate;
}
public Integer getNewActiveCount() {
return newActiveCount;
}
public void setNewActiveCount(Integer newActiveCount) {
this.newActiveCount = newActiveCount;
}
public Integer getNewAdminCount() {
return newAdminCount;
}
public void setNewAdminCount(Integer newAdminCount) {
this.newAdminCount = newAdminCount;
}
public Integer getOldActiveCount() {
return oldActiveCount;
}
public void setOldActiveCount(Integer oldActiveCount) {
this.oldActiveCount = oldActiveCount;
}
public Integer getOldAdminCount() {
return oldAdminCount;
}
public void setOldAdminCount(Integer oldAdminCount) {
this.oldAdminCount = oldAdminCount;
}
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
Repository Interface
package com.sillycat.jobsmonitorapi.repository;
import java.util.List;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.repository.CrudRepository;
import com.sillycat.jobsmonitorapi.domain.JobCountHistory;
public interface JobCountHistoryRepositoryCassandra extends CrudRepository<JobCountHistory, String> {
@Query("select * from jobcounthistory where source_id=?0")
public List<JobCountHistory> findBySourceID(String sourceID);
@Query("delete from jobcounthistory where source_id=?0")
public void deleteBySourceID(String sourceID);
}
Unit Test Class
package
com.sillycat.jobsmonitorapi.repository;
import java.util.Date;import
java.util.List;
import org.apache.http.util.Asserts;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import
org.springframework.test.context.junit4.SpringRunner;
import
com.sillycat.jobsmonitorapi.domain.JobCountHistory;
@RunWith(SpringRunner.class)@SpringBootTest
public class
JobCountHistoryCassandraTest {
@Autowired
JobCountHistoryRepositoryCassandra jobCountHistoryRepositoryCassandra;
@Test
public void save() throws Exception {
jobCountHistoryRepositoryCassandra.deleteBySourceID("9527");
JobCountHistory item1 = new JobCountHistory();
item1.setNewActiveCount(1);
item1.setNewAdminCount(12);
item1.setOldActiveCount(12);
item1.setOldAdminCount(1);
item1.setSourceID("9527");
item1.setRecordDate(new Date());
jobCountHistoryRepositoryCassandra.save(item1);
List<JobCountHistory> result = jobCountHistoryRepositoryCassandra.findBySourceID("9527");
Asserts.notNull(result, "result is not null");
}
}
References:
http://sillycat.iteye.com/blog/2383513
Possible Data Structure
>CREATE KEYSPACE jobsmonitor WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
>use jobsmonitor;
>CREATE TABLE jobcounthistory(
source_id text,
record_date TIMESTAMP,
new_active_count int,
new_admin_count int,
old_active_count int,
old_admin_count int,
PRIMARY KEY ( source_id, record_date )
) WITH CLUSTERING ORDER BY (record_date DESC);
Possible query is as follow:
select * from jobcounthistory where source_id = 'asdfasf';
select * from jobcounthistory where source_id = 'asdf' and record_date > '2017-06-11';
>CREATE TABLE jobcountdiff(
date text,
diff int,
record_date TIMESTAMP,
source_id text,
PRIMARY KEY ( date, diff, record_date )
) WITH CLUSTERING ORDER BY (diff ASC, record_date DESC);
Possible Query is as follow:
select * from jobcountdiff where date = '2017-06-15';
select * from jobcountdiff where date = '2017-06-15' and diff > 10;
Code and Setup
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
Configuration in application.yaml
logging:
level:
debug
spring:
profiles:
active:
dev
data:
solr:
host:
http://localhost:8983/solr/
cassandra:
keyspace-name:jobsmonitor
contact-points: localhost
Domain Class
package com.sillycat.jobsmonitorapi.domain;
import java.util.Date;
import org.apache.commons.lang3.builder.ToStringBuilder;
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("jobcounthistory")
public class JobCountHistory {
@PrimaryKeyColumn(name = "source_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private String sourceID;
@PrimaryKeyColumn(name = "record_date", ordinal = 1, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.DESCENDING)
private Date recordDate;
@Column("new_active_count")
private Integer newActiveCount;
@Column("new_admin_count")
private Integer newAdminCount;
@Column("old_active_count")
private Integer oldActiveCount;
@Column("old_admin_count")
private Integer oldAdminCount;
public JobCountHistory() {
}
public String getSourceID() {
return sourceID;
}
public void setSourceID(String sourceID) {
this.sourceID = sourceID;
}
public Date getRecordDate() {
return recordDate;
}
public void setRecordDate(Date recordDate) {
this.recordDate = recordDate;
}
public Integer getNewActiveCount() {
return newActiveCount;
}
public void setNewActiveCount(Integer newActiveCount) {
this.newActiveCount = newActiveCount;
}
public Integer getNewAdminCount() {
return newAdminCount;
}
public void setNewAdminCount(Integer newAdminCount) {
this.newAdminCount = newAdminCount;
}
public Integer getOldActiveCount() {
return oldActiveCount;
}
public void setOldActiveCount(Integer oldActiveCount) {
this.oldActiveCount = oldActiveCount;
}
public Integer getOldAdminCount() {
return oldAdminCount;
}
public void setOldAdminCount(Integer oldAdminCount) {
this.oldAdminCount = oldAdminCount;
}
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
Repository Interface
package com.sillycat.jobsmonitorapi.repository;
import java.util.List;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.repository.CrudRepository;
import com.sillycat.jobsmonitorapi.domain.JobCountHistory;
public interface JobCountHistoryRepositoryCassandra extends CrudRepository<JobCountHistory, String> {
@Query("select * from jobcounthistory where source_id=?0")
public List<JobCountHistory> findBySourceID(String sourceID);
@Query("delete from jobcounthistory where source_id=?0")
public void deleteBySourceID(String sourceID);
}
Unit Test Class
package
com.sillycat.jobsmonitorapi.repository;
import java.util.Date;import
java.util.List;
import org.apache.http.util.Asserts;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import
org.springframework.test.context.junit4.SpringRunner;
import
com.sillycat.jobsmonitorapi.domain.JobCountHistory;
@RunWith(SpringRunner.class)@SpringBootTest
public class
JobCountHistoryCassandraTest {
@Autowired
JobCountHistoryRepositoryCassandra jobCountHistoryRepositoryCassandra;
@Test
public void save() throws Exception {
jobCountHistoryRepositoryCassandra.deleteBySourceID("9527");
JobCountHistory item1 = new JobCountHistory();
item1.setNewActiveCount(1);
item1.setNewAdminCount(12);
item1.setOldActiveCount(12);
item1.setOldAdminCount(1);
item1.setSourceID("9527");
item1.setRecordDate(new Date());
jobCountHistoryRepositoryCassandra.save(item1);
List<JobCountHistory> result = jobCountHistoryRepositoryCassandra.findBySourceID("9527");
Asserts.notNull(result, "result is not null");
}
}
References:
http://sillycat.iteye.com/blog/2383513
发表评论
-
Update Site will come soon
2021-06-02 04:10 1686I am still keep notes my tech n ... -
Stop Update Here
2020-04-28 09:00 322I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 484NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 374Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 375Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 345Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 436Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 444Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 381Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 463VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 394Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 488NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 432Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 342Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 255GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 456GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 332GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 318Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 324Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 302Serverless with NodeJS and Tenc ...
相关推荐
- `spring-boot-web-example`:展示如何创建一个简单的 RESTful API。 - `spring-boot-data-jpa-example`:演示如何使用 Spring Data JPA 和 Hibernate 进行数据库操作。 - `spring-boot-security-example`:介绍...
Spring Data REST 是基于 Spring Boot 和 Spring Data 项目构建 RESTful API 的强大工具,极大地简化了开发者的工作。在传统的 RESTful 开发中,我们需要手动编写控制器(Controller)来处理 HTTP 请求并映射到业务...
使用Spring Boot进行Web开发,可以通过`@RestController`和`@RequestMapping`注解创建RESTful API。Spring MVC是其基础,支持模板引擎如Thymeleaf和Freemarker,以及WebSocket等高级功能。 7. **数据访问**: ...
同时,Spring MVC作为Spring Boot的默认Web框架,提供模型-视图-控制器架构,方便构建RESTful API。Spring Boot还支持Thymeleaf、Freemarker等模板引擎,用于生成动态HTML页面。 在微服务领域,Spring Boot更是大放...
5. **Spring Data**:Spring Boot与Spring Data结合,可以方便地实现对各种数据库的CRUD操作,包括JPA、MongoDB、Cassandra等,提供了统一的API。 6. **Spring Cloud**:Spring Boot常与Spring Cloud搭配使用,实现...
Spring Data Cassandra是Spring Framework的一部分,它为Cassandra提供了易于使用的API,使得在Spring Boot应用中操作Cassandra变得简单。它支持定义CQL(Cassandra查询语言)实体、CRUD操作、查询方法以及事件监听...
如果采用RESTful API设计,Spring Boot的`@RestController`和`@RequestMapping`等注解能轻松实现API接口。 接着,Spring Boot也支持数据库集成,包括关系型数据库(如MySQL、PostgreSQL)和NoSQL数据库(如MongoDB...
2. RESTful服务:利用Spring MVC轻松创建RESTful API,提供JSON序列化和反序列化的支持。 3. 安全:集成Spring Security,提供身份验证和授权功能。 4. 任务调度:可以使用Spring Task或Quartz进行定时任务的配置。 ...
1. **RESTful API**:Spring Boot 提供了 `@RestController` 和 `@RequestMapping` 等注解,方便构建 RESTful 风格的服务。 2. **模板引擎**:支持 Thymeleaf、FreeMarker、Groovy Templates 等模板引擎,用于动态...
例如,`spring-boot-starter-data-jpa`可以快速引入JPA和Hibernat支持,`spring-boot-starter-data-rest`则可以快速实现RESTful API。 3. **内嵌式Web服务器**:Spring Boot可以内嵌Tomcat、Jetty或Undertow等Web...
9. **数据访问**:Spring Boot支持多种数据存储选项,包括JDBC、JPA、MongoDB、Cassandra等,提供了统一的API,简化了数据访问。 10. **集成测试**:Spring Boot Test模块提供了对单元测试和集成测试的良好支持,...
4. 数据访问增强:Spring Data项目在4.x版本中得到扩展,增加了对NoSQL数据库的支持,如MongoDB、Cassandra等,同时对JPA(Java Persistence API)和JDBC也进行了改进。 5. AOP(面向切面编程)改进:Spring 4.x...
7. **Web开发**:Spring Boot结合了Spring MVC,提供了RESTful API开发的支持。同时,通过Thymeleaf、FreeMarker或JSP等模板引擎可以方便地开发Web界面。 8. **数据访问**:Spring Boot支持多种数据库,如JDBC、...
12. **RESTful API 设计**:Spring Boot 鼓励使用 RESTful 风格设计 API,结合 Swagger 可生成 API 文档。 这个"spring-boot-learning-master.zip"文件可能包含从基础概念到高级特性的各种教程,帮助开发者逐步掌握...
- **Spring Boot**:Spring Boot自动配置功能可简化Spring Data Commons的使用,减少配置工作。 6. **版本1.13.0.RELEASE的特性**: - **性能优化**:可能包含对查询性能的改进,以及内存管理和并发性的优化。 -...
3. **Spring Data**:Spring Boot对Spring Data项目提供了良好的支持,包括JPA、MongoDB、Cassandra等,使得数据访问变得更加简单。只需少量代码,即可实现CRUD操作。 4. **Web开发**:Spring Boot集成了Spring MVC...
6. **Spring Data**:Spring Boot 与 Spring Data 结合,可以简化数据库访问,支持多种数据库,如 JPA、MongoDB、Cassandra 等,并且提供了统一的 CRUD 操作接口。 7. **Spring Cloud**:配合 Spring Cloud,Spring...
在本系统中,Spring Boot可能被用作后端服务的基石,提供RESTful API以供前端或客户端应用调用。通过Spring的自动配置和依赖注入特性,开发者可以快速搭建稳定、健壮的服务。此外,Spring Data JPA或MyBatis等组件...
此外,Spring Boot 还支持RESTful API设计,基于Spring MVC的注解如`@RestController`和`@RequestMapping`可以轻松创建API接口。同时,Swagger等工具可以方便地生成API文档。 总而言之,Spring Boot 是Java开发中的...
5. **Spring Data**:Spring Boot 集成了Spring Data框架,简化了与各种数据存储(如JDBC、MongoDB、Cassandra等)的交互,提供了强大的Repository抽象层,使得数据库操作更加便捷。 6. **RESTful API**:Spring ...