Search in sources :

Example 1 with DirectToFieldMapping

use of org.eclipse.persistence.mappings.DirectToFieldMapping in project cuba by cuba-platform.

the class StudioEclipseLinkSessionEventListener method preLogin.

@Override
public void preLogin(SessionEvent event) {
    Session session = event.getSession();
    Map<Class, ClassDescriptor> descriptorMap = session.getDescriptors();
    for (Map.Entry<Class, ClassDescriptor> entry : descriptorMap.entrySet()) {
        ClassDescriptor desc = entry.getValue();
        if (SoftDelete.class.isAssignableFrom(desc.getJavaClass())) {
            desc.getQueryManager().setAdditionalCriteria("this.deleteTs is null");
            desc.setDeletePredicate(entity -> entity instanceof SoftDelete && PersistenceHelper.isLoaded(entity, "deleteTs") && ((SoftDelete) entity).isDeleted());
        }
        List<DatabaseMapping> mappings = desc.getMappings();
        Class entityClass = entry.getKey();
        for (DatabaseMapping mapping : mappings) {
            if (UUID.class.equals(getFieldType(entityClass, mapping.getAttributeName()))) {
                ((DirectToFieldMapping) mapping).setConverter(UuidConverter.getInstance());
                setDatabaseFieldParameters(session, mapping.getField());
            }
        }
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) Map(java.util.Map) Session(org.eclipse.persistence.sessions.Session)

Example 2 with DirectToFieldMapping

use of org.eclipse.persistence.mappings.DirectToFieldMapping in project cuba by cuba-platform.

the class UuidMappingProcessor method process.

@Override
public void process(MappingProcessorContext context) {
    DatabaseMapping mapping = context.getMapping();
    Session session = context.getSession();
    MetaClass metaClass = metadata.getSession().getClassNN(mapping.getDescriptor().getJavaClass());
    String attributeName = mapping.getAttributeName();
    MetaProperty metaProperty = metaClass.getPropertyNN(attributeName);
    if (metaProperty.getRange().isDatatype()) {
        if (metaProperty.getJavaType().equals(UUID.class)) {
            ((DirectToFieldMapping) mapping).setConverter(UuidConverter.getInstance());
            setDatabaseFieldParameters(session, mapping.getField());
        }
    } else if (metaProperty.getRange().isClass() && !metaProperty.getRange().getCardinality().isMany()) {
        MetaClass refMetaClass = metaProperty.getRange().asClass();
        MetaProperty refPkProperty = metadata.getTools().getPrimaryKeyProperty(refMetaClass);
        if (refPkProperty != null && refPkProperty.getJavaType().equals(UUID.class)) {
            for (DatabaseField field : ((OneToOneMapping) mapping).getForeignKeyFields()) {
                setDatabaseFieldParameters(session, field);
            }
        }
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) MetaClass(com.haulmont.chile.core.model.MetaClass) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Session(org.eclipse.persistence.sessions.Session)

Aggregations

DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)2 Session (org.eclipse.persistence.sessions.Session)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)1 Map (java.util.Map)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1