Search in sources :

Example 1 with LibraryFile

use of beans.dbaccess.LibraryFile in project MSEC by Tencent.

the class DelLibraryFile method deleteAll.

public static String deleteAll(String flsn, String slsn) {
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        return "DB connect failed.";
    }
    try {
        String sql = "select file_name from t_library_file where  first_level_service_name=? and second_level_service_name=?";
        List<Object> params = new ArrayList<Object>();
        params.add(flsn);
        params.add(slsn);
        ArrayList<LibraryFile> result = util.findMoreRefResult(sql, params, LibraryFile.class);
        for (int i = 0; i < result.size(); i++) {
            String file_name = result.get(i).getFile_name();
            sql = "delete from t_library_file where file_name=? and first_level_service_name=? and second_level_service_name=?";
            params = new ArrayList<Object>();
            params.add(file_name);
            params.add(flsn);
            params.add(slsn);
            //删除数据库记录
            int delNum = util.updateByPreparedStatement(sql, params);
            String filename = LibraryFile.getLibraryFileName(flsn, slsn, file_name);
            RemoveFile(filename);
        }
        return "success";
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    } finally {
        util.releaseConn();
    }
}
Also used : DBUtil(ngse.org.DBUtil) ArrayList(java.util.ArrayList) LibraryFile(beans.dbaccess.LibraryFile) SQLException(java.sql.SQLException)

Example 2 with LibraryFile

use of beans.dbaccess.LibraryFile in project MSEC by Tencent.

the class PackDevFile method getLibraryFilesFromDB.

private ArrayList<LibraryFile> getLibraryFilesFromDB(String flsn, String slsn) {
    Logger logger = Logger.getLogger(PackDevFile.class);
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        return null;
    }
    try {
        String sql = "select file_name from t_library_file where first_level_service_name=? and second_level_service_name=?";
        List<Object> params = new ArrayList<Object>();
        params.add(flsn);
        params.add(slsn);
        ArrayList<LibraryFile> ret = util.findMoreRefResult(sql, params, LibraryFile.class);
        logger.info("get library files from db, file number:" + ret.size());
        return ret;
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.toString());
        return null;
    } finally {
        util.releaseConn();
    }
}
Also used : ArrayList(java.util.ArrayList) LibraryFile(beans.dbaccess.LibraryFile) Logger(org.apache.log4j.Logger)

Example 3 with LibraryFile

use of beans.dbaccess.LibraryFile in project MSEC by Tencent.

the class PackDevFile method copyLibraryFile.

private void copyLibraryFile(String baseDir) throws Exception {
    Logger logger = Logger.getLogger(PackDevFile.class);
    ArrayList<LibraryFile> libraryFiles = getLibraryFilesFromDB(pack.getFirst_level_service_name(), pack.getSecond_level_service_name());
    for (int i = 0; i < libraryFiles.size(); i++) {
        String destFile = baseDir + "/lib/" + libraryFiles.get(i).getFile_name();
        String srcFile = LibraryFile.getLibraryFileName(pack.getFirst_level_service_name(), pack.getSecond_level_service_name(), libraryFiles.get(i).getFile_name());
        if (copyFile(new File(srcFile), new File(destFile))) {
            logger.info("copy file successfully." + srcFile + " " + destFile);
            continue;
        } else {
            logger.error("failed to copy file:" + srcFile + " " + destFile);
            throw new Exception("failed to copy file:" + srcFile + " " + destFile);
        }
    }
}
Also used : LibraryFile(beans.dbaccess.LibraryFile) Logger(org.apache.log4j.Logger) LibraryFile(beans.dbaccess.LibraryFile)

Example 4 with LibraryFile

use of beans.dbaccess.LibraryFile in project MSEC by Tencent.

the class PackReleaseFile method getLibraryFilesFromDB.

private ArrayList<LibraryFile> getLibraryFilesFromDB(String flsn, String slsn) {
    Logger logger = Logger.getLogger(PackReleaseFile.class);
    DBUtil util = new DBUtil();
    if (util.getConnection() == null) {
        return null;
    }
    try {
        String sql = "select file_name from t_library_file where first_level_service_name=? and second_level_service_name=?";
        List<Object> params = new ArrayList<Object>();
        params.add(flsn);
        params.add(slsn);
        ArrayList<LibraryFile> ret = util.findMoreRefResult(sql, params, LibraryFile.class);
        logger.info("get library file list:" + ret.size());
        return ret;
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage());
        return null;
    } finally {
        util.releaseConn();
    }
}
Also used : ArrayList(java.util.ArrayList) LibraryFile(beans.dbaccess.LibraryFile) Logger(org.apache.log4j.Logger)

Example 5 with LibraryFile

use of beans.dbaccess.LibraryFile in project MSEC by Tencent.

the class PackReleaseFile method copyLibraryFile.

private void copyLibraryFile(String baseDir) throws Exception {
    Logger logger = Logger.getLogger(PackReleaseFile.class);
    ArrayList<LibraryFile> libraryFiles = getLibraryFilesFromDB(plan.getFirst_level_service_name(), plan.getSecond_level_service_name());
    if (libraryFiles == null) {
        throw new Exception("getLibraryFilesFromDB() failed");
    }
    for (int i = 0; i < libraryFiles.size(); i++) {
        String destFile = baseDir + "/bin/lib/" + libraryFiles.get(i).getFile_name();
        String srcFile = LibraryFile.getLibraryFileName(plan.getFirst_level_service_name(), plan.getSecond_level_service_name(), libraryFiles.get(i).getFile_name());
        if (!copyFile(new File(srcFile), new File(destFile))) {
            throw new Exception("failed to copy file:" + srcFile + " " + destFile);
        }
    }
}
Also used : LibraryFile(beans.dbaccess.LibraryFile) Logger(org.apache.log4j.Logger) LibraryFile(beans.dbaccess.LibraryFile)

Aggregations

LibraryFile (beans.dbaccess.LibraryFile)5 Logger (org.apache.log4j.Logger)4 ArrayList (java.util.ArrayList)3 SQLException (java.sql.SQLException)1 DBUtil (ngse.org.DBUtil)1