Search in sources :

Example 1 with TableSpNames

use of com.ctrip.platform.dal.daogen.domain.TableSpNames in project dal by ctripcorp.

the class DatabaseResource method getTableSPNames.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("table_sps")
public Status getTableSPNames(@QueryParam("db_name") String setName) {
    Status status = Status.OK;
    TableSpNames tableSpNames = new TableSpNames();
    List<String> views;
    List<String> tables;
    List<StoredProcedure> sps;
    try {
        DatabaseSetEntry databaseSetEntry = SpringBeanGetter.getDaoOfDatabaseSet().getMasterDatabaseSetEntryByDatabaseSetName(setName);
        String dbName = databaseSetEntry.getConnectionString();
        views = DbUtils.getAllViewNames(dbName);
        tables = DbUtils.getAllTableNames(dbName);
        sps = DbUtils.getAllSpNames(dbName);
        sps = filterSP(tables, sps);
        java.util.Collections.sort(views, new Comparator<String>() {

            @Override
            public int compare(String o1, String o2) {
                return o1.toLowerCase().compareTo(o2.toLowerCase());
            }
        });
        java.util.Collections.sort(tables, new Comparator<String>() {

            @Override
            public int compare(String o1, String o2) {
                return o1.toLowerCase().compareTo(o2.toLowerCase());
            }
        });
        java.util.Collections.sort(sps);
        tableSpNames.setSps(sps);
        tableSpNames.setViews(views);
        tableSpNames.setTables(tables);
        tableSpNames.setDbType(DbUtils.getDbType(dbName));
        status.setInfo(mapper.writeValueAsString(tableSpNames));
    } catch (Exception e1) {
        status = Status.ERROR;
        status.setInfo(e1.getMessage());
        return status;
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) StoredProcedure(com.ctrip.platform.dal.daogen.domain.StoredProcedure) TableSpNames(com.ctrip.platform.dal.daogen.domain.TableSpNames) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SQLException(java.sql.SQLException)

Aggregations

Status (com.ctrip.platform.dal.daogen.domain.Status)1 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)1 TableSpNames (com.ctrip.platform.dal.daogen.domain.TableSpNames)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SQLException (java.sql.SQLException)1