use of io.crnk.jpa.meta.MetaJpaDataObject in project crnk-framework by crnk-project.
the class JpaResourceInformationProvider method accept.
@Override
public boolean accept(Class<?> resourceClass) {
// needs to be configured for being exposed
if (resourceClass.getAnnotation(JpaResource.class) != null) {
return true;
}
if (JpaMetaUtils.isJpaType(resourceClass)) {
// needs to be an entity
MetaElement meta = metaProvider.discoverMeta(resourceClass);
if (meta instanceof MetaEntity) {
MetaEntity metaEntity = (MetaEntity) meta;
MetaKey primaryKey = metaEntity.getPrimaryKey();
return primaryKey != null && primaryKey.getElements().size() == 1;
} else {
// note that DTOs cannot be handled here
return meta instanceof MetaJpaDataObject;
}
}
return false;
}
use of io.crnk.jpa.meta.MetaJpaDataObject in project crnk-framework by crnk-project.
the class JpaMetaFilter method onInitialized.
@Override
public void onInitialized(MetaElement element) {
if (element.getParent() instanceof MetaJpaDataObject && element instanceof MetaAttribute) {
MetaAttribute attr = (MetaAttribute) element;
MetaDataObject parent = attr.getParent();
Type implementationType = PropertyUtils.getPropertyType(parent.getImplementationClass(), attr.getName());
MetaType metaType = (MetaType) partition.allocateMetaElement(implementationType).get();
attr.setType(metaType);
}
if (element.getParent() instanceof MetaJpaDataObject && element instanceof MetaAttribute && ((MetaAttribute) element).getOppositeAttribute() == null) {
MetaAttribute attr = (MetaAttribute) element;
String mappedBy = getMappedBy(attr);
if (mappedBy != null) {
MetaType attrType = attr.getType();
MetaDataObject oppositeType = attrType.getElementType().asDataObject();
if (!mappedBy.contains(".")) {
MetaAttribute oppositeAttr = oppositeType.getAttribute(mappedBy);
attr.setOppositeAttribute(oppositeAttr);
} else {
// references within embeddables not yet supported
}
}
}
}
use of io.crnk.jpa.meta.MetaJpaDataObject in project crnk-framework by crnk-project.
the class JpaMetaEnricher method onInitialized.
@Override
public void onInitialized(MetaElement element) {
if (element instanceof MetaJsonObject) {
MetaJsonObject jsonDataObject = (MetaJsonObject) element;
Class<?> implementationClass = jsonDataObject.getImplementationClass();
if (metaProvider.hasMeta(implementationClass)) {
MetaJpaDataObject jpaDataObject = metaProvider.getMeta(implementationClass);
if (jpaDataObject.getPrimaryKey() != null && jsonDataObject.getPrimaryKey() != null) {
jsonDataObject.getPrimaryKey().setGenerated(jpaDataObject.getPrimaryKey().isGenerated());
}
List<? extends MetaAttribute> declaredAttributes = jsonDataObject.getDeclaredAttributes();
for (MetaAttribute declaredAttribute : declaredAttributes) {
String name = declaredAttribute.getName();
if (jpaDataObject.hasAttribute(name)) {
MetaAttribute jpaAttribute = jpaDataObject.getAttribute(name);
declaredAttribute.setLob(jpaAttribute.isLob());
declaredAttribute.setVersion(jpaAttribute.isVersion());
declaredAttribute.setNullable(jpaAttribute.isNullable());
declaredAttribute.setCascaded(jpaAttribute.isCascaded());
}
}
}
}
}
Aggregations