use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfClassificationResourceAnalyzerTest method test_analyze_by_lineList.
public void test_analyze_by_lineList() {
// ## Arrange ##
final DfClassificationResourceFileAnalyzer analyzer = new DfClassificationResourceFileAnalyzer() {
@Override
protected void setupClassificationTopOption(DfClassificationTop classificationTop) {
// because of little adjustment properties
// super.setupClassificationTopOption(classificationTop);
}
};
final List<String> lineList = new ArrayList<String>();
lineList.add("<encoding=\"UTF-8\"/>");
lineList.add("AAAAAAAAAAAA");
lineList.add("BBBB");
lineList.add("[会員ステータス]: MEMBER_STATUS_CODE");
lineList.add("$ MemberStatus, 会員の状態を示す");
lineList.add("- FML, Formalized, 正式会員, 正式な会員を示す");
lineList.add("- PVS, Provisinal, 仮会員, 仮の会員を示す");
lineList.add("- WDL, Withdrawal, 退会会員, 退会した会員を示す");
lineList.add("CCCCCCCCCCCC");
lineList.add("[会員ステータス2]: *_FLG");
lineList.add("$ MemberStatus2, 会員の状態を示す");
lineList.add("- FML, Formalized, 正式会員, 正式な会員を示す");
lineList.add("- PVS, Provisinal, 仮会員, 仮の会員を示す");
lineList.add("DDDDDDDDDD");
lineList.add("- WDL, Withdrawal, 退会会員, 退会した会員を示す");
lineList.add("EEEEEEEEEEEEE");
lineList.add("[Dummy]");
lineList.add("FFFFFFFFFFFFFFFFFF");
lineList.add("[Dummy2]");
lineList.add("$ ABC, DEF");
lineList.add("HHHHHHHHHHHHHHHHHHHHHH");
lineList.add("[会員ステータス3]");
lineList.add("$ MemberStatus3");
lineList.add("- FML, Formalized");
lineList.add("- PVS, Provisinal");
lineList.add("IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII");
// ## Act ##
final List<DfClassificationTop> classificationTopList = analyzer.analyze(lineList);
// ## Assert ##
assertNotNull(classificationTopList);
assertFalse(classificationTopList.isEmpty());
assertEquals(3, classificationTopList.size());
{
final DfClassificationTop top = classificationTopList.get(0);
assertEquals("MemberStatus", top.getClassificationName());
assertEquals("会員ステータス: 会員の状態を示す", top.getTopComment());
assertEquals("MEMBER_STATUS_CODE", top.getRelatedColumnName());
assertEquals(3, top.getClassificationElementList().size());
final List<DfClassificationElement> classificationElementList = top.getClassificationElementList();
{
final DfClassificationElement element = classificationElementList.get(0);
assertEquals("FML", element.getCode());
assertEquals("Formalized", element.getName());
assertEquals("正式会員", element.getAlias());
assertEquals("正式な会員を示す", element.getComment());
}
{
final DfClassificationElement element = classificationElementList.get(1);
assertEquals("PVS", element.getCode());
assertEquals("Provisinal", element.getName());
assertEquals("仮会員", element.getAlias());
assertEquals("仮の会員を示す", element.getComment());
}
{
final DfClassificationElement element = classificationElementList.get(2);
assertEquals("WDL", element.getCode());
assertEquals("Withdrawal", element.getName());
assertEquals("退会会員", element.getAlias());
assertEquals("退会した会員を示す", element.getComment());
}
}
{
final DfClassificationTop top = classificationTopList.get(1);
assertEquals("MemberStatus2", top.getClassificationName());
assertEquals("会員ステータス2: 会員の状態を示す", top.getTopComment());
assertEquals("suffix:_FLG", top.getRelatedColumnName());
assertEquals(2, top.getClassificationElementList().size());
final List<DfClassificationElement> classificationElementList = top.getClassificationElementList();
{
final DfClassificationElement element = classificationElementList.get(0);
assertEquals("FML", element.getCode());
assertEquals("Formalized", element.getName());
assertEquals("正式会員", element.getAlias());
assertEquals("正式な会員を示す", element.getComment());
}
{
final DfClassificationElement element = classificationElementList.get(1);
assertEquals("PVS", element.getCode());
assertEquals("Provisinal", element.getName());
assertEquals("仮会員", element.getAlias());
assertEquals("仮の会員を示す", element.getComment());
}
}
{
final DfClassificationTop top = classificationTopList.get(2);
assertEquals("MemberStatus3", top.getClassificationName());
assertEquals(null, top.getTopComment());
assertNull(top.getRelatedColumnName());
assertEquals(2, top.getClassificationElementList().size());
final List<DfClassificationElement> classificationElementList = top.getClassificationElementList();
{
final DfClassificationElement element = classificationElementList.get(0);
assertEquals("FML", element.getCode());
assertEquals("Formalized", element.getName());
assertNull(element.getAlias());
assertNull(element.getComment());
}
{
final DfClassificationElement element = classificationElementList.get(1);
assertEquals("PVS", element.getCode());
assertEquals("Provisinal", element.getName());
assertNull(element.getAlias());
assertNull(element.getComment());
}
}
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfRefClsLoadingHandler method inheritRefClsGroup.
// ===================================================================================
// Inherit refCls Group
// ====================
public void inheritRefClsGroup(DfClassificationTop classificationTop, DfRefClsElement refClsElement) {
// all types are inheritable, considering short grouping elements @since 1.2.5
final DfClassificationTop refClsTop = refClsElement.getReferredClsTop();
classificationTop.inheritRefClsGroup(refClsTop);
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop 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.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 DfClassificationProperties method processAllInOneTableClassification.
// -----------------------------------------------------
// All-in-One Table Classification
// -------------------------------
protected void processAllInOneTableClassification(Connection conn, String sql) {
final DfClassificationAllInOneSqlExecutor executor = new DfClassificationAllInOneSqlExecutor();
final List<Map<String, String>> resultList = executor.executeAllInOneSql(conn, sql);
for (Map<String, String> map : resultList) {
final String classificationName = map.get("classificationName");
final DfClassificationTop classificationTop;
{
DfClassificationTop tmpTop = _classificationTopMap.get(classificationName);
if (tmpTop == null) {
tmpTop = createAllInOneTableClassificationTop(classificationName);
_classificationTopMap.put(classificationName, tmpTop);
}
classificationTop = tmpTop;
}
// }
if (!classificationTop.hasTopComment()) {
final String topComment = map.get(DfClassificationTop.KEY_TOP_COMMENT);
classificationTop.setTopComment(topComment);
}
if (!classificationTop.hasCodeType()) {
final String codeType;
{
String tmpType = map.get(DfClassificationTop.KEY_CODE_TYPE);
if (Srl.is_Null_or_TrimmedEmpty(tmpType)) {
// for compatibility
tmpType = map.get(DfClassificationTop.KEY_DATA_TYPE);
}
codeType = tmpType;
}
classificationTop.setCodeType(codeType);
}
final DfClassificationElement element = new DfClassificationElement();
element.setClassificationName(classificationName);
element.acceptBasicItemMap(map);
classificationTop.addClassificationElement(element);
}
}
Aggregations