Search in sources :

Example 1 with Database

use of org.apache.torque.engine.database.model.Database in project dbflute-core by dbflute.

the class TorqueDocumentationTask method initializeSchemaData.

// ===================================================================================
// Prepare Generation
// ==================
@Override
protected void initializeSchemaData() {
    // basically called in fireVelocityProcess()
    if (isLoadDataReverseOnly() || isSchemaSyncCheckOnly()) {
        // don't use basic schema data
        // not to depends on JDBC task
        _schemaData = AppData.createAsEmpty();
    } else {
        // normally here (SchemaHTML, HistoryHTML)
        if (_schemaData == null) {
            // basically false, already initialized in SchemaHTML process so just in case
            purelyInitializeSchemaHtmlSchemaData();
        }
        final Database database = _schemaData.getDatabase();
        if (_schemaPolicyResult != null) {
            // null allowed when no policy
            database.setSchemaPolicyDisplay(new DfSPolicyDisplay(_schemaPolicyResult));
        }
        database.setEmbeddedPickup(_decoMapPickup);
        database.setFirstDateAgent(new DfFirstDateAgent(() -> {
            // for SchemaHTML's firstDate display
            return prepareCoreSchemaDiffList();
        }));
    }
}
Also used : DfFirstDateAgent(org.dbflute.logic.doc.supplement.firstdate.DfFirstDateAgent) DfSPolicyDisplay(org.dbflute.logic.doc.spolicy.display.DfSPolicyDisplay) Database(org.apache.torque.engine.database.model.Database)

Example 2 with Database

use of org.apache.torque.engine.database.model.Database in project dbflute-core by dbflute.

the class DfPmbPropertyOptionReference method getPmbMetaDataPropertyOptionReferenceColumn.

// ===================================================================================
// Reference Column
// ================
public Column getPmbMetaDataPropertyOptionReferenceColumn(AppData appData) {
    if (appData == null) {
        return null;
    }
    final Database database = appData.getDatabase();
    if (database == null) {
        return null;
    }
    final String refPrefix = OPTION_PREFIX;
    final String refSuffix = OPTION_SUFFIX;
    final String option;
    {
        final String optionExp = getPmbMetaDataPropertyOption();
        if (optionExp == null) {
            return null;
        }
        final List<String> splitOption = splitOption(optionExp);
        String firstOption = null;
        for (String element : splitOption) {
            if (element.startsWith(refPrefix) && element.endsWith(refSuffix)) {
                firstOption = element;
                break;
            }
        }
        if (firstOption == null) {
            return null;
        }
        option = firstOption;
    }
    final ScopeInfo scope = Srl.extractScopeFirst(option, refPrefix, refSuffix);
    final String content = scope.getContent().trim();
    final String delimiter = ".";
    final String tableName;
    final String columnName;
    if (content.contains(".")) {
        tableName = Srl.substringFirstFront(content, delimiter);
        columnName = Srl.substringFirstRear(content, delimiter);
    } else {
        tableName = content;
        columnName = null;
    }
    final Table table = database.getTable(tableName);
    if (table == null) {
        throwParameterBeanReferenceTableNotFoundException(option, tableName);
    }
    final String columnKeyName;
    if (columnName != null) {
        columnKeyName = columnName;
    } else {
        if (_pmbMetaData.isPropertyTypeList(_propertyName) && Srl.endsWith(_propertyName, "List")) {
            // e.g. statusList to status
            columnKeyName = Srl.substringLastFront(_propertyName, "List");
        } else {
            columnKeyName = _propertyName;
        }
    }
    final Column column = table.getColumn(columnKeyName);
    if (column == null) {
        throwParameterBeanReferenceColumnNotFoundException(option, tableName, columnName);
    }
    return column;
}
Also used : Table(org.apache.torque.engine.database.model.Table) Column(org.apache.torque.engine.database.model.Column) Database(org.apache.torque.engine.database.model.Database) List(java.util.List) ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 3 with Database

use of org.apache.torque.engine.database.model.Database in project dbflute-core by dbflute.

