Search in sources :

Example 1 with TableMetaData

use of org.activiti.engine.management.TableMetaData in project Activiti by Activiti.

the class TableDataManager method getTableMetaData.

public TableMetaData getTableMetaData(String tableName) {
    TableMetaData result = new TableMetaData();
    try {
        result.setTableName(tableName);
        DatabaseMetaData metaData = getDbSqlSession().getSqlSession().getConnection().getMetaData();
        if ("postgres".equals(getDbSqlSession().getDbSqlSessionFactory().getDatabaseType())) {
            tableName = tableName.toLowerCase();
        }
        String catalog = null;
        if (getProcessEngineConfiguration().getDatabaseCatalog() != null && getProcessEngineConfiguration().getDatabaseCatalog().length() > 0) {
            catalog = getProcessEngineConfiguration().getDatabaseCatalog();
        }
        String schema = null;
        if (getProcessEngineConfiguration().getDatabaseSchema() != null && getProcessEngineConfiguration().getDatabaseSchema().length() > 0) {
            if ("oracle".equals(getDbSqlSession().getDbSqlSessionFactory().getDatabaseType())) {
                schema = getProcessEngineConfiguration().getDatabaseSchema().toUpperCase();
            } else {
                schema = getProcessEngineConfiguration().getDatabaseSchema();
            }
        }
        ResultSet resultSet = metaData.getColumns(catalog, schema, tableName, null);
        while (resultSet.next()) {
            boolean wrongSchema = false;
            if (schema != null && schema.length() > 0) {
                for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) {
                    String columnName = resultSet.getMetaData().getColumnName(i + 1);
                    if ("TABLE_SCHEM".equalsIgnoreCase(columnName) || "TABLE_SCHEMA".equalsIgnoreCase(columnName)) {
                        if (schema.equalsIgnoreCase(resultSet.getString(resultSet.getMetaData().getColumnName(i + 1))) == false) {
                            wrongSchema = true;
                        }
                        break;
                    }
                }
            }
            if (wrongSchema == false) {
                String name = resultSet.getString("COLUMN_NAME").toUpperCase();
                String type = resultSet.getString("TYPE_NAME").toUpperCase();
                result.addColumnMetaData(name, type);
            }
        }
    } catch (SQLException e) {
        throw new ActivitiException("Could not retrieve database metadata: " + e.getMessage());
    }
    if (result.getColumnNames().isEmpty()) {
        // According to API, when a table doesn't exist, null should be returned
        result = null;
    }
    return result;
}
Also used : TableMetaData(org.activiti.engine.management.TableMetaData) ActivitiException(org.activiti.engine.ActivitiException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 2 with TableMetaData

use of org.activiti.engine.management.TableMetaData in project Activiti by Activiti.

the class TableColumnsResourceTest method testGetTableColumns.

/**
   * Test getting a single table's columns. 
   * GET management/tables/{tableName}/columns
   */
public void testGetTableColumns() throws Exception {
    String tableName = managementService.getTableCount().keySet().iterator().next();
    TableMetaData metaData = managementService.getTableMetaData(tableName);
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE_COLUMNS, tableName)), HttpStatus.SC_OK);
    // Check table
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(tableName, responseNode.get("tableName").textValue());
    ArrayNode names = (ArrayNode) responseNode.get("columnNames");
    ArrayNode types = (ArrayNode) responseNode.get("columnTypes");
    assertNotNull(names);
    assertNotNull(types);
    assertEquals(metaData.getColumnNames().size(), names.size());
    assertEquals(metaData.getColumnTypes().size(), types.size());
    for (int i = 0; i < names.size(); i++) {
        assertEquals(names.get(i).textValue(), metaData.getColumnNames().get(i));
        assertEquals(types.get(i).textValue(), metaData.getColumnTypes().get(i));
    }
}
Also used : TableMetaData(org.activiti.engine.management.TableMetaData) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 3 with TableMetaData

use of org.activiti.engine.management.TableMetaData in project Activiti by Activiti.

the class TableDataManagerImpl method getTableMetaData.

