Spring5学习(二)-spring projects之Spring Data

陶智
2023-12-01

Spring Data

Spring Data’s mission(任务, 使命) is to provide a familiar(熟悉的) and consistent(一致的), Spring-based programming model for data access while still retaining(保留,保持) the special traits(人的个性,显著的特点,特征) of the underlying(底层的) data store.

It makes it easy to use data access technologies, relational and non-relational databases, map-reduce frameworks, and cloud-based data services. This is an umbrella project which contains many subprojects that are specific to a given database. The projects are developed by working together with many of the companies and developers that are behind these exciting technologies.





Features

  • Powerful repository and custom object-mapping(对象映射) abstractions
  • Dynamic query derivation(引出,导出) from repository method names
  • Implementation domain(域) base classes providing basic properties
  • Support for transparent(透明的;清澈的;易识破的;显而易见的) auditing (审计)(created, last changed)
  • Possibility to integrate(整合) custom repository code
  • Easy Spring integration via JavaConfig and custom XML namespaces
  • Advanced(先进的;高等的,高深的) integration with Spring MVC controllers
  • Experimental(实验的;根据实验的;试验性的) support for cross-store persistence(持久化)





Main modules





Community(社区的) modules
  • Spring Data Aerospike - Spring Data module for Aerospike(是一个以分布式为核心基础,可基于行随机存取内存中索引、数据或SSD存储中数据的数据库,参考:csdn blogs).
  • Spring Data Couchbase - Spring Data module for Couchbase(一个具有高性能、可扩展性和可 用性强的数据库引擎,参考:blogs  segmentfault).
  • Spring Data DynamoDB - Spring Data module for DynamoDB(被设计成用来托管的NoSQL数据库服务、可预期的性能、可实现无缝扩展性和可靠性等核心问题,参考:百度百科).
  • Spring Data Elasticsearch - Spring Data module for Elasticsearch(ElasticSearch是一个基于Lucene的搜索服务器,参考:百度百科).
  • Spring Data Hazelcast - Provides Spring Data repository support for Hazelcast(Hazelcast是一个基于Java的开源内存数据网格,参考:Wikipedia).
  • Spring Data Jest - Spring Data for Elasticsearch based on the Jest REST client(jest是一款java Rest client,它支持SSL、proxy等等,来自:cnblogs).
  • Spring Data Neo4j - Spring based, object-graph(对象图) support and repositories for Neo4j(Neo4j是一个高性能的,NOSQL图形数据库,它将结构化数据存储在网络上而不是表中,参考:百度百科).
  • Spring Data Vault - Vault repositories built on top of Spring Data KeyValue.




Related(相关的) modules
  • Spring Data JDBC Extensions - Provides extensions to the JDBC support provided in the Spring Framework.
  • Spring for Apache Hadoop - Simplifies Apache Hadoop by providing a unified(统一) configuration model and easy to use APIs for using HDFS, MapReduce, Pig, and Hive.
  • Spring Content - Associate content with your Spring Data Entities and store it in a number of different stores including the File-system, S3, Database or Mongo’s GridFS.



Release train

Spring Data is an umbrella project consisting of independent projects with, in principle, different release cadences(不同的发行节奏). To manage the portfolio(文件夹), a BOM (Bill of Materials - see this example) is published with a curated set of(一个策划组) dependencies on the individual project. The release trains have names, not versions, to avoid confusion with the sub-projects.

The names are an alphabetic sequence(字母顺序) (so you can sort them chronologically) with names of famous computer scientists and software developers. When point releases of the individual projects accumulate to(积累) a critical mass, or if there is a critical bug(一个关键的错误) in one of them that needs to be available to everyone, the release train will push out “service releases” with names ending “-SRX”, where “X” is a number.

Currently the release train contains the following modules:

  • Spring Data Commons
  • Spring Data JPA
  • Spring Data KeyValue
  • Spring Data LDAP
  • Spring Data MongoDB
  • Spring Data Gemfire
  • Spring Data for Apache Geode
  • Spring Data REST
  • Spring Data Redis
  • Spring Data for Apache Cassandra
  • Spring Data for Apache Solr
  • Spring Data Couchbase (community module)
  • Spring Data Elasticsearch (community module)
  • Spring Data Neo4j (community module)




Quick Start

For a quick taste(尝,品尝), look at the following domain object:

@Entity
public class Employee {

  private @Id @GeneratedValue Long id;
  private String firstName, lastName, description;

