use of org.dbflute.properties.assistant.classification.DfClassificationElement in project dbflute-core by dbflute.
the class DfAppClsTableLoader method doArrangeLiteral.
protected void doArrangeLiteral(String classificationName, DfClassificationTop classificationTop, Map<String, Object> elementMap) {
final DfClassificationElement element = new DfClassificationElement();
element.setClassificationName(classificationName);
element.acceptBasicItemMap(elementMap);
classificationTop.addClassificationElement(element);
}
use of org.dbflute.properties.assistant.classification.DfClassificationElement in project dbflute-core by dbflute.
the class DfRefClsLoadingHandler method includeRefClsElement.
// ===================================================================================
// Include refCls
// ==============
public void includeRefClsElement(DfClassificationTop classificationTop, DfRefClsElement refClsElement) {
final DfClassificationTop refClsTop = refClsElement.getReferredClsTop();
if (refClsElement.isRefTypeIncluded()) {
final String groupName = refClsElement.getGroupName();
final List<DfClassificationElement> refElementList;
if (groupName != null) {
// e.g. map:{ refCls=maihamadb@MemberStatus.serviceAvailable ; refType=included }
refElementList = findRefGroup(refClsElement, refClsTop, groupName).getElementList();
} else {
// e.g. map:{ refCls=maihamadb@MemberStatus ; refType=included }
refElementList = refClsTop.getClassificationElementList();
}
classificationTop.addClassificationElementAll(copyIncludedElementList(classificationTop, refElementList));
}
// later, literal elements are not evaluated yet here
// classificationTop.inheritRefClsGroup(dbClsTop);
}
use of org.dbflute.properties.assistant.classification.DfClassificationElement in project dbflute-core by dbflute.
the class DfClsDeploymentInitializer method initializeClassificationDeployment.
// ===================================================================================
// Initialize
// ==========
public Map<String, Map<String, String>> initializeClassificationDeployment(Database database) {
// this should be called immediately after creating schema data
// it should be called after additional-foreign-key initialization
// so no modification for now
_log.info("...Initializing ClassificationDeployment: project={}", database.getProjectName());
// only overridden if called with same database
if (_allColumnClassificationMap != null) {
final List<Table> tableList = database.getTableList();
for (Table table : tableList) {
final Map<String, String> columnClsMap = getColumnClsMap(_existingDeploymentMap, table.getTableDbName());
for (Entry<String, String> entry : _allColumnClassificationMap.entrySet()) {
columnClsMap.put(entry.getKey(), entry.getValue());
}
}
}
_classificationDefinitionInitializer.process();
for (Entry<String, DfClassificationElement> entry : _tableClassificationMap.entrySet()) {
final DfClassificationElement element = entry.getValue();
if (element.getClassificationTop().isSuppressAutoDeploy()) {
continue;
}
final Map<String, String> columnClsMap = getColumnClsMap(_existingDeploymentMap, element.getTable());
final String classificationName = element.getClassificationName();
registerColumnClsIfNeeds(columnClsMap, element.getCode(), classificationName);
final Table table = database.getTable(element.getTable());
if (table == null || table.hasCompoundPrimaryKey()) {
continue;
}
final Column column = table.getColumn(element.getCode());
if (column == null || !column.isPrimaryKey()) {
continue;
}
final List<ForeignKey> referrers = column.getReferrers();
for (ForeignKey referrer : referrers) {
if (!referrer.isSimpleKeyFK()) {
continue;
}
final Table referrerTable = referrer.getTable();
final String referrerTableDbName = referrerTable.getTableDbName();
final Map<String, String> referrerClsMap = getColumnClsMap(_existingDeploymentMap, referrerTableDbName);
final Column localColumnAsOne = referrer.getLocalColumnAsOne();
registerColumnClsIfNeeds(referrerClsMap, localColumnAsOne.getName(), classificationName);
}
}
return _existingDeploymentMap;
}
use of org.dbflute.properties.assistant.classification.DfClassificationElement in project dbflute-core by dbflute.
the class DfClsTableClassificationArranger method selectTableClassification.
// ===================================================================================
// Select Table Classification
// ===========================
protected void selectTableClassification(DfClassificationTop classificationTop, List<DfClassificationElement> elementList, DfClassificationElement metaElement, Set<String> exceptCodeSet, Connection conn, String sql) {
final String classificationName = classificationTop.getClassificationName();
final String[] sisters = metaElement.getSisters();
final Map<String, Object> subItemPropMap = metaElement.getSubItemMap();
Statement st = null;
ResultSet rs = null;
try {
st = conn.createStatement();
_log.info("...Selecting for " + classificationName + " classification" + ln() + sql);
rs = st.executeQuery(sql);
final Set<String> duplicateCheckSet = StringSet.createAsCaseInsensitive();
while (rs.next()) {
final String code = rs.getString("cls_code");
final String name = rs.getString("cls_name");
final String alias = rs.getString("cls_alias");
final String comment = rs.getString("cls_comment");
if (exceptCodeSet.contains(code)) {
_log.info(" exceptd: " + code);
continue;
}
if (duplicateCheckSet.contains(code)) {
_log.info(" duplicate: " + code);
continue;
} else {
duplicateCheckSet.add(code);
}
final Map<String, Object> selectedMap = new LinkedHashMap<>();
selectedMap.put(DfClassificationElement.KEY_CODE, code);
selectedMap.put(DfClassificationElement.KEY_NAME, filterTableClassificationName(classificationTop, name));
selectedMap.put(DfClassificationElement.KEY_ALIAS, filterTableClassificationLiteralOutput(alias));
if (Srl.is_NotNull_and_NotTrimmedEmpty(comment)) {
// because of not required
selectedMap.put(DfClassificationElement.KEY_COMMENT, comment);
}
if (sisters != null && sisters.length > 0) {
final String sisterValue = rs.getString("cls_sister");
selectedMap.put(DfClassificationElement.KEY_SISTER_CODE, sisterValue);
}
if (subItemPropMap != null && !subItemPropMap.isEmpty()) {
final Map<String, Object> subItemMap = new LinkedHashMap<String, Object>();
for (String subItemKey : subItemPropMap.keySet()) {
final String clsKey = "cls_" + subItemKey;
final String subItemValue = rs.getString(clsKey);
final String subItemVeloFriendlyValue;
if (subItemValue != null) {
subItemVeloFriendlyValue = filterTableClassificationLiteralOutput(subItemValue);
} else {
// for determination in templates
subItemVeloFriendlyValue = "null";
}
subItemMap.put(subItemKey, subItemVeloFriendlyValue);
}
selectedMap.put(DfClassificationElement.KEY_SUB_ITEM_MAP, subItemMap);
}
final DfClassificationElement element = new DfClassificationElement();
element.setClassificationName(classificationName);
element.acceptBasicItemMap(selectedMap);
elementList.add(element);
}
} catch (SQLException e) {
throwTableClassificationSelectSQLFailureException(classificationName, sql, e);
throw new SQLFailureException("Failed to execute the SQL:" + ln() + sql, e);
} finally {
new DfClassificationJdbcCloser().closeStatement(st, rs);
}
}
use of org.dbflute.properties.assistant.classification.DfClassificationElement in project dbflute-core by dbflute.
the class DfRefClsRefTypeVerifier method doVerifyRefExists.
// -----------------------------------------------------
// Exists
// ------
protected void doVerifyRefExists(DfClassificationTop classificationTop) {
final List<DfClassificationElement> appElementList = classificationTop.getClassificationElementList();
final List<DfClassificationElement> referredElementList = _referredElementList;
final List<DfClassificationElement> nonExistingList = appElementList.stream().filter(appElement -> {
return notMatchesReferredElement(referredElementList, appElement);
}).collect(Collectors.toList());
if (!nonExistingList.isEmpty()) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Not found the app classification code in the referred classification");
br.addItem("Advice");
br.addElement("The codes of the app classification should be included");
br.addElement("in the referred classification because of refType='exists'.");
br.addElement("For example:");
br.addElement(" (x): app(A), referred(B, C)");
br.addElement(" (x): app(A, B), referred(A, C)");
br.addElement(" (x): app(A, B, C), referred(A, B)");
br.addElement(" (o): app(A), referred(A, B)");
br.addElement(" (o): app(A, B), referred(A, B, C)");
br.addElement(" (o): app(A, B, C), referred(A, B, C)");
br.addItem("dfprop File");
br.addElement(_resourceFile);
br.addItem("AppCls");
br.addElement(classificationTop.getClassificationName() + ": " + buildClsCodesExp(appElementList));
br.addItem("ReferredCls");
br.addElement(buildReferredExp() + ": " + buildClsCodesExp(referredElementList));
br.addItem("Ref Type");
br.addElement(_refType);
br.addItem("Non-Existing Code");
br.addElement(nonExistingList.stream().map(element -> {
return element.getCode();
}).collect(Collectors.joining(", ")));
final String msg = br.buildExceptionMessage();
throw new DfIllegalPropertySettingException(msg);
}
}
Aggregations