use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfSql2EntityTask method processDomainHandling.
// -----------------------------------------------------
// Result Handling
// ---------------
protected void processDomainHandling(DfCustomizeEntityInfo entityInfo, Table tbl) {
final DfPmbMetaData pmbMetaData = entityInfo.getPmbMetaData();
if (pmbMetaData == null || !pmbMetaData.isTypedReturnEntityPmb()) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("The 'domain' option was not related to a typed parameter-bean.");
br.addItem("Advice");
br.addElement("A 'domain' option should be defined with a typed parameter-bean");
br.addElement("that is typed to things returning an entity.");
br.addElement("For example:");
br.addElement(" (x): selectDomainMember.sql");
br.addElement(" (o): MemberBhv_selectDomainMember.sql");
br.addElement(" (x):");
br.addElement(" -- #df:entity#");
br.addElement(" -- +domain+");
br.addElement("");
br.addElement(" select MEMBER_ID, MEMBER_NAME, ... from MEMBER");
br.addElement(" (o):");
br.addElement(" -- #df:entity#");
br.addElement(" -- +domain+");
br.addElement("");
br.addElement(" -- !df:pmb!");
br.addElement("");
br.addElement(" select MEMBER_ID, MEMBER_NAME, ... from MEMBER");
br.addItem("SQL File");
br.addElement(entityInfo.getSqlFile());
final String msg = br.buildExceptionMessage();
throw new DfCustomizeEntityMarkInvalidException(msg);
}
final String entityClassName = pmbMetaData.getEntityClassName();
if (Srl.is_Null_or_TrimmedEmpty(entityClassName)) {
String msg = "The entity class name should not be null: " + entityInfo.getSqlFile();
// no way
throw new IllegalStateException(msg);
}
final Database database = _schemaData.getDatabase();
Table domainTable = database.getTable(entityClassName);
if (domainTable == null) {
// retry without project-prefix for a class name
final String projectPrefix = getBasicProperties().getProjectPrefix();
domainTable = database.getTable(Srl.substringFirstFront(entityClassName, projectPrefix));
}
if (domainTable == null) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("The table of the behavior query was not found.");
br.addItem("Advice");
br.addElement("A 'domain' option should be defined under behavior query.");
br.addElement("And behavior query should have an existing table.");
br.addElement("For example:");
br.addElement(" (x): MembooBhv_selectDomainMember.sql");
br.addElement(" (o): MemberBhv_selectDomainMember.sql");
br.addItem("SQL File");
br.addElement(entityInfo.getSqlFile());
final String msg = br.buildExceptionMessage();
// basically no way
throw new DfCustomizeEntityMarkInvalidException(msg);
}
final List<Column> columnList = tbl.getColumnList();
for (Column column : columnList) {
final Column found = domainTable.getColumn(column.getName());
if (found == null) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("The selected column was not a column of domain table.");
br.addItem("Advice");
br.addElement("A selected column with a 'domain' option");
br.addElement("should be one of domain table.");
br.addElement("For example:");
br.addElement(" (x):");
br.addElement(" select MEMBER_ID, 'noexist' as NO_EXIST from MEMBER");
br.addElement(" (o):");
br.addElement(" select MEMBER_ID, MEMBER_NAME from MEMBER");
br.addElement(" (o):");
br.addElement(" select member.* from MEMBER member");
br.addItem("SQL File");
br.addElement(entityInfo.getSqlFile());
br.addItem("Unknown Column");
br.addElement(column.getName());
br.addItem("Domain Table");
br.addElement(domainTable.getTableDbName());
final String msg = br.buildExceptionMessage();
throw new DfCustomizeEntityMarkInvalidException(msg);
}
}
entityInfo.setEntityClassName(domainTable.getExtendedEntityClassName());
entityInfo.setEntityClassName(domainTable.getImmutableExtendedEntityClassName());
}
use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfAdditionalUniqueKeyInitializer method initializeAdditionalUniqueKey.
// ===================================================================================
// AdditionalUniqueKey
// ===================
public void initializeAdditionalUniqueKey() {
_log.info("/=======================================");
_log.info("...Initializing additional unique keys.");
final Map<String, Map<String, String>> additionalUniqueKeyMap = getAdditionalUniqueKeyMap();
final Set<String> uniqueKeyNameSet = additionalUniqueKeyMap.keySet();
for (String uniqueKeyName : uniqueKeyNameSet) {
final String tableName = getTableName(uniqueKeyName);
assertTable(uniqueKeyName, tableName);
final List<String> columnNameList = getLocalColumnNameList(uniqueKeyName);
assertColumnList(uniqueKeyName, tableName, columnNameList);
final Table table = getTable(tableName);
final Unique unique = new Unique();
unique.setAdditional(true);
unique.setName(uniqueKeyName);
unique.setTable(table);
for (String columnName : columnNameList) {
unique.addColumn(columnName);
}
table.addUnique(unique);
showResult(uniqueKeyName, table, columnNameList);
}
_log.info("==========/");
}
use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfArrangeQueryDocSetupper method doExtractArrangeQuery.
protected Map<String, DfArrangeQueryTable> doExtractArrangeQuery(List<Table> tableList) {
final Map<String, DfArrangeQueryTable> resultMap = new LinkedHashMap<String, DfArrangeQueryTable>();
for (Table table : tableList) {
final String tableDbName = table.getTableDbName();
String beanClassName = table.getExtendedConditionBeanClassName();
String queryClassName = table.getExtendedConditionQueryClassName();
final DfArrangeQueryTable arrangeQueryTable = new DfArrangeQueryTable(tableDbName, beanClassName, queryClassName);
{
final String cbeanPath = prepareConditionBeanPath(table);
final List<DfArrangeQueryMethod> beanMethodList = searchArrangeQueryMethodList(tableDbName, cbeanPath);
if (!beanMethodList.isEmpty()) {
_log.info(" [{}]", arrangeQueryTable.getBeanClassName());
}
for (DfArrangeQueryMethod method : beanMethodList) {
_log.info(" o {}() // {}", method.getMethodName(), method.getTitle());
arrangeQueryTable.addBeanMethod(method);
}
}
{
final String queryPath = prepareConditionQueryPath(table);
final List<DfArrangeQueryMethod> queryMethodList = searchArrangeQueryMethodList(tableDbName, queryPath);
if (!queryMethodList.isEmpty()) {
_log.info(" [{}]", arrangeQueryTable.getQueryClassName());
}
for (DfArrangeQueryMethod method : queryMethodList) {
_log.info(" o {}() // {}", method.getMethodName(), method.getTitle());
arrangeQueryTable.addQueryMethod(method);
}
}
if (!arrangeQueryTable.getBeanMethodList().isEmpty() || !arrangeQueryTable.getQueryMethodList().isEmpty()) {
resultMap.put(tableDbName, arrangeQueryTable);
}
}
if (resultMap.isEmpty()) {
_log.info(" -> no arrange query");
}
return resultMap;
}
use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfLReverseFileOrder method toOverrideReverseOrderedMap.
// -----------------------------------------------------
// Override Reverse
// ----------------
protected Map<File, DfLReverseOutputResource> toOverrideReverseOrderedMap(List<List<Table>> orderedList, File baseDir) {
final DfLReverseExistingXlsInfo existingXlsInfo = extractExistingXlsInfo(baseDir);
final Map<File, DfLReverseOutputResource> orderedMap = createOrderedMap();
final String dataDirPath = resolvePath(baseDir);
final Map<String, String> tableNameMap = _tableNameProp.findTableNameMap(dataDirPath);
final Map<String, File> translatedXlsMap = prepareTranslatedXlsMap(existingXlsInfo, tableNameMap);
final List<Table> addedTableList = DfCollectionUtil.newArrayList();
int sectionNo = 1;
for (List<Table> nestedList : orderedList) {
for (Table table : nestedList) {
final File existingXls = translatedXlsMap.get(table.getTableDbName());
if (existingXls == null) {
addedTableList.add(table);
continue;
}
DfLReverseOutputResource resource = orderedMap.get(existingXls);
if (resource == null) {
final String mainName = extractMainName(nestedList);
final List<Table> initialList = new ArrayList<Table>();
resource = createOutputResource(existingXls, initialList, sectionNo, mainName);
orderedMap.put(existingXls, resource);
++sectionNo;
}
resource.addTable(table);
}
}
registerAddedTableIfExists(orderedMap, addedTableList, sectionNo);
orderTableByExistingOrder(orderedMap, existingXlsInfo);
return orderedMap;
}
use of org.apache.torque.engine.database.model.Table in project dbflute-core by dbflute.
the class DfLReverseFileOrder method toReplaceReverseOrderedMap.
// -----------------------------------------------------
// Replace Reverse
// ---------------
protected Map<File, DfLReverseOutputResource> toReplaceReverseOrderedMap(List<List<Table>> orderedList) {
final Map<File, DfLReverseOutputResource> orderedMap = DfCollectionUtil.newLinkedHashMap();
int sectionNo = 1;
for (List<Table> nestedList : orderedList) {
final String number = (sectionNo < 10 ? "0" + sectionNo : String.valueOf(sectionNo));
final String mainName = extractMainName(nestedList);
final File xlsFile = new File(buildXlsFilePath(number, mainName));
orderedMap.put(xlsFile, createOutputResource(xlsFile, nestedList, sectionNo, mainName));
++sectionNo;
}
return orderedMap;
}
Aggregations