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.
In general, the top package
Here are the main core of the package to achieve spring-data, which usually are:
-
annotations: annotations,
Query、Repository、Entity、Config
annotation classes for configurationQuery
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 information
-
config: configuration type, based on
SpringData
the configuration base class,Entity
scan class, etc.AbstractTemplateConfiguration
The template configuration base class, some common configuration information can be preferentially configured in itTemplateEntityClassScanner
ScanningRepository
usedEntityClass
, inAbstractTemplateConfiguration.getInitialEntitySet
dependence of the type of processTemplateNamespaceHandler
Configuration injection of namespaces, you don't need
-
core : Core business is done
repository
to achieve the underlying business CRUD operations-
converter: underlying interface entity and
repository
interaction time, object-type field converterDateTimeConverter
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 definition
-
mapping: 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 ofrepository
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 implementation
-
query : query string, annotation inquiry, CRUD operation conditions of the core implementation
-
MyTplTemplate
Template class, CRUD operations is completed, provided to therepository
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 usedTemplateRepositoryBean
Use CdiRepositoryBean CreatingRepository
object instancesTemplateRepositoryExtension
A portable CDI extensions, it isRepository
registered bean, providedCdiRepositoryBean
to achieve the required
-
config: based on
SpringData
the configuration class, open the current framework or some basic configurationEnableTemplateRepositories
Core configuration, whether openspring-data-template
framework and loaded configurationTemplateRepositoriesRegistrar
SetRepositoriesRegistrar
registration implementationTemplateRepositoryConfigurationExtension
ProvideRepositoryConfiguration
configuration information to achieve
-
query: Based on
SpringData
the query implementation, basic needsSpringCommon
some interfaces and classes to complete- simple : Provides a simple implementation of the
repository
interface annotation SQL string query andPartTree
query - complex : Provides a complex implementation of
repository
interface annotation SQL string queries andPartTree
queries TemplateQueryMethod
Providerepository
basic information about the interface query methodSimpleTemplateQueryCreator``repository
Dynamically generate SQL query statements through interface query methodsTemplateEntityMetadata
Providerepository
metadata information for persistent entity objects
- simple : Provides a simple implementation of the
-
support: current
repository
core implementationTemplateEntityInformation
ExpandEntityMetadata
to add the ability to query entity instance informationMappingTemplateEntityInformation
Implement EntityInformation to populate Entity related information. And you can take advantage ofConverter/PersistentEntity
data conversion and the filling.TemplateEntityInformationCreator
Entity informationTemplateEntityInformation
Object creator InterfaceTemplateEntityInformationCreatorImpl
Entity informationTemplateEntityInformation
Object creator interfaceTemplateRepositoryFactory
ByTemplateRepositoryFactory
CreatingTemplateRepository
instancesTemplateRepositoryFactoryBean
Core class, create anTemplateRepositoryFactory
instanceAbstractTemplateRepository
Abstract implementation of repo , easy to expandSimpleTemplateRepository
Simple implementationTemplateRepository
, supporting entity and string generics, string type IdNumberKeyedRepository
Simple implementationTemplateRepository
,Number
type IdUUIDTemplateRepository
Simple implementationTemplateRepository
,UUID
type Id
-
TemplateRepository
Toprepository
interfaces, all interfaces inherit the completionCRUD
ofrepo
the operation
-
-
util : some common tools
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.