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;
 
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
 
The abstract class of entity.

Author(s):
jflute
Since:
1.1.0 (2014/10/19 Sunday)
 
 public abstract class AbstractEntity implements EntityDerivedMappableSerializableCloneable {
 
     // ===================================================================================
     //                                                                          Definition
     //                                                                          ==========
     
The serial version UID for object serialization. (Default)
 
     private static final long serialVersionUID = 1L;
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     // -----------------------------------------------------
     //                                              Internal
     //                                              --------
     
The unique-driven properties for this entity. (NotNull)
 
The modified properties for this entity. (NotNull)
 
     protected final EntityModifiedProperties __modifiedProperties = newModifiedProperties();

    
The modified properties for this entity. (NullAllowed: normally null, created when specified-check)
 
     protected EntityModifiedProperties __specifiedProperties;

    
The map of derived value, key is alias name. (NullAllowed: lazy-loaded)
 
     protected EntityDerivedMap __derivedMap;

    
Does it allow selecting undefined classification code? {Internal}
 
     protected boolean _undefinedClassificationSelectAllowed;

    
Is the entity created by DBFlute select process?
 
     protected boolean __createdBySelect;
 
     // ===================================================================================
     //                                                                    Derived Mappable
     //                                                                    ================
     
 
     public void registerDerivedValue(String aliasNameObject selectedValue) {
         if ( == null) {
              = newDerivedMap();
         }
         .registerDerivedValue(aliasNameselectedValue);
     }

    

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.
 
     public <VALUE> OptionalScalar<VALUE> derived(String aliasNameClass<VALUE> propertyType) {
         if ( == null) {
             // process of finding has existence check of the alias
             // so if called here, exception in the map
              = newDerivedMap();
         }
        return .findDerivedValue(thisaliasNamepropertyType);
    }
    protected EntityDerivedMap newDerivedMap() {
        return new EntityDerivedMap();
    }
    // ===================================================================================
    //                                                                 Modified Properties
    //                                                                 ===================
    // -----------------------------------------------------
    //                                              Modified
    //                                              --------
    
    public Set<StringmymodifiedProperties() {
        return .getPropertyNames();
    }

    
    public void mymodifyProperty(String propertyName) {
        registerModifiedProperty(propertyName);
    }

    
    public void mymodifyPropertyCancel(String propertyName) {
        .remove(propertyName);
    }

    
    public void clearModifiedInfo() {
        .clear();
    }

    
    public boolean hasModification() {
        return !.isEmpty();
    }
        return new EntityModifiedProperties();
    }
    protected void registerModifiedProperty(String propertyName) {
        .addPropertyName(propertyName);
        registerSpecifiedProperty(propertyName); // synchronize if exists, basically for user's manual call
    }
    // -----------------------------------------------------
    //                                             Specified
    //                                             ---------
    
    public void modifiedToSpecified() {
        if (.isEmpty()) {
            return// basically no way when called in Framework (because called when SpecifyColumn exists)
        }
    }

    
    public Set<StringmyspecifiedProperties() {
        if ( != null) {
            return .getPropertyNames();
        }
        return DfCollectionUtil.emptySet();
    }

    
    public void myspecifyProperty(String propertyName) {
        registerSpecifiedProperty(propertyName);
    }

    
    public void myspecifyPropertyCancel(String propertyName) {
        if ( != null) {
            .remove(propertyName);
        }
    }

    
    public void clearSpecifiedInfo() {
        if ( != null) {
            .clear();
        }
    }
    protected void checkSpecifiedProperty(String propertyName) {
        FunCustodial.checkSpecifiedProperty(thispropertyName);
    }
    protected void registerSpecifiedProperty(String propertyName) { // basically called by modified property registration
        if ( != null) { // normally false, true if e.g. setting after selected
            .addPropertyName(propertyName);
        }
    }
    // ===================================================================================
    //                                                                        Key Handling
    //                                                                        ============
    
    public Set<StringmyuniqueDrivenProperties() {
    }
        return new EntityUniqueDrivenProperties();
    }

    
    public void myuniqueByProperty(String propertyName) {
        .addPropertyName(propertyName);
    }

    
    public void myuniqueByPropertyCancel(String propertyName) {
        .remove(propertyName);
    }

    
    public void clearUniqueDrivenInfo() {
    }
    // ===================================================================================
    //                                                                      Classification
    //                                                                      ==============
    protected <NUMBER extends Number> NUMBER toNumber(Object objClass<NUMBER> type) {
        return FunCustodial.toNumber(objtype);
    }
    protected Boolean toBoolean(Object obj) {
        return FunCustodial.toBoolean(obj);
    }
    protected void checkClassificationCode(String columnDbNameClassificationMeta metaObject value) {
        FunCustodial.checkClassificationCode(thiscolumnDbNamemetavalue); // undefined handling is here
    }

    
    public void myunlockUndefinedClassificationAccess() {
    }

    
    public boolean myundefinedClassificationAccessAllowed() {
    }
    // ===================================================================================
    //                                                                     Birthplace Mark
    //                                                                     ===============
    
    public void markAsSelect() {
         = true;
    }

    
    public boolean createdBySelect() {
        return ;
    }
    // ===================================================================================
    //                                                                   Referrer Property
    //                                                                   =================
    protected <ELEMENT> List<ELEMENT> newReferrerList() {
        return new ArrayList<ELEMENT>();
    }
    // ===================================================================================
    //                                                                        Empty String
    //                                                                        ============
    protected String convertEmptyToNull(String value) {
        return FunCustodial.convertEmptyToNull(value);
    }
    // ===================================================================================
    //                                                                      Basic Override
    //                                                                      ==============
    // -----------------------------------------------------
    //                                              equals()
    //                                              --------
    
