Skip to content

Commit bf2783f

Browse files
committed
Optimize the performance of DAO method processing.
1 parent 6dc9f67 commit bf2783f

20 files changed

+387
-322
lines changed

doma-core/src/main/java/org/seasar/doma/NClobFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@
4848
*/
4949
@Target(ElementType.METHOD)
5050
@Retention(RetentionPolicy.RUNTIME)
51+
@DaoMethod
5152
public @interface NClobFactory {}

doma-processor/src/main/java/org/seasar/doma/internal/apt/annot/Annotations.java

Lines changed: 67 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Map;
2323
import java.util.Objects;
2424
import java.util.function.BiFunction;
25-
import java.util.function.Function;
2625
import java.util.stream.Collectors;
2726
import javax.lang.model.element.AnnotationMirror;
2827
import javax.lang.model.element.AnnotationValue;
@@ -32,35 +31,19 @@
3231
import javax.lang.model.element.VariableElement;
3332
import org.seasar.doma.AggregateStrategy;
3433
import org.seasar.doma.AnnotateWith;
35-
import org.seasar.doma.ArrayFactory;
3634
import org.seasar.doma.AssociationLinker;
37-
import org.seasar.doma.BatchDelete;
38-
import org.seasar.doma.BatchInsert;
39-
import org.seasar.doma.BatchUpdate;
40-
import org.seasar.doma.BlobFactory;
41-
import org.seasar.doma.ClobFactory;
4235
import org.seasar.doma.Column;
4336
import org.seasar.doma.Dao;
4437
import org.seasar.doma.DataType;
45-
import org.seasar.doma.Delete;
4638
import org.seasar.doma.Domain;
4739
import org.seasar.doma.DomainConverters;
4840
import org.seasar.doma.Embeddable;
4941
import org.seasar.doma.Entity;
50-
import org.seasar.doma.Insert;
51-
import org.seasar.doma.MultiInsert;
52-
import org.seasar.doma.NClobFactory;
53-
import org.seasar.doma.Procedure;
5442
import org.seasar.doma.ResultSet;
55-
import org.seasar.doma.SQLXMLFactory;
56-
import org.seasar.doma.Script;
57-
import org.seasar.doma.Select;
5843
import org.seasar.doma.SequenceGenerator;
5944
import org.seasar.doma.Sql;
60-
import org.seasar.doma.SqlProcessor;
6145
import org.seasar.doma.Table;
6246
import org.seasar.doma.TableGenerator;
63-
import org.seasar.doma.Update;
6447
import org.seasar.doma.internal.apt.RoundContext;
6548
import org.seasar.doma.internal.apt.util.AnnotationValueUtil;
6649

@@ -131,34 +114,34 @@ public AssociationLinkerAnnot newAssociationLinkerAnnot(VariableElement field) {
131114
return newInstance(field, AssociationLinker.class, AssociationLinkerAnnot::new);
132115
}
133116

