use of org.dbflute.dbmeta.info.ColumnInfo 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.ColumnInfo in project dbflute-core by dbflute.
the class GreatWallOfOracleType method doMappingOracleStructToEntity.
protected Entity doMappingOracleStructToEntity(DBMeta dbmeta, Object[] attrs) throws SQLException {
final Entity entity = dbmeta.newEntity();
final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
assertStructAttributeSizeMatched(entity, attrs, columnInfoList);
for (int i = 0; i < attrs.length; i++) {
final Object attr = attrs[i];
final ColumnInfo columnInfo = columnInfoList.get(i);
final Class<?> nativeType = columnInfo.getObjectNativeType();
if (attr == null) {
if (List.class.isAssignableFrom(nativeType)) {
columnInfo.write(entity, DfCollectionUtil.newArrayList());
}
continue;
}
final Object mappedValue;
if (List.class.isAssignableFrom(nativeType)) {
final Class<?> elementType = columnInfo.getGenericType();
mappedValue = mappingOracleArrayToList(attr, elementType);
} else if (Entity.class.isAssignableFrom(nativeType)) {
mappedValue = mappingOracleStructToEntity(attr, nativeType);
} else {
mappedValue = adjustScalarToPropertyValue(attr, nativeType);
}
columnInfo.write(entity, mappedValue);
}
return entity;
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class GreatWallOfOracleType method mappingEntityToOracleStruct.
protected Object mappingEntityToOracleStruct(Connection conn, Object paramExp, Entity entity) throws SQLException {
final DBMeta dbmeta = entity.asDBMeta();
final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
final List<Object> attrList = new ArrayList<Object>();
for (ColumnInfo columnInfo : columnInfoList) {
final Object propertyValue = columnInfo.read(entity);
final Object mappedValue;
if (propertyValue instanceof List<?>) {
// array in struct
// it works only when the element type is scalar
// (but property type is Object because Sql2Entity does not support this)
final List<?> nested = ((List<?>) propertyValue);
final String arrayTypeName = columnInfo.getColumnDbType();
final Class<?> nativeType = columnInfo.getObjectNativeType();
Class<?> elementType = nativeType;
if (List.class.isAssignableFrom(nativeType)) {
elementType = columnInfo.getGenericType();
} else if (Object.class.equals(nativeType) && DfCollectionUtil.hasValidElement(nested)) {
final Class<?> firstElementType = DfCollectionUtil.findFirstElementType(nested);
if (firstElementType != null) {
elementType = nested.iterator().next().getClass();
}
}
mappedValue = mappingListToOracleArray(conn, paramExp, nested, arrayTypeName, elementType);
} else if (propertyValue instanceof Entity) {
// struct in struct
// it works only when the entity structure matches with the struct type
// (but property type is Object because Sql2Entity does not support this)
mappedValue = mappingEntityToOracleStruct(conn, paramExp, (Entity) propertyValue);
} else {
mappedValue = mappingScalarToSqlValue(conn, paramExp, propertyValue, columnInfo);
}
attrList.add(mappedValue);
}
final String structTypeName = dbmeta.getTableSqlName().toString();
return toOracleStruct(getOracleConnection(conn), structTypeName, attrList.toArray());
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class HpFixedConditionQueryResolver method resolveFixedInlineView.
// ===================================================================================
// Resolve Fixed InlineView
// ========================
public String resolveFixedInlineView(String foreignTableSqlName, boolean treatedAsInnerJoin) {
// so it can uses bridge variables here
if (_inlineViewResourceMap == null || _inlineViewResourceMap.isEmpty()) {
// not uses InlineView
return foreignTableSqlName;
}
// alias is required because foreignTableSqlName may be (normal) InlineView
final String baseAlias = "dffixedbase";
final String baseIndent;
if (treatedAsInnerJoin) {
// ----------" inner join "
baseIndent = " ";
} else {
// ----------" left outer join "
baseIndent = " ";
}
final StringBuilder joinSb = new StringBuilder();
final Map<ForeignInfo, String> relationMap = new HashMap<ForeignInfo, String>();
final List<String> additionalRealColumnList = new ArrayList<String>();
// basically not null
final String resolvedFixedCondition = _resolvedFixedCondition;
String optimizedCondition = _inlineViewOptimizedCondition;
int groupIndex = 0;
for (InlineViewResource resource : _inlineViewResourceMap.values()) {
final List<ForeignInfo> joinInfoList = resource.getJoinInfoList();
final String aliasBase = "dffixedjoin";
String preForeignAlias = null;
String foreignAlias = null;
int joinIndex = 0;
final Map<ForeignInfo, String> foreignAliasMap = new HashMap<ForeignInfo, String>(joinInfoList.size());
for (ForeignInfo joinInfo : joinInfoList) {
if (relationMap.containsKey(joinInfo)) {
// already joined
// update previous alias
preForeignAlias = relationMap.get(joinInfo);
continue;
}
final TableSqlName foreignTable;
final String localAlias;
{
final DBMeta foreignDBMeta = joinInfo.getForeignDBMeta();
foreignTable = foreignDBMeta.getTableSqlName();
localAlias = (preForeignAlias != null ? preForeignAlias : baseAlias);
foreignAlias = aliasBase + "_" + groupIndex + "_" + joinIndex;
preForeignAlias = foreignAlias;
}
joinSb.append(ln()).append(baseIndent);
joinSb.append(" left outer join ").append(foreignTable).append(" ").append(foreignAlias);
joinSb.append(" on ");
final Map<ColumnInfo, ColumnInfo> columnInfoMap = joinInfo.getLocalForeignColumnInfoMap();
int columnIndex = 0;
for (Entry<ColumnInfo, ColumnInfo> localForeignEntry : columnInfoMap.entrySet()) {
final ColumnInfo localColumnInfo = localForeignEntry.getKey();
final ColumnInfo foreignColumninfo = localForeignEntry.getValue();
if (columnIndex > 0) {
joinSb.append(" and ");
}
joinSb.append(localAlias).append(".").append(localColumnInfo.getColumnSqlName());
joinSb.append(" = ").append(foreignAlias).append(".").append(foreignColumninfo.getColumnSqlName());
++columnIndex;
}
foreignAliasMap.put(joinInfo, foreignAlias);
relationMap.put(joinInfo, foreignAlias);
++joinIndex;
}
if (optimizedCondition != null) {
optimizedCondition = resolvedOptimizedCondition(optimizedCondition, resource, foreignAliasMap);
}
collectAdditionalRealColumnList(additionalRealColumnList, resolvedFixedCondition, resource, foreignAlias);
++groupIndex;
}
if (optimizedCondition != null) {
// foreign alias for in-line view is resolved here
optimizedCondition = replaceString(optimizedCondition, getForeignAliasMark(), baseAlias);
optimizedCondition = filterSubQueryIndentMark(optimizedCondition, false, true);
}
final StringBuilder sqlSb = new StringBuilder();
sqlSb.append("(select ").append(baseAlias).append(".*");
for (String columnName : additionalRealColumnList) {
sqlSb.append(", ").append(columnName);
}
sqlSb.append(ln()).append(baseIndent);
sqlSb.append(" from ").append(foreignTableSqlName).append(" ").append(baseAlias);
sqlSb.append(joinSb);
if (optimizedCondition != null) {
buildOptimizedInlineWhereClause(optimizedCondition, baseIndent, sqlSb);
}
sqlSb.append(ln()).append(baseIndent);
sqlSb.append(")");
return sqlSb.toString();
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class HpSLSFunction method setupTargetColumnInfo.
protected void setupTargetColumnInfo(ScalarSelectOption option) {
if (option == null) {
return;
}
final SqlClause sqlClause = _conditionBean.getSqlClause();
ColumnInfo columnInfo = sqlClause.getSpecifiedColumnInfoAsOne();
if (columnInfo != null) {
columnInfo = sqlClause.getSpecifiedDerivingColumnInfoAsOne();
}
option.xsetTargetColumnInfo(columnInfo);
}
Aggregations