Beispiel #1
0
 // ===================================================================================
 //                                                                         Line Helper
 //                                                                         ===========
 protected String filterAsLine(String text, FileTextLineFilter filter) {
   final String cr = "\r";
   final String lf = "\n";
   final StringBuilder sb = new StringBuilder();
   final List<String> lineList = Srl.splitList(text, lf);
   final int lineCount = lineList.size();
   int index = 0;
   for (String line : lineList) {
     final String pureLine;
     final boolean hasCR;
     if (line.endsWith(cr)) {
       pureLine = Srl.substringLastFront(line, cr);
       hasCR = true;
     } else {
       pureLine = line;
       hasCR = false;
     }
     final String filteredLine = filter.filter(pureLine);
     if (filteredLine != null) {
       sb.append(filteredLine);
       if (index + 1 < lineCount) { // not last line
         sb.append(hasCR ? cr : "").append(lf);
       }
     }
     ++index;
   }
   return sb.toString();
 }
 protected String doResolvePackageName(String typeName, boolean exceptUtil) {
   if (typeName == null) {
     return typeName;
   }
   final String processed = processLanguageType(typeName, exceptUtil);
   if (processed != null) {
     return processed;
   }
   if (typeName.contains(VAR_CDEF)) {
     final DfBasicProperties prop = getBasicProperties();
     final String pkg = prop.getBaseCommonPackage();
     final String prefix = prop.getProjectPrefix();
     typeName = DfStringUtil.replace(typeName, VAR_CDEF, pkg + "." + prefix + "CDef");
   }
   if (typeName.contains(VAR_DOMAIN + ".")) { // as domain entity
     final String pkg = getBasicProperties().getExtendedEntityPackage();
     typeName = Srl.replace(typeName, VAR_DOMAIN + ".", pkg + ".");
   }
   if (typeName.contains(VAR_CUSTOMIZE + ".")) { // as customize entity
     final String pkg = getOutsideSqlProperties().getExtendedEntityPackage();
     typeName = Srl.replace(typeName, VAR_CUSTOMIZE + ".", pkg + ".");
   }
   if (typeName.contains(VAR_PMB + ".")) { // as parameter-bean
     final String pkg = getOutsideSqlProperties().getExtendedParameterBeanPackage();
     typeName = Srl.replace(typeName, VAR_PMB + ".", pkg + ".");
   }
   return typeName;
 }
 protected void buildCustomizeEntityColumnInfo(
     StringBuilder logSb,
     String columnName,
     Column column,
     Table relatedTable,
     Column relatedColumn,
     String forcedJavaNatice) {
   final StringBuilder sb = new StringBuilder();
   sb.append(" ").append(column.isPrimaryKey() ? "*" : " ");
   sb.append(columnName);
   sb.append(" ");
   sb.append(column.getDbTypeExpression());
   final String columnSize = column.getColumnSize();
   if (Srl.is_NotNull_and_NotTrimmedEmpty(columnSize)) {
     sb.append("(").append(columnSize).append(")");
   }
   if (relatedColumn != null) {
     sb.append(" related to ").append(relatedTable.getTableDbName());
     sb.append(".").append(relatedColumn.getName());
   }
   if (Srl.is_NotNull_and_NotTrimmedEmpty(forcedJavaNatice)) {
     sb.append(" forced to ").append(forcedJavaNatice);
   }
   logSb.append(sb).append(ln());
 }
 protected String doDerivePropertyTypeFromTestValue(String testValue) { // test point
   if (testValue == null) {
     String msg = "The argument 'testValue' should be not null.";
     throw new IllegalArgumentException(msg);
   }
   final DfLanguageGrammar grammar = getLanguageGrammar();
   final String plainTypeName;
   if (Srl.startsWithIgnoreCase(testValue, "date '", "date'")) {
     plainTypeName = "Date";
   } else if (Srl.startsWithIgnoreCase(testValue, "timestamp '", "timestamp'")) {
     plainTypeName = "Timestamp";
   } else if (Srl.startsWithIgnoreCase(testValue, "time '", "time'")) {
     plainTypeName = "Time";
   } else {
     if (Srl.isQuotedSingle(testValue)) {
       final String unquoted = Srl.unquoteSingle(testValue);
       Timestamp timestamp = null;
       Time time = null;
       try {
         timestamp = DfTypeUtil.toTimestamp(unquoted);
       } catch (ParseTimestampException ignored) {
         try {
           time = DfTypeUtil.toTime(unquoted);
         } catch (ParseTimeException andIgnored) {
         }
       }
       if (timestamp != null) {
         final String timeParts = DfTypeUtil.toString(timestamp, "HH:mm:ss.SSS");
         if (timeParts.equals("00:00:00.000")) {
           plainTypeName = "Date";
         } else {
           plainTypeName = "Timestamp";
         }
       } else if (time != null) {
         plainTypeName = "Time";
       } else {
         plainTypeName = "String";
       }
     } else if (Srl.isQuotedAnything(testValue, "(", ")")) {
       final String unquoted = Srl.unquoteAnything(testValue, "(", ")");
       final List<String> elementList = Srl.splitListTrimmed(unquoted, ",");
       if (elementList.size() > 0) {
         final String firstElement = elementList.get(0);
         // InScope for Date is unsupported at this analyzing
         if (Srl.isQuotedSingle(firstElement)) {
           plainTypeName = "List" + grammar.buildGenericOneClassHint("String");
         } else {
           final String elementType = doDeriveNonQuotedLiteralTypeFromTestValue(firstElement);
           plainTypeName = "List" + grammar.buildGenericOneClassHint(elementType);
         }
       } else {
         plainTypeName = "List" + grammar.buildGenericOneClassHint("String");
       }
     } else {
       plainTypeName = doDeriveNonQuotedLiteralTypeFromTestValue(testValue);
     }
   }
   return plainTypeName;
 }
 protected void setupColumnComment(
     Map<String, DfColumnMeta> metaMap, String columnName, Column column) {
   final DfColumnMeta columnMeta = metaMap.get(columnName);
   final String sql2EntityRelatedTableName = columnMeta.getSql2EntityRelatedTableName();
   final Table relatedTable = getRelatedTable(sql2EntityRelatedTableName);
   String relatedComment = null;
   if (relatedTable != null) {
     final String relatedColumnName = columnMeta.getSql2EntityRelatedColumnName();
     final Column relatedColumn = relatedTable.getColumn(relatedColumnName);
     if (relatedColumn != null) {
       relatedComment = relatedColumn.getPlainComment();
     }
   }
   // the meta has its select column comment
   final String selectColumnComment = columnMeta.getColumnComment();
   final String commentMark = "// ";
   final String delimiter = getAliasDelimiterInDbComment();
   final StringBuilder sb = new StringBuilder();
   if (Srl.is_NotNull_and_NotTrimmedEmpty(relatedComment)) {
     sb.append(relatedComment);
     if (Srl.is_NotNull_and_NotTrimmedEmpty(selectColumnComment)) { // both exist
       if (Srl.is_NotNull_and_NotTrimmedEmpty(delimiter)) { // use alias option
         if (relatedComment.contains(delimiter)) { // resolved in related comment
           sb.append(ln()).append(commentMark).append(selectColumnComment);
         } else { // unresolved yet
           if (isDbCommentOnAliasBasis()) { // related comment is alias
             sb.append(delimiter);
           } else { // related comment is description
             sb.append(ln());
           }
           sb.append(commentMark).append(selectColumnComment);
         }
       } else { // no alias option
         sb.append(ln()).append(commentMark).append(selectColumnComment);
       }
     }
   } else { // not found related comment
     if (Srl.is_NotNull_and_NotTrimmedEmpty(selectColumnComment)) {
       if (Srl.is_NotNull_and_NotTrimmedEmpty(delimiter)) { // use alias option
         if (isDbCommentOnAliasBasis()) {
           // select column comment is treated as description
           sb.append(delimiter);
         }
       }
       sb.append(commentMark).append(selectColumnComment);
     }
   }
   column.setPlainComment(sb.toString());
 }
 protected String processMapType(
     String typeName, boolean exceptUtil, String mapPkg, String mapName) {
   final String mapBegin = mapName + "<";
   final String mapEnd = ">";
   if (typeName.startsWith(mapBegin) && typeName.endsWith(mapEnd)) {
     final ScopeInfo scope = Srl.extractScopeWide(typeName, mapBegin, mapEnd);
     final String content = scope.getContent();
     final String keyType = Srl.substringFirstFront(content, ",").trim();
     final String valueType = Srl.substringFirstRear(content, ",").trim();
     final String resolvedValueType = doResolvePackageName(valueType, exceptUtil);
     return mapPkg + "." + mapBegin + keyType + ", " + resolvedValueType + mapEnd;
   } else {
     return null;
   }
 }
 protected void resolveSuperClassSimplePagingBean(DfPmbMetaData pmbMetaData) {
   final String superClassName = pmbMetaData.getSuperClassName();
   if (Srl.endsWithIgnoreCase(superClassName, "Paging") // main
       || Srl.equalsIgnoreCase(
           superClassName, "SPB")) { // an old style for compatibility before 0.9.7.5
     pmbMetaData.setSuperClassName("SimplePagingBean");
     if (Srl.equalsIgnoreCase(superClassName, "ManualPaging")) {
       pmbMetaData.setPagingType(DfPagingType.MANUAL);
     } else if (Srl.equalsIgnoreCase(superClassName, "AutoPaging")) {
       pmbMetaData.setPagingType(DfPagingType.AUTO);
     } else {
       pmbMetaData.setPagingType(DfPagingType.UNKNOWN);
     }
   }
 }
 // -----------------------------------------------------
 //                                         Common Helper
 //                                         -------------
 protected boolean isRevervedProperty(String propertyName) {
   // properties for TypedParameterBean and SimplePagingBean and so on...
   return Srl.equalsIgnoreCase(
       propertyName,
       "OutsideSqlPath" // TypedParameterBean
       ,
       "EntityType" // TypedSelectPmb
       ,
       "ProcedureName",
       "EscapeStatement",
       "CalledBySelect" // ProcedurePmb
       ,
       "IsEscapeStatement",
       "IsCalledBySelect" // ProcedurePmb (C#)
       ,
       "FetchStartIndex",
       "FetchSize",
       "FetchPageNumber" // PagingBean
       ,
       "PageStartIndex",
       "PageEndIndex" // PagingBean
       ,
       "IsPaging" // PagingBean (C#)
       ,
       "OrderByClause",
       "OrderByComponent" // OrderByBean
       ,
       "SafetyMaxResultSize" // FetchBean
       ,
       "ParameterMap" // MapParameterBean
       );
 }
 protected Table setupSql2EntityRelatedTable(
     String entityName,
     DfCustomizeEntityInfo entityInfo,
     Map<String, DfColumnMeta> metaMap,
     String columnName,
     Column column,
     String pkRelatedTableName) {
   final DfColumnMeta columnMeta = metaMap.get(columnName);
   final String sql2EntityRelatedTableName = columnMeta.getSql2EntityRelatedTableName();
   Table relatedTable = getRelatedTable(sql2EntityRelatedTableName); // first attack
   if (relatedTable == null) {
     if (pkRelatedTableName != null) { // second attack using PK-related
       relatedTable = getRelatedTable(pkRelatedTableName);
       if (relatedTable == null) {
         throwTableRelatedPrimaryKeyNotFoundException(
             entityName, entityInfo, pkRelatedTableName, columnName);
       }
     } else {
       return null;
     }
   } else {
     if (pkRelatedTableName != null) {
       if (!Srl.equalsFlexible(sql2EntityRelatedTableName, pkRelatedTableName)) {
         throwTableRelatedPrimaryKeyDifferentException(
             entityName, entityInfo, sql2EntityRelatedTableName, pkRelatedTableName, columnName);
       }
     }
   }
   column.setSql2EntityRelatedTable(relatedTable);
   return relatedTable;
 }
 // -----------------------------------------------------
 //                                           For Comment
 //                                           -----------
 protected void doProcessAutoDetectForNode(
     String sql,
     Map<String, String> propertyNameTypeMap,
     Map<String, String> propertyNameOptionMap,
     ForNode forNode) {
   final String expression = forNode.getExpression();
   if (!isPmCommentStartsWithPmb(expression)) {
     return;
   }
   final String propertyName = substringPmCommentPmbRear(expression);
   if (propertyNameTypeMap.containsKey(propertyName)) {
     // because of priority low (bind variable is given priority over for-comment)
     return;
   }
   if (isRevervedProperty(propertyName)) {
     return;
   }
   final DetectedPropertyInfo detected = analyzeForNodeElementType(forNode, propertyName);
   if (detected != null) {
     final String propertyType = switchPlainTypeName(detected.getPropertyType());
     propertyNameTypeMap.put(propertyName, propertyType);
     final String propertyOption = detected.getPropertyOption();
     if (Srl.is_NotNull_and_NotTrimmedEmpty(propertyOption)) {
       propertyNameOptionMap.put(propertyName, propertyOption);
     }
   }
 }
 protected String doDeriveNonQuotedLiteralTypeFromTestValue(String testValue) {
   final String plainTypeName;
   if (Srl.contains(testValue, ".")) {
     BigDecimal decimalValue = null;
     try {
       decimalValue = DfTypeUtil.toBigDecimal(testValue);
     } catch (NumberFormatException ignored) {
     }
     if (decimalValue != null) {
       plainTypeName = "BigDecimal";
     } else { // means unknown type
       plainTypeName = "String";
     }
   } else {
     Long longValue = null;
     try {
       longValue = DfTypeUtil.toLong(testValue);
     } catch (NumberFormatException ignored) {
     }
     if (longValue != null) {
       if (longValue > Long.valueOf(Integer.MAX_VALUE)) {
         plainTypeName = "Long";
       } else {
         plainTypeName = "Integer";
       }
     } else {
       if (testValue.equalsIgnoreCase("true") || testValue.equalsIgnoreCase("false")) {
         plainTypeName = "Boolean";
       } else { // means unknown type
         plainTypeName = "String";
       }
     }
   }
   return plainTypeName;
 }
 protected void doProcessAlternateBooleanMethodIfNode(String sql, IfNode ifNode) {
   final String expression = ifNode.getExpression().trim(); // trim it just in case
   if (Srl.containsAny(expression, getIfCommentConnectors())
       || Srl.containsAny(expression, getIfCommentOperands())) {
     return; // unknown (type)
   }
   if (isPmCommentNestedProperty(expression) || !isPmCommentMethodCall(expression)) {
     return; // e.g. pmb.foo.bar
   }
   if (!isPmCommentStartsWithPmb(substringBooleanNotRear(expression))) {
     return; // e.g. #current.isFoo()
   }
   // pmb.foo() or !pmb.foo() here
   String methodName = substringPmCommentPmbRear(expression); // -> foo()
   methodName = Srl.substringLastFront(methodName, "()"); // -> foo
   _alternateBooleanMethodNameSet.add(methodName); // filter later
 }
 // -----------------------------------------------------
 //                                         Setup Element
 //                                         -------------
 protected void setupColumnName(String columnName, final Column col) {
   if (needsConvertToJavaName(columnName)) {
     col.setName(columnName);
   } else {
     col.setupNeedsJavaNameConvertFalse();
     col.setName(Srl.initCap(columnName));
   }
 }
 protected void setupDbType(Map<String, DfColumnMeta> metaMap, String columnName, Column column) {
   final DfColumnMeta columnMeta = metaMap.get(columnName);
   final String dbTypeName;
   final String plainName = columnMeta.getDbTypeName();
   if (Srl.contains(plainName, ".")) { // basically for ARRAY and STRUCT type
     final String catalogSchema = Srl.substringLastFront(plainName, ".");
     final UnifiedSchema unifiedSchema = UnifiedSchema.createAsDynamicSchema(catalogSchema);
     if (unifiedSchema.isMainSchema()) {
       dbTypeName = Srl.substringLastRear(plainName, ".");
     } else {
       dbTypeName = plainName;
     }
   } else {
     dbTypeName = plainName;
   }
   column.setDbType(dbTypeName);
 }
 // -----------------------------------------------------
 //                                               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());
 }
 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;
 }
 // -----------------------------------------------------
 //                                         Bind Variable
 //                                         -------------
 protected void processAutoDetectBindNode(
     String sql,
     Map<String, String> propertyNameTypeMap,
     Map<String, String> propertyNameOptionMap,
     Set<String> autoDetectedPropertyNameSet,
     BindVariableNode variableNode) {
   final String expression = variableNode.getExpression();
   final String testValue = variableNode.getTestValue();
   if (testValue == null) {
     return;
   }
   if (!isPmCommentStartsWithPmb(expression)) {
     return;
   }
   if (isPmCommentNestedProperty(expression) || isPmCommentMethodCall(expression)) {
     return;
   }
   final String propertyName = substringPmCommentPmbRear(expression);
   if (isRevervedProperty(propertyName)) {
     return;
   }
   final String typeName = derivePropertyTypeFromTestValue(testValue);
   propertyNameTypeMap.put(propertyName, typeName); // override if same one exists
   autoDetectedPropertyNameSet.add(propertyName);
   final String option = variableNode.getOptionDef();
   // add option if it exists
   // so it is enough to set an option to only one bind variable comment
   // if several bind variable comments for the same property exist
   final String derivedOption = derivePropertyOptionFromTestValue(testValue);
   if (Srl.is_NotNull_and_NotTrimmedEmpty(option)) {
     final String resolvedOption;
     if (Srl.is_NotNull_and_NotTrimmedEmpty(derivedOption)) {
       resolvedOption = option + "|" + derivedOption; // merged
     } else {
       resolvedOption = option;
     }
     propertyNameOptionMap.put(propertyName, resolvedOption);
   } else {
     if (Srl.is_NotNull_and_NotTrimmedEmpty(derivedOption)) {
       propertyNameOptionMap.put(propertyName, derivedOption);
     }
   }
 }
 protected DetectedPropertyInfo analyzeForNodeElementType(Node node, String propertyName) {
   if (isPmCommentNestedProperty(propertyName) || isPmCommentMethodCall(propertyName)) {
     return null;
   }
   final DfLanguageGrammar grammar = getLanguageGrammar();
   DetectedPropertyInfo detected = null;
   for (int i = 0; i < node.getChildSize(); i++) {
     final Node childNode = node.getChild(i);
     if (childNode instanceof BindVariableNode) {
       final BindVariableNode bindNode = (BindVariableNode) childNode;
       final String expression = bindNode.getExpression();
       if (!isPmCommentEqualsCurrent(expression)) {
         continue;
       }
       if (isPmCommentNestedProperty(expression) || isPmCommentMethodCall(expression)) {
         continue;
       }
       // /*#current*/ here
       final String testValue = bindNode.getTestValue();
       if (testValue == null) {
         continue;
       }
       final String propertyType = derivePropertyTypeFromTestValue(testValue);
       final String propertyOption = derivePropertyOptionFromTestValue(testValue);
       if (Srl.is_NotNull_and_NotTrimmedEmpty(propertyType)) {
         detected = new DetectedPropertyInfo();
         final String generic = grammar.buildGenericOneClassHint(propertyType);
         detected.setPropertyType("List" + generic);
         detected.setPropertyOption(propertyOption);
       }
     } else if (childNode instanceof ForNode) {
       final ForNode nestedNode = (ForNode) childNode;
       final String expression = nestedNode.getExpression();
       if (!isPmCommentStartsWithCurrent(expression)) {
         continue;
       }
       // /*FOR #current.xxx*/ here
       final String nestedForPropName = substringPmCommentCurrentRear(expression);
       detected = analyzeForNodeElementType(nestedNode, nestedForPropName); // recursive call
       if (detected != null) {
         final String generic = grammar.buildGenericOneClassHint(detected.getPropertyType());
         detected.setPropertyType("List" + generic);
       }
     } else if (childNode instanceof ScopeNode) { // IF, Begin, First, ...
       detected = analyzeForNodeElementType(childNode, propertyName); // recursive call
     }
     if (detected != null) {
       break;
     }
   }
   if (detected == null) {
     return null;
   }
   return detected;
 }
 // -----------------------------------------------------
 //                                            If Comment
 //                                            ----------
 protected void doProcessAutoDetectIfNode(
     String sql,
     Map<String, String> propertyNameTypeMap,
     Map<String, String> propertyNameOptionMap,
     IfNode ifNode) {
   final String ifCommentBooleanType = switchPlainTypeName("boolean");
   final String expression = ifNode.getExpression().trim(); // trim it just in case
   final List<String> elementList = Srl.splitList(expression, " ");
   for (int i = 0; i < elementList.size(); i++) {
     // boolean-not mark unused here so remove it at first
     final String element = substringBooleanNotRear(elementList.get(i));
     if (!isPmCommentStartsWithPmb(element)) {
       continue;
     }
     if (isPmCommentNestedProperty(element) || isPmCommentMethodCall(element)) {
       continue;
     }
     final String propertyName = substringPmCommentPmbRear(element);
     if (propertyNameTypeMap.containsKey(propertyName)) {
       // because of priority low (bind variable is given priority over if-comment)
       continue;
     }
     if (isRevervedProperty(propertyName)) {
       continue;
     }
     final int nextIndex = i + 1;
     if (elementList.size() <= nextIndex) { // last now
       propertyNameTypeMap.put(propertyName, ifCommentBooleanType);
       continue;
     }
     // next exists here
     final String nextElement = elementList.get(nextIndex);
     if (isIfCommentStatementConnector(nextElement)) { // e.g. '&&' or '||'
       propertyNameTypeMap.put(propertyName, ifCommentBooleanType);
       continue;
     }
     if (!isIfCommentStatementOperand(nextElement)) { // no way (wrong syntax)
       continue;
     }
     final int nextNextIndex = i + 2;
     if (elementList.size() <= nextNextIndex) { // no way (wrong syntax)
       continue;
     }
     // next next exists
     final String nextNextElement = elementList.get(nextNextIndex);
     if (isPmCommentStartsWithPmb(nextNextElement)) { // e.g. pmb.foo == pmb.bar
       continue;
     }
     // using-value statement here e.g. pmb.foo == 'foo'
     // condition value is treated as testValue to derive
     final String propertyType = derivePropertyTypeFromTestValue(nextNextElement);
     propertyNameTypeMap.put(propertyName, propertyType);
   }
 }
 protected void filterAlternateBooleanMethod(DfPmbMetaData pmbMetaData) {
   if (_alternateBooleanMethodNameSet.isEmpty()) {
     return;
   }
   for (String reservBooleanMethod : _reservBooleanMethodList) {
     if (_alternateBooleanMethodNameSet.contains(reservBooleanMethod)) {
       _alternateBooleanMethodNameSet.remove(reservBooleanMethod);
     }
   }
   final Map<String, String> propertyNameTypeMap = pmbMetaData.getPropertyNameTypeMap();
   for (String propertyName : propertyNameTypeMap.keySet()) {
     final String getterName = "get" + Srl.initCap(propertyName);
     if (_alternateBooleanMethodNameSet.contains(getterName)) {
       _alternateBooleanMethodNameSet.remove(getterName);
     }
     final String isName = "is" + Srl.initCap(propertyName);
     if (_alternateBooleanMethodNameSet.contains(isName)) {
       _alternateBooleanMethodNameSet.remove(isName);
     }
   }
 }
 protected String processListType(
     String typeName, boolean exceptUtil, String listPkg, String listName) {
   final String listBegin = listName + "<";
   final String listEnd = ">";
   if (typeName.startsWith(listBegin) && typeName.endsWith(listEnd)) {
     final ScopeInfo scope = Srl.extractScopeWide(typeName, listBegin, listEnd);
     final String content = scope.getContent();
     final String resolvedContent = doResolvePackageName(content, exceptUtil);
     return listPkg + "." + listBegin + resolvedContent + listEnd;
   } else {
     return null;
   }
 }
  public void test_buildDisplaySql_beforeComment_quotationOverComment() {
    // ## Arrange ##
    String sql = "' ?/*foo's bar*/select * from where FOO_NAME like ? escape '|'";
    String fooName = "fooName%";
    String barCode = "barCode";

    // ## Act ##
    String actual = createTarget().buildDisplaySql(sql, new Object[] {fooName, barCode});

    // ## Assert ##
    log(actual);
    assertTrue(Srl.containsAll(actual, fooName, barCode, "/*foo's bar*/", "escape '|'"));
  }
 protected void showParameterBean() {
   _log.info("* * * * * * * * *");
   _log.info("* ParameterBean *");
   _log.info("* * * * * * * * *");
   final StringBuilder logSb = new StringBuilder();
   final Map<String, DfPmbMetaData> pmbMetaDataMap = _sql2entityMeta.getPmbMetaDataMap();
   for (Entry<String, DfPmbMetaData> pmbEntry : pmbMetaDataMap.entrySet()) {
     final DfPmbMetaData pmbMetaData = pmbEntry.getValue();
     logSb.append(pmbMetaData.getClassName());
     if (pmbMetaData.hasSuperClassDefinition()) {
       logSb.append(" extends ").append(pmbMetaData.getSuperClassName());
     }
     if (pmbMetaData.isRelatedToProcedure()) {
       logSb.append(" (procedure");
       if (pmbMetaData.isProcedureRefCustomizeEntity()) {
         logSb.append(" with customize-entity");
       }
       logSb.append(")").append(ln());
       final Map<String, DfProcedureColumnMeta> propertyNameColumnInfoMap =
           pmbMetaData.getPropertyNameColumnInfoMap();
       for (Entry<String, DfProcedureColumnMeta> columnEntry :
           propertyNameColumnInfoMap.entrySet()) {
         final DfProcedureColumnMeta columnInfo = columnEntry.getValue();
         logSb.append("  ").append(columnInfo.getColumnNameDisp());
         logSb.append(ln());
       }
     } else {
       if (pmbMetaData.isTypedParameterBean()) {
         logSb.append(" ").append(pmbMetaData.buildTypedDisp());
       }
       logSb.append(ln());
       final Map<String, String> propertyNameTypeMap = pmbMetaData.getPropertyNameTypeMap();
       final Map<String, String> propertyOptionMap = pmbMetaData.getPropertyNameOptionMap();
       for (Entry<String, String> propEntry : propertyNameTypeMap.entrySet()) {
         final String propertyName = propEntry.getKey();
         final String propertyType = propEntry.getValue();
         logSb.append("  ").append(propertyType).append(" ").append(propertyName);
         final String optionDef = propertyOptionMap.get(propertyName);
         if (Srl.is_NotNull_and_NotTrimmedEmpty(optionDef)) {
           logSb.append(":").append(optionDef);
         }
         logSb.append(ln());
       }
     }
     logSb.append(ln());
   }
   if (logSb.length() > 0) {
     _log.info(ln() + logSb.toString().trim());
   }
 }
 protected String extractSql2EntityHintedClassification(
     String entityName, DfCustomizeEntityInfo entityInfo, Column column) {
   final String comment = column.getComment();
   final ScopeInfo scopeInfo = Srl.extractScopeFirst(comment, "cls(", ")");
   if (scopeInfo != null) {
     final String classification = scopeInfo.getContent().trim();
     if (!getProperties().getClassificationProperties().hasClassificationTop(classification)) {
       throwUnknownClassificationSpecifiedInHintException(
           entityName, entityInfo, column, classification);
     }
     return classification;
   }
   return null;
 }
 protected DataSource prepareTargetDataSource() {
   final DfDataSourceHandler handler = new DfDataSourceHandler();
   handler.setDriver(getDatabaseProperties().getDatabaseDriver()); // inherit
   final String url = getDocumentProperties().getSchemaSyncCheckDatabaseUrl();
   handler.setUrl(url); // may inherit
   final String user = getDocumentProperties().getSchemaSyncCheckDatabaseUser();
   if (Srl.is_Null_or_TrimmedEmpty(user)) { // just in case
     String msg = "The user for sync target schema was not found: " + user;
     throw new IllegalStateException(msg);
   }
   handler.setUser(user);
   handler.setPassword(getDocumentProperties().getSchemaSyncCheckDatabasePassword());
   handler.setConnectionProperties(getDatabaseProperties().getConnectionProperties()); // inherit
   handler.setAutoCommit(true);
   _log.info("...Preparing data source for SchemaSyncCheck target:");
   _log.info("  url  = " + url);
   _log.info("  user = " + user);
   return new DfFittingDataSource(handler);
 }
 protected void handleException() {
   final Map<String, String> exceptionInfoMap = _sql2entityMeta.getExceptionInfoMap();
   if (exceptionInfoMap.isEmpty()) {
     return;
   }
   final Set<String> nameSet = exceptionInfoMap.keySet();
   final StringBuilder sb = new StringBuilder();
   for (String name : nameSet) {
     final String exceptionInfo = exceptionInfoMap.get(name);
     sb.append("[" + name + "]");
     final boolean containsLn = Srl.contains(exceptionInfo, ln());
     sb.append(containsLn ? ln() : " ");
     sb.append(exceptionInfo);
     sb.append(containsLn ? ln() : "").append(ln());
   }
   _log.warn("/* * * * * * * * * * * * * * * * * {Warning Exception}");
   _log.warn(ln() + sb.toString().trim());
   _log.warn("* * * * * * * * * */");
   _log.warn(" ");
 }
 protected String derivePropertyOptionFromTestValue(String testValue) { // test point
   if (Srl.isQuotedSingle(testValue)) {
     final String unquoted = Srl.unquoteSingle(testValue);
     final int count = Srl.count(unquoted, "%");
     if (Srl.endsWith(unquoted, "%") && count == 1) {
       return "likePrefix";
     } else if (Srl.startsWith(unquoted, "%") && count == 1) {
       return "likeSuffix";
     } else if (Srl.isQuotedAnything(unquoted, "%") && count == 2) {
       return "likeContain";
     } else if (count > 0) {
       return "like";
     }
   }
   return null;
 }
  public void test_buildDisplaySql_questionInComment_quotationInComment() {
    // ## Arrange ##
    String sql =
        "/*foo's bar*/select * from where FOO_NAME/*qux?*/ like ? escape '|' and ? /*quux'?*/and ?";
    String fooName = "fooName%";
    String barCode = "barCode";
    Integer bazId = 3;

    // ## Act ##
    String actual = createTarget().buildDisplaySql(sql, new Object[] {fooName, barCode, bazId});

    // ## Assert ##
    log(actual);
    assertTrue(
        Srl.containsAll(
            actual,
            fooName,
            barCode,
            String.valueOf(bazId),
            "/*foo's bar*/",
            "escape '|'",
            "/*qux?*/",
            "/*quux'?*/and"));
  }
 protected final String initUncap(String str) {
   return Srl.initUncap(str);
 }
 protected final List<String> splitListTrimmed(String str, String delimiter) {
   return Srl.splitListTrimmed(str, delimiter);
 }