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

org.dbflute.dbmeta.accessory.DerivedMappable Maven / Gradle / Ivy

There is a newer version: 1.2.8
Show newest version
/*
 * Copyright 2014-2019 the original author or authors.
 *
 * 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 org.dbflute.dbmeta.accessory;

import org.dbflute.exception.SpecifyDerivedReferrerInvalidAliasNameException;
import org.dbflute.exception.SpecifyDerivedReferrerUnknownAliasNameException;
import org.dbflute.exception.SpecifyDerivedReferrerUnmatchedPropertyTypeException;
import org.dbflute.optional.OptionalScalar;

/**
 * The interface of derived mappable object (basically entity), for (Specify)DerivedReferrer.
 * @author jflute
 * @since 1.0.5J (2014/06/18 Wednesday)
 */
public interface DerivedMappable {

    /** The prefix mark for derived mapping alias. */
    String MAPPING_ALIAS_PREFIX = "$";

    /**
     * Register value derived by (Specify)DerivedReferrer.
     * @param aliasName The alias name of derived-referrer. (NotNull)
     * @param selectedValue The selected value from database. (NullAllowed)
     */
    void registerDerivedValue(String aliasName, Object selectedValue);

    /**
     * Find the derived value from derived map by alias name (starts with '$'). 
* It needs to downcast process for getting the value so don't mistake it.s *
     * mapping type:
     *  count()      : Integer
     *  max(), min() : (same as property type of the column)
     *  sum(), avg() : BigDecimal
     *
     * e.g. use count()
     *  member.derived("$LOGIN_COUNT", Integer.class).alwaysPresent(loginCount -> {
     *      log(loginCount.getClass()); // is Integer
     *      ...
     *  });
     *
     * e.g. use max()
     *  member.derived("$LATEST_PURCHASE_DATETIME", LocalDateTime.class).ifPresent(latestPurchaseDatetime -> {
     *      log(latestPurchaseDatetime.getClass()); // is LocalDateTime
     *      ...
     *  });
     *
     * e.g. overview
     *  String highestAlias = "$HIGHEST_PURCHASE_PRICE";
     *  memberBhv.selectEntity(cb -> {
     *      cb.specify().derivedPurchase().max(purchaseCB -> {
     *          purchaseCB.specify().columnPurchasePrice();
     *          purchaseCB.query()...
     *      }, highestAlias);
     *      cb.query().setMemberId_Equal(1);
     *      ...
     *  }).alwaysPresent(member -> {
     *      ... = member.getMemberName();
     *      member.derived(highestAlias, Integer.class).ifPresent(highestPurchasePrice -> {
     *          log(highestPurchasePrice);
     *          ...
     *      });
     *  });
     * 
* @param The type of the value. * @param aliasName The alias name of derived-referrer, should start with '$'. (NotNull) * @param propertyType The type of the derived property, should match as rule. (NotNull) * @return The optional property for derived value found in the map. (NotNull, EmptyAllowed: when null selected) * @throws SpecifyDerivedReferrerInvalidAliasNameException When the alias name does not start with '$'. * @throws SpecifyDerivedReferrerUnknownAliasNameException When the alias name is unknown, no derived. * @throws SpecifyDerivedReferrerUnmatchedPropertyTypeException When the property type is unmatched with actual type. */ OptionalScalar derived(String aliasName, Class propertyType); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy