use of com.yahoo.elide.core.dictionary.EntityBinding in project elide by yahoo.
the class MultiplexManager method populateEntityDictionary.
@Override
public void populateEntityDictionary(EntityDictionary dictionary) {
this.dictionary = dictionary;
for (DataStore dataStore : dataStores) {
EntityDictionary subordinateDictionary = new EntityDictionary(dictionary.getCheckMappings(), dictionary.getRoleChecks(), dictionary.getInjector(), dictionary.getSerdeLookup(), dictionary.getEntitiesToExclude(), dictionary.getScanner());
dataStore.populateEntityDictionary(subordinateDictionary);
for (EntityBinding binding : subordinateDictionary.getBindings(false)) {
// route class to this database manager
this.dataStoreMap.put(binding.entityClass, dataStore);
// bind to multiplex dictionary
dictionary.bindEntity(binding);
}
for (Map.Entry<Type<?>, Function<RequestScope, PermissionExecutor>> entry : subordinateDictionary.getEntityPermissionExecutor().entrySet()) {
dictionary.bindPermissionExecutor(entry.getKey(), entry.getValue());
}
}
}
use of com.yahoo.elide.core.dictionary.EntityBinding in project elide by yahoo.
the class PersistentResource method copyComplexAttribute.
/**
* Copies a complex attribute. If the attribute fields are complex, recurses to perform a deep copy.
* @param object The attribute to copy.
* @return The copy.
*/
private Object copyComplexAttribute(Object object) {
if (object == null) {
return null;
}
Type<?> type = getType(object);
EntityBinding binding = dictionary.getEntityBinding(type);
Preconditions.checkState(!binding.equals(EMPTY_BINDING), "Model not found.");
Preconditions.checkState(binding.apiRelationships.isEmpty(), "Deep copy of relationships not supported");
Object copy;
try {
copy = type.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException("Cannot perform deep copy of " + type.getName(), e);
}
binding.apiAttributes.forEach(attribute -> {
Object newValue;
Object oldValue = dictionary.getValue(object, attribute, requestScope);
if (!dictionary.isComplexAttribute(type, attribute)) {
newValue = oldValue;
} else {
newValue = copyComplexAttribute(oldValue);
}
dictionary.setValue(copy, attribute, newValue);
});
return copy;
}
use of com.yahoo.elide.core.dictionary.EntityBinding in project elide by yahoo.
the class Table method constructColumns.
/**
* Construct all columns of this table.
*
* @param cls table class
* @param dictionary dictionary contains the table class
* @return all resolved column metadata
*/
private Set<Column> constructColumns(Type<?> cls, EntityDictionary dictionary) {
EntityBinding binding = dictionary.getEntityBinding(cls);
Set<Column> columns = new HashSet<>();
// TODO - refactor entity binding to have classes for attributes & relationships.
binding.fieldsToValues.forEach((name, field) -> {
if (EntityBinding.isIdField(field)) {
return;
}
ValueType valueType = getValueType(cls, name, dictionary);
if (valueType == ValueType.UNKNOWN) {
return;
}
if (isMetricField(dictionary, cls, name)) {
columns.add(constructMetric(name, dictionary));
} else if (dictionary.attributeOrRelationAnnotationExists(cls, name, Temporal.class)) {
columns.add(constructTimeDimension(name, dictionary));
} else {
columns.add(constructDimension(name, dictionary));
}
});
// add id field if exists
if (dictionary.getIdFieldName(cls) != null) {
String idFieldName = dictionary.getIdFieldName(cls);
if (AggregationDataStore.isAggregationStoreModel(cls)) {
columns.add(constructMetric(idFieldName, dictionary));
} else {
columns.add(constructDimension(idFieldName, dictionary));
}
}
return columns;
}
use of com.yahoo.elide.core.dictionary.EntityBinding 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));
}
Aggregations