Search in sources :

Example 16 with ParamMap

use of com.vartech.common.app.beans.ParamMap in project varsql by varsqlinfo.

the class MysqlDDLScript method getFunctions.

@Override
public List<DDLInfo> getFunctions(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    logger.debug(" Function DDL Generation...");
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    StringBuilder ddlStr;
    for (String name : objNmArr) {
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        ddlStr = new StringBuilder();
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP FUNCTION " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        ParamMap source = sqlSesseion.selectOne("functionScript", dataParamInfo);
        ddlStr.append(source.getString("Create Function"));
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo)

Example 17 with ParamMap

use of com.vartech.common.app.beans.ParamMap in project varsql by varsqlinfo.

the class MysqlDDLScript method getTables.

@Override
public List<DDLInfo> getTables(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    SqlSession client = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    StringBuilder ddlStr;
    for (String name : objNmArr) {
        ddlStr = new StringBuilder();
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP TABLE " + name + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        ParamMap source = client.selectOne("tableScript", dataParamInfo);
        ddlStr.append(source.getString("Create Table"));
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo)

Example 18 with ParamMap

use of com.vartech.common.app.beans.ParamMap in project varsql by varsqlinfo.

the class OracleDDLScript method getTables.

@Override
public List<DDLInfo> getTables(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    SqlSession client = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    StringBuilder ddlStr;
    for (String name : objNmArr) {
        ddlStr = new StringBuilder();
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP TABLE " + name + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        List<ParamMap> srcList = client.selectList("tableScript", dataParamInfo);
        ddlStr.append("CREATE TABLE " + name + "(\n");
        String dataType = "";
        dataParamInfo.setObjectName(name);
        DataTypeImpl dataTypeImpl = dbInstanceFactory.getDataTypeImpl();
        ParamMap source;
        for (int i = 0; i < srcList.size(); i++) {
            source = srcList.get(i);
            dataType = String.valueOf(source.get("DATA_TYPE"));
            DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
            ddlStr.append("\t");
            if (i > 0) {
                ddlStr.append(",");
            }
            ddlStr.append(source.get(MetaColumnConstants.COLUMN_NAME)).append(" ");
            ddlStr.append(DbMetaUtils.getTypeName(dataTypeInfo, null, dataTypeInfo.getDataTypeName(), source.getString(MetaColumnConstants.COLUMN_SIZE), source.getString(MetaColumnConstants.DECIMAL_DIGITS)));
            ddlStr.append(getDefaultValue(source.getString("DATA_DEFAULT"), dataTypeInfo, true));
            ddlStr.append(getNotNullValue(source.getString(MetaColumnConstants.NULLABLE)));
            ddlStr.append(BlankConstants.NEW_LINE);
        }
        List srcPkList = client.selectList("tableScriptPk", dataParamInfo);
        Map pkMap;
        for (int i = 0; i < srcPkList.size(); i++) {
            pkMap = (HashMap) srcPkList.get(i);
            if (i == 0)
                ddlStr.append(BlankConstants.TAB).append(",CONSTRAINT ").append(pkMap.get("CONSTRAINT_NAME")).append(" PRIMARY KEY ( ").append(pkMap.get("COLUMN_NAME"));
            else {
                ddlStr.append(", " + pkMap.get("COLUMN_NAME"));
            }
            if (i == srcPkList.size() - 1) {
                ddlStr.append(")").append(BlankConstants.NEW_LINE);
            }
        }
        ddlStr.append(");").append(BlankConstants.NEW_LINE_TWO);
        List srcCommentList = client.selectList("tableScriptComments", dataParamInfo);
        for (int i = 0; i < srcCommentList.size(); i++) {
            ddlStr.append(srcCommentList.get(i)).append(BlankConstants.NEW_LINE);
        }
        if (srcCommentList.size() > 0) {
            ddlStr.append(BlankConstants.NEW_LINE);
        }
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(ddlStr.toString(), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : DataTypeInfo(com.varsql.core.db.valueobject.DataTypeInfo) ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DataTypeImpl(com.varsql.core.db.meta.datatype.DataTypeImpl) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) ParamMap(com.vartech.common.app.beans.ParamMap) Map(java.util.Map)

Example 19 with ParamMap

use of com.vartech.common.app.beans.ParamMap in project varsql by varsqlinfo.

the class CubridDDLScript method getViews.

@Override
public List<DDLInfo> getViews(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    StringBuilder ddlStr;
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    for (String name : objNmArr) {
        ddlStr = new StringBuilder();
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP ViEW " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        ParamMap source = sqlSesseion.selectOne("viewScript", dataParamInfo);
        ddlStr.append("CREATE OR REPLACE VIEW ").append(name).append(" AS ").append(BlankConstants.NEW_LINE_TWO);
        ddlStr.append(source.getString("Create View"));
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo)

Example 20 with ParamMap

use of com.vartech.common.app.beans.ParamMap in project varsql by varsqlinfo.

the class PostgresqlDDLScript method getViews.

@Override
public List<DDLInfo> getViews(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    StringBuilder ddlStr;
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    for (String name : objNmArr) {
        ddlStr = new StringBuilder();
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP ViEW " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        ParamMap source = sqlSesseion.selectOne("viewScript", dataParamInfo);
        ddlStr.append("CREATE OR REPLACE VIEW ").append(name).append(" AS ").append(BlankConstants.NEW_LINE_TWO);
        ddlStr.append(source.getString("VIEW_SOURCE"));
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo)

Aggregations

ParamMap (com.vartech.common.app.beans.ParamMap)27 ArrayList (java.util.ArrayList)21 DDLInfo (com.varsql.core.db.valueobject.ddl.DDLInfo)17 SqlSession (org.apache.ibatis.session.SqlSession)17 List (java.util.List)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DataTypeImpl (com.varsql.core.db.meta.datatype.DataTypeImpl)4 DataTypeInfo (com.varsql.core.db.valueobject.DataTypeInfo)4 PrintWriter (java.io.PrintWriter)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 SecurityUtil (com.varsql.core.common.util.SecurityUtil)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 AuthorityType (com.varsql.core.auth.AuthorityType)1 VarsqlAppCode (com.varsql.core.common.code.VarsqlAppCode)1 VarsqlFileType (com.varsql.core.common.code.VarsqlFileType)1 SqlDataConstants (com.varsql.core.common.constants.SqlDataConstants)1