Search in sources :

Example 1 with IndexInfo

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

the class IndexInfoHandler method handleResult.

@Override
public void handleResult(ResultContext<? extends ParamMap> paramResultContext) {
    ParamMap rowData = paramResultContext.getResultObject();
    String indexName = rowData.getString(MetaColumnConstants.INDEX_NAME);
    if (!indexName.equals(beforeTableName)) {
        currentIndexInfo = new IndexInfo();
        currentIndexInfo.setName(indexName);
        currentIndexInfo.setBufferPool(rowData.getString(MetaColumnConstants.BUFFER_POOL));
        currentIndexInfo.setStatus(rowData.getString(MetaColumnConstants.STATUS));
        currentIndexInfo.setTableSpace(rowData.getString(MetaColumnConstants.TABLE_SPACE));
        currentIndexInfo.setTblName(rowData.getString(MetaColumnConstants.TABLE_NAME));
        currentIndexInfo.setType(rowData.getString(MetaColumnConstants.INDEX_TYPE));
        currentIndexInfo.setColList(new ArrayList<ObjectColumnInfo>());
        indexInfoList.add(currentIndexInfo);
    }
    ObjectColumnInfo column = new ObjectColumnInfo();
    column.setName(rowData.getString(MetaColumnConstants.COLUMN_NAME));
    column.setNo(rowData.getInt(MetaColumnConstants.ORDINAL_POSITION));
    column.setAscOrdesc(rowData.getString(MetaColumnConstants.ASC_OR_DESC));
    currentIndexInfo.addColInfo(column);
    beforeTableName = indexName;
}
Also used : ParamMap(com.vartech.common.app.beans.ParamMap) ObjectColumnInfo(com.varsql.core.db.valueobject.ObjectColumnInfo) IndexInfo(com.varsql.core.db.valueobject.IndexInfo)

Example 2 with IndexInfo

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

the class DBMetaImpl method getIndexMetadata.

@Override
public List<IndexInfo> getIndexMetadata(DatabaseParamInfo dataParamInfo, String... indexNames) throws Exception {
    SqlSession session = SQLManager.getInstance().openSession(dataParamInfo.getVconnid());
    try {
        Connection conn = null;
        ResultSet rs = null;
        List<IndexInfo> indexInfoList = new ArrayList<IndexInfo>();
        String schema = dataParamInfo.getSchema();
        try {
            conn = session.getConnection();
            DatabaseMetaData dbmd = conn.getMetaData();
            List<TableInfo> tableList;
            if (indexNames != null && indexNames.length > 0) {
                tableList = new ArrayList<TableInfo>();
                TableInfo tableInfo = null;
                for (String nm : indexNames) {
                    tableInfo = new TableInfo();
                    tableInfo.setName(nm);
                    tableList.add(tableInfo);
                }
            } else {
                tableList = dBMetaDataUtil.tableInfo(dataParamInfo, conn, "TABLE");
            }
            ObjectColumnInfo oci = null;
            List<ObjectColumnInfo> columnList = new ArrayList<ObjectColumnInfo>();
            String tblName;
            for (int i = 0, len = tableList.size(); i < len; i++) {
                tblName = tableList.get(i).getName();
                rs = dbmd.getIndexInfo(null, schema, tblName, false, false);
                IndexInfo indexInfo;
                String indexName = null;
                String beforeName = "";
                while (rs.next()) {
                    indexName = rs.getString(MetaColumnConstants.INDEX_NAME);
                    if (indexName != null && !"".equals(indexName)) {
                        if (!beforeName.equals(indexName)) {
                            columnList = new ArrayList<ObjectColumnInfo>();
                            indexInfo = new IndexInfo();
                            indexInfo.setName(rs.getString(MetaColumnConstants.INDEX_NAME));
                            indexInfo.setTblName(tblName);
                            indexInfo.setType(rs.getString(MetaColumnConstants.INDEX_TYPE));
                            indexInfo.setColList(columnList);
                            indexInfoList.add(indexInfo);
                        }
                        beforeName = indexName;
                        oci = new ObjectColumnInfo();
                        oci.setName(rs.getString(MetaColumnConstants.COLUMN_NAME));
                        oci.setNo(rs.getInt(MetaColumnConstants.ORDINAL_POSITION));
                        oci.setAscOrdesc(rs.getString(MetaColumnConstants.ASC_OR_DESC));
                        columnList.add(oci);
                    }
                }
            }
        } catch (SQLException e) {
            throw e;
        }
        return indexInfoList;
    } finally {
        sessionClose(dataParamInfo.getVconnid(), session);
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ObjectColumnInfo(com.varsql.core.db.valueobject.ObjectColumnInfo) IndexInfo(com.varsql.core.db.valueobject.IndexInfo) DatabaseMetaData(java.sql.DatabaseMetaData) ResultSet(java.sql.ResultSet) TableInfo(com.varsql.core.db.valueobject.TableInfo)

Aggregations

IndexInfo (com.varsql.core.db.valueobject.IndexInfo)2 ObjectColumnInfo (com.varsql.core.db.valueobject.ObjectColumnInfo)2 TableInfo (com.varsql.core.db.valueobject.TableInfo)1 ParamMap (com.vartech.common.app.beans.ParamMap)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 SqlSession (org.apache.ibatis.session.SqlSession)1