get rid of duplicate db connection script and make work for oracle

This commit is contained in:
servertood
2008-12-21 00:54:39 +00:00
parent 0109ab3925
commit 987b6020d8
6 changed files with 92 additions and 38 deletions

View File

@@ -120,12 +120,14 @@ else if ("Save" == event || "Save/Connect" == event || "Connect" == event)
if ( event.endsWith("Connect"))
{
HashObject profile = (HashObject)profiles.getObject(connProfiles.getText());
String curVendor = dialog.getProperty("currentVendor");
args().put("profile", profile);
DB db = (DB)script("testConnect", args());
DB db = script(String.format("testConnect$%s", curVendor), args());
if (db != null)
{
dialog.dispose();
args().put("db", db);
script("showMainWindow", args());
}
}
@@ -200,7 +202,7 @@ else if ("Vendor" == event)
else if ( newVendor == "oracle" )
{
dialog.setTitle("New Connection - Oracle");
hostLabel.setText("Service@Host");
hostLabel.setText("Service@Host:");
compressBox.setEnabled(false);
dbsLabel.setText(dbsLabel.getText().replaceAll("Database", "Schema"));
sortBox.setText(sortBox.getText().replaceAll("database", "schema"));

View File

@@ -1,35 +0,0 @@
import com.mysql.jdbc.jdbc2.optional.*;
import javax.sql.DataSource;
import com.rendion.editor.*;
DB db = null;
WindowContext context = argObj("windowContext");
HashObject profile = context.get("profile");
AjlEditor editor = context.get("/consoleTabs/SQL Log/outputWindow");
try
{
MysqlDataSource ds = new MysqlDataSource();
String url = "jdbc:mysql://" + profile.get("host") + ":" + profile.get("port") + "/";
url+="?zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true";
if ( "true".equals(profile.get("compress")) )
{
url+="&useCompression=true";
}
ds.setUrl(url);
ds.setUser(profile.get("user"));
ds.setPassword(profile.get("password"));
ds.setLoginTimeout(Integer.parseInt(profile.get("timeout")));
db = new SQLLoggingDB((DataSource)ds, editor);
db.useCache(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
context.put("db", db);

View File

Binary file not shown.

View File

@@ -129,9 +129,13 @@
app.maximize();
app.visible();
DB conn = argObj("db");
DB db = new SQLLoggingDB(conn, editor);
db.useCache(true);
context.put("db", db);
args().put("windowContext", context);
script("initDB", args());
Worker w = worker("initTreeWorker", args());
LongRunningTask.detect("initTreeWorker", "progressWaiter", args(), w , 250);
w = worker("loadHostInfoWorker", args());

View File

@@ -0,0 +1,44 @@
import com.mysql.jdbc.jdbc2.optional.*;
import javax.sql.DataSource;
DB db = null;
WindowContext context = argObj("windowContext");
Frame f = context.get("/");
HashObject profile = argObj("profile");
try
{
MysqlDataSource ds = new MysqlDataSource();
String url = String.format("jdbc:mysql://%s:%s/?zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true&useCompression=%s",
profile.get("host"), profile.get("port"), profile.get("compress"));
ds.setUrl(url);
ds.setUser(profile.get("user"));
ds.setPassword(profile.get("password"));
ds.setLoginTimeout(Integer.parseInt(profile.get("timeout")));
db = new DB((DataSource)ds);
db.execute("select 'abcdefg'");
}
catch (Exception e)
{
Throwable cause = e.getCause();
String message = cause.getMessage();
if (message.indexOf("\n") != -1)
{
int startMessage = message.indexOf("MESSAGE:");
if ( startMessage != -1)
{
startMessage+=8;
message = message.substring(startMessage, message.indexOf("\n", startMessage));
}
}
f.popupMessage("Connection Failed!", message);
db = null;
}
return db;

View File

@@ -0,0 +1,39 @@
import oracle.jdbc.pool.OracleDataSource;
import javax.sql.DataSource;
DB db = null;
WindowContext context = argObj("windowContext");
Frame f = context.get("/");
HashObject profile = argObj("profile");
try
{
OracleDataSource ds = new OracleDataSource();
String host = profile.get("host");
if ( !host.contains("@"))
{
host+="@localhost";
}
String[] serviceHost = host.split("@");
String url = String.format("jdbc:oracle:thin:@%s:%s:%s", serviceHost[1], profile.get("port"), serviceHost[0]);
ds.setURL(url);
ds.setUser(profile.get("user"));
ds.setPassword(profile.get("password"));
ds.setLoginTimeout(Integer.parseInt(profile.get("timeout")));
db = new DB((DataSource)ds);
db.execute("select 'abcdefg' from dual");
}
catch (Exception e)
{
Throwable cause = e.getCause();
String message = cause.getMessage();
f.popupMessage("Connection Failed!", message);
db = null;
}
return db;