Spring Data Framework
The extension or use of template scaffolding, which is a secondary development tool. According to this template, you can easily extract the files in the template and develop your own Spring Data
framework.This case is intended for learning and communication and cannot be used for actual production.
Briefly describe how to apply Spring data templates to develop your own Spring Data
framework.
First, you need to create a meaningful project name, which is SpringData
the name of the current frame. For example, to create a cached SpringData
frame, just name it spring-data-cache
. If you want to create a redis
’s SpringData
, it is named spring-data-redis
.
Creating suitable package
the top pkg
, for example, with a spring-data-cache
frame, for example, it package
should be org.springframework.data.cache
, and end is the name of the frame.
Package
And implementation class introductionIn general, the top package
Here are the main core of the package to achieve spring-data, which usually are:
Query、Repository、Entity、Config
annotation classes for configuration
Query
Query annotations, you can configure this annotation in the interface method of repo to complete the custom conditional query.CountQuery
Inherit Query to complete count queryModel
Entity model annotation, after annotation, you can read the information in the entity annotation to facilitate the persistence operationSetting
Entity model annotations, such as the configuration path of the current entityField
Entity model attribute annotation, you can map attributesScore
Entity attribute annotation, attribute additional configuration informationconfig: configuration type, based onSpringData
the configuration base class, Entity
scan class, etc.
AbstractTemplateConfiguration
The template configuration base class, some common configuration information can be preferentially configured in itTemplateEntityClassScanner
Scanning Repository
used EntityClass
, in AbstractTemplateConfiguration.getInitialEntitySet
dependence of the type of processTemplateNamespaceHandler
Configuration injection of namespaces, you don’t needcore : Core business is done repository
to achieve the underlying business CRUD operations
converter: underlying interface entity and repository
interaction time, object-type field converter
DateTimeConverter
Date time and string conversion, there can also be conversion implementations of other classesMappingTemplateConverter
Map converter to complete the mapping between the underlying and the entityTemplateConverter
Map converter interface definitionmapping: mapping between entities and underlying interface objects, field types
TemplatePersistentEntity
Persistent entity object interface, you can define additional information necessary for a number of persistent entities, to facilitate the realization of repository
the use of timeTemplatePersistentProperty
Persistent entity object attribute interface, additional necessary information to define persistent attributesSimpleTemplateMappingContext
Mapping context, providing methods for building persistent entities and attributesSimpleTemplatePersistentEntity
Persistent entity object interface implementationSimpleTemplatePersistentProperty
Persistent entity object attribute interface implementationquery : query string, annotation inquiry, CRUD operation conditions of the core implementation
MyTplTemplate
Template class, CRUD operations is completed, provided to the repository
underlying implementation
TemplateOperations
Template class interface, complete the definition of CRUD operations
enums : enum class configuration
repository: repository
interface rules and main implementation
cdi: CDI implemented using dependency injection, without depending on spring
the case of injection, the injection may be used
TemplateRepositoryBean
Use CdiRepositoryBean Creating Repository
object instancesTemplateRepositoryExtension
A portable CDI extensions, it is Repository
registered bean, provided CdiRepositoryBean
to achieve the requiredconfig: based onSpringData
the configuration class, open the current framework or some basic configuration
EnableTemplateRepositories
Core configuration, whether open spring-data-template
framework and loaded configurationTemplateRepositoriesRegistrar
Set RepositoriesRegistrar
registration implementationTemplateRepositoryConfigurationExtension
Provide RepositoryConfiguration
configuration information to achievequery: Based on SpringData
the query implementation, basic needs SpringCommon
some interfaces and classes to complete
repository
interface annotation SQL string query and PartTree
queryrepository
interface annotation SQL string queries and PartTree
queriesTemplateQueryMethod
Provide repository
basic information about the interface query methodSimpleTemplateQueryCreator
repository
Dynamically generate SQL query statements through interface query methodsTemplateEntityMetadata
Provide repository
metadata information for persistent entity objectssupport: current repository
core implementation
TemplateEntityInformation
Expand EntityMetadata
to add the ability to query entity instance informationMappingTemplateEntityInformation
Implement EntityInformation to populate Entity related information. And you can take advantage of Converter/PersistentEntity
data conversion and the filling.TemplateEntityInformationCreator
Entity information TemplateEntityInformation
Object creator InterfaceTemplateEntityInformationCreatorImpl
Entity information TemplateEntityInformation
Object creator interfaceTemplateRepositoryFactory
By TemplateRepositoryFactory
Creating TemplateRepository
instancesTemplateRepositoryFactoryBean
Core class, create an TemplateRepositoryFactory
instanceAbstractTemplateRepository
Abstract implementation of repo , easy to expandSimpleTemplateRepository
Simple implementation TemplateRepository
, supporting entity and string generics, string type IdNumberKeyedRepository
Simple implementation TemplateRepository
, Number
type IdUUIDTemplateRepository
Simple implementation TemplateRepository
, UUID
type IdTemplateRepository
Top repository
interfaces, all interfaces inherit the completion CRUD
of repo
the operation
core
related to other related businessespackage
SpringData
And can SpringBoot、SpringCloud、SpringFramework
seamlessly integrate, develop their own SpringData
framework for ease of use and expand the system. This framework is just a template to help you understand and learn the underlying interface knowledge of SpringData.