use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class TnRowCreatorExtension method adjustCreatedRow.
// ===================================================================================
// Fix Row
// =======
/**
* Adjust created row. (clearing modified info, ...)
* @param row The row of result list. (NotNull)
* @param checkNonSp Does is use the check of access to non-specified column?
* @param colNullObj Does is use the handling of column null object?
* @param basePointBmd The bean meta data of the row for base-point table. (NotNull)
* @param cb The condition-bean for the select. (NullAllowed: when not condition-bean select)
*/
public static void adjustCreatedRow(final Object row, boolean checkNonSp, boolean colNullObj, TnBeanMetaData basePointBmd, ConditionBean cb) {
// _/_/_/_/_/_/_/_/_/_/
if (row instanceof Entity) {
final Entity entity = (Entity) row;
// _/_/_/_/_/_/_/_/_/_/
if (checkNonSp) {
// contains enabled by CB and using SpecifyColumn
entity.modifiedToSpecified();
// _/_/_/_/_/_/_/_/_/_/
if (colNullObj && cb != null) {
// check 'cb' just in case
final SqlClause sqlClause = cb.getSqlClause();
for (ColumnInfo columnInfo : sqlClause.getLocalSpecifiedNullObjectColumnSet()) {
entity.myspecifyProperty(columnInfo.getPropertyName());
}
}
}
// only table that has null object target column is object-able (generated as it)
if (colNullObj && 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
basePointBmd.getModifiedPropertyNames(row).clear();
}
}
use of org.dbflute.dbmeta.info.ColumnInfo 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.ColumnInfo in project dbflute-core by dbflute.
the class AbstractConditionQuery method doInvokeQuery.
protected void doInvokeQuery(String colName, String ckey, Object value, ConditionOption option) {
assertStringNotNullAndNotTrimmedEmpty("columnFlexibleName", colName);
assertStringNotNullAndNotTrimmedEmpty("conditionKeyName", ckey);
final boolean noArg = Srl.equalsIgnoreCase(ckey, "IsNull", "IsNotNull", "IsNullOrEmpty", "EmptyString");
if (!noArg && (value == null || "".equals(value))) {
if (xgetSqlClause().isNullOrEmptyQueryChecked()) {
// as default
String msg = "The conditionValue is required but null or empty: column=" + colName + " value=" + value;
throw new IllegalConditionBeanOperationException(msg);
} else {
// e.g. when cb.ignoreNullOrEmptyQuery()
return;
}
}
final PropertyNameCQContainer container = xhelpExtractingPropertyNameCQContainer(colName);
final String flexibleName = container.getFlexibleName();
final ConditionQuery cq = container.getConditionQuery();
final DBMeta dbmeta = findDBMeta(cq.asTableDbName());
final ColumnInfo columnInfo;
try {
columnInfo = dbmeta.findColumnInfo(flexibleName);
} catch (RuntimeException e) {
throwConditionInvokingColumnFindFailureException(colName, ckey, value, option, e);
// unreachable (to avoid compile error)
return;
}
final String columnCapPropName = initCap(columnInfo.getPropertyName());
final boolean rangeOf = Srl.equalsIgnoreCase(ckey, "RangeOf");
final boolean fromTo = Srl.equalsIgnoreCase(ckey, "FromTo", "DateFromTo");
final boolean inScope = Srl.equalsIgnoreCase(ckey, "InScope");
if (!noArg) {
try {
// convert type
value = columnInfo.convertToObjectNativeType(value);
} catch (RuntimeException e) {
throwConditionInvokingValueConvertFailureException(colName, ckey, value, option, e);
}
}
final String methodName = xbuildQuerySetMethodName(ckey, columnCapPropName);
final List<Class<?>> typeList = newArrayListSized(4);
final Class<?> propertyType = columnInfo.getObjectNativeType();
if (fromTo) {
if (LocalDate.class.isAssignableFrom(propertyType)) {
// #date_parade
typeList.add(propertyType);
typeList.add(propertyType);
} else if (LocalDateTime.class.isAssignableFrom(propertyType)) {
typeList.add(propertyType);
typeList.add(propertyType);
} else {
// fixedly util.Date
typeList.add(Date.class);
typeList.add(Date.class);
}
} else if (rangeOf) {
typeList.add(propertyType);
typeList.add(propertyType);
} else {
if (!noArg) {
final Class<?> instanceType = value.getClass();
if (inScope && Collection.class.isAssignableFrom(instanceType)) {
// double check just in case
// inScope's argument is fixed type
typeList.add(Collection.class);
} else {
typeList.add(instanceType);
}
}
}
if (option != null) {
typeList.add(option.getClass());
}
final List<Class<?>> filteredTypeList = newArrayListSized(typeList.size());
for (Class<?> parameterType : typeList) {
filteredTypeList.add(xfilterInvokeQueryParameterType(colName, ckey, parameterType));
}
final Class<?>[] parameterTypes = filteredTypeList.toArray(new Class<?>[filteredTypeList.size()]);
final Method method = xhelpGettingCQMethod(cq, methodName, parameterTypes);
if (method == null) {
throwConditionInvokingSetMethodNotFoundException(colName, ckey, value, option, methodName, parameterTypes);
}
try {
final List<Object> argList = newArrayList();
if (fromTo || rangeOf) {
if (!(value instanceof List<?>)) {
// check type
throwConditionInvokingDateFromToValueInvalidException(colName, ckey, value, option, methodName, parameterTypes);
}
argList.addAll((List<?>) value);
} else {
if (!noArg) {
argList.add(value);
}
}
if (option != null) {
argList.add(option);
}
final List<Object> filteredArgList = newArrayListSized(argList.size());
for (Object arg : argList) {
filteredArgList.add(xfilterInvokeQueryParameterValue(colName, ckey, arg));
}
xhelpInvokingCQMethod(cq, method, filteredArgList.toArray());
} catch (ReflectionFailureException e) {
throwConditionInvokingSetReflectionFailureException(colName, ckey, value, option, methodName, parameterTypes, e);
}
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class AbstractConditionQuery method doRegIQ.
protected void doRegIQ(ConditionKey key, Object value, ConditionValue cvalue, String columnDbName, ConditionOption option) {
if (!prepareQueryChecked(key, value, cvalue, columnDbName).newClause()) {
return;
}
final DBMeta dbmeta = xgetDBMetaProvider().provideDBMetaChecked(asTableDbName());
final ColumnInfo columnInfo = dbmeta.findColumnInfo(columnDbName);
final String propertyName = columnInfo.getPropertyName();
final String uncapPropName = initUncap(propertyName);
// If Java, it is necessary to use uncapPropName!
final String location = xgetLocation(uncapPropName);
key.setupConditionValue(xcreateQueryModeProvider(), cvalue, value, location, option);
final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
final ColumnFunctionCipher cipher = xgetSqlClause().findColumnFunctionCipher(columnInfo);
if (isBaseQuery()) {
xgetSqlClause().registerBaseTableInlineWhereClause(columnSqlName, key, cvalue, cipher, option);
} else {
final String aliasName = xgetAliasName();
xgetSqlClause().registerOuterJoinInlineWhereClause(aliasName, columnSqlName, key, cvalue, cipher, option, _onClause);
}
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class HpCalcSpecification method getResolvedSpecifiedColumnInfo.
/**
* @return The column info of specified resolved column. (NullAllowed)
*/
public ColumnInfo getResolvedSpecifiedColumnInfo() {
// resolved plain or deriving sub-query
checkSpecifiedCB();
final ColumnInfo columnInfo = getSpecifiedColumnInfo();
return columnInfo != null ? columnInfo : getSpecifiedDerivingColumnInfo();
}
Aggregations