mirror of
https://github.com/google/nomulus.git
synced 2025-08-11 20:19:37 +02:00
Convert a couple of @AutoValue classes to Java 15 Records (#2327)
This is the start of a long and low priority migration, but for now I wanted to do a couple of them just to see what it looks like. This also demonstrates the pattern for use of an @AutoBuilder to replace an @AutoValue.Builder. See https://github.com/google/auto/blob/main/value/userguide/records.md#builders for full details on that.
This commit is contained in:
parent
1f516e34b6
commit
670941bec8
2 changed files with 16 additions and 38 deletions
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
package google.registry.flows.custom;
|
package google.registry.flows.custom;
|
||||||
|
|
||||||
|
import com.google.auto.value.AutoBuilder;
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import google.registry.flows.EppException;
|
import google.registry.flows.EppException;
|
||||||
|
@ -81,30 +82,23 @@ public class DomainRenewFlowCustomLogic extends BaseFlowCustomLogic {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A class to encapsulate parameters for a call to {@link #afterValidation}. */
|
/** A class to encapsulate parameters for a call to {@link #afterValidation}. */
|
||||||
@AutoValue
|
public record AfterValidationParameters(Domain existingDomain, int years, DateTime now) {
|
||||||
public abstract static class AfterValidationParameters extends ImmutableObject {
|
|
||||||
|
|
||||||
public abstract Domain existingDomain();
|
|
||||||
|
|
||||||
public abstract int years();
|
|
||||||
|
|
||||||
public abstract DateTime now();
|
|
||||||
|
|
||||||
public static Builder newBuilder() {
|
public static Builder newBuilder() {
|
||||||
return new AutoValue_DomainRenewFlowCustomLogic_AfterValidationParameters.Builder();
|
return new AutoBuilder_DomainRenewFlowCustomLogic_AfterValidationParameters_Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Builder for {@link AfterValidationParameters}. */
|
/** Builder for {@link AfterValidationParameters}. */
|
||||||
@AutoValue.Builder
|
@AutoBuilder
|
||||||
public abstract static class Builder {
|
public interface Builder {
|
||||||
|
|
||||||
public abstract Builder setExistingDomain(Domain existingDomain);
|
Builder setExistingDomain(Domain existingDomain);
|
||||||
|
|
||||||
public abstract Builder setYears(int years);
|
Builder setYears(int years);
|
||||||
|
|
||||||
public abstract Builder setNow(DateTime now);
|
Builder setNow(DateTime now);
|
||||||
|
|
||||||
public abstract AfterValidationParameters build();
|
AfterValidationParameters build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
|
||||||
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
||||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
import com.google.auto.value.AutoValue;
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
|
@ -129,26 +128,11 @@ public class Lock extends ImmutableObject implements Serializable {
|
||||||
return String.format("%s-%s", scope, resourceName);
|
return String.format("%s-%s", scope, resourceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AutoValue
|
record AcquireResult(
|
||||||
abstract static class AcquireResult {
|
DateTime transactionTime,
|
||||||
public abstract DateTime transactionTime();
|
@Nullable Lock existingLock,
|
||||||
|
@Nullable Lock newLock,
|
||||||
@Nullable
|
LockState lockState) {}
|
||||||
public abstract Lock existingLock();
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public abstract Lock newLock();
|
|
||||||
|
|
||||||
public abstract LockState lockState();
|
|
||||||
|
|
||||||
public static AcquireResult create(
|
|
||||||
DateTime transactionTime,
|
|
||||||
@Nullable Lock existingLock,
|
|
||||||
@Nullable Lock newLock,
|
|
||||||
LockState lockState) {
|
|
||||||
return new AutoValue_Lock_AcquireResult(transactionTime, existingLock, newLock, lockState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void logAcquireResult(AcquireResult acquireResult) {
|
private static void logAcquireResult(AcquireResult acquireResult) {
|
||||||
try {
|
try {
|
||||||
|
@ -204,13 +188,13 @@ public class Lock extends ImmutableObject implements Serializable {
|
||||||
lockState = LockState.TIMED_OUT;
|
lockState = LockState.TIMED_OUT;
|
||||||
} else {
|
} else {
|
||||||
lockState = LockState.IN_USE;
|
lockState = LockState.IN_USE;
|
||||||
return AcquireResult.create(now, lock, null, lockState);
|
return new AcquireResult(now, lock, null, lockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
Lock newLock = create(resourceName, scope, now, leaseLength);
|
Lock newLock = create(resourceName, scope, now, leaseLength);
|
||||||
tm().put(newLock);
|
tm().put(newLock);
|
||||||
|
|
||||||
return AcquireResult.create(now, lock, newLock, lockState);
|
return new AcquireResult(now, lock, newLock, lockState);
|
||||||
};
|
};
|
||||||
AcquireResult acquireResult = tm().transact(lockAcquirer);
|
AcquireResult acquireResult = tm().transact(lockAcquirer);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue