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());
}
}
}
}
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);
}
}
}
}
Aggregations