package net.argius.stew.ui.window;
-import static java.awt.EventQueue.invokeLater;
import static java.sql.Types.*;
import static java.util.Collections.nCopies;
import static net.argius.stew.text.TextUtilities.join;
-
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.*;
import java.util.regex.*;
-
import javax.swing.table.*;
-
import net.argius.stew.*;
/**
*/
final class ResultSetTableModel extends DefaultTableModel {
- private static final Logger log = Logger.getLogger(ResultSetTableModel.class);
+ static final Logger log = Logger.getLogger(ResultSetTableModel.class);
private static final long serialVersionUID = -8861356207097438822L;
private static final String PTN1 = "\\s*SELECT\\s.+?\\sFROM\\s+([^\\s]+).*";
}
private static final class RowComparator implements Comparator<List<Object>> {
-
+
private final int f;
private final int columnIndex;
-
+
RowComparator(int f, int columnIndex) {
this.f = f;
this.columnIndex = columnIndex;
}
-
+
@Override
public int compare(List<Object> row1, List<Object> row2) {
return c(row1, row2) * f;
}
-
+
private int c(List<Object> row1, List<Object> row2) {
if (row1 == null || row2 == null) {
return row1 == null ? row2 == null ? 0 : -1 : 1;
}
/**
- * Checks whether this table is linkable.
+ * Checks whether this table is linkable.
* @return
*/
boolean isLinkable() {
}
final CountDownLatch latch = new CountDownLatch(1);
final List<SQLException> errors = new ArrayList<SQLException>();
+ final Connection conn = this.conn;
+ final int[] types = this.types;
// asynchronous execution
- DaemonThreadFactory.execute(new Runnable() {
- @SuppressWarnings("synthetic-access")
+ class SqlTask implements Runnable {
@Override
public void run() {
try {
}
latch.countDown();
}
- });
+ }
+ AnyAction.doParallel(new SqlTask());
try {
// waits for a task to stop
latch.await(3L, TimeUnit.SECONDS);
throw new RuntimeException(ex);
}
if (latch.getCount() != 0) {
- DaemonThreadFactory.execute(new Runnable() {
+ class SqlTaskErrorHandler implements Runnable {
@Override
public void run() {
try {
log.warn(ex);
}
if (!errors.isEmpty()) {
- invokeLater(new Runnable() {
- @Override
- public void run() {
- WindowOutputProcessor.showErrorDialog(null, errors.get(0));
- }
- });
+ WindowOutputProcessor.showErrorDialog(null, errors.get(0));
}
}
- });
+ }
+ AnyAction.doParallel(new SqlTaskErrorHandler());
} else if (!errors.isEmpty()) {
if (log.isDebugEnabled()) {
for (final Exception ex : errors) {
String table) throws SQLException {
ResultSet rs = dbmeta.getPrimaryKeys(catalog, schema, table);
try {
- Map<Short, String> result = new TreeMap<Short, String>();
+ List<String> pkList = new ArrayList<String>();
Set<String> schemaSet = new HashSet<String>();
while (rs.next()) {
- result.put(rs.getShort(5), rs.getString(4));
+ pkList.add(rs.getString(4));
schemaSet.add(rs.getString(2));
}
- if (result.isEmpty() || schemaSet.size() != 1) {
+ if (schemaSet.size() != 1) {
return Collections.emptyList();
}
- List<String> pkList = new ArrayList<String>();
- for (Short key : result.keySet()) {
- pkList.add(result.get(key));
- }
return pkList;
} finally {
rs.close();