Search in sources :

Example 1 with DataTypeImpl

use of com.varsql.core.db.meta.datatype.DataTypeImpl in project varsql by varsqlinfo.

the class MssqlDDLScript 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("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((String) 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 2 with DataTypeImpl

use of com.varsql.core.db.meta.datatype.DataTypeImpl in project varsql by varsqlinfo.

the class DBMetaDataUtil method tableAndColumnsInfo.

protected List<TableInfo> tableAndColumnsInfo(DatabaseParamInfo dataParamInfo, Connection conn, MetaControlBean dbInstanceFactory, String type, List<TableInfo> tableList) throws SQLException {
    List<TableInfo> reLst = new ArrayList<TableInfo>();
    ResultSet colRs = null;
    String schema = dataParamInfo.getSchema();
    try {
        DatabaseMetaData dbmd = conn.getMetaData();
        DataTypeImpl dataTypeImpl = dbInstanceFactory.getDataTypeImpl();
        DBMetaHandlerImpl dbMetaHandlerImpl = dbInstanceFactory.getDBMetaHandlerImpl();
        List<ColumnInfo> columnList = null;
        String tableNm = "";
        Map<String, HashSet<String>> pkMap = new HashMap<String, HashSet<String>>();
        Map<String, TableInfo> tableInfoMap = new HashMap<String, TableInfo>();
        for (TableInfo tableInfo : tableList) {
            columnList = new ArrayList<ColumnInfo>();
            tableNm = tableInfo.getName();
            colRs = dbmd.getPrimaryKeys(null, schema, tableNm);
            HashSet<String> keyColumn = new HashSet<String>();
            while (colRs.next()) {
                keyColumn.add(colRs.getString(MetaColumnConstants.COLUMN_NAME));
            }
            colRs.close();
            pkMap.put(tableNm, keyColumn);
            tableInfoMap.put(tableNm, tableInfo);
            tableInfo.setColList(columnList);
            reLst.add(tableInfo);
        }
        colRs = dbmd.getColumns(null, schema, null, null);
        while (colRs.next()) {
            tableNm = colRs.getString(MetaColumnConstants.TABLE_NAME);
            if (tableInfoMap.containsKey(tableNm)) {
                tableInfoMap.get(tableNm).getColList().add(dbMetaHandlerImpl.getColumnInfo(colRs, dataTypeImpl, pkMap.get(tableNm)));
            }
        }
        colRs.close();
    } finally {
        JdbcUtils.close(colRs);
    }
    return reLst;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DBMetaHandlerImpl(com.varsql.core.db.meta.handler.DBMetaHandlerImpl) ObjectColumnInfo(com.varsql.core.db.valueobject.ObjectColumnInfo) ColumnInfo(com.varsql.core.db.valueobject.ColumnInfo) DatabaseMetaData(java.sql.DatabaseMetaData) DataTypeImpl(com.varsql.core.db.meta.datatype.DataTypeImpl) ResultSet(java.sql.ResultSet) TableInfo(com.varsql.core.db.valueobject.TableInfo) HashSet(java.util.HashSet)

Example 3 with DataTypeImpl

use of com.varsql.core.db.meta.datatype.DataTypeImpl 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 4 with DataTypeImpl

use of com.varsql.core.db.meta.datatype.DataTypeImpl in project varsql by varsqlinfo.

the class PostgresqlDDLScript 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");
        dataParamInfo.setObjectName(name);
        DataTypeImpl dataTypeImpl = dbInstanceFactory.getDataTypeImpl();
        ParamMap source;
        for (int i = 0; i < srcList.size(); i++) {
            source = srcList.get(i);
            ddlStr.append(BlankConstants.TAB);
            if (i > 0) {
                ddlStr.append(",");
            }
            ddlStr.append(source.get(MetaColumnConstants.COLUMN_NAME)).append(" ");
            ddlStr.append(source.get(MetaColumnConstants.DATA_TYPE)).append(" ");
            ddlStr.append(source.getString(MetaColumnConstants.COLUMN_DEF)).append(" ");
            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);
            ddlStr.append(BlankConstants.TAB).append(",CONSTRAINT ").append(pkMap.get("CONSTRAINT_NAME")).append(" ").append(pkMap.get("CONSTRAINDDEF"));
        }
        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 : ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) DataTypeImpl(com.varsql.core.db.meta.datatype.DataTypeImpl) 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 5 with DataTypeImpl

use of com.varsql.core.db.meta.datatype.DataTypeImpl in project varsql by varsqlinfo.

the class TiberoDDLScript 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("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)

Aggregations

DataTypeImpl (com.varsql.core.db.meta.datatype.DataTypeImpl)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 DDLInfo (com.varsql.core.db.valueobject.ddl.DDLInfo)4 ParamMap (com.vartech.common.app.beans.ParamMap)4 List (java.util.List)4 Map (java.util.Map)4 SqlSession (org.apache.ibatis.session.SqlSession)4 DataTypeInfo (com.varsql.core.db.valueobject.DataTypeInfo)3 DBMetaHandlerImpl (com.varsql.core.db.meta.handler.DBMetaHandlerImpl)1 ColumnInfo (com.varsql.core.db.valueobject.ColumnInfo)1 ObjectColumnInfo (com.varsql.core.db.valueobject.ObjectColumnInfo)1 TableInfo (com.varsql.core.db.valueobject.TableInfo)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 HashSet (java.util.HashSet)1