Search in sources :

Example 11 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfLReverseDataExtractor method processLargeData.

// ===================================================================================
// Large Data
// ==========
protected DfLReverseDataResult processLargeData(Table table, final List<String> sqlList) {
    final DfJdbcFacade facade = createJdbcFacade();
    final Map<String, ValueType> valueTypeMap = createColumnValueTypeMap(table.getColumnList());
    final DfJFadStringConverter converter = createStringConverter();
    final DfJFadCursorCallback callback = facade.selectCursor(sqlList, valueTypeMap, converter);
    return new DfLReverseDataResult(callback);
}
Also used : DfJFadStringConverter(org.dbflute.helper.jdbc.facade.DfJFadStringConverter) ValueType(org.dbflute.jdbc.ValueType) DfJFadCursorCallback(org.dbflute.helper.jdbc.facade.DfJFadCursorCallback) DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Example 12 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfProcedureNativeExtractorOracle method doSelectProcedureNativeInfoMap.

protected Map<String, ProcedureNativeInfo> doSelectProcedureNativeInfoMap(String sql) {
    final DfJdbcFacade facade = new DfJdbcFacade(_dataSource);
    final List<String> columnList = new ArrayList<String>();
    columnList.add("OBJECT_NAME");
    columnList.add("PROCEDURE_NAME");
    final List<Map<String, String>> resultList;
    try {
        log(sql);
        resultList = facade.selectStringList(sql, columnList);
    } catch (Exception continued) {
        // because it's basically assist info
        log("Failed to select procedure native info: " + continued.getMessage());
        return DfCollectionUtil.emptyMap();
    }
    final Map<String, ProcedureNativeInfo> infoMap = DfCollectionUtil.newLinkedHashMap();
    for (Map<String, String> map : resultList) {
        final ProcedureNativeInfo info = new ProcedureNativeInfo();
        final String objectName = map.get("OBJECT_NAME");
        final String procedureName = map.get("PROCEDURE_NAME");
        // translate Oracle's strange data structure
        if (Srl.is_NotNull_and_NotTrimmedEmpty(procedureName)) {
            // objectName is packageName here
            info.setPackageName(objectName);
            info.setProcedureName(procedureName);
        } else {
            // objectName is procedureName here
            info.setProcedureName(objectName);
        }
        infoMap.put(generateNativeInfoMapKey(objectName, procedureName), info);
    }
    return infoMap;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Example 13 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfProcedureParameterNativeExtractorOracle method doSelectProcedureArgumentInfoList.

protected List<DfProcedureArgumentInfo> doSelectProcedureArgumentInfoList(String sql) {
    final DfJdbcFacade facade = new DfJdbcFacade(_dataSource);
    final List<String> columnList = new ArrayList<String>();
    columnList.add("PACKAGE_NAME");
    columnList.add("OBJECT_NAME");
    columnList.add("OVERLOAD");
    columnList.add("SEQUENCE");
    columnList.add("ARGUMENT_NAME");
    columnList.add("IN_OUT");
    columnList.add("DATA_TYPE");
    columnList.add("DATA_LENGTH");
    columnList.add("DATA_PRECISION");
    columnList.add("DATA_SCALE");
    columnList.add("TYPE_OWNER");
    columnList.add("TYPE_NAME");
    columnList.add("TYPE_SUBNAME");
    final List<Map<String, String>> resultList;
    try {
        log(sql);
        resultList = facade.selectStringList(sql, columnList);
    } catch (Exception continued) {
        // because it's basically assist info
        log("Failed to select procedure argument info: " + continued.getMessage());
        return DfCollectionUtil.emptyList();
    }
    final List<DfProcedureArgumentInfo> infoList = DfCollectionUtil.newArrayList();
    for (Map<String, String> map : resultList) {
        final DfProcedureArgumentInfo info = new DfProcedureArgumentInfo();
        info.setPackageName(map.get("PACKAGE_NAME"));
        info.setObjectName(map.get("OBJECT_NAME"));
        info.setOverload(map.get("OVERLOAD"));
        info.setSequence(map.get("SEQUENCE"));
        info.setArgumentName(map.get("ARGUMENT_NAME"));
        info.setInOut(map.get("IN_OUT"));
        info.setDataType(map.get("DATA_TYPE"));
        info.setDataLength(map.get("DATA_LENGTH"));
        info.setDataPrecision(map.get("DATA_PRECISION"));
        info.setDataScale(map.get("DATA_SCALE"));
        // ARRAY and STRUCT only
        final String typeOwner = map.get("TYPE_OWNER");
        info.setTypeOwner(typeOwner);
        // nullable
        final String typeName = map.get("TYPE_NAME");
        if (Srl.is_NotNull_and_NotTrimmedEmpty(typeName)) {
            info.setTypeName(Srl.connectPrefix(typeName, typeOwner, "."));
        }
        info.setTypeSubName(map.get("TYPE_SUBNAME"));
        infoList.add(info);
    }
    return infoList;
}
Also used : ArrayList(java.util.ArrayList) DfProcedureArgumentInfo(org.dbflute.logic.jdbc.metadata.info.DfProcedureArgumentInfo) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap) DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Example 14 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfLReverseDataExtractor method selectData.

protected DfLReverseDataResult selectData(Table table) {
    final String tableSqlName = table.getTableSqlNameDirectUse();
    boolean large = false;
    if (_largeBorder >= 0) {
        if (_extractingLimit < 0 || _largeBorder < _extractingLimit) {
            final DfJdbcFacade facade = new DfJdbcFacade(_dataSource);
            final int countAll = facade.selectCountAll(tableSqlName);
            if (countAll > _largeBorder) {
                // it's large
                large = true;
            }
        }
    }
    final String sql = buildExtractingSql(table);
    if (large) {
        return processLargeData(table, sql);
    } else {
        // mainly here
        return processNormalData(table, sql);
    }
}
Also used : DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade)

Example 15 with DfJdbcFacade

use of org.dbflute.helper.jdbc.facade.DfJdbcFacade in project dbflute-core by dbflute.

the class DfJdbcFacadeTest method test_handleSQLException.

public void test_handleSQLException() throws Exception {
    // ## Arrange ##
    DfJdbcFacade facade = new DfJdbcFacade((DataSource) null);
    String sql = "select * from dual";
    SQLException e = new SQLException("foo message");
    try {
        // ## Act ##
        facade.handleSQLException(sql, e);
        // ## Assert ##
        fail();
    } catch (SQLFailureException actual) {
        // OK
        log(actual.getMessage());
        assertEquals(e, actual.getCause());
    }
}
Also used : SQLException(java.sql.SQLException) DfJdbcFacade(org.dbflute.helper.jdbc.facade.DfJdbcFacade) SQLFailureException(org.dbflute.exception.SQLFailureException)

Aggregations

DfJdbcFacade (org.dbflute.helper.jdbc.facade.DfJdbcFacade)23 Map (java.util.Map)13 ArrayList (java.util.ArrayList)12 StringKeyMap (org.dbflute.helper.StringKeyMap)5 DfJFadStringConverter (org.dbflute.helper.jdbc.facade.DfJFadStringConverter)4 ValueType (org.dbflute.jdbc.ValueType)4 LinkedHashMap (java.util.LinkedHashMap)2 DfJFadCursorCallback (org.dbflute.helper.jdbc.facade.DfJFadCursorCallback)2 SQLException (java.sql.SQLException)1 SQLFailureException (org.dbflute.exception.SQLFailureException)1 DfProcedureArgumentInfo (org.dbflute.logic.jdbc.metadata.info.DfProcedureArgumentInfo)1