@Override
public TableMetaData getTableMetaData(String tableName) {
    TableMetaData result = new TableMetaData();
    try {
        result.setTableName(tableName);
        DatabaseMetaData metaData = getDbSqlSession().getSqlSession().getConnection().getMetaData();
        if ("postgres".equals(getDbSqlSession().getDbSqlSessionFactory().getDatabaseType())) {
            tableName = tableName.toLowerCase();
        }
        String catalog = null;
        if (getProcessEngineConfiguration().getDatabaseCatalog() != null && getProcessEngineConfiguration().getDatabaseCatalog().length() > 0) {
            catalog = getProcessEngineConfiguration().getDatabaseCatalog();
        }
        String schema = null;
        if (getProcessEngineConfiguration().getDatabaseSchema() != null && getProcessEngineConfiguration().getDatabaseSchema().length() > 0) {
            if ("oracle".equals(getDbSqlSession().getDbSqlSessionFactory().getDatabaseType())) {
                schema = getProcessEngineConfiguration().getDatabaseSchema().toUpperCase();
            } else {
                schema = getProcessEngineConfiguration().getDatabaseSchema();
            }
        }
        ResultSet resultSet = metaData.getColumns(catalog, schema, tableName, null);
        while (resultSet.next()) {
            boolean wrongSchema = false;
            if (schema != null && schema.length() > 0) {
                for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) {
                    String columnName = resultSet.getMetaData().getColumnName(i + 1);
                    if ("TABLE_SCHEM".equalsIgnoreCase(columnName) || "TABLE_SCHEMA".equalsIgnoreCase(columnName)) {
                        if (!schema.equalsIgnoreCase(resultSet.getString(resultSet.getMetaData().getColumnName(i + 1)))) {
                            wrongSchema = true;
                        }
                        break;
                    }
                }
            }
            if (!wrongSchema) {
                String name = resultSet.getString("COLUMN_NAME").toUpperCase();
                String type = resultSet.getString("TYPE_NAME").toUpperCase();
                result.addColumnMetaData(name, type);
            }
        }
    } catch (SQLException e) {
        throw new ActivitiException("Could not retrieve database metadata: " + e.getMessage());
    }
    if (result.getColumnNames().isEmpty()) {
        // According to API, when a table doesn't exist, null should be returned
        result = null;
    }
    return result;
}
Also used : TableMetaData(org.activiti.engine.management.TableMetaData) ActivitiException(org.activiti.engine.ActivitiException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 4 with TableMetaData

use of org.activiti.engine.management.TableMetaData in project Activiti by Activiti.

the class ManagementServiceTest method testGetMetaDataForUnexistingTable.

public void testGetMetaDataForUnexistingTable() {
    TableMetaData metaData = managementService.getTableMetaData("unexistingtable");
    assertThat(metaData).isNull();
}
Also used : TableMetaData(org.activiti.engine.management.TableMetaData)

Example 5 with TableMetaData

use of org.activiti.engine.management.TableMetaData in project Activiti by Activiti.

the class DatabaseDetailPanel method addTableData.

protected void addTableData() {
    LazyLoadingQuery lazyLoadingQuery = new TableDataQuery(tableName, managementService);
    LazyLoadingContainer lazyLoadingContainer = new LazyLoadingContainer(lazyLoadingQuery, 30);
    if (lazyLoadingContainer.size() > 0) {
        Table data = new Table();
        data.setContainerDataSource(lazyLoadingContainer);
        data.setEditable(false);
        data.setSelectable(true);
        data.setColumnReorderingAllowed(true);
        if (lazyLoadingQuery.size() < 10) {
            data.setPageLength(0);
        } else {
            data.setPageLength(10);
        }
        addDetailComponent(data);
        data.setWidth(100, UNITS_PERCENTAGE);
        data.setHeight(100, UNITS_PERCENTAGE);
        data.addStyleName(ExplorerLayout.STYLE_DATABASE_TABLE);
        setDetailExpandRatio(data, 1.0f);
        // Create column headers
        TableMetaData metaData = managementService.getTableMetaData(tableName);
        for (String columnName : metaData.getColumnNames()) {
            data.addContainerProperty(columnName, String.class, null);
        }
    } else {
        Label noDataLabel = new Label(i18nManager.getMessage(Messages.DATABASE_NO_ROWS));
        noDataLabel.addStyleName(Reindeer.LABEL_SMALL);
        addDetailComponent(noDataLabel);
        setDetailExpandRatio(noDataLabel, 1.0f);
    }
}
Also used : TableMetaData(org.activiti.engine.management.TableMetaData) Table(com.vaadin.ui.Table) Label(com.vaadin.ui.Label) LazyLoadingContainer(org.activiti.explorer.data.LazyLoadingContainer) LazyLoadingQuery(org.activiti.explorer.data.LazyLoadingQuery)

Aggregations

TableMetaData (org.activiti.engine.management.TableMetaData)6 DatabaseMetaData (java.sql.DatabaseMetaData)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ActivitiException (org.activiti.engine.ActivitiException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Label (com.vaadin.ui.Label)1 Table (com.vaadin.ui.Table)1 LazyLoadingContainer (org.activiti.explorer.data.LazyLoadingContainer)1 LazyLoadingQuery (org.activiti.explorer.data.LazyLoadingQuery)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1