use of org.dbflute.twowaysql.DisplaySqlBuilder in project dbflute-core by dbflute.
the class TnRelationRowOptionalNullThrower method throwRelationEntityNotFoundException.
protected void throwRelationEntityNotFoundException() {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Not found the relation entity.");
br.addItem("Advice");
br.addElement("Confirm the existence in your business rule.");
br.addElement("If the relation entity might not exist, check it.");
br.addElement("For example:");
br.addElement(" (x):");
br.addElement(" List<Member> memberList = memberBhv.selectList(cb -> {");
br.addElement(" cb.setupSelect_MemberServiceAsOne();");
br.addElement(" });");
br.addElement(" for (Member member : memberList) {");
br.addElement(" ... = member.getMemberServiceAsOne().alwaysPresent(...); // *No");
br.addElement(" }");
br.addElement(" (o):");
br.addElement(" List<Member> memberList = memberBhv.selectList(cb -> {");
br.addElement(" cb.setupSelect_MemberServiceAsOne();");
br.addElement(" });");
br.addElement(" for (Member member : memberList) {");
br.addElement(" member.getMemberServiceAsOne().ifPresent(service -> { // OK");
br.addElement(" ... = service.getServicePointCount();");
br.addElement(" });");
br.addElement(" }");
br.addItem("Your Operation");
final String localTable;
final String localSuffix;
if (_row instanceof Entity) {
// basically here
final Entity entity = ((Entity) _row);
final DBMeta dbmeta = entity.asDBMeta();
localTable = dbmeta.getTableDispName();
localSuffix = dbmeta.extractPrimaryKeyMap(entity).toString();
} else {
// just in case
localTable = _row != null ? _row.getClass().getSimpleName() : null;
localSuffix = "{" + _row + "}";
}
br.addElement(localTable + ":" + localSuffix + " => " + _propertyName);
if (_row instanceof Entity) {
// basically here
final Entity entity = ((Entity) _row);
br.addItem("Local Entity");
try {
br.addElement(entity.toStringWithRelation());
} catch (RuntimeException continued) {
final String tableDbName = entity.asTableDbName();
final String msg = "*Failed to build string from the entity for debug: " + tableDbName;
if (_log.isDebugEnabled()) {
_log.debug(msg);
}
br.addElement(msg);
}
} else {
br.addItem("Local Entity");
br.addElement(_row);
}
if (_invokePath != null) {
// if saved
br.addItem("Behavior");
br.addElement(_invokePath);
}
if (_sql != null) {
// basically true, just in case
br.addItem("ConditionBean");
try {
final TimeZone finalTimeZone = getFinalTimeZone();
final DisplaySqlBuilder displaySqlBuilder = createDisplaySqlBuilder(finalTimeZone);
br.addElement(displaySqlBuilder.buildDisplaySql(_sql, _args));
br.addElement("");
br.addElement("(using DBFlute system time-zone: " + finalTimeZone.getID() + ")");
} catch (RuntimeException continued) {
final String msg = "*Failed to get display SQL from the condition-bean for debug.";
if (_log.isDebugEnabled()) {
_log.debug(msg);
}
br.addElement(_sql);
if (_args != null) {
br.addElement(Arrays.asList(_args));
}
}
}
// no way outsideSql
// if (outsideSqlPath != null) {
// br.addItem("OutsideSql");
// br.addElement("path : " + outsideSqlPath);
// br.addElement("pmb : " + parameterBean);
// }
final String msg = br.buildExceptionMessage();
throw new RelationEntityNotFoundException(msg);
}
Aggregations