use of org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData in project dbflute-core by dbflute.
the class DfParameterBeanResolver method extractPmbMetaData.
// ===================================================================================
// Extract
// =======
/**
* Extract the meta data of parameter bean.
* @param sql Target SQL. (NotNull and NotEmpty)
* @return the meta data of parameter bean. (NullAllowed: If it returns null, it means 'not found'.)
*/
public DfPmbMetaData extractPmbMetaData(String sql) {
final String parameterBeanName = getParameterBeanName(sql);
if (parameterBeanName == null) {
return null;
}
final DfPmbMetaData pmbMetaData = new DfPmbMetaData();
processClassHeader(sql, parameterBeanName, pmbMetaData);
processParameterProperty(sql, parameterBeanName, pmbMetaData);
pmbMetaData.setOutsideSqlFile(_outsideSqlFile);
pmbMetaData.adjustPropertyMetaFinally(_schemaData);
filterAlternateBooleanMethod(pmbMetaData);
if (!_alternateBooleanMethodNameSet.isEmpty()) {
// copy and clear the collection just in case
final Set<String> set = new LinkedHashSet<String>(_alternateBooleanMethodNameSet);
pmbMetaData.setAlternateMethodBooleanNameSet(set);
_alternateBooleanMethodNameSet.clear();
}
return pmbMetaData;
}
use of org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData in project dbflute-core by dbflute.
the class DfOutsideSqlAnalyzer method processParameterBean.
// -----------------------------------------------------
// ParameterBean
// -------------
protected void processParameterBean(String sql, DfCustomizeEntityInfo customizeEntityInfo) {
final DfParameterBeanResolver resolver = createParameterBeanResolver();
final DfPmbMetaData pmbMetaData = resolver.extractPmbMetaData(sql);
if (pmbMetaData == null) {
return;
}
if (customizeEntityInfo != null) {
pmbMetaData.setCustomizeEntityInfo(customizeEntityInfo);
// reverse reference
customizeEntityInfo.setPmbMetaData(pmbMetaData);
}
final String pmbName = pmbMetaData.getClassName();
assertDuplicateParameterBean(pmbName, _sqlFile);
_sql2entityMeta.addPmbMetaData(pmbName, pmbMetaData);
}
use of org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData 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.dbflute.logic.sql2entity.pmbean.DfPmbMetaData in project dbflute-core by dbflute.
the class DfOutsideSqlAnalyzer method assertDuplicateParameterBean.
protected void assertDuplicateParameterBean(String pmbName, File currentSqlFile) {
final DfPmbMetaData metaData = _sql2entityMeta.getPmbMetaDataMap().get(pmbName);
if (metaData == null) {
return;
}
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("The same-name parameter-beans were found.");
br.addItem("ParameterBean");
br.addElement(pmbName);
br.addItem("SQL Files");
br.addElement(metaData.getOutsideSqlFile());
br.addElement(currentSqlFile);
final String msg = br.buildExceptionMessage();
throw new DfParameterBeanDuplicateException(msg);
}
use of org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData in project dbflute-core by dbflute.
the class DfOldClassHandler method setPmbMetaDataMap.
public void setPmbMetaDataMap(Map<String, DfPmbMetaData> pmbMetaDataMap) {
final Map<String, Map<String, DfPmbMetaData>> pmbLocationMap = new LinkedHashMap<String, Map<String, DfPmbMetaData>>();
final Set<Entry<String, DfPmbMetaData>> entrySet = pmbMetaDataMap.entrySet();
for (Entry<String, DfPmbMetaData> entry : entrySet) {
final String pmbName = entry.getKey();
final DfPmbMetaData pmbMetaData = entry.getValue();
final String outputDirectory = pmbMetaData.getSql2EntityOutputDirectory();
Map<String, DfPmbMetaData> elementMap = pmbLocationMap.get(outputDirectory);
if (elementMap == null) {
elementMap = new LinkedHashMap<String, DfPmbMetaData>();
pmbLocationMap.put(outputDirectory, elementMap);
}
elementMap.put(pmbName, pmbMetaData);
}
if (pmbLocationMap.isEmpty()) {
// no outsideSql (all classes for outsideSql are old)
// main directory only
final String mainDir = getOutsideSqlProperties().getSql2EntityOutputDirectory();
pmbLocationMap.put(mainDir, new HashMap<String, DfPmbMetaData>());
}
_pmbLocationMap = pmbLocationMap;
}
Aggregations