134-
public ArrayFactoryAnnot newArrayFactoryAnnot(ExecutableElement method) {
135-
assertNotNull(method);
136-
return newInstance(method, ArrayFactory.class, ArrayFactoryAnnot::new);
117+
public ArrayFactoryAnnot newArrayFactoryAnnot(AnnotationMirror annotation) {
118+
assertNotNull(annotation);
119+
return newInstance(annotation, ArrayFactoryAnnot::new);
137120
}
138121

139-
public BatchDeleteAnnot newBatchDeleteAnnot(ExecutableElement method) {
140-
assertNotNull(method);
141-
return newInstance(method, BatchDelete.class, BatchDeleteAnnot::new);
122+
public BatchDeleteAnnot newBatchDeleteAnnot(AnnotationMirror annotation) {
123+
assertNotNull(annotation);
124+
return newInstance(annotation, BatchDeleteAnnot::new);
142125
}
143126

144-
public BatchInsertAnnot newBatchInsertAnnot(ExecutableElement method) {
145-
assertNotNull(method);
146-
return newInstance(method, BatchInsert.class, BatchInsertAnnot::new);
127+
public BatchInsertAnnot newBatchInsertAnnot(AnnotationMirror annotation) {
128+
assertNotNull(annotation);
129+
return newInstance(annotation, BatchInsertAnnot::new);
147130
}
148131

149-
public BatchUpdateAnnot newBatchUpdateAnnot(ExecutableElement method) {
150-
assertNotNull(method);
151-
return newInstance(method, BatchUpdate.class, BatchUpdateAnnot::new);
132+
public BatchUpdateAnnot newBatchUpdateAnnot(AnnotationMirror annotation) {
133+
assertNotNull(annotation);
134+
return newInstance(annotation, BatchUpdateAnnot::new);
152135
}
153136

154-
public BlobFactoryAnnot newBlobFactoryAnnot(ExecutableElement method) {
155-
assertNotNull(method);
156-
return newInstance(method, BlobFactory.class, BlobFactoryAnnot::new);
137+
public BlobFactoryAnnot newBlobFactoryAnnot(AnnotationMirror annotation) {
138+
assertNotNull(annotation);
139+
return new BlobFactoryAnnot(annotation);
157140
}
158141

159-
public ClobFactoryAnnot newClobFactoryAnnot(ExecutableElement method) {
160-
assertNotNull(method);
161-
return newInstance(method, ClobFactory.class, ClobFactoryAnnot::new);
142+
public ClobFactoryAnnot newClobFactoryAnnot(AnnotationMirror annotation) {
143+
assertNotNull(annotation);
144+
return new ClobFactoryAnnot(annotation);
162145
}
163146

164147
public ColumnAnnot newColumnAnnot(VariableElement field) {
@@ -186,16 +169,12 @@ public DomainConvertersAnnot newDomainConvertersAnnot(TypeElement typeElement) {
186169
return newInstance(typeElement, DomainConverters.class, DomainConvertersAnnot::new);
187170
}
188171

189-
public DeleteAnnot newDeleteAnnot(ExecutableElement method) {
190-
assertNotNull(method);
191-
AnnotationMirror deleteMirror = ctx.getMoreElements().getAnnotationMirror(method, Delete.class);
192-
if (deleteMirror == null) {
193-
return null;
194-
}
195-
ReturningAnnot returningAnnot = newReturningAnnot(deleteMirror, ModifyAnnot.RETURNING);
172+
public DeleteAnnot newDeleteAnnot(AnnotationMirror annotation) {
173+
assertNotNull(annotation);
174+
ReturningAnnot returningAnnot = newReturningAnnot(annotation, ModifyAnnot.RETURNING);
196175
Map<String, AnnotationValue> valuesWithDefaults =
197-
ctx.getMoreElements().getValuesWithDefaults(deleteMirror);
198-
return new DeleteAnnot(deleteMirror, returningAnnot, valuesWithDefaults);
176+
ctx.getMoreElements().getValuesWithDefaults(annotation);
177+
return new DeleteAnnot(annotation, returningAnnot, valuesWithDefaults);
199178
}
200179

201180
public EmbeddableAnnot newEmbeddableAnnot(TypeElement typeElement) {
@@ -237,57 +216,43 @@ public EntityAnnot newEntityAnnot(TypeElement typeElement) {
237216
return new EntityAnnot(entityMirror, metamodelAnnot, valuesWithDefaults);
238217
}
239218

240-
public FunctionAnnot newFunctionAnnot(final ExecutableElement method) {
241-
assertNotNull(method);
219+
public FunctionAnnot newFunctionAnnot(final AnnotationMirror annotation, String name) {
220+
assertNotNull(annotation);
242221
return newInstance(
243-
method,
244-
org.seasar.doma.Function.class,
245-
(annotationMirror, values) ->
246-
new FunctionAnnot(annotationMirror, values, method.getSimpleName().toString()));
222+
annotation,
223+
(annotationMirror, values) -> new FunctionAnnot(annotationMirror, values, name));
247224
}
248225

249-
public InsertAnnot newInsertAnnot(ExecutableElement method) {
250-
assertNotNull(method);
251-
AnnotationMirror insertMirror = ctx.getMoreElements().getAnnotationMirror(method, Insert.class);
252-
if (insertMirror == null) {
253-
return null;
254-
}
255-
ReturningAnnot returningAnnot = newReturningAnnot(insertMirror, ModifyAnnot.RETURNING);
226+
public InsertAnnot newInsertAnnot(AnnotationMirror annotation) {
227+
ReturningAnnot returningAnnot = newReturningAnnot(annotation, ModifyAnnot.RETURNING);
256228
Map<String, AnnotationValue> valuesWithDefaults =
257-
ctx.getMoreElements().getValuesWithDefaults(insertMirror);
258-
return new InsertAnnot(insertMirror, returningAnnot, valuesWithDefaults);
229+
ctx.getMoreElements().getValuesWithDefaults(annotation);
230+
return new InsertAnnot(annotation, returningAnnot, valuesWithDefaults);
259231
}
260232

261-
public MultiInsertAnnot newMultiInsertAnnot(ExecutableElement method) {
262-
assertNotNull(method);
263-
AnnotationMirror multiInsertMirror =
264-
ctx.getMoreElements().getAnnotationMirror(method, MultiInsert.class);
265-
if (multiInsertMirror == null) {
266-
return null;
267-
}
268-
ReturningAnnot returningAnnot = newReturningAnnot(multiInsertMirror, ModifyAnnot.RETURNING);
233+
public MultiInsertAnnot newMultiInsertAnnot(AnnotationMirror annotation) {
234+
assertNotNull(annotation);
235+
ReturningAnnot returningAnnot = newReturningAnnot(annotation, ModifyAnnot.RETURNING);
269236
Map<String, AnnotationValue> valuesWithDefaults =
270-
ctx.getMoreElements().getValuesWithDefaults(multiInsertMirror);
271-
return new MultiInsertAnnot(multiInsertMirror, returningAnnot, valuesWithDefaults);
237+
ctx.getMoreElements().getValuesWithDefaults(annotation);
238+
return new MultiInsertAnnot(annotation, returningAnnot, valuesWithDefaults);
272239
}
273240

274241
public MetamodelAnnot newMetamodelAnnot(AnnotationMirror annotationMirror) {
275242
assertNotNull(annotationMirror);
276243
return newInstance(annotationMirror, MetamodelAnnot::new);
277244
}
278245

279-
public NClobFactoryAnnot newNClobFactoryAnnot(ExecutableElement method) {
280-
assertNotNull(method);
281-
return newInstance(method, NClobFactory.class, NClobFactoryAnnot::new);
246+
public NClobFactoryAnnot newNClobFactoryAnnot(AnnotationMirror annotation) {
247+
assertNotNull(annotation);
248+
return new NClobFactoryAnnot(annotation);
282249
}
283250

284-
public ProcedureAnnot newProcedureAnnot(ExecutableElement method) {
285-
assertNotNull(method);
251+
public ProcedureAnnot newProcedureAnnot(AnnotationMirror annotation, String name) {
252+
assertNotNull(annotation);
286253
return newInstance(
287-
method,
288-
Procedure.class,
289-
(annotationMirror, values) ->
290-
new ProcedureAnnot(annotationMirror, values, method.getSimpleName().toString()));
254+
annotation,
255+
(annotationMirror, values) -> new ProcedureAnnot(annotationMirror, values, name));
291256
}
292257

293258
public ResultSetAnnot newResultSetAnnot(VariableElement param) {
@@ -316,14 +281,14 @@ private ReturningAnnot newReturningAnnot(
316281
return newReturningAnnot(returningMirror);
317282
}
318283

319-
public ScriptAnnot newScriptAnnot(ExecutableElement method) {
320-
assertNotNull(method);
321-
return newInstance(method, Script.class, ScriptAnnot::new);
284+
public ScriptAnnot newScriptAnnot(AnnotationMirror annotation) {
285+
assertNotNull(annotation);
286+
return newInstance(annotation, ScriptAnnot::new);
322287
}
323288

324-
public SelectAnnot newSelectAnnot(ExecutableElement method) {
325-
assertNotNull(method);
326-
return newInstance(method, Select.class, SelectAnnot::new);
289+
public SelectAnnot newSelectAnnot(AnnotationMirror annotation) {
290+
assertNotNull(annotation);
291+
return newInstance(annotation, SelectAnnot::new);
327292
}
328293

329294
public SequenceGeneratorAnnot newSequenceGeneratorAnnot(VariableElement field) {
@@ -336,14 +301,14 @@ public SqlAnnot newSqlAnnot(ExecutableElement method) {
336301
return newInstance(method, Sql.class, SqlAnnot::new);
337302
}
338303

339-
public SqlProcessorAnnot newSqlProcessorAnnot(ExecutableElement method) {
340-
assertNotNull(method);
341-
return newInstance(method, SqlProcessor.class, SqlProcessorAnnot::new);
304+
public SqlProcessorAnnot newSqlProcessorAnnot(AnnotationMirror annotation) {
305+
assertNotNull(annotation);
306+
return new SqlProcessorAnnot(annotation);
342307
}
343308

344-
public SQLXMLFactoryAnnot newSQLXMLFactoryAnnot(ExecutableElement method) {
345-
assertNotNull(method);
346-
return newInstance(method, SQLXMLFactory.class, SQLXMLFactoryAnnot::new);
309+
public SQLXMLFactoryAnnot newSQLXMLFactoryAnnot(AnnotationMirror annotation) {
310+
assertNotNull(annotation);
311+
return new SQLXMLFactoryAnnot(annotation);
347312
}
348313

349314
public TableGeneratorAnnot newTableGeneratorAnnot(VariableElement field) {
@@ -356,37 +321,28 @@ public TableAnnot newTableAnnot(TypeElement typeElement) {
356321
return newInstance(typeElement, Table.class, TableAnnot::new);
357322
}
358323

359-
public UpdateAnnot newUpdateAnnot(ExecutableElement method) {
360-
assertNotNull(method);
361-
AnnotationMirror updateMirror = ctx.getMoreElements().getAnnotationMirror(method, Update.class);
362-
if (updateMirror == null) {
363-
return null;
364-
}
365-
ReturningAnnot returningAnnot = newReturningAnnot(updateMirror, ModifyAnnot.RETURNING);
324+
public UpdateAnnot newUpdateAnnot(AnnotationMirror annotation) {
325+
assertNotNull(annotation);
326+
ReturningAnnot returningAnnot = newReturningAnnot(annotation, ModifyAnnot.RETURNING);
366327
Map<String, AnnotationValue> valuesWithDefaults =
367-
ctx.getMoreElements().getValuesWithDefaults(updateMirror);
368-
return new UpdateAnnot(updateMirror, returningAnnot, valuesWithDefaults);
328+
ctx.getMoreElements().getValuesWithDefaults(annotation);
329+
return new UpdateAnnot(annotation, returningAnnot, valuesWithDefaults);
369330
}
370331

371332
public ValueAnnot newValueAnnot(TypeElement typeElement) {
372333
assertNotNull(typeElement);
373334
return newInstance(typeElement, ctx.getOptions().getLombokValue(), ValueAnnot::new);
374335
}
375336

376-
private <ANNOT> ANNOT newInstance(
377-
Element element,
378-
Class<? extends java.lang.annotation.Annotation> annotationClass,
379-
Function<AnnotationMirror, ANNOT> function) {
380-
return newInstance(
381-
element, annotationClass, (annotationMirror, __) -> function.apply(annotationMirror));
382-
}
383-
384337
private <ANNOT> ANNOT newInstance(
385338
Element element,
386339
Class<? extends java.lang.annotation.Annotation> annotationClass,
387340
BiFunction<AnnotationMirror, Map<String, AnnotationValue>, ANNOT> biFunction) {
388341
AnnotationMirror annotationMirror =
389342
ctx.getMoreElements().getAnnotationMirror(element, annotationClass);
343+
if (annotationMirror == null) {
344+
return null;
345+
}
390346
return newInstance(annotationMirror, biFunction);
391347
}
392348

@@ -396,15 +352,16 @@ private <ANNOT> ANNOT newInstance(
396352
BiFunction<AnnotationMirror, Map<String, AnnotationValue>, ANNOT> biFunction) {
397353
AnnotationMirror annotationMirror =
398354
ctx.getMoreElements().getAnnotationMirror(element, annotationClassName);
355+
if (annotationMirror == null) {
356+
return null;
357+
}
399358
return newInstance(annotationMirror, biFunction);
400359
}
401360

402361
private <ANNOT> ANNOT newInstance(
403362
AnnotationMirror annotationMirror,
404363
BiFunction<AnnotationMirror, Map<String, AnnotationValue>, ANNOT> biFunction) {
405-
if (annotationMirror == null) {
406-
return null;
407-
}
364+
assertNotNull(annotationMirror);
408365
Map<String, AnnotationValue> values =
409366
ctx.getMoreElements().getValuesWithDefaults(annotationMirror);
410367
return biFunction.apply(annotationMirror, values);

0 commit comments

Comments
 (0)