use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class TnRowCreatorExtension method createRowCreator.
/**
* @param beanClass The class of target bean to find DB-meta. (NullAllowed)
* @return The instance of internal row creator. (NotNull)
*/
public static TnRowCreatorExtension createRowCreator(Class<?> beanClass) {
final TnRowCreatorExtension rowCreator = new TnRowCreatorExtension();
if (beanClass != null) {
final DBMeta dbmeta = findDBMetaByClass(beanClass);
if (dbmeta != null) {
rowCreator.setFixedDBMeta(dbmeta);
rowCreator.setCreatableByDBMeta(isCreatableByDBMeta(beanClass, dbmeta.getEntityType()));
}
}
return rowCreator;
}
use of org.dbflute.dbmeta.DBMeta 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;
}
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class OutsideSqlContext method buildBehaviorSqlPackageName.
protected String buildBehaviorSqlPackageName() {
final DBMeta dbmeta = _dbmetaProvider.provideDBMetaChecked(_tableDbName);
final String behaviorType = dbmeta.getBehaviorTypeName();
final String outsideSqlPackage = _outsideSqlPackage;
if (outsideSqlPackage != null && outsideSqlPackage.trim().length() > 0) {
return mergeBehaviorSqlPackage(behaviorType, outsideSqlPackage);
} else {
return behaviorType;
}
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class AbstractSqlClause method buildJoinTableClause.
protected void buildJoinTableClause(StringBuilder sb, LeftOuterJoinInfo joinInfo, String joinExp, boolean canBeInnerJoin) {
final String foreignTableDbName = joinInfo.getForeignTableDbName();
// basically for in-line view indent
final int tablePos = 3 + joinExp.length();
final DBMeta foreignDBMeta = findDBMeta(foreignTableDbName);
final TableSqlName foreignTableSqlName = foreignDBMeta.getTableSqlName();
final List<QueryClause> inlineWhereClauseList = joinInfo.getInlineWhereClauseList();
final String tableExp;
if (inlineWhereClauseList.isEmpty()) {
tableExp = foreignTableSqlName.toString();
} else {
tableExp = getInlineViewClause(foreignTableSqlName, inlineWhereClauseList, tablePos);
}
if (joinInfo.hasFixedCondition()) {
sb.append(joinInfo.resolveFixedInlineView(tableExp, canBeInnerJoin));
} else {
sb.append(tableExp);
}
}
use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.
the class AbstractSqlClause method getClauseQueryUpdate.
// -----------------------------------------------------
// Query Update
// ------------
public String getClauseQueryUpdate(Map<String, Object> columnParameterMap) {
if (columnParameterMap == null) {
String msg = "The argument 'columnParameterMap' should not be null.";
throw new IllegalArgumentException(msg);
}
if (columnParameterMap.isEmpty()) {
return null;
}
final DBMeta dbmeta = getDBMeta();
final StringBuilder sb = new StringBuilder();
sb.append("update ").append(dbmeta.getTableSqlName());
if (isUseQueryUpdateDirect(dbmeta)) {
// direct (in-scope unsupported or compound primary keys)
final String whereClause = processSubQueryIndent(getWhereClause());
buildQueryUpdateDirectClause(columnParameterMap, whereClause, dbmeta, sb);
} else {
// basically here
buildQueryUpdateInScopeClause(columnParameterMap, dbmeta, sb);
}
return sb.toString();
}
Aggregations