use of org.dbflute.logic.manage.freegen.reflector.DfFreeGenLazyReflector in project dbflute-core by dbflute.
the class DfElasticsearchLoadingAgent method prepareRefColumn.
protected void prepareRefColumn(Map<String, Map<String, Object>> schemaMap, final String tableName, String columnName, Map<String, Object> columnAttrMap, Map<String, Object> columnBeanMap) {
// same as column name
final String refTableName = columnName;
addLazyReflector(new DfFreeGenLazyReflector() {
public void reflect() {
final Map<String, Object> tableBeanMap = schemaMap.get(refTableName);
if (tableBeanMap == null) {
throwJsonTableReferenceNotFoundException(tableName, refTableName);
}
columnBeanMap.put("entity", tableBeanMap);
}
});
}
use of org.dbflute.logic.manage.freegen.reflector.DfFreeGenLazyReflector in project dbflute-core by dbflute.
the class DfJsonSchemaLoadingAgent method prepareRefColumn.
protected void prepareRefColumn(Map<String, Map<String, Object>> schemaMap, final String tableName, String columnName, Map<String, Object> columnAttrMap, Map<String, Object> columnBeanMap) {
// same as column name
final String refTableName = columnName;
addLazyReflector(new DfFreeGenLazyReflector() {
public void reflect() {
final Map<String, Object> tableBeanMap = schemaMap.get(refTableName);
if (tableBeanMap == null) {
throwJsonTableReferenceNotFoundException(tableName, refTableName);
}
columnBeanMap.put("entity", tableBeanMap);
}
});
}
use of org.dbflute.logic.manage.freegen.reflector.DfFreeGenLazyReflector in project dbflute-core by dbflute.
the class DfXlsTableLoader method loadTable.
// ===================================================================================
// Load Table
// ==========
// ; resourceMap = map:{
// ; resourceType = XLS
// ; resourceFile = ../../...
// }
// ; outputMap = map:{
// ; templateFile = CsvDto.vm
// ; outputDirectory = ../src/main/java
// ; package = org.dbflute...
// ; className = FooDto
// }
// ; optionMap = map:{
// ; sheetName = [sheet-name]
// ; rowBeginNumber = 3
// ; columnMap = map:{
// ; name = 3
// ; type = 4
// }
// ; mappingMap = map:{
// ; type = map:{
// ; INTEGER = Integer
// ; VARCHAR = String
// }
// }
// }
@Override
public DfFreeGenMetaData loadTable(String requestName, DfFreeGenResource resource, DfFreeGenMapProp mapProp) {
final Map<String, Object> tableMap = mapProp.getOptionMap();
final Map<String, Map<String, String>> mappingMap = mapProp.getMappingMap();
if (tableMap == null || tableMap.isEmpty()) {
String msg = "The tableMap was not found in the FreeGen property: " + requestName;
throw new DfRequiredPropertyNotFoundException(msg);
}
final String sheetName = (String) tableMap.get("sheetName");
if (sheetName == null) {
String msg = "The sheetName was not found in the FreeGen property: " + requestName;
throw new DfRequiredPropertyNotFoundException(msg);
}
final Integer rowBeginNumber;
{
final String numStr = (String) tableMap.get("rowBeginNumber");
if (numStr == null) {
String msg = "The rowBeginNumber was not found in the FreeGen property: " + requestName;
throw new DfRequiredPropertyNotFoundException(msg);
}
rowBeginNumber = Integer.valueOf(numStr);
}
final String resourceFile = resource.getResourceFile();
@SuppressWarnings("unchecked") final Map<String, String> columnMap = (Map<String, String>) tableMap.get("columnMap");
final Workbook workbook = DfXlsFactory.instance().createWorkbook(new File(resourceFile));
final Sheet sheet = workbook.getSheet(sheetName);
if (sheet == null) {
String msg = "Not found the sheet name in the file: name=" + sheetName + " xls=" + resourceFile;
throw new IllegalStateException(msg);
}
// rows
final List<Map<String, Object>> columnList = new ArrayList<Map<String, Object>>();
for (int i = (rowBeginNumber - 1); i < Integer.MAX_VALUE; i++) {
final Row row = sheet.getRow(i);
if (row == null) {
break;
}
final Map<String, Object> beanMap = DfCollectionUtil.newLinkedHashMap();
final List<DfFreeGenLazyReflector> reflectorList = DfCollectionUtil.newArrayList();
boolean exists = false;
for (Entry<String, String> entry : columnMap.entrySet()) {
final String key = entry.getKey();
final String value = entry.getValue();
if (value == null) {
String msg = "Not found the value of the key in FreeGen " + requestName + ": " + key;
throw new DfIllegalPropertySettingException(msg);
}
if (processColumnValue(requestName, columnMap, row, beanMap, key, value, reflectorList, mappingMap)) {
exists = true;
}
}
prepareColumnNameConversion(requestName, beanMap, reflectorList);
if (exists) {
columnList.add(beanMap);
} else {
// means empty row
break;
}
for (DfFreeGenLazyReflector reflector : reflectorList) {
reflector.reflect();
}
}
// basically unused, also for compatible
final String tableName = sheetName;
return DfFreeGenMetaData.asOnlyOne(tableMap, tableName, columnList);
}
Aggregations