Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit d92ff35

Browse files
committed
bug fix in QueryBuilder in FieldExpressionResolver does not take same fieldExpression more than once
1 parent 04960a2 commit d92ff35

File tree

4 files changed

+32
-36
lines changed

4 files changed

+32
-36
lines changed

elasta-orm/src/main/java/elasta/orm/query/expression/builder/FieldExpressionResolverImpl.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public Map<FieldExpression, FieldExpressionHolderFunc> getFuncMap() {
4141
return funcMap;
4242
}
4343

44+
public boolean containsKey(FieldExpression fieldExpression) {
45+
return funcMap.containsKey(fieldExpression);
46+
}
47+
4448
public FieldExpressionResolverImpl addKey(FieldExpression fieldExpression) {
45-
if (funcMap.containsKey(fieldExpression)) {
46-
throw new FieldExpressionResolverException("Same fieldExpression '" + fieldExpression + "' more than once is not supported in selections");
47-
}
4849
funcMap.put(fieldExpression, new NoOpsFieldExpressionHolderFuncImpl());
4950
return this;
5051
}

elasta-orm/src/main/java/elasta/orm/query/expression/builder/impl/QueryBuilderImpl.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import elasta.orm.query.QueryExecutor;
55
import elasta.orm.query.expression.FieldExpression;
66
import elasta.orm.query.expression.Query;
7+
import elasta.orm.query.expression.builder.ex.FieldExpressionResolverException;
78
import elasta.orm.query.expression.impl.QueryImpl;
89
import elasta.orm.query.expression.builder.*;
910
import elasta.orm.query.expression.impl.FieldExpressionImpl;
@@ -55,7 +56,11 @@ public FieldExpressionHolderFunc field(String fieldExpression) {
5556
}
5657

5758
@Override
58-
public FieldExpressionHolderFunc select(FieldExpression fieldExpression) {
59+
public FieldExpressionHolderFunc select(final FieldExpression fieldExpression) {
60+
61+
if (selectFieldExpressionResolver.containsKey(fieldExpression)) {
62+
throw new FieldExpressionResolverException("Same fieldExpression '" + fieldExpression + "' more than once is not supported in selections");
63+
}
5964

6065
return new FieldExpressionHolderFuncImpl(
6166
fieldExpression,

tracker/src/main/java/tracker/message/handlers/impl/ReplayMessageHandlerImpl.java

+19-27
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,25 @@ private void reqReplyLoop(LoopContext context) {
8585
return;
8686
}
8787

88-
final Message<JsonObject> replyMessage = event.result();
89-
final JsonObject req = replyMessage.body();
90-
Objects.requireNonNull(req);
91-
92-
reqReplyLoop(
93-
LoopContext.builder()
94-
.endTime(context.getEndTime())
95-
.step(context.getStep())
96-
.totalSlots(context.getTotalSlots())
97-
.message(replyMessage)
98-
.startTime(context.getStartTime() + context.getStep() * reqSlots)
99-
.slotsReturned(context.getSlotsReturned() + reqSlots)
100-
.build()
101-
);
88+
try {
89+
90+
final Message<JsonObject> replyMessage = event.result();
91+
final JsonObject req = replyMessage.body();
92+
Objects.requireNonNull(req);
93+
94+
reqReplyLoop(
95+
LoopContext.builder()
96+
.endTime(context.getEndTime())
97+
.step(context.getStep())
98+
.totalSlots(context.getTotalSlots())
99+
.message(replyMessage)
100+
.startTime(context.getStartTime() + context.getStep() * reqSlots)
101+
.slotsReturned(context.getSlotsReturned() + reqSlots)
102+
.build()
103+
);
104+
} catch (Exception ex) {
105+
messageProcessingErrorHandler.handleError(ex, event.result());
106+
}
102107
}
103108
);
104109

@@ -107,19 +112,6 @@ private void reqReplyLoop(LoopContext context) {
107112

108113
}
109114

110-
private int remainingSlots(long time, long timeStart, long timeEnd, long step) {
111-
final long timeDiff = timeEnd - timeStart;
112-
final int slotCount = (int) ((time - timeStart) / step) + 1;
113-
final int division = (int) (timeDiff / step);
114-
final int totalSlotCount = timeDiff % step == 0 ? (division) : (division) + 1;
115-
return totalSlotCount - slotCount;
116-
}
117-
118-
private boolean isInLastSlot(final long time, long timeEnd, long step) {
119-
120-
return (timeEnd - step) <= (time);
121-
}
122-
123115
@Value
124116
@Builder
125117
static final class LoopContext {

tracker/src/main/java/tracker/services/impl/ReplayServiceImpl.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ public Observable<JsonObject> next(int count) {
4242
final TimeSlot timeSlot = new TimeSlot(timeStart, step);
4343
UserIdToPositionMapGenerator userIdToPositionMapGenerator = new UserIdToPositionMapGenerator();
4444

45-
Observable<JsonObject> dataObservable = loadData(timeStart + count * step);
46-
47-
return dataObservable
45+
return loadData(timeStart + count * step)
4846
.flatMap(timeSlot::buffer)
4947
.map(userIdToPositionMapGenerator::produce)
5048
;
@@ -60,8 +58,8 @@ private Observable<JsonObject> loadData(long timeEnd) {
6058
.criteria(
6159
JsonOps.and(
6260
ImmutableList.of(
63-
JsonOps.gte("r.time", appDateTimeFormatter.format(new Date(timeStart))),
64-
JsonOps.lt("r.time", appDateTimeFormatter.format(new Date(timeEnd)))
61+
JsonOps.gte("r." + PositionModel.time, appDateTimeFormatter.format(new Date(timeStart))),
62+
JsonOps.lt("r." + PositionModel.time, appDateTimeFormatter.format(new Date(timeEnd)))
6563
)
6664
)
6765
)

0 commit comments

Comments
 (0)