Search in sources :

Example 6 with DfLanguageGrammar

use of org.dbflute.logic.generate.language.grammar.DfLanguageGrammar in project dbflute-core by dbflute.

the class DfPmbMetaData method getPropertyOptionClassificationFixedElementValueExp.

public String getPropertyOptionClassificationFixedElementValueExp(String propertyName) {
    if (!isPropertyOptionClassificationFixedElement(propertyName)) {
        // no way
        return null;
    }
    final String classificationName = getPropertyOptionSpecifiedClassificationName(propertyName);
    if (isPropertyTypeList(propertyName)) {
        final List<String> elementList = DfCollectionUtil.newArrayList();
        if (isPropertyOptionClassificationFixedElementList(propertyName)) {
            final List<String> fixedElementList = getPropertyOptionClassificationFixedElementList(propertyName);
            for (String fixedElement : fixedElementList) {
                final String valueExp = buildPropertyOptionClassificationElementValueExp(propertyName, classificationName, fixedElement);
                elementList.add(valueExp);
            }
        } else {
            // property is list but specified one
            final String fixedElement = getPropertyOptionClassificationFixedElement(propertyName);
            final String valueExp = buildPropertyOptionClassificationElementValueExp(propertyName, classificationName, fixedElement);
            elementList.add(valueExp);
        }
        final DfLanguageGrammar grammar = getLanguageGrammar();
        return grammar.buildOneLinerListNewBackStage(elementList);
    } else {
        if (isPropertyOptionClassificationFixedElementList(propertyName)) {
            final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
            br.addNotice("Not list property but classification fixed element list.");
            br.addItem("ParameterBean");
            br.addElement(getClassName());
            br.addItem("Property");
            br.addElement(getPropertyType(propertyName) + " " + propertyName);
            br.addItem("Classification");
            br.addElement(classificationName);
            final List<String> fixedElementList = getPropertyOptionClassificationFixedElementList(propertyName);
            br.addItem("Element List");
            br.addElement(fixedElementList);
            final String msg = br.buildExceptionMessage();
            throw new IllegalStateException(msg);
        }
        final String fixedElement = getPropertyOptionClassificationFixedElement(propertyName);
        return buildPropertyOptionClassificationElementValueExp(propertyName, classificationName, fixedElement);
    }
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar)

Example 7 with DfLanguageGrammar

use of org.dbflute.logic.generate.language.grammar.DfLanguageGrammar in project dbflute-core by dbflute.

the class DfParameterAutoDetectAssist method doDerivePropertyTypeFromTestValue.

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;
}
Also used : ParseTimestampException(org.dbflute.util.DfTypeUtil.ParseTimestampException) Time(java.sql.Time) List(java.util.List) DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar) Timestamp(java.sql.Timestamp) ParseTimeException(org.dbflute.util.DfTypeUtil.ParseTimeException)

Example 8 with DfLanguageGrammar

use of org.dbflute.logic.generate.language.grammar.DfLanguageGrammar in project dbflute-core by dbflute.

the class DfDocumentTextResolver method doResolveJavaDocContent.

protected String doResolveJavaDocContent(String comment, String indent, boolean directIndent, boolean preText) {
    if (comment == null || comment.trim().length() == 0) {
        return null;
    }
    String work = comment;
    final DfBasicProperties basicProp = getBasicProperties();
    final DfLanguageGrammar grammar = basicProp.getLanguageDependency().getLanguageGrammar();
    work = grammar.escapeJavaDocString(work);
    work = removeCR(work);
    final String sourceCodeLineSeparator = basicProp.getSourceCodeLineSeparator();
    final String javaDocLineSeparator;
    if (directIndent) {
        javaDocLineSeparator = grammar.buildJavaDocLineAndIndentDirectly(sourceCodeLineSeparator, indent);
    // #for_now jflute directIndent with preText is unsupported for now (2021/08/15)
    } else {
        if (preText) {
            javaDocLineSeparator = grammar.buildJavaDocLineAndIndentPre(sourceCodeLineSeparator, indent);
        } else {
            javaDocLineSeparator = grammar.buildJavaDocLineAndIndent(sourceCodeLineSeparator, indent);
        }
    }
    if (work.contains(BASIC_LINE_SEPARATOR)) {
        work = work.replaceAll(BASIC_LINE_SEPARATOR, javaDocLineSeparator);
    }
    if (work.contains(SPECIAL_LINE_SEPARATOR)) {
        work = work.replaceAll(SPECIAL_LINE_SEPARATOR, javaDocLineSeparator);
    }
    return work;
}
Also used : DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar) DfBasicProperties(org.dbflute.properties.DfBasicProperties)

