Search in sources :

Example 1 with SqlStatementInfo

use of com.varsql.core.db.valueobject.SqlStatementInfo in project varsql by varsqlinfo.

the class FileImportExportServiceImpl method jsonImport.

private SQLExecuteResult jsonImport(FileInfoEntity fileInfo, String conuid) throws SQLException {
    SqlStatementInfo ssi = new SqlStatementInfo();
    ssi.setConuid(conuid);
    ssi.setExportType(VarsqlFileType.JSON.name());
    ssi.addCustom(FileImportExecutor.IMPORT_FILE_PARAM_NAME, FileServiceUtils.getPath(fileInfo.getFilePath()).toUri());
    SQLExecuteResult ser = new FileImportExecutor().execute(ssi);
    return ser;
}
Also used : SqlStatementInfo(com.varsql.core.db.valueobject.SqlStatementInfo) SQLExecuteResult(com.varsql.core.sql.executor.SQLExecuteResult) FileImportExecutor(com.varsql.core.sql.executor.FileImportExecutor)

Example 2 with SqlStatementInfo

use of com.varsql.core.db.valueobject.SqlStatementInfo in project varsql by varsqlinfo.

the class BaseExecutorTest method testUpdate.

// @Test
// @Ignore
void testUpdate() {
    ConnectionInfo connInfo = getBaseConnection();
    try {
        DatabaseInfo di = getDatabaseInfo(connInfo);
        SqlStatementInfo sqi = new SqlStatementInfo();
        sqi.setSchema("PUBLIC");
        sqi.setConuid(connInfo.getConnid(), TEST_CON_UID, di);
        SQLExecutor baseExecutor = new SqlUpdateExecutor();
        sqi.setSqlParam("{}");
        String insertQuery = getResourceContent("/db/importdata/insertdata.sql");
        sqi.setSql(insertQuery);
        SQLExecuteResult ser = baseExecutor.execute(sqi, new AbstractSQLExecutorHandler() {

            @Override
            public boolean handle(SQLHandlerParameter handleParam) {
                return true;
            }
        });
        System.out.println("testUpdate ser.getTotalCount(): " + ser.getTotalCount());
        System.out.println("testUpdate ser.getResult(): " + ser.getResult());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SqlStatementInfo(com.varsql.core.db.valueobject.SqlStatementInfo) AbstractSQLExecutorHandler(com.varsql.core.sql.executor.handler.AbstractSQLExecutorHandler) DatabaseInfo(com.varsql.core.db.valueobject.DatabaseInfo) SQLHandlerParameter(com.varsql.core.sql.executor.handler.SQLHandlerParameter) ConnectionInfo(com.varsql.core.connection.beans.ConnectionInfo) IOException(java.io.IOException)

Example 3 with SqlStatementInfo

use of com.varsql.core.db.valueobject.SqlStatementInfo in project varsql by varsqlinfo.

the class BaseExecutorTest method testSelect.

@Test
// @Ignore
void testSelect() {
    ConnectionInfo connInfo = getBaseConnection();
    try {
        DatabaseInfo di = getDatabaseInfo(connInfo);
        SqlStatementInfo sqi = new SqlStatementInfo();
        sqi.setSchema("PUBLIC");
        sqi.setConuid(connInfo.getConnid(), TEST_CON_UID, di);
        SQLExecutor baseExecutor = new SelectExecutor();
        sqi.setSqlParam("{}");
        sqi.setSql("select * from test2222");
        SQLWriter writer = new SQLWriter(new FileOutputStream(new File("c:/zzz/exportInsertQuery.sql")), DBType.getDBType(sqi.getDbType()), "test2222");
        AbstractSQLExecutorHandler handler = new AbstractSQLExecutorHandler() {

            private boolean firstFlag = true;

            @Override
            public boolean handle(SQLHandlerParameter handleParam) {
                if (firstFlag) {
                    writer.setColumnInfos(handleParam.getColumnInfoList());
                    firstFlag = false;
                }
                try {
                    writer.addRow(handleParam.getRowObject());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return true;
            }
        };
        SQLExecuteResult ser = baseExecutor.execute(sqi, handler);
        writer.write();
        System.out.println("testUpdate ser.getTotalCount(): " + ser.getTotalCount());
        System.out.println("testSelect ser.getResult(): " + ser.getResult());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SqlStatementInfo(com.varsql.core.db.valueobject.SqlStatementInfo) DatabaseInfo(com.varsql.core.db.valueobject.DatabaseInfo) SQLHandlerParameter(com.varsql.core.sql.executor.handler.SQLHandlerParameter) IOException(java.io.IOException) IOException(java.io.IOException) AbstractSQLExecutorHandler(com.varsql.core.sql.executor.handler.AbstractSQLExecutorHandler) SQLWriter(com.varsql.core.data.writer.SQLWriter) FileOutputStream(java.io.FileOutputStream) ConnectionInfo(com.varsql.core.connection.beans.ConnectionInfo) File(java.io.File) Test(org.junit.jupiter.api.Test) BaseTest(com.varsql.core.test.BaseTest)

Example 4 with SqlStatementInfo

use of com.varsql.core.db.valueobject.SqlStatementInfo in project varsql by varsqlinfo.

the class FileImportExportServiceImpl method sqlImport.

/**
 * @method  : sqlImport
 * @desc : sql import
 * @author   : ytkim
 * @date   : 2021. 5. 23.
 * @param fileInfo
 * @param conuid
 * @return
 * @throws IOException
 * @throws SQLException
 */
private SQLExecuteResult sqlImport(FileInfoEntity fileInfo, String conuid) throws IOException, SQLException {
    SqlStatementInfo ssi = new SqlStatementInfo();
    ssi.setConuid(conuid);
    ssi.setSqlParam("{}");
    String insertQuery = FileUtils.readFileToString(FileServiceUtils.getFileInfoToFile(fileInfo));
    ssi.setSql(insertQuery);
    SQLExecuteResult ser = new SqlUpdateExecutor().execute(ssi, new AbstractSQLExecutorHandler() {

        @Override
        public boolean handle(SQLHandlerParameter handleParam) {
            return true;
        }
    });
    return ser;
}
Also used : SqlStatementInfo(com.varsql.core.db.valueobject.SqlStatementInfo) AbstractSQLExecutorHandler(com.varsql.core.sql.executor.handler.AbstractSQLExecutorHandler) SQLHandlerParameter(com.varsql.core.sql.executor.handler.SQLHandlerParameter) SQLExecuteResult(com.varsql.core.sql.executor.SQLExecuteResult) SqlUpdateExecutor(com.varsql.core.sql.executor.SqlUpdateExecutor)

Example 5 with SqlStatementInfo

use of com.varsql.core.db.valueobject.SqlStatementInfo in project varsql by varsqlinfo.

the class FileImportExportServiceImpl method xmlImport.

private SQLExecuteResult xmlImport(FileInfoEntity fileInfo, String conuid) throws SQLException {
    SqlStatementInfo ssi = new SqlStatementInfo();
    ssi.setConuid(conuid);
    ssi.setExportType(VarsqlFileType.XML.name());
    ssi.addCustom(FileImportExecutor.IMPORT_FILE_PARAM_NAME, FileServiceUtils.getPath(fileInfo.getFilePath()).toUri());
    SQLExecuteResult ser = new FileImportExecutor().execute(ssi);
    return ser;
}
Also used : SqlStatementInfo(com.varsql.core.db.valueobject.SqlStatementInfo) SQLExecuteResult(com.varsql.core.sql.executor.SQLExecuteResult) FileImportExecutor(com.varsql.core.sql.executor.FileImportExecutor)

Aggregations

SqlStatementInfo (com.varsql.core.db.valueobject.SqlStatementInfo)5 SQLExecuteResult (com.varsql.core.sql.executor.SQLExecuteResult)3 AbstractSQLExecutorHandler (com.varsql.core.sql.executor.handler.AbstractSQLExecutorHandler)3 SQLHandlerParameter (com.varsql.core.sql.executor.handler.SQLHandlerParameter)3 ConnectionInfo (com.varsql.core.connection.beans.ConnectionInfo)2 DatabaseInfo (com.varsql.core.db.valueobject.DatabaseInfo)2 FileImportExecutor (com.varsql.core.sql.executor.FileImportExecutor)2 IOException (java.io.IOException)2 SQLWriter (com.varsql.core.data.writer.SQLWriter)1 SqlUpdateExecutor (com.varsql.core.sql.executor.SqlUpdateExecutor)1 BaseTest (com.varsql.core.test.BaseTest)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Test (org.junit.jupiter.api.Test)1