  private Employee() {}

  public Employee(String firstName, String lastName, String description) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.description = description;
  }
}

This defines a simple JPA entity with a few fields. The following code shows a simple repository definition:

public interface EmployeeRepository extends CrudRepository<Employee, Long> {

  Employee findByFirstName(String firstName);

  List<Employee> findByLastName(String lastName);
}
This interface extends Spring Data’s CrudRepository and defines the type (Employee) and the id type (Long). Put this code inside a Spring Boot application with spring-boot-starter-data-jpa like this:
@SpringBootApplication
public class MyApp {

  public static void main(String[] args) {
    SpringApplication.run(MyApp.class, args);
  }
}
Launch your app and Spring Data (having been autoconfigured by Boot, SQL or NoSQL) will automatically craft a concrete set of operations:

  • save(Employee)
  • delete(Employee)
  • find(Employee)
  • find(Long)
  • findAll()

On top of the CRUD operations inherited from CrudRepository, the interface defines two query methods.

  • findByFirstName(…) automatically writes a JPA query based on firstName and only return the first employee found.
  • findByLastName(…) automatically writes a JPA query based on lastName and returns a collection.



Spring Boot starters

If you are using Spring Boot, you will inherit(继承) predefined versions for each project. To plugin a newer or older release train, configure the spring-data-releasetrain.version property to the release train iteration(迭代) name you want to use.

Spring Boot provides so called started POMs for a variety of SPring Data modules which pull in a curated set of dependencies you’ll need to use the individual modules. For details on that see the Spring Boot reference documentation.




说明:

1. MapReduce:MapReduce is a programming model and an associated implementation for processing and generating big data sets with a parallel(并行), distributed algorithm on a cluster。(来自:wikipedia


2. GemFire: Pivotal GemFire is the distributed, in-memory database for developers who are building the highest scaling(定标;缩放比例) and performing data-centric apps in the world.(来自:官网 csdn blogs


3. JPA:The Java Persistence API (JPA) is a Java application programming interface specification that describes the management of relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition.(Java持久性API(Java Persistence API,JPA)是一种Java应用程序编程接口规范,它描述了在使用Java平台标准版和Java平台企业版的应用程序中管理关系数据。)(来自:wikipedia


4. SPIs:没找到


5. LDAP:轻量级目录访问协议,The Lightweight Directory Access Protocol (LDAP; /ˈɛldæp/) is an open, vendor-neutral, industry standard application protocol for accessing and maintaining distributed directory information services over an Internet Protocol (IP) network (来自:Wikipedia


6. MongoDB:MongoDB (from humongous) is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas.(MongoDB(来自humongous)是一个免费且开源的跨平台的面向文档的数据库程序。分类为NoSQL数据库程序,MongoDB使用类似JSON的文档和模式。)(来自:Wikipedia


7. RESTful:Representational(具有代表性的) state transfer (REST) or RESTful web services are a way of providing interoperability(互用性,协同工作的能力) between computer systems on the Internet. REST-compliant(兼容) Web services allow requesting systems to access and manipulate textual representations(操纵文本表示) of Web resources using a uniform(规格一致的) and predefined(预定义的) set of stateless(无状态) operations. Other forms of Web services exist, which expose(暴露) their own arbitrary(任意的) sets of operations such as WSDL(网络服务描述语言是Web Service的描述语言,它包含一系列描述某个web service的定义,来自:百度百科) and SOAP(简单对象访问协议,来自:百度百科).(来自:wikipedia)


8. Cassandra:开源分布式NoSQL数据库系统,参看之前笔记,或官网,或百度百科


9. Apache Hadoop:Apache Hadoop是一套用于在由通用硬件构建的大型集群上运行应用程序的框架。它实现了Map/Reduce编程范型,计算任务会被分割成小块(多次)运行在不同的节点上。除此之外,它还提供了一款分布式文件系统(HDFS),数据被存储在计算节点上以提供极高的跨数据中心聚合带宽。(来自:百度百科


10. Pig&Hive:(参考:csdn


11. S3:Database Backup Amazon S3 to create Database Backup & Restore Database Backup easy. Database Backups can be uploaded to Amazon S3 Cloud to store database backup on safe place – Amazon S3 Cloud (来自:workpress 文档


12. GridFS:GridFS是一种将大型文件存储在MongoDB的文件规范。所有官方支持的驱动均实现了GridFS规范。(来自:百度百科

 类似资料: