repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPADefaultEdmNameBuilder.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPADefaultEdmNameBuilder.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import javax.annotation.Nonnull; import jakarta.persistence.metamodel.Attribute; import jakarta.persistence.metamodel.EmbeddableType; import jakarta.persistence.metamodel.EntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder; public final record JPADefaultEdmNameBuilder(@Nonnull String namespace) implements JPAEdmNameBuilder { private static final int DISTANCE_NEXT_TO_LAST_CHAR = 2; private static final int DISTANCE_LAST_CHAR = 1; // V2 NameBuilder: package org.apache.olingo.odata2.jpa.processor.core.access.model private static final String ENTITY_CONTAINER_SUFFIX = "Container"; private static final String ENTITY_SET_SUFFIX = "s"; public static String firstToLower(final String substring) { return Character.toLowerCase(substring.charAt(0)) + substring.substring(1); } public static String firstToUpper(final String jpaAttributeName) { return Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1); } /** * EDM Complex Type Name - RULE: * <p> * Use JPA Embeddable Type Simple Name as Complex Type Name */ @Override public final String buildComplexTypeName(final EmbeddableType<?> jpaEmbeddedType) { return jpaEmbeddedType.getJavaType().getSimpleName(); } /** * EDM EntityContainer Name - RULE: * <p> * The Entity Container Name is build of EDM Namespace + Literal "Container". Container names are simple identifiers, * so contain only letter, digits and underscores. However namespaces * can contain also dots => eliminate dots and convert to camel case. */ @Override public String buildContainerName() { final StringBuilder containerName = new StringBuilder(); final String[] elements = namespace.split("\\."); for (final String element : elements) { containerName.append(firstToUpper(element)); } containerName.append(ENTITY_CONTAINER_SUFFIX); return containerName.toString(); } /** * EDM EntitySet Name - RULE: * <p> * Use plural of entity type name. The naming bases on the assumption that English nouns are used.<br> * Entity Set Name = JPA Entity Type Name + Literal "s" */ @Override public final String buildEntitySetName(final String entityTypeName) { if (entityTypeName.charAt(entityTypeName.length() - DISTANCE_LAST_CHAR) == 'y' && entityTypeName.charAt(entityTypeName.length() - DISTANCE_NEXT_TO_LAST_CHAR) != 'a' && entityTypeName.charAt(entityTypeName.length() - DISTANCE_NEXT_TO_LAST_CHAR) != 'e' && entityTypeName.charAt(entityTypeName.length() - DISTANCE_NEXT_TO_LAST_CHAR) != 'i' && entityTypeName.charAt(entityTypeName.length() - DISTANCE_NEXT_TO_LAST_CHAR) != 'o' && entityTypeName.charAt(entityTypeName.length() - DISTANCE_NEXT_TO_LAST_CHAR) != 'u') { return entityTypeName.substring(0, entityTypeName.length() - DISTANCE_LAST_CHAR) + "ie" + ENTITY_SET_SUFFIX; } return entityTypeName + ENTITY_SET_SUFFIX; } /** * EDM EntityType Name - RULE: * <p> * Use JPA Entity Name as EDM Entity Type Name */ @Override public String buildEntityTypeName(final EntityType<?> jpaEntityType) { return jpaEntityType.getName(); } @Override public final String getNamespace() { return namespace; } /** * EDM Navigation Property Name - RULE: * <p> * OData requires: "The name of the navigation property MUST be unique * within the set of structural and navigation properties of the containing * structured type and any of its base types." * This is fulfilled by taking the property name it self. * @param jpaAttribute * @return */ @Override public final String buildNaviPropertyName(final Attribute<?, ?> jpaAttribute) { return buildPropertyName(jpaAttribute.getName()); } /** * EDM Property Name - RULE: * <p> * OData Property Names are represented in Camel Case. The first character * of JPA Attribute Name is converted to an UpperCase Character. * @param jpaAttributeName * @return */ @Override public final String buildPropertyName(final String jpaAttributeName) { return firstToUpper(jpaAttributeName); } /** * Convert the internal name of a java based operation into the external entity data model name. * @param internalOperationName * @return */ @Override public final String buildOperationName(final String internalOperationName) { return firstToUpper(internalOperationName); } /** * Convert the internal java class name of an enumeration into the external entity data model name. * @param javaEnum * @return */ @Override public final String buildEnumerationTypeName(final Class<? extends Enum<?>> javaEnum) { return javaEnum.getSimpleName(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPAServiceDocumentFactory.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPAServiceDocumentFactory.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import java.util.List; import jakarta.persistence.metamodel.Metamodel; import com.sap.olingo.jpa.metadata.api.JPAEdmMetadataPostProcessor; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.AnnotationProvider; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public final class JPAServiceDocumentFactory { /** * Late creation of the service document. A service document contains at least one schema and a container. * @return * @throws ODataJPAModelException */ public JPAServiceDocument getServiceDocument(final JPAEdmNameBuilder nameBuilder, final Metamodel jpaMetamodel, final JPAEdmMetadataPostProcessor postProcessor, final String[] packageName, final List<AnnotationProvider> annotationProvider) throws ODataJPAModelException { return new IntermediateServiceDocument(nameBuilder, jpaMetamodel, postProcessor, packageName, annotationProvider); } public JPAServiceDocument asUserGroupRestricted(final JPAServiceDocument serviceDocument, final List<String> userGroups) throws ODataJPAModelException { if (serviceDocument instanceof IntermediateServiceDocument intermediate) return intermediate.asUserGroupRestricted(userGroups); return serviceDocument; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/ODataActionKey.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/ODataActionKey.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import java.util.Objects; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.provider.CsdlOperation; import org.apache.olingo.commons.api.edm.provider.CsdlParameter; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; /** * * @author Oliver Grande * @since 1.1.0 * 04.09.2022 */ class ODataActionKey { private final String externalName; private final FullQualifiedName bindingParameterType; public ODataActionKey(final IntermediateOperation operation) throws ODataJPAModelException { this.externalName = operation.getExternalName(); this.bindingParameterType = determineBindingParameter(operation); } public ODataActionKey(final String externalName, final FullQualifiedName actionFqn) { this.externalName = externalName; this.bindingParameterType = actionFqn; } private FullQualifiedName determineBindingParameter(final IntermediateOperation operation) throws ODataJPAModelException { if (operation.isBound()) { final CsdlParameter parameter = ((CsdlOperation) operation.getEdmItem()).getParameters().get(0); return parameter.getTypeFQN(); } return null; } public String getExternalName() { return externalName; } public FullQualifiedName getBindingParameterType() { return bindingParameterType; } @Override public int hashCode() { return Objects.hash(externalName, bindingParameterType); } @Override public boolean equals(final Object obj) { if (this == obj) return true; if (!(obj instanceof ODataActionKey)) return false; // NOSONAR final ODataActionKey other = (ODataActionKey) obj; return Objects.equals(bindingParameterType, other.bindingParameterType) && Objects.equals(externalName, other.externalName); } @Override public String toString() { return "ODataActionKey [externalName=" + externalName + ", bindingParameterType=" + bindingParameterType + "]"; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPAPathImpl.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPAPathImpl.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.NOT_SUPPORTED_MIXED_PART_OF_GROUP; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAElement; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; final class JPAPathImpl implements JPAPath { private static final List<String> EMPTY_FILED_GROUPS = Collections.emptyList(); private final String alias; private final List<JPAElement> pathElements; private final String dbFieldName; private final boolean ignore; private final List<String> fieldGroups; private Optional<Boolean> isTransient; JPAPathImpl(final String alias, final String dbFieldName, final IntermediateProperty element) throws ODataJPAModelException { this(alias, dbFieldName, Arrays.asList(element)); } JPAPathImpl(final String alias, final String dbFieldName, final List<JPAElement> attribute) throws ODataJPAModelException { this.alias = alias; this.pathElements = Collections.unmodifiableList(attribute); this.dbFieldName = dbFieldName; this.ignore = ((IntermediateModelElement) pathElements.get(pathElements.size() - 1)).ignore(); this.fieldGroups = determineFieldGroups(); this.isTransient = Optional.empty(); } @Override public int compareTo(final JPAPath o) { return this.alias.compareTo(o.getAlias()); } @Override public boolean equals(final Object object) { if (this == object) return true; if (object == null) return false; if (getClass() != object.getClass()) return false; final JPAPathImpl other = (JPAPathImpl) object; if (alias == null) { if (other.alias != null) return false; } else if (!alias.equals(other.alias)) return false; if (pathElements == null) { if (other.pathElements != null) return false; } else if (!pathElements.equals(other.pathElements)) return false; return true; } /* * (non-Javadoc) * * @see com.sap.olingo.jpa.metadata.core.edm.mapper.impl.JPAPath#getAlias() */ @Override public String getAlias() { return alias; } /* * (non-Javadoc) * * @see com.sap.olingo.jpa.metadata.core.edm.mapper.impl.JPAPath#getDBFieldName() */ @Override public String getDBFieldName() { return dbFieldName; } /* * (non-Javadoc) * * @see com.sap.olingo.jpa.metadata.core.edm.mapper.impl.JPAPath#getLeaf() */ @Override public JPAAttribute getLeaf() { return (JPAAttribute) pathElements.get(pathElements.size() - 1); } /* * (non-Javadoc) * * @see com.sap.olingo.jpa.metadata.core.edm.mapper.impl.JPAPath#getPath() */ @Override public List<JPAElement> getPath() { return pathElements; } @Override public String getPathAsString() { return getAlias(); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((alias == null) ? 0 : alias.hashCode()); result = prime * result + ((pathElements == null) ? 0 : pathElements.hashCode()); return result; } /* * (non-Javadoc) * * @see com.sap.olingo.jpa.metadata.core.edm.mapper.impl.JPAPath#ignore() */ @Override public boolean ignore() { return ignore; } @Override public boolean isPartOfGroups(final List<String> groups) { return fieldGroups == EMPTY_FILED_GROUPS || fieldGroupMatches(groups); } @Override public boolean isTransient() { return isTransient.orElseGet(this::determineIsTransient); } @Override public String toString() { return "JPAPathImpl [alias=" + alias + ", pathElements=" + pathElements + ", dbFieldName=" + dbFieldName + ", ignore=" + ignore + ", fieldGroups=" + fieldGroups + "]"; } /** * @return * @throws ODataJPAModelException */ private List<String> determineFieldGroups() throws ODataJPAModelException { List<String> groups = null; for (final JPAElement pathElement : pathElements) { if (pathElement instanceof final IntermediateProperty intermediateProperty && intermediateProperty.isPartOfGroup()) { if (groups == null) groups = intermediateProperty.getUserGroups(); else { final List<String> newGroups = ((IntermediateProperty) pathElement).getUserGroups(); if (groups.size() != newGroups.size() || !groups.stream().allMatch(newGroups::contains)) throw new ODataJPAModelException(NOT_SUPPORTED_MIXED_PART_OF_GROUP, alias); } } } return groups == null ? EMPTY_FILED_GROUPS : groups; } private Boolean determineIsTransient() { isTransient = Optional.of( pathElements.stream() .filter(JPAAttribute.class::isInstance) .map(JPAAttribute.class::cast) .anyMatch(JPAAttribute::isTransient)); return isTransient.get(); } /** * @param groups * @return */ private boolean fieldGroupMatches(final List<String> groups) { for (final String group : groups) { if (fieldGroups.contains(group)) return true; } return false; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateTopLevelEntity.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateTopLevelEntity.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation; import org.apache.olingo.commons.api.edm.provider.CsdlNavigationPropertyBinding; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlDynamicExpression; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmQueryExtensionProvider; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.ODataAnnotatable; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.ODataNavigationPath; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.ODataPathNotFoundException; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.ODataPropertyPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAssociationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAQueryExtension; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPATopLevelEntity; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelInternalException; abstract class IntermediateTopLevelEntity extends IntermediateModelElement implements JPATopLevelEntity, ODataAnnotatable { final IntermediateEntityType<?> entityType; IntermediateTopLevelEntity(final JPAEdmNameBuilder nameBuilder, final IntermediateEntityType<?> et, final IntermediateAnnotationInformation annotationInfo) { super(nameBuilder, InternalNameBuilder.buildEntitySetName(nameBuilder, et), annotationInfo); this.entityType = et; } protected List<CsdlNavigationPropertyBinding> determinePropertyBinding() throws ODataJPAModelException { final List<CsdlNavigationPropertyBinding> navigationPropBindingList = new ArrayList<>(); final var navigationPropertyList = entityType.getAssociationPathList(); if (navigationPropertyList != null && !navigationPropertyList.isEmpty()) { // http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406398035 for (final JPAAssociationPath navigationPropertyPath : navigationPropertyList) { if (navigationPropertyPath.getTargetType() instanceof final IntermediateEntityType<?> et && (et.asEntitySet() || et.asSingleton())) { navigationPropBindingList.add(createNavigationPropertyBinding(navigationPropertyPath)); } } } return navigationPropBindingList; } private CsdlNavigationPropertyBinding createNavigationPropertyBinding(final JPAAssociationPath navigationPropertyPath) throws ODataJPAModelException { final var navigationPropBinding = new CsdlNavigationPropertyBinding(); navigationPropBinding.setPath(navigationPropertyPath.getAlias()); // TODO Check is FQN is better here final var navigationProperty = navigationPropertyPath.getLeaf(); navigationPropBinding.setTarget(nameBuilder.buildEntitySetName(navigationProperty.getTargetEntity() .getExternalName())); return navigationPropBinding; } /** * Returns the entity type that shall be used to create the metadata document. * This can differ from the internally used one e.g. if multiple entity sets shall * point to the same entity type, but base on different tables * @return * @throws ODataJPAModelException */ public JPAEntityType getODataEntityType() throws ODataJPAModelException { if (entityType.asTopLevelOnly()) return (JPAEntityType) entityType.getBaseType(); else return entityType; } /** * Returns the entity type to be used internally e.g. for the query generation * @return */ public JPAEntityType getEntityType() { return entityType; } @Override public Optional<JPAQueryExtension<EdmQueryExtensionProvider>> getQueryExtension() throws ODataJPAModelException { return getEntityType().getQueryExtension(); } @Override public ODataPropertyPath convertStringToPath(final String internalPath) throws ODataPathNotFoundException { return entityType.convertStringToPath(internalPath); } @Override public ODataNavigationPath convertStringToNavigationPath(final String internalPath) throws ODataPathNotFoundException { return entityType.convertStringToNavigationPath(internalPath); } @Override public Annotation javaAnnotation(final String name) { return entityType.javaAnnotation(name); } @Override public Map<String, Annotation> javaAnnotations(final String packageName) { return entityType.javaAnnotations(packageName); } @Override public Object getAnnotationValue(final String alias, final String term, final String property) throws ODataJPAModelException { try { return Optional.ofNullable(getAnnotation(alias, term)) .map(CsdlAnnotation::getExpression) .map(expression -> getAnnotationValue(property, expression)) .orElse(null); } catch (final ODataJPAModelInternalException e) { throw (ODataJPAModelException) e.getCause(); } } @Override public List<String> getUserGroups() throws ODataJPAModelException { return entityType.getUserGroups(); } @Override protected Object getAnnotationDynamicValue(final String property, final CsdlDynamicExpression expression) throws ODataJPAModelInternalException { try { if (expression.isRecord()) { // This may create a problem if the property in question is a record itself. Currently non is supported in // standard final var propertyValue = findAnnotationPropertyValue(property, expression); if (propertyValue.isPresent()) { return getAnnotationValue(property, propertyValue.get()); } } else if (expression.isCollection()) { return getAnnotationCollectionValue(expression); } else if (expression.isPropertyPath()) { return getEntityType().getPath(expression.asPropertyPath().getValue()); } else if (expression.isNavigationPropertyPath()) { return getEntityType().getAssociationPath(expression.asNavigationPropertyPath().getValue()); } return null; } catch (final ODataJPAModelException e) { throw new ODataJPAModelInternalException(e); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPAProtectionInfo.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/JPAProtectionInfo.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import java.util.List; final class JPAProtectionInfo { private final List<String> path; private final boolean wildcards; JPAProtectionInfo(List<String> path, boolean wildcards) { super(); this.path = path; this.wildcards = wildcards; } @Override public String toString() { return "JPAProtectionInfo [path=" + path + ", wildcards=" + wildcards + "]"; } List<String> getPath() { return path; } /** * Returns the maintained wildcard setting. * @return */ boolean supportsWildcards() { return wildcards; } /** * Returns wildcard support if the protected property it of type <i>clazz</i> * @param <T> * @param clazz * @return */ <T> boolean supportsWildcards(final Class<T> clazz) { if (clazz.equals(String.class)) return wildcards; return false; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateProperty.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateProperty.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.COMPLEX_PROPERTY_MISSING_PROTECTION_PATH; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.PROPERTY_PRECISION_NOT_IN_RANGE; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.TRANSIENT_CALCULATOR_TOO_MANY_CONSTRUCTORS; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.TRANSIENT_CALCULATOR_WRONG_PARAMETER; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.TRANSIENT_KEY_NOT_SUPPORTED; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Parameter; import java.lang.reflect.ParameterizedType; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import jakarta.persistence.AttributeConverter; import jakarta.persistence.Column; import jakarta.persistence.Convert; import jakarta.persistence.EntityManager; import jakarta.persistence.Enumerated; import jakarta.persistence.Lob; import jakarta.persistence.metamodel.Attribute; import jakarta.persistence.metamodel.Attribute.PersistentAttributeType; import jakarta.persistence.metamodel.ManagedType; import jakarta.persistence.metamodel.Type.PersistenceType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.geo.Geospatial.Dimension; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation; import org.apache.olingo.commons.api.edm.provider.CsdlMapping; import org.apache.olingo.commons.api.edm.provider.CsdlProperty; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlDynamicExpression; import com.sap.olingo.jpa.metadata.api.JPAHttpHeaderMap; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmGeospatial; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmIgnore; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmProtectedBy; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmProtections; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmSearchable; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransient; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransientPropertyCalculator; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmVisibleFor; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.Applicability; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.ODataAnnotatable; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAParameter; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAStructuredType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelInternalException; import com.sap.olingo.jpa.metadata.core.edm.mapper.extension.IntermediatePropertyAccess; /** * Properties can be classified by two different aspects: * <ol> * <li>If they are complex, so are structured, or primitive</li> * <li>If they are a collection of instances or if they are simple and can have up to one instance</li> * </ol> * So properties maybe e.g. a complex collection property or a simple primitive property * @author Oliver Grande * */ abstract class IntermediateProperty extends IntermediateModelElement implements IntermediatePropertyAccess, ODataAnnotatable, JPAAttribute { private static final Log LOGGER = LogFactory.getLog(IntermediateProperty.class); private static final int UPPER_LIMIT_PRECISION_TEMP = 12; private static final int LOWER_LIMIT_PRECISION_TEMP = 0; protected final jakarta.persistence.metamodel.Attribute<?, ?> jpaAttribute; protected final IntermediateSchema schema; protected CsdlProperty edmProperty; protected JPAStructuredType type; protected AttributeConverter<?, ?> valueConverter; protected String dbFieldName; protected Class<?> dbType; protected Class<?> entityType; protected final ManagedType<?> managedType; protected boolean isVersion; protected boolean searchable; protected boolean conversionRequired; private boolean isEnum; private final Map<String, JPAProtectionInfo> externalProtectedPathNames; private List<String> userGroups; protected List<String> requiredAttributes; private Constructor<? extends EdmTransientPropertyCalculator<?>> transientCalculatorConstructor; IntermediateProperty(final JPAEdmNameBuilder nameBuilder, final Attribute<?, ?> jpaAttribute, final IntermediateSchema schema) throws ODataJPAModelException { super(nameBuilder, InternalNameBuilder.buildAttributeName(jpaAttribute), schema.getAnnotationInformation()); this.jpaAttribute = jpaAttribute; this.schema = schema; this.managedType = jpaAttribute.getDeclaringType(); this.externalProtectedPathNames = new HashMap<>(1); buildProperty(nameBuilder); } IntermediateProperty(IntermediateProperty source, List<String> userGroups) throws ODataJPAModelException { super(source.nameBuilder, source.getInternalName(), source.getAnnotationInformation(), true); this.jpaAttribute = source.jpaAttribute; this.schema = source.schema; this.managedType = source.managedType; this.externalProtectedPathNames = source.externalProtectedPathNames; this.userGroups = source.userGroups; this.requiredAttributes = source.requiredAttributes; this.transientCalculatorConstructor = source.transientCalculatorConstructor; this.type = source.type == null ? null : ((IntermediateModelElement) source.type).asUserGroupRestricted(userGroups); this.valueConverter = source.valueConverter; this.dbFieldName = source.dbFieldName; this.dbType = source.dbType; this.entityType = source.entityType; this.isVersion = source.isVersion; this.searchable = source.searchable; this.conversionRequired = source.conversionRequired; this.isEnum = source.isEnum; setExternalName(source.getExternalName()); this.edmProperty = source.edmProperty; } @Override public void addAnnotations(final List<CsdlAnnotation> annotations) { edmAnnotations.addAll(annotations); } @SuppressWarnings("unchecked") @Override public <T extends EdmTransientPropertyCalculator<?>> Constructor<T> getCalculatorConstructor() throws ODataJPAModelException { if (this.edmProperty == null) { lazyBuildEdmItem(); } return (Constructor<T>) transientCalculatorConstructor; } @Override public <X, Y extends Object> AttributeConverter<X, Y> getConverter() { return conversionRequired ? getRawConverter() : null; } @SuppressWarnings("unchecked") @Override public <X, Y extends Object> AttributeConverter<X, Y> getRawConverter() { return (AttributeConverter<X, Y>) valueConverter; } @Override public EdmPrimitiveTypeKind getEdmType() throws ODataJPAModelException { return JPATypeConverter.convertToEdmSimpleType(getType(), jpaAttribute); } @Override public CsdlProperty getProperty() throws ODataJPAModelException { return getEdmItem(); } @Override public Set<String> getProtectionClaimNames() { return externalProtectedPathNames.keySet(); } @Override public List<String> getProtectionPath(final String claimName) throws ODataJPAModelException { if (externalProtectedPathNames.containsKey(claimName)) return externalProtectedPathNames.get(claimName).getPath(); return new ArrayList<>(0); } /** * @return */ @Override public List<String> getRequiredProperties() { return requiredAttributes; } @Override public JPAStructuredType getStructuredType() { return type == null ? null : type; } @Override public Class<?> getType() { if (conversionRequired) return dbType.isPrimitive() ? boxPrimitive(dbType) : dbType; else return entityType.isPrimitive() ? boxPrimitive(entityType) : entityType; } @Override public Class<?> getDbType() { return dbType.isPrimitive() ? boxPrimitive(dbType) : dbType; } @Override public Class<?> getJavaType() { return entityType.isPrimitive() ? boxPrimitive(entityType) : entityType; } @Override public boolean hasProtection() { return !externalProtectedPathNames.isEmpty(); } @Override public boolean isEnum() { return isEnum; } private void determineIsEnum() { isEnum = schema.getEnumerationType(entityType) != null; } @Override public boolean isEtag() { return isVersion; } @Override public boolean isSearchable() { return searchable; } @Override public boolean isTransient() { return requiredAttributes != null; } @Override public Map<String, Annotation> javaAnnotations(final String packageName) { return findJavaAnnotation(packageName, ((AnnotatedElement) this.jpaAttribute.getJavaMember())); } protected void buildProperty(final JPAEdmNameBuilder nameBuilder) throws ODataJPAModelException { // Set element specific attributes of super type this.setExternalName(nameBuilder.buildPropertyName(internalName)); entityType = dbType = determinePropertyType(); if (this.jpaAttribute.getJavaMember() instanceof AnnotatedElement) { retrieveAnnotations(this, Applicability.PROPERTY); determineIgnore(); determineIsEnum(); determineStructuredType(); determineInternalTypesFromConverter(); determineDBFieldName(); determineTransient(); determineSearchable(); determineStreamInfo(); determineIsVersion(); determineProtection(); determineUserGroups(); checkConsistency(); } postProcessor.processProperty(this, jpaAttribute.getDeclaringType().getJavaType().getCanonicalName()); // Process annotations after post processing, as external name it could // have been changed getAnnotations(edmAnnotations, this.jpaAttribute.getJavaMember(), internalName); } protected FullQualifiedName determineTypeByPersistenceType(final Enum<?> persistenceType) throws ODataJPAModelException { if (PersistentAttributeType.BASIC.equals(persistenceType) || PersistenceType.BASIC.equals(persistenceType)) { final var odataType = getODataPrimitiveType(); if (odataType == null) return getSimpleType(); else return odataType.getExternalFQN(); } if (PersistentAttributeType.EMBEDDED.equals(persistenceType) || PersistenceType.EMBEDDABLE.equals(persistenceType)) return buildFQN(type.getExternalName()); else return EdmPrimitiveTypeKind.Boolean.getFullQualifiedName(); } protected String getDBFieldName() { return dbFieldName; } @Override protected CsdlProperty getEdmItem() throws ODataJPAModelException { if (this.edmProperty == null) { lazyBuildEdmItem(); } return edmProperty; } @Override protected synchronized void lazyBuildEdmItem() throws ODataJPAModelException { if (edmProperty == null) { edmProperty = new CsdlProperty(); edmProperty.setName(this.getExternalName()); edmProperty.setType(determineType()); setFacet(); edmProperty.setMapping(createMapper()); edmProperty.setAnnotations(edmAnnotations); if (type != null && type instanceof IntermediateModelElement element) { element.getEdmItem(); } } } @Override public CsdlAnnotation getAnnotation(final String alias, final String term) throws ODataJPAModelException { return filterAnnotation(alias, term); } @Override public Object getAnnotationValue(final String alias, final String term, final String property) throws ODataJPAModelException { try { return Optional.ofNullable(getAnnotation(alias, term)) .map(a -> a.getExpression()) .map(expression -> getAnnotationValue(property, expression)) .orElse(null); } catch (final ODataJPAModelInternalException e) { throw (ODataJPAModelException) e.getCause(); } } @Override protected Object getAnnotationDynamicValue(final String property, final CsdlDynamicExpression expression) throws ODataJPAModelInternalException { if (expression.isRecord()) { // This may create a problem if the property in question is a record itself. Currently non is supported in // standard final var propertyValue = findAnnotationPropertyValue(property, expression); if (propertyValue.isPresent()) { return getAnnotationValue(property, propertyValue.get()); } } return null; } /** * Check consistency of provided attribute e.g. check id attribute was annotated with unsupported annotations * @throws ODataJPAModelException */ abstract void checkConsistency() throws ODataJPAModelException; CsdlMapping createMapper() { if (!isLob() && !(getConverter() == null || isEnum())) { final var mapping = new CsdlMapping(); mapping.setInternalName(this.getExternalName()); mapping.setMappedJavaClass(dbType); return mapping; } return null; } abstract Class<?> determinePropertyType(); abstract void determineIsVersion(); void determineProtection() throws ODataJPAModelException { final var jpaProtections = ((AnnotatedElement) this.jpaAttribute.getJavaMember()) .getAnnotation(EdmProtections.class); if (jpaProtections != null) { for (final EdmProtectedBy jpaProtectedBy : jpaProtections.value()) { determineOneProtection(jpaProtectedBy); } } else { final var jpaProtectedBy = ((AnnotatedElement) this.jpaAttribute.getJavaMember()) .getAnnotation(EdmProtectedBy.class); if (jpaProtectedBy != null) { determineOneProtection(jpaProtectedBy); } } } void determineSearchable() { final var jpaSearchable = ((AnnotatedElement) this.jpaAttribute.getJavaMember()) .getAnnotation(EdmSearchable.class); if (jpaSearchable != null) searchable = true; } abstract void determineStreamInfo() throws ODataJPAModelException; abstract void determineStructuredType(); abstract FullQualifiedName determineType() throws ODataJPAModelException; abstract String getDefaultValue() throws ODataJPAModelException; /** * @return */ List<String> getUserGroups() { return userGroups; } IntermediateModelElement getODataPrimitiveType() { return schema.getEnumerationType(entityType); } FullQualifiedName getSimpleType() throws ODataJPAModelException { return JPATypeConverter.convertToEdmSimpleType(getType(), jpaAttribute) .getFullQualifiedName(); } SRID getSRID() { SRID result = null; if (jpaAttribute.getJavaMember() instanceof AnnotatedElement) { final var annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember(); final var spatialDetails = annotatedElement.getAnnotation(EdmGeospatial.class); if (spatialDetails != null) { final var srid = spatialDetails.srid(); final var dimension = spatialDetails.dimension(); if (srid.isEmpty()) // Set default values external: See https://issues.apache.org/jira/browse/OLINGO-1564 result = SRID.valueOf(dimension == Dimension.GEOMETRY ? "0" : "4326"); else result = SRID.valueOf(srid); result.setDimension(spatialDetails.dimension()); } } return result; } boolean isPartOfGroup() { return !userGroups.isEmpty(); } abstract boolean isStream(); /** * Determines if wildcards are supported. In case a complex type is annotated this depends on the type of the target * attribute. To prevent deed locks during metadata generation the determination is done late. * @param <T> * @param claimName * @param clazz * @return */ <T> boolean protectionWithWildcard(final String claimName, final Class<T> clazz) { if (externalProtectedPathNames.containsKey(claimName)) return externalProtectedPathNames.get(claimName).supportsWildcards(clazz); return true; } void setFacet() throws ODataJPAModelException { if (jpaAttribute.getJavaMember() instanceof AnnotatedElement) { final var jpaColumn = ((AnnotatedElement) jpaAttribute.getJavaMember()).getAnnotation(Column.class); if (jpaColumn != null) { edmProperty.setNullable(jpaColumn.nullable()); edmProperty.setSrid(getSRID()); edmProperty.setDefaultValue(getDefaultValue()); edmProperty.setMaxLength(determineMaxLength(jpaColumn)); determinePrecisionScale(jpaColumn); // TODO Attribute Unicode } } } private void determinePrecisionScale(final Column jpaColumn) throws ODataJPAModelException { if (edmProperty.getType() .equals(EdmPrimitiveTypeKind.Decimal.getFullQualifiedName().toString())) { setPrecisionScale(jpaColumn); } else { setPrecisionScaleTemporal(jpaColumn); } } private Integer determineMaxLength(final Column jpaColumn) { if ((edmProperty.getTypeAsFQNObject().equals(EdmPrimitiveTypeKind.String.getFullQualifiedName()) || edmProperty.getTypeAsFQNObject().equals(EdmPrimitiveTypeKind.Binary.getFullQualifiedName())) && !isLob() && jpaColumn.length() > 0) { return jpaColumn.length(); } return null; } /** * For a temporal property the value of this attribute specifies the number of decimal * places allowed in the seconds portion of the property's value; it MUST be a non-negative integer between * zero and twelve. If no value is specified, the temporal property has a precision of zero.<br> * See: <a href="https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530360">7.2.3 * Precision</a> * @param jpaColumn * @throws ODataJPAModelException */ private void setPrecisionScaleTemporal(final Column jpaColumn) throws ODataJPAModelException { if (edmProperty.getType() .equals(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName().toString()) || edmProperty.getType() .equals(EdmPrimitiveTypeKind.TimeOfDay.getFullQualifiedName().toString()) || edmProperty.getType() .equals(EdmPrimitiveTypeKind.Duration.getFullQualifiedName().toString())) { if (jpaColumn.precision() < LOWER_LIMIT_PRECISION_TEMP || jpaColumn.precision() > UPPER_LIMIT_PRECISION_TEMP) { // The type of property '%1$s' requires a precision between 0 and 12, but was '%2$s'. throw new ODataJPAModelException(PROPERTY_PRECISION_NOT_IN_RANGE, jpaAttribute.getName(), Integer.toString( jpaColumn.precision())); } else { edmProperty.setPrecision(jpaColumn.precision()); } } } /** * Sets Precision and Scale for a Decimal:<br> * For a decimal property the value of this attribute specifies the maximum number of digits allowed in the * properties value; it MUST be a positive integer. If no value is specified, the decimal property has * unspecified precision. <br> * See: <a href="https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530360">7.2.3 * Precision</a> * @param jpaColumn * @throws ODataJPAModelException */ private void setPrecisionScale(final Column jpaColumn) { if (jpaColumn.precision() > 0) edmProperty.setPrecision(jpaColumn.precision()); if (edmProperty.getType().equals(EdmPrimitiveTypeKind.Decimal.getFullQualifiedName().toString()) && jpaColumn.scale() > 0) edmProperty.setScale(jpaColumn.scale()); } /** * Converts an internal path into an external path * @param internalPath * @return */ private String convertPath(final String internalPath) { final var pathSegments = internalPath.split(JPAPath.PATH_SEPARATOR); final var externalPath = new StringBuilder(); for (final String segment : pathSegments) { externalPath.append(nameBuilder.buildPropertyName(segment)); externalPath.append(JPAPath.PATH_SEPARATOR); } externalPath.deleteCharAt(externalPath.length() - 1); return externalPath.toString(); } /** * @param calculator * @return * @throws ODataJPAModelException */ @SuppressWarnings("unchecked") private Constructor<? extends EdmTransientPropertyCalculator<?>> determineCalculatorConstructor( final Class<? extends EdmTransientPropertyCalculator<?>> calculator) throws ODataJPAModelException { if (calculator.getConstructors().length > 1) throw new ODataJPAModelException(TRANSIENT_CALCULATOR_TOO_MANY_CONSTRUCTORS, calculator.getName(), jpaAttribute.getName(), jpaAttribute.getJavaMember().getDeclaringClass().getName()); final Constructor<?> constructor = calculator.getConstructors()[0]; if (constructor.getParameters() != null) { for (final Parameter p : constructor.getParameters()) { if (!(p.getType().isAssignableFrom(EntityManager.class) || p.getType().isAssignableFrom(JPAParameter.class) || p.getType().isAssignableFrom(JPAHttpHeaderMap.class))) throw new ODataJPAModelException(TRANSIENT_CALCULATOR_WRONG_PARAMETER, calculator.getName(), jpaAttribute.getName(), jpaAttribute.getJavaMember().getDeclaringClass().getName()); } } return (Constructor<? extends EdmTransientPropertyCalculator<?>>) constructor; } private void determineDBFieldName() { final var jpaColumnDetails = ((AnnotatedElement) this.jpaAttribute.getJavaMember()) .getAnnotation(Column.class); if (jpaColumnDetails != null) { dbFieldName = jpaColumnDetails.name(); if (dbFieldName.isEmpty()) { dbFieldName = nameBuilder.buildColumnName(internalName); } } else { // Hibernate problem: Hibernate tested with 5.6.7 did not provide Column annotation // for @Id attributes. Try another way to get the information try { if (jpaAttribute.getDeclaringType() != null) { final var declaringClass = jpaAttribute.getDeclaringType().getJavaType().getDeclaredField(jpaAttribute .getName()); final var jpaColumn = declaringClass.getAnnotation(Column.class); if (jpaColumn != null) dbFieldName = jpaColumn.name(); } } catch (NoSuchFieldException | SecurityException e) { LOGGER.trace("Could not find field '" + jpaAttribute.getName() + "' of class '" + this.jpaAttribute .getDeclaringType().getJavaType().getCanonicalName() + "'"); } } if (dbFieldName == null || dbFieldName.isEmpty()) dbFieldName = internalName; } /** * */ private void determineUserGroups() { final var jpaFieldGroups = ((AnnotatedElement) this.jpaAttribute.getJavaMember()) .getAnnotation(EdmVisibleFor.class); if (jpaFieldGroups != null) userGroups = Arrays.stream(jpaFieldGroups.value()).toList(); else userGroups = new ArrayList<>(0); } private void determineIgnore() { final var jpaIgnore = ((AnnotatedElement) this.jpaAttribute.getJavaMember()) .getAnnotation(EdmIgnore.class); if (jpaIgnore != null) { this.setIgnore(true); } } @SuppressWarnings("unchecked") private void determineInternalTypesFromConverter() throws ODataJPAModelException { final var jpaConverter = ((AnnotatedElement) this.jpaAttribute.getJavaMember()) .getAnnotation(Convert.class); if (jpaConverter != null) { try { final var converterType = jpaConverter.converter().getGenericInterfaces(); final var types = ((ParameterizedType) converterType[0]).getActualTypeArguments(); entityType = (Class<?>) types[0]; dbType = (Class<?>) types[1]; conversionRequired = !JPATypeConverter.isSupportedByOlingo(entityType); valueConverter = (AttributeConverter<?, ?>) jpaConverter.converter().getDeclaredConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new ODataJPAModelException( ODataJPAModelException.MessageKeys.TYPE_MAPPER_COULD_NOT_INSTANTIATED, e); } } else { final var enumerated = ((AnnotatedElement) this.jpaAttribute.getJavaMember()) .getAnnotation(Enumerated.class); if (enumerated != null) { switch (enumerated.value()) { case ORDINAL -> dbType = Integer.class; case STRING -> dbType = String.class; default -> throw new IllegalArgumentException("Unexpected value: " + enumerated.value()); } conversionRequired = false; } else if (isEnum) { dbType = Integer.class; conversionRequired = false; } } } private void determineOneProtection(final EdmProtectedBy jpaProtectedBy) throws ODataJPAModelException { List<String> externalNames; final var protectionClaimName = jpaProtectedBy.name(); if (externalProtectedPathNames.containsKey(protectionClaimName)) externalNames = externalProtectedPathNames.get(protectionClaimName).getPath(); else externalNames = new ArrayList<>(2); if (jpaAttribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED) { final var internalProtectedPath = jpaProtectedBy.path(); if (internalProtectedPath.isEmpty()) { throw new ODataJPAModelException(COMPLEX_PROPERTY_MISSING_PROTECTION_PATH, this.managedType.getJavaType() .getCanonicalName(), this.internalName); } externalNames.add(getExternalName() + JPAPath.PATH_SEPARATOR + convertPath(jpaProtectedBy.path())); } else { externalNames.add(getExternalName()); } externalProtectedPathNames.put(protectionClaimName, new JPAProtectionInfo(externalNames, jpaProtectedBy .wildcardSupported())); } private List<String> determineRequiredAttributesTransient(final EdmTransient jpaTransient) { return jpaTransient.requiredAttributes() == null ? Collections.emptyList() : Arrays.asList( jpaTransient.requiredAttributes()); } /** * @throws ODataJPAModelException * */ void determineTransient() throws ODataJPAModelException { final var jpaTransient = ((AnnotatedElement) this.jpaAttribute.getJavaMember()) .getAnnotation(EdmTransient.class); if (jpaTransient != null) { if (isKey()) throw new ODataJPAModelException(TRANSIENT_KEY_NOT_SUPPORTED, jpaAttribute.getJavaMember().getDeclaringClass().getName()); requiredAttributes = determineRequiredAttributesTransient(jpaTransient); transientCalculatorConstructor = determineCalculatorConstructor(jpaTransient.calculator()); } } private boolean isLob() { if (jpaAttribute != null && jpaAttribute.getJavaMember() instanceof AnnotatedElement) { final var annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember(); if (annotatedElement != null && annotatedElement.getAnnotation(Lob.class) != null) { return true; } } return false; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateEntityContainer.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateEntityContainer.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.apache.olingo.commons.api.edm.provider.CsdlAction; import org.apache.olingo.commons.api.edm.provider.CsdlActionImport; import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation; import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer; import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet; import org.apache.olingo.commons.api.edm.provider.CsdlFunction; import org.apache.olingo.commons.api.edm.provider.CsdlFunctionImport; import org.apache.olingo.commons.api.edm.provider.CsdlSingleton; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAction; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntitySet; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAFunction; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAUserGroupRestrictable; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.metadata.core.edm.mapper.extension.IntermediateEntityContainerAccess; /** * <a href= * "https://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406398024" * >OData Version 4.0 Part 3 - 13 Entity Container</a> * @author Oliver Grande * */ //TODO How to handle multiple schemas final class IntermediateEntityContainer extends IntermediateModelElement implements IntermediateEntityContainerAccess { private final Map<String, IntermediateSchema> schemaList; private final Map<String, IntermediateEntitySet> entitySetListInternalKey; private final Map<String, IntermediateSingleton> singletonListInternalKey; private CsdlEntityContainer edmContainer; IntermediateEntityContainer(final JPAEdmNameBuilder nameBuilder, final Map<String, IntermediateSchema> schemaList, final IntermediateAnnotationInformation annotationInfo) { super(nameBuilder, nameBuilder.buildContainerName(), annotationInfo); this.schemaList = schemaList; this.setExternalName(nameBuilder.buildContainerName()); this.entitySetListInternalKey = new HashMap<>(); this.singletonListInternalKey = new HashMap<>(); } private IntermediateEntityContainer(IntermediateEntityContainer source, Map<String, IntermediateSchema> schemaListInternalKey, List<String> userGroups) throws ODataJPAModelException { super(source.nameBuilder, source.nameBuilder.buildContainerName(), source.getAnnotationInformation()); schemaList = schemaListInternalKey; setExternalName(source.getExternalName()); entitySetListInternalKey = copyRestricted(source.entitySetListInternalKey, userGroups); singletonListInternalKey = copyRestricted(source.singletonListInternalKey, userGroups); } private <T extends IntermediateModelElement> Map<String, T> copyRestricted(Map<String, T> source, List<String> userGroups) throws ODataJPAModelException { final Map<String, T> result = new HashMap<>(source.size()); for (var item : source.entrySet()) { if (item.getValue() instanceof JPAUserGroupRestrictable restrictable) { if (restrictable.isAccessibleFor(userGroups)) { result.put(item.getKey(), item.getValue().asUserGroupRestricted(userGroups)); } } else { result.put(item.getKey(), item.getValue().asUserGroupRestricted(userGroups)); } } return result; } @Override public void addAnnotations(final List<CsdlAnnotation> annotations) { this.edmAnnotations.addAll(annotations); } IntermediateEntityContainer asUserGroupRestricted(Map<String, IntermediateSchema> schemaListInternalKey, List<String> userGroups) throws ODataJPAModelException { return new IntermediateEntityContainer(this, schemaListInternalKey, userGroups); } @Override protected synchronized void lazyBuildEdmItem() throws ODataJPAModelException { if (edmContainer == null) { postProcessor.processEntityContainer(this); edmContainer = new CsdlEntityContainer(); edmContainer.setName(getExternalName()); edmContainer.setEntitySets(buildEntitySets()); edmContainer.setFunctionImports(buildFunctionImports()); edmContainer.setActionImports(buildActionImports()); edmContainer.setAnnotations(edmAnnotations); edmContainer.setSingletons(buildSingletons()); } } @Override CsdlEntityContainer getEdmItem() throws ODataJPAModelException { if (edmContainer == null) { lazyBuildEdmItem(); } return edmContainer; } IntermediateEntitySet getEntitySet(final String edmEntitySetName) throws ODataJPAModelException { if (edmContainer == null) { lazyBuildEdmItem(); } return (IntermediateEntitySet) findModelElementByEdmItem(edmEntitySetName, entitySetListInternalKey); } IntermediateSingleton getSingleton(final String edmSingletonName) throws ODataJPAModelException { if (edmContainer == null) { lazyBuildEdmItem(); } return (IntermediateSingleton) findModelElementByEdmItem(edmSingletonName, singletonListInternalKey); } /** * Internal Entity Type * @param entityType * @return * @throws ODataJPAModelException */ JPAEntitySet getEntitySet(final JPAEntityType entityType) throws ODataJPAModelException { if (edmContainer == null) { lazyBuildEdmItem(); } for (final Entry<String, IntermediateEntitySet> entitySet : entitySetListInternalKey.entrySet()) { if (entitySet.getValue().getEntityType().getExternalFQN().equals(entityType.getExternalFQN())) { return entitySet.getValue(); } } return null; } /** * Entity Sets are described in <a href= * "https://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406398024" * >OData Version 4.0 Part 3 - 13.2 Element edm:EntitySet</a> * @param Entity Type * @return Entity Set */ private List<CsdlEntitySet> buildEntitySets() throws ODataJPAModelException { for (final Entry<String, IntermediateSchema> schema : schemaList.entrySet()) { for (final IntermediateEntityType<?> et : schema.getValue().getEntityTypes()) { if ((!et.ignore() || et.asTopLevelOnly()) && et.asEntitySet()) { final IntermediateEntitySet es = new IntermediateEntitySet(nameBuilder, et, getAnnotationInformation()); entitySetListInternalKey.put(es.internalName, es); } } } return extractEdmModelElements(entitySetListInternalKey); } /** * * @return List of Singletons * @throws ODataJPAModelException */ private List<CsdlSingleton> buildSingletons() throws ODataJPAModelException { for (final Entry<String, IntermediateSchema> schema : schemaList.entrySet()) { for (final IntermediateEntityType<?> et : schema.getValue().getEntityTypes()) { if ((!et.ignore() || et.asTopLevelOnly()) && et.asSingleton()) { final IntermediateSingleton singleton = new IntermediateSingleton(nameBuilder, et, getAnnotationInformation()); singletonListInternalKey.put(singleton.internalName, singleton); } } } return extractEdmModelElements(singletonListInternalKey); } /** * Creates the FunctionImports. Function Imports have to be created for <i>unbound</i> functions. These are functions, * which do not depend on an entity set. E.g. .../MyFunction(). * <p> * Details are described in : <a href= * "https://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406398042" * >OData Version 4.0 Part 3 - 13.6 Element edm:FunctionImport</a> * @param CsdlFunction edmFu */ private CsdlFunctionImport buildFunctionImport(final CsdlFunction edmFunction) { final CsdlFunctionImport edmFunctionImport = new CsdlFunctionImport(); edmFunctionImport.setName(edmFunction.getName()); edmFunctionImport.setFunction(buildFQN(edmFunction.getName())); edmFunctionImport.setIncludeInServiceDocument(true); // edmFuImport.setEntitySet(entitySet) return edmFunctionImport; } private List<CsdlFunctionImport> buildFunctionImports() throws ODataJPAModelException { final List<CsdlFunctionImport> edmFunctionImports = new ArrayList<>(); for (final Entry<String, IntermediateSchema> namespace : schemaList.entrySet()) { // Build Entity Sets final IntermediateSchema schema = namespace.getValue(); final List<JPAFunction> functions = schema.getFunctions(); for (final JPAFunction jpaFu : functions) { if (!((IntermediateFunction) jpaFu).isBound() && ((IntermediateFunction) jpaFu).hasImport()) edmFunctionImports.add(buildFunctionImport(((IntermediateFunction) jpaFu).getEdmItem())); } } return edmFunctionImports; } private List<CsdlActionImport> buildActionImports() throws ODataJPAModelException { final List<CsdlActionImport> edmActionImports = new ArrayList<>(); for (final Entry<String, IntermediateSchema> namespace : schemaList.entrySet()) { // Build Entity Sets final IntermediateSchema schema = namespace.getValue(); final List<JPAAction> actions = schema.getActions(); for (final JPAAction jpaAc : actions) { if (((IntermediateJavaAction) jpaAc).hasImport()) edmActionImports.add(buildActionImport(((IntermediateJavaAction) jpaAc).getEdmItem())); } } return edmActionImports; } /** * Creates the ActionImports. Function Imports have to be created for <i>unbound</i> actions. These are actions, * which do not depend on an entity set. E.g. .../MyAction(). * <p> * Details are described in : <a href= * "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl- * complete.html#_Toc406398038">13.5 Element edm:ActionImport</a> * @param edmAction * @return */ private CsdlActionImport buildActionImport(final CsdlAction edmAction) { final CsdlActionImport edmActionImport = new CsdlActionImport(); edmActionImport.setName(edmAction.getName()); edmActionImport.setAction(buildFQN(edmAction.getName())); // edmAcImport.setEntitySet(entitySet) return edmActionImport; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateOperationFactory.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateOperationFactory.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Set; import org.reflections8.Reflections; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.metadata.core.edm.mapper.extension.ODataOperation; /** * * @author Oliver Grande * * @param <O> Type of operation */ interface IntermediateOperationFactory<O extends IntermediateOperation> { O createOperation(final JPAEdmNameBuilder nameBuilder, final IntermediateSchema schema, final Method method, final Object functionDescription) throws ODataJPAModelException; @SuppressWarnings("unchecked") default Map<String, O> createOperationMap(final JPAEdmNameBuilder nameBuilder, final Reflections reflections, final IntermediateSchema schema, final Class<? extends ODataOperation> clazz, final Class<? extends Annotation> annotation) throws ODataJPAModelException { final Map<String, O> operations = new HashMap<>(); if (reflections != null) { final Set<?> operationClasses = findJavaOperations(reflections, clazz); for (final Object operationClass : operationClasses) { processOneClass(nameBuilder, schema, annotation, operations, (Class<? extends ODataOperation>) operationClass); } } return operations; } default <T extends ODataOperation> Set<Class<? extends T>> findJavaOperations(final Reflections reflections, final Class<T> clazz) { return reflections.getSubTypesOf(clazz); } private void processOneClass(final JPAEdmNameBuilder nameBuilder, final IntermediateSchema schema, final Class<? extends Annotation> annotation, final Map<String, O> operations, final Class<? extends ODataOperation> operationClass) throws ODataJPAModelException { for (final Method m : Arrays.asList(operationClass.getMethods())) { final Object operationDescription = m.getAnnotation(annotation); if (operationDescription != null) { final O operation = createOperation(nameBuilder, schema, m, operationDescription); operations.put(operation.getInternalName(), operation); } } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateInheritanceInformationJoinTable.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateInheritanceInformationJoinTable.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import java.util.List; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAInheritanceInformation; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAInheritanceType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAOnConditionItem; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; class IntermediateInheritanceInformationJoinTable implements JPAInheritanceInformation { private final List<JPAOnConditionItem> joinColumns; IntermediateInheritanceInformationJoinTable(List<JPAOnConditionItem> joinColumns) { this.joinColumns = joinColumns; } @Override public JPAInheritanceType getInheritanceType() { return JPAInheritanceType.JOIN_TABLE; } @Override public List<JPAOnConditionItem> getJoinColumnsList() throws ODataJPAModelException { return joinColumns; } @Override public List<JPAOnConditionItem> getReversedJoinColumnsList() throws ODataJPAModelException { return joinColumns.stream().map(this::invertColumns).toList(); } private JPAOnConditionItem invertColumns(JPAOnConditionItem jpaColumn) { return new JPAOnConditionItemImpl(jpaColumn.getRightPath(), jpaColumn.getLeftPath()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateEntityType.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateEntityType.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import static java.util.stream.Collectors.toMap; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.function.Function; import javax.annotation.Nonnull; import jakarta.persistence.DiscriminatorColumn; import jakarta.persistence.IdClass; import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.PrimaryKeyJoinColumn; import jakarta.persistence.PrimaryKeyJoinColumns; import jakarta.persistence.Table; import jakarta.persistence.metamodel.EmbeddableType; import jakarta.persistence.metamodel.EntityType; import jakarta.persistence.metamodel.IdentifiableType; import jakarta.persistence.metamodel.ManagedType; import jakarta.persistence.metamodel.MappedSuperclassType; import jakarta.persistence.metamodel.Type; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmItem; import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation; import org.apache.olingo.commons.api.edm.provider.CsdlEntityType; import org.apache.olingo.commons.api.edm.provider.CsdlProperty; import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlDynamicExpression; import org.apache.olingo.server.api.uri.UriResourceProperty; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmEntityType; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmQueryExtensionProvider; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTopLevelElementRepresentation; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.Applicability; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPACollectionAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEntityType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEtagValidator; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAInheritanceInformation; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAInheritanceType; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAOnConditionItem; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAQueryExtension; import com.sap.olingo.jpa.metadata.core.edm.mapper.cache.InstanceCache; import com.sap.olingo.jpa.metadata.core.edm.mapper.cache.InstanceCacheFunction; import com.sap.olingo.jpa.metadata.core.edm.mapper.cache.InstanceCacheSupplier; import com.sap.olingo.jpa.metadata.core.edm.mapper.cache.ListCacheSupplier; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelInternalException; import com.sap.olingo.jpa.metadata.core.edm.mapper.extension.IntermediateEntityTypeAccess; /** * <a href= * "https://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406397974" * >OData Version 4.0 Part 3 - 8 Entity Type</a> * * @param <T> Java type the entity type base on. * @author Oliver Grande * */ final class IntermediateEntityType<T> extends IntermediateStructuredType<T> implements JPAEntityType, IntermediateEntityTypeAccess { private static final Log LOGGER = LogFactory.getLog(IntermediateEntityType.class); private Optional<JPAPath> etagPath; private Optional<JPAEtagValidator> etagValidator; private final InstanceCache<JPAQueryExtension<EdmQueryExtensionProvider>> extensionQueryProvider; private final ListCacheSupplier<JPAAttribute> keyAttributes; private final ListCacheSupplier<String> userGroups; private final InstanceCache<IntermediateStructuredType<? super T>> baseType; private final boolean asTopLevelOnly; private final boolean asEntitySet; private final boolean asSingleton; private final InstanceCache<JPAInheritanceInformation> inheritanceType; IntermediateEntityType(final JPAEdmNameBuilder nameBuilder, final EntityType<T> et, final IntermediateSchema schema) { super(nameBuilder, et, schema); this.setExternalName(nameBuilder.buildEntityTypeName(et)); asTopLevelOnly = determineAsTopLevelOnly(); asEntitySet = determineAsEntitySet(); asSingleton = determineAsSingleton(); etagPath = Optional.empty(); extensionQueryProvider = new InstanceCacheSupplier<>(this::determineExtensionQueryProvide); baseType = new InstanceCacheSupplier<>(this::determineBaseType); inheritanceType = new InstanceCacheSupplier<>(this::determineInheritanceInformation); keyAttributes = new ListCacheSupplier<>(this::buildKeyAttributes); userGroups = new ListCacheSupplier<>(this::determineUserGroups); } private IntermediateEntityType(IntermediateEntityType<T> source, List<String> requesterUserGroups) throws ODataJPAModelException { // Navigations in complex properties need to be restricted as well super(source, requesterUserGroups); this.setExternalName(source.getExternalName()); asTopLevelOnly = source.asTopLevelOnly; asEntitySet = source.asEntitySet; asSingleton = source.asSingleton; etagPath = source.etagPath; extensionQueryProvider = source.extensionQueryProvider; userGroups = source.userGroups; baseType = new InstanceCacheFunction<>(this::baseTypeRestricted, source.getBaseType(), requesterUserGroups); inheritanceType = source.inheritanceType; etagPath = source.etagPath; etagValidator = source.etagValidator; keyAttributes = new ListCacheSupplier<>(this::buildKeyAttributes); } @Override public void addAnnotations(final List<CsdlAnnotation> annotations) { this.edmAnnotations.addAll(annotations); } @Override public CsdlAnnotation getAnnotation(final String alias, final String term) throws ODataJPAModelException { getEdmItem(); return filterAnnotation(alias, term); } @Override public Object getAnnotationValue(final String alias, final String term, final String property) throws ODataJPAModelException { try { return Optional.ofNullable(getAnnotation(alias, term)) .map(CsdlAnnotation::getExpression) .map(expression -> getAnnotationValue(property, expression)) .orElse(null); } catch (final ODataJPAModelInternalException e) { throw (ODataJPAModelException) e.getCause(); } } @Override protected Object getAnnotationDynamicValue(final String property, final CsdlDynamicExpression expression) throws ODataJPAModelInternalException { try { if (expression.isRecord()) { // This may create a problem if the property in question is a record itself. Currently non is supported in // standard final var propertyValue = findAnnotationPropertyValue(property, expression); if (propertyValue.isPresent()) { return getAnnotationValue(property, propertyValue.get()); } } else if (expression.isCollection()) { return getAnnotationCollectionValue(expression); } else if (expression.isPropertyPath()) { return getPath(expression.asPropertyPath().getValue()); } else if (expression.isNavigationPropertyPath()) { return getAssociationPath(expression.asNavigationPropertyPath().getValue()); } return null; } catch (final ODataJPAModelException e) { throw new ODataJPAModelInternalException(e); } } @Override public Optional<JPAAttribute> getAttribute(final String internalName) throws ODataJPAModelException { final var a = super.getAttribute(internalName); if (a.isPresent()) return a; return getKey(internalName); } @Override public Optional<JPAAttribute> getAttribute(final UriResourceProperty uriResourceItem) throws ODataJPAModelException { final var a = super.getAttribute(uriResourceItem); if (a.isPresent()) return a; return getKey(uriResourceItem); } @Override public JPACollectionAttribute getCollectionAttribute(final String externalName) throws ODataJPAModelException { final var path = getPath(externalName); if (path != null && path.getLeaf() instanceof final JPACollectionAttribute collectionAttribute) return collectionAttribute; return null; } @Override public String getContentType() throws ODataJPAModelException { return getStreamProperty() .map(IntermediateSimpleProperty::getContentType) .orElse(""); } @Override public JPAPath getContentTypeAttributePath() throws ODataJPAModelException { final var propertyInternalName = getStreamProperty() .map(IntermediateSimpleProperty::getContentTypeProperty) .orElse(""); if (propertyInternalName == null || propertyInternalName.isEmpty()) { return null; } // Ensure that Ignore is ignored return getPathByDBField(getProperty(propertyInternalName).getDBFieldName()); } @Override public Optional<JPAAttribute> getDeclaredAttribute(@Nonnull final String internalName) throws ODataJPAModelException { final var a = super.getDeclaredAttribute(internalName); if (a.isPresent()) return a; return getKey(internalName); } @Override public JPAPath getEtagPath() throws ODataJPAModelException { if (hasEtag() && etagPath.isPresent()) return etagPath.get(); return null; } @Override public JPAEtagValidator getEtagValidator() throws ODataJPAModelException { if (hasEtag()) return etagValidator.orElse(null); return null; } @Override public List<JPAAttribute> getKey() throws ODataJPAModelException { return keyAttributes.get(); } private List<JPAAttribute> buildKeyAttributes() { final List<JPAAttribute> intermediateKey = new ArrayList<>(); // Cycle break try { buildCompletePropertyMap(); addKeyAttribute(intermediateKey, Arrays.asList(this.getTypeClass().getDeclaredFields())); addKeyAttribute(intermediateKey, mappedSuperclass.stream() .map(ManagedType::getJavaType) .map(Class::getDeclaredFields) .flatMap(Arrays::stream) .toList()); final IntermediateStructuredType<? super T> type = getBaseType(); if (type != null) { intermediateKey.addAll(((IntermediateEntityType<?>) type).getKey()); } return Collections.unmodifiableList(updateAttributeListDbFieldName(intermediateKey)); } catch (ODataJPAModelException e) { throw new ODataJPAModelInternalException(e); } } @Override List<JPAAttribute> getBaseTypeAttributes() throws ODataJPAModelException { final IntermediateStructuredType<? super T> superType = getBaseType(); if (superType != null) { final Map<String, PrimaryKeyJoinColumn> mappings = getPrimaryKeyJoinColumns(); final List<JPAAttribute> result = new ArrayList<>(); for (var attribute : superType.getAttributes()) { result.add(updateAttributeDbFieldName(mappings, attribute)); } return result; } return List.of(); } private final JPAAttribute updateAttributeDbFieldName(final Map<String, PrimaryKeyJoinColumn> mappings, JPAAttribute attribute) throws ODataJPAModelException { if (attribute instanceof IntermediateSimpleProperty property && mappings.containsKey(property.getDBFieldName())) { LOGGER.debug("Key mapping (PrimaryKeyJoinColumn) found for " + jpaJavaType.getSimpleName() + "#" + property .getInternalName()); final var targetDbName = mappings.get(property.getDBFieldName()).name(); if (targetDbName != null && !targetDbName.isBlank()) return new IntermediateSimpleProperty(property, mappings.get(property.getDBFieldName()).name()); else LOGGER.warn("Missing 'name' at annotation PrimaryKeyJoinColumn mapping found for " + jpaJavaType .getSimpleName() + "#" + property.getInternalName()); } return attribute; } private final List<JPAAttribute> updateAttributeListDbFieldName(List<JPAAttribute> intermediateKey) throws ODataJPAModelException { final Map<String, PrimaryKeyJoinColumn> mappings = getPrimaryKeyJoinColumns(); for (int i = 0; i < intermediateKey.size(); i++) { intermediateKey.set(i, updateAttributeDbFieldName(mappings, intermediateKey.get(i))); } return intermediateKey; } private final Map<String, PrimaryKeyJoinColumn> getPrimaryKeyJoinColumns() throws ODataJPAModelException { final Map<String, PrimaryKeyJoinColumn> mappings; if (this.jpaJavaType.getAnnotation(PrimaryKeyJoinColumn.class) != null) { final var mapping = this.jpaJavaType.getAnnotation(PrimaryKeyJoinColumn.class); final var referenceColumn = !mapping.referencedColumnName().isEmpty() ? mapping.referencedColumnName() : ((JPAEntityType) getBaseType()).getKeyPath().get(0).getDBFieldName(); mappings = Map.of(referenceColumn, this.jpaJavaType.getAnnotation(PrimaryKeyJoinColumn.class)); } else if (jpaJavaType.getAnnotation(PrimaryKeyJoinColumns.class) != null) mappings = Arrays.asList(this.jpaJavaType.getAnnotation(PrimaryKeyJoinColumns.class).value()) .stream() .collect(toMap(PrimaryKeyJoinColumn::referencedColumnName, Function.identity())); else mappings = Map.of(); return mappings; } @Override public List<JPAPath> getKeyPath() throws ODataJPAModelException { final List<JPAPath> result = new ArrayList<>(); for (final Entry<String, IntermediateProperty> property : this.getDeclaredPropertiesMap().entrySet()) { final JPAAttribute attribute = property.getValue(); if (attribute instanceof IntermediateEmbeddedIdProperty) { result.add(getIntermediatePathMap().get(attribute.getExternalName())); } else if (attribute.isKey()) { result.add(getResolvedPathMap().get(attribute.getExternalName())); } } final IntermediateStructuredType<?> type = getBaseType(); if (type != null) { result.addAll(updatePathListDbFieldName(((IntermediateEntityType<?>) type).getKeyPath())); } return Collections.unmodifiableList(result); } private List<JPAPath> updatePathListDbFieldName(List<JPAPath> keyPath) throws ODataJPAModelException { final Map<String, PrimaryKeyJoinColumn> mappings = getPrimaryKeyJoinColumns(); final List<JPAPath> result = new ArrayList<>(); for (int i = 0; i < keyPath.size(); i++) { final var path = keyPath.get(i); result.add(updatePathDbFieldName(mappings, path)); } return result; } private final JPAPath updatePathDbFieldName(final Map<String, PrimaryKeyJoinColumn> mappings, final JPAPath path) throws ODataJPAModelException { if (mappings.containsKey(path.getDBFieldName())) { LOGGER.debug("Key mapping (PrimaryKeyJoinColumn) found for " + jpaJavaType.getSimpleName() + "#" + path .getLeaf().getInternalName()); final var targetDbName = mappings.get(path.getDBFieldName()).name(); if (targetDbName != null && !targetDbName.isBlank()) { return new JPAPathImpl(path.getAlias(), mappings.get(path.getDBFieldName()).name(), path.getPath()); } else LOGGER.warn("Missing 'name' at annotation PrimaryKeyJoinColumn mapping found for " + jpaJavaType .getSimpleName() + "#" + path.getLeaf().getInternalName()); } return path; } @Override protected Map<String, JPAPath> getBaseTypeResolvedPathMap() throws ODataJPAModelException { final IntermediateStructuredType<? super T> superType = getBaseType(); if (superType != null) { final Map<String, PrimaryKeyJoinColumn> mappings = getPrimaryKeyJoinColumns(); final Map<String, JPAPath> result = new HashMap<>(); for (var path : superType.getResolvedPathMap().entrySet()) { result.put(path.getKey(), updatePathDbFieldName(mappings, path.getValue())); } return result; } return Map.of(); } @Override public Class<?> getKeyType() { if (jpaManagedType instanceof IdentifiableType<?>) { Class<?> idClass = null; final Type<?> idType = ((IdentifiableType<?>) jpaManagedType).getIdType(); if (idType == null) // Hibernate does not return an IdType in case of compound key that do not use // EmbeddableId. So fallback to hand made evaluation idClass = jpaManagedType.getJavaType().getAnnotation(IdClass.class).value(); else idClass = idType.getJavaType(); return idClass; } else { return null; } } @Override public Optional<JPAQueryExtension<EdmQueryExtensionProvider>> getQueryExtension() throws ODataJPAModelException { return extensionQueryProvider.get(); } @Override public List<JPAPath> getSearchablePath() throws ODataJPAModelException { final var allPath = getPathList(); final List<JPAPath> searchablePath = new ArrayList<>(); for (final JPAPath p : allPath) { if (p.getLeaf().isSearchable()) searchablePath.add(p); } return searchablePath; } @Override public JPAPath getStreamAttributePath() throws ODataJPAModelException { var externalName = getStreamProperty() .map(IntermediateSimpleProperty::getExternalName) .orElse(null); return externalName == null ? null : getPath(externalName); } @Override public String getTableName() { try { final AnnotatedElement a = jpaManagedType.getJavaType(); Table table = null; if (a != null) table = a.getAnnotation(Table.class); final IntermediateStructuredType<?> type = getBaseType(); if (table == null && type != null) return ((IntermediateEntityType<?>) type).getTableName(); return (table == null) ? jpaManagedType.getJavaType().getSimpleName().toUpperCase(Locale.ENGLISH) : buildFQTableName(table.schema(), table.name()); } catch (ODataJPAModelException e) { throw new IllegalStateException(e); } } @Override public boolean hasCompoundKey() { final Type<?> idType = ((IdentifiableType<?>) jpaManagedType).getIdType(); return jpaManagedType.getJavaType().getAnnotation(IdClass.class) != null || idType instanceof EmbeddableType; } @Override public boolean hasEmbeddedKey() { return ((IdentifiableType<?>) jpaManagedType).hasSingleIdAttribute() && hasCompoundKey(); } @Override public boolean hasEtag() throws ODataJPAModelException { getEdmItem(); return etagPath.isPresent(); } @Override public boolean hasStream() throws ODataJPAModelException { getEdmItem(); return this.determineHasStream(); } @Override public boolean ignore() { return (asTopLevelOnly || super.ignore()); } @Override public boolean isAbstract() { return determineAbstract(); } @Override public List<String> getUserGroups() throws ODataJPAModelException { return userGroups.get(); } @Override public IntermediateStructuredType<? super T> getBaseType() throws ODataJPAModelException { // NOSONAR return baseType.get().orElse(null); } @Override public JPAInheritanceInformation getInheritanceInformation() throws ODataJPAModelException { return inheritanceType.get().orElse(new NoInheritance()); } /** * Determines if the structured type has a super type that will be part of OData metadata. That is, the method will * return null in case the entity has a MappedSuperclass. * @return Determined super type or null */ private IntermediateStructuredType<? super T> determineBaseType() { // NOSONAR final Class<?> superType = jpaManagedType.getJavaType().getSuperclass(); if (superType != null) { @SuppressWarnings("unchecked") final IntermediateStructuredType<? super T> baseEntity = (IntermediateStructuredType<? super T>) schema .getEntityType(superType); if (baseEntity != null) return baseEntity; } return null; } private JPAInheritanceInformation determineInheritanceInformation() { final Class<?> superType = jpaManagedType.getJavaType().getSuperclass(); if (superType != Object.class) { @SuppressWarnings("unchecked") final IntermediateEntityType<? super T> baseEntity = (IntermediateEntityType<? super T>) schema .getEntityType(superType); Objects.requireNonNull(baseEntity); try { return copyInheritanceInfo(baseEntity); } catch (ODataJPAModelException e) { throw new ODataJPAModelInternalException(e); } } else { return determineInheritanceType(jpaManagedType.getJavaType()); } } private JPAInheritanceInformation determineInheritanceType(Class<?> clazz) { var inheritance = clazz.getAnnotation(Inheritance.class); if (inheritance != null && inheritance.strategy() == InheritanceType.JOINED) { return new IntermediateInheritanceInformationJoinTable(List.of()); } var discriminator = clazz.getAnnotation(DiscriminatorColumn.class); if (discriminator != null) return new IntermediateInheritanceInformationSingleTable(); return new NoInheritance(); } private JPAInheritanceInformation copyInheritanceInfo(JPAEntityType baseEntity) throws ODataJPAModelException { var inheritanceInfo = baseEntity.getInheritanceInformation(); return inheritanceInfo.getInheritanceType() == JPAInheritanceType.JOIN_TABLE ? new IntermediateInheritanceInformationJoinTable(buildInheritanceJoinColumns(baseEntity)) : inheritanceInfo; } private List<JPAOnConditionItem> buildInheritanceJoinColumns(JPAEntityType baseEntity) throws ODataJPAModelException { final Map<String, PrimaryKeyJoinColumn> mappings = getPrimaryKeyJoinColumns(); final Map<String, JPAPath> subKeyPath = getKeyPath().stream().collect(toMap(JPAPath::getDBFieldName, Function .identity())); final List<JPAOnConditionItem> result = new ArrayList<>(); for (var superPath : baseEntity.getKeyPath()) { if (mappings.containsKey(superPath.getDBFieldName())) { var subDbFieldName = mappings.get(superPath.getDBFieldName()).name(); result.add(new JPAOnConditionItemImpl(subKeyPath.get(subDbFieldName), superPath)); } else { result.add(new JPAOnConditionItemImpl(subKeyPath.get(superPath.getDBFieldName()), superPath)); } } return result; } @SuppressWarnings("unchecked") @Override protected <I extends CsdlAbstractEdmItem> List<I> extractEdmModelElements( final Map<?, ? extends IntermediateModelElement> mappingBuffer) throws ODataJPAModelException { final List<I> extractionTarget = new ArrayList<>(); for (final IntermediateModelElement element : mappingBuffer.values()) { if (!element.ignore() // Skip Streams && !(element instanceof final IntermediateSimpleProperty simpleProperty && simpleProperty.isStream())) { if (element instanceof final IntermediateEmbeddedIdProperty embeddedId) { extractionTarget.addAll((Collection<? extends I>) resolveEmbeddedId(embeddedId)); } else { extractionTarget.add((I) element.getEdmItem()); } } } return returnNullIfEmpty(extractionTarget); } @SuppressWarnings("unchecked") @Override protected <X extends IntermediateModelElement> X asUserGroupRestricted(List<String> userGroups) throws ODataJPAModelException { return (X) new IntermediateEntityType<>(this, userGroups); } @Override protected void lazyBuildEdmItem() throws ODataJPAModelException { getEdmItem(); } @Override synchronized CsdlEntityType buildEdmItem() { try { var edmEntityType = createEdmItem(); postProcessingBuildEdmItem(); checkPropertyConsistency(); return edmEntityType; } catch (ODataJPAModelException e) { throw new ODataJPAModelInternalException(e); } } @Override protected synchronized Map<String, IntermediateProperty> buildCompletePropertyMap() { try { Map<String, IntermediateProperty> result = new HashMap<>(); result.putAll(buildPropertyList()); result.putAll(addDescriptionProperty()); result.putAll(addTransientProperties()); result.putAll(addVirtualProperties(result)); return result; } catch (ODataJPAModelException e) { throw new ODataJPAModelInternalException(e); } } private CsdlEntityType createEdmItem() throws ODataJPAModelException { var edmEntityType = new CsdlEntityType(); determineHasEtag(); edmEntityType.setName(getExternalName()); edmEntityType.setProperties(extractEdmModelElements(getDeclaredPropertiesMap())); edmEntityType.setNavigationProperties(extractEdmModelElements(getDeclaredNavigationPropertiesMap())); edmEntityType.setKey(extractEdmKeyElements()); edmEntityType.setAbstract(determineAbstract()); edmEntityType.setBaseType(determineBaseTypeFqn()); edmEntityType.setHasStream(determineHasStream()); edmEntityType.setAnnotations(determineAnnotations()); return edmEntityType; } private void postProcessingBuildEdmItem() { determineExtensionQueryProvide(); postProcessor.processEntityType(this); retrieveAnnotations(this, Applicability.ENTITY_TYPE); } /** * The top level representation of this entity type is entity set. * @return */ boolean asEntitySet() { return asEntitySet; } boolean asSingleton() { return asSingleton; } /** * This entity type represents only an entity set and not a entity type itself, but an alternative way to access the * superordinate entity type. See: {@link EdmAsEntitySet} * @return */ boolean asTopLevelOnly() { return asTopLevelOnly; } /** * * @param dbCatalog * @param dbSchema * @param dbTableName * @return * @throws ODataJPAModelException */ boolean dbEquals(final String dbCatalog, final String dbSchema, @Nonnull final String dbTableName) { final AnnotatedElement a = jpaManagedType.getJavaType(); Table table = null; if (a != null) table = a.getAnnotation(Table.class); if (table == null) { if (dbSchema != null && !dbSchema.isEmpty()) { return getTableName().equals(buildFQTableName(dbSchema, dbTableName)); } else { return (dbCatalog == null || dbCatalog.isEmpty()) && (dbSchema == null || dbSchema.isEmpty()) && dbTableName.equals(getTableName()); } } else return table.catalog().equals(dbCatalog) && table.schema().equals(dbSchema) && table.name().equals(dbTableName); } boolean determineAbstract() { final var modifiers = jpaManagedType.getJavaType().getModifiers(); return Modifier.isAbstract(modifiers); } /** * Creates the key of an entity. In case the POJO is declared with an embedded ID the key fields get resolved, so that * they occur as separate properties within the metadata document * * @param propertyList * @return * @throws ODataJPAModelException */ List<CsdlPropertyRef> extractEdmKeyElements() throws ODataJPAModelException { return getKey().stream() .map(this::asPropertyRef) .toList(); } @Override CsdlEntityType getEdmItem() throws ODataJPAModelException { return (CsdlEntityType) super.getEdmItem(); } List<MappedSuperclassType<? super T>> getMappedSuperType() { return mappedSuperclass; } private void addKeyAttribute(final List<JPAAttribute> intermediateKey, final List<Field> keyFields) throws ODataJPAModelException { for (final Field candidate : keyFields) { final JPAAttribute attribute = this.getDeclaredPropertiesMap().get(candidate.getName()); if (attribute != null && attribute.isKey()) { if (attribute.isComplex()) { intermediateKey.addAll(buildEmbeddedIdKey(attribute)); } else { intermediateKey.add(attribute); } } } } private CsdlPropertyRef asPropertyRef(final JPAAttribute idAttribute) { // TODO setAlias final var keyElement = new CsdlPropertyRef(); keyElement.setName(idAttribute.getExternalName()); return keyElement; } private List<JPAAttribute> buildEmbeddedIdKey(final JPAAttribute attribute) throws ODataJPAModelException { final var id = ((IntermediateEmbeddedIdProperty) attribute).getStructuredType(); final List<JPAAttribute> keyElements = new ArrayList<>(id.getTypeClass().getDeclaredFields().length); final var keyFields = id.getTypeClass().getDeclaredFields(); for (var i = 0; i < keyFields.length; i++) { id.getAttribute(keyFields[i].getName()).ifPresent(keyElements::add); } return keyElements; } private List<CsdlAnnotation> determineAnnotations() throws ODataJPAModelException { getAnnotations(edmAnnotations, this.jpaManagedType.getJavaType(), internalName); return edmAnnotations; } private boolean determineAsEntitySet() { final Optional<EdmEntityType> jpaEntityType = getAnnotation(jpaJavaType, EdmEntityType.class); return !jpaEntityType.isPresent() || jpaEntityType.get().as() == EdmTopLevelElementRepresentation.AS_ENTITY_SET || jpaEntityType.get().as() == EdmTopLevelElementRepresentation.AS_ENTITY_SET_ONLY; } private boolean determineAsSingleton() { final var jpaEntityType = this.jpaManagedType.getJavaType().getAnnotation(EdmEntityType.class); return jpaEntityType != null && (jpaEntityType.as() == EdmTopLevelElementRepresentation.AS_SINGLETON || jpaEntityType.as() == EdmTopLevelElementRepresentation.AS_SINGLETON_ONLY); } private boolean determineAsTopLevelOnly() { final Optional<EdmEntityType> jpaEntityType = getAnnotation(jpaJavaType, EdmEntityType.class); return (jpaEntityType.isPresent() && (jpaEntityType.get().as() == EdmTopLevelElementRepresentation.AS_ENTITY_SET_ONLY || jpaEntityType.get().as() == EdmTopLevelElementRepresentation.AS_SINGLETON_ONLY)); } @SuppressWarnings("unchecked") private JPAQueryExtension<EdmQueryExtensionProvider> determineExtensionQueryProvide() { try { JPAQueryExtension<EdmQueryExtensionProvider> provider = null; final Optional<EdmEntityType> jpaEntityType = getAnnotation(jpaJavaType, EdmEntityType.class); if (jpaEntityType.isPresent()) { final var providerClass = (Class<EdmQueryExtensionProvider>) jpaEntityType .get().extensionProvider(); final Class<?> defaultProvider = EdmQueryExtensionProvider.class; if (providerClass != null && providerClass != defaultProvider) provider = new JPAQueryExtensionProvider<>(providerClass); } final IntermediateStructuredType<?> type = getBaseType(); if (provider == null && type != null) provider = ((IntermediateEntityType<?>) type).getQueryExtension().orElse(null); return provider; } catch (ODataJPAModelException e) { throw new ODataJPAModelInternalException(e); } } private void determineHasEtag() throws ODataJPAModelException { for (final Entry<String, IntermediateProperty> property : this.getDeclaredPropertiesMap().entrySet()) { if (property.getValue().isEtag()) { etagPath = Optional.of(getPath(property.getValue().getExternalName(), false)); etagValidator = Optional.of(Number.class.isAssignableFrom(property.getValue().getJavaType()) ? JPAEtagValidator.STRONG : JPAEtagValidator.WEAK); } } if (getBaseType() instanceof final IntermediateEntityType<?> baseEntityType) { etagPath = Optional.ofNullable(baseEntityType.getEtagPath()); etagValidator = Optional.ofNullable(baseEntityType.getEtagValidator()); } } private <A extends Annotation> Optional<A> getAnnotation(final Class<?> annotated, final Class<A> type) { return Optional.ofNullable(annotated.getAnnotation(type)); } private Optional<JPAAttribute> getKey(final String internalName) throws ODataJPAModelException { if (internalName == null) return Optional.empty(); for (final JPAAttribute attribute : getKey()) { if (internalName.equals(attribute.getInternalName()))
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
true
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateJavaAction.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateJavaAction.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.ACTION_PARAM_ANNOTATION_MISSING; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.ACTION_PARAM_BINDING_NOT_FOUND; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.ACTION_PARAM_ONLY_PRIMITIVE; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.ACTION_RETURN_TYPE_EXP; import static com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException.MessageKeys.ACTION_UNBOUND_ENTITY_SET; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.List; import javax.annotation.CheckForNull; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.geo.SRID; import org.apache.olingo.commons.api.edm.provider.CsdlAction; import org.apache.olingo.commons.api.edm.provider.CsdlMapping; import org.apache.olingo.commons.api.edm.provider.CsdlParameter; import org.apache.olingo.commons.api.edm.provider.CsdlReturnType; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmAction; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmFunction.ReturnType; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmParameter; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAction; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAOperationResultParameter; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAParameter; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; class IntermediateJavaAction extends IntermediateOperation implements JPAAction { private CsdlAction edmAction; final EdmAction jpaAction; private final IntermediateSchema schema; private final Method javaAction; private final Constructor<?> javaConstructor; private List<JPAParameter> parameterList; IntermediateJavaAction(final JPAEdmNameBuilder nameBuilder, final EdmAction jpaAction, final Method javaAction, final IntermediateSchema schema) throws ODataJPAModelException { super(nameBuilder, InternalNameBuilder.buildActionName(jpaAction).isEmpty() ? javaAction.getName() : InternalNameBuilder.buildActionName(jpaAction), schema.getAnnotationInformation()); this.schema = schema; this.jpaAction = jpaAction; this.setExternalName(nameBuilder.buildOperationName(internalName)); this.javaAction = javaAction; this.javaConstructor = IntermediateOperationHelper.determineConstructor(javaAction); } @SuppressWarnings("unchecked") @Override public <T> Constructor<T> getConstructor() { return (Constructor<T>) javaConstructor; } @Override public Method getMethod() { return javaAction; } public List<JPAParameter> getParameter() throws ODataJPAModelException { if (parameterList == null) { parameterList = new ArrayList<>(); final Class<?>[] types = javaAction.getParameterTypes(); final Parameter[] declaredParameters = javaAction.getParameters(); for (int i = 0; i < declaredParameters.length; i++) { final Parameter declaredParameter = declaredParameters[i]; final EdmParameter definedParameter = declaredParameter.getAnnotation(EdmParameter.class); if (definedParameter == null) // Function parameter %1$s of method %2$s at class %3$s without required annotation throw new ODataJPAModelException(ACTION_PARAM_ANNOTATION_MISSING, declaredParameter.getName(), javaAction.getName(), javaAction .getDeclaringClass().getName()); if (definedParameter.name().isEmpty()) // Fallback not possible. Reflection does not contain parameter name, just returns e.g. arg1 // Name of parameter required. Name missing at function '%1$s' in class '%2$s'. throw new ODataJPAModelException(ODataJPAModelException.MessageKeys.FUNC_PARAM_NAME_REQUIRED, javaAction.getName(), javaAction.getDeclaringClass().getName()); final JPAParameter parameter = new IntermediateOperationParameter( nameBuilder, definedParameter, nameBuilder.buildPropertyName(definedParameter.name()), declaredParameter.getName(), types[i], getAnnotationInformation()); parameterList.add(parameter); } } return parameterList; } @Override @CheckForNull public JPAParameter getParameter(final Parameter declaredParameter) throws ODataJPAModelException { for (final JPAParameter param : getParameter()) { if (param.getInternalName().equals(declaredParameter.getName())) return param; } return null; } @Override public JPAOperationResultParameter getResultParameter() { return new IntermediateOperationResultParameter(this, jpaAction.returnType(), javaAction.getReturnType(), IntermediateOperationHelper.isCollection(javaAction.getReturnType())); } @Override public CsdlReturnType getReturnType() { return edmAction.getReturnType(); } protected List<CsdlParameter> determineEdmInputParameter() throws ODataJPAModelException { final List<CsdlParameter> parameters = new ArrayList<>(); final List<JPAParameter> jpaParameterList = getParameter(); final BindingPosition bindingPosition = new BindingPosition(); for (int i = 0; i < jpaParameterList.size(); i++) { final JPAParameter jpaParameter = jpaParameterList.get(i); final CsdlParameter parameter = new CsdlParameter(); parameter.setName(jpaParameter.getName()); parameter.setType(determineParameterType(bindingPosition, i, jpaParameter)); parameter.setPrecision(nullIfNotSet(jpaParameter.getPrecision())); parameter.setScale(nullIfNotSet(jpaParameter.getScale())); parameter.setMaxLength(nullIfNotSet(jpaParameter.getMaxLength())); parameter.setSrid(jpaParameter.getSrid()); parameter.setMapping(new CsdlMapping() .setInternalName(getInternalName()) .setMappedJavaClass(jpaParameter.getType())); parameters.add(parameter); } if (jpaAction.isBound() && bindingPosition.getPosition() != 1) // Binding parameter not found within in interface of method %1$s of class %2$s. Binding parameter must be the // first parameter. throw new ODataJPAModelException(ACTION_PARAM_BINDING_NOT_FOUND, javaAction.getName(), javaAction.getDeclaringClass().getName()); return parameters; } private FullQualifiedName determineParameterType(final BindingPosition bindingPosition, final int i, final JPAParameter jpaParameter) throws ODataJPAModelException { final EdmPrimitiveTypeKind edmType = JPATypeConverter.convertToEdmSimpleType(jpaParameter.getType()); if (edmType != null) return edmType.getFullQualifiedName(); final IntermediateEnumerationType enumType = schema.getEnumerationType(jpaParameter.getType()); if (enumType != null) { return enumType.getExternalFQN(); } else { final IntermediateStructuredType<?> structuredType = schema.getEntityType(jpaParameter.getType()); if (structuredType != null) { if (bindingPosition.getPosition() == 0) bindingPosition.setPosition(i + 1); return structuredType.getExternalFQN(); } else { // The type of %1$s of action of method %2$s of class %1$s could not be converted throw new ODataJPAModelException(ACTION_PARAM_ONLY_PRIMITIVE, jpaParameter.getInternalName(), javaAction.getName(), javaAction.getDeclaringClass().getName()); } } } @Override protected boolean hasImport() { // 13.5 Element edm:ActionImport: // The edm:ActionImport element allows exposing an unbound action as a top-level element in an entity container. // Action imports are never advertised in the service document. return !jpaAction.isBound(); } @Override protected synchronized void lazyBuildEdmItem() throws ODataJPAModelException { if (edmAction == null) { // TODO handle annotations edmAction = new CsdlAction(); edmAction.setBound(jpaAction.isBound()); edmAction.setName(getExternalName()); edmAction.setParameters(returnNullIfEmpty(determineEdmInputParameter())); edmAction.setReturnType(determineEdmResultType(jpaAction.returnType(), javaAction)); edmAction.setEntitySetPath(setEntitySetPath()); determineUserGroups(this.jpaAction.visibleFor()); } } @Override CsdlAction getEdmItem() throws ODataJPAModelException { if (edmAction == null) { lazyBuildEdmItem(); } return edmAction; } @Override boolean isBound() throws ODataJPAModelException { return getEdmItem().isBound(); } private CsdlReturnType determineEdmResultType(final ReturnType definedReturnType, final Method javaOperation) throws ODataJPAModelException { final Class<?> declaredReturnType = javaOperation.getReturnType(); if (declaredReturnType == void.class) return null; final CsdlReturnType edmResultType = new CsdlReturnType(); if (IntermediateOperationHelper.isCollection(declaredReturnType)) { if (definedReturnType.type() == Object.class) // Type parameter expected for %1$s throw new ODataJPAModelException(ACTION_RETURN_TYPE_EXP, javaOperation.getName(), javaOperation .getName()); edmResultType.setCollection(true); edmResultType.setType(IntermediateOperationHelper.determineReturnType(definedReturnType, definedReturnType.type(), schema, javaOperation.getName())); } else { edmResultType.setCollection(false); edmResultType.setType(IntermediateOperationHelper.determineReturnType(definedReturnType, declaredReturnType, schema, javaOperation.getName())); } edmResultType.setNullable(definedReturnType.isNullable()); edmResultType.setPrecision(nullIfNotSet(definedReturnType.precision())); edmResultType.setScale(nullIfNotSet(definedReturnType.scale())); edmResultType.setMaxLength(nullIfNotSet(definedReturnType.maxLength())); if (definedReturnType.srid() != null && !definedReturnType.srid().srid().isEmpty()) { final SRID srid = SRID.valueOf(definedReturnType.srid().srid()); srid.setDimension(definedReturnType.srid().dimension()); edmResultType.setSrid(srid); } return edmResultType; } private String setEntitySetPath() throws ODataJPAModelException { if (jpaAction.entitySetPath() == null || jpaAction.entitySetPath().isEmpty()) return null; if (!jpaAction.isBound()) // Entity Set Path shall only provided for bound actions. Action method %1$s of class %2$s is unbound. throw new ODataJPAModelException(ACTION_UNBOUND_ENTITY_SET, javaAction.getName(), javaAction.getDeclaringClass().getName()); if (schema.getEntityType(javaAction.getReturnType()) == null) throw new ODataJPAModelException(ACTION_UNBOUND_ENTITY_SET, javaAction.getName(), javaAction.getDeclaringClass().getName()); return jpaAction.entitySetPath(); } private static class BindingPosition { private Integer position = 0; Integer getPosition() { return position; } void setPosition(final Integer position) { this.position = position; } } @Override public String toString() { return "IntermediateJavaAction [jpaAction=" + jpaAction.name() + ", javaAction=" + javaAction .getName() + ", javaConstructor=" + javaConstructor.getName() + ", parameterList=" + parameterList + "]"; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateJoinColumn.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/impl/IntermediateJoinColumn.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.impl; import jakarta.persistence.JoinColumn; import com.sap.olingo.jpa.metadata.api.JPAJoinColumn; final class IntermediateJoinColumn implements JPAJoinColumn { private String name; private String referencedColumnName; IntermediateJoinColumn(final JoinColumn jpaJoinColumn) { super(); this.name = jpaJoinColumn.name(); this.referencedColumnName = jpaJoinColumn.referencedColumnName(); } IntermediateJoinColumn(final String name, final String referencedColumnName) { super(); this.name = name; this.referencedColumnName = referencedColumnName; } @Override public String getName() { return name; } public void setName(final String name) { this.name = name; } @Override public String getReferencedColumnName() { return referencedColumnName; } public void setReferencedColumnName(final String referencedColumnName) { this.referencedColumnName = referencedColumnName; } @Override public String toString() { return "IntermediateJoinColumn [name=" + name + ", referencedColumnName=" + referencedColumnName + "]"; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAssociationPath.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAssociationPath.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import javax.annotation.CheckForNull; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.ODataNavigationPath; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAAssociationPath extends ODataNavigationPath { String getAlias(); /** * Only available if a Join Table was used * @return * @throws ODataJPAModelException */ List<JPAPath> getInverseLeftJoinColumnsList() throws ODataJPAModelException; List<JPAOnConditionItem> getJoinColumnsList() throws ODataJPAModelException; /** * Check with {@link JPAAssociationPath#hasJoinTable()} if an join table exists * @return the join table representation if present */ JPAJoinTable getJoinTable(); JPAAssociationAttribute getLeaf(); /** * * @return * @throws ODataJPAModelException */ List<JPAPath> getLeftColumnsList() throws ODataJPAModelException; @CheckForNull JPAAssociationAttribute getPartner(); List<JPAElement> getPath(); /** * * @return * @throws ODataJPAModelException */ List<JPAPath> getRightColumnsList() throws ODataJPAModelException; JPAStructuredType getSourceType(); JPAStructuredType getTargetType(); /** * @return True if the target entity is linked via a join table */ boolean hasJoinTable(); boolean isCollection(); List<JPAPath> getForeignKeyColumns() throws ODataJPAModelException; Cardinality cardinality(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAQueryExtension.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAQueryExtension.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.lang.reflect.Constructor; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmQueryExtensionProvider; public interface JPAQueryExtension<X extends EdmQueryExtensionProvider> { Constructor<X> getConstructor(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAServiceDocument.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAServiceDocument.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import java.util.Map; import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import org.apache.olingo.commons.api.edm.EdmAction; import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.commons.api.edm.EdmEnumType; import org.apache.olingo.commons.api.edm.EdmFunction; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer; import org.apache.olingo.commons.api.edm.provider.CsdlSchema; import org.apache.olingo.commons.api.edm.provider.CsdlTerm; import org.apache.olingo.commons.api.edmx.EdmxReference; import org.apache.olingo.server.api.etag.CustomETagSupport; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAServiceDocument extends CustomETagSupport { CsdlEntityContainer getEdmEntityContainer() throws ODataJPAModelException; List<CsdlSchema> getEdmSchemas() throws ODataJPAModelException; List<CsdlSchema> getAllSchemas() throws ODataJPAModelException; /** * Returns the internal representation of an entity type by Olingo entity type * @param edmType Olingo entity type * @return null if not found * @throws ODataJPAModelException */ @CheckForNull JPAEntityType getEntity(final EdmType edmType) throws ODataJPAModelException; /** * Returns the internal representation of an entity type by given full qualified name * @param typeName fill qualified name of an entity type * @return null if not found */ @CheckForNull JPAEntityType getEntity(final FullQualifiedName typeName); /** * * Returns the internal representation of an entity type by given entity set or singleton name. Entity types that are * annotated with EdmIgnore are ignored. * @param edmTargetName * @return null if not found * @throws ODataJPAModelException */ @CheckForNull JPAEntityType getEntity(final String edmTargetName) throws ODataJPAModelException; /** * * Returns the internal representation of an entity type by JPA POJO class. Entity types that are annotated with * EdmIgnore are respected. * @param entityClass * @return null if not found * @throws ODataJPAModelException */ @CheckForNull JPAEntityType getEntity(Class<?> entityClass) throws ODataJPAModelException; @CheckForNull JPAFunction getFunction(final EdmFunction function); /** * Find an Action. As the selection for overloaded actions, as described in * <a href="https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#_Toc31359015"> * Action Overload Resolution (part1 protocol 11.5.5.2)</a> is done by Olingo, a resolution is not performed. * * @param action * @return null if action not found */ @CheckForNull JPAAction getAction(final EdmAction action); @CheckForNull JPAEntitySet getEntitySet(final JPAEntityType entityType) throws ODataJPAModelException; /** * Find an entity set based on the external name. Entity sets marked as with EdmIgnore are ignored * @param edmTargetName * @return * @throws ODataJPAModelException */ Optional<JPAEntitySet> getEntitySet(@Nonnull final String edmTargetName) throws ODataJPAModelException; /** * Find an entity set or singleton based on the external name. Entity sets or singletons marked as with EdmIgnore are * ignored * @param edmTargetName * @return * @throws ODataJPAModelException */ Optional<JPATopLevelEntity> getTopLevelEntity(@Nonnull final String edmTargetName) throws ODataJPAModelException; List<EdmxReference> getReferences(); CsdlTerm getTerm(final FullQualifiedName termName); @CheckForNull JPAStructuredType getComplexType(final EdmComplexType edmComplexType); @CheckForNull JPAStructuredType getComplexType(Class<?> typeClass); @CheckForNull JPAEnumerationAttribute getEnumType(final EdmEnumType type); @CheckForNull JPAEnumerationAttribute getEnumType(final String fqnAsString); JPAEdmNameBuilder getNameBuilder(); /** * Returns a map of claims by claim names. It can be used e.g. to convert the values of a JWT token. In case the same * claim name is used multiple time just one occurrence is returned, assuming that they have the same type. * @return * @throws ODataJPAModelException */ Map<String, JPAProtectionInfo> getClaims() throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAStructuredType.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAStructuredType.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import org.apache.olingo.server.api.uri.UriResourceProperty; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; /** * External view on an Intermediate Structured Type. * * @author Oliver Grande * */ public interface JPAStructuredType extends JPAElement { public JPAAssociationAttribute getAssociation(@Nonnull final String internalName) throws ODataJPAModelException; /** * Searches for an AssociationPath defined by the name used in the OData metadata in all the navigation properties * that are available for this type via the OData service. That is: * <ul> * <li>All not ignored navigation properties of this type. * <li>All not ignored navigation properties from super types. * <li>All not ignored navigation properties from embedded types. * </ul> * @param externalName * @return * @throws ODataJPAModelException */ public JPAAssociationPath getAssociationPath(@Nonnull final String externalName) throws ODataJPAModelException; /** * Searches in the navigation properties that are available for this type via the OData service. That is: * <ul> * <li>All not ignored navigation properties of this type. * <li>All not ignored navigation properties from super types. * <li>All not ignored navigation properties from embedded types. * </ul> * @return null if no navigation property found. * @throws ODataJPAModelException */ public List<JPAAssociationPath> getAssociationPathList() throws ODataJPAModelException; /** * Returns declared attribute. Attributes that shall be ignored are ignored. * <p> * In case all properties are needed use {@link #getDeclaredAttribute(String)} * @param internalName * @return * @throws ODataJPAModelException */ public Optional<JPAAttribute> getAttribute(@Nonnull final String internalName) throws ODataJPAModelException; public Optional<JPAAttribute> getAttribute(@Nonnull final String internalName, final boolean respectIgnore) throws ODataJPAModelException; public Optional<JPAAttribute> getAttribute(@Nonnull final UriResourceProperty uriResourceItem) throws ODataJPAModelException; @Nonnull public List<JPAAttribute> getAttributes() throws ODataJPAModelException; /** * List of the path to all collection properties of this type. That is: * <ul> * <li>All not ignored collection properties of this type. * <li>All not ignored collection properties from super types. * <li>All not ignored collection properties from embedded types. * </ul> * @return * @throws ODataJPAModelException */ @Nonnull public List<JPAPath> getCollectionAttributesPath() throws ODataJPAModelException; /** * List of all associations that are declared at this type. That is: * <ul> * <li>All navigation properties of this type. * <li>All navigation properties from super types. * </ul> * @return * @throws ODataJPAModelException */ @Nonnull public List<JPAAssociationAttribute> getDeclaredAssociations() throws ODataJPAModelException; /** * List of all attributes that are declared at this type. That is: * <ul> * <li>All properties of this type. * <li>All properties from super types. * </ul> * @return * @throws ODataJPAModelException */ @Nonnull public List<JPAAttribute> getDeclaredAttributes() throws ODataJPAModelException; public Optional<JPAAttribute> getDeclaredAttribute(@Nonnull final String internalName) throws ODataJPAModelException; /** * List of all collection attributes that are declared at this type. That is: * <ul> * <li>All collection properties of this type. * <li>All collection properties from super types. * </ul> * @return * @throws ODataJPAModelException */ public List<JPACollectionAttribute> getDeclaredCollectionAttributes() throws ODataJPAModelException; @CheckForNull public JPAPath getPath(final String externalName) throws ODataJPAModelException; @CheckForNull public JPAPath getPath(final String externalName, final boolean respectIgnore) throws ODataJPAModelException; /** * List of all attributes that are available for this type via the OData service. That is: * <ul> * <li>All not ignored properties of the type. * <li>All not ignored properties from super types. * <li>All not ignored properties from embedded types. * </ul> * @return List of all attributes that are available via the OData service. * @throws ODataJPAModelException */ public List<JPAPath> getPathList() throws ODataJPAModelException; /** * List of all protected Attributes including protection/claim information. That is: * <ul> * <li>All not ignored protected properties of the type. * <li>All not ignored protected properties from super types. * <li>All not ignored protected properties from embedded types. * </ul> * @return * @throws ODataJPAModelException */ public List<JPAProtectionInfo> getProtections() throws ODataJPAModelException; public Class<?> getTypeClass(); public boolean isAbstract(); /** * Determines if the structured type has a super type, that will be part of OData metadata. That is, the method will * return null in case the entity has a MappedSuperclass. * @return Determined super type or null * @throws ODataJPAModelException */ @CheckForNull public JPAStructuredType getBaseType() throws ODataJPAModelException; public List<JPAPath> searchChildPath(final JPAPath selectItemPath) throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAParameter.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAParameter.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; public interface JPAParameter extends JPAParameterFacet { /** * Name of the parameter at the UDF or the java method * @return */ public String getInternalName(); /** * Externally used name * @return */ public String getName(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAUserGroupRestrictable.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAUserGroupRestrictable.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import javax.annotation.Nonnull; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAUserGroupRestrictable { /** * @return The list of user groups a artifact is assigned to. In case the list is empty, the artifact is not assigned * to a special group and therefore can be accessed by everyone * @throws ODataJPAModelException */ @Nonnull public List<String> getUserGroups() throws ODataJPAModelException; /** * * @param assignedUserGroups * @return * @throws ODataJPAModelException */ public default boolean isAccessibleFor(@Nonnull List<String> assignedUserGroups) throws ODataJPAModelException { if (getUserGroups().isEmpty()) return true; for (var userGroup : getUserGroups()) { if (assignedUserGroups.contains(userGroup)) return true; } return false; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAInheritanceInformation.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAInheritanceInformation.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; /** * * * * 2025-10-21 * */ public interface JPAInheritanceInformation { default JPAInheritanceType getInheritanceType() { return JPAInheritanceType.NON; } /** * * @return The join condition in case of inheritance by join * @throws ODataJPAModelException */ List<JPAOnConditionItem> getJoinColumnsList() throws ODataJPAModelException; List<JPAOnConditionItem> getReversedJoinColumnsList() throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAttribute.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAttribute.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.lang.reflect.Constructor; import java.util.List; import java.util.Set; import javax.annotation.CheckForNull; import jakarta.persistence.AttributeConverter; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmItem; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransientPropertyCalculator; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAAttribute extends JPAElement, JPAAnnotatable { /** * Returns an instance of the converter defined at the attribute, in case an explicit conversion is required. That is, * Olingo does not support the Java type. In that case the JPA Processor converts the attribute into the DB type * before handing over the value to Olingo. * @param <X> the type of the entity attribute * @param <Y> the type of the database column * @return */ public <X, Y extends Object> AttributeConverter<X, Y> getConverter(); /** * Returns an instance of the converter defined at the attribute independent from the ability of Olingo. * @param <X> the type of the entity attribute * @param <Y> the type of the database column * @return */ public <X, Y extends Object> AttributeConverter<X, Y> getRawConverter(); public EdmPrimitiveTypeKind getEdmType() throws ODataJPAModelException; public CsdlAbstractEdmItem getProperty() throws ODataJPAModelException; /** * Returns the complex type if Attributes is structured and Null if not. Check with {@link #isComplex()} * @return * @throws ODataJPAModelException */ public JPAStructuredType getStructuredType() throws ODataJPAModelException; /** * Returns a list of names of the claims that shall be matched with this property * @return */ public Set<String> getProtectionClaimNames(); /** * Provides a List of path to the protected attributed * @return * @throws ODataJPAModelException */ public List<String> getProtectionPath(String claimName) throws ODataJPAModelException; /** * @return The JAVA type that is used to derive an OData (Edm) type. This could be a simple JAVA type like Integer or * String or a complex type in case of embedded attributes of navigation attributes. For simple attributes the type is * usually the type given in the entity definition. In case this is not supported by Olingo and an * {@link AttributeConverter} is provided, the database type is used. * */ public Class<?> getType(); /** * @return For simple attributes the JAVA type that can be expected to be returned from the database, otherwise null. * */ public @CheckForNull Class<?> getDbType(); /** * @return The type of the attribute as defined in the entity. * */ public @CheckForNull Class<?> getJavaType(); public boolean isAssociation(); /** * True if a to n association is involved * @return */ public boolean isCollection(); public default boolean isComplex() { return false; } /** * True if the property has an enum as type * @return */ public default boolean isEnum() { return false; } public default boolean isEtag() { return false; } public default boolean isKey() { return false; } public default boolean isSearchable() { return false; } public boolean hasProtection(); public boolean isTransient(); /** * * @param <T> * @return * @throws ODataJPAModelException */ public <T extends EdmTransientPropertyCalculator<?>> Constructor<T> getCalculatorConstructor() throws ODataJPAModelException; /** * @return A list of path pointing to the properties that are required to calculate the value of this property */ List<String> getRequiredProperties(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPADataBaseFunction.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPADataBaseFunction.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; public interface JPADataBaseFunction extends JPAFunction { /** * * @return Name of the function on the database */ public String getDBName(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAOperationResultParameter.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAOperationResultParameter.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; public interface JPAOperationResultParameter extends JPAParameterFacet { public boolean isCollection(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/CardinalityValue.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/CardinalityValue.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; public enum CardinalityValue { ONE, MANY; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/Cardinality.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/Cardinality.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import static com.sap.olingo.jpa.metadata.core.edm.mapper.api.CardinalityValue.MANY; import static com.sap.olingo.jpa.metadata.core.edm.mapper.api.CardinalityValue.ONE; public enum Cardinality { MANY_TO_ONE(MANY, ONE), ONE_TO_ONE(ONE, ONE), MANY_TO_MANY(MANY, MANY), ONE_TO_MANY(ONE, MANY); public final CardinalityValue source; public final CardinalityValue target; private Cardinality(final CardinalityValue source, final CardinalityValue target) { this.source = source; this.target = target; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAPath.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAPath.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.ODataPropertyPath; /** * A path within an JPA entity to an attribute. * @author Oliver Grande * */ public interface JPAPath extends ODataPropertyPath, Comparable<JPAPath> { final String PATH_SEPARATOR = "/"; /** * External unique identifier for a path. Two path are seen as equal if they have the same alias * @return */ String getAlias(); /** * @return the name of the data base table/view column of the leaf of a path */ String getDBFieldName(); /** * @return the last element of a path */ JPAAttribute getLeaf(); /** * @return all elements of a path */ List<JPAElement> getPath(); /** * @return true if the leaf of the path shall be ignored */ boolean ignore(); /** * Returns true in case the leaf of the path is part of one of the provided groups or none of the path elements is * annotated with EdmVisibleFor. The leaf is seen as a member of a group in case its EdmVisibleFor annotation contains * the group or the groups is mentioned at any other element of the path. <br> * <b>Note:</b> Based on this inheritance of EdmVisibleFor a path is seen as inconsistent if multiple elements are * annotated and the difference of the set of groups is not empty. * @return */ public boolean isPartOfGroups(final List<String> groups); /** * * @return True in case at least one of the elements of the path is a transient property */ public boolean isTransient(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAParameterFacet.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAParameterFacet.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.geo.SRID; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAParameterFacet { Integer getMaxLength(); Integer getPrecision(); Integer getScale(); SRID getSrid(); Class<?> getType(); FullQualifiedName getTypeFQN() throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAFunction.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAFunction.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmFunctionType; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAFunction extends JPAOperation { /** * * @return List of import parameter * @throws ODataJPAModelException */ public List<JPAParameter> getParameter() throws ODataJPAModelException; /** * * @param internalName * @return * @throws ODataJPAModelException */ public JPAParameter getParameter(String internalName) throws ODataJPAModelException; /** * * @return The type of function */ public EdmFunctionType getFunctionType(); public boolean isBound() throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAction.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAction.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; public interface JPAAction extends JPAOperation, JPAJavaOperation { }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPASingleton.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPASingleton.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; public interface JPASingleton extends JPATopLevelEntity { }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAJavaOperation.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAJavaOperation.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAJavaOperation { /** * @return The Method that implements a function */ public Method getMethod(); /** * * @return The constructor to be used to create a new instance */ public <X> Constructor<X> getConstructor(); /** * * @param declaredParameter * @return * @throws ODataJPAModelException */ JPAParameter getParameter(final Parameter declaredParameter) throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEtagValidator.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEtagValidator.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; /** * Strength of the entity tag (ETag) validator according to * <a href="https://datatracker.ietf.org/doc/html/rfc7232#section-2.1">RFC 7232 Section-2.1</a><br> * * @author Oliver Grande * @since 25.06.2024 * @version 2.1.3 */ public enum JPAEtagValidator { WEAK, STRONG }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAOperation.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAOperation.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import org.apache.olingo.commons.api.edm.provider.CsdlReturnType; public interface JPAOperation extends JPAElement, JPAUserGroupRestrictable { /** * * @return The return or result parameter of the function */ public JPAOperationResultParameter getResultParameter(); public CsdlReturnType getReturnType(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAElement.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAElement.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import org.apache.olingo.commons.api.edm.FullQualifiedName; public interface JPAElement { /** * Returns the full qualified name of an element * @return */ public FullQualifiedName getExternalFQN(); /** * Returns the element name published by the API * @return */ public String getExternalName(); /** * Returns the internally used (Java) name for an element * @return */ public String getInternalName(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAssociationAttribute.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAssociationAttribute.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAAssociationAttribute extends JPAAttribute { public JPAStructuredType getTargetEntity() throws ODataJPAModelException; public JPAAssociationAttribute getPartner(); public JPAAssociationPath getPath() throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEntitySet.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEntitySet.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAEntitySet extends JPATopLevelEntity { JPAEntityType getODataEntityType() throws ODataJPAModelException; JPAEntityType getEntityType(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAOnConditionItem.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAOnConditionItem.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; public interface JPAOnConditionItem { public JPAPath getLeftPath(); public JPAPath getRightPath(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAProtectionInfo.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAProtectionInfo.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; /** * Provides information about a protected attribute * @author Oliver Grande * */ public interface JPAProtectionInfo { /** * The protected attribute * @return */ JPAAttribute getAttribute(); /** * Path within the entity type to the attribute * @return */ JPAPath getPath(); /** * Claim names that shall be used to protect this attribute * @return */ String getClaimName(); /** * Returns the maintained wildcard setting.<p> * In case wildcards are supported, only for attributes of type string, '*' and '%' representing * zero or more characters and '+' as well as '_' for a single character. * @return */ boolean supportsWildcards(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPADescriptionAttribute.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPADescriptionAttribute.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.Map; public interface JPADescriptionAttribute extends JPAAttribute { public boolean isLocationJoin(); /** * @return Property of description entity that contains the text/description */ public JPAAttribute getDescriptionAttribute(); public JPAPath getLocaleFieldName(); public Map<JPAPath, String> getFixedValueAssignment(); public JPAAssociationAttribute asAssociationAttribute(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAJavaFunction.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAJavaFunction.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; public interface JPAJavaFunction extends JPAFunction, JPAJavaOperation { }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEdmNameBuilder.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEdmNameBuilder.java
/** * */ package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import javax.annotation.Nonnull; import jakarta.persistence.Column; import jakarta.persistence.metamodel.Attribute; import jakarta.persistence.metamodel.EmbeddableType; import jakarta.persistence.metamodel.EntityType; import org.apache.olingo.commons.api.edm.provider.CsdlEntityType; /** * A name builder creates, based on information from the JPA entity model names, the names of the corresponding element * of the OData entity data model (EDM) * @author Oliver Grande * Created: 15.09.2019 * */ public interface JPAEdmNameBuilder { static final String DB_FIELD_NAME_PATTERN = "\"&1\""; /** * * @param jpaEmbeddedType * @return */ @Nonnull String buildComplexTypeName(final EmbeddableType<?> jpaEmbeddedType); /** * Container names are <a * href= * "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_SimpleIdentifier"> * Simple Identifier</a>, * so can contain only letters, digits and underscores. * @return non empty unique name of an Entity Set */ @Nonnull String buildContainerName(); /** * Create a name of an <a * href= * "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_12.2_The_edm:EntitySet"> * Entity Set</a> derived from the name of the corresponding entity type. * @param entityTypeName * @return non empty unique name of an Entity Set */ @Nonnull String buildEntitySetName(final String entityTypeName); default String buildEntitySetName(final CsdlEntityType entityType) { return buildEntitySetName(entityType.getName()); } /** * Create a name of an <a * href= * "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406398032"> * Singleton</a> derived from the name of the corresponding entity type. * @param entityTypeName * @return non empty unique name of a Singleton */ @Nonnull default String buildSingletonName(final String entityTypeName) { return entityTypeName; } default String buildSingletonName(final CsdlEntityType entityType) { return buildSingletonName(entityType.getName()); } /** * Creates the name of an <a * href= * "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406397976">Entity * Type</a> derived from JPA Entity Type. * @param jpaEntityType * @return non empty unique name of an Entity Type */ @Nonnull String buildEntityTypeName(final EntityType<?> jpaEntityType); /** * Converts the internal java class name of an enumeration into the external entity data model <a * href= * "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406397991"> * Enumeration Type</a> name. * @param javaEnum * @return non empty unique name of an Enumeration */ @Nonnull String buildEnumerationTypeName(final Class<? extends Enum<?>> javaEnum); /** * Converts the name of an JPA association attribute into the name of an EDM navigation property * @param jpaAttribute * @return non empty unique name of a Navigation Property */ @Nonnull String buildNaviPropertyName(final Attribute<?, ?> jpaAttribute); /** * Convert the internal name of a java based operation into the external entity data model name. * @param internalOperationName * @return non empty unique name of an Operation (Function or Action) */ @Nonnull String buildOperationName(final String internalOperationName); /** * Converts the name of an JPA attribute into the name of an EDM property * @param jpaAttributeName * @return non empty unique name of a property */ @Nonnull String buildPropertyName(final String jpaAttributeName); /** * @return name space to a schema */ @Nonnull String getNamespace(); /** * Build the name of the database column in case it is not provided by the annotation {@link Column}. * The Default converts a field name by adding quotation marks. E.g.: <br> * id -> "id" * <p> * In case you want to use the field name converted into the default database representation, e.g. all upper case, * the you can just return the field name: * * <pre> * {@code * return jpaFieldName * } * </pre> * * * If you would use (upper case) snake case for column names, the implementation could look like this: * * <pre> * {@code * int start = 0; * final List<String> splits = new ArrayList<>(); * final var chars = jpaFieldName.toCharArray(); * for (int i = 0; i < chars.length; i++) { * if (Character.isUpperCase(chars[i])) { * splits.add(String.copyValueOf(chars, start, i - start)); * start = i; * } * } * if (start < chars.length) * splits.add(String.copyValueOf(chars, start, chars.length - start)); * * return splits.stream() * .map(String::toUpperCase) * .collect(Collectors.joining("_")); * } * </pre> * * @param jpaFieldName Name of the field in the entity * @return column name */ @Nonnull default String buildColumnName(final String jpaFieldName) { final var stringBuilder = new StringBuilder(DB_FIELD_NAME_PATTERN); stringBuilder.replace(1, 3, jpaFieldName); return stringBuilder.toString(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEntityType.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEntityType.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import java.util.Optional; import javax.annotation.CheckForNull; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmQueryExtensionProvider; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAEntityType extends JPAStructuredType, JPAAnnotatable, JPAUserGroupRestrictable { /** * Searches for a Collection Property defined by the name used in the OData metadata in all the collection properties * that are available for this type via the OData service. That is: * <ul> * <li>All not ignored collection properties of this type. * <li>All not ignored collection properties from super types. * <li>All not ignored collection properties from embedded types. * </ul> * @param externalName * @return * @throws ODataJPAModelException */ public JPACollectionAttribute getCollectionAttribute(final String externalName) throws ODataJPAModelException; /** * * @return Mime type of streaming content. Empty if no stream property exists * @throws ODataJPAModelException */ public String getContentType() throws ODataJPAModelException; public JPAPath getContentTypeAttributePath() throws ODataJPAModelException; public JPAPath getEtagPath() throws ODataJPAModelException; /** * Returns a resolved list of all attributes that are marked as Id, so the attributes of an EmbeddedId are returned as * separate entries. They are returned in the same order they are mentioned in the corresponding type. * @return * @throws ODataJPAModelException */ public List<JPAAttribute> getKey() throws ODataJPAModelException; /** * Returns a list of path of all attributes annotated as Id. EmbeddedId are <b>not</b> resolved * @return * @throws ODataJPAModelException */ public List<JPAPath> getKeyPath() throws ODataJPAModelException; /** * Returns the class of the Key. This could by either a primitive type, the IdClass or the Embeddable of an EmbeddedId * @return */ public Class<?> getKeyType(); /** * True in case the entity type has a compound key, so an EmbeddedId or multiple id properties * @return */ public boolean hasCompoundKey(); /** * True in case the entity type has an EmbeddedId * @return */ public boolean hasEmbeddedKey(); /** * @return a list of JPAPath to attributes marked with EdmSearchable * @throws ODataJPAModelException */ public List<JPAPath> getSearchablePath() throws ODataJPAModelException; public JPAPath getStreamAttributePath() throws ODataJPAModelException; /** * * @return Name of the database table. The table name is composed from schema name and table name * @throws ODataJPAModelException */ public String getTableName(); public boolean hasEtag() throws ODataJPAModelException; @CheckForNull public JPAEtagValidator getEtagValidator() throws ODataJPAModelException; public boolean hasStream() throws ODataJPAModelException; public <X extends EdmQueryExtensionProvider> Optional<JPAQueryExtension<X>> getQueryExtension() throws ODataJPAModelException; /** * @return Type of inheritance of {@link JPAInheritanceType#NON} */ public JPAInheritanceInformation getInheritanceInformation() throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEnumerationAttribute.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEnumerationAttribute.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAEnumerationAttribute { <T extends Enum<?>> T enumOf(final String value) throws ODataJPAModelException; <T extends Number, E extends Enum<E>> E enumOf(final T value) throws ODataJPAModelException; <T extends Number> T valueOf(final String value) throws ODataJPAModelException; <T extends Number> T valueOf(final List<String> value) throws ODataJPAModelException; boolean isFlags() throws ODataJPAModelException; /** * Converts a list of string representations either into an array of enumerations, if a converter is given, or * otherwise the first value into an enumeration * @param value * @return * @throws ODataJPAModelException */ Object convert(final List<String> values) throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAnnotatable.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAAnnotatable.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.AliasAccess; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.PropertyAccess; import com.sap.olingo.jpa.metadata.core.edm.extension.vocabularies.TermAccess; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; /** * Gives access to OData annotations * * @author Oliver Grande * @since 1.1.1 * 01.03.2023 */ public interface JPAAnnotatable { /** * Returns a OData annotation. E.g. <code>getAnnotation("Capabilities", "FilterRestrictions")</code> will return the * filter restrictions as maintained for the annotatable type * @param alias of the vocabulary. * @param term of the annotation in question. * @return * @throws ODataJPAModelException */ @CheckForNull CsdlAnnotation getAnnotation(@Nonnull String alias, @Nonnull String term) throws ODataJPAModelException; /** * Returns the value of a given property of an annotation. E.g., * <code>getAnnotationValue("Capabilities", "FilterRestrictions", "filterable") </code> * <p> * The value is returned as instance of corresponding type, with the following features * <ul> * <li>Enumerations are returned as strings</li> * <li>Path are returned as {@link JPAPath}</li> * <li>Navigation path are returned as {@link JPAAssociationPath}</li> * </ul> * @param alias of the vocabulary. * @param term of the annotation in question. * @param property the value is requested for. * @return The value of the property * @throws ODataJPAModelException * @since 2.1.0 */ @CheckForNull Object getAnnotationValue(@Nonnull String alias, @Nonnull String term, @Nonnull String property) throws ODataJPAModelException; /** * Returns the value of a given property of an annotation. E.g., * <code>getAnnotationValue("Capabilities", "FilterRestrictions", "filterable", Boolean.class) </code> * <p> * The value is returned as instance of corresponding type, with the following features * <ul> * <li>Enumerations are returned as strings</li> * <li>Path are returned as {@link JPAPath}</li> * <li>Navigation path are returned as {@link JPAAssociationPath}</li> * </ul> * @param <T> Java type of annotation. * @param alias of the vocabulary. * @param term of the annotation in question. * @param propertyName the value is requested for. * @param type java type of property e.g., Boolean.class. * @return * @throws ODataJPAModelException * @since 2.1.0 */ @SuppressWarnings("unchecked") @CheckForNull default <T> T getAnnotationValue(@Nonnull final String alias, @Nonnull final String term, @Nonnull final String property, @Nonnull final Class<?> type) throws ODataJPAModelException { return (T) getAnnotationValue(alias, term, property); } /** * Returns the value of a given property of an annotation. E.g., * <code>getAnnotationValue(Aliases.CAPABILITIES, Terms.FILTER_RESTRICTIONS, FilterRestrictionsProperties.FILTERABLE, Boolean.class) </code> * <p> * The value is returned as instance of corresponding type, with the following features * <ul> * <li>Enumerations are returned as strings</li> * <li>Path are returned as {@link JPAPath}</li> * <li>Navigation path are returned as {@link JPAAssociationPath}</li> * </ul> * @param <T> Java type of annotation. * @param alias of the vocabulary. * @param term of the annotation in question. * @param property the value is requested for. * @param type java type of property e.g., Boolean.class. * @return * @throws ODataJPAModelException * @since 2.1.0 */ @CheckForNull default <T> T getAnnotationValue(@Nonnull final AliasAccess alias, @Nonnull final TermAccess term, @Nonnull final PropertyAccess property, @Nonnull final Class<T> type) throws ODataJPAModelException { return getAnnotationValue(alias.alias(), term.term(), property.property(), type); } String getExternalName(); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPACollectionAttribute.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPACollectionAttribute.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPACollectionAttribute extends JPAAttribute { JPAAssociationPath asAssociation() throws ODataJPAModelException; /** * Returns for simple collections attributes the corresponding attribute of the target entity type. E.g. the following * property definition: <br><br> * <code> * &#64ElementCollection(fetch = FetchType.LAZY)<br> * &#64CollectionTable(name = "\"Comment\"", <br> * &nbsp&nbsp&nbsp&nbspjoinColumns = &#64@JoinColumn(name = "\"BusinessPartnerID\""))<br> * &#64Column(name = "\"Text\"")<br> * private List<String> comment = new ArrayList<>(); * </code><br><br> * creates a simple collection attribute. For this collection attribute jpa processor requires that a corresponding * entity exists. This entity has to have a property pointing to the same database column, which is returned. * * @return In case of simple collections attributes the corresponding attribute of the target entity type otherwise * null. * @throws ODataJPAModelException */ JPAAttribute getTargetAttribute() throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAJoinTable.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAJoinTable.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.List; import com.sap.olingo.jpa.metadata.api.JPAJoinColumn; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPAJoinTable { /** * @return Name of the join table including the schema name, using the following pattern: {schema}.{table} */ public String getTableName(); /** * @return Entity type of the join table */ public JPAEntityType getEntityType(); public List<JPAOnConditionItem> getJoinColumns() throws ODataJPAModelException; /** * @return List of inverse join columns with exchanged left/right order. * @throws ODataJPAModelException */ public List<JPAOnConditionItem> getInverseJoinColumns() throws ODataJPAModelException; public <T extends JPAJoinColumn> List<T> getRawJoinInformation(); public <T extends JPAJoinColumn> List<T> getRawInverseJoinInformation() throws ODataJPAModelException; List<JPAPath> getRightColumnsList() throws ODataJPAModelException; List<JPAPath> getLeftColumnsList() throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAInheritanceType.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAInheritanceType.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; public enum JPAInheritanceType { NON, SINGLE_TABLE, JOIN_TABLE; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPATopLevelEntity.java
jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPATopLevelEntity.java
package com.sap.olingo.jpa.metadata.core.edm.mapper.api; import java.util.Optional; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmQueryExtensionProvider; import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException; public interface JPATopLevelEntity extends JPAElement, JPAAnnotatable, JPAUserGroupRestrictable { public Optional<JPAQueryExtension<EdmQueryExtensionProvider>> getQueryExtension() throws ODataJPAModelException; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/test/java/com/sap/olingo/jpa/processor/cb/ProcessorSelectionSelectionItemTest.java
jpa/odata-jpa-processor-ext/src/test/java/com/sap/olingo/jpa/processor/cb/ProcessorSelectionSelectionItemTest.java
package com.sap.olingo.jpa.processor.cb; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; import com.sap.olingo.jpa.processor.cb.ProcessorSelection.SelectionItem; class ProcessorSelectionSelectionItemTest { private SelectionItem cut; private JPAPath path; @BeforeEach void setup() { path = mock(JPAPath.class); cut = new SelectionItem("Test", path); } @Test void testGetKey() { assertEquals("Test", cut.getKey()); } @Test void testGetValue() { assertEquals(path, cut.getValue()); } @Test void testSetValueThrowsException() { assertThrows(IllegalAccessError.class, () -> cut.setValue(path)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/test/java/com/sap/olingo/jpa/processor/cb/ProcessorSelectionSelectionAttributeTest.java
jpa/odata-jpa-processor-ext/src/test/java/com/sap/olingo/jpa/processor/cb/ProcessorSelectionSelectionAttributeTest.java
package com.sap.olingo.jpa.processor.cb; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.processor.cb.ProcessorSelection.SelectionAttribute; class ProcessorSelectionSelectionAttributeTest { private SelectionAttribute cut; private JPAAttribute attribute; @BeforeEach void setup() { attribute = mock(JPAAttribute.class); cut = new SelectionAttribute("Test", attribute); } @Test void testGetKey() { assertEquals("Test", cut.getKey()); } @Test void testGetValue() { assertEquals(attribute, cut.getValue()); } @Test void testSetValueThrowsException() { assertThrows(IllegalAccessError.class, () -> cut.setValue(attribute)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlPattern.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlPattern.java
package com.sap.olingo.jpa.processor.cb; public interface ProcessorSqlPattern { }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSubQueryProvider.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSubQueryProvider.java
package com.sap.olingo.jpa.processor.cb; public interface ProcessorSubQueryProvider { public <U> ProcessorSubquery<U> subquery(Class<U> type); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorCriteriaQuery.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorCriteriaQuery.java
package com.sap.olingo.jpa.processor.cb; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; public interface ProcessorCriteriaQuery<T> extends CriteriaQuery<T>, ProcessorSubQueryProvider { @Override public <U> ProcessorSubquery<U> subquery(Class<U> type); /** * Create and add a query root corresponding to the given entity, * forming a cartesian product with any existing roots. * @param subquery * @return query root corresponding to the given entity */ <X> Root<X> from(final ProcessorSubquery<X> subquery); /** * The position of the first result the query object was set to * retrieve. Returns 0 if <code>setFirstResult</code> was not applied to the * query object. * @return position of the first result * @since 2.0 */ int getFirstResult(); /** * Set the position of the first result to retrieve. * @param startPosition position of the first result, * numbered from 0 * @return the same query instance * @throws IllegalArgumentException if the argument is negative */ void setFirstResult(int startPosition); /** * The maximum number of results the query object was set to * retrieve. Returns <code>Integer.MAX_VALUE</code> if <code>setMaxResults</code> was not * applied to the query object. * @return maximum number of results * @since 2.0 */ int getMaxResults(); /** * Set the maximum number of results to retrieve. * @param maxResult maximum number of results to retrieve * @return the same query instance * @throws IllegalArgumentException if the argument is negative */ void setMaxResults(int maxResult); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlOperator.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlOperator.java
package com.sap.olingo.jpa.processor.cb; import java.util.List; public record ProcessorSqlOperator(List<ProcessorSqlParameter> parameters) implements ProcessorSqlPattern { }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlFunction.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlFunction.java
package com.sap.olingo.jpa.processor.cb; import java.util.List; public record ProcessorSqlFunction(String function, List<ProcessorSqlParameter> parameters) implements ProcessorSqlPattern { }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSelection.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSelection.java
package com.sap.olingo.jpa.processor.cb; import java.util.List; import java.util.Map; import java.util.Map.Entry; import jakarta.persistence.criteria.Selection; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAAttribute; import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAPath; public interface ProcessorSelection<X> extends Selection<X> { /** * * @return a list of pairs of alias and path */ List<Entry<String, JPAPath>> getResolvedSelection(); /** * Immutable pair * @author Oliver Grande * */ public static record SelectionItem(String key, JPAPath value) implements Map.Entry<String, JPAPath> { @Override public String getKey() { return key; } @Override public JPAPath getValue() { return value; } @Override public JPAPath setValue(final JPAPath value) { throw new IllegalAccessError(); } } public static record SelectionAttribute(String key, JPAAttribute value) implements Map.Entry<String, JPAAttribute> { @Override public String getKey() { return key; } @Override public JPAAttribute getValue() { return value; } @Override public JPAAttribute setValue(final JPAAttribute value) { throw new IllegalAccessError(); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlParameter.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlParameter.java
package com.sap.olingo.jpa.processor.cb; public record ProcessorSqlParameter(String keyword, String parameter, boolean isOptional) { public ProcessorSqlParameter(final String parameter, final boolean isOptional) { this("", parameter, isOptional); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSubquery.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSubquery.java
package com.sap.olingo.jpa.processor.cb; import java.util.List; import javax.annotation.Nullable; import jakarta.persistence.criteria.Order; import jakarta.persistence.criteria.Root; import jakarta.persistence.criteria.Selection; import jakarta.persistence.criteria.Subquery; /** * * @param <T> the type of the selection item. */ public interface ProcessorSubquery<T> extends Subquery<T>, ProcessorSubQueryProvider { @Override public <U> ProcessorSubquery<U> subquery(Class<U> type); /** * Specify the selection items that are to be returned in the * query result.<br> * Replaces the previously specified selection(s), if any. Alias are ignored. * <p> * Main purpose is to use multiselect together with the IN operator. * @param selections selection items corresponding to the * results to be returned by the query * @return the modified query * @throws IllegalArgumentException if the selection is * a compound selection and more than one selection * item has the same assigned alias */ ProcessorSubquery<T> multiselect(Selection<?>... selections); /** * Specify the selection items that are to be returned in the * query result.<br> * Replaces the previously specified selection(s), if any. Alias are ignored. * <p> * Main purpose is to use multiselect together with the IN operator. * @param selectionList selection items corresponding to the * results to be returned by the query * @return the modified query * @throws IllegalArgumentException if the selection is * a compound selection and more than one selection * item has the same assigned alias */ ProcessorSubquery<T> multiselect(List<Selection<?>> selectionList); /** * Specify the ordering expressions that are used to * order the query results. * Replaces the previous ordering expressions, if any. * If no ordering expressions are specified, the previous * ordering, if any, is simply removed, and results will * be returned in no particular order. * The order of the ordering expressions in the list * determines the precedence, whereby the first element in the * list has highest precedence. * @param o list of zero or more ordering expressions * @return the modified query */ ProcessorSubquery<T> orderBy(final List<Order> o); /** * Specify the ordering expressions that are used to * order the query results. * Replaces the previous ordering expressions, if any. * If no ordering expressions are specified, the previous * ordering, if any, is simply removed, and results will * be returned in no particular order. * The left-to-right sequence of the ordering expressions * determines the precedence, whereby the leftmost has highest * precedence. * @param o zero or more ordering expressions * @return the modified query */ ProcessorSubquery<T> orderBy(Order... o); /** * Set the maximum number of results to retrieve. * @param maxResult maximum number of results to retrieve * @return the same query instance * @throws IllegalArgumentException if the argument is negative */ ProcessorSubquery<T> setMaxResults(@Nullable final Integer maxResult); /** * Set the position of the first result to retrieve. * @param startPosition position of the first result, * numbered from 0 * @return the same query instance * @throws IllegalArgumentException if the argument is negative */ ProcessorSubquery<T> setFirstResult(@Nullable final Integer startPosition); <X> Root<X> from(ProcessorSubquery<?> innerQuery); }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlPatternProvider.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorSqlPatternProvider.java
package com.sap.olingo.jpa.processor.cb; import java.util.Arrays; import java.util.Collections; import javax.annotation.Nonnull; /** * * * @author Oliver Grande * 2024-07-03 * 2.2.0 */ public interface ProcessorSqlPatternProvider { static final String VALUE_PLACEHOLDER = "#VALUE#"; static final String START_PLACEHOLDER = "#START#"; static final String LENGTH_PLACEHOLDER = "#LENGTH#"; static final String SEARCH_STRING_PLACEHOLDER = "#SEARCH_STRING#"; static final String COMMA_SEPARATOR = ", "; // Pattern static final String LIMIT_PATTERN = "LIMIT " + VALUE_PLACEHOLDER; static final String OFFSET_PATTERN = "OFFSET " + VALUE_PLACEHOLDER; /** * Default pattern: LIMIT #VALUE# * @return Pattern for the clause limiting the number of rows returned */ @Nonnull default String getMaxResultsPattern() { return LIMIT_PATTERN; } /** * Default pattern: OFFSET #VALUE# * @return Pattern for the clause defining the first row to be returned */ @Nonnull default String getFirstResultPattern() { return OFFSET_PATTERN; } /** * Default: true * @return true if the database requires that the max result clause need to be before the first result clause */ default boolean maxResultsFirst() { return true; } /** * Default pattern: SUBSTRING(#VALUE#, #START#, #LENGTH#) * <p> * The sub string of <i>value</i> from <i>start</i> with the length <i>length</i>. * <p> * @return Pattern for the sub string function */ @Nonnull default ProcessorSqlFunction getSubStringPattern() { return new ProcessorSqlFunction("SUBSTRING", Arrays.asList( new ProcessorSqlParameter(VALUE_PLACEHOLDER, false), new ProcessorSqlParameter(COMMA_SEPARATOR, START_PLACEHOLDER, false), new ProcessorSqlParameter(COMMA_SEPARATOR, LENGTH_PLACEHOLDER, true))); } /** * Default pattern: CONCAT(#VALUE#, #VALUE#) * <p> * Concatenates two string. Some database, e.g. Postgresql, not having a named function to concatenate two strings, * but use an operator, * e.g. ||. * @return Pattern for a function that concatenates two strings */ @Nonnull default ProcessorSqlPattern getConcatenatePattern() { return new ProcessorSqlFunction("CONCAT", Arrays.asList( new ProcessorSqlParameter(VALUE_PLACEHOLDER, false), new ProcessorSqlParameter(COMMA_SEPARATOR, VALUE_PLACEHOLDER, false))); } /** * Default pattern: LOCATE(#SEARCH_STRING#, #VALUE#, #START#) * <p> * Returns the position of the first occurrence of <i>search_string</i> in <i>value</i>. The search shall start at * <i>start</i> * <p> * The start position is seen as optional. In case the database supports an optional occurrences, to express that e.g. * the 3rd occurrence shall be found, it must not be mentioned here, as this is not supported by JPA. * @return Pattern for a function that searches for the position of a search string in another string/value. */ @Nonnull default ProcessorSqlFunction getLocatePattern() { return new ProcessorSqlFunction("LOCATE", Arrays.asList( new ProcessorSqlParameter(SEARCH_STRING_PLACEHOLDER, false), new ProcessorSqlParameter(COMMA_SEPARATOR, VALUE_PLACEHOLDER, false), new ProcessorSqlParameter(COMMA_SEPARATOR, START_PLACEHOLDER, true))); } /** * Default pattern: LENGTH(#VALUE#) * <p> * The character length of <i>value</i>. * <p> * @return Pattern to determine the character length of a string. */ @Nonnull default ProcessorSqlFunction getLengthPattern() { return new ProcessorSqlFunction("LENGTH", Collections.singletonList( new ProcessorSqlParameter(VALUE_PLACEHOLDER, false))); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorCriteriaBuilder.java
jpa/odata-jpa-processor-ext/src/main/java/com/sap/olingo/jpa/processor/cb/ProcessorCriteriaBuilder.java
package com.sap.olingo.jpa.processor.cb; import java.util.List; import jakarta.persistence.Tuple; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Order; import jakarta.persistence.criteria.Path; import jakarta.persistence.criteria.Subquery; public interface ProcessorCriteriaBuilder extends CriteriaBuilder { @Override public ProcessorCriteriaQuery<Tuple> createTupleQuery(); @Override public ProcessorCriteriaQuery<Object> createQuery(); @Override public <T> ProcessorCriteriaQuery<T> createQuery(final Class<T> resultClass); public WindowFunction<Long> rowNumber(); /** * Create predicate to test whether given expression * is contained in a list of values. * @param list of path to be tested against list of values * @return in predicate */ public In<List<Comparable<?>>> in(final List<Path<Comparable<?>>> expression, final Subquery<List<Comparable<?>>> subquery); /** * Create predicate to test whether given expression * is contained in a list of values. * @param path to be tested against list of values * @return in predicate */ public <T> In<T> in(final Path<?> path); public default void resetParameterBuffer() {} public default Object getParameterBuffer() { return null; } public static interface WindowFunction<T> extends Expression<T> { /** * * @param order * @return */ WindowFunction<T> orderBy(final Order... order); WindowFunction<T> orderBy(final List<Order> order); /** * Takes an array of simple path expressions. * @param path * @return */ WindowFunction<T> partitionBy(@SuppressWarnings("unchecked") final Path<Comparable<?>>... path); WindowFunction<T> partitionBy(final List<Path<Comparable<?>>> path); Path<T> asPath(final String tableAlias); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/AbstractConverterTest.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/AbstractConverterTest.java
package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import jakarta.persistence.AttributeConverter; import org.junit.jupiter.api.Test; abstract class AbstractConverterTest<E, D> { protected AttributeConverter<E, D> cut; protected E exp; @Test void testConversion() { assertEquals(exp, cut.convertToEntityAttribute(cut.convertToDatabaseColumn(exp))); } @Test void testToDatabaseReturnsNullOnNull() { assertNull(cut.convertToDatabaseColumn(null)); } @Test void testToEntityAttributeReturnsNullOnNull() { assertNull(cut.convertToEntityAttribute(null)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestCriteriaBuilder.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestCriteriaBuilder.java
package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; import jakarta.persistence.PersistenceException; import jakarta.persistence.Tuple; import jakarta.persistence.TypedQuery; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaBuilder.In; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Path; import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Root; import jakarta.persistence.criteria.Subquery; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivision; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivisionDescription; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivisionDescriptionKey; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartner; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartnerRole; import com.sap.olingo.jpa.processor.core.testmodel.DataSourceHelper; import com.sap.olingo.jpa.processor.core.testmodel.Membership; import com.sap.olingo.jpa.processor.core.testmodel.Organization; import com.sap.olingo.jpa.processor.core.testmodel.Person; import com.sap.olingo.jpa.processor.core.testmodel.Team; class TestCriteriaBuilder { protected static final String PUNIT_NAME = "com.sap.olingo.jpa"; private static final String ENTITY_MANAGER_DATA_SOURCE = "jakarta.persistence.nonJtaDataSource"; private static EntityManagerFactory emf; private EntityManager em; private CriteriaBuilder cb; @BeforeAll public static void setupClass() { final Map<String, Object> properties = new HashMap<>(); properties.put(ENTITY_MANAGER_DATA_SOURCE, DataSourceHelper.createDataSource( DataSourceHelper.DB_HSQLDB)); emf = Persistence.createEntityManagerFactory(PUNIT_NAME, properties); } @BeforeEach void setup() { em = emf.createEntityManager(); assertNotNull(em); cb = em.getCriteriaBuilder(); assertNotNull(cb); } @SuppressWarnings("unchecked") @Test void testSubstringWithExpression() { final CriteriaQuery<Tuple> adminQ = cb.createTupleQuery(); final Root<AdministrativeDivisionDescription> adminRoot1 = adminQ.from(AdministrativeDivisionDescription.class); final Path<?> p = adminRoot1.get("name"); final Expression<Integer> sum = cb.sum(cb.literal(1), cb.literal(4)); adminQ.where(cb.equal(cb.substring((Expression<String>) (p), cb.literal(1), sum), "North")); adminQ.multiselect(adminRoot1.get("name")); final TypedQuery<Tuple> tq = em.createQuery(adminQ); assertFalse(tq.getResultList().isEmpty()); } @Disabled("To time consuming") @Test void testSubSelect() { // https://stackoverflow.com/questions/29719321/combining-conditional-expressions-with-and-and-or-predicates-using-the-jpa-c final CriteriaQuery<Tuple> adminQ1 = cb.createTupleQuery(); final Subquery<Long> adminQ2 = adminQ1.subquery(Long.class); final Subquery<Long> adminQ3 = adminQ2.subquery(Long.class); final Subquery<Long> org = adminQ3.subquery(Long.class); final Root<AdministrativeDivision> adminRoot1 = adminQ1.from(AdministrativeDivision.class); final Root<AdministrativeDivision> adminRoot2 = adminQ2.from(AdministrativeDivision.class); final Root<AdministrativeDivision> adminRoot3 = adminQ3.from(AdministrativeDivision.class); final Root<Organization> org1 = org.from(Organization.class); org.where(cb.and(cb.equal(org1.get("iD"), "3")), createParentOrg(org1, adminRoot3)); org.select(cb.literal(1L)); adminQ3.where(cb.and(createParentAdmin(adminRoot3, adminRoot2), cb.exists(org))); adminQ3.select(cb.literal(1L)); adminQ2.where(cb.and(createParentAdmin(adminRoot2, adminRoot1), cb.exists(adminQ3))); adminQ2.select(cb.literal(1L)); adminQ1.where(cb.exists(adminQ2)); adminQ1.multiselect(adminRoot1.get("divisionCode")); final TypedQuery<Tuple> tq = em.createQuery(adminQ1); assertNotNull(tq.getResultList()); } @SuppressWarnings("unchecked") @Test void testSubSelectTopOrderBy() { // https://stackoverflow.com/questions/9321916/jpa-criteriabuilder-how-to-use-in-comparison-operator // https://stackoverflow.com/questions/24109412/in-clause-with-a-composite-primary-key-in-jpa-criteria#24265131 final CriteriaQuery<Tuple> roleQ = cb.createTupleQuery(); final Root<BusinessPartnerRole> roleRoot = roleQ.from(BusinessPartnerRole.class); final Subquery<BusinessPartner> bupaQ = roleQ.subquery(BusinessPartner.class); @SuppressWarnings("rawtypes") final Root bupaRoot = roleQ.from(BusinessPartner.class); bupaQ.select(bupaRoot.get("iD")); // Expression<String> exp = scheduleRequest.get("createdBy"); // Predicate predicate = exp.in(myList); // criteria.where(predicate); final List<String> ids = new ArrayList<>(); ids.add("1"); ids.add("2"); bupaQ.where(bupaRoot.get("iD").in(ids)); // bupaQ.select( // (Expression<BusinessPartner>) cb.construct( // BusinessPartner.class, // bupaRoot.get("ID"))); // roleQ.where(cb.in(roleRoot.get("businessPartnerID")).value(bupaQ)); roleQ.where(cb.in(roleRoot.get("businessPartnerID")).value(bupaQ)); roleQ.multiselect(roleRoot.get("businessPartnerID")); final TypedQuery<Tuple> tq = em.createQuery(roleQ); assertNotNull(tq.getResultList()); } @Test void testFilterOnPrimitiveCollectionAttribute() { final CriteriaQuery<Tuple> orgQ = cb.createTupleQuery(); final Root<Organization> orgRoot = orgQ.from(Organization.class); orgQ.select(orgRoot.get("iD")); orgQ.where(cb.like(orgRoot.get("comment"), "%just%")); final TypedQuery<Tuple> tq = em.createQuery(orgQ); final List<Tuple> act = tq.getResultList(); assertEquals(1, act.size()); } @Test void testFilterOnEmbeddedCollectionAttribute() { final CriteriaQuery<Tuple> pQ = cb.createTupleQuery(); final Root<Person> pRoot = pQ.from(Person.class); pQ.select(pRoot.get("iD")); pQ.where(cb.equal(pRoot.get("inhouseAddress").get("taskID"), "MAIN")); final TypedQuery<Tuple> tq = em.createQuery(pQ); final List<Tuple> act = tq.getResultList(); assertEquals(1, act.size()); } @Test void testExpandCount() { final CriteriaQuery<Tuple> count = cb.createTupleQuery(); final Root<?> roles = count.from(BusinessPartnerRole.class); count.multiselect(roles.get("businessPartnerID").alias("S0"), cb.count(roles).alias("$count")); count.groupBy(roles.get("businessPartnerID")); count.orderBy(cb.desc(cb.count(roles))); final TypedQuery<Tuple> tq = em.createQuery(count); tq.getResultList(); assertEquals(0, tq.getFirstResult()); } @Test void testAnd() { final CriteriaQuery<Tuple> count = cb.createTupleQuery(); final Root<?> adminDiv = count.from(AdministrativeDivision.class); count.multiselect(adminDiv); final Predicate[] restrictions = new Predicate[3]; restrictions[0] = cb.equal(adminDiv.get("codeID"), "NUTS2"); restrictions[1] = cb.equal(adminDiv.get("divisionCode"), "BE34"); restrictions[2] = cb.equal(adminDiv.get("codePublisher"), "Eurostat"); count.where(cb.and(restrictions)); final TypedQuery<Tuple> tq = em.createQuery(count); assertNotNull(tq.getResultList()); } @Disabled("To be checked") @Test void testSearchEmbeddedId() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<?> adminDiv = cq.from(AdministrativeDivisionDescription.class); cq.multiselect(adminDiv); final Subquery<AdministrativeDivisionDescriptionKey> sq = cq.subquery(AdministrativeDivisionDescriptionKey.class); final Root<AdministrativeDivisionDescription> text = sq.from(AdministrativeDivisionDescription.class); sq.where(cb.function("CONTAINS", Boolean.class, text.get("name"), cb.literal("luettich"))); final Expression<AdministrativeDivisionDescriptionKey> exp = text.get("key"); sq.select(exp); cq.where(cb.and(cb.equal(adminDiv.get("key").get("codeID"), "NUTS2"), cb.in(sq).value(sq))); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> act = tq.getResultList(); System.out.println(act.size()); assertNotNull(act); } @Disabled("To be checked") @Test void testSearchNoSubquery() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<?> adminDiv = cq.from(AdministrativeDivisionDescription.class); cq.multiselect(adminDiv); // Predicate[] restrictions = new Predicate[2]; cq.where( cb.and(cb.equal(cb.conjunction(), cb.function("CONTAINS", Boolean.class, adminDiv.get("name"), cb.literal("luettich"))), cb.equal(adminDiv.get("key").get("codeID"), "NUTS2"))); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> act = tq.getResultList(); System.out.println(act.size()); assertNotNull(act); } @Test void testInClauseSimpleKey() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<?> bupa = cq.from(BusinessPartner.class); cq.select(bupa.get("iD")); cq.where(cb.in(bupa.get("iD")).value("3")); // (bupa.get("iD").in(Arrays.asList("3"))); final TypedQuery<Tuple> tq = em.createQuery(cq); Object dq; String sqlMethod; if ("org.eclipse.persistence.internal.jpa.EJBQueryImpl".equals(tq.getClass().getCanonicalName())) { dq = tq.getClass().getMethod("getDatabaseQuery").invoke(tq); sqlMethod = "getSQLString"; } else { dq = tq; sqlMethod = "toString"; } System.out.println(dq.getClass().getMethod(sqlMethod).invoke(dq)); final List<Tuple> act = tq.getResultList(); System.out.println(dq.getClass().getMethod(sqlMethod).invoke(dq)); Assertions.assertEquals(1, act.size()); } @Test void testEntityTransaction() { Assertions.assertFalse(em.getTransaction().isActive()); em.getTransaction().begin(); Assertions.assertTrue(em.getTransaction().isActive()); } @Test void testInClauseComplexKey() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<?> adminDiv = cq.from(AdministrativeDivisionDescription.class); final AdministrativeDivisionDescriptionKey key = new AdministrativeDivisionDescriptionKey(); cq.multiselect(adminDiv); key.setCodeID("3166-1"); key.setCodePublisher("ISO"); key.setDivisionCode("DEU"); key.setLanguage("de"); // Create IN step by step final In<Object> in = cb.in(adminDiv.get("key")); in.value(key); cq.where(in); // Execute query final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> act = tq.getResultList(); if ("org.apache.openjpa.persistence.criteria.CriteriaBuilderImpl".equals(cb.getClass().getCanonicalName())) assertEquals(1, act.size()); else // EclipseLink problem has been solved: ("WHERE ((NULL, NULL, NULL, NULL) IN ")); assertEquals(1, act.size()); } @Test void testInClauseSubquery() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<BusinessPartner> businessPartner = cq.from(BusinessPartner.class); cq.select(businessPartner.get("iD")); final Subquery<String> subquery = cq.subquery(String.class); final Root<BusinessPartnerRole> role = subquery.from(BusinessPartnerRole.class); subquery.select(role.get("businessPartnerID")).distinct(false); final In<Object> in = cb.in(businessPartner.get("iD")).value(subquery); cq.where(in); final List<Tuple> act = em.createQuery(cq).getResultList(); assertFalse(act.isEmpty()); } @Test void testInClauseSubqueryInvert() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<BusinessPartner> businessPartner = cq.from(BusinessPartner.class); cq.select(businessPartner.get("iD")); final Subquery<BusinessPartnerRole> subquery = cq.subquery(BusinessPartnerRole.class); final Root<BusinessPartnerRole> role = subquery.from(BusinessPartnerRole.class); subquery.select(role.get("businessPartnerID")) .distinct(false); final Predicate in = role.in(businessPartner.get("iD")); cq.where(in); final TypedQuery<Tuple> tq = em.createQuery(cq); assertThrows(PersistenceException.class, () -> tq.getResultList()); } @Test void testManyToMany() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<Person> root = cq.from(Person.class); final Join<Person, Team> join = root.join("teams"); cq.multiselect(root.get("iD"), join.get("iD")); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> act = tq.getResultList(); assertEquals(5, act.size()); } @Test void testManyToManySubquery() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<Team> root = cq.from(Team.class); final Subquery<String> subquery = cq.subquery(String.class); final Root<Person> subRoot = subquery.from(Person.class); subquery.select(subRoot.get("iD")); final Root<Membership> subJoin = subquery.from(Membership.class); subquery.where( cb.and( cb.equal(subRoot.get("country"), "DEU"), cb.and( cb.equal(subRoot.get("iD"), subJoin.get("personID")), cb.equal(root.get("iD"), subJoin.get("teamID"))))); cq.where(cb.exists(subquery)); cq.multiselect(root.get("iD")); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> act = tq.getResultList(); assertEquals(2, act.size()); } private Expression<Boolean> createParentAdmin(final Root<AdministrativeDivision> subQuery, final Root<AdministrativeDivision> query) { return cb.and( cb.equal(query.get("codePublisher"), subQuery.get("codePublisher")), cb.and( cb.equal(query.get("codeID"), subQuery.get("parentCodeID")), cb.equal(query.get("divisionCode"), subQuery.get("parentDivisionCode")))); } private Predicate createParentOrg(final Root<Organization> org1, final Root<AdministrativeDivision> adminRoot3) { return cb.and( cb.equal(adminRoot3.get("codePublisher"), org1.get("address").get("regionCodePublisher")), cb.and( cb.equal(adminRoot3.get("codeID"), org1.get("address").get("regionCodeID")), cb.equal(adminRoot3.get("divisionCode"), org1.get("address").get("region")))); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TimestampLongConverterTest.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TimestampLongConverterTest.java
package com.sap.olingo.jpa.processor.test; import java.sql.Timestamp; import java.time.LocalDateTime; import java.time.Month; import org.junit.jupiter.api.BeforeEach; import com.sap.olingo.jpa.processor.core.testmodel.TimestampLongConverter; final class TimestampLongConverterTest extends AbstractConverterTest<Timestamp, Long> { @BeforeEach void setup() { cut = new TimestampLongConverter(); exp = Timestamp.valueOf(LocalDateTime.of(2020, Month.FEBRUARY, 29, 12, 0, 0)); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/UUIDToBinaryConverterTest.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/UUIDToBinaryConverterTest.java
package com.sap.olingo.jpa.processor.test; import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import com.sap.olingo.jpa.processor.core.testmodel.UUIDToBinaryConverter; final class UUIDToBinaryConverterTest extends AbstractConverterTest<UUID, byte[]> { @BeforeEach void setup() { cut = new UUIDToBinaryConverter(); exp = UUID.randomUUID(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestEqualHashCodeMethods.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestEqualHashCodeMethods.java
/** * */ package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.time.LocalDate; import java.time.LocalTime; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.stream.Stream; import jakarta.persistence.metamodel.EntityType; import jakarta.persistence.metamodel.Metamodel; import jakarta.persistence.metamodel.SingularAttribute; import jakarta.persistence.metamodel.Type.PersistenceType; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; /** * @author Oliver Grande * Created: 11.11.2019 * */ abstract class TestEqualHashCodeMethods { protected static final String ENTITY_MANAGER_DATA_SOURCE = "jakarta.persistence.nonJtaDataSource"; protected static Metamodel model; @SuppressWarnings({ "rawtypes" }) public static Stream<Entry<Object, List<Object>>> equalInstances() { final Map<Object, List<Object>> instances = new HashMap<>(); for (final EntityType<?> et : model.getEntities()) { if (hasOwnId(et)) { final Set<SingularAttribute> keyElements = getKeyAttributes(et); final Class<?> keyClass = getKeyClass(et); Integer counter = 0; try { final Object a = keyClass.getConstructor().newInstance(); final Object b = keyClass.getConstructor().newInstance(); for (final SingularAttribute keyElement : keyElements) { final Method setter = getSetter(keyClass, keyElement); setter.invoke(a, getValue(keyElement.getJavaType(), counter)); setter.invoke(b, getValue(keyElement.getJavaType(), counter)); counter = counter + 1; } instances.put(a, Arrays.asList(a, b)); } catch (SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { continue; } catch (final NoSuchMethodException e) { System.out.println(e.toString()); } } } return instances.entrySet().stream(); } @SuppressWarnings("rawtypes") public static Stream<Entry<Object, List<Object>>> notEqualInstances() { final Map<Object, List<Object>> instances = new HashMap<>(); for (final EntityType<?> et : model.getEntities()) { if (hasOwnId(et)) { final Set<SingularAttribute> keyElements = getKeyAttributes(et); final Class<?> keyClass = getKeyClass(et); try { for (int i = 0; i < keyElements.size(); i++) { Integer counter = 0; final Object a = keyClass.getConstructor().newInstance(); final Object b = keyClass.getConstructor().newInstance(); final Object c = keyClass.getConstructor().newInstance(); for (final SingularAttribute keyElement : keyElements) { final Method setter = getSetter(keyClass, keyElement); setter.invoke(a, getValue(keyElement.getJavaType(), counter)); if (counter != i) { setter.invoke(b, getValue(keyElement.getJavaType(), counter)); setter.invoke(c, getValue(keyElement.getJavaType(), counter)); } else { setter.invoke(b, getValue(keyElement.getJavaType(), 10 * (i + 1) + counter)); } counter = counter + 1; } if (instances.containsKey(a)) instances.get(a).addAll(Arrays.asList(b, c)); else instances.put(a, new ArrayList<>(Arrays.asList(b, c))); instances.put(c, Arrays.asList(a, null, LocalTime.now())); } } catch (SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { continue; } catch (final NoSuchMethodException e) { System.out.println(e.toString()); } } } return instances.entrySet().stream(); } /** * @param javaType * @param counter * @return */ private static Object getValue(final Class<?> javaType, final Integer counter) { if (javaType == String.class) return counter.toString(); if (javaType == Integer.class) return counter; if (javaType == LocalDate.class) return LocalDate.now().plusDays(counter.longValue()); return null; } @SuppressWarnings("rawtypes") private static Set<SingularAttribute> getKeyAttributes(final EntityType<?> et) { final Set<SingularAttribute> keyElements = new HashSet<>(); try { Set<?> attributes; if (et.getIdType().getPersistenceType() == PersistenceType.EMBEDDABLE) { attributes = model.embeddable(et.getIdType().getJavaType()).getSingularAttributes(); } else { var type = et; while (type.getSupertype() != null && type.getSupertype() instanceof EntityType<?> superType) type = superType; attributes = type.getIdClassAttributes(); } for (final Object keyElement : attributes) { keyElements.add((SingularAttribute) keyElement); } } catch (final IllegalArgumentException e) { final SingularAttribute<?, ?> id = et.getId(et.getIdType().getJavaType()); keyElements.add(id); } return keyElements; } private static Class<?> getKeyClass(final EntityType<?> et) { if (et.getIdType().getPersistenceType() == PersistenceType.EMBEDDABLE) { return et.getIdType().getJavaType(); } else { return et.getJavaType(); } } private static boolean hasOwnId(final EntityType<?> et) { try { et.getJavaType().getMethod("equals", Object.class); return !Modifier.isAbstract(et.getJavaType().getModifiers()); // && et.getIdType().getPersistenceType() == PersistenceType.BASIC; } catch (NoSuchMethodException | SecurityException | IllegalArgumentException e) { return false; } } @SuppressWarnings("rawtypes") private static Method getSetter(final Class<?> keyClass, final SingularAttribute keyElement) throws NoSuchMethodException { final StringBuilder setterName = new StringBuilder(); setterName .append("set") .append(keyElement.getName().substring(0, 1).toUpperCase()) .append(keyElement.getName().substring(1)); return keyClass.getMethod(setterName.toString(), keyElement.getJavaType()); } @ParameterizedTest @MethodSource("equalInstances") void testEqualsReturnsTrue(final Entry<Object, List<Object>> instance) { for (final Object comparator : instance.getValue()) { assertEquals(comparator, instance.getKey()); } } @ParameterizedTest @MethodSource("notEqualInstances") void testEqualsReturnsFalse(final Entry<Object, List<Object>> instance) { for (final Object comparator : instance.getValue()) { assertNotEquals(comparator, instance.getKey()); } } @ParameterizedTest @MethodSource("equalInstances") void testHashCodeReturnsValue(final Entry<Object, List<Object>> instance) { assertNotEquals(0, instance.getKey().hashCode()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestEqualHashCodeMethodsErrorModel.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestEqualHashCodeMethodsErrorModel.java
/** * */ package com.sap.olingo.jpa.processor.test; import java.util.HashMap; import java.util.Map; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; import org.junit.jupiter.api.BeforeAll; import com.sap.olingo.jpa.processor.core.testmodel.DataSourceHelper; /** * @author Oliver Grande * Created: 11.11.2019 * */ public class TestEqualHashCodeMethodsErrorModel extends TestEqualHashCodeMethods { private static final String PUNIT_NAME = "error"; @BeforeAll public static void setupClass() { final Map<String, Object> properties = new HashMap<>(); properties.put(ENTITY_MANAGER_DATA_SOURCE, DataSourceHelper.createDataSource( DataSourceHelper.DB_HSQLDB)); final EntityManagerFactory emf = Persistence.createEntityManagerFactory(PUNIT_NAME, properties); model = emf.getMetamodel(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TransientPropertyCalculatorWrongConstructorTest.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TransientPropertyCalculatorWrongConstructorTest.java
package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; import jakarta.persistence.EntityManager; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.processor.core.errormodel.TransientPropertyCalculatorWrongConstructor; class TransientPropertyCalculatorWrongConstructorTest { private TransientPropertyCalculatorWrongConstructor cut; private EntityManager em; @Test void testConstructorWithParameter() { em = mock(EntityManager.class); cut = new TransientPropertyCalculatorWrongConstructor(em, "Test"); assertNotNull(cut); assertEquals(em, cut.getEntityManager()); assertEquals("Test", cut.getDummy()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestFunctions.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestFunctions.java
package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.sql.DataSource; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityTransaction; import jakarta.persistence.ParameterMode; import jakarta.persistence.Persistence; import jakarta.persistence.Query; import jakarta.persistence.StoredProcedureQuery; import jakarta.persistence.Tuple; import jakarta.persistence.TypedQuery; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivision; import com.sap.olingo.jpa.processor.core.testmodel.DataSourceHelper; class TestFunctions { protected static final String PUNIT_NAME = "com.sap.olingo.jpa"; private static final String ENTITY_MANAGER_DATA_SOURCE = "jakarta.persistence.nonJtaDataSource"; private static EntityManagerFactory emf; private static DataSource ds; @BeforeAll public static void setupClass() { final Map<String, Object> properties = new HashMap<>(); ds = DataSourceHelper.createDataSource(DataSourceHelper.DB_HSQLDB); properties.put(ENTITY_MANAGER_DATA_SOURCE, ds); emf = Persistence.createEntityManagerFactory(PUNIT_NAME, properties); } private EntityManager em; private CriteriaBuilder cb; @BeforeEach void setup() { em = emf.createEntityManager(); cb = em.getCriteriaBuilder(); } @Disabled("Not implemented") @Test void TestProcedure() throws SQLException { final StoredProcedureQuery pc = em.createStoredProcedureQuery("\"OLINGO\".\"Siblings\""); pc.registerStoredProcedureParameter("CodePublisher", String.class, ParameterMode.IN); pc.setParameter("CodePublisher", "Eurostat"); pc.registerStoredProcedureParameter("CodeID", String.class, ParameterMode.IN); pc.setParameter("CodeID", "NUTS2"); pc.registerStoredProcedureParameter("DivisionCode", String.class, ParameterMode.IN); pc.setParameter("DivisionCode", "BE25"); try (final Connection connection = ds.getConnection()) { final DatabaseMetaData meta = connection.getMetaData(); try (final ResultSet metaR = meta.getProcedures(connection.getCatalog(), "OLINGO", "%")) { while (metaR.next()) { final String procedureCatalog = metaR.getString(1); final String procedureSchema = metaR.getString(2); final String procedureName = metaR.getString(3); // reserved for future use // reserved for future use // reserved for future use final String remarks = metaR.getString(7); final Short procedureType = metaR.getShort(8); // String specificName = metaR.getString(9); System.out.println("procedureCatalog=" + procedureCatalog); System.out.println("procedureSchema=" + procedureSchema); System.out.println("procedureName=" + procedureName); System.out.println("remarks=" + remarks); System.out.println("procedureType=" + procedureType); // System.out.println("specificName=" + specificName); } final ResultSet rs = meta.getProcedureColumns(connection.getCatalog(), "OLINGO", "%", "%"); while (rs.next()) { // get stored procedure metadata final String procedureCatalog = rs.getString(1); final String procedureSchema = rs.getString(2); final String procedureName = rs.getString(3); final String columnName = rs.getString(4); final short columnReturn = rs.getShort(5); final int columnDataType = rs.getInt(6); final String columnReturnTypeName = rs.getString(7); final int columnPrecision = rs.getInt(8); final int columnByteLength = rs.getInt(9); final short columnScale = rs.getShort(10); final short columnRadix = rs.getShort(11); final short columnNullable = rs.getShort(12); final String columnRemarks = rs.getString(13); System.out.println("storedProcedureName=" + procedureName); System.out.println("procedureCatalog=" + procedureCatalog); System.out.println("procedureSchema=" + procedureSchema); System.out.println("procedureName=" + procedureName); System.out.println("columnName=" + columnName); System.out.println("columnReturn=" + columnReturn); System.out.println("columnDataType=" + columnDataType); System.out.println("columnReturnTypeName=" + columnReturnTypeName); System.out.println("columnPrecision=" + columnPrecision); System.out.println("columnByteLength=" + columnByteLength); System.out.println("columnScale=" + columnScale); System.out.println("columnRadix=" + columnRadix); System.out.println("columnNullable=" + columnNullable); System.out.println("columnRemarks=" + columnRemarks); } pc.execute(); } } final List<?> r = pc.getResultList(); final Object[] one = (Object[]) r.get(0); assertNotNull(one); } @Disabled("Not implemented") @Test void TestScalarFunctionsWhere() { CreateUDFDerby(); final CriteriaQuery<Tuple> count = cb.createTupleQuery(); final Root<?> adminDiv = count.from(AdministrativeDivision.class); count.multiselect(adminDiv); count.where(cb.equal( cb.function("IS_PRIME", boolean.class, cb.literal(5)), Boolean.TRUE)); // cb.literal final TypedQuery<Tuple> tq = em.createQuery(count); final List<Tuple> act = tq.getResultList(); assertNotNull(act); tq.getFirstResult(); } private void CreateUDFDerby() { final EntityTransaction t = em.getTransaction(); final StringBuffer dropString = new StringBuffer("DROP FUNCTION IS_PRIME"); final StringBuffer sqlString = new StringBuffer(); sqlString.append("CREATE FUNCTION IS_PRIME(number Integer) RETURNS Integer "); sqlString.append("PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA "); sqlString.append("EXTERNAL NAME 'com.sap.olingo.jpa.processor.core.test_udf.isPrime'"); t.begin(); final Query d = em.createNativeQuery(dropString.toString()); final Query q = em.createNativeQuery(sqlString.toString()); d.executeUpdate(); q.executeUpdate(); t.commit(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestFunctionsHSQLDB.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestFunctionsHSQLDB.java
package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.sql.DataSource; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityTransaction; import jakarta.persistence.Persistence; import jakarta.persistence.Query; import jakarta.persistence.Tuple; import jakarta.persistence.TypedQuery; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivision; import com.sap.olingo.jpa.processor.core.testmodel.DataSourceHelper; class TestFunctionsHSQLDB { protected static final String PUNIT_NAME = "com.sap.olingo.jpa"; private static final String ENTITY_MANAGER_DATA_SOURCE = "jakarta.persistence.nonJtaDataSource"; private static EntityManagerFactory emf; private static DataSource ds; @BeforeAll public static void setupClass() { final Map<String, Object> properties = new HashMap<>(); ds = DataSourceHelper.createDataSource(DataSourceHelper.DB_HSQLDB); properties.put(ENTITY_MANAGER_DATA_SOURCE, ds); emf = Persistence.createEntityManagerFactory(PUNIT_NAME, properties); } private EntityManager em; private CriteriaBuilder cb; @BeforeEach public void setup() { em = emf.createEntityManager(); cb = em.getCriteriaBuilder(); } @Test void TestScalarFunctionsWhere() { CreateUDFHSQLDB(); final CriteriaQuery<Tuple> count = cb.createTupleQuery(); final Root<?> adminDiv = count.from(AdministrativeDivision.class); count.multiselect(adminDiv); count.where(cb.and(cb.greaterThan( // cb.function("PopulationDensity", Integer.class, adminDiv.get("area"), adminDiv.get("population")), 60)), cb.equal(adminDiv.get("countryCode"), cb.literal("BEL"))); // cb.literal final TypedQuery<Tuple> tq = em.createQuery(count); final List<Tuple> act = tq.getResultList(); assertNotNull(act); tq.getFirstResult(); } private void CreateUDFHSQLDB() { final EntityTransaction t = em.getTransaction(); // StringBuffer dropString = new StringBuffer("DROP FUNCTION PopulationDensity"); final StringBuffer sqlString = new StringBuffer(); sqlString.append("CREATE FUNCTION PopulationDensity (area INT, population BIGINT ) "); sqlString.append("RETURNS INT "); sqlString.append("IF area <= 0 THEN RETURN 0;"); sqlString.append("ELSE RETURN population / area; "); sqlString.append("END IF"); t.begin(); // Query d = em.createNativeQuery(dropString.toString()); final Query q = em.createNativeQuery(sqlString.toString()); // d.executeUpdate(); q.executeUpdate(); t.commit(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestStandardMethodsOfTestModel.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestStandardMethodsOfTestModel.java
/** * */ package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.params.provider.Arguments.arguments; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Clob; import java.sql.Date; import java.sql.SQLException; import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.stream.Stream; import org.hsqldb.jdbc.JDBCClob; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import com.sap.olingo.jpa.processor.core.testmodel.AddressDeepProtected; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivision; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivisionDescription; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivisionDescriptionKey; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivisionKey; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeInformation; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartnerProtected; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartnerRole; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartnerRoleKey; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartnerRoleProtected; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartnerRoleWithGroup; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartnerWithGroups; import com.sap.olingo.jpa.processor.core.testmodel.ChangeInformation; import com.sap.olingo.jpa.processor.core.testmodel.Collection; import com.sap.olingo.jpa.processor.core.testmodel.CollectionDeep; import com.sap.olingo.jpa.processor.core.testmodel.CollectionFirstLevelComplex; import com.sap.olingo.jpa.processor.core.testmodel.CollectionInnerComplex; import com.sap.olingo.jpa.processor.core.testmodel.CollectionNestedComplex; import com.sap.olingo.jpa.processor.core.testmodel.CollectionPartOfComplex; import com.sap.olingo.jpa.processor.core.testmodel.CollectionSecondLevelComplex; import com.sap.olingo.jpa.processor.core.testmodel.CollectionWithTwoKey; import com.sap.olingo.jpa.processor.core.testmodel.Comment; import com.sap.olingo.jpa.processor.core.testmodel.CommunicationData; import com.sap.olingo.jpa.processor.core.testmodel.Country; import com.sap.olingo.jpa.processor.core.testmodel.CountryKey; import com.sap.olingo.jpa.processor.core.testmodel.CountryRestriction; import com.sap.olingo.jpa.processor.core.testmodel.DummyToBeIgnored; import com.sap.olingo.jpa.processor.core.testmodel.InhouseAddress; import com.sap.olingo.jpa.processor.core.testmodel.InhouseAddressTable; import com.sap.olingo.jpa.processor.core.testmodel.InhouseAddressWithGroup; import com.sap.olingo.jpa.processor.core.testmodel.InhouseAddressWithProtection; import com.sap.olingo.jpa.processor.core.testmodel.InhouseAddressWithThreeProtections; import com.sap.olingo.jpa.processor.core.testmodel.InstanceRestrictionKey; import com.sap.olingo.jpa.processor.core.testmodel.JoinRelationKey; import com.sap.olingo.jpa.processor.core.testmodel.MembershipKey; import com.sap.olingo.jpa.processor.core.testmodel.NestedComplex; import com.sap.olingo.jpa.processor.core.testmodel.NestedComplexKey; import com.sap.olingo.jpa.processor.core.testmodel.Organization; import com.sap.olingo.jpa.processor.core.testmodel.OrganizationImage; import com.sap.olingo.jpa.processor.core.testmodel.Pages; import com.sap.olingo.jpa.processor.core.testmodel.Person; import com.sap.olingo.jpa.processor.core.testmodel.PersonDeepProtected; import com.sap.olingo.jpa.processor.core.testmodel.PersonDeepProtectedHidden; import com.sap.olingo.jpa.processor.core.testmodel.PersonImage; import com.sap.olingo.jpa.processor.core.testmodel.PostalAddressData; import com.sap.olingo.jpa.processor.core.testmodel.PostalAddressDataWithGroup; import com.sap.olingo.jpa.processor.core.testmodel.Team; import com.sap.olingo.jpa.processor.core.testmodel.TemporalWithValidityPeriod; import com.sap.olingo.jpa.processor.core.testmodel.TemporalWithValidityPeriodKey; import com.sap.olingo.jpa.processor.core.testmodel.User; /** * The following set of test methods checks a number of standard methods of model pojos. * @author Oliver Grande * Created: 05.10.2019 * */ class TestStandardMethodsOfTestModel { private final String expString = "TestString"; private final Integer expInteger = 20; private final int expInt = 10; private final Boolean expBoolean = Boolean.TRUE; private final BigInteger expBigInt = new BigInteger("10"); private final BigDecimal expDecimal = new BigDecimal(1.10); private final LocalDate expLocalDate = LocalDate.now(); private final long expLong = 15l; private final byte[] expByteArray = new byte[] { 1, 1, 1, 1 }; private final Date expDate = Date.valueOf(expLocalDate); @SuppressWarnings("deprecation") private final java.util.Date expUtilDate = new java.util.Date(119, 10, 01); private final Timestamp expTimestamp = Timestamp.valueOf(LocalDateTime.now()); private final Short expShort = Short.valueOf("10"); private Clob expClob; static Stream<Arguments> testModelEntities() { return Stream.of( arguments(AddressDeepProtected.class), arguments(AdministrativeDivisionDescription.class), arguments(AdministrativeDivisionDescriptionKey.class), arguments(AdministrativeDivisionKey.class), arguments(AdministrativeDivision.class), arguments(AdministrativeInformation.class), arguments(BusinessPartnerProtected.class), arguments(BusinessPartnerWithGroups.class), arguments(BusinessPartnerRole.class), arguments(BusinessPartnerRoleWithGroup.class), arguments(BusinessPartnerRoleProtected.class), arguments(BusinessPartnerRoleKey.class), arguments(ChangeInformation.class), arguments(CommunicationData.class), arguments(Collection.class), arguments(CollectionInnerComplex.class), arguments(CollectionPartOfComplex.class), arguments(CollectionNestedComplex.class), arguments(CollectionDeep.class), arguments(CollectionFirstLevelComplex.class), arguments(CollectionSecondLevelComplex.class), arguments(CollectionWithTwoKey.class), arguments(Comment.class), arguments(Country.class), arguments(CountryKey.class), arguments(CountryRestriction.class), arguments(InhouseAddress.class), arguments(InhouseAddressTable.class), arguments(InhouseAddressWithGroup.class), arguments(InhouseAddressWithProtection.class), arguments(InhouseAddressWithThreeProtections.class), arguments(InstanceRestrictionKey.class), arguments(JoinRelationKey.class), arguments(MembershipKey.class), arguments(NestedComplex.class), arguments(NestedComplexKey.class), arguments(Organization.class), arguments(OrganizationImage.class), arguments(Pages.class), arguments(Person.class), arguments(PersonImage.class), arguments(PersonDeepProtected.class), arguments(PersonDeepProtectedHidden.class), arguments(PostalAddressData.class), arguments(PostalAddressDataWithGroup.class), arguments(Team.class), arguments(TemporalWithValidityPeriod.class), arguments(TemporalWithValidityPeriodKey.class), arguments(User.class), arguments(DummyToBeIgnored.class)); } static Stream<Arguments> testErrorEntities() { return Stream.of( arguments(com.sap.olingo.jpa.processor.core.errormodel.Team.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.AdministrativeInformation.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.ChangeInformation.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.CollectionAttributeProtected.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.ComplexProtectedNoPath.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.ComplexProtectedWrongPath.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.EmbeddedKeyPartOfGroup.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.NavigationAttributeProtected.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.NavigationPropertyPartOfGroup.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.KeyPartOfGroup.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.MandatoryPartOfGroup.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.PersonDeepCollectionProtected.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.TeamWithTransientCalculatorConstructorError.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.TeamWithTransientCalculatorError.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.TeamWithTransientKey.class), arguments(com.sap.olingo.jpa.processor.core.errormodel.TeamWithTransientCalculatorError.class)); } @BeforeEach void setup() throws SQLException { expClob = new JDBCClob("Test"); } @ParameterizedTest @MethodSource({ "testModelEntities", "testErrorEntities" }) void testGetterReturnsSetPrimitiveValue(final Class<?> clazz) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final Method[] methods = clazz.getMethods(); final Constructor<?> constructor = clazz.getConstructor(); assertNotNull(constructor); final Object instance = constructor.newInstance(); for (final Method setter : methods) { if ("set".equals(setter.getName().substring(0, 3)) && setter.getParameterCount() == 1) { final String getterName = "g" + setter.getName().substring(1); assertNotNull(clazz.getMethod(getterName)); final Method getter = clazz.getMethod(getterName); final var returnType = getter.getReturnType(); final Class<?> paramType = setter.getParameterTypes()[0]; final Object exp = getExpected(paramType); if (returnType.equals(paramType) && exp != null) { setter.invoke(instance, exp); if (exp.getClass().isArray()) if ("byte[]".equals(exp.getClass().getTypeName())) assertArrayEquals((byte[]) exp, (byte[]) getter.invoke(instance)); else assertArrayEquals((Object[]) exp, (Object[]) getter.invoke(instance)); else assertEquals(exp, getter.invoke(instance)); } } } } @ParameterizedTest @MethodSource({ "testModelEntities", "testErrorEntities" }) void testToStringReturnsValue(final Class<?> clazz) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final Constructor<?> constructor = clazz.getConstructor(); assertNotNull(constructor); final Object instance = constructor.newInstance(); assertFalse(instance.toString().isEmpty()); } @ParameterizedTest @MethodSource({ "testModelEntities", "testErrorEntities" }) void testHasValueReturnsValue(final Class<?> clazz) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final Method[] methods = clazz.getMethods(); final Constructor<?> constructor = clazz.getConstructor(); assertNotNull(constructor); final Object instance = constructor.newInstance(); for (final Method hashCode : methods) { if ("hashCode".equals(hashCode.getName()) && hashCode.getParameterCount() == 0) { assertNotEquals(0, hashCode.invoke(instance)); } } } private Object getExpected(final Class<?> paramType) { if (paramType == String.class) return expString; else if (paramType == Integer.class) return expInteger; else if (paramType == int.class) return expInt; else if (paramType == Boolean.class) return expBoolean; else if (paramType == BigInteger.class) return expBigInt; else if (paramType == BigDecimal.class) return expDecimal; else if (paramType == LocalDate.class) return expLocalDate; else if (paramType == Long.class) return expLong; else if (paramType == long.class) return expLong; else if (paramType == Clob.class) return expClob; else if (paramType == expByteArray.getClass()) return expByteArray; else if (paramType == Date.class) return expDate; else if (paramType == expUtilDate.getClass()) return expUtilDate; else if (paramType == Timestamp.class) return expTimestamp; else if (paramType == Short.class) return expShort; else if (paramType == short.class) return expShort; else return null; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/UUIDToStringConverterTest.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/UUIDToStringConverterTest.java
package com.sap.olingo.jpa.processor.test; import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import com.sap.olingo.jpa.processor.core.testmodel.UUIDToStringConverter; final class UUIDToStringConverterTest extends AbstractConverterTest<UUID, String> { @BeforeEach void setup() { cut = new UUIDToStringConverter(); exp = UUID.randomUUID(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/LocalDateTimeConverterTest.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/LocalDateTimeConverterTest.java
package com.sap.olingo.jpa.processor.test; import java.time.LocalDateTime; import java.time.Month; import java.util.Date; import org.junit.jupiter.api.BeforeEach; import com.sap.olingo.jpa.processor.core.testmodel.LocalDateTimeConverter; final class LocalDateTimeConverterTest extends AbstractConverterTest<LocalDateTime, Date> { @BeforeEach void setup() { cut = new LocalDateTimeConverter(); exp = LocalDateTime.of(2020, Month.FEBRUARY, 29, 12, 0, 0); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestAssociations.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestAssociations.java
package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.HashMap; import java.util.List; import java.util.Map; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; import jakarta.persistence.Tuple; import jakarta.persistence.TypedQuery; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivision; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivisionDescription; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartner; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartnerRole; import com.sap.olingo.jpa.processor.core.testmodel.Country; import com.sap.olingo.jpa.processor.core.testmodel.DataSourceHelper; class TestAssociations { protected static final String PUNIT_NAME = "com.sap.olingo.jpa"; private static final String ENTITY_MANAGER_DATA_SOURCE = "jakarta.persistence.nonJtaDataSource"; private static EntityManagerFactory emf; private EntityManager em; private CriteriaBuilder cb; @BeforeAll public static void setupClass() { final Map<String, Object> properties = new HashMap<>(); properties.put(ENTITY_MANAGER_DATA_SOURCE, DataSourceHelper.createDataSource( DataSourceHelper.DB_HSQLDB)); emf = Persistence.createEntityManagerFactory(PUNIT_NAME, properties); } @BeforeEach void setup() { em = emf.createEntityManager(); cb = em.getCriteriaBuilder(); } @Test void getBuPaRoles() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<BusinessPartner> root = cq.from(BusinessPartner.class); cq.multiselect(root.get("roles").alias("roles")); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> result = tq.getResultList(); final BusinessPartnerRole role = (BusinessPartnerRole) result.get(0).get("roles"); assertNotNull(role); } @Test void getBuPaLocation() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<BusinessPartner> root = cq.from(BusinessPartner.class); cq.multiselect(root.get("locationName").alias("L")); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> result = tq.getResultList(); final AdministrativeDivisionDescription act = (AdministrativeDivisionDescription) result.get(0).get("L"); assertNotNull(act); } @Test void getRoleBuPa() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<BusinessPartnerRole> root = cq.from(BusinessPartnerRole.class); cq.multiselect(root.get("businessPartner").alias("BuPa")); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> result = tq.getResultList(); final BusinessPartner bp = (BusinessPartner) result.get(0).get("BuPa"); assertNotNull(bp); } @Test void getBuPaCountryName() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<BusinessPartner> root = cq.from(BusinessPartner.class); // Works with eclipselink, but not with openjap cq.multiselect(root.get("address").get("countryName").alias("CN")); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> result = tq.getResultList(); final Country region = (Country) result.get(0).get("CN"); assertNotNull(region); } @Test void getBuPaRegionName() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<BusinessPartner> root = cq.from(BusinessPartner.class); cq.multiselect(root.get("address").get("regionName").alias("RN")); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> result = tq.getResultList(); final AdministrativeDivisionDescription region = (AdministrativeDivisionDescription) result.get(0).get("RN"); assertNotNull(region); } @Test void getAdministrativeDivisionParent() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<AdministrativeDivision> root = cq.from(AdministrativeDivision.class); cq.multiselect(root.get("parent").alias("P")); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> result = tq.getResultList(); final AdministrativeDivision act = (AdministrativeDivision) result.get(0).get("P"); assertNotNull(act); } @Test void getAdministrativeDivisionOneParent() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<AdministrativeDivision> root = cq.from(AdministrativeDivision.class); root.alias("Source"); cq.multiselect(root.get("parent").alias("P")); // cq.select((Selection<? extends Tuple>) root); cq.where(cb.and( cb.equal(root.get("codePublisher"), "Eurostat"), cb.and( cb.equal(root.get("codeID"), "NUTS3"), cb.equal(root.get("divisionCode"), "BE251")))); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> result = tq.getResultList(); final AdministrativeDivision act = (AdministrativeDivision) result.get(0).get("P"); assertNotNull(act); assertEquals("NUTS2", act.getCodeID()); assertEquals("BE25", act.getDivisionCode()); } @Test void getAdministrativeDivisionChildrenOfOneParent() { final CriteriaQuery<Tuple> cq = cb.createTupleQuery(); final Root<AdministrativeDivision> root = cq.from(AdministrativeDivision.class); root.alias("Source"); cq.multiselect(root.get("children").alias("C")); cq.where(cb.and( cb.equal(root.get("codePublisher"), "Eurostat"), cb.and( cb.equal(root.get("codeID"), "NUTS2"), cb.equal(root.get("divisionCode"), "BE25")))); cq.orderBy(cb.desc(root.get("divisionCode"))); final TypedQuery<Tuple> tq = em.createQuery(cq); final List<Tuple> result = tq.getResultList(); final AdministrativeDivision act = (AdministrativeDivision) result.get(0).get("C"); assertNotNull(act); assertEquals(8, result.size()); assertEquals("NUTS3", act.getCodeID()); assertEquals("BE251", act.getDivisionCode()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestEqualHashCodeMethodsTestModel.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TestEqualHashCodeMethodsTestModel.java
package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.LocalDate; import java.util.HashMap; import java.util.Map; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.processor.core.testmodel.AdministrativeDivisionKey; import com.sap.olingo.jpa.processor.core.testmodel.BusinessPartnerRoleKey; import com.sap.olingo.jpa.processor.core.testmodel.DataSourceHelper; import com.sap.olingo.jpa.processor.core.testmodel.InstanceRestrictionKey; import com.sap.olingo.jpa.processor.core.testmodel.MembershipKey; import com.sap.olingo.jpa.processor.core.testmodel.TemporalWithValidityPeriodKey; /** * @author Oliver Grande * Created: 11.11.2019 * */ class TestEqualHashCodeMethodsTestModel extends TestEqualHashCodeMethods { private static final String PUNIT_NAME = "com.sap.olingo.jpa"; @BeforeAll static void setupClass() { final Map<String, Object> properties = new HashMap<>(); properties.put(ENTITY_MANAGER_DATA_SOURCE, DataSourceHelper.createDataSource( DataSourceHelper.DB_HSQLDB)); final EntityManagerFactory emf = Persistence.createEntityManagerFactory(PUNIT_NAME, properties); model = emf.getMetamodel(); } @Test void testBusinessPartnerRoleKeyEqual() { final BusinessPartnerRoleKey cut = new BusinessPartnerRoleKey("12", "A"); assertFalse(cut.equals(null)); // NOSONAR assertTrue(cut.equals(cut));// NOSONAR assertTrue(cut.equals(new BusinessPartnerRoleKey("12", "A")));// NOSONAR assertFalse(cut.equals(new BusinessPartnerRoleKey()));// NOSONAR assertFalse(cut.equals(new BusinessPartnerRoleKey("12", "B")));// NOSONAR assertFalse(cut.equals(new BusinessPartnerRoleKey("11", "A")));// NOSONAR assertFalse(new BusinessPartnerRoleKey("12", null).equals(cut));// NOSONAR assertFalse(new BusinessPartnerRoleKey(null, "A").equals(cut));// NOSONAR } @Test void testInstanceRestrictionKeyEqual() { final InstanceRestrictionKey cut = new InstanceRestrictionKey("12", 1); assertFalse(cut.equals(null));// NOSONAR assertTrue(cut.equals(cut));// NOSONAR assertTrue(cut.equals(new InstanceRestrictionKey("12", 1)));// NOSONAR assertFalse(cut.equals(new InstanceRestrictionKey()));// NOSONAR assertFalse(cut.equals(new InstanceRestrictionKey("12", 2)));// NOSONAR assertFalse(cut.equals(new InstanceRestrictionKey("11", 1)));// NOSONAR assertFalse(new InstanceRestrictionKey(null, 1).equals(cut));// NOSONAR assertFalse(new InstanceRestrictionKey("12", null).equals(cut));// NOSONAR } @Test void testMembershipKeyEqual() { final MembershipKey cut = new MembershipKey("12", "A"); assertFalse(cut.equals(null));// NOSONAR assertTrue(cut.equals(cut));// NOSONAR assertTrue(cut.equals(new MembershipKey("12", "A")));// NOSONAR assertFalse(cut.equals(new MembershipKey()));// NOSONAR assertFalse(cut.equals(new MembershipKey("12", "B")));// NOSONAR assertFalse(cut.equals(new MembershipKey("11", "A")));// NOSONAR assertFalse(new MembershipKey(null, "A").equals(cut));// NOSONAR assertFalse(new MembershipKey("12", null).equals(cut));// NOSONAR } @Test void testAdministrativeDivisionKeyEqual() { final AdministrativeDivisionKey cut = new AdministrativeDivisionKey("A", "B", "C"); assertFalse(cut.equals(null));// NOSONAR assertTrue(cut.equals(cut));// NOSONAR assertTrue(cut.equals(new AdministrativeDivisionKey("A", "B", "C")));// NOSONAR assertFalse(cut.equals(new AdministrativeDivisionKey()));// NOSONAR assertFalse(new AdministrativeDivisionKey("B", "B", "C").equals(cut));// NOSONAR assertFalse(new AdministrativeDivisionKey("A", "C", "C").equals(cut));// NOSONAR assertFalse(new AdministrativeDivisionKey("A", "B", "D").equals(cut));// NOSONAR assertFalse(new AdministrativeDivisionKey(null, "B", "C").equals(cut));// NOSONAR assertFalse(new AdministrativeDivisionKey("A", null, "C").equals(cut));// NOSONAR assertFalse(new AdministrativeDivisionKey("A", "B", null).equals(cut));// NOSONAR } @Test void testAdministrativeDivisionKeyCompareTo() { final AdministrativeDivisionKey cut = new AdministrativeDivisionKey("B", "B", "B"); assertEquals(0, cut.compareTo(cut)); assertEquals(1, cut.compareTo(new AdministrativeDivisionKey("B", "B", "A"))); assertEquals(-1, cut.compareTo(new AdministrativeDivisionKey("B", "B", "C"))); assertEquals(1, cut.compareTo(new AdministrativeDivisionKey("B", "A", "B"))); assertEquals(-1, cut.compareTo(new AdministrativeDivisionKey("B", "C", "B"))); assertEquals(1, cut.compareTo(new AdministrativeDivisionKey("A", "B", "B"))); assertEquals(-1, cut.compareTo(new AdministrativeDivisionKey("C", "B", "B"))); } @Test void testTemporalWithValidityPeriodKeyEqual() { final LocalDate now = LocalDate.now(); final TemporalWithValidityPeriodKey cut = new TemporalWithValidityPeriodKey("12", now); assertFalse(cut.equals(null));// NOSONAR assertTrue(cut.equals(cut));// NOSONAR assertTrue(cut.equals(new TemporalWithValidityPeriodKey("12", now)));// NOSONAR assertFalse(cut.equals(new TemporalWithValidityPeriodKey()));// NOSONAR assertFalse(cut.equals(new TemporalWithValidityPeriodKey("12", now.minusDays(1L))));// NOSONAR assertFalse(cut.equals(new TemporalWithValidityPeriodKey("11", now)));// NOSONAR assertFalse(new TemporalWithValidityPeriodKey(null, now).equals(cut));// NOSONAR assertFalse(new TemporalWithValidityPeriodKey("12", null).equals(cut));// NOSONAR } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TransientPropertyCalculatorTwoConstructorsTest.java
jpa/odata-jpa-test/src/test/java/com/sap/olingo/jpa/processor/test/TransientPropertyCalculatorTwoConstructorsTest.java
package com.sap.olingo.jpa.processor.test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; import jakarta.persistence.EntityManager; import org.junit.jupiter.api.Test; import com.sap.olingo.jpa.processor.core.errormodel.TransientPropertyCalculatorTwoConstructors; class TransientPropertyCalculatorTwoConstructorsTest { private TransientPropertyCalculatorTwoConstructors cut; private EntityManager em; @Test void testConstructor() { assertNotNull(new TransientPropertyCalculatorTwoConstructors()); } @Test void testConstructorWithParameter() { em = mock(EntityManager.class); cut = new TransientPropertyCalculatorTwoConstructors(em); assertNotNull(cut); assertEquals(em, cut.getEntityManager()); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/db/migration/V1_1__SchemaMigration.java
jpa/odata-jpa-test/src/main/java/db/migration/V1_1__SchemaMigration.java
package db.migration; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import org.flywaydb.core.api.migration.BaseJavaMigration; import org.flywaydb.core.api.migration.Context; import org.flywaydb.core.internal.database.DatabaseType; /** * * * * Created 2024-06-09 * @author Oliver Grande * @since 2.1.2 * */ public class V1_1__SchemaMigration extends BaseJavaMigration { // NOSONAR @Override public void migrate(final Context context) throws Exception { final var configuration = context.getConfiguration(); final var connection = context.getConnection(); final DatabaseType dbType = configuration.getDatabaseType(); final List<Optional<PreparedStatement>> preparedStatements = switch (dbType.getName()) { case "H2" -> createFunctionH2(); case "SAP HANA" -> createFunctionHANA(connection); case "HSQLDB" -> createFunctionHSQLDB(connection); case "PostgreSQL" -> createFunctionPostgres(connection); case "Derby" -> createFunctionDerby(); case "MySQL" -> createFunctionDerby(); default -> raiseUnsupportedDbException(dbType); }; for (final var preparedStatement : preparedStatements) { if (preparedStatement.isPresent()) { preparedStatement.get().execute(); preparedStatement.get().close(); } } } private List<Optional<PreparedStatement>> raiseUnsupportedDbException(final DatabaseType dbType) { throw new IllegalArgumentException("No migration for database of type: " + dbType.getName()); } private List<Optional<PreparedStatement>> createFunctionPostgres(final Connection connection) throws SQLException { final String sql = """ CREATE OR REPLACE FUNCTION "OLINGO"."Siblings"("CodePublisher" character varying, "CodeID" character varying, "DivisionCode" character varying) RETURNS SETOF "OLINGO"."AdministrativeDivision" LANGUAGE sql AS $function$ SELECT "CodePublisher", "CodeID", "DivisionCode", "CountryISOCode", "ParentCodeID", "ParentDivisionCode", "AlternativeCode", "Area", "Population" FROM "OLINGO"."AdministrativeDivision" as kids WHERE ("CodePublisher", "ParentCodeID", "ParentDivisionCode") IN (SELECT "CodePublisher", "ParentCodeID", "ParentDivisionCode" FROM "OLINGO"."AdministrativeDivision" WHERE "CodePublisher" = $1 AND "CodeID" = $2 AND "DivisionCode" = $3 ) AND kids."DivisionCode" <> $3; $function$ ; """; return Collections.singletonList(Optional.of(connection.prepareStatement(sql))); } private List<Optional<PreparedStatement>> createFunctionHSQLDB(final Connection connection) throws SQLException { final String sqlSiblings = """ CREATE FUNCTION "OLINGO"."Siblings" ("Publisher" VARCHAR(10), "ID" VARCHAR(10), "Division" VARCHAR(10)) RETURNS TABLE( "CodePublisher" VARCHAR(10), "CodeID" VARCHAR(10), "DivisionCode" VARCHAR(10), "CountryISOCode" VARCHAR(4), "ParentCodeID" VARCHAR(10), "ParentDivisionCode" VARCHAR(10), "AlternativeCode" VARCHAR(10), "Area" int, "Population" BIGINT) READS SQL DATA RETURN TABLE( SELECT "CodePublisher", "CodeID", "DivisionCode", "CountryISOCode", "ParentCodeID", "ParentDivisionCode", "AlternativeCode", "Area", "Population" FROM "AdministrativeDivision" as a WHERE EXISTS (SELECT "CodePublisher" FROM "AdministrativeDivision" as b WHERE b."CodeID" = "ID" AND b."DivisionCode" = "Division" AND b."CodePublisher" = a."CodePublisher" AND b."ParentCodeID" = a."ParentCodeID" AND b."ParentDivisionCode" = a."ParentDivisionCode") AND NOT( a."CodePublisher" = "Publisher" AND a."CodeID" = "ID" AND a."DivisionCode" = "Division" ) ); """; final String sqlPopulationDensity = """ CREATE FUNCTION "OLINGO"."PopulationDensity" (UnitArea BIGINT, Population BIGINT ) RETURNS DOUBLE BEGIN ATOMIC DECLARE areaDouble DOUBLE; DECLARE populationDouble DOUBLE; SET areaDouble = UnitArea; SET populationDouble = Population; IF UnitArea <= 0 THEN RETURN 0; ELSE RETURN populationDouble / areaDouble; END IF; END """; final String sqlConvertToQkm = """ CREATE FUNCTION "OLINGO"."ConvertToQkm" (UnitArea BIGINT ) RETURNS INT IF UnitArea <= 0 THEN RETURN 0; ELSE RETURN UnitArea / 1000 / 1000; END IF """; return Arrays.asList( Optional.of(connection.prepareStatement(sqlSiblings)), Optional.of(connection.prepareStatement(sqlConvertToQkm)), Optional.of(connection.prepareStatement(sqlPopulationDensity))); } private List<Optional<PreparedStatement>> createFunctionHANA(final Connection connection) throws SQLException { final String sql = """ CREATE FUNCTION "OLINGO"."Siblings" ("CodePublisher" VARCHAR(10), "CodeID" VARCHAR(10), "DivisionCode" VARCHAR(10)) RETURNS TABLE ( "CodePublisher" VARCHAR(10), "CodeID" VARCHAR(10), "DivisionCode" VARCHAR(10), "CountryISOCode" VARCHAR(4), "ParentCodeID" VARCHAR(10), "ParentDivisionCode" VARCHAR(10), "AlternativeCode" VARCHAR(10), "Area" BIGINT, "Population" BIGINT) LANGUAGE SQLSCRIPT AS BEGIN RETURN SELECT "CodePublisher", "CodeID", "DivisionCode", "CountryISOCode", "ParentCodeID", "ParentDivisionCode", "AlternativeCode", "Area", "Population" FROM "OLINGO"."AdministrativeDivision" as kids WHERE ("CodePublisher", "ParentCodeID", "ParentDivisionCode") IN (SELECT "CodePublisher", "ParentCodeID", "ParentDivisionCode" FROM "OLINGO"."AdministrativeDivision" WHERE "CodePublisher" = :"CodePublisher" AND "CodeID" = :"CodeID" AND "DivisionCode" = :"DivisionCode" ) AND kids."DivisionCode" <> :"DivisionCode"; END; """; return Arrays.asList(Optional.of(connection.prepareStatement(sql))); } private List<Optional<PreparedStatement>> createFunctionDerby() { return Collections.emptyList(); } private List<Optional<PreparedStatement>> createFunctionH2() { return Collections.emptyList(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/util/Assertions.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/util/Assertions.java
package com.sap.olingo.jpa.processor.core.util; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import org.apache.commons.lang3.builder.EqualsBuilder; import org.junit.jupiter.api.function.Executable; public class Assertions { public static final String CB_ONLY_TEST = "CB_ONLY"; public static <T extends Throwable> void assertException(final Class<T> expectedType, final Executable executable, final String expMessageKey) { assertException(expectedType, executable, expMessageKey, null); } public static <T extends Throwable> void assertException(final Class<T> expectedType, final Executable executable, final String expMessageKey, final Integer expStatusCode) { try { final T act = assertThrows(expectedType, executable); // NOSONAR final List<Method> methods = Arrays.asList(act.getClass().getMethods()); if (hasMethod(methods, "getId")) { final Method getId = act.getClass().getMethod("getId"); assertEquals(expMessageKey, getId.invoke(act)); } if (hasMethod(methods, "getStatusCode")) { final Method statusCode = act.getClass().getMethod("getStatusCode"); assertEquals(expStatusCode, statusCode.invoke(act)); } assertNotNull(act.getMessage()); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); // NOSONAR } } private static boolean hasMethod(final List<Method> methods, final String name) { return methods.stream().filter(m -> m.getName().equals(name)).count() > 0; } public static <T> void assertListEquals(final List<T> exp, final List<T> act, final Class<T> reflection) { assertEquals(exp.size(), act.size()); boolean found; for (final T expItem : exp) { found = false; for (final T actItem : act) { found = EqualsBuilder.reflectionEquals(expItem, actItem, true, reflection); if (found) { break; } } assertTrue(found, "Could not find " + expItem.toString()); } } private Assertions() { super(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/util/TestDataConstants.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/util/TestDataConstants.java
package com.sap.olingo.jpa.processor.core.util; public enum TestDataConstants { NO_ATTRIBUTES_POSTAL_ADDRESS(10), NO_ATTRIBUTES_POSTAL_ADDRESS_T(1), NO_ATTRIBUTES_COMMUNICATION_DATA(4), NO_ATTRIBUTES_CHANGE_INFO(2), NO_ATTRIBUTES_BUSINESS_PARTNER(6), NO_ATTRIBUTES_BUSINESS_PARTNER_T(1), NO_ATTRIBUTES_ORGANIZATION(4), NO_ATTRIBUTES_PERSON(2), NO_DEC_ATTRIBUTES_BUSINESS_PARTNER(9), NO_ENTITY_TYPES(46), NO_ENTITY_SETS(42), NO_SINGLETONS(3), NO_COMPLEX_TYPES(26); public final int value; TestDataConstants(final int i) { value = i; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/util/HttpRequestHeaderDouble.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/util/HttpRequestHeaderDouble.java
package com.sap.olingo.jpa.processor.core.util; import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class HttpRequestHeaderDouble { private final HashMap<String, List<String>> headers; public HttpRequestHeaderDouble() { super(); headers = new HashMap<>(); headers.put("host", Arrays.asList("localhost:8090")); headers.put("connection", Arrays.asList("keep-alive")); headers.put("cache-control", Arrays.asList("max-age=0")); headers.put("accept", Arrays.asList("text/html,application/json,application/xml;q=0.9,image/webp,*/*;q=0.8")); headers.put("accept-encoding", Arrays.asList("gzip, deflate, sdch")); headers.put("accept-language", Arrays.asList("de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4")); } public Enumeration<String> get(final String headerName) { return new HeaderItem(headers.get(headerName)); } public Enumeration<String> getEnumerator() { return new HeaderEnumerator(headers.keySet()); } public void setBatchRequest() { final List<String> headerValue = new ArrayList<>(); headerValue.add("multipart/mixed;boundary=abc123"); headers.put("content-type", headerValue); } public void setHeaders(final Map<String, List<String>> additionalHeaders) { if (additionalHeaders != null) { for (final Entry<String, List<String>> header : additionalHeaders.entrySet()) headers.put(header.getKey(), header.getValue()); } } static class HeaderEnumerator implements Enumeration<String> { // NOSONAR private final Iterator<String> keys; HeaderEnumerator(final Set<String> keySet) { keys = keySet.iterator(); } @Override public boolean hasMoreElements() { return keys.hasNext(); } @Override public String nextElement() { return keys.next(); } } static class HeaderItem implements Enumeration<String> {// NOSONAR private final Iterator<String> keys; public HeaderItem(final List<String> header) { keys = header.iterator(); } @Override public boolean hasMoreElements() { return keys.hasNext(); } @Override public String nextElement() { return keys.next(); } } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/util/ServletInputStreamDouble.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/util/ServletInputStreamDouble.java
package com.sap.olingo.jpa.processor.core.util; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import jakarta.servlet.ReadListener; import jakarta.servlet.ServletInputStream; public class ServletInputStreamDouble extends ServletInputStream { private final InputStream stream; public ServletInputStreamDouble(final ServletInputStream stream) { super(); this.stream = stream; } public ServletInputStreamDouble(final StringBuilder stream) { super(); if (stream != null) this.stream = new ByteArrayInputStream(stream.toString().getBytes(StandardCharsets.UTF_8)); else this.stream = null; } @Override public int read() throws IOException { return stream.read(); } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return true; } @Override public void setReadListener(final ReadListener readListener) { throw new IllegalAccessError(); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/CompoundKey.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/CompoundKey.java
package com.sap.olingo.jpa.processor.core.errormodel; import java.io.Serializable; import java.util.Objects; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; @Embeddable public class CompoundKey implements Serializable { /** * */ private static final long serialVersionUID = -2350388598203342905L; @Column(name = "\"TeamKey\"") private String iD; @Column(name = "\"Name\"") private String name; public CompoundKey() { // Needed for JPA } public CompoundKey(final String iD, final String name) { super(); this.iD = iD; this.name = name; } public String getID() { return iD; } public void setID(final String iD) { this.iD = iD; } public String getName() { return name; } public void setName(final String name) { this.name = name; } public static long getSerialVersionUID() { return serialVersionUID; } @Override public int hashCode() { return Objects.hash(iD, name); } @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final CompoundKey other = (CompoundKey) obj; return Objects.equals(iD, other.iD) && Objects.equals(name, other.name); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/NavigationAttributeProtected.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/NavigationAttributeProtected.java
package com.sap.olingo.jpa.processor.core.errormodel; import java.util.List; import jakarta.persistence.Column; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; import jakarta.persistence.Version; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmProtectedBy; @Entity(name = "NavigationAttributeProtected") @DiscriminatorValue(value = "1") public class NavigationAttributeProtected { @Id @Column(name = "\"ID\"") protected String iD; @Version @Column(name = "\"ETag\"", nullable = false) protected long eTag; @ManyToMany @JoinTable(name = "\"Membership\"", schema = "\"OLINGO\"", joinColumns = @JoinColumn(name = "\"PersonID\""), inverseJoinColumns = @JoinColumn(name = "\"TeamID\"")) @EdmProtectedBy(name = "WrongAnnotation") private List<Team> teams; public String getID() { return iD; } public void setID(final String iD) { this.iD = iD; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((iD == null) ? 0 : iD.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final NavigationAttributeProtected other = (NavigationAttributeProtected) obj; if (iD == null) { if (other.iD != null) return false; } else if (!iD.equals(other.iD)) return false; return true; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/NavigationPropertyPartOfGroup.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/NavigationPropertyPartOfGroup.java
/** * */ package com.sap.olingo.jpa.processor.core.errormodel; import java.util.List; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; import jakarta.persistence.Version; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmVisibleFor; /** * @author Oliver Grande * Created: 29.06.2019 * */ @Entity(name = "NavigationPropertyPartOfGroup") public class NavigationPropertyPartOfGroup { @Id @Column(name = "\"ID\"") protected String iD; @Version @Column(name = "\"ETag\"", nullable = false) protected long eTag; @ManyToMany @JoinTable(name = "\"Membership\"", schema = "\"OLINGO\"", joinColumns = @JoinColumn(name = "\"PersonID\""), inverseJoinColumns = @JoinColumn(name = "\"TeamID\"")) @EdmVisibleFor("Person") private List<Team> teams; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/ChangeInformation.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/ChangeInformation.java
package com.sap.olingo.jpa.processor.core.errormodel; import java.util.Date; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; @Embeddable public class ChangeInformation { @Column private String by; @Column(precision = 9) @Temporal(TemporalType.TIMESTAMP) private Date at; String user; public ChangeInformation() {} public ChangeInformation(final String by, final Date at) { super(); this.by = by; this.at = at; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/EmbeddedKeyPartOfGroup.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/EmbeddedKeyPartOfGroup.java
/** * */ package com.sap.olingo.jpa.processor.core.errormodel; import jakarta.persistence.Column; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; import jakarta.persistence.Version; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmVisibleFor; import com.sap.olingo.jpa.processor.core.testmodel.CountryKey; /** * @author Oliver Grande * Created: 29.06.2019 * */ @Entity public class EmbeddedKeyPartOfGroup { @EdmVisibleFor("Person") @EmbeddedId private CountryKey key; @Version @Column(name = "\"ETag\"", nullable = false) protected long eTag; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/DummyPropertyCalculator.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/DummyPropertyCalculator.java
/** * */ package com.sap.olingo.jpa.processor.core.errormodel; import java.util.Arrays; import java.util.List; import jakarta.persistence.EntityManager; import jakarta.persistence.Tuple; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransientPropertyCalculator; /** * @author Oliver Grande * Created: 17.03.2020 * */ public class DummyPropertyCalculator implements EdmTransientPropertyCalculator<String> { private final EntityManager em; public DummyPropertyCalculator(final EntityManager em) { super(); this.em = em; } public EntityManager getEntityManager() { return em; } @Override public List<String> calculateCollectionProperty(final Tuple row) { return Arrays.asList("Hello", "World"); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/Team.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/Team.java
package com.sap.olingo.jpa.processor.core.errormodel; import java.util.List; import java.util.Objects; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.ManyToMany; import jakarta.persistence.Table; @Entity(name = "ErrorTeam") @Table(schema = "\"OLINGO\"", name = "\"Team\"") public class Team { @Id @Column(name = "\"TeamKey\"") private String iD; @Column(name = "\"Name\"") private String name; @ManyToMany(mappedBy = "teams") private List<NavigationAttributeProtected> member; public String getID() { return iD; } public void setID(final String iD) { this.iD = iD; } public String getName() { return name; } public void setName(final String name) { this.name = name; } public List<NavigationAttributeProtected> getMember() { return member; } public void setMember(final List<NavigationAttributeProtected> member) { this.member = member; } @Override public int hashCode() { return Objects.hash(iD, member, name); } @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final Team other = (Team) obj; return Objects.equals(iD, other.iD) && Objects.equals(member, other.member) && Objects.equals(name, other.name); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/ComplexProtectedWrongPath.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/ComplexProtectedWrongPath.java
package com.sap.olingo.jpa.processor.core.errormodel; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.Version; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmProtectedBy; @Entity @Table(schema = "\"OLINGO\"", name = "\"BusinessPartner\"") public class ComplexProtectedWrongPath { @Id @Column(name = "\"ID\"") protected String iD; @Version @Column(name = "\"ETag\"", nullable = false) protected long eTag; @Embedded @EdmProtectedBy(name = "UserId", path = "created/wrong") private final AdministrativeInformation administrativeInformation = new AdministrativeInformation(); @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((iD == null) ? 0 : iD.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final ComplexProtectedWrongPath other = (ComplexProtectedWrongPath) obj; if (iD == null) { if (other.iD != null) return false; } else if (!iD.equals(other.iD)) return false; return true; } public String getID() { return iD; } public void setID(final String iD) { this.iD = iD; } public long getETag() { return eTag; } public void setETag(final long eTag) { this.eTag = eTag; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/AdministrativeInformation.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/AdministrativeInformation.java
package com.sap.olingo.jpa.processor.core.errormodel; import java.sql.Timestamp; import java.util.Date; import jakarta.persistence.AttributeOverride; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import jakarta.persistence.Embedded; import jakarta.persistence.PrePersist; import jakarta.persistence.PreUpdate; @Embeddable public class AdministrativeInformation { @Embedded @AttributeOverride(name = "by", column = @Column(name = "\"CreatedBy\"")) @AttributeOverride(name = "at", column = @Column(name = "\"CreatedAt\"")) private ChangeInformation created; @Embedded @AttributeOverride(name = "by", column = @Column(name = "\"UpdatedBy\"")) @AttributeOverride(name = "at", column = @Column(name = "\"UpdatedAt\"")) private ChangeInformation updated; public ChangeInformation getCreated() { return created; } public ChangeInformation getUpdated() { return updated; } public void setCreated(final ChangeInformation created) { this.created = created; } public void setUpdated(final ChangeInformation updated) { this.updated = updated; } @PrePersist void onCreate() { created = new ChangeInformation("99", new Timestamp(new Date().getTime())); } @PreUpdate void onUpdate() { updated = new ChangeInformation("99", new Timestamp(new Date().getTime())); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/ComplexProtectedNoPath.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/ComplexProtectedNoPath.java
package com.sap.olingo.jpa.processor.core.errormodel; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.Version; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmProtectedBy; @Entity @Table(schema = "\"OLINGO\"", name = "\"BusinessPartner\"") public class ComplexProtectedNoPath { @Id @Column(name = "\"ID\"") protected String iD; @Version @Column(name = "\"ETag\"", nullable = false) protected long eTag; @Embedded @EdmProtectedBy(name = "UserId") private final AdministrativeInformation administrativeInformation = new AdministrativeInformation(); @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((iD == null) ? 0 : iD.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final ComplexProtectedNoPath other = (ComplexProtectedNoPath) obj; if (iD == null) { if (other.iD != null) return false; } else if (!iD.equals(other.iD)) return false; return true; } public String getID() { return iD; } public long getETag() { return eTag; } public void setID(final String iD) { this.iD = iD; } public void setETag(final long eTag) { this.eTag = eTag; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/KeyPartOfGroup.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/KeyPartOfGroup.java
/** * */ package com.sap.olingo.jpa.processor.core.errormodel; import java.util.Objects; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Version; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmVisibleFor; /** * @author Oliver Grande * Created: 29.06.2019 * */ @Entity public class KeyPartOfGroup { @Id @EdmVisibleFor("Person") @Column(name = "\"ID\"") protected String iD; @Version @Column(name = "\"ETag\"", nullable = false) protected long eTag; public String getID() { return iD; } public void setID(final String iD) { this.iD = iD; } public long getETag() { return eTag; } public void setETag(final long eTag) { this.eTag = eTag; } @Override public int hashCode() { return Objects.hash(eTag, iD); } @Override public boolean equals(final Object obj) { if (obj instanceof final KeyPartOfGroup other) return eTag == other.eTag && Objects.equals(iD, other.iD); return false; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TeamWithTransientCalculatorError.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TeamWithTransientCalculatorError.java
package com.sap.olingo.jpa.processor.core.errormodel; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransient; @Entity(name = "TeamWithTransientCalculatorError") @Table(schema = "\"OLINGO\"", name = "\"Team\"") public class TeamWithTransientCalculatorError { @Id @Column(name = "\"TeamKey\"") private String iD; @Column(name = "\"Name\"") private String name; @EdmTransient(requiredAttributes = { "name" }, calculator = TransientPropertyCalculatorTwoConstructors.class) private String completeName; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TeamWithTransientKey.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TeamWithTransientKey.java
package com.sap.olingo.jpa.processor.core.errormodel; import java.util.Objects; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.IdClass; import jakarta.persistence.Table; import jakarta.persistence.Transient; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransient; @IdClass(CompoundKey.class) @Entity(name = "TeamWithTransientKey") @Table(schema = "\"OLINGO\"", name = "\"Team\"") public class TeamWithTransientKey { @Id @Column(name = "\"TeamKey\"") private String iD; @Id @Transient @EdmTransient(calculator = DummyPropertyCalculator.class) private String name; @Override public int hashCode() { return Objects.hash(iD, name); } @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final TeamWithTransientKey other = (TeamWithTransientKey) obj; return Objects.equals(iD, other.iD) && Objects.equals(name, other.name); } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/CollectionAttributeProtected.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/CollectionAttributeProtected.java
package com.sap.olingo.jpa.processor.core.errormodel; import java.util.ArrayList; import java.util.List; import jakarta.persistence.CollectionTable; import jakarta.persistence.Column; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.ElementCollection; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.Version; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmProtectedBy; import com.sap.olingo.jpa.processor.core.testmodel.InhouseAddress; @Entity(name = "CollectionAttributeProtected") @DiscriminatorValue(value = "1") public class CollectionAttributeProtected { @Id @Column(name = "\"ID\"") protected String iD; @Version @Column(name = "\"ETag\"", nullable = false) protected long eTag; @ElementCollection(fetch = FetchType.LAZY) @CollectionTable(schema = "\"OLINGO\"", name = "\"InhouseAddress\"", joinColumns = @JoinColumn(name = "\"ParentID\"")) @EdmProtectedBy(name = "WrongAnnotation") private List<InhouseAddress> inhouseAddress = new ArrayList<>(); public String getID() { return iD; } public void setID(final String iD) { this.iD = iD; } public List<InhouseAddress> getInhouseAddress() { return inhouseAddress; } public void setInhouseAddress(final List<InhouseAddress> inhouseAddress) { this.inhouseAddress = inhouseAddress; } public void addInhouseAddress(final InhouseAddress address) { inhouseAddress.add(address); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((iD == null) ? 0 : iD.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final CollectionAttributeProtected other = (CollectionAttributeProtected) obj; if (iD == null) { if (other.iD != null) return false; } else if (!iD.equals(other.iD)) return false; return true; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TeamWithTransientEmbeddableKey.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TeamWithTransientEmbeddableKey.java
package com.sap.olingo.jpa.processor.core.errormodel; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; import jakarta.persistence.Table; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransient; @Entity(name = "TeamWithTransientEmbeddableKey") @Table(schema = "\"OLINGO\"", name = "\"Team\"") public class TeamWithTransientEmbeddableKey { @EmbeddedId @EdmTransient(calculator = DummyPropertyCalculator.class) private CompoundKey key; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TransientPropertyCalculatorWrongConstructor.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TransientPropertyCalculatorWrongConstructor.java
/** * */ package com.sap.olingo.jpa.processor.core.errormodel; import jakarta.persistence.EntityManager; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransientPropertyCalculator; /** * @author Oliver Grande * Created: 17.03.2020 * */ public class TransientPropertyCalculatorWrongConstructor implements EdmTransientPropertyCalculator<String> { private final EntityManager em; private final String dummy; public TransientPropertyCalculatorWrongConstructor(final EntityManager em, final String dummy) { super(); this.em = em; this.dummy = dummy; } public EntityManager getEntityManager() { return em; } public String getDummy() { return dummy; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/MissingCardinalityAnnotation.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/MissingCardinalityAnnotation.java
package com.sap.olingo.jpa.processor.core.errormodel; import java.util.List; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; @Entity() public class MissingCardinalityAnnotation { @Id @Column(name = "\"ID\"") protected String id; @JoinTable(name = "\"Membership\"", schema = "\"OLINGO\"", joinColumns = @JoinColumn(name = "\"PersonID\""), inverseJoinColumns = @JoinColumn(name = "\"TeamID\"")) private List<Team> teams; @JoinColumn(name = "\"TeamKey\"") private Team oneTeam; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/MandatoryPartOfGroup.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/MandatoryPartOfGroup.java
/** * */ package com.sap.olingo.jpa.processor.core.errormodel; import java.util.List; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; import jakarta.persistence.Version; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmVisibleFor; /** * @author Oliver Grande * Created: 29.06.2019 * */ @Entity() public class MandatoryPartOfGroup { @Id @Column(name = "\"ID\"") protected String iD; @Version @EdmVisibleFor("Person") @Column(name = "\"ETag\"", nullable = false) protected long eTag; @ManyToMany @JoinTable(name = "\"Membership\"", schema = "\"OLINGO\"", joinColumns = @JoinColumn(name = "\"PersonID\""), inverseJoinColumns = @JoinColumn(name = "\"TeamID\"")) private List<Team> teams; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TransientPropertyCalculatorTwoConstructors.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TransientPropertyCalculatorTwoConstructors.java
/** * */ package com.sap.olingo.jpa.processor.core.errormodel; import jakarta.persistence.EntityManager; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransientPropertyCalculator; /** * @author Oliver Grande<br> * Created: 17.03.2020 * */ public class TransientPropertyCalculatorTwoConstructors implements EdmTransientPropertyCalculator<String> { private final EntityManager em; public TransientPropertyCalculatorTwoConstructors() { super(); this.em = null; } public TransientPropertyCalculatorTwoConstructors(final EntityManager em) { super(); this.em = em; } public EntityManager getEntityManager() { return em; } }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false
SAP/olingo-jpa-processor-v4
https://github.com/SAP/olingo-jpa-processor-v4/blob/c6fddac331f51f37fd9e4b46aa6bf7ab256c386b/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TeamWithTransientError.java
jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/errormodel/TeamWithTransientError.java
package com.sap.olingo.jpa.processor.core.errormodel; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmTransient; @Entity(name = "TeamWithTransientError") @Table(schema = "\"OLINGO\"", name = "\"Team\"") public class TeamWithTransientError { @Id @Column(name = "\"TeamKey\"") private String iD; @Column(name = "\"Name\"") private String name; @EdmTransient(requiredAttributes = { "name", "unknown" }, calculator = DummyPropertyCalculator.class) private String completeName; }
java
Apache-2.0
c6fddac331f51f37fd9e4b46aa6bf7ab256c386b
2026-01-05T02:41:58.937563Z
false