use of com.cubrid.cubridmanager.core.cubrid.table.model.DBAttributeStatistic in project cubrid-manager by CUBRID.
the class GetPartitionedClassListTask method getColumnStatistics.
/**
* Returning column statistic informations.
*
* @param tableName String the given table name
* @return List<DBAttributeStatistic>
*/
public List<DBAttributeStatistic> getColumnStatistics(String tableName) {
List<DBAttributeStatistic> list = null;
try {
if (errorMsg != null && errorMsg.trim().length() > 0) {
return null;
}
if (connection == null || connection.isClosed()) {
errorMsg = Messages.error_getConnection;
return null;
}
list = new ArrayList<DBAttributeStatistic>();
int cnt = 0;
StringBuilder qry = new StringBuilder();
qry.append("SELECT ");
String sql = "SELECT attr_name, data_type FROM db_attribute WHERE class_name = '" + tableName.trim().toLowerCase() + "'";
connection.setAutoCommit(true);
stmt = connection.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
String attrName = rs.getString("attr_name");
String dataType = rs.getString("data_type");
qry.append("'").append(attrName).append("',");
qry.append("'").append(dataType).append("',");
qry.append("MIN(").append(attrName).append("), ");
qry.append("MAX(").append(attrName).append("), ");
qry.append("COUNT(DISTINCT ").append(attrName).append("), ");
cnt += 5;
}
qry.append("NULL FROM ").append(tableName);
QueryUtil.freeQuery(stmt, rs);
stmt = connection.createStatement();
rs = stmt.executeQuery(qry.toString());
if (rs.next()) {
for (int i = 1; i < cnt; i += 5) {
DBAttributeStatistic attr = new DBAttributeStatistic();
attr.setName(rs.getString(i));
attr.setType(rs.getString(i + 1));
attr.setMinValue(rs.getString(i + 2));
attr.setMaxValue(rs.getString(i + 3));
attr.setValueDistinctCount(rs.getInt(i + 4));
list.add(attr);
}
}
} catch (SQLException e) {
errorMsg = e.getMessage();
} finally {
finish();
}
return list;
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.DBAttributeStatistic in project cubrid-manager by CUBRID.
the class PartitionTypePage method createAttrTable.
/**
* Create attribute table information
*
* @param parent Composite
*/
private void createAttrTable(Composite parent) {
useColumnButton = new Button(parent, SWT.RADIO | SWT.LEFT);
useColumnButton.setText(Messages.btnUseColumn);
useColumnButton.setLayoutData(CommonUITool.createGridData(2, 1, -1, -1));
useColumnButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (useColumnButton.getSelection()) {
useExprButton.setSelection(false);
partitionExprText.setText("");
partitionExprText.setEnabled(false);
setErrorMessage(Messages.errNoSelectColumn);
setPageComplete(false);
attributeTable.setEnabled(true);
}
}
});
List<DBAttributeStatistic> dbAttrStatList = null;
if (!isNewTable) {
GetPartitionedClassListTask task = new GetPartitionedClassListTask(dbInfo);
dbAttrStatList = task.getColumnStatistics(schemaInfo.getClassname());
}
attrList.addAll(schemaInfo.getAttributes());
for (int i = 0; dbAttrStatList != null && i < dbAttrStatList.size(); i++) {
DBAttributeStatistic dbAttributeStatics = dbAttrStatList.get(i);
for (int j = 0; j < attrList.size(); j++) {
DBAttribute dbAttribute = attrList.get(j);
if (dbAttribute.getName().equals(dbAttributeStatics.getName())) {
attrList.remove(j);
attrList.add(dbAttributeStatics);
break;
}
}
}
attrTableView = new TableViewer(parent, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
attributeTable = attrTableView.getTable();
attributeTable.setLayout(TableViewUtil.createTableViewLayout(new int[] { 20, 20, 20, 20, 20 }));
attributeTable.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, 200));
attributeTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
validate();
}
});
attributeTable.setHeaderVisible(true);
attributeTable.setLinesVisible(true);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColColumnName);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColDataType);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColMiniValue);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColMaxValue);
TableViewUtil.createTableColumn(attributeTable, SWT.CENTER, Messages.tblColValueCount);
attrTableView.setContentProvider(new PartitionTypeContentProvider());
attrTableView.setLabelProvider(new PartitionTypeLabelProvider());
attrTableView.setInput(attrList);
}
Aggregations