use of org.dbflute.dbmeta.info.ColumnInfo 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);
}
use of org.dbflute.dbmeta.info.ColumnInfo 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.ColumnInfo in project dbflute-core by dbflute.
the class TnRelationRowCreatorExtension method adjustCreatedRelationRow.
/**
* Adjust created row for relation tables.
* @param relationRow The relation row of tables related to the base-point table. (NotNull)
* @param relationNoSuffix The suffix of relation no, e.g. _0, _1_3. (NotNull)
* @param relSelector The selector of relation, which has various determination. (NotNull)
* @param rpt The property type of the relation. (NotNull)
*/
public static void adjustCreatedRelationRow(Object relationRow, String relationNoSuffix, TnRelationSelector relSelector, TnRelationPropertyType rpt) {
// *similar implementation for base-point row exists, see it for the details
if (relationRow instanceof Entity) {
final Entity entity = (Entity) relationRow;
// check access to non-specified-column
if (// not allowed
!relSelector.isNonSpecifiedColumnAccessAllowed(relationNoSuffix) && relSelector.isUsingSpecifyColumnInRelation(relationNoSuffix)) {
// and use SpecifyColumn
// so check it
entity.modifiedToSpecified();
// adjust specification for column null object handling
final Set<ColumnInfo> nullObjectColumnSet = relSelector.getRelationSpecifiedNullObjectColumnSet(relationNoSuffix);
for (ColumnInfo columnInfo : nullObjectColumnSet) {
// might be empty loop if no null object
entity.myspecifyProperty(columnInfo.getPropertyName());
}
}
// enable the handling of column null object if allowed and object-able
if (relSelector.isColumnNullObjectEnabled(relationNoSuffix) && entity instanceof ColumnNullObjectable) {
((ColumnNullObjectable) entity).enableColumnNullObject();
}
// clear modified properties for update process using selected entity
entity.clearModifiedInfo();
// mark as select to determine the entity is selected or user-created
// basically for e.g. determine columns of batch insert
entity.markAsSelect();
} else {
// not DBFlute entity
// actually any bean meta data can be accepted
// because only it gets modified properties
rpt.getYourBeanMetaData().getModifiedPropertyNames(relationRow).clear();
}
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class TnAbstractPropertyTypeFactory method createPropertyType.
protected TnPropertyType createPropertyType(DfPropertyDesc propertyDesc) {
final ValueType valueType = getValueType(propertyDesc);
final String columnDbName = getColumnDbName(propertyDesc);
final ColumnSqlName columnSqlName = getColumnSqlName(columnDbName);
final ColumnInfo entityColumnInfo = getEntityColumnInfo(columnDbName);
return new TnPropertyTypeImpl(propertyDesc, valueType, columnDbName, columnSqlName, entityColumnInfo);
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class TnRowCreatorExtension method createRow.
// ===================================================================================
// Main
// ====
/**
* {@inheritDoc}
*/
public Object createRow(ResultSet rs, Map<String, Map<String, Integer>> selectIndexMap, Map<String, TnPropertyMapping> propertyCache, Class<?> beanClass, ConditionBean cb) throws SQLException {
if (propertyCache.isEmpty()) {
String msg = "The propertyCache should not be empty: bean=" + beanClass.getName();
throw new IllegalStateException(msg);
}
// temporary variable, for exception message, debug message
String columnName = null;
TnPropertyMapping mapping = null;
String propertyName = null;
Object selectedValue = null;
ColumnInfo columnInfo = null;
final Object row;
final DBMeta dbmeta;
if (_fixedDBMeta != null) {
if (_creatableByDBMeta) {
// mainly here
final Entity entity = _fixedDBMeta.newEntity();
reflectConditionBeanOptionToEntity(cb, entity);
row = entity;
} else {
// e.g. manual-extended entity
row = newBean(beanClass);
}
dbmeta = _fixedDBMeta;
} else {
// e.g. manual-created bean of outsideSql
row = newBean(beanClass);
// find just in case
dbmeta = findCachedDBMeta(row);
}
try {
if (dbmeta != null) {
// mainly here
// almost always true
final boolean isEntity = row instanceof Entity;
final Entity entityRow = isEntity ? (Entity) row : null;
for (Entry<String, TnPropertyMapping> entry : propertyCache.entrySet()) {
columnName = entry.getKey();
mapping = entry.getValue();
propertyName = mapping.getPropertyName();
selectedValue = getValue(rs, columnName, mapping.getValueType(), selectIndexMap);
columnInfo = mapping.getEntityColumnInfo();
if (columnInfo != null && isEntity) {
columnInfo.write(entityRow, selectedValue);
} else {
mapping.getPropertyAccessor().setValue(row, selectedValue);
}
}
if (canHandleDerivedMap(row)) {
processDerivedMap(rs, selectIndexMap, propertyCache, row);
}
} else {
// not DBFlute entity
for (Entry<String, TnPropertyMapping> entry : propertyCache.entrySet()) {
columnName = entry.getKey();
mapping = entry.getValue();
propertyName = mapping.getPropertyName();
selectedValue = getValue(rs, columnName, mapping.getValueType(), selectIndexMap);
mapping.getPropertyAccessor().setValue(row, selectedValue);
}
}
return row;
} catch (ClassCastException e) {
throwMappingClassCastException(row, dbmeta, mapping, selectedValue, e);
// unreachable
return null;
} catch (SQLException e) {
if (_log.isDebugEnabled()) {
String msg = "Failed to get selected values while resultSet handling:";
msg = msg + " target=" + DfTypeUtil.toClassTitle(beanClass) + "." + propertyName;
_log.debug(msg);
}
throw e;
}
}
Aggregations