use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfImplicitClassificationChecker method check.
public void check(File file, String tableDbName, String columnDbName, Connection conn) throws SQLException {
final DfClassificationProperties prop = getClassificationProperties();
final String classificationName = prop.getClassificationName(tableDbName, columnDbName);
final DfClassificationTop classificationTop = prop.getClassificationTop(classificationName);
if (classificationTop == null) {
// no way (just in case)
return;
}
if (classificationTop.isTableClassification()) {
// basically checked by FK constraint
return;
}
if (!classificationTop.isCheckClassificationCode() && !classificationTop.isCheckImplicitSet()) {
// no option
return;
}
final ClassificationUndefinedHandlingType undefinedHandlingType = classificationTop.getUndefinedHandlingType();
if (undefinedHandlingType == null) {
// no way (just in case)
return;
}
if (!undefinedHandlingType.isChecked()) {
// no handling option
return;
}
final boolean quote = prop.isCodeTypeNeedsQuoted(classificationName);
final List<String> codeList = prop.getClassificationElementCodeList(classificationName);
final String sql = buildDistinctSql(tableDbName, columnDbName, quote, codeList);
PreparedStatement ps = null;
ResultSet rs = null;
try {
_log.info(sql);
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
final List<String> illegalCodeList = new ArrayList<String>();
while (rs.next()) {
illegalCodeList.add(rs.getString(1));
}
if (!illegalCodeList.isEmpty()) {
handleLoadDataIllegalImplicitClassificationValueException(file, tableDbName, columnDbName, classificationName, codeList, illegalCodeList, undefinedHandlingType);
}
} finally {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
}
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfRefClsLoadingHandler method registerRefClsReference.
// ===================================================================================
// Register Reference
// ==================
public void registerRefClsReference(String requestName, String clsTheme, List<DfClassificationTop> topList, Map<String, Object> optionMap) {
if (!isOptionLastaFlute(optionMap)) {
// only LastaFlute classifications can be referred (to be simple logic)
return;
}
if (isOptionLastaDoc(optionMap)) {
// LastaDoc uses real loader's registration (to avoid unexpected data use)
return;
}
final Map<String, DfClassificationTop> clsTopMap = topList.stream().collect(Collectors.toMap(top -> top.getClassificationName(), top -> top));
// not null here, already checked here
final String cdefPackage = extractCDefPackage(optionMap);
// me too
final String cdefClassName = extractCDefClassName(optionMap);
if (cdefPackage == null || cdefClassName == null) {
// just in case
throwRefClsReferenceCDefInfoNotFoundException(requestName, clsTheme, optionMap, cdefPackage, cdefClassName);
}
final DfRefClsReferredCDef referredCDef = new DfRefClsReferredCDef(cdefPackage, cdefClassName);
DfRefClsReferenceRegistry.getInstance().registerReference(clsTheme, clsTopMap, referredCDef);
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfRefClsLoadingHandler method prepareImportedReferredCDefFqcnList.
// ===================================================================================
// Referred CDef
// =============
public List<String> prepareImportedReferredCDefFqcnList(List<DfClassificationTop> topList, Map<String, Object> optionMap) {
// null allowed, as best effort way
final String currentCDefPackage = extractCDefPackage(optionMap);
final Map<String, String> refThemeCDefFqcnMap = new LinkedHashMap<String, String>();
for (DfClassificationTop top : topList) {
final List<DfRefClsElement> refClsElementList = top.getRefClsElementList();
for (DfRefClsElement refClsElement : refClsElementList) {
final String refClsTheme = refClsElement.getRefClsTheme();
final String existingImportExp = refThemeCDefFqcnMap.get(refClsTheme);
if (existingImportExp != null) {
break;
}
final String referredCDefPackage = refClsElement.getReferredCDefPackage();
if (currentCDefPackage != null && currentCDefPackage.equals(referredCDefPackage)) {
// same-package import statement is unneeded (to avoid Eclipse warning) e.g. namedcls to namedcls
continue;
}
final String referredCDefClassName = refClsElement.getReferredCDefClassName();
final String refThemeCDefFqcn = referredCDefPackage + "." + referredCDefClassName;
refThemeCDefFqcnMap.put(refClsTheme, refThemeCDefFqcn);
}
}
return new ArrayList<>(refThemeCDefFqcnMap.values());
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfRefClsLoadingHandler method findReferredClsTop.
// ===================================================================================
// Find Reference
// ==============
// -----------------------------------------------------
// Referred ClsTop
// ---------------
protected DfClassificationTop findReferredClsTop(String classificationName, String refAttr, String refClsTheme, String refClsName, DfFreeGenResource resource) {
final DfRefClsReference reference = findReference(classificationName, refAttr, refClsTheme, refClsName, resource);
final Map<String, DfClassificationTop> clsTopMap = reference.getReferredClsTopMap();
final DfClassificationTop referredClsTop = clsTopMap.get(refClsName);
if (referredClsTop == null) {
throwAppClsReferredClsNotFoundException(classificationName, refAttr, refClsTheme, refClsName, clsTopMap, resource);
}
return referredClsTop;
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfRefClsLoadingHandler method createRefClsElement.
public DfRefClsElement createRefClsElement(String classificationName, Map<String, Object> elementMap, DfFreeGenResource resource) {
// e.g. map:{ refCls=maihamadb@MemberStatus ; refType=included }
final String refAttr = (String) elementMap.get(DfRefClsElement.KEY_REFCLS);
// of e.g. DB or "appcls" or namedcls's name
final String refClsTheme;
// classification name
final String refClsName;
final String refGroupName;
if (refAttr.contains("@")) {
// #hope other schema's reference
refClsTheme = Srl.substringFirstFront(refAttr, "@");
final String rearName = Srl.substringFirstRear(refAttr, "@");
if (rearName.contains(".")) {
refClsName = Srl.substringFirstFront(rearName, ".");
refGroupName = Srl.substringFirstRear(rearName, ".");
} else {
refClsName = rearName;
refGroupName = null;
}
} else {
// current DB as default
refClsTheme = getBasicProperties().getProjectName();
if (refAttr.contains(".")) {
refClsName = Srl.substringFirstFront(refAttr, ".");
refGroupName = Srl.substringFirstRear(refAttr, ".");
} else {
refClsName = refAttr;
refGroupName = null;
}
}
final String refType = extractRefType(classificationName, elementMap);
final DfClassificationTop referredClsTop = findReferredClsTop(classificationName, refAttr, refClsTheme, refClsName, resource);
final DfRefClsReferredCDef referredCDef = findReferredCDef(classificationName, refAttr, refClsTheme, refClsName, resource);
final DfClassificationGroup referredGroup = findReferredGroup(classificationName, refAttr, refClsTheme, refClsName, refGroupName, referredClsTop, resource);
final String resourceFile = resource.getResourceFile();
return new DfRefClsElement(refClsTheme, refClsName, refGroupName, refType, referredClsTop, referredCDef, referredGroup, resourceFile);
}
Aggregations