Search in sources :

Example 36 with DDLInfo

use of com.varsql.core.db.valueobject.ddl.DDLInfo 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 37 with DDLInfo

use of com.varsql.core.db.valueobject.ddl.DDLInfo 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 38 with DDLInfo

use of com.varsql.core.db.valueobject.ddl.DDLInfo 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 39 with DDLInfo

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

the class OracleDDLScript method getIndexs.

@Override
public List<DDLInfo> getIndexs(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    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);
        dataParamInfo.setObjectName(name);
        ddlStr = new StringBuilder();
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP INDEX " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        List srcScriptList = sqlSesseion.selectList("indexScriptSource", dataParamInfo);
        ddlStr.append("CREATE ");
        Map indexMap;
        if (srcScriptList.size() > 0) {
            indexMap = (Map) srcScriptList.get(0);
            if ("UNIQUE".equals(indexMap.get("UNIQUENESS")))
                ddlStr.append(" UNIQUE INDEX ");
            else {
                ddlStr.append(" INDEX ");
            }
            ddlStr.append(indexMap.get("TABLE_OWNER") + ".");
            ddlStr.append(indexMap.get("INDEX_NAME") + " ON ");
            ddlStr.append(indexMap.get("TABLE_OWNER") + ".");
            ddlStr.append(indexMap.get("TABLE_NAME") + "\n ( ");
            for (int i = 0; i < srcScriptList.size(); i++) {
                indexMap = (Map) srcScriptList.get(i);
                if (("NORMAL".equals(indexMap.get("INDEX_TYPE"))) && (indexMap.get("COLUMN_EXPRESSION") == null)) {
                    if (i > 0)
                        ddlStr.append(",");
                    ddlStr.append(indexMap.get("COLUMN_NAME"));
                } else {
                    if (i > 0)
                        ddlStr.append(",");
                    ddlStr.append(indexMap.get("COLUMN_EXPRESSION"));
                }
            }
            ddlStr.append(" ) ").append(BlankConstants.NEW_LINE);
            ;
            if ("YES".equals(indexMap.get("LOGGING")))
                ddlStr.append(" LOGGING ").append(BlankConstants.NEW_LINE);
            else {
                ddlStr.append(" NO LOGGING ").append(BlankConstants.NEW_LINE);
            }
            ddlStr.append(" TABLESPACE " + indexMap.get("TABLESPACE_NAME") + BlankConstants.NEW_LINE);
            ddlStr.append(" PCTFREE " + String.valueOf(indexMap.get("PCT_FREE")) + BlankConstants.NEW_LINE);
            ddlStr.append(" INITRANS " + String.valueOf(indexMap.get("INI_TRANS")) + BlankConstants.NEW_LINE);
            ddlStr.append(" MAXTRANS " + String.valueOf(indexMap.get("MAX_TRANS")) + BlankConstants.NEW_LINE);
            ddlStr.append(" STORAGE ( \n ");
            ddlStr.append(BlankConstants.TAB + " INITIAL " + String.valueOf(indexMap.get("INITIAL_EXTENT")) + BlankConstants.NEW_LINE);
            ddlStr.append(BlankConstants.TAB + " MINEXTENTS " + String.valueOf(indexMap.get("MIN_EXTENTS")) + BlankConstants.NEW_LINE);
            ddlStr.append(BlankConstants.TAB + " MAXEXTENTS " + String.valueOf(indexMap.get("MAX_EXTENTS")) + BlankConstants.NEW_LINE);
            ddlStr.append(BlankConstants.TAB + " PCTINCREASE " + String.valueOf(indexMap.get("PCT_INCREASE")) + BlankConstants.NEW_LINE);
            ddlStr.append(BlankConstants.TAB + " BUFFER_POOL " + String.valueOf(indexMap.get("BUFFER_POOL")) + BlankConstants.NEW_LINE);
            ddlStr.append("\t ) \n ");
        }
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) 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 40 with DDLInfo

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

the class OracleDDLScript method getFunctions.

@Override
public List<DDLInfo> getFunctions(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    logger.debug(" Function DDL Generation info {}", VartechUtils.reflectionToString(dataParamInfo));
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    StringBuilder ddlStr;
    dataParamInfo.setObjectType(ObjectType.FUNCTION.name());
    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);
        }
        ddlStr.append("CREATE OR REPLACE ");
        List srcList = sqlSesseion.selectList("objectScriptSource", dataParamInfo);
        for (int i = 0; i < srcList.size(); i++) {
            ddlStr.append(srcList.get(i));
        }
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

DDLInfo (com.varsql.core.db.valueobject.ddl.DDLInfo)62 ArrayList (java.util.ArrayList)61 SqlSession (org.apache.ibatis.session.SqlSession)60 ParamMap (com.vartech.common.app.beans.ParamMap)32 Map (java.util.Map)29 HashMap (java.util.HashMap)18 List (java.util.List)15 DataTypeImpl (com.varsql.core.db.meta.datatype.DataTypeImpl)4 DataTypeInfo (com.varsql.core.db.valueobject.DataTypeInfo)4 ProgressInfo (com.varsql.core.common.beans.ProgressInfo)1 VarsqlFileType (com.varsql.core.common.code.VarsqlFileType)1 BlankConstants (com.varsql.core.common.constants.BlankConstants)1 VarsqlConstants (com.varsql.core.common.constants.VarsqlConstants)1 SecurityUtil (com.varsql.core.common.util.SecurityUtil)1 SQLWriter (com.varsql.core.data.writer.SQLWriter)1 DBType (com.varsql.core.db.DBType)1 MetaControlBean (com.varsql.core.db.MetaControlBean)1 MetaControlFactory (com.varsql.core.db.MetaControlFactory)1 VarsqlReportConfig (com.varsql.core.db.report.VarsqlReportConfig)1 ObjectType (com.varsql.core.db.servicemenu.ObjectType)1