Determine the object is equal with this.
If primary-keys or columns of the other are same as this one, returns true.

Parameters:
obj The object as other entity. (NullAllowed: if null, returns false fixedly)
Returns:
Comparing result.
    public boolean equals(Object obj) {
        return obj != null && doEquals(obj);
    }

    

Parameters:
obj The object as other entity. (NotNull)
Returns:
The determination, true or false.
    protected abstract boolean doEquals(Object obj);
    protected boolean xSV(Object v1Object v2) {
        return FunCustodial.isSameValue(v1v2);
    }
    // -----------------------------------------------------
    //                                            hashCode()
    //                                            ----------
    
Calculate the hash-code from primary-keys or columns.

Returns:
The hash-code from primary-key or columns.
    public int hashCode() {
        return doHashCode(17);
    }

    

Parameters:
initial The initial value to calculate hash-code.
Returns:
The calculated hash-code.
    protected abstract int doHashCode(int initial);
    protected int xCH(int hsObject vl) {
        return FunCustodial.calculateHashcode(hsvl);
    }

    
    public int instanceHash() {
        return super.hashCode();
    }
    // -----------------------------------------------------
    //                                            toString()
    //                                            ----------
    
Convert to display string of entity's data. (no relation data)

Returns:
The display string of all columns and relation existences. (NotNull)
    @Override
    public String toString() {
        return buildDisplayString(FunCustodial.toClassTitle(this), truetrue);
    }
    protected String xbRDS(Entity etString name) { // buildRelationDisplayString()
        // another overload method exists in template
        return et.buildDisplayString(nametruetrue);
    }

    
    public String toStringWithRelation() {
        final StringBuilder sb = new StringBuilder();
        sb.append(toString());
        sb.append(doBuildStringWithRelation("\n  ")); // line and two spaces indent
        return sb.toString();
    }
    protected abstract String doBuildStringWithRelation(String li);

    
    public String buildDisplayString(String nameboolean columnboolean relation) {
        StringBuilder sb = new StringBuilder();
        if (name != null) {
            sb.append(name).append(column || relation ? ":" : "");
        }
        if (column) {
            sb.append(doBuildColumnString(", ")); // e.g. 1, Stojkovic, Pixy, ...
        }
        if (relation) {
            sb.append(doBuildRelationString(",")); // e.g. (memberStatus,memberServiceAsOne)
        }
        sb.append("@").append(Integer.toHexString(hashCode()));
        return sb.toString();
    }
    protected abstract String doBuildColumnString(String dm);
    protected abstract String doBuildRelationString(String dm);
    protected String xfUD(Date date) { // formatUtilDate()
        return FunCustodial.toStringDate(datemytimeZone(), myutilDatePattern());
    }
    protected String myutilDatePattern() {
        // actually, Oracle's date needs time-parts
        // but not important point and LocalDate is main since 1.1
        // so simple logic here
        return .// as default
    }
    protected TimeZone mytimeZone() {
        return null// as default
    }
    protected String xfBA(byte[] bytes) { // formatByteArray()
        return FunCustodial.toStringBytes(bytes);
    }
    protected Object xfND(Object obj) { // formatNormalData()
        if (obj == null) {
            return null;
        }
        if (!(obj instanceof String)) {
            return obj;
        }
        String filteredStr = (Stringobj;
        filteredStr = mycutLargeStringForToString(filteredStr);
        filteredStr = myremoveLineSepForToString(filteredStr);
        return filteredStr;
    }
    protected String mycutLargeStringForToString(String filteredStr) {
        final int actualSize = filteredStr.length();
        final int limit = mylargeStringForToStringLimit();
        if (actualSize > limit) {
            // e.g. {sea, land, long text now...(length:182), iks, amphi}
            filteredStr = Srl.cut(filteredStrlimit) + "...(length:" + actualSize + ")";
        }
        return filteredStr;
    }
    protected int mylargeStringForToStringLimit() {
        return 140;
    }
    protected String myremoveLineSepForToString(String filteredStr) {
        final String cr = "\r";
        final String lf = "\n";
        if (Srl.containsAny(filteredStrcrlf)) {
            return Srl.replace(Srl.replace(filteredStrcr"\\r"), lf"\\n"); // remove lines
        }
        return filteredStr;
    }
    // -----------------------------------------------------
    //                                               clone()
    //                                               -------
    
Clone entity instance using super.clone(). (shallow copy)

Returns:
The cloned instance of this entity. (NotNull)
Throws:
java.lang.IllegalStateException When it fails to clone the entity.
    @Override
    public Entity clone() {
        try {
            return (Entitysuper.clone();
        } catch (CloneNotSupportedException e) {
            throw new IllegalStateException("Failed to clone the entity: " + toString(), e);
        }
    }
New to GrepCode? Check out our FAQ X