public abstract class BaseJpaEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, unique = true)
private Long id;
}
@Entity
@Table(name = "check_lists")
public class CheckListEntity extends BaseJpaEntity {
@Column(name = "created", nullable = false)
private Instant created;
@OneToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "creator_id", nullable = false)
private ProfileEntity creator;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "template_id", nullable = false)
private TemplateEntity template;
@OneToMany(mappedBy = "checkList", cascade = CascadeType.ALL, orphanRemoval = true)
private List<AnswerEntity> answers;
@OneToMany(mappedBy = "checkList", cascade = CascadeType.ALL, orphanRemoval = true)
private List<GoodPracticeEntity> goodPractices;
@OneToMany(mappedBy = "checkList", cascade = CascadeType.ALL, orphanRemoval = true)
private List<SkillToImproveEntity> skillsToImprove;
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "previous_plan_fact_id", referencedColumnName = "id")
private CheckListPlanFactEntity previousPlanFact;
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "current_plan_fact_id", referencedColumnName = "id")
private CheckListPlanFactEntity currentPlanFact;
}
@Entity
@Table(name = "check_list_good_practices")
public class GoodPracticeEntity extends BaseJpaEntity {
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "list_id", nullable = false)
private CheckListEntity checkList;
@Column(name = "text", nullable = false, columnDefinition = "TEXT")
private String text;
}
@Entity
@Table(name = "check_list_skills_to_improve")
public class SkillToImproveEntity extends BaseJpaEntity {
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "list_id", nullable = false)
private CheckListEntity checkList;
@Column(name = "text", nullable = false, columnDefinition = "TEXT")
private String text;
}
@Entity
@Table(name = "check_list_answers")
public class AnswerEntity extends BaseJpaEntity {
@Column(name = "affirmative", nullable = false)
private Boolean affirmative;
@Column(name = "reason", columnDefinition = "TEXT")
private String reason;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "check_list_id", nullable = false)
private CheckListEntity checkList;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "question_id", nullable = false)
private QuestionEntity question;
}
@Entity
@Table(name = "check_list_templates")
public class TemplateEntity extends BaseJpaEntity {
@Column(name = "created", nullable = false)
private Instant created;
@Column(name = "description", nullable = false, columnDefinition = "TEXT")
private String description;
@OneToMany(mappedBy = "template", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<BlockPositionEntity> blocks;
@OneToMany(mappedBy = "template", cascade = CascadeType.ALL)
private Set<CheckListEntity> checkLists;
}
@Entity
@Table(name = "check_list_templates_blocks")
public class BlockPositionEntity extends BaseJpaEntity {
@Column(name = "position", nullable = false)
private Integer position;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "template_id", nullable = false)
private TemplateEntity template;
@ManyToOne
@JoinColumn(name = "block_id", nullable = false)
private BlockEntity block;
}
@Entity
@Table(name = "check_list_blocks")
public class BlockEntity extends BaseJpaEntity {
@Column(name = "title", nullable = false)
private String title;
@OneToMany(mappedBy = "block", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
private Set<QuestionPositionEntity> questions;
}
@Entity
@Table(name = "check_list_blocks_questions")
public class QuestionPositionEntity extends BaseJpaEntity {
@Column(name = "position", nullable = false)
private Integer position;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "block_id", nullable = false)
private BlockEntity block;
@ManyToOne
@JoinColumn(name = "question_id", nullable = false)
private QuestionEntity question;
}
@Entity
@Table(name = "check_list_questions")
public class QuestionEntity extends BaseJpaEntity {
@Column(name = "text", nullable = false, columnDefinition = "TEXT")
private String text;
}
@Repository
public interface CheckListRepository extends JpaRepository<CheckListEntity, Long> {
@Query("""
SELECT cle
FROM CheckListEntity cle
LEFT JOIN FETCH cle.template AS t
LEFT JOIN FETCH t.blocks AS bp
LEFT JOIN FETCH bp.block
LEFT JOIN FETCH cle.creator
LEFT JOIN FETCH cle.previousPlanFact
LEFT JOIN FETCH cle.currentPlanFact
WHERE (:from IS NULL OR cle.created > :from)
AND (:to IS NULL OR cle.created < :to)
ORDER BY cle.employeeEmail ASC,
cle.created DESC
""")
List<CheckListEntity> findAllByPeriod(Instant from, Instant to);
}
@Repository
public interface CheckListRepository extends JpaRepository<CheckListEntity, Long> {
@Query("""
SELECT cle
FROM CheckListEntity cle
LEFT JOIN FETCH cle.template AS t
LEFT JOIN FETCH t.blocks AS bp
LEFT JOIN FETCH bp.block
LEFT JOIN FETCH cle.creator
LEFT JOIN FETCH cle.previousPlanFact
LEFT JOIN FETCH cle.currentPlanFact
WHERE (:from IS NULL OR cle.created > :from)
AND (:to IS NULL OR cle.created < :to)
""")
List<CheckListEntity> findAllByPeriod(Instant from, Instant to);
@Query("""
SELECT cle
FROM CheckListEntity cle
LEFT JOIN FETCH cle.goodPractices
WHERE cle in :checkLists
""")
List<CheckListEntity> addGoodPractices(List<CheckListEntity> checkLists);
@Query("""
SELECT cle
FROM CheckListEntity cle
LEFT JOIN FETCH cle.skillsToImprove
WHERE cle in :checkLists
""")
List<CheckListEntity> addSkillsToImprove(List<CheckListEntity> checkLists);
@Query("""
SELECT cle
FROM CheckListEntity cle
LEFT JOIN FETCH cle.answers AS a
LEFT JOIN FETCH a.question
WHERE cle in :checkLists
ORDER BY cle.employeeEmail ASC,
cle.created DESC
""")
List<CheckListEntity> addAnswersAndSort(List<CheckListEntity> checkLists);
}
@Repository
@RequiredArgsConstructor
public class CheckListDao {
private final CheckListRepository checkListRepository;
public List<CheckListEntity> findAllByPeriod(Instant from, Instant to) {
return executeChain(checkListRepository.findAllByPeriod(from, to),
checkListRepository::addGoodPractices,
checkListRepository::addSkillsToImprove,
checkListRepository::addAnswersAndSort);
}
@SafeVarargs
private static <T> T executeChain(T initialResult, UnaryOperator<T>... operators) {
T result = initialResult;
for (UnaryOperator<T> operator : operators) {
result = operator.apply(result);
}
return result;
}
}
select checkliste0_.`id` as id1_20_0_, templateen1_.`id` as id1_18_1_, (и все остальные поля из check_lists, check_list_templates, check_list_blocks, profiles и check_list_plan_fact_history) from `check_lists` checkliste0_ left outer join `check_list_templates` templateen1_ on checkliste0_.`template_id`=templateen1_.`id` left outer join `check_list_templates_blocks` blocks2_ on templateen1_.`id`=blocks2_.`template_id` left outer join `check_list_blocks` blockentit3_ on blocks2_.`block_id`=blockentit3_.`id` left outer join `profiles` profileent4_ on checkliste0_.`creator_id`=profileent4_.`id` left outer join `check_list_plan_fact_history` checklistp5_ on checkliste0_.`previous_plan_fact_id`=checklistp5_.`id` left outer join `check_list_plan_fact_history` checklistp6_ on checkliste0_.`current_plan_fact_id`=checklistp6_.`id` where (? is null or checkliste0_.`created`>?) and (? is null or checkliste0_.`created`<?)
select questions0_.`block_id` as block_id3_12_0_, questions0_.`id` as id1_12_0_, ... from `check_list_blocks_questions` questions0_ inner join `check_list_questions` questionen1_ on questions0_.`question_id`=questionen1_.`id` where questions0_.`block_id`=?
... (по кол-ву блоков)
select questions0_.`block_id` as block_id3_12_0_, questions0_.`id` as id1_12_0_, ... from `check_list_blocks_questions` questions0_ inner join `check_list_questions` questionen1_ on questions0_.`question_id`=questionen1_.`id` where questions0_.`block_id`=?
select checkliste0_.`id` as id1_20_0_, goodpracti1_.`id` as id1_13_1_, ... from `check_lists` checkliste0_ left outer join `check_list_good_practices` goodpracti1_ on checkliste0_.`id`=goodpracti1_.`list_id` where checkliste0_.`id` in (? , ? , ... , ? , ?)
select checkliste0_.`id` as id1_20_0_, skillstoim1_.`id` as id1_17_1_, ... from `check_lists` checkliste0_ left outer join `check_list_skills_to_improve` skillstoim1_ on checkliste0_.`id`=skillstoim1_.`list_id` where checkliste0_.`id` in (? , ? , ... , ? , ?)
select checkliste0_.`id` as id1_20_0_, answers1_.`id` as id1_10_1_, ... from `check_lists` checkliste0_ left outer join `check_list_answers` answers1_ on checkliste0_.`id`=answers1_.`check_list_id` left outer join `check_list_questions` questionen2_ on answers1_.`question_id`=questionen2_.`id` where checkliste0_.`id` in (? , ? , ... , ? , ?) order by checkliste0_.`employee_email` ASC, checkliste0_.`created` DESC
select checkliste0_.`id` as id1_20_0_, templateen1_.`id` as id1_18_1_, ... where (? is null or checkliste0_.`created`>?) and (? is null or checkliste0_.`created`<?) order by checkliste0_.`employee_email` ASC, checkliste0_.`created` DESC
select blocks0_.`template_id` as template4_19_2_, blocks0_.`id` as id1_19_2_, ... from `check_list_templates_blocks` blocks0_ inner join `check_list_blocks` blockentit1_ on blocks0_.`block_id`=blockentit1_.`id` where blocks0_.`template_id` in (select templateen1_.`id` from `check_lists` checkliste0_ left outer join `check_list_templates` templateen1_ on checkliste0_.`template_id`=templateen1_.`id` left outer join `profiles` profileent2_ on checkliste0_.`creator_id`=profileent2_.`id` left outer join `check_list_plan_fact_history` checklistp3_ on checkliste0_.`previous_plan_fact_id`=checklistp3_.`id` left outer join `check_list_plan_fact_history` checklistp4_ on checkliste0_.`current_plan_fact_id`=checklistp4_.`id` where (? is null or checkliste0_.`created`>?) and (? is null or checkliste0_.`created`<?) )
N+1 queries detected with eager fetching on the entity BlockEntity
at CheckListService.getLists(CheckListService.java:164)
Hint: Missing Lazy fetching configuration on a field of type BlockEntity of one of the entities fetched in the query
select questions0_.`block_id` as block_id3_12_2_, questions0_.`id` as id1_12_2_, ... from `check_list_blocks_questions` questions0_
inner join `check_list_questions` questionen1_ on questions0_.`question_id`=questionen1_.`id`
where questions0_.`block_id` in
(select blockentit1_.`id` from `check_list_templates_blocks` blocks0_
inner join `check_list_blocks` blockentit1_ on blocks0_.`block_id`=blockentit1_.`id` where blocks0_.`template_id` in
(select templateen1_.`id` from `check_lists` checkliste0_
left outer join `check_list_templates` templateen1_ on checkliste0_.`template_id`=templateen1_.`id`
left outer join `profiles` profileent2_ on checkliste0_.`creator_id`=profileent2_.`id` left outer join `check_list_plan_fact_history` checklistp3_ on checkliste0_.`previous_plan_fact_id`=checklistp3_.`id`
left outer join `check_list_plan_fact_history` checklistp4_ on checkliste0_.`current_plan_fact_id`=checklistp4_.`id` where (? is null or checkliste0_.`created`>?) and (? is null or checkliste0_.`created`<?) ))
N+1 queries detected with eager fetching on the entity QuestionEntity
at CheckListService.getLists(CheckListService.java:164)
Hint: Missing Lazy fetching configuration on a field of type QuestionEntity of one of the entities fetched in the query
@Entity
@Table(name = "check_lists")
public class CheckListEntity extends BaseJpaEntity {
...
@OneToMany(mappedBy = "checkList", cascade = CascadeType.ALL, orphanRemoval = true)
@BatchSize(size = 150)
private Set<AnswerEntity> answers;
@OneToMany(mappedBy = "checkList", cascade = CascadeType.ALL, orphanRemoval = true)
@BatchSize(size = 150)
private Set<GoodPracticeEntity> goodPractices;
@OneToMany(mappedBy = "checkList", cascade = CascadeType.ALL, orphanRemoval = true)
@BatchSize(size = 150)
private Set<SkillToImproveEntity> skillsToImprove;
...
}
@Entity
@Table(name = "check_list_templates")
public class TemplateEntity extends BaseJpaEntity {
...
@OneToMany(mappedBy = "template", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@BatchSize(size = 150)
private Set<BlockPositionEntity> blocks;
...
}
@Entity
@Table(name = "check_list_blocks")
public class BlockEntity extends BaseJpaEntity {
...
@OneToMany(mappedBy = "block", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@BatchSize(size = 150)
private Set<QuestionPositionEntity> questions;
...
}
select checkliste0_.`id` as id1_20_0_, ... from `check_lists` checkliste0_ left outer join `check_list_templates` templateen1_ on checkliste0_.`template_id`=templateen1_.`id` left outer join `profiles` profileent2_ on checkliste0_.`creator_id`=profileent2_.`id` left outer join `check_list_plan_fact_history` checklistp3_ on checkliste0_.`previous_plan_fact_id`=checklistp3_.`id` left outer join `check_list_plan_fact_history` checklistp4_ on checkliste0_.`current_plan_fact_id`=checklistp4_.`id` where (? is null or checkliste0_.`created`>?) and (? is null or checkliste0_.`created`<?) order by checkliste0_.`employee_email` ASC, checkliste0_.`created` DESC
select blocks0_.`template_id` as template4_19_2_, blocks0_.`id` as id1_19_2_, ... from `check_list_templates_blocks` blocks0_ inner join `check_list_blocks` blockentit1_ on blocks0_.`block_id`=blockentit1_.`id` where blocks0_.`template_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
N+1 queries detected with eager fetching on the entity BlockEntity
at CheckListService.getLists(CheckListService.java:164)
Hint: Missing Lazy fetching configuration on a field of type BlockEntity of one of the entities fetched in the query
select questions0_.`block_id` as block_id3_12_2_, questions0_.`id` as id1_12_2_, ... from `check_list_blocks_questions` questions0_ inner join `check_list_questions` questionen1_ on questions0_.`question_id`=questionen1_.`id` where questions0_.`block_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
N+1 queries detected with eager fetching on the entity QuestionEntity
at CheckListService.getLists(CheckListService.java:164)
Hint: Missing Lazy fetching configuration on a field of type QuestionEntity of one of the entities fetched in the query
select blocks0_.`template_id` as template4_19_2_, blocks0_.`id` as id1_19_2_, ... from `check_list_templates_blocks` blocks0_ inner join `check_list_blocks` blockentit1_ on blocks0_.`block_id`=blockentit1_.`id` where blocks0_.`template_id`=?
N+1 queries detected with eager fetching on the entity BlockPositionEntity
at CheckListService.getLists(CheckListService.java:164)
Hint: Missing Lazy fetching configuration on a field of type BlockPositionEntity of one of the entities fetched in the query
select questions0_.`block_id` as block_id3_12_2_, questions0_.`id` as id1_12_2_, ... from `check_list_blocks_questions` questions0_ inner join `check_list_questions` questionen1_ on questions0_.`question_id`=questionen1_.`id` where questions0_.`block_id`=?
N+1 queries detected with eager fetching on the entity QuestionPositionEntity
at CheckListService.getLists(CheckListService.java:164)
Hint: Missing Lazy fetching configuration on a field of type QuestionPositionEntity of one of the entities fetched in the query
select goodpracti0_.`list_id` as list_id3_13_1_, goodpracti0_.`id` as id1_13_1_, ... from `check_list_good_practices` goodpracti0_ where goodpracti0_.`list_id` in (?, ?, и еще 73 значения)
select skillstoim0_.`list_id` as list_id3_17_1_, skillstoim0_.`id` as id1_17_1_, ... from `check_list_skills_to_improve` skillstoim0_ where skillstoim0_.`list_id` in (?, ?, и еще 73 значения)
select answers0_.`check_list_id` as check_li4_10_1_, answers0_.`id` as id1_10_1_, ... from `check_list_answers` answers0_ where answers0_.`check_list_id` in (?, ?, и еще 73 значения)
select goodpracti0_.`list_id` as list_id3_13_1_, goodpracti0_.`id` as id1_13_1_, ... from `check_list_good_practices` goodpracti0_ where goodpracti0_.`list_id` in (?, ?, и еще 35 значений)
select skillstoim0_.`list_id` as list_id3_17_1_, skillstoim0_.`id` as id1_17_1_, ... from `check_list_skills_to_improve` skillstoim0_ where skillstoim0_.`list_id` in (?, ?, и еще 35 значений)
select answers0_.`check_list_id` as check_li4_10_1_, answers0_.`id` as id1_10_1_, ... from `check_list_answers` answers0_ where answers0_.`check_list_id` in (?, ?, и еще 35 значений)
select goodpracti0_.`list_id` as list_id3_13_1_, goodpracti0_.`id` as id1_13_1_, ... from `check_list_good_practices` goodpracti0_ where goodpracti0_.`list_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
select skillstoim0_.`list_id` as list_id3_17_1_, skillstoim0_.`id` as id1_17_1_, ... from `check_list_skills_to_improve` skillstoim0_ where skillstoim0_.`list_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
select answers0_.`check_list_id` as check_li4_10_1_, answers0_.`id` as id1_10_1_, ... from `check_list_answers` answers0_ where answers0_.`check_list_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
select goodpracti0_.`list_id` as list_id3_13_1_, goodpracti0_.`id` as id1_13_1_, ... from `check_list_good_practices` goodpracti0_ where goodpracti0_.`list_id` in (?, ?, ?, ?, ?, ?, ?, ?)
select skillstoim0_.`list_id` as list_id3_17_1_, skillstoim0_.`id` as id1_17_1_, ... from `check_list_skills_to_improve` skillstoim0_ where skillstoim0_.`list_id` in (?, ?, ?, ?, ?, ?, ?, ?)
select answers0_.`check_list_id` as check_li4_10_1_, answers0_.`id` as id1_10_1_, ... from `check_list_answers` answers0_ where answers0_.`check_list_id` in (?, ?, ?, ?, ?, ?, ?, ?)
public static BatchingEntityLoaderBuilder getBuilder(SessionFactoryImplementor factory) {
switch(factory.getSessionFactoryOptions().getBatchFetchStyle()) {
case PADDED:
return PaddedBatchingEntityLoaderBuilder.INSTANCE;
case DYNAMIC:
return DynamicBatchingEntityLoaderBuilder.INSTANCE;
default:
return LegacyBatchingEntityLoaderBuilder.INSTANCE;
}
}
select checkliste0_.`id` as id1_20_0_, ... from `check_lists` checkliste0_ left outer join `check_list_templates` templateen1_ on checkliste0_.`template_id`=templateen1_.`id` left outer join `profiles` profileent2_ on checkliste0_.`creator_id`=profileent2_.`id` left outer join `check_list_plan_fact_history` checklistp3_ on checkliste0_.`previous_plan_fact_id`=checklistp3_.`id` left outer join `check_list_plan_fact_history` checklistp4_ on checkliste0_.`current_plan_fact_id`=checklistp4_.`id` where (? is null or checkliste0_.`created`>?) and (? is null or checkliste0_.`created`<?) order by checkliste0_.`employee_email` ASC, checkliste0_.`created` DESC
select blocks0_.`template_id` as template4_19_2_, blocks0_.`id` as id1_19_2_, ... from `check_list_templates_blocks` blocks0_ inner join `check_list_blocks` blockentit1_ on blocks0_.`block_id`=blockentit1_.`id` where blocks0_.`template_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
N+1 queries detected with eager fetching on the entity BlockEntity
at CheckListService.getLists(CheckListService.java:164)
Hint: Missing Lazy fetching configuration on a field of type BlockEntity of one of the entities fetched in the query
select questions0_.`block_id` as block_id3_12_2_, questions0_.`id` as id1_12_2_, questions0_.`id` as id1_12_1_, ... from `check_list_blocks_questions` questions0_ inner join `check_list_questions` questionen1_ on questions0_.`question_id`=questionen1_.`id` where questions0_.`block_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
N+1 queries detected with eager fetching on the entity QuestionEntity
at CheckListService.getLists(CheckListService.java:164)
Hint: Missing Lazy fetching configuration on a field of type QuestionEntity of one of the entities fetched in the query
select goodpracti0_.`list_id` as list_id3_13_1_, goodpracti0_.`id` as id1_13_1_, ... from `check_list_good_practices` goodpracti0_ where goodpracti0_.`list_id` in (?, ?, и еще 62 значения)
select skillstoim0_.`list_id` as list_id3_17_1_, skillstoim0_.`id` as id1_17_1_, ... from `check_list_skills_to_improve` skillstoim0_ where skillstoim0_.`list_id` in (?, ?, и еще 62 значения)
select answers0_.`check_list_id` as check_li4_10_1_, answers0_.`id` as id1_10_1_, ... from `check_list_answers` answers0_ where answers0_.`check_list_id` in (?, ?, и еще 62 значения)
select goodpracti0_.`list_id` as list_id3_13_1_, goodpracti0_.`id` as id1_13_1_, ... from `check_list_good_practices` goodpracti0_ where goodpracti0_.`list_id` in (?, ?, и еще 62 значения)
select skillstoim0_.`list_id` as list_id3_17_1_, skillstoim0_.`id` as id1_17_1_, ... from `check_list_skills_to_improve` skillstoim0_ where skillstoim0_.`list_id` in (?, ?, и еще 62 значения)
select answers0_.`check_list_id` as check_li4_10_1_, answers0_.`id` as id1_10_1_, ... from `check_list_answers` answers0_ where answers0_.`check_list_id` in (?, ?, и еще 62 значения)
select goodpracti0_.`list_id` as list_id3_13_1_, goodpracti0_.`id` as id1_13_1_, ... from `check_list_good_practices` goodpracti0_ where goodpracti0_.`list_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
select skillstoim0_.`list_id` as list_id3_17_1_, skillstoim0_.`id` as id1_17_1_, ... where skillstoim0_.`list_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
select answers0_.`check_list_id` as check_li4_10_1_, answers0_.`id` as id1_10_1_, ... from `check_list_answers` answers0_ where answers0_.`check_list_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
public PaddedBatchingEntityLoader(...) {
super(persister);
this.batchSizes = ArrayHelper.getBatchSizes(maxBatchSize);
this.loaders = new EntityLoader[this.batchSizes.length];
Builder entityLoaderBuilder = EntityLoader.forEntity(persister).withInfluencers(loadQueryInfluencers).withLockOptions(lockOptions);
this.loaders[0] = entityLoaderBuilder.withBatchSize(this.batchSizes[0]).byPrimaryKey();
for(int i = 1; i < this.batchSizes.length; ++i) {
this.loaders[i] = entityLoaderBuilder.withEntityLoaderTemplate(this.loaders[0]).withBatchSize(this.batchSizes[i]).byPrimaryKey();
}
this.validate(maxBatchSize);
}
protected LegacyBatchingEntityLoader(...) {
super(persister);
this.batchSizes = ArrayHelper.getBatchSizes(maxBatchSize);
this.loaders = new EntityLoader[this.batchSizes.length];
Builder entityLoaderBuilder = EntityLoader.forEntity(persister).withInfluencers(loadQueryInfluencers).withLockMode(lockMode).withLockOptions(lockOptions);
this.loaders[0] = entityLoaderBuilder.withBatchSize(this.batchSizes[0]).byPrimaryKey();
for(int i = 1; i < this.batchSizes.length; ++i) {
this.loaders[i] = entityLoaderBuilder.withEntityLoaderTemplate(this.loaders[0]).withBatchSize(this.batchSizes[i]).byPrimaryKey();
}
}
public static int[] getBatchSizes(int maxBatchSize) {
int batchSize = maxBatchSize;
int n;
for(n = 1; batchSize > 1; ++n) {
batchSize = getNextBatchSize(batchSize);
}
int[] result = new int[n];
batchSize = maxBatchSize;
for(int i = 0; i < n; ++i) {
result[i] = batchSize;
batchSize = getNextBatchSize(batchSize);
}
return result;
}
private static int getNextBatchSize(int batchSize) {
if (batchSize <= 10) {
return batchSize - 1;
} else {
return batchSize / 2 < 10 ? 10 : batchSize / 2;
}
}