New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2017.02 #60

Merged
merged 30 commits into from Feb 8, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+74 鈭341
Diff settings

Always

Just for now

Viewing a subset of changes. View all

Enhancement for Export function (#43)

* export enhancement: apply to SQL, CSV, XLS, TXT files

* export enhancement: apply to loaddb type

* export enhancement: delete unnecessary codes

* export enhancement: refine export datas and delete handling columns

* export enhancement: delete where condition that is duplicated

* export enhancement: deleted subtree check logic

* export enhancement: corrected the typo in messages class

* export enhancement: <> diamond is not support before 1.7 java

* export enhancement: moved getSelectSQL(), getColumnList() to QueryUtil

* export enhancement: replaced StringBuffer to StringBuilder because unnecessary thread safe class.

* export enhancement: moveed totalRecord checking under the table checking
  • Loading branch information...
Seunghun Kim authored and hongwoo-nam committed Jan 5, 2017
commit 1f1af60f74ffae2f71f04da067ef73fb72610d44
@@ -636,4 +636,41 @@ public static String extractBindParameterName(String bindParameter) {
return m.group(2);
}
public static String getSelectSQL(Connection conn, String name) {
String sql = null;
List<String> columnList = getColumnList(conn, name);
StringBuilder columns = new StringBuilder();
int size = columnList.size();
for (int i = 0; i < columnList.size(); i++) {
columns.append(QuerySyntax.escapeKeyword(columnList.get(i)));
if (i != size - 1) {
columns.append(',');
}
}
sql = "SELECT " + columns + " FROM " + QuerySyntax.escapeKeyword(name);
return sql;
}
public static List<String> getColumnList(Connection conn, String tableName) {
List<String> columnList = new ArrayList<String>();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT attr_name FROM db_attribute WHERE class_name = ?";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tableName);
rs = pstmt.executeQuery();
while (rs.next()) {
columnList.add(QuerySyntax.escapeKeyword(rs.getString(1)));
}
} catch (SQLException e) {
LOGGER.error(e.getLocalizedMessage());
} finally {
QueryUtil.freeQuery(pstmt, rs);
}
return columnList;
}
}
@@ -119,12 +119,9 @@ protected void loadExportConfigs() {
String tableName = tables[j].getString("name");
tableList.add(tableName);
String whereCondition = tables[j].getString("where");
String[] columns = tables[j].getString("columns").split(",");
if (whereCondition != null && whereCondition.trim().length() > 0) {
tableWhereConditionMap.put(tableName, whereCondition);
}
List<String> colList = Arrays.asList(columns);
exportTableColumnMap.put(tableName, colList);
}
ExportConfig model = new ExportConfig();
@@ -197,12 +194,8 @@ public void saveConfigs() {
List<String> tableList = model.getTableNameList();
for (String tableName : tableList) {
List<String> colList = model.getColumnNameList(tableName);
String[] cols = new String[colList.size()];
String colNames = StringUtil.implode(",", colList.toArray(cols));
IXMLMemento tableMemento = configMemento.createChild("table");
tableMemento.putString("name", tableName);
tableMemento.putString("columns", colNames);
String whereCondition = model.getWhereCondition(tableName);
if (StringUtil.isNotEmpty(whereCondition)) {
tableMemento.putString("where", whereCondition);
@@ -37,10 +37,8 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.PageChangedEvent;
@@ -71,7 +69,6 @@
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.slf4j.Logger;
import com.cubrid.common.core.util.ConstantsUtil;
@@ -85,14 +82,12 @@
import com.cubrid.common.ui.cubrid.table.progress.ExportConfig;
import com.cubrid.common.ui.spi.model.DefaultSchemaNode;
import com.cubrid.common.ui.spi.model.ICubridNode;
import com.cubrid.common.ui.spi.model.ICubridNodeLoader;
import com.cubrid.common.ui.spi.model.NodeType;
import com.cubrid.common.ui.spi.persist.QueryOptions;
import com.cubrid.common.ui.spi.util.CommonUITool;
import com.cubrid.common.ui.spi.util.TableUtil;
import com.cubrid.cubridmanager.core.common.jdbc.JDBCConnectionManager;
import com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo;
import com.cubrid.cubridmanager.core.cubrid.table.model.TableColumn;
/**
* The ExportSettingForLoadDBPage
@@ -177,51 +172,10 @@ public void createControl(Composite parent) {
ctv.getTree().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
ctv.setContentProvider(new FilterTreeContentProvider());
final Tree tableTree = ctv.getTree();
tableTree.setHeaderVisible(true);
tableTree.setLinesVisible(true);
ctv.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
ctv.setGrayed(event.getElement(), false);
ctv.setSubtreeChecked(event.getElement(), event.getChecked());
if (event.getElement() instanceof ICubridNode) {
ICubridNode node = (ICubridNode) event.getElement();
ICubridNode parent = node.getParent();
if (parent != null) {
changeParentNodeState(parent);
}
}
updateDialogStatus();
}
/**
* Change parent node state based upon the children node state
*
* @param parent the parent node
*/
private void changeParentNodeState(ICubridNode parent) {
int checkedCount = 0;
Object[] objects = ctv.getCheckedElements();
List<ICubridNode> children = parent.getChildren();
for (ICubridNode child : children) {
for (Object obj : objects) {
ICubridNode checkedNode = (ICubridNode) obj;
if (child.getId().equals(checkedNode.getId())) {
checkedCount++;
}
}
}
if (checkedCount == 0) {
ctv.setChecked(parent, false);
ctv.setGrayed(parent, false);
} else if (!children.isEmpty() && checkedCount == children.size()) {
ctv.setChecked(parent, true);
ctv.setGrayed(parent, false);
} else {
ctv.setGrayChecked(parent, true);
}
}
});
final TreeViewerColumn dbObjectCol = new TreeViewerColumn(ctv, SWT.NONE);
@@ -286,7 +240,6 @@ public void widgetSelected(SelectionEvent event) {
for (ICubridNode node : tablesOrViewLst) {
ctv.setGrayed(node, false);
ctv.setChecked(node, selection);
ctv.setSubtreeChecked(node, selection);
}
updateDialogStatus();
}
@@ -487,15 +440,6 @@ private void init() {
if (StringUtil.isNotEmpty(whereCondition)) {
node.setData(ExportObjectLabelProvider.CONDITION, whereCondition);
}
List<String> columnList = exportConfig.getColumnNameList(table);
for (ICubridNode columnNode : node.getChildren()) {
for (String columnName : columnList) {
if (columnNode.getName().equals(columnName)) {
ctv.setChecked(columnNode, true);
break;
}
}
}
}
}
}
@@ -528,7 +472,6 @@ private void init() {
for (ICubridNode node : tablesOrViewLst) {
if (table.equalsIgnoreCase(node.getName())) {
ctv.setChecked(node, true);
ctv.setSubtreeChecked(node, true);
}
}
}
@@ -621,69 +564,6 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException {
}
QueryUtil.freeQuery(rs);
monitor.worked(1);
monitor.subTask(Messages.taskLoadingColumn);
StringBuilder getColumnsSQL = new StringBuilder(
"SELECT attr_name, class_name, is_nullable ");
getColumnsSQL.append("FROM db_attribute WHERE class_name IN (");
for (int i = 0; i < tablesOrViewLst.size(); i++) {
if (i != 0) {
getColumnsSQL.append(" , ");
}
getColumnsSQL.append(" '").append(tablesOrViewLst.get(i).getName()).append(
"' ");
}
getColumnsSQL.append(") ORDER BY class_name, def_order");
query = getColumnsSQL.toString();
// [TOOLS-2425]Support shard broker
if (getDatabase() != null) {
query = DatabaseInfo.wrapShardQuery(getDatabase().getDatabaseInfo(),
query);
}
rs = stmt.executeQuery(query);
Map<String, List<TableColumn>> tableColumMap = new HashMap<String, List<TableColumn>>();
while (rs.next()) {
String columnName = rs.getString(1);
String className = rs.getString(2);
String nullAble = rs.getString(3);
List<TableColumn> columnList = tableColumMap.get(className);
if (columnList == null) {
columnList = new ArrayList<TableColumn>();
tableColumMap.put(className, columnList);
}
TableColumn dbColumn = new TableColumn();
dbColumn.setColumnName(columnName);
if ("YES".equals(nullAble)) {
dbColumn.setPrimaryKey(false);
} else {
dbColumn.setPrimaryKey(true);
}
columnList.add(dbColumn);
}
for (ICubridNode classNode : tablesOrViewLst) {
String tableName = classNode.getName();
List<TableColumn> columns = tableColumMap.get(tableName);
for (TableColumn column : columns) {
String label = column.getColumnName();
String columnId = tableName + ICubridNodeLoader.NODE_SEPARATOR
+ label;
ICubridNode columnNode = new DefaultSchemaNode(columnId, label,
"icons/navigator/table_column_item.png");
if (column.isPrimaryKey()) {
columnNode.setIconPath("icons/primary_key.png");
}
columnNode.setType(NodeType.TABLE_COLUMN);
columnNode.setContainer(false);
classNode.addChild(columnNode);
}
}
monitor.worked(1);
} catch (SQLException e) {
CommonUITool.openErrorBox(getShell(),
e.getErrorCode() + System.getProperty("line.separator")
@@ -803,25 +683,6 @@ private void updateDialogStatus() {
}
}
Object[] objects = ctv.getCheckedElements();
for (Object object : objects) {
ICubridNode node = (ICubridNode) object;
if (node.getType() == NodeType.TABLE_COLUMN_FOLDER) {
boolean hasColumnChecked = false;
for (ICubridNode columnNode : node.getChildren()) {
if (ctv.getChecked(columnNode)) {
hasColumnChecked = true;
break;
}
}
if (!hasColumnChecked) {
setErrorMessage(Messages.bind(Messages.errorExportHistoryColumn, node.getName()));
setPageComplete(false);
return;
}
}
}
String fileCharset = fileCharsetCombo.getText();
if (fileCharset.trim().length() == 0) {
setErrorMessage(Messages.exportWizardLoadDBPageErrMsg5);
@@ -1066,7 +927,6 @@ public void clearOptions() {
Object[] objects = ctv.getCheckedElements();
for (Object o : objects) {
ctv.setChecked(o, false);
ctv.setSubtreeChecked(o, false);
}
tablesOrViewLst.clear();
}
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.