Search in sources :

Example 41 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class SelectNextValCommand method doPrepareSequenceCache.

protected String doPrepareSequenceCache(String sql, SequenceCache sequenceCache, Integer incrementSize, Integer cacheSize) {
    if (sequenceCache != null) {
        final DBMeta dbmeta = _dbmeta;
        if (incrementSize != null) {
            assertIncrementSizeNotMinusAndNotZero(incrementSize, dbmeta);
            // cacheSize is not null here because the sequence cache has been found
            sql = _sequenceCacheHandler.filterNextValSql(cacheSize, incrementSize, sql);
        }
    }
    return sql;
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta)

Example 42 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class InsertEntityCommand method createNonPrimaryInsertSqlExecution.

/**
 * @param bmd The meta data of bean. (NotNull)
 * @return Whether the method is target. (For example if it has primary key, returns false.)
 */
protected SqlExecution createNonPrimaryInsertSqlExecution(TnBeanMetaData bmd) {
    final DBMeta dbmeta = findDBMeta();
    if (dbmeta.hasPrimaryKey()) {
        return null;
    }
    final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
    final StringBuilder columnDefSb = new StringBuilder();
    for (org.dbflute.dbmeta.info.ColumnInfo columnInfo : columnInfoList) {
        columnDefSb.append(", ").append(columnInfo.getColumnSqlName());
    }
    columnDefSb.delete(0, ", ".length()).insert(0, "(").append(")");
    final StringBuilder columnValuesSb = new StringBuilder();
    for (org.dbflute.dbmeta.info.ColumnInfo columnInfo : columnInfoList) {
        columnValuesSb.append(", /*pmb.").append(columnInfo.getPropertyName()).append("*/null");
    }
    columnValuesSb.delete(0, ", ".length()).insert(0, "(").append(")");
    final String sql = "insert into " + dbmeta.getTableSqlName() + columnDefSb + " values" + columnValuesSb;
    return createOutsideSqlExecuteExecution(_entity.getClass(), sql);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 43 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class SelectCBExecution method processPagingSelectAndQuerySplit.

// ===================================================================================
// Paging Select and Query Split
// =============================
protected Object processPagingSelectAndQuerySplit(Object[] args, ConditionBean cb) {
    if (!cb.canPagingSelectAndQuerySplit()) {
        return null;
    }
    if (!cb.isFetchScopeEffective()) {
        return null;
    }
    final DBMeta dbmeta = cb.asDBMeta();
    final PrimaryInfo primaryInfo = dbmeta.getPrimaryInfo();
    if (primaryInfo.isCompoundKey()) {
        // basically no way, already checked
        return null;
    }
    final ColumnInfo pkColumn = primaryInfo.getFirstColumn();
    final SqlClause sqlClause = cb.getSqlClause();
    final List<Object> pkList = doSplitSelectFirst(args, cb, dbmeta, sqlClause);
    if (pkList == null) {
        // no way just in case
        return null;
    }
    if (pkList.isEmpty()) {
        return pkList;
    }
    return doSplitSelectSecond(args, cb, pkColumn, sqlClause, pkList);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo)

Example 44 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class TnRelationRowCreatorExtension method setupRelationKeyValue.

// ===================================================================================
// Relation KeyValue Setup
// =======================
@Override
protected void setupRelationKeyValue(TnRelationRowCreationResource res) {
    // /= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    // setup of relation key is handled at all-value setup marked as '#RELKEY'
    // so only entity instance creation exists in this method
    // = = = = = = = = = =/
    final TnRelationPropertyType rpt = res.getRelationPropertyType();
    final TnBeanMetaData yourBmd = rpt.getYourBeanMetaData();
    if (!res.hasRowInstance()) {
        // always no instance here (check just in case)
        final DBMeta dbmeta = yourBmd.getDBMeta();
        final Object row = newRelationRow(rpt, res.getRelationSelector(), res.getRelationNoSuffix(), dbmeta);
        res.setRow(row);
    }
}
Also used : TnRelationPropertyType(org.dbflute.s2dao.metadata.TnRelationPropertyType) DBMeta(org.dbflute.dbmeta.DBMeta) TnBeanMetaData(org.dbflute.s2dao.metadata.TnBeanMetaData)

Example 45 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class TnRelationRowOptionalNullThrower method throwRelationEntityNotFoundException.

protected void throwRelationEntityNotFoundException() {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Not found the relation entity.");
    br.addItem("Advice");
    br.addElement("Confirm the existence in your business rule.");
    br.addElement("If the relation entity might not exist, check it.");
    br.addElement("For example:");
    br.addElement("  (x):");
    br.addElement("    List<Member> memberList = memberBhv.selectList(cb -> {");
    br.addElement("        cb.setupSelect_MemberServiceAsOne();");
    br.addElement("    });");
    br.addElement("    for (Member member : memberList) {");
    br.addElement("        ... = member.getMemberServiceAsOne().alwaysPresent(...); // *No");
    br.addElement("    }");
    br.addElement("  (o):");
    br.addElement("    List<Member> memberList = memberBhv.selectList(cb -> {");
    br.addElement("        cb.setupSelect_MemberServiceAsOne();");
    br.addElement("    });");
    br.addElement("    for (Member member : memberList) {");
    br.addElement("        member.getMemberServiceAsOne().ifPresent(service -> {  // OK");
    br.addElement("            ... = service.getServicePointCount();");
    br.addElement("        });");
    br.addElement("    }");
    br.addItem("Your Operation");
    final String localTable;
    final String localSuffix;
    if (_row instanceof Entity) {
        // basically here
        final Entity entity = ((Entity) _row);
        final DBMeta dbmeta = entity.asDBMeta();
        localTable = dbmeta.getTableDispName();
        localSuffix = dbmeta.extractPrimaryKeyMap(entity).toString();
    } else {
        // just in case
        localTable = _row != null ? _row.getClass().getSimpleName() : null;
        localSuffix = "{" + _row + "}";
    }
    br.addElement(localTable + ":" + localSuffix + " => " + _propertyName);
    if (_row instanceof Entity) {
        // basically here
        final Entity entity = ((Entity) _row);
        br.addItem("Local Entity");
        try {
            br.addElement(entity.toStringWithRelation());
        } catch (RuntimeException continued) {
            final String tableDbName = entity.asTableDbName();
            final String msg = "*Failed to build string from the entity for debug: " + tableDbName;
            if (_log.isDebugEnabled()) {
                _log.debug(msg);
            }
            br.addElement(msg);
        }
    } else {
        br.addItem("Local Entity");
        br.addElement(_row);
    }
    if (_invokePath != null) {
        // if saved
        br.addItem("Behavior");
        br.addElement(_invokePath);
    }
    if (_sql != null) {
        // basically true, just in case
        br.addItem("ConditionBean");
        try {
            final TimeZone finalTimeZone = getFinalTimeZone();
            final DisplaySqlBuilder displaySqlBuilder = createDisplaySqlBuilder(finalTimeZone);
            br.addElement(displaySqlBuilder.buildDisplaySql(_sql, _args));
            br.addElement("");
            br.addElement("(using DBFlute system time-zone: " + finalTimeZone.getID() + ")");
        } catch (RuntimeException continued) {
            final String msg = "*Failed to get display SQL from the condition-bean for debug.";
            if (_log.isDebugEnabled()) {
                _log.debug(msg);
            }
            br.addElement(_sql);
            if (_args != null) {
                br.addElement(Arrays.asList(_args));
            }
        }
    }
    // no way outsideSql
    // if (outsideSqlPath != null) {
    // br.addItem("OutsideSql");
    // br.addElement("path : " + outsideSqlPath);
    // br.addElement("pmb  : " + parameterBean);
    // }
    final String msg = br.buildExceptionMessage();
    throw new RelationEntityNotFoundException(msg);
}
Also used : Entity(org.dbflute.Entity) TimeZone(java.util.TimeZone) DBMeta(org.dbflute.dbmeta.DBMeta) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DisplaySqlBuilder(org.dbflute.twowaysql.DisplaySqlBuilder) RelationEntityNotFoundException(org.dbflute.exception.RelationEntityNotFoundException)

Aggregations

DBMeta (org.dbflute.dbmeta.DBMeta)64 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)32 ArrayList (java.util.ArrayList)13 ForeignInfo (org.dbflute.dbmeta.info.ForeignInfo)13 List (java.util.List)12 LinkedHashMap (java.util.LinkedHashMap)11 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)10 Entity (org.dbflute.Entity)9 PrimaryInfo (org.dbflute.dbmeta.info.PrimaryInfo)9 ReferrerInfo (org.dbflute.dbmeta.info.ReferrerInfo)9 Method (java.lang.reflect.Method)8 ReflectionFailureException (org.dbflute.util.DfReflectionUtil.ReflectionFailureException)8 Map (java.util.Map)7 ColumnFunctionCipher (org.dbflute.cbean.cipher.ColumnFunctionCipher)7 RelationInfo (org.dbflute.dbmeta.info.RelationInfo)7 LocalDate (java.time.LocalDate)6 LocalDateTime (java.time.LocalDateTime)6 Collection (java.util.Collection)6 Date (java.util.Date)6 HashMap (java.util.HashMap)6