All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.blazebit.persistence.view.Mapping Maven / Gradle / Ivy

There is a newer version: 1.6.14
Show newest version
/*
 * Copyright 2014 - 2019 Blazebit.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.blazebit.persistence.view;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * A mapping to a JPQL expression which contains references to fields of the entity.
 * The {@linkplain Mapping} annotation can be applied to abstract getter methods of an interface or abstract class. It may also be applied to constructor parameters.
 *
 * The use of the {@linkplain Mapping} annotation is optional for getter methods. If the {@linkplain Mapping} annotation is not
 * specified for such a getter, the default values of the {@linkplain Mapping} annotation will apply. This means that getter
 * methods are automatically mapped to their attribute names.
 *
 * 
 * Example 1:
 *
 * public String getName();
 *
 * Example 2:
 *
 * {@literal @}Mapping("UPPER(name)")
 * public String getUpperName();
 *
 * 
 *
 * Example 1 shows a getter which is implicitly mapped to the attribute name which in this case is "name".
 * Example 2 shows that a mapping can contain arbitrary JPQL expressions.
 *
 * @author Christian Beikov
 * @since 1.0.0
 */
@Target({ ElementType.METHOD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface Mapping {

    /**
     * The JPQL expression mapping the annotated getter or parameter should map to.
     *
     * @return The JPQL expression mapping
     */
    String value() default "";

    /**
     * The associations of the entity that should be fetched.
     * This is only valid if the mapping refers to an entity and is mapped as attribute with the original type.
     *
     * @return The JPQL expression mapping
     * @since 1.2.0
     */
    String[] fetches() default {};

    /**
     * The fetch strategy to use for the attribute.
     *
     * @return The fetch strategy
     */
    FetchStrategy fetch() default FetchStrategy.JOIN;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy