EclipseLink ORM (fixed CCPayments tests, added @EmbeddedParameters, standard views include system props). #PL-5412

This commit is contained in:
Konstantin Krivopustov 2015-07-14 07:15:30 +00:00
parent 8f1ad2bdcb
commit 6aa734e29c
3 changed files with 42 additions and 1 deletions

View File

@ -9,12 +9,14 @@ import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.cuba.core.entity.BaseEntity;
import com.haulmont.cuba.core.entity.SoftDelete;
import com.haulmont.cuba.core.entity.annotation.EmbeddedParameters;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.core.sys.UuidConverter;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.descriptors.DescriptorEventListener;
import org.eclipse.persistence.internal.helper.DatabaseField;
import org.eclipse.persistence.mappings.AggregateObjectMapping;
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.mappings.DirectToFieldMapping;
import org.eclipse.persistence.mappings.OneToOneMapping;
@ -58,6 +60,7 @@ public class EclipseLinkSessionEventListener extends SessionEventAdapter {
List<DatabaseMapping> mappings = desc.getMappings();
for (DatabaseMapping mapping : mappings) {
// support UUID
String attributeName = mapping.getAttributeName();
MetaProperty metaProperty = metaClass.getPropertyNN(attributeName);
if (metaProperty.getRange().isDatatype()) {
@ -74,6 +77,13 @@ public class EclipseLinkSessionEventListener extends SessionEventAdapter {
}
}
}
// embedded attributes
if (mapping instanceof AggregateObjectMapping) {
EmbeddedParameters embeddedParameters =
metaProperty.getAnnotatedElement().getAnnotation(EmbeddedParameters.class);
if (embeddedParameters != null && !embeddedParameters.nullAllowed())
((AggregateObjectMapping) mapping).setIsNullAllowed(false);
}
}
}
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2008-2015 Haulmont. All rights reserved.
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
*/
package com.haulmont.cuba.core.entity.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Defines additional parameters for Embedded attributes.
*
* @author Konstantin Krivopustov
* @version $Id$
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface EmbeddedParameters {
/**
* If false, the embedded entity can not be null. This means you can always provide an instance when persisting
* the entity, even if all its attributes are null.
* <p>
* By default, the embedded entity can be null. In this case ORM does not create the instance on loading
* if all attributes are null.
*/
boolean nullAllowed() default true;
}

View File

@ -268,7 +268,7 @@ public class AbstractViewRepository implements ViewRepository {
name, metaClass.getName()));
}
View view = new View(javaClass, name, false);
View view = new View(javaClass, name, true); // standard views include system attributes since v6 to avoid problems with assigning them automatically on saving
if (View.LOCAL.equals(name)) {
for (MetaProperty property : metaClass.getProperties()) {
if (!property.getRange().isClass()