use of org.dbflute.logic.sql2entity.cmentity.DfCustomizeEntityInfo in project dbflute-core by dbflute.
the class DfOutsideSqlAnalyzer method execSQL.
// ===================================================================================
// Execution
// =========
@Override
protected void execSQL(String sql) {
checkRequiredSqlComment(sql);
ResultSet rs = null;
try {
DfCustomizeEntityInfo customizeEntityInfo = null;
boolean alreadyIncrementGoodSqlCount = false;
if (isTargetEntityMakingSql(sql)) {
{
final String executedSql = buildExecutedSql(sql);
checkStatement(executedSql);
rs = _currentStatement.executeQuery(executedSql);
}
_goodSqlCount++;
alreadyIncrementGoodSqlCount = true;
// for Customize Entity
final Map<String, DfColumnMeta> columnMetaMap = extractColumnMetaMap(sql, rs);
customizeEntityInfo = processCustomizeEntity(sql, columnMetaMap);
}
if (isTargetParameterBeanMakingSql(sql)) {
if (customizeEntityInfo == null) {
_log.info("*Only parameter-bean is created: the SQL was not executed.");
}
if (!alreadyIncrementGoodSqlCount) {
_goodSqlCount++;
}
// for Parameter Bean
processParameterBean(sql, customizeEntityInfo);
}
} catch (SQLException e) {
if (_runInfo.isErrorContinue()) {
_log.warn("Failed to execute: " + sql, e);
_sql2entityMeta.addExceptionInfo(_sqlFile.getName(), e.getMessage() + ln() + sql);
} else {
throwSQLFailureException(sql, e);
}
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException ignored) {
_log.warn("Ignored exception: " + ignored.getMessage());
}
}
}
}
use of org.dbflute.logic.sql2entity.cmentity.DfCustomizeEntityInfo in project dbflute-core by dbflute.
the class DfOutsideSqlAnalyzer method processCustomizeEntity.
protected DfCustomizeEntityInfo processCustomizeEntity(String sql, Map<String, DfColumnMeta> columnMetaMap) {
String entityName = getCustomizeEntityName(sql);
if (entityName == null) {
return null;
}
entityName = resolveEntityNameIfNeeds(entityName, _sqlFile);
assertDuplicateEntity(entityName, _sqlFile);
// saves for setting to pmbMetaData
DfCustomizeEntityInfo entityInfo = new DfCustomizeEntityInfo(entityName, columnMetaMap);
entityInfo.setSqlFile(_sqlFile);
if (isDomain(sql)) {
entityInfo.setDomainHandling(true);
} else if (isCursor(sql)) {
entityInfo.setCursorHandling(true);
} else if (isScalar(sql)) {
entityInfo.setScalarHandling(true);
}
entityInfo.setPrimaryKeyList(getPrimaryKeyColumnNameList(sql));
entityInfo.setOutsideSqlFile(getCurrentOutsideSqlFile());
entityInfo.acceptSelectColumnComment(getSelectColumnCommentMap(sql));
_sql2entityMeta.addEntityInfo(entityName, entityInfo);
return entityInfo;
}
use of org.dbflute.logic.sql2entity.cmentity.DfCustomizeEntityInfo in project dbflute-core by dbflute.
the class DfOutsideSqlAnalyzer method assertDuplicateEntity.
// ===================================================================================
// Assert Definition
// =================
protected void assertDuplicateEntity(String entityName, File currentSqlFile) {
final DfCustomizeEntityInfo entityInfo = _sql2entityMeta.getEntityInfoMap().get(entityName);
if (entityInfo == null) {
return;
}
final File sqlFile = entityInfo.getSqlFile();
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("The same-name customize-entities were found.");
br.addItem("CustomizeEntity");
br.addElement(entityName);
br.addItem("SQL Files");
br.addElement(sqlFile);
br.addElement(currentSqlFile);
final String msg = br.buildExceptionMessage();
throw new DfCustomizeEntityDuplicateException(msg);
}
use of org.dbflute.logic.sql2entity.cmentity.DfCustomizeEntityInfo in project dbflute-core by dbflute.
the class DfProcedurePmbSetupper method doCreateEntityInfo.
protected DfCustomizeEntityInfo doCreateEntityInfo(String entityName, Map<String, DfColumnMeta> columnMap, DfTypeStructInfo structInfo) {
final DfCustomizeEntityInfo entityInfo;
if (structInfo != null) {
entityInfo = new DfCustomizeEntityInfo(entityName, columnMap, structInfo);
} else {
entityInfo = new DfCustomizeEntityInfo(entityName, columnMap);
}
entityInfo.setProcedureHandling(true);
return entityInfo;
}
use of org.dbflute.logic.sql2entity.cmentity.DfCustomizeEntityInfo in project dbflute-core by dbflute.
the class DfSql2EntityTask method initControlContext.
// ===================================================================================
// Prepare Generation
// ==================
@Override
public Context initControlContext() throws Exception {
_log.info("");
_log.info("...Preparing generation of customize-entities and parameter-beans");
_log.info("* * * * * * * * * *");
_log.info("* CustomizeEntity *");
_log.info("* * * * * * * * * *");
final StringBuilder logSb = new StringBuilder();
final Database database = _database;
database.setSql2EntitySchemaData(_schemaData);
database.setPmbMetaDataMap(_sql2entityMeta.getPmbMetaDataMap());
database.setSkipDeleteOldClass(isSkipDeleteOldClass());
final Map<String, DfCustomizeEntityInfo> entityInfoMap = _sql2entityMeta.getEntityInfoMap();
final Set<String> entityNameSet = entityInfoMap.keySet();
for (String entityName : entityNameSet) {
final DfCustomizeEntityInfo entityInfo = entityInfoMap.get(entityName);
final Map<String, DfColumnMeta> metaMap = entityInfo.getColumnMap();
final DfOutsideSqlFile outsideSqlFile = entityInfo.getOutsideSqlFile();
final Table tbl = new Table();
tbl.setSql2EntityCustomize(true);
if (outsideSqlFile != null) {
// basically true but checked just in case
tbl.setSql2EntitySqlFile(outsideSqlFile);
}
tbl.setName(entityInfo.getTableDbName());
if (!entityInfo.needsJavaNameConvert()) {
// basically here (except STRUCT type)
tbl.suppressJavaNameConvert();
}
if (entityInfo.hasNestedCustomizeEntity()) {
// basically when STRUCT type
tbl.setSql2EntityCustomizeHasNested(true);
}
if (entityInfo.isAdditionalSchema()) {
// basically when STRUCT type
tbl.setUnifiedSchema(entityInfo.getAdditionalSchema());
}
tbl.setSql2EntityTypeSafeCursor(entityInfo.isCursorHandling());
buildCustomizeEntityTitle(logSb, entityName, entityInfo);
final StringKeyMap<String> pkMap = getPrimaryKeyMap(entityInfo);
final boolean allCommonColumn = hasAllCommonColumn(metaMap);
final Set<String> columnNameSet = metaMap.keySet();
for (String columnName : columnNameSet) {
final Column column = new Column();
setupColumnName(columnName, column);
// an element removed from pkMap if true
// and a table name related to primary key is returned
final String pkRelatedTableName = setupPrimaryKey(pkMap, entityName, columnName, column);
setupTorqueType(metaMap, columnName, column, allCommonColumn);
setupDbType(metaMap, columnName, column);
setupNotNull(metaMap, columnName, column);
setupColumnSizeContainsDigit(metaMap, columnName, column);
setupColumnComment(metaMap, columnName, column);
setupSql2EntityElement(entityName, entityInfo, metaMap, columnName, column, pkRelatedTableName, logSb);
tbl.addColumn(column);
}
if (!pkMap.isEmpty()) {
// if not-removed columns exist
throwPrimaryKeyNotFoundException(entityName, pkMap, columnNameSet);
}
if (entityInfo.isScalarHandling()) {
// it does not generate an only-one-column entity
// one-way love for utility (just in case)
tbl.setDatabase(database);
processScalarHandling(entityInfo, tbl);
} else if (entityInfo.isDomainHandling()) {
// it does not generate an customize-entity
// one-way love for utility (just in case)
tbl.setDatabase(database);
processDomainHandling(entityInfo, tbl);
} else {
// initialize a class name of the entity for typed parameter-bean
// should be before getting names
database.addTable(tbl);
entityInfo.setEntityClassName(tbl.getExtendedEntityClassName());
entityInfo.setImmutableClassName(tbl.getImmutableExtendedEntityClassName());
}
logSb.append(ln());
}
final String databaseType = getDatabaseTypeFacadeProp().getTargetDatabase();
final AppData appData = new AppData(databaseType);
appData.addDatabase(database);
showCustomizeEntity(logSb);
showParameterBean();
final VelocityContext context = createVelocityContext(appData);
return context;
}
Aggregations