// ===================================================================================
 //                                                                   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);
 }
Exemplo n.º 2
0
 // -----------------------------------------------------
 //                                               Logging
 //                                               -------
 protected void buildCustomizeEntityTitle(
     StringBuilder logSb, String entityName, DfCustomizeEntityInfo entityInfo) {
   logSb.append(entityName);
   final String handlingDisp = entityInfo.buildHandlingDisp();
   if (Srl.is_NotNull_and_NotTrimmedEmpty(handlingDisp)) {
     logSb.append(" ").append(handlingDisp);
   }
   logSb.append(ln());
 }
Exemplo n.º 3
0
 protected void throwTableRelatedPrimaryKeyNotFoundException(
     String entityName, DfCustomizeEntityInfo entityInfo, String tableName, String columnName) {
   final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
   br.addNotice("The table name related to the primary key is not found.");
   br.addItem("OutsideSql");
   br.addElement(entityInfo.getOutsideSqlFile());
   br.addItem("Entity");
   br.addElement(entityName);
   br.addItem("Table Name");
   br.addElement(tableName);
   br.addItem("Primary Key");
   br.addElement(columnName);
   final String msg = br.buildExceptionMessage();
   throw new IllegalOutsideSqlOperationException(msg);
 }
Exemplo n.º 4
0
 protected void throwUnknownClassificationSpecifiedInHintException(
     String entityName, DfCustomizeEntityInfo entityInfo, Column column, String classification) {
   final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
   br.addNotice("Unknown classification specified in the hint.");
   br.addItem("OutsideSql");
   br.addElement(entityInfo.getOutsideSqlFile());
   br.addItem("Entity");
   br.addElement(entityName);
   br.addItem("Column");
   br.addElement(column.getName());
   br.addItem("Comment");
   br.addElement(column.getComment());
   br.addItem("Unknown Classification");
   br.addElement(classification);
   final String msg = br.buildExceptionMessage();
   throw new IllegalOutsideSqlOperationException(msg);
 }
Exemplo n.º 5
0
 protected StringKeyMap<String> getPrimaryKeyMap(DfCustomizeEntityInfo entityInfo) {
   final StringKeyMap<String> pkMap = StringKeyMap.createAsFlexibleOrdered();
   final List<String> pkList = entityInfo.getPrimaryKeyList();
   if (pkList == null || pkList.isEmpty()) {
     return pkMap;
   }
   for (String pk : pkList) {
     if (Srl.contains(pk, ".")) {
       final IndexOfInfo info = Srl.indexOfFirst(pk, ".");
       String tableName = info.substringFrontTrimmed();
       String pkName = info.substringRearTrimmed();
       pkMap.put(pkName, tableName);
     } else {
       pkMap.put(pk, null); // no specified related table
     }
   }
   return pkMap;
 }
Exemplo n.º 6
0
 protected void processScalarHandling(DfCustomizeEntityInfo entityInfo, Table tbl) {
   final DfPmbMetaData pmbMetaData = entityInfo.getPmbMetaData(); // for check only
   if (pmbMetaData == null || !pmbMetaData.isTypedSelectPmb()) { // not pinpoint (but enough)
     final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
     br.addNotice("The 'scalar' option was not related to a typed parameter-bean.");
     br.addItem("Advice");
     br.addElement("A 'scalar' option should be defined with a typed parameter-bean");
     br.addElement("that is typed to things returning an scalar value.");
     br.addElement("For example:");
     br.addElement("  (x): selectMemberName.sql");
     br.addElement("  (o): MemberBhv_selectMemberName.sql");
     br.addElement("  (x):");
     br.addElement("    -- #df:entity#");
     br.addElement("    -- +scalar+");
     br.addElement("");
     br.addElement("    select MEMBER_NAME from MEMBER");
     br.addElement("  (o):");
     br.addElement("    -- #df:entity#");
     br.addElement("    -- +scalar+");
     br.addElement("");
     br.addElement("    -- !df:pmb!");
     br.addElement("");
     br.addElement("    select MEMBER_NAME from MEMBER");
     br.addItem("SQL File");
     br.addElement(entityInfo.getSqlFile());
     final String msg = br.buildExceptionMessage();
     throw new DfCustomizeEntityMarkInvalidException(msg);
   }
   final List<Column> columnList = tbl.getColumnList();
   if (columnList.size() != 1) {
     final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
     br.addNotice("The 'scalar' option was related to non-only-one-column SQL.");
     br.addItem("Advice");
     br.addElement("A 'scalar' option should be defined on only-one-column SQL.");
     br.addElement("For example:");
     br.addElement("  (x):");
     br.addElement("    -- #df:entity#");
     br.addElement("    -- +scalar+");
     br.addElement("  ");
     br.addElement("    -- !df:pmb!");
     br.addElement("  ");
     br.addElement("    select MEMBER_NAME, BIRTHDATE from MEMBER");
     br.addElement("  (o):");
     br.addElement("    -- #df:entity#");
     br.addElement("    -- +scalar+");
     br.addElement("");
     br.addElement("    -- !df:pmb!");
     br.addElement("");
     br.addElement("    select BIRTHDATE from MEMBER");
     br.addItem("SQL File");
     br.addElement(entityInfo.getSqlFile());
     br.addItem("Selected Column");
     if (!columnList.isEmpty()) {
       for (Column column : columnList) {
         br.addElement(column.getName());
       }
     } else {
       br.addElement("(empty)");
     }
     final String msg = br.buildExceptionMessage();
     throw new DfCustomizeEntityMarkInvalidException(msg);
   }
   final Column column = columnList.get(0);
   entityInfo.setScalarJavaNative(column.getJavaNative());
   entityInfo.setScalarColumnDisp(column.getColumnDefinitionLineDisp());
 }
Exemplo n.º 7
0
 // -----------------------------------------------------
 //                                       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();
     throw new IllegalStateException(msg); // no way
   }
   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();
     throw new DfCustomizeEntityMarkInvalidException(msg); // basically no way
   }
   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());
 }
Exemplo n.º 8
0
  // ===================================================================================
  //                                                                  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()) {
        tbl.suppressJavaNameConvert(); // basically here (except STRUCT type)
      }
      if (entityInfo.hasNestedCustomizeEntity()) {
        tbl.setSql2EntityCustomizeHasNested(true); // basically when STRUCT type
      }
      if (entityInfo.isAdditionalSchema()) {
        tbl.setUnifiedSchema(entityInfo.getAdditionalSchema()); // basically when STRUCT type
      }
      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
        tbl.setDatabase(database); // one-way love for utility (just in case)
        processScalarHandling(entityInfo, tbl);
      } else if (entityInfo.isDomainHandling()) {
        // it does not generate an customize-entity
        tbl.setDatabase(database); // one-way love for utility (just in case)
        processDomainHandling(entityInfo, tbl);
      } else {
        // initialize a class name of the entity for typed parameter-bean
        database.addTable(tbl); // should be before getting names
        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;
  }