Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: using non-final index definitions is problematic
Generally speaking, modifying a static field is a code smell. The values are not getting cached, and it doesn't work well with defaults Lombok does for value classes (final statics) Solution: deprecate existing index definition syntax and introduce a new one The new syntax is: ```java public static final SimpleIndex<MyEvent, UUID> ID = SimpleIndex.as(StandardEntity::uuid); public static final MultiValueIndex<MyEvent, String> VALS = MultiValueIndex.as(MyEvent::vals); ``` This way, at the expense of a slightly more verbose index, we're allowing to make index statics final.
- Loading branch information
Showing
33 changed files
with
234 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
eventsourcing-core/src/main/java/com/eventsourcing/index/IndexWithAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright (c) 2016, All Contributors (see CONTRIBUTORS file) | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package com.eventsourcing.index; | ||
|
||
import com.eventsourcing.Entity; | ||
|
||
public interface IndexWithAttribute<O extends Entity, A> { | ||
Attribute<O, A> getAttribute(); | ||
void setAttribute(Attribute<O, A> attribute); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
eventsourcing-core/src/main/java/com/eventsourcing/index/WrappedMultiValueIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (c) 2016, All Contributors (see CONTRIBUTORS file) | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package com.eventsourcing.index; | ||
|
||
import com.eventsourcing.Entity; | ||
import com.googlecode.cqengine.query.option.QueryOptions; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
import static com.eventsourcing.index.EntityQueryFactory.noQueryOptions; | ||
|
||
class WrappedMultiValueIndex<O extends Entity, A, I extends Iterable<A>> implements MultiValueIndex<O, A>, | ||
IndexWithAttribute<O, A> { | ||
private final BiFunction<O, QueryOptions, I> index; | ||
@Getter @Setter | ||
private Attribute<O, A> attribute; | ||
|
||
public WrappedMultiValueIndex(Function<O, I> index) {this.index = (object, queryOptions) -> index.apply(object);} | ||
public WrappedMultiValueIndex(BiFunction<O, QueryOptions, I> index) {this.index = index;} | ||
|
||
|
||
@Override public Iterable<A> getValues(O object) { | ||
return index.apply(object, noQueryOptions()); | ||
} | ||
|
||
@Override public Iterable<A> getValues(O object, QueryOptions queryOptions) { | ||
return index.apply(object, queryOptions); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
eventsourcing-core/src/main/java/com/eventsourcing/index/WrappedSimpleIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2016, All Contributors (see CONTRIBUTORS file) | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package com.eventsourcing.index; | ||
|
||
import com.eventsourcing.Entity; | ||
import com.googlecode.cqengine.attribute.*; | ||
import com.googlecode.cqengine.query.option.QueryOptions; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
import static com.eventsourcing.index.EntityQueryFactory.noQueryOptions; | ||
|
||
class WrappedSimpleIndex<O extends Entity, A> implements SimpleIndex<O, A>, IndexWithAttribute<O, A> { | ||
private final BiFunction<O, QueryOptions, A> index; | ||
@Getter @Setter | ||
private Attribute<O, A> attribute; | ||
|
||
public WrappedSimpleIndex(Function<O, A> index) {this.index = (e, queryOptions) -> index.apply(e);} | ||
public WrappedSimpleIndex(BiFunction<O, QueryOptions, A> index) {this.index = index;} | ||
|
||
@Override public A getValue(O object) { | ||
return index.apply(object, noQueryOptions()); | ||
} | ||
|
||
@Override public A getValue(O object, QueryOptions queryOptions) { | ||
return index.apply(object, queryOptions); | ||
} | ||
} |
Oops, something went wrong.