Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2014-2015 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;
The interface of derived mappable object (basically entity), for (Specify)DerivedReferrer.

Author(s):
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.

Parameters:
aliasName The alias name of derived-referrer. (NotNull)
selectedValue The selected value from database. (NullAllowed)
    void registerDerivedValue(String aliasNameObject 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);
          ...
      });
  });
 

Parameters:
<VALUE> The type of the value.
aliasName The alias name of derived-referrer, should start with '$'. (NotNull)
propertyType The type of the derived property, should match as rule. (NotNull)
Returns:
The optional property for derived value found in the map. (NotNull, EmptyAllowed: when null selected)
Throws:
org.dbflute.exception.SpecifyDerivedReferrerInvalidAliasNameException When the alias name does not start with '$'.
org.dbflute.exception.SpecifyDerivedReferrerUnknownAliasNameException When the alias name is unknown, no derived.
org.dbflute.exception.SpecifyDerivedReferrerUnmatchedPropertyTypeException When the property type is unmatched with actual type.
    <VALUE> OptionalScalar<VALUE> derived(String aliasNameClass<VALUE> propertyType);
New to GrepCode? Check out our FAQ X