Search in sources :

Example 1 with DuplicateMappingException

use of com.yahoo.elide.core.exceptions.DuplicateMappingException in project elide by yahoo.

the class MetaDataStore method addMetaData.

/**
 * Add a meta data object into this data store, check for duplication.
 *
 * @param object a meta data object
 */
private void addMetaData(Object object, String version) {
    HashMapDataStore hashMapDataStore = hashMapDataStores.computeIfAbsent(version, SERVER_ERROR);
    EntityDictionary dictionary = hashMapDataStore.getDictionary();
    Type<?> cls = dictionary.lookupBoundClass(EntityDictionary.getType(object));
    String id = dictionary.getId(object);
    if (hashMapDataStore.get(cls).containsKey(id)) {
        if (!hashMapDataStore.get(cls).get(id).equals(object)) {
            throw new DuplicateMappingException("Duplicated " + cls.getSimpleName() + " metadata " + id);
        }
    } else {
        hashMapDataStore.get(cls).put(id, object);
    }
}
Also used : HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) DuplicateMappingException(com.yahoo.elide.core.exceptions.DuplicateMappingException) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 2 with DuplicateMappingException

use of com.yahoo.elide.core.exceptions.DuplicateMappingException in project elide by yahoo.

the class NonEntityDictionary method bindEntity.

/**
 * Add given class to dictionary.
 *
 * @param cls Entity bean class
 */
@Override
public void bindEntity(Type<?> cls) {
    String type = WordUtils.uncapitalize(cls.getSimpleName());
    Type<?> duplicate = bindJsonApiToEntity.put(Pair.of(type, NO_VERSION), cls);
    if (duplicate != null && !duplicate.equals(cls)) {
        log.error("Duplicate binding {} for {}, {}", type, cls, duplicate);
        throw new DuplicateMappingException(type + " " + cls.getName() + ":" + duplicate.getName());
    }
    entityBindings.put(cls, new EntityBinding(getInjector(), cls, type));
}
Also used : EntityBinding(com.yahoo.elide.core.dictionary.EntityBinding) DuplicateMappingException(com.yahoo.elide.core.exceptions.DuplicateMappingException)

Aggregations

DuplicateMappingException (com.yahoo.elide.core.exceptions.DuplicateMappingException)2 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)1 EntityBinding (com.yahoo.elide.core.dictionary.EntityBinding)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1