New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xor options #1510
Comments
.user(asId(...)) // or .user(asEntity(user)) |
I apologize for the messy ticket, I realize what I'm trying to get to is hard to understand. Although I don't have an example handy, I don't know why there couldn't be N options that are mutually exclusive. I'm fine with a runtime check, I don't think I was expecting a staged builder. @Builder.Xor({"user", "userId", "userSupplier"})
@Builder.Factory
static IdentityProviderUser identityProviderUser(
@Nonnull Optional<User.Identifier> userId,
@Nonnull Optional<User> user,
@Nonnull Supplier<@NonNull User> userSupplier // only thing I can think of for a 3rd option... there's probably better examples
) { IdentityProviderUserBuilder.create().userId(userId).build(); // OK
IdentityProviderUserBuilder.create().user(user).build(); // OK
IdentityProviderUserBuilder.create().userId(userId).user(user).build(); // throws
IdentityProviderUserBuilder.create().build(); // throws note: this supplier concept is interesting. I might make another issue for it because I've been finding writing these internally to be rather obnoxious and I'm wondering if there's something that could be done to improve writing factories. update: I'm trying to figure out if using the body of a TestDataBuilder was a mistake, or if I'm trying to demonstrate an additional problem. that might take me a few days... |
So, I'm using Factory builders to build JPA aggregates.
problem is coming up when I have an aggregate with children that have a composite key that points back to the aggregate id, and they also have a parent reference for the aggregate.
In order to do test data builders I've got a little bit of a construction problem since collections handed to the static factory is also immutable, so by default this structure is getting tricky. Included the current state of code to provide hopefully some illumination.
Anyways, so in order to construct
IdentityProviderUser.Identifier
I have to have aUser.Identifier
, at some point it also needs a fullUser
instance.Obviously this
addIf
might or might not be a good plan, it certainly isn't the immutable way.Alright, the ask, I can easily early create
IdentifyProviderUser.Identifier
whenUser.Identifier
exists. However, depending on circumstances you'll see this means I need aUser.Identifer
andUser
as parameters. However, these are mutually exclusive, and you should provide only one or the other. This is similar in concept toSwitch
but these aren't enums or booleans. Maybe something like@Xor("userId", "user")
could be added.The text was updated successfully, but these errors were encountered: