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;
}
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));
}
}
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;
}
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();
}
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);
}
}
Aggregations