Example 9 with DfLanguageGrammar

use of org.dbflute.logic.generate.language.grammar.DfLanguageGrammar in project dbflute-core by dbflute.

the class DfDocumentProperties method doResolveTextForJavaDoc.

protected String doResolveTextForJavaDoc(String comment, String indent, boolean directIndent) {
    if (comment == null || comment.trim().length() == 0) {
        return null;
    }
    String work = comment;
    final DfLanguageGrammar grammar = getBasicProperties().getLanguageDependency().getLanguageGrammar();
    work = grammar.escapeJavaDocString(work);
    work = removeCR(work);
    final String sourceCodeLineSeparator = getBasicProperties().getSourceCodeLineSeparator();
    final String javaDocLineSeparator;
    if (directIndent) {
        javaDocLineSeparator = grammar.buildJavaDocLineAndIndentDirectly(sourceCodeLineSeparator, indent);
    } else {
        javaDocLineSeparator = grammar.buildJavaDocLineAndIndent(sourceCodeLineSeparator, indent);
    }
    if (work.contains(BASIC_LINE_SEPARATOR)) {
        work = work.replaceAll(BASIC_LINE_SEPARATOR, javaDocLineSeparator);
    }
    if (work.contains(SPECIAL_LINE_SEPARATOR)) {
        work = work.replaceAll(SPECIAL_LINE_SEPARATOR, javaDocLineSeparator);
    }
    return work;
}
Also used : DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar)

Example 10 with DfLanguageGrammar

use of org.dbflute.logic.generate.language.grammar.DfLanguageGrammar in project dbflute-core by dbflute.

the class Table method getLoadableCustomizePrimaryKeySettingExpressionList.

public List<String> getLoadableCustomizePrimaryKeySettingExpressionList() {
    final Table domain = getLoadableCustomizeDomain();
    if (domain == null) {
        return DfCollectionUtil.emptyList();
    }
    final List<Column> primaryKeyList = getPrimaryKey();
    final List<String> settingList = DfCollectionUtil.newArrayList();
    // true if all PKs have related columns
    final boolean hasRelatedColumn;
    {
        boolean notFoundExists = false;
        for (Column pk : primaryKeyList) {
            if (!pk.hasSql2EntityRelatedColumn()) {
                // for example, PostgreSQL
                notFoundExists = true;
                break;
            }
        }
        hasRelatedColumn = !notFoundExists;
    }
    int index = 0;
    for (Column pk : primaryKeyList) {
        final Column relatedColumn;
        if (hasRelatedColumn) {
            relatedColumn = pk.getSql2EntityRelatedColumn();
        } else {
            // if there are not related columns, it uses a key order
            relatedColumn = domain.getPrimaryKey().get(index);
        }
        final DfLanguageGrammar grammar = getBasicProperties().getLanguageDependency().getLanguageGrammar();
        settingList.add(grammar.buildEntityPropertyGetSet(pk, relatedColumn));
        ++index;
    }
    return settingList;
}
Also used : DfArrangeQueryTable(org.dbflute.logic.doc.arrqy.DfArrangeQueryTable) DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar)

Aggregations

DfLanguageGrammar (org.dbflute.logic.generate.language.grammar.DfLanguageGrammar)24 DfLanguageDependency (org.dbflute.logic.generate.language.DfLanguageDependency)3 DfLanguageImplStyle (org.dbflute.logic.generate.language.implstyle.DfLanguageImplStyle)2 DfBasicProperties (org.dbflute.properties.DfBasicProperties)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Map (java.util.Map)1 Column (org.apache.torque.engine.database.model.Column)1 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)1 DfArrangeQueryTable (org.dbflute.logic.doc.arrqy.DfArrangeQueryTable)1