use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class PathTarget method resolveProperty.
@Nullable
private PropertyModel resolveProperty(String segment) {
if (context != null) {
PropertyModel model = context.getProperty(segment);
if (model == null) {
Iterator<EntityModel> subTypes = context.getSubtypes().iterator();
while (model == null && subTypes.hasNext()) {
context = subTypes.next();
model = resolveProperty(segment);
}
}
if (model != null) {
try {
context = mapper.getEntityModel(model.getNormalizedType());
} catch (NotMappableException ignored) {
context = null;
}
}
return model;
} else {
return null;
}
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class IndexHelper method collectTopLevelIndexes.
private List<Index> collectTopLevelIndexes(EntityModel entityModel) {
List<Index> list = new ArrayList<>();
final Indexes indexes = entityModel.getAnnotation(Indexes.class);
if (indexes != null) {
for (Index index : indexes.value()) {
List<Field> fields = new ArrayList<>();
for (Field field : index.fields()) {
fields.add(fieldBuilder().value(findField(entityModel, index.options(), field.value())).type(field.type()).weight(field.weight()).build());
}
list.add(replaceFields(index, fields));
}
}
EntityModel superClass = entityModel.getSuperClass();
if (superClass != null) {
list.addAll(collectTopLevelIndexes(superClass));
}
return list;
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class Mapper method register.
/**
* @param entityModel the model to register
* @return the model
* @morphia.internal
* @since 2.3
*/
public EntityModel register(EntityModel entityModel) {
discriminatorLookup.addModel(entityModel);
mappedEntities.put(entityModel.getType(), entityModel);
if (entityModel.getCollectionName() != null) {
mappedEntitiesByCollection.computeIfAbsent(entityModel.getCollectionName(), s -> new CopyOnWriteArraySet<>()).add(entityModel);
}
if (!entityModel.isInterface()) {
new MappingValidator().validate(this, entityModel);
}
return entityModel;
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class Mapper method getEntityModel.
/**
* Gets the {@link EntityModel} for the object (type). If it isn't mapped, create a new class and cache it (without validating).
*
* @param type the type to process
* @return the EntityModel for the object given
*/
public EntityModel getEntityModel(Class type) {
final Class actual = MorphiaProxy.class.isAssignableFrom(type) ? type.getSuperclass() : type;
EntityModel model = mappedEntities.get(actual);
if (model == null) {
if (!isMappable(actual)) {
throw new NotMappableException(type);
}
model = register(createEntityModel(type));
}
return model;
}
use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by mongodb.
the class Mapper method getId.
/**
* Gets the ID value for an entity
*
* @param entity the entity to process
* @return the ID value
*/
@Nullable
public Object getId(@Nullable Object entity) {
if (entity == null) {
return null;
}
try {
final EntityModel model = getEntityModel(entity.getClass());
final PropertyModel idField = model.getIdProperty();
if (idField != null) {
return idField.getValue(entity);
}
} catch (NotMappableException ignored) {
}
return null;
}
Aggregations