Search in sources :

Example 1 with EppHistoryVKey

use of google.registry.persistence.EppHistoryVKey in project nomulus by google.

the class EppHistoryVKeyTranslatorFactory method createTranslator.

@Override
SimpleTranslator<EppHistoryVKey, Key> createTranslator() {
    return new SimpleTranslator<EppHistoryVKey, Key>() {

        @Nullable
        @Override
        public EppHistoryVKey loadValue(@Nullable Key datastoreValue) {
            if (datastoreValue == null) {
                return null;
            } else {
                com.googlecode.objectify.Key<?> ofyKey = com.googlecode.objectify.Key.create(datastoreValue);
                String kindPath = EppHistoryVKey.createKindPath(ofyKey);
                if (kindPathToVKeyClass.containsKey(kindPath)) {
                    Class<? extends EppHistoryVKey> vKeyClass = kindPathToVKeyClass.get(kindPath);
                    try {
                        Method createVKeyMethod = vKeyClass.getDeclaredMethod("create", com.googlecode.objectify.Key.class);
                        return (EppHistoryVKey) createVKeyMethod.invoke(null, ofyKey);
                    } catch (NoSuchMethodException e) {
                        throw new IllegalStateException("Missing static method create(com.googlecode.objectify.Key) on " + vKeyClass);
                    } catch (IllegalAccessException | InvocationTargetException e) {
                        throw new IllegalStateException("Error invoking createVKey on " + vKeyClass, e);
                    }
                } else {
                    throw new IllegalStateException("Missing EppHistoryVKey implementation for kind path: " + kindPath);
                }
            }
        }

        @Nullable
        @Override
        public Key saveValue(@Nullable EppHistoryVKey pojoValue) {
            return pojoValue == null ? null : pojoValue.createOfyKey().getRaw();
        }
    };
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) EppHistoryVKey(google.registry.persistence.EppHistoryVKey) Nullable(javax.annotation.Nullable) EppHistoryVKey(google.registry.persistence.EppHistoryVKey) DomainHistoryVKey(google.registry.persistence.DomainHistoryVKey) BillingRecurrenceVKey(google.registry.persistence.BillingVKey.BillingRecurrenceVKey) Key(com.google.appengine.api.datastore.Key) BillingEventVKey(google.registry.persistence.BillingVKey.BillingEventVKey)

Aggregations

Key (com.google.appengine.api.datastore.Key)1 BillingEventVKey (google.registry.persistence.BillingVKey.BillingEventVKey)1 BillingRecurrenceVKey (google.registry.persistence.BillingVKey.BillingRecurrenceVKey)1 DomainHistoryVKey (google.registry.persistence.DomainHistoryVKey)1 EppHistoryVKey (google.registry.persistence.EppHistoryVKey)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Nullable (javax.annotation.Nullable)1