Search in sources :

Example 1 with PrimaryInfo

use of org.dbflute.dbmeta.info.PrimaryInfo in project dbflute-core by dbflute.

the class AbstractDBMeta method searchPrimaryInfo.

/**
 * {@inheritDoc}
 */
public OptionalObject<PrimaryInfo> searchPrimaryInfo(Collection<ColumnInfo> columnInfoList) {
    // exception if no PK
    final PrimaryInfo primaryInfo = getPrimaryInfo();
    final Set<ColumnInfo> colSet = new HashSet<ColumnInfo>(columnInfoList);
    final List<ColumnInfo> pkList = primaryInfo.getPrimaryColumnList();
    for (ColumnInfo pk : pkList) {
        if (!colSet.contains(pk)) {
            return OptionalObject.ofNullable(null, () -> {
                throwSpecifiedColumnNotPrimaryException(columnInfoList, pkList);
            });
        }
    }
    return OptionalObject.of(primaryInfo);
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo) HashSet(java.util.HashSet)

Example 2 with PrimaryInfo

use of org.dbflute.dbmeta.info.PrimaryInfo in project dbflute-core by dbflute.

the class TnRelationPropertyTypeImpl method deriveUniqueKeys.

protected List<TnPropertyType> deriveUniqueKeys(String[] yourKeys, TnBeanMetaData yourBeanMetaData) {
    final DBMeta dbmeta = yourBeanMetaData.getDBMeta();
    final List<TnPropertyType> uniquePropertyTypeList;
    if (dbmeta != null && dbmeta.hasPrimaryKey()) {
        final PrimaryInfo primaryInfo = dbmeta.getPrimaryInfo();
        final List<ColumnInfo> primaryColumnList = 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;
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo)

Example 3 with PrimaryInfo

use of org.dbflute.dbmeta.info.PrimaryInfo in project dbflute-core by dbflute.

the class InsertOption method xcheckSpecifiedInsertColumnPrimaryKey.

// -----------------------------------------------------
// Insert Process
// --------------
public void xcheckSpecifiedInsertColumnPrimaryKey() {
    // checked later by process if it needs
    if (_insertColumnSpecification == null) {
        return;
    }
    assertInsertColumnSpecifiedCB();
    final CB cb = _insertColumnSpecifiedCB;
    final String basePointAliasName = cb.getSqlClause().getBasePointAliasName();
    final DBMeta dbmeta = cb.asDBMeta();
    if (dbmeta.hasPrimaryKey()) {
        final PrimaryInfo pkInfo = dbmeta.getPrimaryInfo();
        final List<ColumnInfo> pkList = pkInfo.getPrimaryColumnList();
        for (ColumnInfo pk : pkList) {
            final String columnDbName = pk.getColumnDbName();
            if (cb.getSqlClause().hasSpecifiedSelectColumn(basePointAliasName, columnDbName)) {
                String msg = "PK columns should not be allowed to specify as update columns: " + columnDbName;
                throw new SpecifyUpdateColumnInvalidException(msg);
            }
        }
    }
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) SpecifyUpdateColumnInvalidException(org.dbflute.exception.SpecifyUpdateColumnInvalidException) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo)

Example 4 with PrimaryInfo

use of org.dbflute.dbmeta.info.PrimaryInfo 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 5 with PrimaryInfo

use of org.dbflute.dbmeta.info.PrimaryInfo in project dbflute-core by dbflute.

the class UpdateOption method xcheckSpecifiedUpdateColumnPrimaryKey.

// -----------------------------------------------------
// Update Process
// --------------
public void xcheckSpecifiedUpdateColumnPrimaryKey() {
    // checked later by process if it needs
    if (_updateColumnSpecification == null) {
        return;
    }
    assertUpdateColumnSpecifiedCB();
    final CB cb = _updateColumnSpecifiedCB;
    final String basePointAliasName = cb.getSqlClause().getBasePointAliasName();
    final DBMeta dbmeta = cb.asDBMeta();
    if (dbmeta.hasPrimaryKey()) {
        final PrimaryInfo pkInfo = dbmeta.getPrimaryInfo();
        final List<ColumnInfo> pkList = pkInfo.getPrimaryColumnList();
        for (ColumnInfo pk : pkList) {
            final String columnDbName = pk.getColumnDbName();
            if (cb.getSqlClause().hasSpecifiedSelectColumn(basePointAliasName, columnDbName)) {
                String msg = "PK columns should not be allowed to specify as update columns: " + columnDbName;
                throw new SpecifyUpdateColumnInvalidException(msg);
            }
        }
    }
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) SpecifyUpdateColumnInvalidException(org.dbflute.exception.SpecifyUpdateColumnInvalidException) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo)

Aggregations

ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)5 PrimaryInfo (org.dbflute.dbmeta.info.PrimaryInfo)5 DBMeta (org.dbflute.dbmeta.DBMeta)4 SpecifyUpdateColumnInvalidException (org.dbflute.exception.SpecifyUpdateColumnInvalidException)2 HashSet (java.util.HashSet)1 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)1 TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)1