Skip to content

Commit fc3bc9c

Browse files
committed
検索用メソッドの戻り値の型を Stream とすることを認めた
1 parent 67c3bf0 commit fc3bc9c

File tree

20 files changed

+875
-161
lines changed

20 files changed

+875
-161
lines changed

src/main/java/org/seasar/doma/internal/apt/DaoGenerator.java

Lines changed: 191 additions & 154 deletions
Large diffs are not rendered by default.

src/main/java/org/seasar/doma/internal/apt/meta/QueryReturnMeta.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.seasar.doma.internal.apt.cttype.OptionalIntCtType;
4141
import org.seasar.doma.internal.apt.cttype.OptionalLongCtType;
4242
import org.seasar.doma.internal.apt.cttype.SimpleCtTypeVisitor;
43+
import org.seasar.doma.internal.apt.cttype.StreamCtType;
4344
import org.seasar.doma.internal.apt.util.TypeMirrorUtil;
4445
import org.seasar.doma.jdbc.BatchResult;
4546
import org.seasar.doma.jdbc.Result;
@@ -84,6 +85,11 @@ protected CtType createCtType(final ExecutableElement methodElement,
8485
return iterableCtType;
8586
}
8687

88+
StreamCtType streamCtType = StreamCtType.newInstance(type, env);
89+
if (streamCtType != null) {
90+
return streamCtType;
91+
}
92+
8793
EntityCtType entityCtType = EntityCtType.newInstance(type, env);
8894
if (entityCtType != null) {
8995
return entityCtType;

src/main/java/org/seasar/doma/internal/apt/meta/SqlFileSelectQueryMeta.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class SqlFileSelectQueryMeta extends AbstractSqlFileQueryMeta {
4949

5050
protected EntityCtType entityCtType;
5151

52+
protected boolean resultStream;
53+
5254
public SqlFileSelectQueryMeta(ExecutableElement method) {
5355
super(method);
5456
}
@@ -157,6 +159,14 @@ public boolean isExpandable() {
157159
return entityCtType != null;
158160
}
159161

162+
public boolean isResultStream() {
163+
return resultStream;
164+
}
165+
166+
public void setResultStream(boolean resultStream) {
167+
this.resultStream = resultStream;
168+
}
169+
160170
@Override
161171
public <R, P> R accept(QueryMetaVisitor<R, P> visitor, P p) {
162172
return visitor.visitSqlFileSelectQueryMeta(this, p);

src/main/java/org/seasar/doma/internal/apt/meta/SqlFileSelectQueryMetaFactory.java

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
import javax.annotation.processing.ProcessingEnvironment;
2121
import javax.lang.model.element.ExecutableElement;
2222
import javax.lang.model.element.VariableElement;
23+
import javax.tools.Diagnostic.Kind;
2324

2425
import org.seasar.doma.SelectType;
26+
import org.seasar.doma.Suppress;
2527
import org.seasar.doma.internal.apt.AptException;
28+
import org.seasar.doma.internal.apt.Notifier;
2629
import org.seasar.doma.internal.apt.cttype.AnyCtType;
2730
import org.seasar.doma.internal.apt.cttype.BasicCtType;
2831
import org.seasar.doma.internal.apt.cttype.CollectorCtType;
@@ -442,10 +445,14 @@ protected class ReturnCtTypeVisitor extends
442445

443446
protected QueryReturnMeta returnMeta;
444447

448+
protected Suppress suppress;
449+
445450
protected ReturnCtTypeVisitor(SqlFileSelectQueryMeta queryMeta,
446451
QueryReturnMeta returnMeta) {
447452
this.queryMeta = queryMeta;
448453
this.returnMeta = returnMeta;
454+
this.suppress = queryMeta.getExecutableElement().getAnnotation(
455+
Suppress.class);
449456
}
450457

451458
@Override
@@ -496,6 +503,20 @@ public Void visitIterableCtType(IterableCtType ctType, Void p)
496503
return null;
497504
}
498505

506+
@Override
507+
public Void visitStreamCtType(StreamCtType ctType, Void p)
508+
throws RuntimeException {
509+
if (!isSuppressed(Message.DOMA4274)) {
510+
Notifier.notify(env, Kind.WARNING, Message.DOMA4274,
511+
returnMeta.getElement());
512+
}
513+
queryMeta.setResultStream(true);
514+
ctType.getElementCtType()
515+
.accept(new ReturnStreamElementCtTypeVisitor(queryMeta,
516+
returnMeta), p);
517+
return null;
518+
}
519+
499520
@Override
500521
public Void visitOptionalCtType(OptionalCtType ctType, Void p)
501522
throws RuntimeException {
@@ -523,6 +544,17 @@ public Void visitOptionalDoubleCtType(OptionalDoubleCtType ctType,
523544
return null;
524545
}
525546

547+
protected boolean isSuppressed(Message message) {
548+
if (suppress != null) {
549+
for (Message suppressMessage : suppress.messages()) {
550+
if (suppressMessage == message) {
551+
return true;
552+
}
553+
}
554+
}
555+
return false;
556+
}
557+
526558
}
527559

528560
/**
@@ -608,6 +640,89 @@ public Void visitOptionalDoubleCtType(OptionalDoubleCtType ctType,
608640

609641
}
610642

643+
/**
644+
*
645+
* @author nakamura-to
646+
*
647+
*/
648+
protected class ReturnStreamElementCtTypeVisitor extends
649+
SimpleCtTypeVisitor<Void, Void, RuntimeException> {
650+
651+
protected SqlFileSelectQueryMeta queryMeta;
652+
653+
protected QueryReturnMeta returnMeta;
654+
655+
protected ReturnStreamElementCtTypeVisitor(
656+
SqlFileSelectQueryMeta queryMeta, QueryReturnMeta returnMeta) {
657+
this.queryMeta = queryMeta;
658+
this.returnMeta = returnMeta;
659+
}
660+
661+
@Override
662+
protected Void defaultAction(CtType type, Void p)
663+
throws RuntimeException {
664+
throw new AptException(Message.DOMA4271, env,
665+
returnMeta.getElement(), type.getTypeName());
666+
}
667+
668+
@Override
669+
public Void visitBasicCtType(BasicCtType ctType, Void p)
670+
throws RuntimeException {
671+
return null;
672+
}
673+
674+
@Override
675+
public Void visitDomainCtType(DomainCtType ctType, Void p)
676+
throws RuntimeException {
677+
return null;
678+
}
679+
680+
@Override
681+
public Void visitMapCtType(MapCtType ctType, Void p)
682+
throws RuntimeException {
683+
return null;
684+
}
685+
686+
@Override
687+
public Void visitEntityCtType(EntityCtType ctType, Void p)
688+
throws RuntimeException {
689+
if (ctType.isAbstract()) {
690+
throw new AptException(Message.DOMA4272, env,
691+
returnMeta.getElement(), ctType.getTypeMirror());
692+
}
693+
queryMeta.setEntityCtType(ctType);
694+
return null;
695+
}
696+
697+
@Override
698+
public Void visitOptionalCtType(OptionalCtType ctType, Void p)
699+
throws RuntimeException {
700+
ctType.getElementCtType().accept(
701+
new ReturnStreamOptionalElementCtTypeVisitor(queryMeta,
702+
returnMeta), p);
703+
return null;
704+
}
705+
706+
@Override
707+
public Void visitOptionalIntCtType(OptionalIntCtType ctType, Void p)
708+
throws RuntimeException {
709+
return null;
710+
}
711+
712+
@Override
713+
public Void visitOptionalLongCtType(OptionalLongCtType ctType, Void p)
714+
throws RuntimeException {
715+
return null;
716+
}
717+
718+
@Override
719+
public Void visitOptionalDoubleCtType(OptionalDoubleCtType ctType,
720+
Void p) throws RuntimeException {
721+
return null;
722+
}
723+
724+
}
725+
611726
/**
612727
*
613728
* @author nakamura-to
@@ -701,4 +816,42 @@ public Void visitDomainCtType(DomainCtType ctType, Void p)
701816
}
702817
}
703818

819+
/**
820+
*
821+
* @author nakamura-to
822+
*
823+
*/
824+
protected class ReturnStreamOptionalElementCtTypeVisitor extends
825+
SimpleCtTypeVisitor<Void, Void, RuntimeException> {
826+
827+
protected SqlFileSelectQueryMeta queryMeta;
828+
829+
protected QueryReturnMeta returnMeta;
830+
831+
protected ReturnStreamOptionalElementCtTypeVisitor(
832+
SqlFileSelectQueryMeta queryMeta, QueryReturnMeta returnMeta) {
833+
this.queryMeta = queryMeta;
834+
this.returnMeta = returnMeta;
835+
}
836+
837+
@Override
838+
protected Void defaultAction(CtType type, Void p)
839+
throws RuntimeException {
840+
throw new AptException(Message.DOMA4267, env,
841+
returnMeta.getElement(), type.getTypeName());
842+
}
843+
844+
@Override
845+
public Void visitBasicCtType(BasicCtType ctType, Void p)
846+
throws RuntimeException {
847+
return null;
848+
}
849+
850+
@Override
851+
public Void visitDomainCtType(DomainCtType ctType, Void p)
852+
throws RuntimeException {
853+
return null;
854+
}
855+
}
856+
704857
}

0 commit comments

Comments
 (0)