mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
mv com/google/domain/registry google/registry
This change renames directories in preparation for the great package rename. The repository is now in a broken state because the code itself hasn't been updated. However this should ensure that git correctly preserves history for each file.
This commit is contained in:
parent
a41677aea1
commit
5012893c1d
2396 changed files with 0 additions and 0 deletions
75
java/google/registry/model/SchemaVersion.java
Normal file
75
java/google/registry/model/SchemaVersion.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.model;
|
||||
|
||||
import static com.google.common.base.Predicates.assignableFrom;
|
||||
import static com.google.common.base.Predicates.or;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/** Utility methods for getting the version of the model schema from the model code. */
|
||||
public final class SchemaVersion {
|
||||
|
||||
/**
|
||||
* Returns a set of classes corresponding to all types persisted within the model classes, sorted
|
||||
* by the string representation.
|
||||
*/
|
||||
private static SortedSet<Class<?>> getAllPersistedTypes() {
|
||||
SortedSet<Class<?>> persistedTypes = new TreeSet<>(Ordering.usingToString());
|
||||
Queue<Class<?>> queue = new ArrayDeque<>();
|
||||
// Do a breadth-first search for persisted types, starting with @Entity types and expanding each
|
||||
// ImmutableObject by querying it for all its persisted field types.
|
||||
persistedTypes.addAll(EntityClasses.ALL_CLASSES);
|
||||
queue.addAll(persistedTypes);
|
||||
while (!queue.isEmpty()) {
|
||||
Class<?> clazz = queue.remove();
|
||||
if (ImmutableObject.class.isAssignableFrom(clazz)) {
|
||||
for (Class<?> persistedFieldType : ModelUtils.getPersistedFieldTypes(clazz)) {
|
||||
if (persistedTypes.add(persistedFieldType)) {
|
||||
// If we haven't seen this type before, add it to the queue to query its field types.
|
||||
queue.add(persistedFieldType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return persistedTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representing the schema which includes the definition of all persisted entity
|
||||
* types (and their field types, recursively). Each definition contains the field names and their
|
||||
* types (for classes), or else a list of all possible values (for enums).
|
||||
*/
|
||||
public static String getSchema() {
|
||||
return FluentIterable.from(getAllPersistedTypes())
|
||||
.filter(or(assignableFrom(Enum.class), assignableFrom(ImmutableObject.class)))
|
||||
.transform(new Function<Class<?>, String>() {
|
||||
@Override
|
||||
public String apply(Class<?> clazz) {
|
||||
return ModelUtils.getSchema(clazz);
|
||||
}})
|
||||
.join(Joiner.on('\n'));
|
||||
}
|
||||
|
||||
private SchemaVersion() {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue