Remove ofy scaffolding from DomainContent and core classes (#1660)

This removes the code that converts between ofy fields and SQL fields in DomainContent and a number of related core classes (basically anything that also needed modification to support the removal from DomainContent).
This commit is contained in:
Michael Muller 2022-06-29 14:39:25 -04:00 committed by GitHub
parent a2fc56e108
commit 68470e5cdf
62 changed files with 740 additions and 914 deletions

View file

@ -0,0 +1,50 @@
// Copyright 2022 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.util;
import com.google.common.collect.ImmutableCollection;
import javax.annotation.Nullable;
/**
* Collection builder that simply ignores requests to add null elements.
*
* <p>Useful because we do this in a number of cases.
*/
public class NullIgnoringCollectionBuilder<E, B extends ImmutableCollection.Builder<E>> {
private B builder;
private NullIgnoringCollectionBuilder(B builder) {
this.builder = builder;
}
public static <E2, B2 extends ImmutableCollection.Builder<E2>>
NullIgnoringCollectionBuilder<E2, B2> create(B2 builder) {
return new NullIgnoringCollectionBuilder<E2, B2>(builder);
}
/** If 'elem' is not null, add it to the builder. */
public NullIgnoringCollectionBuilder<E, B> add(@Nullable E elem) {
if (elem != null) {
builder.add(elem);
}
return this;
}
/** Returns the underlying builder. */
public B getBuilder() {
return builder;
}
}

View file

@ -0,0 +1,54 @@
// Copyright 2022 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.util;
import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.junit.jupiter.api.Test;
public class NullIgnoringCollectionBuilderTest {
public NullIgnoringCollectionBuilderTest() {}
@Test
public void testNullSafeCollections() {
assertThat(
NullIgnoringCollectionBuilder.create(new ImmutableList.Builder<Integer>())
.getBuilder()
.build())
.isEqualTo(ImmutableList.of());
assertThat(
NullIgnoringCollectionBuilder.create(new ImmutableList.Builder<Integer>())
.add(100)
.add(200)
.add(null)
.getBuilder()
.build())
.containsExactly(100, 200)
.inOrder();
assertThat(
NullIgnoringCollectionBuilder.create(new ImmutableSet.Builder<Integer>())
.add(100)
.add(200)
.add(null)
.getBuilder()
.build())
.containsExactly(100, 200);
}
}