기본 개념
ElastiCORE의 핵심 개념과 작동 방식을 이해하여 프레임워크를 효과적으로 활용하세요.
ElastiCORE 아키텍처
핵심 구성 요소
1. DSL (Domain Specific Language)
직관적인 YAML 기반 문법으로 도메인 모델을 정의합니다.
entity:
User:
meta: entity @expose(20) @audited
fields:
id: string(36)! @id @genid
username: string(50)! @search(like)
email: string(100)! @search(eq) @unique
isActive: boolean @default(true)
2. 어노테이션 프로세서
컴파일 시점에 @EnableElastiCore 어노테이션을 감지하고 자동 코드 생성을 시작합니다.
@EnableElastiCore // 이 어노테이션이 마법을 시작합니다
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
3. 코드 생성 엔진
블루프린트 정의를 분석하고 Spring Boot 표준 패턴에 따라 Java 코드를 자동 생성합니다.
핵심 개념
1. 블루프린트(Blueprint)
프로젝트의 도메인 모델을 정의하는 YAML 파일의 체계적인 모음입니다.
src/main/resources/blueprint/
├── user/ # 사용자 도메인
│ ├── env.yml # 환경 설정
│ ├── entity.yml # 엔티티 정의
│ └── dto.yml # DTO 정의
├── product/ # 상품 도메인
│ ├── env.yml
│ └── model.yml
└── order/ # 주문 도메인
└── models.yml
2. 도메인(Domain)
관련된 엔티티와 비즈니스 로직을 그룹화하는 논리적 단위입니다.
user/env.yml
elasticore:
enable: true
config:
domainName: user
framework: springboot
mode: jpa
j2ee: jakarta
namespace:
entity: com.example.user.entity
dto: com.example.user.dto
repository: com.example.user.repository
service: com.example.user.service
control: com.example.user.controller
3. 엔티티(Entity)
데이터베이스 테이블에 매핑되는 JPA 엔티티를 정의합니다.
entity:
User:
meta: entity @expose(20) @audited @table(app_users)
fields:
id: string(36)! @id @genid
username: string(50)! @search(like) @unique
email: string(100)! @search(eq) @unique
password: string(255)! @updatable(false)
profile: UserProfile @OneToOne @cascade(ALL)
roles: List<Role> @ManyToMany @cascade(PERSIST)
createdDate: datetime @jpa:org.springframework.data.annotation.CreatedDate
lastModifiedDate: datetime @jpa:org.springframework.data.annotation.LastModifiedDate
4. 검색 DTO(Search DTO)
@expose 또는 @searchable 어노테이션 사용 시 자동 생성되는 동적 검색 전용 DTO입니다.
// 자동 생성되는 SearchDTO:
public class UserSearchDTO implements PageableObject {
private String username; // @search(like) → 부분 일치
private String email; // @search(eq) → 정확한 일치
private int pageNumber = 0; // 페이지네이션
private int pageSize = 20;
private String sortCode;
}
5. 엔티티 관계
entity:
Post:
meta: entity @expose(10)
fields:
id: long @id @sequence
title: string(200)! @search(like)
content: text
author: User @ManyToOne @fetchjoin # 자동 N+1 문제 해결
comments: List<Comment> @OneToMany(mappedBy="post") @dtype(List<CommentDTO>)
tags: List<Tag> @ManyToMany @cascade(PERSIST)
Comment:
meta: entity @service(20) # Service만 생성, Controller 없음
fields:
id: long @id @sequence
content: text!
post: Post @ManyToOne
author: User @ManyToOne @fetchjoin
createdDate: datetime @jpa:org.springframework.data.annotation.CreatedDate
어노테이션 시스템
메타 어노테이션 (엔티티/DTO 레벨)
| 어노테이션 | 설명 | 생성 코드 |
|---|---|---|
@expose(n) | REST API + 검색 DTO 자동 생성 | Controller + Service + SearchDTO |
@service(n) | Service만 생성 (API 없음) | Service + SearchDTO만 생성 |
@audited | JPA Envers 감사 추적 | @Audited |
@abstract | 추상 엔티티 (상속용) | abstract class |
@extend(Parent) | 엔티티 상속 | extends ParentEntity |
@table(name) | 테이블명 지정 | @Table(name = "custom_name") |
@pageable(n) | 기본 페이지 크기 | Pageable 파라미터 추가 |
필드 어노테이션
| 어노테이션 | 설명 | 생성 코드 |
|---|---|---|
@id | 기본키 필드 | @Id |
@sequence | 자동 증가 ID | @GeneratedValue(IDENTITY) |
@genid | 커스텀 ID 생성기 | env.yml 설정 기반 |
@search(type) | 검색 조건 | SearchDTO 필드 생성 |
@default(value) | 기본값 | 생성자에서 기본값 설정 |
@unique | 유니크 제약 조건 | @Column(unique = true) |
@updatable(false) | 수정 불가 필드 | @Column(updatable = false) |
@fetchjoin | JOIN FETCH 최적화 | 자동 N+1 문제 해결 |
검색 어노테이션
entity:
Product:
meta: entity @expose(20)
fields:
name: string(100) @search(like) # 부분 일치 (LIKE %name%)
sku: string(20) @search(eq) # 정확한 일치 (= sku)
price: bigdecimal(10,2) @search(between) # 범위 검색 (BETWEEN)
category: CategoryEnum @search(in) # 다중 선택 (IN)
rating: int @search(gte) # 이상 (>=)
deletedDate: datetime @search(null) # IS NULL 검사