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.s2dao.metadata.impl;
 
 import java.util.List;
 

Author(s):
modified by jflute (originated in S2Dao)
 
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     protected final int _relationNo;
     protected final String _relationNoSuffixPart;
     protected final String[] _myKeys;
     protected final String[] _yourKeys;
     protected final TnBeanMetaData _myBeanMetaData;
     protected final TnBeanMetaData _yourBeanMetaData;
     protected final List<TnPropertyType_uniquePropertyTypeList;
     protected final boolean _hasSimpleUniqueKey;
     protected final boolean _hasCompoundUniqueKey;
     protected final TnPropertyType _simpleUniquePropertyType;
     protected final DfPropertyAccessor _propertyAccessor;
 
     // ===================================================================================
     //                                                                         Constructor
     //                                                                         ===========
     public TnRelationPropertyTypeImpl(final DfPropertyDesc propertyDescint relationNoString[] myKeysString[] yourKeys,
             TnBeanMetaData myBeanMetaDataTnBeanMetaData yourBeanMetaData) {
         super(propertyDesc);
          = relationNo;
          = buildRelationNoSuffixPart(relationNo);
          = myKeys;
          = yourKeys;
          = myBeanMetaData;
          = yourBeanMetaData;
          = deriveUniqueKeys(yourKeysyourBeanMetaData);
 
         // save at this point for performance (suppose that many relation has the only one key)
          = .size() == 1;
          = .size() >= 2;
          = createPropertyAccessor(propertyDescmyBeanMetaData);
     }
 
     protected String buildRelationNoSuffixPart(int relationNo) {
         return . + relationNo;
     }
 
     protected List<TnPropertyTypederiveUniqueKeys(String[] yourKeysTnBeanMetaData yourBeanMetaData) {
         final DBMeta dbmeta = yourBeanMetaData.getDBMeta();
         final List<TnPropertyTypeuniquePropertyTypeList;
         if (dbmeta != null && dbmeta.hasPrimaryKey()) {
             final PrimaryInfo primaryInfo = dbmeta.getPrimaryInfo();
             final List<ColumnInfoprimaryColumnList = primaryInfo.getPrimaryColumnList();
             uniquePropertyTypeList = new ArrayList<TnPropertyType>(primaryColumnList.size());
             for (ColumnInfo pk : primaryColumnList) {
                 final TnPropertyType pt = yourBeanMetaData.getPropertyTypeByColumnName(pk.getColumnDbName());
                 uniquePropertyTypeList.add(pt);
             }
         } else {
             uniquePropertyTypeList = new ArrayList<TnPropertyType>(yourKeys.length);
             for (String yourKey : yourKeys) {
                 final TnPropertyType pt = yourBeanMetaData.getPropertyTypeByColumnName(yourKey);
                 uniquePropertyTypeList.add(pt);
             }
         }
         return uniquePropertyTypeList;
     }
 
     protected DfPropertyAccessor createPropertyAccessor(final DfPropertyDesc propertyDescTnBeanMetaData myBeanMetaData) {
        final DBMeta dbmeta = myBeanMetaData.getDBMeta();
        final String propertyName = propertyDesc.getPropertyName();
        final ForeignInfo foreignInfo = dbmeta.hasForeign(propertyName) ? dbmeta.findForeignInfo(propertyName) : null;
        return new DfPropertyAccessor() {
            public String getPropertyName() {
                return foreignInfo != null ? foreignInfo.getForeignPropertyName() : propertyName;
            }
            public Class<?> getPropertyType() {
                return foreignInfo != null ? foreignInfo.getPropertyAccessType() : propertyDesc.getPropertyType();
            }
            public Class<?> getGenericType() {
                return propertyDesc.getGenericType();
            }
            public Object getValue(Object target) {
                if (foreignInfo != null && target instanceof Entity) { // basically here
                    return foreignInfo.read((Entitytarget);
                } else {
                    return propertyDesc.getValue(target);
                }
            }
            public void setValue(Object targetObject value) {
                if (foreignInfo != null && target instanceof Entity) { // basically here
                    foreignInfo.write((Entitytargetvalue);
                } else {
                    propertyDesc.setValue(targetvalue);
                }
            }
            public boolean isReadable() {
                return propertyDesc.isReadable();
            }
            public boolean isWritable() {
                return propertyDesc.isWritable();
            }
        };
    }
    // ===================================================================================
    //                                                                            Accessor
    //                                                                            ========
    public int getRelationNo() {
        return ;
    }
    public String getRelationNoSuffixPart() {
        return ;
    }
    public int getKeySize() {
        if (. > 0) {
            return .;
        } else {
            return .getPrimaryKeySize();
        }
    }
    public String getMyKey(int index) {
        if (. > 0) {
            return [index];
        } else {
            return .getPrimaryKeyDbName(index);
        }
    }
    public String getYourKey(int index) {
        if (. > 0) {
            return [index];
        } else {
            return .getPrimaryKeyDbName(index);
        }
    }
    public boolean isYourKey(String columnName) {
        for (int i = 0; i < getKeySize(); ++i) {
            if (columnName.equalsIgnoreCase(getYourKey(i))) {
                return true;
            }
        }
        return false;
    }
    public TnBeanMetaData getMyBeanMetaData() {
        return ;
    }
        return ;
    }
        return ;
    }
    public boolean hasSimpleUniqueKey() {
        return ;
    }
    public boolean hasCompoundUniqueKey() {
        return ;
    }
        return ;
    }
    @Override
        return ;
    }
New to GrepCode? Check out our FAQ X