Search in sources :

Example 6 with FileTextIO

use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.

the class DfArrangeQueryDocSetupper method searchArrangeQueryMethodList.

// ===================================================================================
// Analyze Method
// ==============
protected List<DfArrangeQueryMethod> searchArrangeQueryMethodList(String tableDbName, String classFilePath) {
    final FileTextIO textIO = prepareSourceFileTextIO();
    if (!new File(classFilePath).exists()) {
        // e.g. generate-only of table-except
        return Collections.emptyList();
    }
    final String cqText = textIO.read(classFilePath);
    final List<String> lineList = Srl.splitList(cqText, "\n");
    return analyzeArrangeQueryLineList(tableDbName, lineList);
}
Also used : FileTextIO(org.dbflute.helper.filesystem.FileTextIO) File(java.io.File)

Example 7 with FileTextIO

use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.

the class DfAbsractDataWriter method processLargeTextFile.

// -----------------------------------------------------
// Large Text File
// ---------------
// contributed by awaawa, thanks!
protected boolean processLargeTextFile(String dataDirectory, File dataFile, String tableName, String columnName, String value, PreparedStatement ps, int bindCount, Map<String, DfColumnMeta> columnInfoMap, int rowNumber) throws SQLException {
    if (value == null || value.trim().length() == 0) {
        // cannot be binary
        return false;
    }
    final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
    if (columnInfo == null) {
        // unsupported when meta data is not found
        return false;
    }
    final Class<?> columnType = getBindType(tableName, columnInfo);
    if (columnType == null) {
        // unsupported too
        return false;
    }
    if (!isLargeTextFile(dataDirectory, tableName, columnName)) {
        // not target as large text file
        return false;
    }
    // the value should be a path to a text file
    // from data file's current directory
    final String path;
    final String trimmedValue = value.trim();
    if (trimmedValue.startsWith("/")) {
        // means absolute path
        path = trimmedValue;
    } else {
        final String dataFilePath = Srl.replace(dataFile.getAbsolutePath(), "\\", "/");
        final String baseDirPath = Srl.substringLastFront(dataFilePath, "/");
        path = baseDirPath + "/" + trimmedValue;
    }
    final File textFile = new File(path);
    if (!textFile.exists()) {
        throwLoadDataTextFileReadFailureException(tableName, columnName, path, rowNumber);
    }
    try {
        final String read = new FileTextIO().encodeAsUTF8().removeUTF8Bom().read(path);
        ps.setString(bindCount, read);
    } catch (RuntimeException e) {
        throwLoadDataTextFileReadFailureException(tableName, columnName, path, rowNumber, e);
    }
    return true;
}
Also used : DfColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfColumnMeta) FileTextIO(org.dbflute.helper.filesystem.FileTextIO) File(java.io.File)

Example 8 with FileTextIO

use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.

the class DfMigrationFromAntTest method test_FileUtils_to_Path.

// ===================================================================================
// FileUtils
// =========
public void test_FileUtils_to_Path() throws IOException {
    // ## Arrange ##
    String dirPath = getTestCaseBuildDir().getCanonicalPath() + "/fromant";
    File testDir = new File(dirPath);
    if (testDir.exists()) {
        testDir.delete();
    }
    testDir.mkdir();
    File srcFile = new File(dirPath + "/fromant-src.txt");
    File destByAntFile = new File(dirPath + "/fromant-desc-by-ant.txt");
    File destByNioFile = new File(dirPath + "/fromant-desc-by-nio.txt");
    // sea in maihama(as kanji)
    String writtenText = "sea in \u821e\u6d5c";
    FileTextIO textIO = new FileTextIO().encodeAsUTF8();
    textIO.write(new FileOutputStream(srcFile), writtenText);
    assertTrue(srcFile.exists());
    try {
        // ## Act ##
        // AlterCheck uses
        FileUtils.getFileUtils().copyFile(srcFile, destByAntFile);
        Files.copy(srcFile.toPath(), destByNioFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
        // ## Assert ##
        assertTrue(destByAntFile.exists());
        assertTrue(destByNioFile.exists());
        String byAntText = textIO.read(new FileInputStream(destByAntFile));
        String byNioText = textIO.read(new FileInputStream(destByNioFile));
        assertEquals(byAntText, byNioText);
    } finally {
        if (srcFile.exists()) {
            srcFile.delete();
        }
        if (destByAntFile.exists()) {
            destByAntFile.delete();
        }
        if (destByNioFile.exists()) {
            destByNioFile.delete();
        }
    }
}
Also used : FileTextIO(org.dbflute.helper.filesystem.FileTextIO) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 9 with FileTextIO

use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.

the class DfRefreshMan method detectEclipseProjectName.

protected String detectEclipseProjectName() {
    // e.g.
    // PROJECT_ROOT
    // |-dbflute_maihamadb
    // |-mydbflute
    // |-...
    // |-.project
    final File projectFile = new File("../.project");
    if (!projectFile.exists()) {
        return null;
    }
    final Set<String> resultSet = new HashSet<String>();
    try {
        new FileTextIO().encodeAsUTF8().readFilteringLine(new FileInputStream(projectFile), new FileTextLineFilter() {

            boolean _found = false;

            public String filter(String line) {
                if (_found || !line.contains("<name>")) {
                    return null;
                }
                ScopeInfo scopeInfo = Srl.extractScopeFirst(line, "<name>", "</name>");
                if (scopeInfo == null) {
                    // basically no way, just in case
                    return null;
                }
                final String content = scopeInfo.getContent().trim();
                resultSet.add(content);
                _found = true;
                return null;
            }
        });
    } catch (FileNotFoundException ignored) {
        // no way because of already checked, just in case
        return null;
    }
    if (resultSet.isEmpty()) {
        _log.info("*The .project file exists but not found project name: " + projectFile);
        return null;
    }
    return resultSet.iterator().next();
}
Also used : FileTextIO(org.dbflute.helper.filesystem.FileTextIO) FileNotFoundException(java.io.FileNotFoundException) FileTextLineFilter(org.dbflute.helper.filesystem.FileTextLineFilter) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) File(java.io.File) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Example 10 with FileTextIO

use of org.dbflute.helper.filesystem.FileTextIO in project dbflute-core by dbflute.

the class DfUpgradeTask method replaceDBFluteClientReference.

// ===================================================================================
// Replace Reference
// =================
protected void replaceDBFluteClientReference(final String upgradeVersion) {
    final FileTextIO textIO = new FileTextIO().encodeAsUTF8();
    doReplaceProjectBat(upgradeVersion, textIO);
    doReplaceProjectSh(upgradeVersion, textIO);
}
Also used : FileTextIO(org.dbflute.helper.filesystem.FileTextIO)

Aggregations

FileTextIO (org.dbflute.helper.filesystem.FileTextIO)10 File (java.io.File)7 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)3 ScopeInfo (org.dbflute.util.Srl.ScopeInfo)3 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)2 HashSet (java.util.HashSet)1 FileTextLineFilter (org.dbflute.helper.filesystem.FileTextLineFilter)1