use of org.dbflute.properties.assistant.classification.element.proploading.DfClsElementLiteralArranger in project dbflute-core by dbflute.
the class DfClassificationProperties method getClassificationDefinitionMap.
// -----------------------------------------------------
// Native Definition
// -----------------
/**
* Get the map of classification definition.
* @return The map of classification definition. (NotNull)
*/
protected Map<String, DfClassificationTop> getClassificationDefinitionMap() {
if (_classificationTopMap != null) {
return _classificationTopMap;
}
_classificationTopMap = newLinkedHashMap();
final Map<String, Object> plainDefinitionMap;
{
final String mapName = KEY_classificationDefinitionMap;
final String propKey = "torque." + mapName;
plainDefinitionMap = resolveSplit(mapName, mapProp(propKey, DEFAULT_EMPTY_MAP));
}
final DfClsElementLiteralArranger literalArranger = new DfClsElementLiteralArranger();
String allInOneSql = null;
Connection conn = null;
try {
for (Entry<String, Object> entry : plainDefinitionMap.entrySet()) {
final String classificationName = entry.getKey();
final Object objValue = entry.getValue();
// handle special elements
if (classificationName.equalsIgnoreCase("$$SQL$$")) {
allInOneSql = (String) objValue;
continue;
}
// check duplicate classification
if (_classificationTopMap.containsKey(classificationName)) {
String msg = "Duplicate classification: " + classificationName;
throw new DfIllegalPropertySettingException(msg);
}
final DfClassificationTop classificationTop = new DfClassificationTop(classificationName);
_classificationTopMap.put(classificationName, classificationTop);
// handle classification elements
if (!(objValue instanceof List<?>)) {
throwClassificationMapValueIllegalListTypeException(objValue);
}
final List<?> plainList = (List<?>) objValue;
final List<DfClassificationElement> elementList = new ArrayList<DfClassificationElement>();
boolean tableClassification = false;
for (Object element : plainList) {
if (!(element instanceof Map<?, ?>)) {
throwClassificationListElementIllegalMapTypeException(element);
}
@SuppressWarnings("unchecked") final Map<String, Object> elementMap = (Map<String, Object>) element;
// from table
final String table = (String) elementMap.get(DfClassificationElement.KEY_TABLE);
if (Srl.is_NotNull_and_NotTrimmedEmpty(table)) {
tableClassification = true;
if (conn == null) {
// on demand
conn = createMainSchemaConnection();
}
arrangeTableClassification(classificationTop, elementMap, table, elementList, conn);
continue;
}
// from literal
if (isElementMapClassificationTop(elementMap)) {
// top definition
arrangeClassificationTopFromLiteral(classificationTop, elementMap);
} else {
literalArranger.arrange(classificationName, elementMap);
final DfClassificationElement classificationElement = new DfClassificationElement();
classificationElement.setClassificationName(classificationName);
classificationElement.acceptBasicItemMap(elementMap);
elementList.add(classificationElement);
}
}
// adjust classification top
classificationTop.addClassificationElementAll(elementList);
classificationTop.setTableClassification(tableClassification);
_classificationTopMap.put(classificationName, classificationTop);
}
if (allInOneSql != null) {
if (conn == null) {
// on demand
conn = createMainSchemaConnection();
}
arrangeAllInOneTableClassification(conn, allInOneSql);
}
// *Classification Resource Point!
reflectClassificationResourceToDefinition();
filterUseDocumentOnly();
verifyClassificationConstraintsIfNeeds();
prepareSuppressedDBAccessClassTableSet();
} finally {
new DfClassificationJdbcCloser().closeConnection(conn);
}
return _classificationTopMap;
}
use of org.dbflute.properties.assistant.classification.element.proploading.DfClsElementLiteralArranger in project dbflute-core by dbflute.
the class DfAppClsTableLoader method loadTable.
// ===================================================================================
// Load Table
// ==========
// ; resourceMap = map:{
// ; baseDir = ../src/main
// ; resourceType = APP_CLS
// ; resourceFile = ../../../dockside_appcls.properties
// }
// ; outputMap = map:{
// ; templateFile = LaAppCDef.vm
// ; outputDirectory = $$baseDir$$/java
// ; package = org.dbflute...
// ; className = unused
// }
// ; optionMap = map:{
// }
@Override
public DfFreeGenMetaData loadTable(String requestName, DfFreeGenResource resource, DfFreeGenMapProp mapProp) {
final String resourceFile = resource.getResourceFile();
final Map<String, Object> appClsMap = readAppClsMap(resourceFile);
boolean hasRefCls = false;
final DfClassificationProperties clsProp = getClassificationProperties();
final DfClsElementLiteralArranger literalArranger = new DfClsElementLiteralArranger();
final List<DfClassificationTop> topList = new ArrayList<DfClassificationTop>();
for (Entry<String, Object> entry : appClsMap.entrySet()) {
final String classificationName = entry.getKey();
final DfClassificationTop classificationTop = new DfClassificationTop(classificationName);
topList.add(classificationTop);
DfRefClsElement refClsElement = null;
@SuppressWarnings("unchecked") final List<Map<String, Object>> elementMapList = (List<Map<String, Object>>) entry.getValue();
for (Map<String, Object> elementMap : elementMapList) {
if (isElementMapTop(elementMap)) {
// e.g. map:{ topComment=... ; codeType=String }
classificationTop.acceptBasicItem(elementMap);
classificationTop.putGroupingAll(clsProp.getElementMapGroupingMap(elementMap));
classificationTop.putDeprecatedAll(clsProp.getElementMapDeprecatedMap(elementMap));
} else {
if (isElementMapRefCls(elementMap)) {
// e.g. map:{ refCls=maihamadb@MemberStatus ; refType=included }
refClsElement = arrangeRefCls(resource, classificationName, classificationTop, refClsElement, elementMap);
} else {
// e.g. map:{ code=FML ; name=OneMan ; alias=ShowBase ; comment=Formalized }
arrangeLiteral(resource, classificationName, classificationTop, refClsElement, elementMap, literalArranger);
}
}
}
if (refClsElement != null) {
// should be after all literal evaluation
inheritRefClsGroup(classificationTop, refClsElement);
refClsElement.verifyRelationshipByRefTypeIfNeeds(classificationTop);
hasRefCls = true;
}
}
final Map<String, Object> optionMap = mapProp.getOptionMap();
// basically exists
final String clsTheme = (String) optionMap.getOrDefault("clsTheme", getDefaultClsTheme());
setupOptionMap(optionMap, topList, hasRefCls, clsTheme);
// @since 1.2.5
stopRedundantCommentIfNeeds(requestName, resourceFile, topList, optionMap);
// for next appcls's refCls @since 1.2.5
registerRefClsReference(requestName, clsTheme, topList, optionMap);
// #for_now can be flexible? (table name is unused?)
return DfFreeGenMetaData.asOnlyOne(optionMap, clsTheme, Collections.emptyList());
}
Aggregations