the class DfFreeGenInitializer method prepareDatabase.

protected Database prepareDatabase(DfSchemaXmlReader reader) {
    final AppData appData = reader.read();
    final Database database = appData.getDatabase();
    // same as ControlGenerateJava.vm
    database.initializeVersion(90);
    database.initializeSupplementaryMetaData();
    database.initializeIncludeQuery();
    database.checkProperties();
    return database;
}
Also used : AppData(org.apache.torque.engine.database.model.AppData) Database(org.apache.torque.engine.database.model.Database)

Example 4 with Database

use of org.apache.torque.engine.database.model.Database in project dbflute-core by dbflute.

the class DfFreeGenInitializer method setupReservedOption.

// ===================================================================================
// Reserved Option
// ===============
protected void setupReservedOption(String requestName, Map<String, Object> optionMap) {
    @SuppressWarnings("unchecked") final Map<String, Object> databaseMap = (Map<String, Object>) optionMap.get("databaseMap");
    if (databaseMap == null) {
        return;
    }
    for (Entry<String, Object> entry : databaseMap.entrySet()) {
        final String databaseName = entry.getKey();
        @SuppressWarnings("unchecked") final Map<String, Object> settingsMap = (Map<String, Object>) entry.getValue();
        final String schemaDir = (String) settingsMap.get("schemaDir");
        final String schemaXml;
        if (Srl.is_NotNull_and_NotTrimmedEmpty(schemaDir)) {
            schemaXml = schemaDir + "/project-schema-" + databaseName + ".xml";
        } else {
            final String schemaFile = (String) settingsMap.get("schemaFile");
            if (Srl.is_Null_or_TrimmedEmpty(schemaFile)) {
                String msg = "Not found the schemaDir or schemaFile property in the " + databaseName + " for " + requestName;
                throw new DfIllegalPropertySettingException(msg);
            }
            schemaXml = schemaFile;
        }
        final DfSchemaXmlReader reader = DfSchemaXmlReader.createAsFlexibleToManage(schemaXml);
        final Database database = prepareDatabase(reader);
        settingsMap.put("instance", database);
    }
}
Also used : Database(org.apache.torque.engine.database.model.Database) DfSchemaXmlReader(org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 5 with Database

use of org.apache.torque.engine.database.model.Database in project dbflute-core by dbflute.

the class DfLReverseProcess method execute.

// ===================================================================================
// Execute
// =======
public void execute() {
    final Database database = prepareDatabase();
    final List<Table> tableList = filterTableList(database);
    final List<String> sectionInfoList = prepareTitleSection(tableList);
    final File baseDir = prepareBaseDir();
    final Map<File, DfLReverseOutputResource> orderedMap = prepareOrderedMap(tableList, baseDir);
    reverseTableData(orderedMap, baseDir, sectionInfoList);
    outputTableNameMap();
    synchronizeOriginDateIfNeeds(sectionInfoList);
    outputResultMark(sectionInfoList);
}
Also used : Table(org.apache.torque.engine.database.model.Table) Database(org.apache.torque.engine.database.model.Database) File(java.io.File)

Aggregations

Database (org.apache.torque.engine.database.model.Database)11 Table (org.apache.torque.engine.database.model.Table)6 Column (org.apache.torque.engine.database.model.Column)5 List (java.util.List)3 Map (java.util.Map)3 AppData (org.apache.torque.engine.database.model.AppData)3 StringKeyMap (org.dbflute.helper.StringKeyMap)3 DfSchemaXmlReader (org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader)3 ArrayList (java.util.ArrayList)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 DfBuildProperties (org.dbflute.DfBuildProperties)2 DfBasicProperties (org.dbflute.properties.DfBasicProperties)2 DfCollectionUtil (org.dbflute.util.DfCollectionUtil)2 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1 VelocityContext (org.apache.velocity.VelocityContext)1 DfCustomizeEntityMarkInvalidException (org.dbflute.exception.DfCustomizeEntityMarkInvalidException)1 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)1