use of io.jmix.core.FetchPlanProperty in project jmix by jmix-framework.
the class PropertyDatasourceImpl method getView.
@Override
public FetchPlan getView() {
if (view == null) {
MetaClass metaMetaClass = masterDs.getMetaClass();
if (metadata.getTools().isJpaEntity(metaMetaClass) || metadata.getTools().isJpaEmbeddable(metaMetaClass)) {
FetchPlan masterView = masterDs.getView();
if (masterView == null) {
throw new DevelopmentException("No view for datasource " + masterDs.getId(), ParamsMap.of("masterDs", masterDs.getId(), "propertyDs", getId()));
}
FetchPlanProperty property = masterView.getProperty(metaProperty.getName());
if (property == null) {
return null;
}
if (property.getFetchPlan() == null) {
throw new DevelopmentException(String.format("Invalid view definition: %s. Property '%s' must have a view", masterView, property), ParamsMap.of("masterDs", masterDs.getId(), "propertyDs", getId(), "masterView", masterView, "property", property));
}
view = metadata.getViewRepository().getView(getMetaClass(), property.getFetchPlan().getName());
// anonymous (nameless) view
if (view == null)
view = property.getFetchPlan();
}
}
return view;
}
use of io.jmix.core.FetchPlanProperty in project jmix by jmix-framework.
the class ViewBuilderTest method testMerging.
@Test
public void testMerging() {
FetchPlan view1 = ViewBuilder.of(Pet.class).add("owner", FetchPlan.LOCAL).build();
FetchPlan view2 = ViewBuilder.of(Pet.class).addView(view1).add("name").build();
FetchPlanProperty ownerProp = view2.getProperty("owner");
assertTrue(ownerProp != null && ownerProp.getFetchPlan() != null);
assertTrue(ownerProp.getFetchPlan().containsProperty("name"));
}
use of io.jmix.core.FetchPlanProperty in project jmix by jmix-framework.
the class CollectionDsHelper method createProperties.
public static List<MetaPropertyPath> createProperties(FetchPlan fetchPlan, MetaClass metaClass) {
List<MetaPropertyPath> properties = new ArrayList<>();
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
if (fetchPlan != null && metadataTools.isJpaEntity(metaClass)) {
for (FetchPlanProperty property : fetchPlan.getProperties()) {
final String name = property.getName();
final MetaProperty metaProperty = metaClass.findProperty(name);
if (metaProperty == null) {
String message = String.format("Unable to find property %s for entity %s", name, metaClass.getName());
throw new DevelopmentException(message);
}
if (!metadataTools.isJpa(metaProperty)) {
String message = String.format("Specified transient property %s in view for datasource with persistent entity %s", name, metaClass.getName());
LoggerFactory.getLogger(CollectionDsHelper.class).warn(message);
continue;
}
final Range range = metaProperty.getRange();
if (range == null) {
continue;
}
final Range.Cardinality cardinality = range.getCardinality();
if (!cardinality.isMany()) {
properties.add(new MetaPropertyPath(metaClass, metaProperty));
}
}
// add all non-persistent properties
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (!metadataTools.isJpa(metaProperty)) {
properties.add(new MetaPropertyPath(metaClass, metaProperty));
}
}
} else {
if (fetchPlan != null) {
LoggerFactory.getLogger(CollectionDsHelper.class).warn("Specified view {} for datasource with not persistent entity {}", fetchPlan.getName(), metaClass.getName());
}
for (MetaProperty metaProperty : metaClass.getProperties()) {
final Range range = metaProperty.getRange();
if (range == null)
continue;
final Range.Cardinality cardinality = range.getCardinality();
if (!cardinality.isMany()) {
properties.add(new MetaPropertyPath(metaClass, metaProperty));
}
}
}
return properties;
}
Aggregations