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);
}
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;
}
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);
}
}
}
}
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);
}
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);
}
}
}
}
Aggregations