mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
134 lines
3.3 KiB
Plaintext
134 lines
3.3 KiB
Plaintext
import java.util.*;
|
|
|
|
|
|
String event = arg("workerEvent");
|
|
if ( event == "done" || event =="alreadyRunning" || event == "longRunningTask")
|
|
return;
|
|
|
|
final WindowContext context = argObj("windowContext");
|
|
Worker worker = argObj("worker");
|
|
final HashObject profile = context.get("profile");
|
|
|
|
Tree tree = context.get("/schemaTree");
|
|
NodeInfo root = (NodeInfo)tree.getModel().getRoot();
|
|
|
|
if ( event == "init" )
|
|
{
|
|
if ( root.getText().equals("A Tree") )
|
|
{
|
|
// we are new and not in a refresh
|
|
tree.setCellRenderer(new IconicCellRenderer("images/db.gif", "images/instance.gif", "images/table.gif"));
|
|
root.setText(profile.get("user") + "@" + profile.get("host"));
|
|
root.setIcon("instance");
|
|
}
|
|
else
|
|
{
|
|
tree.saveState();
|
|
}
|
|
root.removeAllChildren();
|
|
}
|
|
else if ( event == "backgroundTask" )
|
|
{
|
|
final DB db = new SQLLoggingDB((SQLLoggingDB)context.get("db"));
|
|
worker.setProperty("db", db);
|
|
worker.setProperty("waitOperation", "select schema_name from information_schema.schemata");
|
|
|
|
DB.AutoCleanupTX tx = new DB.AutoCleanupTX() {
|
|
public void execute()
|
|
{
|
|
String dbs = profile.get("dbs");
|
|
|
|
String sql = null;
|
|
if ( dbs == null || dbs.length() == 0 )
|
|
{
|
|
sql = "select schema_name from information_schema.schemata order by schema_name";
|
|
}
|
|
else
|
|
{
|
|
String[] dbArray = dbs.split(";");
|
|
sql = "select schema_name from information_schema.schemata where schema_name in (";
|
|
String sep="";
|
|
for (String aDb: dbArray)
|
|
{
|
|
sql+=sep+"'"+aDb + "'";
|
|
sep=",";
|
|
}
|
|
sql+=")";
|
|
}
|
|
|
|
DB.Result databases = db.execute(sql);
|
|
|
|
if ( "true".equals(profile.get("sort")))
|
|
{
|
|
Collections.sort(databases, databases.getComparator(0));
|
|
}
|
|
|
|
HashObject taskResult = new HashObject();
|
|
taskResult.put("databases", databases);
|
|
HashObject tableMap = new HashObject();
|
|
taskResult.put("tables", tableMap);
|
|
|
|
log.debug("database count:" + databases.size());
|
|
|
|
for ( HashObject _dbs : databases )
|
|
{
|
|
String dbName = (String) _dbs.get(0);
|
|
DB.Result tables = db.execute("select table_name from information_schema.tables where table_schema = '" + dbName + "' order by table_name");
|
|
tableMap.put(dbName, tables);
|
|
}
|
|
publish(taskResult);
|
|
}
|
|
};
|
|
|
|
db.execute(tx);
|
|
|
|
}
|
|
else if ( event == "update" )
|
|
{
|
|
HashObject taskResult = (HashObject)((List)argObj("taskResult")).get(0);
|
|
|
|
DB.Result databases = taskResult.getObject("databases");
|
|
HashObject tableMap = taskResult.getObject("tables");
|
|
|
|
HashObject dbNodes = null;
|
|
|
|
dbNodes = TreeUtils.populateList(root, databases, 0, "db");
|
|
|
|
for (String key: (Set<String>)tableMap.keySet())
|
|
{
|
|
DB.Result tables = tableMap.getObject(key);
|
|
TreeUtils.populateList((NodeInfo)dbNodes.getObject(key), tables, 0, "table");
|
|
}
|
|
|
|
tree.updateUI();
|
|
tree.restoreState();
|
|
}
|
|
else if ( event == "cancelled" )
|
|
{
|
|
DB db = worker.getProperty("db");
|
|
if ( db != null )
|
|
{
|
|
db.cancel();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|